The open source coding agent.
TypeScript
initialized
Dax Raadcaf9fdc893bf
diff --git a/packages/opencode/src/app/app.ts b/packages/opencode/src/app/app.tsindex fc75cd26a98..ed4408da053 100644--- a/packages/opencode/src/app/app.ts+++ b/packages/opencode/src/app/app.ts@@ -10,15 +10,15 @@ export namespace App {export const Info = z.object({- time: z.object({- initialized: z.number().optional(),- }),git: z.boolean(),path: z.object({data: z.string(),root: z.string(),cwd: z.string(),}),+ time: z.object({+ initialized: z.number().optional(),+ }),}).openapi({ref: "App.Info",@@ -33,16 +33,12 @@ export namespace App {)const data = path.join(Global.data(), git ?? "global")- await Bun.write(path.join(data, "version"), input.version)const stateFile = Bun.file(path.join(data, "state"))- const state = (- (await stateFile.exists()) ? await stateFile.json() : {}- ) as {+ const state = (await stateFile.json().catch(() => ({}))) as {initialized: numberversion: string}state.version = input.version- if (!git) state.initialized = Date.now()await stateFile.write(JSON.stringify(state))const services = new Map<@@ -67,6 +63,7 @@ export namespace App {},}const result = {+ version: input.version,services,info,}@@ -102,7 +99,6 @@ export namespace App {cb: T,) {const app = await create(input)-return ctx.provide(app, async () => {const result = await cb(app.info)for (const [key, entry] of app.services.entries()) {@@ -112,4 +108,16 @@ export namespace App {return result})}++ export async function initialize() {+ const { info, version } = ctx.use()+ info.time.initialized = Date.now()+ await Bun.write(+ path.join(info.path.data, "state"),+ JSON.stringify({+ version,+ initialized: Date.now(),+ }),+ )+ }}diff --git a/packages/opencode/src/server/server.ts b/packages/opencode/src/server/server.tsindex 245ade4feb0..9b370b04a37 100644--- a/packages/opencode/src/server/server.ts+++ b/packages/opencode/src/server/server.ts@@ -100,6 +100,26 @@ export namespace Server {return c.json(App.info())},)+ .post(+ "/app_initialize",+ describeRoute({+ description: "Initialize the app",+ responses: {+ 200: {+ description: "Initialize the app",+ content: {+ "application/json": {+ schema: resolver(z.boolean()),+ },+ },+ },+ },+ }),+ async (c) => {+ await App.initialize()+ return c.json(true)+ },+ ).post("/session_initialize",describeRoute({diff --git a/packages/opencode/src/session/session.ts b/packages/opencode/src/session/session.tsindex 52b954f93ea..190c93eeadc 100644--- a/packages/opencode/src/session/session.ts+++ b/packages/opencode/src/session/session.ts@@ -350,6 +350,7 @@ ${app.git ? await ListTool.execute({ path: app.path.cwd }, { sessionID: input.seassistant.tokens = usage.tokensawait updateMessage(next)},+ toolCallStreaming: false,abortSignal: abort.signal,maxRetries: 6,stopWhen: stepCountIs(1000),@@ -403,6 +404,21 @@ ${app.git ? await ListTool.execute({ path: app.path.cwd }, { sessionID: input.se})break+ case "tool-call-streaming-start":+ next.parts.push({+ type: "tool-invocation",+ toolInvocation: {+ state: "call",+ toolName: value.toolName,+ toolCallId: value.toolCallId,+ args: {},+ },+ })+ break++ case "tool-call-delta":+ break+case "tool-result":const match = next.parts.find((p) =>@@ -566,5 +582,6 @@ ${app.git ? await ListTool.execute({ path: app.path.cwd }, { sessionID: input.se},],})+ await App.initialize()}}diff --git a/packages/tui/pkg/client/gen/openapi.json b/packages/tui/pkg/client/gen/openapi.jsonindex 7ca11e6b2ba..758d54620f4 100644--- a/packages/tui/pkg/client/gen/openapi.json+++ b/packages/tui/pkg/client/gen/openapi.json@@ -44,6 +44,69 @@"description": "Get app info"}},+ "/app_initialize": {+ "post": {+ "responses": {+ "200": {+ "description": "Initialize the app",+ "content": {+ "application/json": {+ "schema": {+ "type": "boolean"+ }+ }+ }+ }+ },+ "operationId": "postApp_initialize",+ "parameters": [],+ "description": "Initialize the app"+ }+ },+ "/session_initialize": {+ "post": {+ "responses": {+ "200": {+ "description": "200",+ "content": {+ "application/json": {+ "schema": {+ "type": "boolean"+ }+ }+ }+ }+ },+ "operationId": "postSession_initialize",+ "parameters": [],+ "description": "Analyze the app and create an AGENTS.md file",+ "requestBody": {+ "content": {+ "application/json": {+ "schema": {+ "type": "object",+ "properties": {+ "sessionID": {+ "type": "string"+ },+ "providerID": {+ "type": "string"+ },+ "modelID": {+ "type": "string"+ }+ },+ "required": [+ "sessionID",+ "providerID",+ "modelID"+ ]+ }+ }+ }+ }+ }+ },"/path_get": {"post": {"responses": {@@ -932,13 +995,8 @@"App.Info": {"type": "object","properties": {- "time": {- "type": "object",- "properties": {- "initialized": {- "type": "number"- }- }+ "git": {+ "type": "boolean"},"path": {"type": "object",@@ -958,11 +1016,20 @@"root","cwd"]+ },+ "time": {+ "type": "object",+ "properties": {+ "initialized": {+ "type": "number"+ }+ }}},"required": [- "time",- "path"+ "git",+ "path",+ "time"]},"Provider.Info": {diff --git a/packages/tui/pkg/client/generated-client.go b/packages/tui/pkg/client/generated-client.goindex 4552a37b462..2d3369eac58 100644--- a/packages/tui/pkg/client/generated-client.go+++ b/packages/tui/pkg/client/generated-client.go@@ -26,6 +26,7 @@ const (// AppInfo defines model for App.Info.type AppInfo struct {+ Git bool `json:"git"`Path struct {Cwd string `json:"cwd"`Data string `json:"data"`@@ -251,6 +252,13 @@ type PostSessionChatJSONBody struct {SessionID string `json:"sessionID"`}+// PostSessionInitializeJSONBody defines parameters for PostSessionInitialize.+type PostSessionInitializeJSONBody struct {+ ModelID string `json:"modelID"`+ ProviderID string `json:"providerID"`+ SessionID string `json:"sessionID"`+}+// PostSessionMessagesJSONBody defines parameters for PostSessionMessages.type PostSessionMessagesJSONBody struct {SessionID string `json:"sessionID"`@@ -274,6 +282,9 @@ type PostSessionAbortJSONRequestBody PostSessionAbortJSONBody// PostSessionChatJSONRequestBody defines body for PostSessionChat for application/json ContentType.type PostSessionChatJSONRequestBody PostSessionChatJSONBody+// PostSessionInitializeJSONRequestBody defines body for PostSessionInitialize for application/json ContentType.+type PostSessionInitializeJSONRequestBody PostSessionInitializeJSONBody+// PostSessionMessagesJSONRequestBody defines body for PostSessionMessages for application/json ContentType.type PostSessionMessagesJSONRequestBody PostSessionMessagesJSONBody@@ -866,6 +877,9 @@ type ClientInterface interface {// PostAppInfo requestPostAppInfo(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)+ // PostAppInitialize request+ PostAppInitialize(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)+// GetEvent requestGetEvent(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)@@ -888,6 +902,11 @@ type ClientInterface interface {// PostSessionCreate requestPostSessionCreate(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)+ // PostSessionInitializeWithBody request with any body+ PostSessionInitializeWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)++ PostSessionInitialize(ctx context.Context, body PostSessionInitializeJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)+// PostSessionList requestPostSessionList(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)@@ -919,6 +938,18 @@ func (c *Client) PostAppInfo(ctx context.Context, reqEditors ...RequestEditorFn)return c.Client.Do(req)}+func (c *Client) PostAppInitialize(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {+ req, err := NewPostAppInitializeRequest(c.Server)+ if err != nil {+ return nil, err+ }+ req = req.WithContext(ctx)+ if err := c.applyEditors(ctx, req, reqEditors); err != nil {+ return nil, err+ }+ return c.Client.Do(req)+}+func (c *Client) GetEvent(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {req, err := NewGetEventRequest(c.Server)if err != nil {@@ -1015,6 +1046,30 @@ func (c *Client) PostSessionCreate(ctx context.Context, reqEditors ...RequestEdireturn c.Client.Do(req)}+func (c *Client) PostSessionInitializeWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {+ req, err := NewPostSessionInitializeRequestWithBody(c.Server, contentType, body)+ if err != nil {+ return nil, err+ }+ req = req.WithContext(ctx)+ if err := c.applyEditors(ctx, req, reqEditors); err != nil {+ return nil, err+ }+ return c.Client.Do(req)+}++func (c *Client) PostSessionInitialize(ctx context.Context, body PostSessionInitializeJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {+ req, err := NewPostSessionInitializeRequest(c.Server, body)+ if err != nil {+ return nil, err+ }+ req = req.WithContext(ctx)+ if err := c.applyEditors(ctx, req, reqEditors); err != nil {+ return nil, err+ }+ return c.Client.Do(req)+}+func (c *Client) PostSessionList(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {req, err := NewPostSessionListRequest(c.Server)if err != nil {@@ -1126,6 +1181,33 @@ func NewPostAppInfoRequest(server string) (*http.Request, error) {return req, nil}+// NewPostAppInitializeRequest generates requests for PostAppInitialize+func NewPostAppInitializeRequest(server string) (*http.Request, error) {+ var err error++ serverURL, err := url.Parse(server)+ if err != nil {+ return nil, err+ }++ operationPath := fmt.Sprintf("/app_initialize")+ if operationPath[0] == '/' {+ operationPath = "." + operationPath+ }++ queryURL, err := serverURL.Parse(operationPath)+ if err != nil {+ return nil, err+ }++ req, err := http.NewRequest("POST", queryURL.String(), nil)+ if err != nil {+ return nil, err+ }++ return req, nil+}+// NewGetEventRequest generates requests for GetEventfunc NewGetEventRequest(server string) (*http.Request, error) {var err error@@ -1314,6 +1396,46 @@ func NewPostSessionCreateRequest(server string) (*http.Request, error) {return req, nil}+// NewPostSessionInitializeRequest calls the generic PostSessionInitialize builder with application/json body+func NewPostSessionInitializeRequest(server string, body PostSessionInitializeJSONRequestBody) (*http.Request, error) {+ var bodyReader io.Reader+ buf, err := json.Marshal(body)+ if err != nil {+ return nil, err+ }+ bodyReader = bytes.NewReader(buf)+ return NewPostSessionInitializeRequestWithBody(server, "application/json", bodyReader)+}++// NewPostSessionInitializeRequestWithBody generates requests for PostSessionInitialize with any type of body+func NewPostSessionInitializeRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) {+ var err error++ serverURL, err := url.Parse(server)+ if err != nil {+ return nil, err+ }++ operationPath := fmt.Sprintf("/session_initialize")+ if operationPath[0] == '/' {+ operationPath = "." + operationPath+ }++ queryURL, err := serverURL.Parse(operationPath)+ if err != nil {+ return nil, err+ }++ req, err := http.NewRequest("POST", queryURL.String(), body)+ if err != nil {+ return nil, err+ }++ req.Header.Add("Content-Type", contentType)++ return req, nil+}+// NewPostSessionListRequest generates requests for PostSessionListfunc NewPostSessionListRequest(server string) (*http.Request, error) {var err error@@ -1507,6 +1629,9 @@ type ClientWithResponsesInterface interface {// PostAppInfoWithResponse requestPostAppInfoWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostAppInfoResponse, error)+ // PostAppInitializeWithResponse request+ PostAppInitializeWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostAppInitializeResponse, error)+// GetEventWithResponse requestGetEventWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetEventResponse, error)@@ -1529,6 +1654,11 @@ type ClientWithResponsesInterface interface {// PostSessionCreateWithResponse requestPostSessionCreateWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostSessionCreateResponse, error)+ // PostSessionInitializeWithBodyWithResponse request with any body+ PostSessionInitializeWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionInitializeResponse, error)++ PostSessionInitializeWithResponse(ctx context.Context, body PostSessionInitializeJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSessionInitializeResponse, error)+// PostSessionListWithResponse requestPostSessionListWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostSessionListResponse, error)@@ -1570,6 +1700,28 @@ func (r PostAppInfoResponse) StatusCode() int {return 0}+type PostAppInitializeResponse struct {+ Body []byte+ HTTPResponse *http.Response+ JSON200 *bool+}++// Status returns HTTPResponse.Status+func (r PostAppInitializeResponse) Status() string {+ if r.HTTPResponse != nil {+ return r.HTTPResponse.Status+ }+ return http.StatusText(0)+}++// StatusCode returns HTTPResponse.StatusCode+func (r PostAppInitializeResponse) StatusCode() int {+ if r.HTTPResponse != nil {+ return r.HTTPResponse.StatusCode+ }+ return 0+}+type GetEventResponse struct {Body []byteHTTPResponse *http.Response@@ -1707,6 +1859,28 @@ func (r PostSessionCreateResponse) StatusCode() int {return 0}+type PostSessionInitializeResponse struct {+ Body []byte+ HTTPResponse *http.Response+ JSON200 *bool+}++// Status returns HTTPResponse.Status+func (r PostSessionInitializeResponse) Status() string {+ if r.HTTPResponse != nil {+ return r.HTTPResponse.Status+ }+ return http.StatusText(0)+}++// StatusCode returns HTTPResponse.StatusCode+func (r PostSessionInitializeResponse) StatusCode() int {+ if r.HTTPResponse != nil {+ return r.HTTPResponse.StatusCode+ }+ return 0+}+type PostSessionListResponse struct {Body []byteHTTPResponse *http.Response@@ -1804,6 +1978,15 @@ func (c *ClientWithResponses) PostAppInfoWithResponse(ctx context.Context, reqEdreturn ParsePostAppInfoResponse(rsp)}+// PostAppInitializeWithResponse request returning *PostAppInitializeResponse+func (c *ClientWithResponses) PostAppInitializeWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostAppInitializeResponse, error) {+ rsp, err := c.PostAppInitialize(ctx, reqEditors...)+ if err != nil {+ return nil, err+ }+ return ParsePostAppInitializeResponse(rsp)+}+// GetEventWithResponse request returning *GetEventResponsefunc (c *ClientWithResponses) GetEventWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetEventResponse, error) {rsp, err := c.GetEvent(ctx, reqEditors...)@@ -1874,6 +2057,23 @@ func (c *ClientWithResponses) PostSessionCreateWithResponse(ctx context.Context,return ParsePostSessionCreateResponse(rsp)}+// PostSessionInitializeWithBodyWithResponse request with arbitrary body returning *PostSessionInitializeResponse+func (c *ClientWithResponses) PostSessionInitializeWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionInitializeResponse, error) {+ rsp, err := c.PostSessionInitializeWithBody(ctx, contentType, body, reqEditors...)+ if err != nil {+ return nil, err+ }+ return ParsePostSessionInitializeResponse(rsp)+}++func (c *ClientWithResponses) PostSessionInitializeWithResponse(ctx context.Context, body PostSessionInitializeJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSessionInitializeResponse, error) {+ rsp, err := c.PostSessionInitialize(ctx, body, reqEditors...)+ if err != nil {+ return nil, err+ }+ return ParsePostSessionInitializeResponse(rsp)+}+// PostSessionListWithResponse request returning *PostSessionListResponsefunc (c *ClientWithResponses) PostSessionListWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostSessionListResponse, error) {rsp, err := c.PostSessionList(ctx, reqEditors...)@@ -1960,6 +2160,32 @@ func ParsePostAppInfoResponse(rsp *http.Response) (*PostAppInfoResponse, error)return response, nil}+// ParsePostAppInitializeResponse parses an HTTP response from a PostAppInitializeWithResponse call+func ParsePostAppInitializeResponse(rsp *http.Response) (*PostAppInitializeResponse, error) {+ bodyBytes, err := io.ReadAll(rsp.Body)+ defer func() { _ = rsp.Body.Close() }()+ if err != nil {+ return nil, err+ }++ response := &PostAppInitializeResponse{+ Body: bodyBytes,+ HTTPResponse: rsp,+ }++ switch {+ case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:+ var dest bool+ if err := json.Unmarshal(bodyBytes, &dest); err != nil {+ return nil, err+ }+ response.JSON200 = &dest++ }++ return response, nil+}+// ParseGetEventResponse parses an HTTP response from a GetEventWithResponse callfunc ParseGetEventResponse(rsp *http.Response) (*GetEventResponse, error) {bodyBytes, err := io.ReadAll(rsp.Body)@@ -2121,6 +2347,32 @@ func ParsePostSessionCreateResponse(rsp *http.Response) (*PostSessionCreateResporeturn response, nil}+// ParsePostSessionInitializeResponse parses an HTTP response from a PostSessionInitializeWithResponse call+func ParsePostSessionInitializeResponse(rsp *http.Response) (*PostSessionInitializeResponse, error) {+ bodyBytes, err := io.ReadAll(rsp.Body)+ defer func() { _ = rsp.Body.Close() }()+ if err != nil {+ return nil, err+ }++ response := &PostSessionInitializeResponse{+ Body: bodyBytes,+ HTTPResponse: rsp,+ }++ switch {+ case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:+ var dest bool+ if err := json.Unmarshal(bodyBytes, &dest); err != nil {+ return nil, err+ }+ response.JSON200 = &dest++ }++ return response, nil+}+// ParsePostSessionListResponse parses an HTTP response from a PostSessionListWithResponse callfunc ParsePostSessionListResponse(rsp *http.Response) (*PostSessionListResponse, error) {bodyBytes, err := io.ReadAll(rsp.Body)