@amends-dev/harness-opencode 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/LICENSE +21 -0
  2. package/Opencode2Agent.d.ts +105 -0
  3. package/Opencode2Agent.d.ts.map +1 -0
  4. package/Opencode2Agent.js +72 -0
  5. package/Opencode2Agent.js.map +1 -0
  6. package/OpencodeAgent.d.ts +110 -0
  7. package/OpencodeAgent.d.ts.map +1 -0
  8. package/OpencodeAgent.js +83 -0
  9. package/OpencodeAgent.js.map +1 -0
  10. package/README.md +223 -2
  11. package/index.d.ts +18 -0
  12. package/index.d.ts.map +1 -0
  13. package/index.js +19 -0
  14. package/index.js.map +1 -0
  15. package/internal/agent.d.ts +29 -0
  16. package/internal/agent.d.ts.map +1 -0
  17. package/internal/agent.js +34 -0
  18. package/internal/agent.js.map +1 -0
  19. package/internal/bridge/bunBridge.d.ts +33 -0
  20. package/internal/bridge/bunBridge.d.ts.map +1 -0
  21. package/internal/bridge/bunBridge.js +62 -0
  22. package/internal/bridge/bunBridge.js.map +1 -0
  23. package/internal/bridge/driver.d.ts +81 -0
  24. package/internal/bridge/driver.d.ts.map +1 -0
  25. package/internal/bridge/driver.js +82 -0
  26. package/internal/bridge/driver.js.map +1 -0
  27. package/internal/bridge/hostTools.d.ts +28 -0
  28. package/internal/bridge/hostTools.d.ts.map +1 -0
  29. package/internal/bridge/hostTools.js +41 -0
  30. package/internal/bridge/hostTools.js.map +1 -0
  31. package/internal/bridge/server.d.ts +64 -0
  32. package/internal/bridge/server.d.ts.map +1 -0
  33. package/internal/bridge/server.js +129 -0
  34. package/internal/bridge/server.js.map +1 -0
  35. package/internal/bridge/steps.d.ts +29 -0
  36. package/internal/bridge/steps.d.ts.map +1 -0
  37. package/internal/bridge/steps.js +42 -0
  38. package/internal/bridge/steps.js.map +1 -0
  39. package/internal/bridge/v1/api.d.ts +181 -0
  40. package/internal/bridge/v1/api.d.ts.map +1 -0
  41. package/internal/bridge/v1/api.js +83 -0
  42. package/internal/bridge/v1/api.js.map +1 -0
  43. package/internal/bridge/v1/event.d.ts +597 -0
  44. package/internal/bridge/v1/event.d.ts.map +1 -0
  45. package/internal/bridge/v1/event.js +186 -0
  46. package/internal/bridge/v1/event.js.map +1 -0
  47. package/internal/bridge/v1/main.d.ts +6 -0
  48. package/internal/bridge/v1/main.d.ts.map +1 -0
  49. package/internal/bridge/v1/main.js +8 -0
  50. package/internal/bridge/v1/main.js.map +1 -0
  51. package/internal/bridge/v1/prompt.d.ts +18 -0
  52. package/internal/bridge/v1/prompt.d.ts.map +1 -0
  53. package/internal/bridge/v1/prompt.js +92 -0
  54. package/internal/bridge/v1/prompt.js.map +1 -0
  55. package/internal/bridge/v1/session.d.ts +28 -0
  56. package/internal/bridge/v1/session.d.ts.map +1 -0
  57. package/internal/bridge/v1/session.js +188 -0
  58. package/internal/bridge/v1/session.js.map +1 -0
  59. package/internal/bridge/v1/turn.d.ts +82 -0
  60. package/internal/bridge/v1/turn.d.ts.map +1 -0
  61. package/internal/bridge/v1/turn.js +335 -0
  62. package/internal/bridge/v1/turn.js.map +1 -0
  63. package/internal/bridge/v2/api.d.ts +86 -0
  64. package/internal/bridge/v2/api.d.ts.map +1 -0
  65. package/internal/bridge/v2/api.js +105 -0
  66. package/internal/bridge/v2/api.js.map +1 -0
  67. package/internal/bridge/v2/event.d.ts +539 -0
  68. package/internal/bridge/v2/event.d.ts.map +1 -0
  69. package/internal/bridge/v2/event.js +164 -0
  70. package/internal/bridge/v2/event.js.map +1 -0
  71. package/internal/bridge/v2/main.d.ts +6 -0
  72. package/internal/bridge/v2/main.d.ts.map +1 -0
  73. package/internal/bridge/v2/main.js +8 -0
  74. package/internal/bridge/v2/main.js.map +1 -0
  75. package/internal/bridge/v2/prompt.d.ts +109 -0
  76. package/internal/bridge/v2/prompt.d.ts.map +1 -0
  77. package/internal/bridge/v2/prompt.js +209 -0
  78. package/internal/bridge/v2/prompt.js.map +1 -0
  79. package/internal/bridge/v2/session.d.ts +21 -0
  80. package/internal/bridge/v2/session.d.ts.map +1 -0
  81. package/internal/bridge/v2/session.js +198 -0
  82. package/internal/bridge/v2/session.js.map +1 -0
  83. package/internal/bridge/v2/turn.d.ts +62 -0
  84. package/internal/bridge/v2/turn.d.ts.map +1 -0
  85. package/internal/bridge/v2/turn.js +277 -0
  86. package/internal/bridge/v2/turn.js.map +1 -0
  87. package/internal/models.d.ts +47 -0
  88. package/internal/models.d.ts.map +1 -0
  89. package/internal/models.js +170 -0
  90. package/internal/models.js.map +1 -0
  91. package/internal/template.d.ts +46 -0
  92. package/internal/template.d.ts.map +1 -0
  93. package/internal/template.js +267 -0
  94. package/internal/template.js.map +1 -0
  95. package/package.json +39 -4
