@astrosheep/keiyaku 4.0.0 → 4.0.1
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.
- package/README.md +2 -9
- package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +2 -2
- package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +4 -4
- package/build/integrations/marketplace/plugins/keiyaku/opencode.js +2 -2
- package/build/integrations/marketplace/plugins/keiyaku/package.json +2 -2
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +11 -3
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +9 -6
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +94 -0
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/agents/openai.yaml +4 -0
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-task/SKILL.md +41 -6
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +162 -45
- package/build/src/akuma/akuma.d.ts +33 -25
- package/build/src/akuma/akuma.js +93 -61
- package/build/src/akuma/archetype.d.ts +8 -0
- package/build/src/akuma/archetype.js +28 -9
- package/build/src/akuma/body.js +196 -84
- package/build/src/akuma/coordinate.d.ts +9 -0
- package/build/src/akuma/coordinate.js +22 -0
- package/build/src/akuma/heart/facts.d.ts +67 -15
- package/build/src/akuma/heart/facts.js +3 -3
- package/build/src/akuma/heart/index.d.ts +41 -29
- package/build/src/akuma/heart/index.js +72 -193
- package/build/src/akuma/heart/rows.d.ts +30 -53
- package/build/src/akuma/heart/rows.js +91 -111
- package/build/src/akuma/heart/schema.d.ts +1 -1
- package/build/src/akuma/heart/schema.js +55 -8
- package/build/src/akuma/heart/storage.d.ts +33 -0
- package/build/src/akuma/heart/storage.js +164 -0
- package/build/src/akuma/heart/tells.d.ts +12 -0
- package/build/src/akuma/heart/tells.js +79 -0
- package/build/src/akuma/heart/timeline.d.ts +15 -0
- package/build/src/akuma/heart/timeline.js +86 -0
- package/build/src/akuma/index.d.ts +4 -2
- package/build/src/akuma/index.js +1 -1
- package/build/src/akuma/projection.d.ts +97 -0
- package/build/src/akuma/projection.js +145 -0
- package/build/src/akuma/provider.d.ts +57 -11
- package/build/src/akuma/provider.js +57 -37
- package/build/src/akuma/providers/{claude.d.ts → claude/events.d.ts} +9 -41
- package/build/src/akuma/providers/claude/events.js +185 -0
- package/build/src/akuma/providers/claude/index.d.ts +46 -0
- package/build/src/akuma/providers/claude/index.js +265 -0
- package/build/src/akuma/providers/claude/input.d.ts +13 -0
- package/build/src/akuma/providers/claude/input.js +109 -0
- package/build/src/akuma/providers/codex-app-server/events.d.ts +1 -1
- package/build/src/akuma/providers/codex-app-server/events.js +12 -12
- package/build/src/akuma/providers/codex-app-server/index.d.ts +13 -11
- package/build/src/akuma/providers/codex-app-server/index.js +73 -22
- package/build/src/akuma/providers/index.js +22 -8
- package/build/src/akuma/providers/opencode-sdk/events.d.ts +48 -0
- package/build/src/akuma/providers/opencode-sdk/events.js +116 -0
- package/build/src/akuma/providers/opencode-sdk/index.d.ts +32 -0
- package/build/src/akuma/providers/opencode-sdk/index.js +203 -0
- package/build/src/akuma/providers/opencode-sdk/session.d.ts +41 -0
- package/build/src/akuma/providers/opencode-sdk/session.js +62 -0
- package/build/src/akuma/providers/pi/events.d.ts +33 -0
- package/build/src/akuma/providers/pi/events.js +128 -0
- package/build/src/akuma/providers/pi/index.d.ts +11 -0
- package/build/src/akuma/providers/pi/index.js +162 -0
- package/build/src/akuma/requests.d.ts +1 -0
- package/build/src/akuma/requests.js +5 -2
- package/build/src/alias/index.d.ts +4 -3
- package/build/src/alias/index.js +2 -3
- package/build/src/body/render.js +2 -1
- package/build/src/body/shape.js +7 -1
- package/build/src/body/verification.js +19 -4
- package/build/src/cli/accepted.d.ts +2 -0
- package/build/src/cli/accepted.js +2 -1
- package/build/src/cli/commands/akuma-invoke.d.ts +42 -18
- package/build/src/cli/commands/akuma-invoke.js +94 -50
- package/build/src/cli/commands/akuma.d.ts +15 -7
- package/build/src/cli/commands/akuma.js +94 -56
- package/build/src/cli/commands/contract.d.ts +142 -0
- package/build/src/cli/commands/contract.js +14 -0
- package/build/src/cli/commands/install.js +2 -0
- package/build/src/cli/commands/task-invoke.d.ts +3 -1
- package/build/src/cli/commands/task-invoke.js +27 -2
- package/build/src/cli/commands/task.js +2 -2
- package/build/src/cli/invoke.d.ts +6 -1
- package/build/src/cli/invoke.js +241 -43
- package/build/src/cli/main.js +20 -1
- package/build/src/cli/parse.d.ts +13 -116
- package/build/src/cli/parse.js +51 -78
- package/build/src/cli/render/akuma-tool.d.ts +2 -0
- package/build/src/cli/render/akuma-tool.js +6 -2
- package/build/src/cli/render/akuma.d.ts +2 -1
- package/build/src/cli/render/akuma.js +157 -217
- package/build/src/cli/render/catalog.d.ts +2 -0
- package/build/src/cli/render/catalog.js +16 -0
- package/build/src/cli/render/contract.d.ts +1 -1
- package/build/src/cli/render/contract.js +38 -5
- package/build/src/cli/render/kanshi.js +53 -5
- package/build/src/cli/render/refusal.js +17 -0
- package/build/src/cli/render/terminal.d.ts +13 -0
- package/build/src/cli/render/terminal.js +75 -0
- package/build/src/cli/render/text.js +5 -0
- package/build/src/cli/result.d.ts +15 -3
- package/build/src/contract-worktree.d.ts +43 -0
- package/build/src/contract-worktree.js +213 -0
- package/build/src/coordination/durable-file.d.ts +3 -0
- package/build/src/coordination/durable-file.js +44 -1
- package/build/src/core/facts/codec.js +23 -4
- package/build/src/core/facts/eligibility.d.ts +1 -10
- package/build/src/core/facts/eligibility.js +0 -49
- package/build/src/core/facts/observation.d.ts +3 -0
- package/build/src/core/facts/observation.js +12 -0
- package/build/src/core/facts/types.d.ts +10 -3
- package/build/src/core/subject.js +2 -2
- package/build/src/core/verbs/amend.js +12 -16
- package/build/src/core/verbs/bind.js +2 -16
- package/build/src/core/verbs/deliver.js +20 -4
- package/build/src/core/verbs/placement.js +3 -8
- package/build/src/dispatch/index.d.ts +3 -1
- package/build/src/dispatch/index.js +14 -5
- package/build/src/duration.d.ts +10 -0
- package/build/src/duration.js +22 -0
- package/build/src/git/admission.d.ts +2 -2
- package/build/src/git/admission.js +26 -16
- package/build/src/git/hooks.d.ts +15 -0
- package/build/src/git/hooks.js +57 -5
- package/build/src/git/identity.d.ts +5 -1
- package/build/src/git/identity.js +23 -4
- package/build/src/git/integration.d.ts +49 -0
- package/build/src/git/integration.js +214 -0
- package/build/src/git/observe.d.ts +25 -13
- package/build/src/git/observe.js +175 -72
- package/build/src/git/read-observation.d.ts +41 -0
- package/build/src/git/read-observation.js +361 -0
- package/build/src/git/reconcile.d.ts +15 -5
- package/build/src/git/reconcile.js +238 -85
- package/build/src/git/repository.d.ts +19 -4
- package/build/src/git/repository.js +77 -43
- package/build/src/git/scratch.d.ts +13 -0
- package/build/src/git/scratch.js +66 -0
- package/build/src/git/target-placement.d.ts +56 -0
- package/build/src/git/target-placement.js +255 -0
- package/build/src/git/tender.d.ts +48 -0
- package/build/src/git/tender.js +82 -0
- package/build/src/git/terminal-seal.d.ts +24 -0
- package/build/src/git/terminal-seal.js +87 -0
- package/build/src/git/tree.d.ts +2 -2
- package/build/src/git/tree.js +4 -0
- package/build/src/git/workspace.d.ts +21 -0
- package/build/src/git/workspace.js +104 -0
- package/build/src/identity/selector.d.ts +6 -0
- package/build/src/identity/selector.js +19 -0
- package/build/src/index.d.ts +4 -2
- package/build/src/index.js +2 -1
- package/build/src/kanshi/index.d.ts +1 -1
- package/build/src/kanshi/read.d.ts +5 -2
- package/build/src/kanshi/read.js +154 -45
- package/build/src/kanshi/report.d.ts +31 -6
- package/build/src/kanshi/select.js +1 -1
- package/build/src/library/address.d.ts +48 -0
- package/build/src/library/address.js +134 -0
- package/build/src/library/akuma-creation.d.ts +10 -6
- package/build/src/library/akuma-creation.js +12 -11
- package/build/src/library/bind.d.ts +21 -0
- package/build/src/library/bind.js +56 -0
- package/build/src/library/catalog.d.ts +58 -0
- package/build/src/library/catalog.js +72 -0
- package/build/src/library/configuration.d.ts +6 -15
- package/build/src/library/configuration.js +14 -17
- package/build/src/library/contract.d.ts +21 -46
- package/build/src/library/contract.js +193 -183
- package/build/src/library/delivery.d.ts +23 -0
- package/build/src/library/delivery.js +21 -0
- package/build/src/library/fleet.d.ts +65 -0
- package/build/src/library/fleet.js +189 -0
- package/build/src/library/input.d.ts +3 -0
- package/build/src/library/input.js +19 -0
- package/build/src/library/keiyaku.d.ts +16 -2
- package/build/src/library/keiyaku.js +11 -1
- package/build/src/library/mutation.d.ts +38 -0
- package/build/src/library/mutation.js +39 -0
- package/build/src/library/refusal.d.ts +21 -0
- package/build/src/library/refusal.js +29 -0
- package/build/src/library/region.d.ts +2 -1
- package/build/src/library/region.js +3 -3
- package/build/src/library/repo.d.ts +4 -1
- package/build/src/library/repo.js +31 -16
- package/build/src/protocol/attempt.d.ts +16 -3
- package/build/src/protocol/attempt.js +39 -8
- package/build/src/protocol/bind.d.ts +9 -2
- package/build/src/protocol/bind.js +47 -39
- package/build/src/protocol/intent.d.ts +42 -18
- package/build/src/protocol/intent.js +36 -75
- package/build/src/protocol/operations.d.ts +93 -35
- package/build/src/protocol/operations.js +235 -123
- package/build/src/protocol/outcome.d.ts +7 -2
- package/build/src/protocol/outcome.js +9 -3
- package/build/src/protocol/placement.d.ts +30 -0
- package/build/src/protocol/placement.js +114 -0
- package/build/src/protocol/read/audit.d.ts +9 -3
- package/build/src/protocol/read/audit.js +25 -9
- package/build/src/protocol/read/documents.d.ts +2 -2
- package/build/src/protocol/read/documents.js +4 -4
- package/build/src/protocol/read/status.d.ts +11 -5
- package/build/src/protocol/read/status.js +28 -15
- package/build/src/protocol/run.d.ts +49 -7
- package/build/src/protocol/run.js +53 -25
- package/build/src/runtime/proc/line-rpc.d.ts +1 -0
- package/build/src/runtime/proc/line-rpc.js +21 -0
- package/build/src/runtime/proc/run.d.ts +18 -2
- package/build/src/runtime/proc/run.js +34 -8
- package/build/src/settings.d.ts +6 -0
- package/build/src/settings.js +29 -14
- package/build/src/settlement/fence.d.ts +9 -0
- package/build/src/settlement/fence.js +23 -0
- package/build/src/settlement/holder.d.ts +25 -4
- package/build/src/settlement/holder.js +102 -28
- package/build/src/settlement/settle.d.ts +8 -0
- package/build/src/settlement/settle.js +102 -28
- package/build/src/task/board.d.ts +20 -2
- package/build/src/task/board.js +11 -1
- package/build/src/task/compose.d.ts +2 -2
- package/build/src/task/compose.js +2 -2
- package/build/src/task/context.js +2 -7
- package/build/src/task/index.d.ts +9 -9
- package/build/src/task/index.js +15 -12
- package/build/src/task/operations.d.ts +31 -12
- package/build/src/task/operations.js +8 -4
- package/build/src/task/store.d.ts +4 -6
- package/build/src/task/store.js +3 -3
- package/build/src/verification/declaration.d.ts +1 -0
- package/build/src/verification/execution.d.ts +49 -0
- package/build/src/verification/execution.js +104 -0
- package/build/src/world.d.ts +13 -0
- package/build/src/world.js +103 -0
- package/package.json +7 -4
- package/build/src/akuma/activity.d.ts +0 -66
- package/build/src/akuma/activity.js +0 -139
- package/build/src/akuma/providers/claude.js +0 -305
- package/build/src/context-root.d.ts +0 -4
- package/build/src/context-root.js +0 -15
- package/build/src/git/delivery.d.ts +0 -20
- package/build/src/git/delivery.js +0 -109
- package/build/src/git/verification.d.ts +0 -14
- package/build/src/git/verification.js +0 -56
- package/build/src/verification/producer.d.ts +0 -23
- package/build/src/verification/producer.js +0 -54
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { decodeResumeCoordinate, encodeResumeCoordinate } from "./coordinate.js";
|
|
1
2
|
export const AKUMA_REQUESTS_ENV = "AKUMA_REQUESTS";
|
|
2
3
|
export const AGENT_EVENT_TEXT_LIMIT = 16_384;
|
|
3
4
|
export const AGENT_THOUGHT_TEXT_LIMIT = 4_000;
|
|
@@ -14,6 +15,7 @@ function object(value) {
|
|
|
14
15
|
? value
|
|
15
16
|
: null;
|
|
16
17
|
}
|
|
18
|
+
export { decodeResumeCoordinate, encodeResumeCoordinate };
|
|
17
19
|
function optionText(options, field, blank) {
|
|
18
20
|
const selected = options[field];
|
|
19
21
|
if (selected === undefined)
|
|
@@ -106,27 +108,34 @@ function decodeToolResult(value) {
|
|
|
106
108
|
};
|
|
107
109
|
}
|
|
108
110
|
function decodeToolEvent(event) {
|
|
111
|
+
if (event.truncated !== undefined && event.truncated !== true)
|
|
112
|
+
return null;
|
|
109
113
|
if (typeof event.id !== "string" || typeof event.name !== "string")
|
|
110
114
|
return null;
|
|
111
115
|
const call = decodeToolCall(event.call);
|
|
112
116
|
if (call !== null && event.phase === "started" && event.result === undefined) {
|
|
113
|
-
return { type: "tool", phase: "started", id: event.id, name: event.name, call
|
|
117
|
+
return { type: "tool", phase: "started", id: event.id, name: event.name, call,
|
|
118
|
+
...(event.truncated === true ? { truncated: true } : {}) };
|
|
114
119
|
}
|
|
115
120
|
const result = decodeToolResult(event.result);
|
|
116
121
|
if (call !== null && event.phase === "completed" && result !== null) {
|
|
117
|
-
return { type: "tool", phase: "completed", id: event.id, name: event.name, call, result
|
|
122
|
+
return { type: "tool", phase: "completed", id: event.id, name: event.name, call, result,
|
|
123
|
+
...(event.truncated === true ? { truncated: true } : {}) };
|
|
118
124
|
}
|
|
119
125
|
return null;
|
|
120
126
|
}
|
|
121
127
|
function decodeTypedEvent(type, event) {
|
|
128
|
+
if (type !== "session" && event.truncated !== undefined && event.truncated !== true)
|
|
129
|
+
return null;
|
|
130
|
+
const truncated = event.truncated === true ? { truncated: true } : {};
|
|
122
131
|
switch (type) {
|
|
123
132
|
case "assistant":
|
|
124
|
-
case "thought": return typeof event.text === "string" ? { type, text: event.text } : null;
|
|
125
|
-
case "note": return typeof event.text === "string" ? { type, text: event.text } : null;
|
|
126
|
-
case "unknown": return typeof event.kind === "string" ? { type, kind: event.kind } : null;
|
|
133
|
+
case "thought": return typeof event.text === "string" ? { type, text: event.text, ...truncated } : null;
|
|
134
|
+
case "note": return typeof event.text === "string" ? { type, text: event.text, ...truncated } : null;
|
|
135
|
+
case "unknown": return typeof event.kind === "string" ? { type, kind: event.kind, ...truncated } : null;
|
|
127
136
|
case "session": {
|
|
128
|
-
const coordinate =
|
|
129
|
-
return
|
|
137
|
+
const coordinate = decodeResumeCoordinate(event.coordinate);
|
|
138
|
+
return coordinate === null ? null : { type, coordinate };
|
|
130
139
|
}
|
|
131
140
|
case "tool": return decodeToolEvent(event);
|
|
132
141
|
default: return type;
|
|
@@ -143,50 +152,61 @@ export function decodeAgentEvent(value) {
|
|
|
143
152
|
}
|
|
144
153
|
function boundedToolCall(call) {
|
|
145
154
|
switch (call.kind) {
|
|
146
|
-
case "run": return { kind: call.kind, command: boundedEventText(call.command) };
|
|
147
|
-
case "read": return { kind: call.kind, path: boundedEventText(call.path) };
|
|
148
|
-
case "search": return { kind: call.kind, query: boundedEventText(call.query) };
|
|
155
|
+
case "run": return { value: { kind: call.kind, command: boundedEventText(call.command) }, truncated: call.command.length > AGENT_EVENT_TEXT_LIMIT };
|
|
156
|
+
case "read": return { value: { kind: call.kind, path: boundedEventText(call.path) }, truncated: call.path.length > AGENT_EVENT_TEXT_LIMIT };
|
|
157
|
+
case "search": return { value: { kind: call.kind, query: boundedEventText(call.query) }, truncated: call.query.length > AGENT_EVENT_TEXT_LIMIT };
|
|
149
158
|
case "fileChange": return {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
...change,
|
|
153
|
-
|
|
154
|
-
|
|
159
|
+
value: {
|
|
160
|
+
kind: call.kind,
|
|
161
|
+
changes: call.changes.map((change) => ({ ...change, path: boundedEventText(change.path) })),
|
|
162
|
+
},
|
|
163
|
+
truncated: call.changes.some((change) => change.path.length > AGENT_EVENT_TEXT_LIMIT),
|
|
155
164
|
};
|
|
156
|
-
case "other": return { kind: call.kind, display: boundedEventText(call.display) };
|
|
165
|
+
case "other": return { value: { kind: call.kind, display: boundedEventText(call.display) }, truncated: call.display.length > AGENT_EVENT_TEXT_LIMIT };
|
|
157
166
|
default: return call;
|
|
158
167
|
}
|
|
159
168
|
}
|
|
160
169
|
function boundedToolResult(result) {
|
|
161
170
|
return {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
171
|
+
value: {
|
|
172
|
+
status: result.status,
|
|
173
|
+
...(result.message === undefined ? {} : { message: boundedEventText(result.message) }),
|
|
174
|
+
...(result.exitCode === undefined ? {} : { exitCode: result.exitCode }),
|
|
175
|
+
},
|
|
176
|
+
truncated: result.message !== undefined && result.message.length > AGENT_EVENT_TEXT_LIMIT,
|
|
165
177
|
};
|
|
166
178
|
}
|
|
167
179
|
export function encodeAgentEvent(event) {
|
|
180
|
+
const marked = (value, changed) => ({
|
|
181
|
+
...value,
|
|
182
|
+
...(changed || ("truncated" in event && event.truncated === true) ? { truncated: true } : {}),
|
|
183
|
+
});
|
|
168
184
|
switch (event.type) {
|
|
169
|
-
case "session": return { type: event.type, coordinate:
|
|
170
|
-
case "assistant": return { type: event.type, text: boundedEventText(event.text) };
|
|
171
|
-
case "thought": return { type: event.type, text: boundedThoughtText(event.text) };
|
|
172
|
-
case "note": return { type: event.type, text: boundedEventText(event.text) };
|
|
173
|
-
case "unknown": return { type: event.type, kind: boundedEventText(event.kind) };
|
|
174
|
-
case "tool":
|
|
175
|
-
|
|
185
|
+
case "session": return { type: event.type, coordinate: encodeResumeCoordinate(event.coordinate) };
|
|
186
|
+
case "assistant": return marked({ type: event.type, text: boundedEventText(event.text) }, event.text.length > AGENT_EVENT_TEXT_LIMIT);
|
|
187
|
+
case "thought": return marked({ type: event.type, text: boundedThoughtText(event.text) }, event.text.length > AGENT_THOUGHT_TEXT_LIMIT);
|
|
188
|
+
case "note": return marked({ type: event.type, text: boundedEventText(event.text) }, event.text.length > AGENT_EVENT_TEXT_LIMIT);
|
|
189
|
+
case "unknown": return marked({ type: event.type, kind: boundedEventText(event.kind) }, event.kind.length > AGENT_EVENT_TEXT_LIMIT);
|
|
190
|
+
case "tool": {
|
|
191
|
+
const call = boundedToolCall(event.call);
|
|
192
|
+
const name = boundedEventText(event.name);
|
|
193
|
+
const result = event.phase === "completed" ? boundedToolResult(event.result) : undefined;
|
|
194
|
+
return marked(event.phase === "started" ? {
|
|
176
195
|
type: event.type,
|
|
177
196
|
id: event.id,
|
|
178
197
|
phase: event.phase,
|
|
179
|
-
name
|
|
180
|
-
call:
|
|
198
|
+
name,
|
|
199
|
+
call: call.value,
|
|
181
200
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
201
|
+
: {
|
|
202
|
+
type: event.type,
|
|
203
|
+
id: event.id,
|
|
204
|
+
phase: event.phase,
|
|
205
|
+
name,
|
|
206
|
+
call: call.value,
|
|
207
|
+
result: result.value,
|
|
208
|
+
}, name !== event.name || call.truncated || result?.truncated === true);
|
|
209
|
+
}
|
|
190
210
|
default: return event;
|
|
191
211
|
}
|
|
192
212
|
}
|
|
@@ -197,7 +217,7 @@ export function boundedThoughtText(value) {
|
|
|
197
217
|
return value.slice(0, AGENT_THOUGHT_TEXT_LIMIT);
|
|
198
218
|
}
|
|
199
219
|
export function noteEvent(note) {
|
|
200
|
-
return { type: "note", text:
|
|
220
|
+
return { type: "note", text: note.replace(/\s+/g, " ").trim() };
|
|
201
221
|
}
|
|
202
222
|
export function unknownEvent(kind) {
|
|
203
223
|
return { type: "unknown", kind };
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { SDKMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import { AgentEventChannel, type ToolCall } from "../../provider.js";
|
|
3
|
+
export type ClaudeObservationState = {
|
|
4
|
+
tools: Map<string, Readonly<{
|
|
5
|
+
name: string;
|
|
6
|
+
call: ToolCall;
|
|
7
|
+
}>>;
|
|
8
|
+
};
|
|
3
9
|
export declare const CLAUDE_MESSAGE_DISPOSITIONS: {
|
|
4
10
|
readonly assistant: "assistant";
|
|
5
11
|
readonly auth_status: "auth";
|
|
@@ -43,42 +49,4 @@ export declare const CLAUDE_SYSTEM_DISPOSITIONS: {
|
|
|
43
49
|
readonly thinking_tokens: "drop";
|
|
44
50
|
readonly worker_shutting_down: "note";
|
|
45
51
|
};
|
|
46
|
-
export
|
|
47
|
-
query(input: Readonly<{
|
|
48
|
-
prompt: string;
|
|
49
|
-
options?: Options;
|
|
50
|
-
}>): Query;
|
|
51
|
-
forkSession?(sessionId: string, options: Readonly<{
|
|
52
|
-
dir: string;
|
|
53
|
-
upToMessageId: string;
|
|
54
|
-
}>): Promise<Readonly<{
|
|
55
|
-
sessionId: string;
|
|
56
|
-
}>>;
|
|
57
|
-
}>;
|
|
58
|
-
export declare function createClaudeProvider(load: () => Promise<ClaudeSdk>, execution?: Readonly<{
|
|
59
|
-
executable?: string;
|
|
60
|
-
env?: Readonly<Record<string, string>>;
|
|
61
|
-
}>): ProviderAdapter;
|
|
62
|
-
export declare const claudeProvider: Readonly<{
|
|
63
|
-
confinement(input: Readonly<{
|
|
64
|
-
cwd: string;
|
|
65
|
-
options: ProviderOptions;
|
|
66
|
-
}>): import("../index.js").Confinement;
|
|
67
|
-
admitOptions(options: ProviderOptions): import("../provider.js").ProviderOptionAdmission;
|
|
68
|
-
fork?(input: Readonly<{
|
|
69
|
-
session: import("../provider.js").ResumeCoordinate;
|
|
70
|
-
at: string;
|
|
71
|
-
cwd: string;
|
|
72
|
-
}>): Promise<Readonly<{
|
|
73
|
-
session: import("../provider.js").ResumeCoordinate;
|
|
74
|
-
}>>;
|
|
75
|
-
start(input: Readonly<{
|
|
76
|
-
prompt: string;
|
|
77
|
-
cwd: string;
|
|
78
|
-
options: ProviderOptions;
|
|
79
|
-
session?: import("../provider.js").ResumeCoordinate;
|
|
80
|
-
requests?: Readonly<{
|
|
81
|
-
dir: string;
|
|
82
|
-
}>;
|
|
83
|
-
}>): Promise<Drive>;
|
|
84
|
-
}>;
|
|
52
|
+
export declare function emitClaudeMessage(message: SDKMessage, events: AgentEventChannel, state: ClaudeObservationState): void;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { noteEvent, unknownEvent, } from "../../provider.js";
|
|
2
|
+
export const CLAUDE_MESSAGE_DISPOSITIONS = {
|
|
3
|
+
assistant: "assistant",
|
|
4
|
+
auth_status: "auth",
|
|
5
|
+
conversation_reset: "note",
|
|
6
|
+
prompt_suggestion: "drop",
|
|
7
|
+
rate_limit_event: "drop",
|
|
8
|
+
result: "terminal",
|
|
9
|
+
stream_event: "drop",
|
|
10
|
+
system: "system",
|
|
11
|
+
tool_progress: "drop",
|
|
12
|
+
tool_use_summary: "drop",
|
|
13
|
+
user: "tool-results",
|
|
14
|
+
};
|
|
15
|
+
export const CLAUDE_SYSTEM_DISPOSITIONS = {
|
|
16
|
+
api_retry: "note",
|
|
17
|
+
background_tasks_changed: "note",
|
|
18
|
+
commands_changed: "drop",
|
|
19
|
+
compact_boundary: "drop",
|
|
20
|
+
control_request_progress: "control-progress",
|
|
21
|
+
elicitation_complete: "drop",
|
|
22
|
+
files_persisted: "note",
|
|
23
|
+
hook_progress: "drop",
|
|
24
|
+
hook_response: "drop",
|
|
25
|
+
hook_started: "note",
|
|
26
|
+
informational: "note",
|
|
27
|
+
init: "drop",
|
|
28
|
+
local_command_output: "drop",
|
|
29
|
+
memory_recall: "drop",
|
|
30
|
+
mirror_error: "note",
|
|
31
|
+
model_refusal_fallback: "note",
|
|
32
|
+
model_refusal_no_fallback: "note",
|
|
33
|
+
notification: "note",
|
|
34
|
+
permission_denied: "note",
|
|
35
|
+
plugin_install: "note",
|
|
36
|
+
session_state_changed: "drop",
|
|
37
|
+
status: "note",
|
|
38
|
+
task_notification: "note",
|
|
39
|
+
task_progress: "note",
|
|
40
|
+
task_started: "note",
|
|
41
|
+
task_updated: "note",
|
|
42
|
+
thinking_tokens: "drop",
|
|
43
|
+
worker_shutting_down: "note",
|
|
44
|
+
};
|
|
45
|
+
function object(value) {
|
|
46
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
47
|
+
? value
|
|
48
|
+
: undefined;
|
|
49
|
+
}
|
|
50
|
+
function nonblank(value) {
|
|
51
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
52
|
+
}
|
|
53
|
+
function number(value) {
|
|
54
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
55
|
+
}
|
|
56
|
+
const CLAUDE_SYSTEM_NOTES = {
|
|
57
|
+
api_retry: (message) => {
|
|
58
|
+
const attempt = number(message.attempt);
|
|
59
|
+
const maximum = number(message.max_retries);
|
|
60
|
+
return attempt === undefined || maximum === undefined
|
|
61
|
+
? "Retrying request"
|
|
62
|
+
: `Retrying request ${attempt}/${maximum}`;
|
|
63
|
+
},
|
|
64
|
+
background_tasks_changed: (message) => `Background tasks: ${Array.isArray(message.tasks) ? message.tasks.length : 0}`,
|
|
65
|
+
files_persisted: (message) => {
|
|
66
|
+
const files = Array.isArray(message.files) ? message.files.length : 0;
|
|
67
|
+
const failed = Array.isArray(message.failed) ? message.failed.length : 0;
|
|
68
|
+
return failed === 0 ? `Persisted ${files} files` : `Persisted ${files} files; ${failed} failed`;
|
|
69
|
+
},
|
|
70
|
+
hook_started: (message) => `Hook ${nonblank(message.hook_name) ?? "unknown"} started`,
|
|
71
|
+
informational: (message) => nonblank(message.content) ?? "Informational notice",
|
|
72
|
+
mirror_error: (message) => `Transcript mirror warning: ${nonblank(message.error) ?? nonblank(message.message) ?? "unknown error"}`,
|
|
73
|
+
model_refusal_fallback: () => "Model refusal; using fallback",
|
|
74
|
+
model_refusal_no_fallback: () => "Model refusal; no fallback available",
|
|
75
|
+
notification: (message) => nonblank(message.message) ?? nonblank(message.content) ?? "Notification",
|
|
76
|
+
permission_denied: (message) => `Permission refused${nonblank(message.message) === undefined ? "" : `: ${nonblank(message.message)}`}`,
|
|
77
|
+
plugin_install: (message) => `Plugin install ${nonblank(message.status) ?? "updated"}${nonblank(message.name) === undefined ? "" : `: ${nonblank(message.name)}`}`,
|
|
78
|
+
status: (message) => `Status: ${nonblank(message.status) ?? "idle"}${nonblank(message.error) === undefined ? "" : ` (${nonblank(message.error)})`}`,
|
|
79
|
+
task_notification: (message) => `Task ${nonblank(message.task_id) ?? "unknown"} ${nonblank(message.status) ?? "updated"}`,
|
|
80
|
+
task_progress: (message) => nonblank(message.description) ?? `Task ${nonblank(message.task_id) ?? "unknown"} progressed`,
|
|
81
|
+
task_started: (message) => nonblank(message.description) ?? `Task ${nonblank(message.task_id) ?? "unknown"} started`,
|
|
82
|
+
task_updated: (message) => `Task ${nonblank(message.task_id) ?? "unknown"} updated`,
|
|
83
|
+
worker_shutting_down: (message) => `Worker stopping: ${nonblank(message.reason) ?? "unknown reason"}`,
|
|
84
|
+
};
|
|
85
|
+
function toolCall(name, input) {
|
|
86
|
+
const value = object(input) ?? {};
|
|
87
|
+
const command = nonblank(value.command);
|
|
88
|
+
if (command !== undefined)
|
|
89
|
+
return { kind: "run", command };
|
|
90
|
+
const path = nonblank(value.file_path) ?? nonblank(value.path);
|
|
91
|
+
if (/^(?:read|view)/iu.test(name) && path !== undefined)
|
|
92
|
+
return { kind: "read", path };
|
|
93
|
+
const query = nonblank(value.query) ?? nonblank(value.pattern);
|
|
94
|
+
if (/search|grep|glob/iu.test(name) && query !== undefined)
|
|
95
|
+
return { kind: "search", query };
|
|
96
|
+
if (/write/iu.test(name) && path !== undefined)
|
|
97
|
+
return { kind: "fileChange", changes: [{ op: "add", path }] };
|
|
98
|
+
if (/edit|notebook/iu.test(name) && path !== undefined)
|
|
99
|
+
return { kind: "fileChange", changes: [{ op: "update", path }] };
|
|
100
|
+
return { kind: "other", display: name };
|
|
101
|
+
}
|
|
102
|
+
function assistantEvents(message, events, state) {
|
|
103
|
+
if (message.aborted === true)
|
|
104
|
+
return;
|
|
105
|
+
if (message.error !== undefined) {
|
|
106
|
+
events.emit(noteEvent(`Assistant error: ${message.error}`));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const text = message.message.content
|
|
110
|
+
.filter((block) => block.type === "text")
|
|
111
|
+
.map((block) => block.text).join("");
|
|
112
|
+
if (text.length > 0)
|
|
113
|
+
events.emit({ type: "assistant", text });
|
|
114
|
+
for (const block of message.message.content) {
|
|
115
|
+
const value = object(block);
|
|
116
|
+
if (value?.type === "thinking" && typeof value.thinking === "string" && value.thinking.trim().length > 0) {
|
|
117
|
+
events.emit({ type: "thought", text: value.thinking });
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (block.type !== "tool_use")
|
|
121
|
+
continue;
|
|
122
|
+
const call = toolCall(block.name, block.input);
|
|
123
|
+
state.tools.set(block.id, { name: block.name, call });
|
|
124
|
+
events.emit({ type: "tool", phase: "started", id: block.id, name: block.name, call });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function toolResultEvents(message, events, state) {
|
|
128
|
+
const content = object(message.message)?.content;
|
|
129
|
+
if (!Array.isArray(content))
|
|
130
|
+
return;
|
|
131
|
+
for (const block of content) {
|
|
132
|
+
const value = object(block);
|
|
133
|
+
if (value?.type !== "tool_result")
|
|
134
|
+
continue;
|
|
135
|
+
const id = nonblank(value.tool_use_id);
|
|
136
|
+
if (id === undefined)
|
|
137
|
+
continue;
|
|
138
|
+
const observed = state.tools.get(id);
|
|
139
|
+
if (observed === undefined)
|
|
140
|
+
continue;
|
|
141
|
+
state.tools.delete(id);
|
|
142
|
+
events.emit({
|
|
143
|
+
type: "tool", phase: "completed", id, name: observed.name, call: observed.call,
|
|
144
|
+
result: { status: value.is_error === true ? "error" : "ok" },
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function emitSystemMessage(value, events) {
|
|
149
|
+
const subtype = nonblank(value?.subtype) ?? "unknown";
|
|
150
|
+
if (!Object.hasOwn(CLAUDE_SYSTEM_DISPOSITIONS, subtype)) {
|
|
151
|
+
events.emit(unknownEvent(subtype));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const systemDisposition = CLAUDE_SYSTEM_DISPOSITIONS[subtype];
|
|
155
|
+
if (systemDisposition === "drop")
|
|
156
|
+
return;
|
|
157
|
+
if (systemDisposition === "control-progress" && value?.status !== "api_retry")
|
|
158
|
+
return;
|
|
159
|
+
const note = CLAUDE_SYSTEM_NOTES[subtype];
|
|
160
|
+
events.emit(noteEvent(note?.(value ?? {}) ?? subtype));
|
|
161
|
+
}
|
|
162
|
+
export function emitClaudeMessage(message, events, state) {
|
|
163
|
+
const value = object(message) ?? {};
|
|
164
|
+
const kind = nonblank(value.type) ?? "unknown";
|
|
165
|
+
if (!Object.hasOwn(CLAUDE_MESSAGE_DISPOSITIONS, kind))
|
|
166
|
+
return events.emit(unknownEvent(kind));
|
|
167
|
+
const disposition = CLAUDE_MESSAGE_DISPOSITIONS[kind];
|
|
168
|
+
if (disposition === "assistant") {
|
|
169
|
+
assistantEvents(message, events, state);
|
|
170
|
+
}
|
|
171
|
+
else if (disposition === "tool-results") {
|
|
172
|
+
toolResultEvents(message, events, state);
|
|
173
|
+
}
|
|
174
|
+
else if (disposition === "auth") {
|
|
175
|
+
const error = nonblank(value.error);
|
|
176
|
+
if (error !== undefined)
|
|
177
|
+
events.emit(noteEvent(`Authentication warning: ${error}`));
|
|
178
|
+
}
|
|
179
|
+
else if (disposition === "note") {
|
|
180
|
+
events.emit(noteEvent("Conversation reset"));
|
|
181
|
+
}
|
|
182
|
+
else if (disposition === "system") {
|
|
183
|
+
emitSystemMessage(value, events);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Options, Query, SDKUserMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import { type ProviderAdapter, type ProviderOptions, type Session } from "../../provider.js";
|
|
3
|
+
import type { ResumeCoordinate } from "../../provider.js";
|
|
4
|
+
export { CLAUDE_MESSAGE_DISPOSITIONS, CLAUDE_SYSTEM_DISPOSITIONS } from "./events.js";
|
|
5
|
+
type ClaudeExecution = Readonly<{
|
|
6
|
+
executable?: string;
|
|
7
|
+
env?: Readonly<Record<string, string>>;
|
|
8
|
+
}>;
|
|
9
|
+
export type ClaudeSdk = Readonly<{
|
|
10
|
+
query(input: Readonly<{
|
|
11
|
+
prompt: string | AsyncIterable<SDKUserMessage>;
|
|
12
|
+
options?: Options;
|
|
13
|
+
}>): Query;
|
|
14
|
+
forkSession?(sessionId: string, options: Readonly<{
|
|
15
|
+
dir: string;
|
|
16
|
+
upToMessageId: string;
|
|
17
|
+
}>): Promise<Readonly<{
|
|
18
|
+
sessionId: string;
|
|
19
|
+
}>>;
|
|
20
|
+
}>;
|
|
21
|
+
export declare function createClaudeProvider(load: () => Promise<ClaudeSdk>, execution?: ClaudeExecution): ProviderAdapter;
|
|
22
|
+
export declare const claudeProvider: Readonly<{
|
|
23
|
+
confinement(input: Readonly<{
|
|
24
|
+
cwd: string;
|
|
25
|
+
options: ProviderOptions;
|
|
26
|
+
}>): import("../../index.js").Confinement;
|
|
27
|
+
admitOptions(options: ProviderOptions): import("../../provider.js").ProviderOptionAdmission;
|
|
28
|
+
fork?(input: Readonly<{
|
|
29
|
+
session: ResumeCoordinate;
|
|
30
|
+
at: string;
|
|
31
|
+
cwd: string;
|
|
32
|
+
}>): Promise<Readonly<{
|
|
33
|
+
session: ResumeCoordinate;
|
|
34
|
+
}>>;
|
|
35
|
+
start(input: import("../../provider.js").DriveInput & Readonly<{
|
|
36
|
+
session: Readonly<{
|
|
37
|
+
kind: "fresh";
|
|
38
|
+
}>;
|
|
39
|
+
}>): Promise<Session>;
|
|
40
|
+
resume?(input: import("../../provider.js").DriveInput & Readonly<{
|
|
41
|
+
session: Readonly<{
|
|
42
|
+
kind: "resume";
|
|
43
|
+
coordinate: ResumeCoordinate;
|
|
44
|
+
}>;
|
|
45
|
+
}>): Promise<Session>;
|
|
46
|
+
}>;
|