@vibecook/chopsticks-core 0.1.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.
- package/LICENSE +21 -0
- package/dist/events.d.ts +210 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +25 -0
- package/dist/events.js.map +1 -0
- package/dist/host.d.ts +69 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +12 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/session.d.ts +63 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +12 -0
- package/dist/session.js.map +1 -0
- package/dist/state.d.ts +77 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +240 -0
- package/dist/state.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 James Yong
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalized agent events and the envelope that carries them (DESIGN §14),
|
|
3
|
+
* corrected by the Phase 0 probe (draft/HOOK-SURFACE-FINDINGS.md):
|
|
4
|
+
* - Claude Code supplies BOTH a prompt id (user turn, on all post-prompt hook
|
|
5
|
+
* events) and a distinct assistant turn id (MessageDisplay) — the envelope
|
|
6
|
+
* keeps both instead of collapsing them.
|
|
7
|
+
* - MessageDisplay streams deltas keyed by message id; assistant.message here
|
|
8
|
+
* is the accumulated form, `final` marks completion.
|
|
9
|
+
* - Stop carries the final assistant text, surfaced on turn.completed.
|
|
10
|
+
*/
|
|
11
|
+
/** DESIGN ADR-001 — native-tui is a first-class mode, not a fallback. */
|
|
12
|
+
export type AgentExecutionMode = 'native-tui' | 'structured' | 'acp';
|
|
13
|
+
/**
|
|
14
|
+
* DESIGN §19.2 — the runtime must never overstate what it can observe.
|
|
15
|
+
* `structured` (above `native-hooks`) is a driver whose native surface is an
|
|
16
|
+
* authoritative structured protocol — streaming semantic events AND structured
|
|
17
|
+
* approvals — e.g. Codex's app-server (M5). `native-hooks` is authoritative
|
|
18
|
+
* lifecycle/tool state via hooks; the rest degrade from there.
|
|
19
|
+
*/
|
|
20
|
+
export type ObservationLevel = 'structured' | 'native-hooks' | 'native-log' | 'workspace-process' | 'terminal-only';
|
|
21
|
+
/** DESIGN §14.1 — where a normalized event came from. */
|
|
22
|
+
export type AgentEventSource = 'native-hook' | 'native-transcript' | 'workspace' | 'process' | 'terminal-inference' | 'runtime';
|
|
23
|
+
export type AgentEventConfidence = 'authoritative' | 'derived' | 'inferred';
|
|
24
|
+
/** DESIGN §21.4 — process exit and semantic turn completion are separate facts. */
|
|
25
|
+
export type ProcessExitReason = 'completed' | 'user-terminated' | 'runtime-terminated' | 'signal' | 'crash' | 'spawn-failed' | 'workspace-failed' | 'unknown';
|
|
26
|
+
export interface AgentEventEnvelope<T extends AgentEvent = AgentEvent> {
|
|
27
|
+
/** Monotonic per session, assigned by the runtime at ingestion, before fan-out. */
|
|
28
|
+
sequence: number;
|
|
29
|
+
sessionId: string;
|
|
30
|
+
nativeSessionId?: string;
|
|
31
|
+
/** User-turn correlation (Claude Code `prompt_id`). */
|
|
32
|
+
promptId?: string;
|
|
33
|
+
/** Assistant response-cycle correlation (Claude Code `turn_id`). */
|
|
34
|
+
turnId?: string;
|
|
35
|
+
timestamp: string;
|
|
36
|
+
monotonicTime: number;
|
|
37
|
+
source: AgentEventSource;
|
|
38
|
+
confidence: AgentEventConfidence;
|
|
39
|
+
event: T;
|
|
40
|
+
/** DESIGN ADR-008 — the raw native event is always retained. */
|
|
41
|
+
nativeEvent?: unknown;
|
|
42
|
+
}
|
|
43
|
+
export interface SessionStartedEvent {
|
|
44
|
+
type: 'session.started';
|
|
45
|
+
nativeSessionId?: string;
|
|
46
|
+
title?: string;
|
|
47
|
+
/** Claude Code `SessionStart.source`, e.g. "startup". */
|
|
48
|
+
startSource?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface SessionReadyEvent {
|
|
51
|
+
type: 'session.ready';
|
|
52
|
+
}
|
|
53
|
+
export interface SessionExitedEvent {
|
|
54
|
+
type: 'session.exited';
|
|
55
|
+
/** Claude Code `SessionEnd.reason`; value set not yet fully mapped. */
|
|
56
|
+
reason?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface TurnStartedEvent {
|
|
59
|
+
type: 'turn.started';
|
|
60
|
+
/** Claude Code `prompt_id`. */
|
|
61
|
+
turnId?: string;
|
|
62
|
+
prompt?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface TurnCompletedEvent {
|
|
65
|
+
type: 'turn.completed';
|
|
66
|
+
turnId?: string;
|
|
67
|
+
stopReason?: string;
|
|
68
|
+
/** Claude Code `Stop.last_assistant_message`. */
|
|
69
|
+
lastAssistantMessage?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface TurnFailedEvent {
|
|
72
|
+
type: 'turn.failed';
|
|
73
|
+
turnId?: string;
|
|
74
|
+
error?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface AssistantMessageEvent {
|
|
77
|
+
type: 'assistant.message';
|
|
78
|
+
messageId?: string;
|
|
79
|
+
turnId?: string;
|
|
80
|
+
text: string;
|
|
81
|
+
/** False while deltas are still accumulating (MessageDisplay `final`). */
|
|
82
|
+
final?: boolean;
|
|
83
|
+
/** True when sourced from display events rather than the transcript. */
|
|
84
|
+
displayOnly?: boolean;
|
|
85
|
+
}
|
|
86
|
+
/** A protocol-authoritative reasoning phase. This carries presence, not hidden thought text. */
|
|
87
|
+
export interface ReasoningStartedEvent {
|
|
88
|
+
type: 'reasoning.started';
|
|
89
|
+
reasoningId?: string;
|
|
90
|
+
}
|
|
91
|
+
/** An explicitly user-displayable reasoning summary, accumulated by the adapter. */
|
|
92
|
+
export interface ReasoningSummaryEvent {
|
|
93
|
+
type: 'reasoning.summary';
|
|
94
|
+
reasoningId?: string;
|
|
95
|
+
text: string;
|
|
96
|
+
final?: boolean;
|
|
97
|
+
}
|
|
98
|
+
/** A reasoning pulse whose raw provider payload is retained on the envelope. */
|
|
99
|
+
export interface ReasoningProgressEvent {
|
|
100
|
+
type: 'reasoning.progress';
|
|
101
|
+
reasoningId?: string;
|
|
102
|
+
}
|
|
103
|
+
export interface ReasoningCompletedEvent {
|
|
104
|
+
type: 'reasoning.completed';
|
|
105
|
+
reasoningId?: string;
|
|
106
|
+
}
|
|
107
|
+
export type ToolActivityKind = 'command' | 'web-search' | 'file-read' | 'file-edit' | 'browser' | 'mcp' | 'other';
|
|
108
|
+
/** Provider-neutral UI metadata. Adapters classify native tool names here. */
|
|
109
|
+
export interface ToolPresentation {
|
|
110
|
+
kind: ToolActivityKind;
|
|
111
|
+
title: string;
|
|
112
|
+
detail?: string;
|
|
113
|
+
}
|
|
114
|
+
export interface ToolRequestedEvent {
|
|
115
|
+
type: 'tool.requested';
|
|
116
|
+
toolCallId: string;
|
|
117
|
+
tool: string;
|
|
118
|
+
input?: unknown;
|
|
119
|
+
presentation?: ToolPresentation;
|
|
120
|
+
}
|
|
121
|
+
/** For structured/ACP drivers that distinguish acceptance from execution. */
|
|
122
|
+
export interface ToolStartedEvent {
|
|
123
|
+
type: 'tool.started';
|
|
124
|
+
toolCallId: string;
|
|
125
|
+
tool?: string;
|
|
126
|
+
input?: unknown;
|
|
127
|
+
presentation?: ToolPresentation;
|
|
128
|
+
}
|
|
129
|
+
export interface ToolCompletedEvent {
|
|
130
|
+
type: 'tool.completed';
|
|
131
|
+
toolCallId: string;
|
|
132
|
+
tool?: string;
|
|
133
|
+
output?: unknown;
|
|
134
|
+
durationMs?: number;
|
|
135
|
+
presentation?: ToolPresentation;
|
|
136
|
+
}
|
|
137
|
+
export interface ToolFailedEvent {
|
|
138
|
+
type: 'tool.failed';
|
|
139
|
+
toolCallId: string;
|
|
140
|
+
tool?: string;
|
|
141
|
+
error?: string;
|
|
142
|
+
presentation?: ToolPresentation;
|
|
143
|
+
}
|
|
144
|
+
export interface PermissionRequestedEvent {
|
|
145
|
+
type: 'permission.requested';
|
|
146
|
+
requestId: string;
|
|
147
|
+
toolCallId?: string;
|
|
148
|
+
tool?: string;
|
|
149
|
+
input?: unknown;
|
|
150
|
+
presentation: 'native-tui' | 'host-ui';
|
|
151
|
+
}
|
|
152
|
+
export interface PermissionResolvedEvent {
|
|
153
|
+
type: 'permission.resolved';
|
|
154
|
+
requestId: string;
|
|
155
|
+
outcome: 'allowed' | 'denied' | 'dismissed' | 'unknown';
|
|
156
|
+
}
|
|
157
|
+
export interface SubagentStartedEvent {
|
|
158
|
+
type: 'subagent.started';
|
|
159
|
+
subagentId: string;
|
|
160
|
+
agentType?: string;
|
|
161
|
+
}
|
|
162
|
+
export interface SubagentStoppedEvent {
|
|
163
|
+
type: 'subagent.stopped';
|
|
164
|
+
subagentId: string;
|
|
165
|
+
}
|
|
166
|
+
export interface TaskCreatedEvent {
|
|
167
|
+
type: 'task.created';
|
|
168
|
+
taskId: string;
|
|
169
|
+
description?: string;
|
|
170
|
+
}
|
|
171
|
+
export interface TaskCompletedEvent {
|
|
172
|
+
type: 'task.completed';
|
|
173
|
+
taskId: string;
|
|
174
|
+
}
|
|
175
|
+
export interface WorkspaceChangedEvent {
|
|
176
|
+
type: 'workspace.changed';
|
|
177
|
+
paths?: string[];
|
|
178
|
+
}
|
|
179
|
+
export interface ProcessStartedEvent {
|
|
180
|
+
type: 'process.started';
|
|
181
|
+
pid: number;
|
|
182
|
+
}
|
|
183
|
+
export interface ProcessExitedEvent {
|
|
184
|
+
type: 'process.exited';
|
|
185
|
+
exitCode?: number;
|
|
186
|
+
signal?: string;
|
|
187
|
+
reason: ProcessExitReason;
|
|
188
|
+
}
|
|
189
|
+
export interface NativeNotificationEvent {
|
|
190
|
+
type: 'notification';
|
|
191
|
+
message?: string;
|
|
192
|
+
notificationType?: string;
|
|
193
|
+
}
|
|
194
|
+
/** DESIGN ADR-008 — unrecognized native events survive normalization. */
|
|
195
|
+
export interface UnknownNativeEvent {
|
|
196
|
+
type: 'adapter.native-event';
|
|
197
|
+
adapter: string;
|
|
198
|
+
nativeType?: string;
|
|
199
|
+
}
|
|
200
|
+
export type AgentEvent = SessionStartedEvent | SessionReadyEvent | SessionExitedEvent | TurnStartedEvent | TurnCompletedEvent | TurnFailedEvent | AssistantMessageEvent | ReasoningStartedEvent | ReasoningProgressEvent | ReasoningSummaryEvent | ReasoningCompletedEvent | ToolRequestedEvent | ToolStartedEvent | ToolCompletedEvent | ToolFailedEvent | PermissionRequestedEvent | PermissionResolvedEvent | SubagentStartedEvent | SubagentStoppedEvent | TaskCreatedEvent | TaskCompletedEvent | WorkspaceChangedEvent | ProcessStartedEvent | ProcessExitedEvent | NativeNotificationEvent | UnknownNativeEvent;
|
|
201
|
+
export interface EnvelopeStamper {
|
|
202
|
+
next<T extends AgentEvent>(fields: Omit<AgentEventEnvelope<T>, 'sequence'>): AgentEventEnvelope<T>;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Sequence numbers are assigned at ingestion, before fan-out, so every
|
|
206
|
+
* consumer observes the same order (DESIGN §12.1 applies the same rule to
|
|
207
|
+
* terminal chunks). One stamper per session.
|
|
208
|
+
*/
|
|
209
|
+
export declare function createEnvelopeStamper(): EnvelopeStamper;
|
|
210
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,yEAAyE;AACzE,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,YAAY,GAAG,KAAK,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG,cAAc,GAAG,YAAY,GAAG,mBAAmB,GAAG,eAAe,CAAC;AAEpH,yDAAyD;AACzD,MAAM,MAAM,gBAAgB,GAC1B,aAAa,GAAG,mBAAmB,GAAG,WAAW,GAAG,SAAS,GAAG,oBAAoB,GAAG,SAAS,CAAC;AAEnG,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG,SAAS,GAAG,UAAU,CAAC;AAE5E,mFAAmF;AACnF,MAAM,MAAM,iBAAiB,GACzB,WAAW,GACX,iBAAiB,GACjB,oBAAoB,GACpB,QAAQ,GACR,OAAO,GACP,cAAc,GACd,kBAAkB,GAClB,SAAS,CAAC;AAEd,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IACnE,mFAAmF;IACnF,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;I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mB,GACnB,kBAAkB,GAClB,uBAAuB,GACvB,kBAAkB,CAAC;AAMvB,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;CACpG;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,eAAe,CAQvD"}
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalized agent events and the envelope that carries them (DESIGN §14),
|
|
3
|
+
* corrected by the Phase 0 probe (draft/HOOK-SURFACE-FINDINGS.md):
|
|
4
|
+
* - Claude Code supplies BOTH a prompt id (user turn, on all post-prompt hook
|
|
5
|
+
* events) and a distinct assistant turn id (MessageDisplay) — the envelope
|
|
6
|
+
* keeps both instead of collapsing them.
|
|
7
|
+
* - MessageDisplay streams deltas keyed by message id; assistant.message here
|
|
8
|
+
* is the accumulated form, `final` marks completion.
|
|
9
|
+
* - Stop carries the final assistant text, surfaced on turn.completed.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Sequence numbers are assigned at ingestion, before fan-out, so every
|
|
13
|
+
* consumer observes the same order (DESIGN §12.1 applies the same rule to
|
|
14
|
+
* terminal chunks). One stamper per session.
|
|
15
|
+
*/
|
|
16
|
+
export function createEnvelopeStamper() {
|
|
17
|
+
let sequence = 0;
|
|
18
|
+
return {
|
|
19
|
+
next(fields) {
|
|
20
|
+
sequence += 1;
|
|
21
|
+
return { sequence, ...fields };
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAkRH;;;;GAIG;AACH,MAAM,UAAU,qBAAqB;IACnC,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,OAAO;QACL,IAAI,CAAC,MAAM;YACT,QAAQ,IAAI,CAAC,CAAC;YACd,OAAO,EAAE,QAAQ,EAAE,GAAG,MAAM,EAAE,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentHost — the terminal/process capability an application (the workbench, a
|
|
3
|
+
* CLI, …) lends to an adapter so the adapter can own its FULL native-TUI spawn
|
|
4
|
+
* recipe without owning PTY infrastructure. This lifts the Claude adapter's
|
|
5
|
+
* `ports` shape (DESIGN §16) into core so every adapter shares ONE injection
|
|
6
|
+
* point, and it is what lets the Codex app-server + `codex --remote` and the
|
|
7
|
+
* Grok leader + `grok --leader` recipes move out of the app and into their
|
|
8
|
+
* adapters (ADR-007: process lifecycle belongs to the host; the adapter only
|
|
9
|
+
* asks the host to spawn/automate, and observes/controls the result).
|
|
10
|
+
*/
|
|
11
|
+
/** A native terminal (PTY) the host should spawn on the adapter's behalf. */
|
|
12
|
+
export interface TerminalSpec {
|
|
13
|
+
command: string;
|
|
14
|
+
args: string[];
|
|
15
|
+
cwd: string;
|
|
16
|
+
/** Extra environment for the spawned process (merged over the host's base). */
|
|
17
|
+
env?: Record<string, string>;
|
|
18
|
+
/** Initial geometry; the host may substitute its own default when omitted. */
|
|
19
|
+
cols?: number;
|
|
20
|
+
rows?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The capability surface an adapter needs from its host. Deliberately tiny:
|
|
24
|
+
* spawn a terminal and write raw bytes to one. Everything else (transcripts,
|
|
25
|
+
* app-servers, leaders, sockets) the adapter builds itself.
|
|
26
|
+
*/
|
|
27
|
+
export type TerminalAutomationOperation = {
|
|
28
|
+
kind: 'paste';
|
|
29
|
+
text: string;
|
|
30
|
+
submit: boolean;
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'text';
|
|
33
|
+
text: string;
|
|
34
|
+
} | {
|
|
35
|
+
kind: 'interrupt';
|
|
36
|
+
};
|
|
37
|
+
export type TerminalAutomationResult = {
|
|
38
|
+
accepted: true;
|
|
39
|
+
} | {
|
|
40
|
+
accepted: false;
|
|
41
|
+
reason: 'human-input-conflict' | string;
|
|
42
|
+
};
|
|
43
|
+
export interface AgentHost {
|
|
44
|
+
/** Spawn a native terminal for the agent; returns the host's routing id. */
|
|
45
|
+
spawnTerminal(spec: TerminalSpec): Promise<{
|
|
46
|
+
runtimeSessionId: string;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Submit one semantic automation operation. The terminal service orders it
|
|
50
|
+
* atomically against accepted human input without attaching a view, taking
|
|
51
|
+
* focus, or claiming resize control.
|
|
52
|
+
*/
|
|
53
|
+
automateTerminal(runtimeSessionId: string, operation: TerminalAutomationOperation): Promise<TerminalAutomationResult>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The options every native-TUI session factory accepts. Each adapter's
|
|
57
|
+
* `createXTuiSession` extends this with its own extras (executable, sandbox, …)
|
|
58
|
+
* and returns an {@link AgentSession} whose `runtimeSessionId` is the terminal
|
|
59
|
+
* the host spawned and whose `dispose()` tears down the adapter's own backing
|
|
60
|
+
* services (observer, app-server, leader client).
|
|
61
|
+
*/
|
|
62
|
+
export interface AgentTuiSessionOptions {
|
|
63
|
+
cwd: string;
|
|
64
|
+
/** Resume an existing session by its native/join id. */
|
|
65
|
+
resume?: string;
|
|
66
|
+
/** The host capability the adapter spawns/writes its terminal through. */
|
|
67
|
+
host: AgentHost;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6EAA6E;AAC7E,MAAM,WAAW,YAAY;IAC3B,OAAO,EA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|
|
3
|
+
* CLI, …) lends to an adapter so the adapter can own its FULL native-TUI spawn
|
|
4
|
+
* recipe without owning PTY infrastructure. This lifts the Claude adapter's
|
|
5
|
+
* `ports` shape (DESIGN §16) into core so every adapter shares ONE injection
|
|
6
|
+
* point, and it is what lets the Codex app-server + `codex --remote` and the
|
|
7
|
+
* Grok leader + `grok --leader` recipes move out of the app and into their
|
|
8
|
+
* adapters (ADR-007: process lifecycle belongs to the host; the adapter only
|
|
9
|
+
* asks the host to spawn/automate, and observes/controls the result).
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vibecook/chopsticks-core — contracts for the chopsticks agent runtime.
|
|
3
|
+
*
|
|
4
|
+
* Zero I/O by design (DESIGN §8, acceptance criterion 19): types, the session
|
|
5
|
+
* state reducer, and pure helpers only. Anything touching a PTY, process,
|
|
6
|
+
* socket, or file lives in @vibecook/chopsticks-node or an adapter package.
|
|
7
|
+
*/
|
|
8
|
+
export * from './events.js';
|
|
9
|
+
export * from './state.js';
|
|
10
|
+
export * from './session.js';
|
|
11
|
+
export * from './host.js';
|
|
12
|
+
export declare const CHOPSTICKS_CORE_VERSION = "0.1.0";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAE1B,eAAO,MAAM,uBAAuB,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vibecook/chopsticks-core — contracts for the chopsticks agent runtime.
|
|
3
|
+
*
|
|
4
|
+
* Zero I/O by design (DESIGN §8, acceptance criterion 19): types, the session
|
|
5
|
+
* state reducer, and pure helpers only. Anything touching a PTY, process,
|
|
6
|
+
* socket, or file lives in @vibecook/chopsticks-node or an adapter package.
|
|
7
|
+
*/
|
|
8
|
+
export * from './events.js';
|
|
9
|
+
export * from './state.js';
|
|
10
|
+
export * from './session.js';
|
|
11
|
+
export * from './host.js';
|
|
12
|
+
export const CHOPSTICKS_CORE_VERSION = '0.1.0'; // x-release-please-version
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAE1B,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,CAAC,CAAC,2BAA2B"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent-agnostic session contract (DESIGN §9), lifted into core once a
|
|
3
|
+
* second driver existed to test it against (M5: Claude's hook+PTY driver and
|
|
4
|
+
* Codex's structured app-server driver). Before that, `AgentSession` lived as a
|
|
5
|
+
* concrete `ClaudeSession` in the Claude adapter — lifting off one example
|
|
6
|
+
* would have baked in Claude's shape.
|
|
7
|
+
*
|
|
8
|
+
* Zero I/O by design (like the rest of core): interfaces only. Concrete drivers
|
|
9
|
+
* (`createClaudeSession`, the forthcoming `createCodexSession`) implement these.
|
|
10
|
+
*/
|
|
11
|
+
import type { AgentEventEnvelope, ObservationLevel } from './events.js';
|
|
12
|
+
import type { SessionRuntimeState } from './state.js';
|
|
13
|
+
/**
|
|
14
|
+
* A programmatic prompt submission (generalized from the Claude guarded
|
|
15
|
+
* injector, DESIGN §17).
|
|
16
|
+
*/
|
|
17
|
+
export interface PromptSubmission {
|
|
18
|
+
text: string;
|
|
19
|
+
/**
|
|
20
|
+
* Paste-and-submit (default) appends Enter; paste-only leaves it staged.
|
|
21
|
+
* Meaningful only to guarded-paste (native-TUI) injectors; structured drivers
|
|
22
|
+
* submit atomically and ignore it.
|
|
23
|
+
*/
|
|
24
|
+
mode?: 'paste-and-submit' | 'paste-only';
|
|
25
|
+
confirmationTimeoutMs?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Outcome of a prompt submission. `uncertain` is first-class: a guarded-paste
|
|
29
|
+
* injector cannot always prove the agent accepted exactly our text (DESIGN
|
|
30
|
+
* §17). Structured drivers with deterministic confirmation never emit it.
|
|
31
|
+
*/
|
|
32
|
+
export type PromptReceipt = {
|
|
33
|
+
status: 'confirmed';
|
|
34
|
+
turnId?: string;
|
|
35
|
+
} | {
|
|
36
|
+
status: 'rejected';
|
|
37
|
+
reason: string;
|
|
38
|
+
} | {
|
|
39
|
+
status: 'uncertain';
|
|
40
|
+
reason: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The handle every driver returns for one live agent process/thread — observed
|
|
44
|
+
* and controlled. Process lifecycle (spawn/terminate) belongs to the host, not
|
|
45
|
+
* this handle (ADR-007); `dispose()` tears down observation/control only.
|
|
46
|
+
*
|
|
47
|
+
* Adapters MAY extend this with native extras, but applications should normally
|
|
48
|
+
* consume the provider-neutral AgentRuntime surface from chopsticks-runtime.
|
|
49
|
+
*/
|
|
50
|
+
export interface AgentSession {
|
|
51
|
+
/** Native/join id — the chopsticks ↔ spaghetti correlation key. */
|
|
52
|
+
readonly sessionId: string;
|
|
53
|
+
/** The host's id for the terminal session (attach/write/kill routing). */
|
|
54
|
+
readonly runtimeSessionId: string;
|
|
55
|
+
state(): SessionRuntimeState;
|
|
56
|
+
/** Honest, current observation level — never overstated (DESIGN §19.2). */
|
|
57
|
+
observationLevel(): ObservationLevel;
|
|
58
|
+
onEvent(listener: (envelope: AgentEventEnvelope) => void): () => void;
|
|
59
|
+
submitPrompt(submission: PromptSubmission): Promise<PromptReceipt>;
|
|
60
|
+
/** Tear down observation/control. Process lifecycle stays with the host. */
|
|
61
|
+
dispose(): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,IAAI,CAAC,EAAE,kBAAkB,GAAG,YAAY,CAAC;IACzC,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACxC;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACtC;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,mEAAmE;IACnE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,0EAA0E;IAC1E,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,KAAK,IAAI,mBAAmB,CAAC;IAC7B,2EAA2E;IAC3E,gBAAgB,IAAI,gBAAgB,CAAC;IACrC,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACtE,YAAY,CAAC,UAAU,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACnE,4EAA4E;IAC5E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent-agnostic session contract (DESIGN §9), lifted into core once a
|
|
3
|
+
* second driver existed to test it against (M5: Claude's hook+PTY driver and
|
|
4
|
+
* Codex's structured app-server driver). Before that, `AgentSession` lived as a
|
|
5
|
+
* concrete `ClaudeSession` in the Claude adapter — lifting off one example
|
|
6
|
+
* would have baked in Claude's shape.
|
|
7
|
+
*
|
|
8
|
+
* Zero I/O by design (like the rest of core): interfaces only. Concrete drivers
|
|
9
|
+
* (`createClaudeSession`, the forthcoming `createCodexSession`) implement these.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session state reducer (DESIGN §15).
|
|
3
|
+
*
|
|
4
|
+
* All normalized events pass through this deterministic, pure reducer:
|
|
5
|
+
* - never throws on duplicate, out-of-order, or unknown events
|
|
6
|
+
* - duplicates (sequence <= lastSequence) are skipped by returning the SAME
|
|
7
|
+
* state reference, so replays are idempotent
|
|
8
|
+
* - invalid transitions produce bounded diagnostics, never exceptions
|
|
9
|
+
* - the raw event log is retained upstream (envelopes are append-only);
|
|
10
|
+
* state is always rebuildable by replay
|
|
11
|
+
*
|
|
12
|
+
* Terminal geometry and control-lease state (DESIGN §15's `terminal`/`control`
|
|
13
|
+
* fields) are owned by the node runtime, not this reducer — they derive from
|
|
14
|
+
* PTY and lease facts, not agent events.
|
|
15
|
+
*/
|
|
16
|
+
import type { AgentEventEnvelope, ProcessExitReason, ToolPresentation } from './events.js';
|
|
17
|
+
export type SessionLifecycle = 'preparing' | 'starting' | 'ready' | 'running' | 'interrupting' | 'terminating' | 'exited' | 'failed';
|
|
18
|
+
export interface ToolRuntimeState {
|
|
19
|
+
toolCallId: string;
|
|
20
|
+
tool?: string;
|
|
21
|
+
state: 'requested' | 'running';
|
|
22
|
+
input?: unknown;
|
|
23
|
+
presentation?: ToolPresentation;
|
|
24
|
+
}
|
|
25
|
+
export interface ReasoningRuntimeState {
|
|
26
|
+
reasoningId?: string;
|
|
27
|
+
startedAt: string;
|
|
28
|
+
}
|
|
29
|
+
export interface PermissionRuntimeState {
|
|
30
|
+
requestId: string;
|
|
31
|
+
toolCallId?: string;
|
|
32
|
+
tool?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface SubagentRuntimeState {
|
|
35
|
+
subagentId: string;
|
|
36
|
+
agentType?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface TaskRuntimeState {
|
|
39
|
+
taskId: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface ReducerDiagnostic {
|
|
43
|
+
sequence: number;
|
|
44
|
+
code: string;
|
|
45
|
+
message: string;
|
|
46
|
+
}
|
|
47
|
+
export interface SessionRuntimeState {
|
|
48
|
+
lifecycle: SessionLifecycle;
|
|
49
|
+
activeTurn?: {
|
|
50
|
+
id?: string;
|
|
51
|
+
startedAt: string;
|
|
52
|
+
};
|
|
53
|
+
/** Present only for providers with an explicit reasoning signal. */
|
|
54
|
+
activeReasoning?: ReasoningRuntimeState;
|
|
55
|
+
/** Tools currently in flight. Completed/failed tools LEAVE this map. */
|
|
56
|
+
tools: Map<string, ToolRuntimeState>;
|
|
57
|
+
/** Pending permission requests. Resolved requests leave this map. */
|
|
58
|
+
permissions: Map<string, PermissionRuntimeState>;
|
|
59
|
+
subagents: Map<string, SubagentRuntimeState>;
|
|
60
|
+
tasks: Map<string, TaskRuntimeState>;
|
|
61
|
+
lastAssistantMessage?: string;
|
|
62
|
+
exit?: {
|
|
63
|
+
exitCode?: number;
|
|
64
|
+
signal?: string;
|
|
65
|
+
reason?: ProcessExitReason | string;
|
|
66
|
+
};
|
|
67
|
+
counters: {
|
|
68
|
+
toolsCompleted: number;
|
|
69
|
+
toolsFailed: number;
|
|
70
|
+
unknownEvents: number;
|
|
71
|
+
};
|
|
72
|
+
lastSequence: number;
|
|
73
|
+
diagnostics: ReducerDiagnostic[];
|
|
74
|
+
}
|
|
75
|
+
export declare function createInitialSessionState(): SessionRuntimeState;
|
|
76
|
+
export declare function reduceSessionState(state: SessionRuntimeState, envelope: AgentEventEnvelope): SessionRuntimeState;
|
|
77
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAc,kBAAkB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEvG,MAAM,MAAM,gBAAgB,GAC1B,WAAW,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,cAAc,GAAG,aAAa,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAExG,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,WAAW,GAAG,SAAS,CAAC;IAC/B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,gBAAgB,CAAC;CACjC;AAED,MAAM,WAAW,qBAAqB;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB;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,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,iBAAiB,EAAE,CAAC;CAClC;AAID,wBAAgB,yBAAyB,IAAI,mBAAmB,CAW/D;AAgBD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,kBAAkB,GAAG,mBAAmB,CAyOhH"}
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session state reducer (DESIGN §15).
|
|
3
|
+
*
|
|
4
|
+
* All normalized events pass through this deterministic, pure reducer:
|
|
5
|
+
* - never throws on duplicate, out-of-order, or unknown events
|
|
6
|
+
* - duplicates (sequence <= lastSequence) are skipped by returning the SAME
|
|
7
|
+
* state reference, so replays are idempotent
|
|
8
|
+
* - invalid transitions produce bounded diagnostics, never exceptions
|
|
9
|
+
* - the raw event log is retained upstream (envelopes are append-only);
|
|
10
|
+
* state is always rebuildable by replay
|
|
11
|
+
*
|
|
12
|
+
* Terminal geometry and control-lease state (DESIGN §15's `terminal`/`control`
|
|
13
|
+
* fields) are owned by the node runtime, not this reducer — they derive from
|
|
14
|
+
* PTY and lease facts, not agent events.
|
|
15
|
+
*/
|
|
16
|
+
const MAX_DIAGNOSTICS = 50;
|
|
17
|
+
export function createInitialSessionState() {
|
|
18
|
+
return {
|
|
19
|
+
lifecycle: 'preparing',
|
|
20
|
+
tools: new Map(),
|
|
21
|
+
permissions: new Map(),
|
|
22
|
+
subagents: new Map(),
|
|
23
|
+
tasks: new Map(),
|
|
24
|
+
counters: { toolsCompleted: 0, toolsFailed: 0, unknownEvents: 0 },
|
|
25
|
+
lastSequence: 0,
|
|
26
|
+
diagnostics: [],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function withDiagnostic(state, sequence, code, message) {
|
|
30
|
+
if (state.diagnostics.length >= MAX_DIAGNOSTICS)
|
|
31
|
+
return state;
|
|
32
|
+
return { ...state, diagnostics: [...state.diagnostics, { sequence, code, message }] };
|
|
33
|
+
}
|
|
34
|
+
function isTerminal(lifecycle) {
|
|
35
|
+
return lifecycle === 'exited' || lifecycle === 'failed';
|
|
36
|
+
}
|
|
37
|
+
export function reduceSessionState(state, envelope) {
|
|
38
|
+
// Duplicate / out-of-order guard: envelopes are stamped in ingestion order,
|
|
39
|
+
// so a non-increasing sequence is a replayed or stale event. Returning the
|
|
40
|
+
// same reference keeps replays idempotent.
|
|
41
|
+
if (envelope.sequence <= state.lastSequence)
|
|
42
|
+
return state;
|
|
43
|
+
let next = { ...state, lastSequence: envelope.sequence };
|
|
44
|
+
const event = envelope.event;
|
|
45
|
+
const seq = envelope.sequence;
|
|
46
|
+
switch (event.type) {
|
|
47
|
+
case 'process.started': {
|
|
48
|
+
if (next.lifecycle === 'preparing')
|
|
49
|
+
next = { ...next, lifecycle: 'starting' };
|
|
50
|
+
else
|
|
51
|
+
next = withDiagnostic(next, seq, 'process-started-late', `process.started in ${next.lifecycle}`);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case 'session.started':
|
|
55
|
+
case 'session.ready': {
|
|
56
|
+
if (isTerminal(next.lifecycle)) {
|
|
57
|
+
next = withDiagnostic(next, seq, 'session-start-after-exit', `${event.type} in ${next.lifecycle}`);
|
|
58
|
+
}
|
|
59
|
+
else if (next.lifecycle !== 'running') {
|
|
60
|
+
next = { ...next, lifecycle: 'ready' };
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case 'turn.started': {
|
|
65
|
+
if (isTerminal(next.lifecycle)) {
|
|
66
|
+
next = withDiagnostic(next, seq, 'turn-after-exit', `turn.started in ${next.lifecycle}`);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
if (next.activeTurn) {
|
|
70
|
+
next = withDiagnostic(next, seq, 'turn-overlap', `turn.started while turn ${next.activeTurn.id ?? '?'} active`);
|
|
71
|
+
}
|
|
72
|
+
next = { ...next, lifecycle: 'running', activeTurn: { id: event.turnId, startedAt: envelope.timestamp } };
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case 'turn.completed':
|
|
76
|
+
case 'turn.failed': {
|
|
77
|
+
if (next.activeTurn && event.turnId && next.activeTurn.id && next.activeTurn.id !== event.turnId) {
|
|
78
|
+
next = withDiagnostic(next, seq, 'turn-mismatch', `${event.type} for ${event.turnId}, active is ${next.activeTurn.id}`);
|
|
79
|
+
}
|
|
80
|
+
next = { ...next, activeTurn: undefined, activeReasoning: undefined };
|
|
81
|
+
if (!isTerminal(next.lifecycle))
|
|
82
|
+
next = { ...next, lifecycle: 'ready' };
|
|
83
|
+
if (event.type === 'turn.completed' && event.lastAssistantMessage !== undefined) {
|
|
84
|
+
next = { ...next, lastAssistantMessage: event.lastAssistantMessage };
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case 'assistant.message': {
|
|
89
|
+
if (event.final !== false)
|
|
90
|
+
next = { ...next, lastAssistantMessage: event.text };
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
case 'reasoning.started':
|
|
94
|
+
next = {
|
|
95
|
+
...next,
|
|
96
|
+
activeReasoning: { reasoningId: event.reasoningId, startedAt: envelope.timestamp },
|
|
97
|
+
};
|
|
98
|
+
break;
|
|
99
|
+
case 'reasoning.progress':
|
|
100
|
+
case 'reasoning.summary':
|
|
101
|
+
if (!next.activeReasoning) {
|
|
102
|
+
next = {
|
|
103
|
+
...next,
|
|
104
|
+
activeReasoning: { reasoningId: event.reasoningId, startedAt: envelope.timestamp },
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case 'reasoning.completed':
|
|
109
|
+
next = { ...next, activeReasoning: undefined };
|
|
110
|
+
break;
|
|
111
|
+
case 'tool.requested': {
|
|
112
|
+
const tools = new Map(next.tools);
|
|
113
|
+
tools.set(event.toolCallId, {
|
|
114
|
+
toolCallId: event.toolCallId,
|
|
115
|
+
tool: event.tool,
|
|
116
|
+
state: 'requested',
|
|
117
|
+
input: event.input,
|
|
118
|
+
presentation: event.presentation,
|
|
119
|
+
});
|
|
120
|
+
next = { ...next, tools };
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
case 'tool.started': {
|
|
124
|
+
const existing = next.tools.get(event.toolCallId);
|
|
125
|
+
const tools = new Map(next.tools);
|
|
126
|
+
tools.set(event.toolCallId, {
|
|
127
|
+
toolCallId: event.toolCallId,
|
|
128
|
+
tool: event.tool ?? existing?.tool,
|
|
129
|
+
state: 'running',
|
|
130
|
+
input: event.input ?? existing?.input,
|
|
131
|
+
presentation: event.presentation ?? existing?.presentation,
|
|
132
|
+
});
|
|
133
|
+
next = { ...next, tools };
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case 'tool.completed':
|
|
137
|
+
case 'tool.failed': {
|
|
138
|
+
// Absent ids are not diagnostics: hook and transcript sources may both
|
|
139
|
+
// report the same completion, and the second one finds the map empty.
|
|
140
|
+
if (next.tools.has(event.toolCallId)) {
|
|
141
|
+
const tools = new Map(next.tools);
|
|
142
|
+
tools.delete(event.toolCallId);
|
|
143
|
+
next = { ...next, tools };
|
|
144
|
+
}
|
|
145
|
+
const counters = { ...next.counters };
|
|
146
|
+
if (event.type === 'tool.completed')
|
|
147
|
+
counters.toolsCompleted += 1;
|
|
148
|
+
else
|
|
149
|
+
counters.toolsFailed += 1;
|
|
150
|
+
next = { ...next, counters };
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
case 'permission.requested': {
|
|
154
|
+
// Permission state is intentionally isolated from tool state (DESIGN §26.5).
|
|
155
|
+
const permissions = new Map(next.permissions);
|
|
156
|
+
permissions.set(event.requestId, { requestId: event.requestId, toolCallId: event.toolCallId, tool: event.tool });
|
|
157
|
+
next = { ...next, permissions };
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case 'permission.resolved': {
|
|
161
|
+
if (next.permissions.has(event.requestId)) {
|
|
162
|
+
const permissions = new Map(next.permissions);
|
|
163
|
+
permissions.delete(event.requestId);
|
|
164
|
+
next = { ...next, permissions };
|
|
165
|
+
}
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
case 'subagent.started': {
|
|
169
|
+
const subagents = new Map(next.subagents);
|
|
170
|
+
subagents.set(event.subagentId, { subagentId: event.subagentId, agentType: event.agentType });
|
|
171
|
+
next = { ...next, subagents };
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case 'subagent.stopped': {
|
|
175
|
+
if (next.subagents.has(event.subagentId)) {
|
|
176
|
+
const subagents = new Map(next.subagents);
|
|
177
|
+
subagents.delete(event.subagentId);
|
|
178
|
+
next = { ...next, subagents };
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
case 'task.created': {
|
|
183
|
+
const tasks = new Map(next.tasks);
|
|
184
|
+
tasks.set(event.taskId, { taskId: event.taskId, description: event.description });
|
|
185
|
+
next = { ...next, tasks };
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
case 'task.completed': {
|
|
189
|
+
if (next.tasks.has(event.taskId)) {
|
|
190
|
+
const tasks = new Map(next.tasks);
|
|
191
|
+
tasks.delete(event.taskId);
|
|
192
|
+
next = { ...next, tasks };
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case 'session.exited': {
|
|
197
|
+
if (next.activeTurn) {
|
|
198
|
+
next = withDiagnostic(next, seq, 'turn-orphaned-on-exit', `session exited with turn ${next.activeTurn.id ?? '?'} active`);
|
|
199
|
+
}
|
|
200
|
+
if (next.tools.size > 0) {
|
|
201
|
+
next = withDiagnostic(next, seq, 'tools-orphaned-on-exit', `session exited with ${next.tools.size} tool(s) in flight`);
|
|
202
|
+
}
|
|
203
|
+
next = {
|
|
204
|
+
...next,
|
|
205
|
+
lifecycle: 'exited',
|
|
206
|
+
activeTurn: undefined,
|
|
207
|
+
activeReasoning: undefined,
|
|
208
|
+
tools: new Map(),
|
|
209
|
+
permissions: new Map(),
|
|
210
|
+
exit: next.exit ?? { reason: event.reason },
|
|
211
|
+
};
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
case 'process.exited': {
|
|
215
|
+
const failed = event.reason === 'crash' || event.reason === 'spawn-failed' || event.reason === 'workspace-failed';
|
|
216
|
+
next = {
|
|
217
|
+
...next,
|
|
218
|
+
lifecycle: isTerminal(next.lifecycle) ? next.lifecycle : failed ? 'failed' : 'exited',
|
|
219
|
+
activeTurn: undefined,
|
|
220
|
+
activeReasoning: undefined,
|
|
221
|
+
exit: { exitCode: event.exitCode, signal: event.signal, reason: event.reason },
|
|
222
|
+
};
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
case 'workspace.changed':
|
|
226
|
+
case 'notification':
|
|
227
|
+
break;
|
|
228
|
+
case 'adapter.native-event': {
|
|
229
|
+
next = { ...next, counters: { ...next.counters, unknownEvents: next.counters.unknownEvents + 1 } };
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
default: {
|
|
233
|
+
// Unknown event types must never throw (DESIGN §15.2).
|
|
234
|
+
next = { ...next, counters: { ...next.counters, unknownEvents: next.counters.unknownEvents + 1 } };
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return next;
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAgEH,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,MAAM,UAAU,yBAAyB;IACvC,OAAO;QACL,SAAS,EAAE,WAAW;QACtB,KAAK,EAAE,IAAI,GAAG,EAAE;QAChB,WAAW,EAAE,IAAI,GAAG,EAAE;QACtB,SAAS,EAAE,IAAI,GAAG,EAAE;QACpB,KAAK,EAAE,IAAI,GAAG,EAAE;QA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CAAC,MAAM,KAAK,cAAc,IAAI,KAAK,CAAC,MAAM,KAAK,kBAAkB,CAAC;YAClH,IAAI,GAAG;gBACL,GAAG,IAAI;gBACP,SAAS,EAAE,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;gBACrF,UAAU,EAAE,SAAS;gBACrB,eAAe,EAAE,SAAS;gBAC1B,IAAI,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE;aAC/E,CAAC;YACF,MAAM;QACR,CAAC;QAED,KAAK,mBAAmB,CAAC;QACzB,KAAK,cAAc;YACjB,MAAM;QAER,KAAK,sBAAsB,CAAC,CAAC,CAAC;YAC5B,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,aAAa,GAAG,CAAC,EAAE,EAAE,CAAC;YACnG,MAAM;QACR,CAAC;QAED,OAAO,CAAC,CAAC,CAAC;YACR,uDAAuD;YACvD,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,aAAa,GAAG,CAAC,EAAE,EAAE,CAAC;YACnG,MAAM;QACR,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vibecook/chopsticks-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Core contracts for the chopsticks agent runtime: events, session state reducer, adapter interfaces. Zero I/O.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "James Yong",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/jamesyong-42/chopsticks.git",
|
|
11
|
+
"directory": "packages/core"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public",
|
|
23
|
+
"provenance": true
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"fast-check": "^4.0.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
36
|
+
"build": "pnpm clean && tsc -p tsconfig.build.json",
|
|
37
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
38
|
+
"test": "vitest run"
|
|
39
|
+
}
|
|
40
|
+
}
|