@@ -0,0 +1,186 @@
1
+ /**
2
+ * The events opencode publishes on its event stream in opencode 1's session API: a message of a
3
+ * session being written, each of its parts as it changes, the deltas of a text as it streams, the
4
+ * session's status, and what a tool asks of the session's user. opencode keeps a message's parts
5
+ * as the latest state of each, not as events, and publishes each change to the instance of one
6
+ * directory, live only.
7
+ *
8
+ * The schemas are opencode 1.18's, for the events this adapter reads, with the fields it reads of
9
+ * them; other fields pass. Each step of a turn is an assistant message of its own, complete once
10
+ * its `time.completed` is set. Text and reasoning stream as deltas of a part, whose update then
11
+ * holds it whole; a call of a tool is a part that goes from `pending` to `running`, and then to
12
+ * `completed` or `error`.
13
+ */
14
+ import * as Schema from "effect/Schema";
15
+ import { Tokens } from "../steps.js";
16
+ /** What opencode reports of a failure: its kind, such as `MessageAbortedError`, and its message. */
17
+ export const Failure = Schema.Struct({
18
+ name: Schema.String,
19
+ data: Schema.optional(Schema.Struct({ message: Schema.optional(Schema.String) }))
20
+ });
21
+ const JsonObject = Schema.Record(Schema.String, Schema.Unknown);
22
+ /** Fields every part of a message has. */
23
+ const inMessage = {
24
+ id: Schema.String,
25
+ sessionID: Schema.String,
26
+ messageID: Schema.String
27
+ };
28
+ /** When a part started and, once it has, ended. */
29
+ const Time = Schema.Struct({
30
+ start: Schema.optional(Schema.Finite),
31
+ end: Schema.optional(Schema.Finite)
32
+ });
33
+ /** A text of the message. Its `text` is whole once `time.end` is set. */
34
+ export const TextPart = Schema.Struct({
35
+ ...inMessage,
36
+ type: Schema.tag("text"),
37
+ text: Schema.String,
38
+ time: Schema.optional(Time)
39
+ });
40
+ /** A reasoning of the message, whole once `time.end` is set. */
41
+ export const ReasoningPart = Schema.Struct({
42
+ ...inMessage,
43
+ type: Schema.tag("reasoning"),
44
+ text: Schema.String,
45
+ time: Schema.optional(Time),
46
+ metadata: Schema.optional(JsonObject)
47
+ });
48
+ /** The model is writing the call's input. */
49
+ const ToolPending = Schema.Struct({ status: Schema.tag("pending") });
50
+ /** opencode is running the call with `input`. */
51
+ const ToolRunning = Schema.Struct({ status: Schema.tag("running"), input: JsonObject });
52
+ /** The call succeeded, with `output` for the model to read, and what the tool reported. */
53
+ const ToolCompleted = Schema.Struct({
54
+ status: Schema.tag("completed"),
55
+ input: JsonObject,
56
+ output: Schema.String,
57
+ metadata: Schema.optional(JsonObject)
58
+ });
59
+ const ToolError = Schema.Struct({
60
+ status: Schema.tag("error"),
61
+ input: JsonObject,
62
+ error: Schema.String
63
+ });
64
+ export const ToolState = Schema.Union([ToolPending, ToolRunning, ToolCompleted, ToolError]).pipe(Schema.toTaggedUnion("status"));
65
+ /** A call of the tool `tool`, in the state `state`. */
66
+ export const ToolPart = Schema.Struct({
67
+ ...inMessage,
68
+ type: Schema.tag("tool"),
69
+ callID: Schema.String,
70
+ tool: Schema.String,
71
+ state: ToolState
72
+ });
73
+ /** A part of a type the adapter does not read, such as a step's start, or a snapshot. */
74
+ export const OtherPart = Schema.Struct({
75
+ ...inMessage,
76
+ type: Schema.String.check(Schema.makeFilter((type) => !["text", "reasoning", "tool"].includes(type)))
77
+ });
78
+ export const Part = Schema.Union([TextPart, ReasoningPart, ToolPart, OtherPart]);
79
+ export const isTextPart = Schema.is(TextPart);
80
+ export const isReasoningPart = Schema.is(ReasoningPart);
81
+ export const isToolPart = Schema.is(ToolPart);
82
+ /** A model, as opencode 1 names one in a prompt: its provider, and its id there. */
83
+ export const MessageModel = Schema.Struct({ providerID: Schema.String, modelID: Schema.String });
84
+ /**
85
+ * An assistant message: one step of a turn. It is complete once `time.completed` is set, having
86
+ * ended as `finish` says, or failed with `error`. A step that answered in JSON holds the answer as
87
+ * `structured`, and one that summarized the conversation is a `summary`.
88
+ */
89
+ export const AssistantMessage = Schema.Struct({
90
+ id: Schema.String,
91
+ sessionID: Schema.String,
92
+ role: Schema.tag("assistant"),
93
+ providerID: Schema.String,
94
+ modelID: Schema.String,
95
+ time: Schema.Struct({ created: Schema.Finite, completed: Schema.optional(Schema.Finite) }),
96
+ error: Schema.optional(Failure),
97
+ summary: Schema.optional(Schema.Boolean),
98
+ tokens: Schema.optional(Tokens),
99
+ structured: Schema.optional(Schema.Unknown),
100
+ finish: Schema.optional(Schema.String)
101
+ });
102
+ /** A user message: a prompt the session took. */
103
+ export const UserMessage = Schema.Struct({
104
+ id: Schema.String,
105
+ sessionID: Schema.String,
106
+ role: Schema.tag("user")
107
+ });
108
+ export const Message = Schema.Union([AssistantMessage, UserMessage]).pipe(Schema.toTaggedUnion("role"));
109
+ /** A message was written, or changed: its latest state. */
110
+ export const MessageUpdated = Schema.Struct({
111
+ type: Schema.tag("message.updated"),
112
+ properties: Schema.Struct({ sessionID: Schema.String, info: Message })
113
+ });
114
+ /** A part of a message was written, or changed: its latest state. */
115
+ export const MessagePartUpdated = Schema.Struct({
116
+ type: Schema.tag("message.part.updated"),
117
+ properties: Schema.Struct({ sessionID: Schema.String, part: Part })
118
+ });
119
+ /**
120
+ * The model wrote `delta` more of a part's `field`. opencode names the field `text` for a
121
+ * reasoning's text too.
122
+ */
123
+ export const MessagePartDelta = Schema.Struct({
124
+ type: Schema.tag("message.part.delta"),
125
+ properties: Schema.Struct({
126
+ sessionID: Schema.String,
127
+ messageID: Schema.String,
128
+ partID: Schema.String,
129
+ field: Schema.String,
130
+ delta: Schema.String
131
+ })
132
+ });
133
+ /**
134
+ * The session is `busy` working on a turn, `idle`, or waiting to `retry` a request its model's
135
+ * provider refused.
136
+ */
137
+ export const SessionStatus = Schema.Struct({
138
+ type: Schema.tag("session.status"),
139
+ properties: Schema.Struct({
140
+ sessionID: Schema.String,
141
+ status: Schema.Struct({ type: Schema.String })
142
+ })
143
+ });
144
+ /** The session stopped working on its turn, whether the turn ended or failed. */
145
+ export const SessionIdle = Schema.Struct({
146
+ type: Schema.tag("session.idle"),
147
+ properties: Schema.Struct({ sessionID: Schema.String })
148
+ });
149
+ /** The session's turn failed, as when its model's provider refused it, or it was aborted. */
150
+ export const SessionErrored = Schema.Struct({
151
+ type: Schema.tag("session.error"),
152
+ properties: Schema.Struct({
153
+ sessionID: Schema.optional(Schema.String),
154
+ error: Schema.optional(Failure)
155
+ })
156
+ });
157
+ /**
158
+ * A tool asks the user's permission before it goes on, for the action `permission` on `patterns`,
159
+ * such as a command or a path. `tool` names the call that asks.
160
+ */
161
+ export const PermissionAsked = Schema.Struct({
162
+ type: Schema.tag("permission.asked"),
163
+ properties: Schema.Struct({
164
+ id: Schema.String,
165
+ sessionID: Schema.String,
166
+ permission: Schema.String,
167
+ patterns: Schema.Array(Schema.String),
168
+ tool: Schema.optional(Schema.Struct({ messageID: Schema.String, callID: Schema.String }))
169
+ })
170
+ });
171
+ /** The model asks the user questions, with its `question` tool. */
172
+ export const QuestionAsked = Schema.Struct({
173
+ type: Schema.tag("question.asked"),
174
+ properties: Schema.Struct({ id: Schema.String, sessionID: Schema.String })
175
+ });
176
+ export const SessionEvent = Schema.Union([
177
+ MessageUpdated,
178
+ MessagePartUpdated,
179
+ MessagePartDelta,
180
+ SessionStatus,
181
+ SessionIdle,
182
+ SessionErrored,
183
+ PermissionAsked,
184
+ QuestionAsked
185
+ ]).pipe(Schema.toTaggedUnion("type"));
186
+ //# sourceMappingURL=event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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Ac;IACd,kBAAkB;IAClB,gBAAgB;IAChB,aAAa;IACb,WAAW;IACX,cAAc;IACd,eAAe;IACf,aAAa;CACd,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAA"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The bridge program of the opencode agent, which a host launches in its sandbox, over opencode 1's
3
+ * session API, as `BunBridge.runProgram` runs it.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../../src/internal/bridge/v1/main.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The bridge program of the opencode agent, which a host launches in its sandbox, over opencode 1's
3
+ * session API, as `BunBridge.runProgram` runs it.
4
+ */
5
+ import * as BunBridge from "../bunBridge.js";
6
+ import { makeCreateSession } from "./session.js";
7
+ BunBridge.runProgram("opencode", import.meta.dirname, makeCreateSession);
8
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../src/internal/bridge/v1/main.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD,SAAS,CAAC,UAAU,CAAC,UAAU,EAAE,OAAO,IAAI,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAA"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * What opencode 1 is prompted with: the parts of a turn's prompt, and a conversation started on
3
+ * another agent, which opencode 1 has no way to record as its own steps. The conversation is
4
+ * written instead as one message of the session that the model reads and does not answer: each
5
+ * message as who wrote it and what it said, the tools called with their results, and the files
6
+ * the user gave attached as they were.
7
+ */
8
+ import type * as Prompt from "effect/ai/Prompt";
9
+ import type { PromptPart } from "./api.ts";
10
+ /** The parts of a user message, as opencode 1 takes them: its texts, and its files by URL. */
11
+ export declare const promptPartsOf: (message: Prompt.UserMessage) => ReadonlyArray<PromptPart>;
12
+ /**
13
+ * The parts that record `conversation` in a session that has no record of it: its messages written
14
+ * out as one text, which opencode marks as written for the model rather than by the user, and the
15
+ * files of its user messages. Nothing for an empty conversation.
16
+ */
17
+ export declare const conversationPartsOf: (conversation: Prompt.Prompt) => ReadonlyArray<PromptPart>;
18
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../../src/internal/bridge/v1/prompt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,MAAM,kBAAkB,CAAA;AAE/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,8FAA8F;AAC9F,eAAO,MAAM,aAAa,YAAa,MAAM,CAAC,WAAW,KAAG,aAAa,CAAC,UAAU,CAC0B,CAAA;AAE9G;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,iBAAkB,MAAM,CAAC,MAAM,KAAG,aAAa,CAAC,UAAU,CAkDzF,CAAA"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * What opencode 1 is prompted with: the parts of a turn's prompt, and a conversation started on
3
+ * another agent, which opencode 1 has no way to record as its own steps. The conversation is
4
+ * written instead as one message of the session that the model reads and does not answer: each
5
+ * message as who wrote it and what it said, the tools called with their results, and the files
6
+ * the user gave attached as they were.
7
+ */
8
+ import * as Base64 from "effect/encoding/Base64";
9
+ /** The parts of a user message, as opencode 1 takes them: its texts, and its files by URL. */
10
+ export const promptPartsOf = (message) => message.content.map((part) => (part.type === "text" ? { type: "text", text: part.text } : filePartOf(part)));
11
+ /**
12
+ * The parts that record `conversation` in a session that has no record of it: its messages written
13
+ * out as one text, which opencode marks as written for the model rather than by the user, and the
14
+ * files of its user messages. Nothing for an empty conversation.
15
+ */
16
+ export const conversationPartsOf = (conversation) => {
17
+ if (conversation.content.length === 0)
18
+ return [];
19
+ const lines = [];
20
+ const files = [];
21
+ for (const message of conversation.content) {
22
+ switch (message.role) {
23
+ case "system":
24
+ lines.push(`System: ${message.content}`);
25
+ break;
26
+ case "user":
27
+ for (const part of message.content) {
28
+ if (part.type === "text") {
29
+ lines.push(`User: ${part.text}`);
30
+ }
31
+ else {
32
+ lines.push(`User attached ${nameOf(part)}.`);
33
+ files.push(filePartOf(part));
34
+ }
35
+ }
36
+ break;
37
+ case "assistant":
38
+ for (const part of message.content) {
39
+ switch (part.type) {
40
+ case "text":
41
+ lines.push(`Assistant: ${part.text}`);
42
+ break;
43
+ case "file":
44
+ lines.push(`Assistant wrote ${nameOf(part)}.`);
45
+ break;
46
+ case "tool-call":
47
+ lines.push(`Assistant called the tool ${part.name} with ${JSON.stringify(part.params)}.`);
48
+ break;
49
+ case "tool-result":
50
+ lines.push(resultLineOf(part));
51
+ break;
52
+ // Reasoning was the model's own, and an approval request is answered by a result.
53
+ case "reasoning":
54
+ case "tool-approval-request":
55
+ break;
56
+ }
57
+ }
58
+ break;
59
+ case "tool":
60
+ for (const part of message.content) {
61
+ if (part.type === "tool-result")
62
+ lines.push(resultLineOf(part));
63
+ }
64
+ break;
65
+ }
66
+ }
67
+ const text = ["This conversation continues one held earlier, which went as follows.", "", ...lines].join("\n");
68
+ return [{ type: "text", text, synthetic: true }, ...files];
69
+ };
70
+ const resultLineOf = (part) => `The tool ${part.name} ${part.isFailure ? "failed with" : "returned"} ${typeof part.result === "string" ? part.result : JSON.stringify(part.result)}.`;
71
+ const nameOf = (part) => part.fileName === undefined ? `a file of type ${part.mediaType}` : `the file ${part.fileName}`;
72
+ /**
73
+ * A file as opencode 1 takes it, by URL: a URL as it is, and data, or a string of data in base64,
74
+ * as a `data:` URL.
75
+ */
76
+ const filePartOf = (part) => {
77
+ const { data, mediaType } = part;
78
+ const url = data instanceof URL
79
+ ? data.href
80
+ : typeof data === "string"
81
+ ? /^(data|https?):/.test(data)
82
+ ? data
83
+ : `data:${mediaType};base64,${data}`
84
+ : `data:${mediaType};base64,${Base64.encode(data)}`;
85
+ return {
86
+ type: "file",
87
+ mime: mediaType,
88
+ url,
89
+ ...(part.fileName === undefined ? {} : { filename: part.fileName })
90
+ };
91
+ };
92
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../../src/internal/bridge/v1/prompt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAA;AAGhD,8FAA8F;AAC9F,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAA2B,EAA6B,EAAE,CACtF,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAE9G;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,YAA2B,EAA6B,EAAE;IAC5F,IAAI,YAAY,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IAChD,MAAM,KAAK,GAAkB,EAAE,CAAA;IAC/B,MAAM,KAAK,GAAsB,EAAE,CAAA;IACnC,KAAK,MAAM,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,CAAC;QAC3C,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;YACrB,KAAK,QAAQ;gBACX,KAAK,CAAC,IAAI,CAAC,WAAW,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;gBACxC,MAAK;YACP,KAAK,MAAM;gBACT,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC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M,CAAC,IAAI,CAAC,EAAE,CAAA;IACzD,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,SAAS;QACf,GAAG;QACH,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;KACpE,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * A session of opencode 1's session API, as the driver runs it: an opencode session in the
3
+ * session's directory. A turn is a prompt to it, with the turn's instructions as its system prompt,
4
+ * the schema of an answer in JSON, the files of the prompt, and the turn's model; `Turn`
5
+ * translates the events opencode publishes for the turn as they happen. A session that starts
6
+ * with a conversation from another agent has it written into the session first, as `Prompt`
7
+ * writes it.
8
+ *
9
+ * The host's tools reach opencode through the bridge's `HostToolRelay`, as `HostTools` lists them,
10
+ * and opencode names them `host_<tool>`: the relay streams their calls, which the host answers with
11
+ * `submitToolResult`. A tool of opencode's own that asks
12
+ * permission waits for `approve`. `compact` asks opencode to summarize the conversation, which it
13
+ * does without instructions.
14
+ */
15
+ import { type HostToolRelay } from "@amends-dev/harness";
16
+ import type * as Driver from "../driver.ts";
17
+ /**
18
+ * The name opencode gives the host's tool `name`: the MCP server's name and the tool's, each with
19
+ * the characters MCP's names leave out replaced.
20
+ */
21
+ export declare const hostToolName: (name: string) => string;
22
+ /**
23
+ * The function that creates sessions as `Driver.CreateSession` does, each with a session of
24
+ * `relay` for the host's tools: a new opencode session, or the one its `agentState` names, when
25
+ * opencode still has it.
26
+ */
27
+ export declare const makeCreateSession: (relay: HostToolRelay.HostToolRelay["Service"]) => Driver.CreateSession;
28
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../../src/internal/bridge/v1/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAA6B,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAQnF,OAAO,KAAK,KAAK,MAAM,MAAM,cAAc,CAAA;AAQ3C;;;GAGG;AACH,eAAO,MAAM,YAAY,SAAU,MAAM,WAA8D,CAAA;AAOvG;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,UACpB,aAAa,CAAC,aAAa,CAAC,SAAS,CAAC,KAAG,MAAM,CAAC,aA2JpD,CAAA"}
@@ -0,0 +1,188 @@
1
+ /**
2
+ * A session of opencode 1's session API, as the driver runs it: an opencode session in the
3
+ * session's directory. A turn is a prompt to it, with the turn's instructions as its system prompt,
4
+ * the schema of an answer in JSON, the files of the prompt, and the turn's model; `Turn`
5
+ * translates the events opencode publishes for the turn as they happen. A session that starts
6
+ * with a conversation from another agent has it written into the session first, as `Prompt`
7
+ * writes it.
8
+ *
9
+ * The host's tools reach opencode through the bridge's `HostToolRelay`, as `HostTools` lists them,
10
+ * and opencode names them `host_<tool>`: the relay streams their calls, which the host answers with
11
+ * `submitToolResult`. A tool of opencode's own that asks
12
+ * permission waits for `approve`. `compact` asks opencode to summarize the conversation, which it
13
+ * does without instructions.
14
+ */
15
+ import { HarnessError } from "@amends-dev/harness";
16
+ import * as Effect from "effect/Effect";
17
+ import * as FileSystem from "effect/FileSystem";
18
+ import * as Ref from "effect/Ref";
19
+ import * as Schedule from "effect/Schedule";
20
+ import * as Schema from "effect/Schema";
21
+ import * as Stream from "effect/Stream";
22
+ import * as HostTools from "../hostTools.js";
23
+ import * as Server from "../server.js";
24
+ import * as Api from "./api.js";
25
+ import { isTextPart } from "./event.js";
26
+ import { conversationPartsOf, promptPartsOf } from "./prompt.js";
27
+ import * as Turn from "./turn.js";
28
+ /**
29
+ * The name opencode gives the host's tool `name`: the MCP server's name and the tool's, each with
30
+ * the characters MCP's names leave out replaced.
31
+ */
32
+ export const hostToolName = (name) => `${HostTools.serverName}_${name.replace(/[^\w-]/g, "_")}`;
33
+ /** What `state` returns, for `createSession` to take back. */
34
+ const State = Schema.Struct({ sessionID: Schema.String });
35
+ const StateJson = Schema.toCodecJson(State);
36
+ /**
37
+ * The function that creates sessions as `Driver.CreateSession` does, each with a session of
38
+ * `relay` for the host's tools: a new opencode session, or the one its `agentState` names, when
39
+ * opencode still has it.
40
+ */
41
+ export const makeCreateSession = (relay) => (server, options, sessionOptions) => Effect.gen(function* () {
42
+ const api = Api.make(server, sessionOptions.directory);
43
+ const harnessError = (reason, cause) => Server.harnessError(server.agent, reason, cause);
44
+ // opencode may have lost the session, as when the sandbox lost its data, and then starts one
45
+ // from the conversation.
46
+ const saved = yield* readState(harnessError, sessionOptions.agentState);
47
+ const kept = saved !== undefined && (yield* api.hasSession(saved.sessionID)) ? saved : undefined;
48
+ const sessionID = kept?.sessionID ?? (yield* createOpencodeSession(api, messageModelOf(options.model), sessionOptions.history));
49
+ const relaySession = yield* relay.open(sessionOptions.id);
50
+ const listHostTools = yield* HostTools.makeLister(relay.url, relaySession, {
51
+ add: (mcpServer) => api.addMcpServer(HostTools.serverName, mcpServer),
52
+ reconnect: api.reconnectMcpServer(HostTools.serverName),
53
+ disconnect: api.disconnectMcpServer(HostTools.serverName)
54
+ });
55
+ // opencode reports the files a tool changed by their real paths.
56
+ const fs = yield* FileSystem.FileSystem;
57
+ const realDirectory = yield* fs
58
+ .realPath(sessionOptions.directory)
59
+ .pipe(Effect.orElseSucceed(() => sessionOptions.directory));
60
+ /** What opencode is prompted with for a turn with `turnOptions`. */
61
+ const promptOptionsOf = Effect.fnUntraced(function* (turnOptions) {
62
+ const model = yield* modelNamed(harnessError, options, turnOptions.model);
63
+ const { responseFormat } = turnOptions;
64
+ const prompt = {
65
+ model: messageModelOf(model),
66
+ ...(model.variant === undefined ? {} : { variant: model.variant }),
67
+ ...(turnOptions.instructions === undefined ? {} : { system: turnOptions.instructions }),
68
+ ...(responseFormat.type === "json" ? { format: { type: "json_schema", schema: responseFormat.schema } } : {}),
69
+ // A question to the user would wait for an answer no host gives.
70
+ tools: { question: false },
71
+ parts: promptPartsOf(turnOptions.prompt)
72
+ };
73
+ return prompt;
74
+ });
75
+ /**
76
+ * Runs a turn, streaming its parts until its `finish`, with the calls the relay streams of
77
+ * the host's tools. A stream that ends before the turn finishes, as when the bridge aborts the
78
+ * turn, aborts the turn in opencode.
79
+ */
80
+ const promptTurn = (turnOptions) => Stream.unwrap(Effect.gen(function* () {
81
+ const prompt = yield* promptOptionsOf(turnOptions);
82
+ const finished = yield* Ref.make(false);
83
+ // Aborting a session that runs no turn does nothing, so this holds from before opencode
84
+ // takes the prompt.
85
+ yield* Effect.addFinalizer(() => Effect.flatMap(Ref.get(finished), (done) => (done ? Effect.void : Effect.ignore(api.abort(sessionID)))));
86
+ const hostCalls = turnOptions.tools.length === 0 ? Stream.empty : yield* relaySession.offerTools(turnOptions.tools);
87
+ yield* listHostTools(turnOptions.tools);
88
+ // The turn's events are published only to subscriptions made before them.
89
+ const events = yield* api.subscribe;
90
+ yield* api.prompt(sessionID, prompt);
91
+ const translated = yield* Ref.make(Turn.initial({
92
+ sessionID,
93
+ directory: realDirectory,
94
+ hostTools: new Set(turnOptions.tools.map((tool) => hostToolName(tool.name)))
95
+ }));
96
+ const ended = harnessError(new HarnessError.UnavailableError({
97
+ description: "opencode's events ended before the turn did"
98
+ }));
99
+ const turnParts = events.pipe(Stream.tap((event) => event.type === "question.asked" ? Effect.ignore(api.rejectQuestion(event.properties.id)) : Effect.void), Stream.concat(Stream.fail(ended)), Stream.mapEffect((event) => Ref.modify(translated, (turn) => {
100
+ const [next, parts] = Turn.translate(turn, event);
101
+ return [parts, next];
102
+ })), Stream.flattenIterable, Stream.takeUntil((part) => part.type === "finish"), Stream.tap((part) => (part.type === "finish" ? Ref.set(finished, true) : Effect.void)));
103
+ return Stream.merge(turnParts, hostCalls, { haltStrategy: "left" });
104
+ }));
105
+ /**
106
+ * Asks opencode to summarize the conversation, on the model of its last step, and waits for
107
+ * the summary it writes as a message of the session.
108
+ */
109
+ const compact = Effect.fnUntraced(function* (instructions) {
110
+ if (instructions !== undefined && instructions.trim() !== "") {
111
+ return yield* harnessError(new HarnessError.UnsupportedError({
112
+ description: "opencode 1 summarizes a conversation without instructions"
113
+ }));
114
+ }
115
+ const before = yield* api.messages(sessionID);
116
+ const lastStep = before.findLast(({ info }) => info.role === "assistant")?.info;
117
+ const model = lastStep?.role === "assistant"
118
+ ? { providerID: lastStep.providerID, modelID: lastStep.modelID }
119
+ : messageModelOf(options.model);
120
+ const summariesBefore = before.filter(({ info }) => isSummary(info)).length;
121
+ yield* api.summarize(sessionID, model);
122
+ const summary = yield* api.messages(sessionID).pipe(Effect.map((messages) => messages.filter(({ info }) => isSummary(info))[summariesBefore]), Effect.repeat({
123
+ until: (written) => written !== undefined && written.info.role === "assistant" && written.info.time.completed !== undefined,
124
+ schedule: Schedule.spaced("1 second").pipe(Schedule.upTo({ duration: "10 minutes" }))
125
+ }));
126
+ if (summary === undefined || summary.info.role !== "assistant") {
127
+ return yield* harnessError(new HarnessError.UnavailableError({
128
+ description: "opencode did not summarize the conversation within 10 minutes"
129
+ }));
130
+ }
131
+ if (summary.info.error !== undefined) {
132
+ return yield* harnessError(new HarnessError.UnknownError({
133
+ description: `opencode failed to summarize the conversation: ${summary.info.error.data?.message ?? summary.info.error.name}`
134
+ }));
135
+ }
136
+ const text = summary.parts.flatMap((part) => (isTextPart(part) ? [part.text] : []));
137
+ return {
138
+ type: "compaction",
139
+ trigger: "manual",
140
+ summary: text.join("\n")
141
+ };
142
+ });
143
+ const session = {
144
+ keptConversation: kept !== undefined,
145
+ promptTurn,
146
+ submitToolResult: relaySession.submitToolResult,
147
+ approve: ({ approvalId, approved, reason }) => api.replyPermission(approvalId, approved ? "once" : "reject", approved ? undefined : reason),
148
+ compact,
149
+ state: Effect.orDie(Schema.encodeEffect(StateJson)({ sessionID })),
150
+ destroy: api.deleteSession(sessionID)
151
+ };
152
+ return session;
153
+ });
154
+ /**
155
+ * A new opencode session holding `history`, which the model reads with the session's first
156
+ * prompt. A session the history could not be written into is deleted.
157
+ */
158
+ const createOpencodeSession = Effect.fnUntraced(function* (api, model, history) {
159
+ const sessionID = yield* api.createSession;
160
+ const parts = conversationPartsOf(history);
161
+ if (parts.length > 0) {
162
+ yield* api
163
+ .addMessage(sessionID, model, parts)
164
+ .pipe(Effect.onError(() => Effect.ignore(api.deleteSession(sessionID))));
165
+ }
166
+ return sessionID;
167
+ });
168
+ const isSummary = (info) => info.role === "assistant" && info.summary === true;
169
+ /** A model as opencode 1's prompts name it, without the variant, which a prompt gives apart. */
170
+ const messageModelOf = (model) => ({
171
+ providerID: model.providerID,
172
+ modelID: model.id
173
+ });
174
+ /** The model a turn that names `name` runs on, failing for a name the options do not give. */
175
+ const modelNamed = (harnessError, options, name) => {
176
+ if (name === undefined)
177
+ return Effect.succeed(options.model);
178
+ const model = Object.hasOwn(options.models, name) ? options.models[name] : undefined;
179
+ if (model !== undefined)
180
+ return Effect.succeed(model);
181
+ const description = `The opencode agent has no model named ${name}`;
182
+ return Effect.fail(harnessError(new HarnessError.UnsupportedError({ description })));
183
+ };
184
+ /** The state `createSession` was given, if any, as the state `state` returned. */
185
+ const readState = (harnessError, json) => Schema.decodeEffect(Schema.UndefinedOr(StateJson))(json).pipe(Effect.mapError((cause) => harnessError(new HarnessError.AgentContractError({
186
+ description: `opencode cannot read the state it was given: ${cause.message}`
187
+ }), cause)));
188
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../../src/internal/bridge/v1/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAe,YAAY,EAAsB,MAAM,qBAAqB,CAAA;AAEnF,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,GAAG,MAAM,YAAY,CAAA;AACjC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KA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