claws-code 0.8.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/.claude/commands/claws-auto.md +90 -0
- package/.claude/commands/claws-bin.md +28 -0
- package/.claude/commands/claws-cleanup.md +28 -0
- package/.claude/commands/claws-do.md +82 -0
- package/.claude/commands/claws-fix.md +40 -0
- package/.claude/commands/claws-goal.md +111 -0
- package/.claude/commands/claws-help.md +54 -0
- package/.claude/commands/claws-plan.md +103 -0
- package/.claude/commands/claws-report.md +29 -0
- package/.claude/commands/claws-status.md +37 -0
- package/.claude/commands/claws-update.md +32 -0
- package/.claude/commands/claws.md +64 -0
- package/.claude/rules/claws-default-behavior.md +76 -0
- package/.claude/settings.json +112 -0
- package/.claude/settings.local.json +19 -0
- package/.claude/skills/claws-auto-engine/SKILL.md +97 -0
- package/.claude/skills/claws-goal-tracker/SKILL.md +106 -0
- package/.claude/skills/claws-prompt-templates/SKILL.md +203 -0
- package/.claude/skills/claws-wave-lead/SKILL.md +126 -0
- package/.claude/skills/claws-wave-subworker/SKILL.md +60 -0
- package/CHANGELOG.md +1949 -0
- package/LICENSE +21 -0
- package/README.md +420 -0
- package/bin/cli.js +84 -0
- package/cli.js +223 -0
- package/docs/ARCHITECTURE.md +511 -0
- package/docs/event-protocol.md +588 -0
- package/docs/features.md +562 -0
- package/docs/guide.md +891 -0
- package/docs/index.html +716 -0
- package/docs/protocol.md +323 -0
- package/extension/.vscodeignore +15 -0
- package/extension/CHANGELOG.md +1906 -0
- package/extension/LICENSE +21 -0
- package/extension/README.md +137 -0
- package/extension/docs/features.md +424 -0
- package/extension/docs/protocol.md +197 -0
- package/extension/esbuild.mjs +25 -0
- package/extension/icon.png +0 -0
- package/extension/native/.metadata.json +10 -0
- package/extension/native/node-pty/LICENSE +69 -0
- package/extension/native/node-pty/README.md +165 -0
- package/extension/native/node-pty/lib/conpty_console_list_agent.js +16 -0
- package/extension/native/node-pty/lib/conpty_console_list_agent.js.map +1 -0
- package/extension/native/node-pty/lib/eventEmitter2.js +47 -0
- package/extension/native/node-pty/lib/eventEmitter2.js.map +1 -0
- package/extension/native/node-pty/lib/index.js +52 -0
- package/extension/native/node-pty/lib/index.js.map +1 -0
- package/extension/native/node-pty/lib/interfaces.js +7 -0
- package/extension/native/node-pty/lib/interfaces.js.map +1 -0
- package/extension/native/node-pty/lib/shared/conout.js +11 -0
- package/extension/native/node-pty/lib/shared/conout.js.map +1 -0
- package/extension/native/node-pty/lib/terminal.js +190 -0
- package/extension/native/node-pty/lib/terminal.js.map +1 -0
- package/extension/native/node-pty/lib/types.js +7 -0
- package/extension/native/node-pty/lib/types.js.map +1 -0
- package/extension/native/node-pty/lib/unixTerminal.js +346 -0
- package/extension/native/node-pty/lib/unixTerminal.js.map +1 -0
- package/extension/native/node-pty/lib/utils.js +39 -0
- package/extension/native/node-pty/lib/utils.js.map +1 -0
- package/extension/native/node-pty/lib/windowsConoutConnection.js +125 -0
- package/extension/native/node-pty/lib/windowsConoutConnection.js.map +1 -0
- package/extension/native/node-pty/lib/windowsPtyAgent.js +320 -0
- package/extension/native/node-pty/lib/windowsPtyAgent.js.map +1 -0
- package/extension/native/node-pty/lib/windowsTerminal.js +199 -0
- package/extension/native/node-pty/lib/windowsTerminal.js.map +1 -0
- package/extension/native/node-pty/lib/worker/conoutSocketWorker.js +22 -0
- package/extension/native/node-pty/lib/worker/conoutSocketWorker.js.map +1 -0
- package/extension/native/node-pty/package.json +64 -0
- package/extension/native/node-pty/prebuilds/darwin-arm64/pty.node +0 -0
- package/extension/native/node-pty/prebuilds/darwin-arm64/spawn-helper +0 -0
- package/extension/native/node-pty/prebuilds/darwin-x64/pty.node +0 -0
- package/extension/native/node-pty/prebuilds/darwin-x64/spawn-helper +0 -0
- package/extension/native/node-pty/prebuilds/win32-arm64/conpty/OpenConsole.exe +0 -0
- package/extension/native/node-pty/prebuilds/win32-arm64/conpty/conpty.dll +0 -0
- package/extension/native/node-pty/prebuilds/win32-arm64/conpty.node +0 -0
- package/extension/native/node-pty/prebuilds/win32-arm64/conpty_console_list.node +0 -0
- package/extension/native/node-pty/prebuilds/win32-arm64/pty.node +0 -0
- package/extension/native/node-pty/prebuilds/win32-arm64/winpty-agent.exe +0 -0
- package/extension/native/node-pty/prebuilds/win32-arm64/winpty.dll +0 -0
- package/extension/native/node-pty/prebuilds/win32-x64/conpty/OpenConsole.exe +0 -0
- package/extension/native/node-pty/prebuilds/win32-x64/conpty/conpty.dll +0 -0
- package/extension/native/node-pty/prebuilds/win32-x64/conpty.node +0 -0
- package/extension/native/node-pty/prebuilds/win32-x64/conpty_console_list.node +0 -0
- package/extension/native/node-pty/prebuilds/win32-x64/pty.node +0 -0
- package/extension/native/node-pty/prebuilds/win32-x64/winpty-agent.exe +0 -0
- package/extension/native/node-pty/prebuilds/win32-x64/winpty.dll +0 -0
- package/extension/package-lock.json +605 -0
- package/extension/package.json +343 -0
- package/extension/scripts/bundle-native.mjs +104 -0
- package/extension/scripts/deploy-dev.mjs +60 -0
- package/extension/src/ansi-strip.ts +52 -0
- package/extension/src/backends/vscode/claws-pty.ts +483 -0
- package/extension/src/backends/vscode/status-bar.ts +99 -0
- package/extension/src/backends/vscode/vscode-backend.ts +282 -0
- package/extension/src/capture-store.ts +125 -0
- package/extension/src/event-log.ts +629 -0
- package/extension/src/event-schemas.ts +478 -0
- package/extension/src/extension.js +492 -0
- package/extension/src/extension.ts +873 -0
- package/extension/src/lifecycle-engine.ts +60 -0
- package/extension/src/lifecycle-rules.ts +171 -0
- package/extension/src/lifecycle-store.ts +506 -0
- package/extension/src/peer-registry.ts +176 -0
- package/extension/src/pipeline-registry.ts +82 -0
- package/extension/src/platform.ts +64 -0
- package/extension/src/protocol.ts +532 -0
- package/extension/src/server-config.ts +98 -0
- package/extension/src/server.ts +2210 -0
- package/extension/src/task-registry.ts +51 -0
- package/extension/src/terminal-backend.ts +211 -0
- package/extension/src/terminal-manager.ts +395 -0
- package/extension/src/topic-registry.ts +70 -0
- package/extension/src/topic-utils.ts +46 -0
- package/extension/src/transport.ts +45 -0
- package/extension/src/uninstall-cleanup.ts +232 -0
- package/extension/src/wave-registry.ts +314 -0
- package/extension/src/websocket-transport.ts +153 -0
- package/extension/tsconfig.json +23 -0
- package/lib/capabilities.js +145 -0
- package/lib/dry-run.js +43 -0
- package/lib/install.js +1018 -0
- package/lib/mcp-setup.js +92 -0
- package/lib/platform.js +240 -0
- package/lib/preflight.js +152 -0
- package/lib/shell-hook.js +343 -0
- package/lib/uninstall.js +162 -0
- package/lib/verify.js +166 -0
- package/mcp_server.js +3529 -0
- package/package.json +48 -0
- package/rules/claws-default-behavior.md +72 -0
- package/scripts/_helpers/atomic-file.mjs +137 -0
- package/scripts/_helpers/fix-repair.js +64 -0
- package/scripts/_helpers/json-safe.mjs +218 -0
- package/scripts/bump-version.sh +84 -0
- package/scripts/codegen/gen-docs.mjs +61 -0
- package/scripts/codegen/gen-json-schema.mjs +62 -0
- package/scripts/codegen/gen-mcp-tools.mjs +358 -0
- package/scripts/codegen/gen-types.mjs +172 -0
- package/scripts/codegen/index.mjs +42 -0
- package/scripts/dev-hooks/check-extension-dirs.js +77 -0
- package/scripts/dev-hooks/check-open-claws-terminals.js +70 -0
- package/scripts/dev-hooks/check-stale-main.js +55 -0
- package/scripts/dev-hooks/check-tag-pushed.js +51 -0
- package/scripts/dev-hooks/check-tag-vs-main.js +56 -0
- package/scripts/dev-vsix-install.sh +60 -0
- package/scripts/fix.sh +702 -0
- package/scripts/gen-client-types.mjs +81 -0
- package/scripts/git-hooks/pre-commit +31 -0
- package/scripts/hooks/lifecycle-state.js +61 -0
- package/scripts/hooks/package.json +4 -0
- package/scripts/hooks/post-tool-use-claws.js +292 -0
- package/scripts/hooks/pre-bash-no-verify-block.js +72 -0
- package/scripts/hooks/pre-tool-use-claws.js +206 -0
- package/scripts/hooks/session-start-claws.js +97 -0
- package/scripts/hooks/stop-claws.js +88 -0
- package/scripts/inject-claude-md.js +205 -0
- package/scripts/inject-dev-hooks.js +96 -0
- package/scripts/inject-global-claude-md.js +140 -0
- package/scripts/inject-settings-hooks.js +370 -0
- package/scripts/install.ps1 +146 -0
- package/scripts/install.sh +1729 -0
- package/scripts/monitor-arm-watch.js +155 -0
- package/scripts/rebuild-node-pty.sh +245 -0
- package/scripts/report.sh +232 -0
- package/scripts/shell-hook.fish +164 -0
- package/scripts/shell-hook.ps1 +33 -0
- package/scripts/shell-hook.sh +232 -0
- package/scripts/stream-events.js +399 -0
- package/scripts/terminal-wrapper.sh +36 -0
- package/scripts/test-enforcement.sh +132 -0
- package/scripts/test-install.sh +174 -0
- package/scripts/test-installer-parity.sh +135 -0
- package/scripts/test-template-enforcement.sh +76 -0
- package/scripts/uninstall.sh +143 -0
- package/scripts/update.sh +337 -0
- package/scripts/verify-release.sh +323 -0
- package/scripts/verify-wrapped.sh +194 -0
- package/templates/CLAUDE.global.md +135 -0
- package/templates/CLAUDE.project.md +37 -0
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// ── Enums ──────────────────────────────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
export const PHASES = [
|
|
6
|
+
'PLAN', 'SPAWN', 'DEPLOY', 'OBSERVE', 'RECOVER',
|
|
7
|
+
'HARVEST', 'CLEANUP', 'REFLECT', 'FAILED',
|
|
8
|
+
] as const;
|
|
9
|
+
export const PhaseEnum = z.enum(PHASES);
|
|
10
|
+
export type Phase = z.infer<typeof PhaseEnum>;
|
|
11
|
+
|
|
12
|
+
export const EVENT_KINDS = [
|
|
13
|
+
'BLOCKED', 'REQUEST', 'HARVEST', 'ERROR', 'DECISION', 'PROGRESS', 'LOG',
|
|
14
|
+
] as const;
|
|
15
|
+
export const EventKindEnum = z.enum(EVENT_KINDS);
|
|
16
|
+
export type EventKind = z.infer<typeof EventKindEnum>;
|
|
17
|
+
|
|
18
|
+
export const CLAWS_ROLES = ['orchestrator', 'worker', 'observer'] as const;
|
|
19
|
+
export const ClawsRoleEnum = z.enum(CLAWS_ROLES);
|
|
20
|
+
export type ClawsRole = z.infer<typeof ClawsRoleEnum>;
|
|
21
|
+
|
|
22
|
+
export const RESULT_KINDS = ['ok', 'failed', 'cancelled'] as const;
|
|
23
|
+
export const ResultEnum = z.enum(RESULT_KINDS);
|
|
24
|
+
export type ResultKind = z.infer<typeof ResultEnum>;
|
|
25
|
+
|
|
26
|
+
export const HEARTBEAT_KINDS = [
|
|
27
|
+
'progress', 'heartbeat', 'approach', 'error', 'mission_complete', 'mission_failed',
|
|
28
|
+
] as const;
|
|
29
|
+
export const HeartbeatKindEnum = z.enum(HEARTBEAT_KINDS);
|
|
30
|
+
export type HeartbeatKind = z.infer<typeof HeartbeatKindEnum>;
|
|
31
|
+
|
|
32
|
+
export const SEVERITY_LEVELS = ['info', 'warn', 'error', 'fatal'] as const;
|
|
33
|
+
export const SeverityEnum = z.enum(SEVERITY_LEVELS);
|
|
34
|
+
export type SeverityLevel = z.infer<typeof SeverityEnum>;
|
|
35
|
+
|
|
36
|
+
// ── Failure cause ──────────────────────────────────────────────────────────
|
|
37
|
+
// Structured reason attached to a FAILED lifecycle transition. Kept in state
|
|
38
|
+
// so the orchestrator can read it after recovery via plan() and apply
|
|
39
|
+
// corrective direction to the new mission.
|
|
40
|
+
export interface FailureCause {
|
|
41
|
+
phase: string; // phase where failure occurred
|
|
42
|
+
reason: string; // human-readable description
|
|
43
|
+
file_line?: string; // optional code reference e.g. "server.ts:412"
|
|
44
|
+
recovery_hint?: string; // optional guidance for re-plan
|
|
45
|
+
failed_at: string; // ISO timestamp
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ── Universal envelope ─────────────────────────────────────────────────────
|
|
49
|
+
|
|
50
|
+
export const EnvelopeV1 = z.object({
|
|
51
|
+
v: z.literal(1),
|
|
52
|
+
id: z.string().uuid(),
|
|
53
|
+
correlation_id: z.string().uuid().nullable().optional(),
|
|
54
|
+
parent_id: z.string().nullable().optional(),
|
|
55
|
+
from_peer: z.string().min(1),
|
|
56
|
+
from_name: z.string().min(1),
|
|
57
|
+
terminal_id: z.string().nullable().optional(),
|
|
58
|
+
ts_published: z.string().datetime(),
|
|
59
|
+
ts_server: z.string().datetime().optional(),
|
|
60
|
+
// Monotonic per-stream sequence number stamped by the server (optional for
|
|
61
|
+
// backward compat with pre-γ producers that do not set this field).
|
|
62
|
+
sequence: z.number().int().nonnegative().optional(),
|
|
63
|
+
schema: z.string().min(1),
|
|
64
|
+
data: z.unknown(),
|
|
65
|
+
});
|
|
66
|
+
export type Envelope = z.infer<typeof EnvelopeV1>;
|
|
67
|
+
|
|
68
|
+
// ── Worker event schemas ───────────────────────────────────────────────────
|
|
69
|
+
|
|
70
|
+
export const WorkerBootV1 = z.object({
|
|
71
|
+
model: z.string().min(1),
|
|
72
|
+
role: ClawsRoleEnum,
|
|
73
|
+
parent_peer_id: z.string().nullable(),
|
|
74
|
+
mission_summary: z.string().min(1),
|
|
75
|
+
capabilities: z.array(z.string()),
|
|
76
|
+
cwd: z.string().min(1),
|
|
77
|
+
terminal_id: z.string(),
|
|
78
|
+
});
|
|
79
|
+
export type WorkerBoot = z.infer<typeof WorkerBootV1>;
|
|
80
|
+
|
|
81
|
+
export const WorkerPhaseV1 = z.object({
|
|
82
|
+
phase: PhaseEnum,
|
|
83
|
+
prev: PhaseEnum.nullable(),
|
|
84
|
+
transition_reason: z.string().min(1),
|
|
85
|
+
phases_completed: z.array(PhaseEnum),
|
|
86
|
+
metadata: z.record(z.unknown()).optional(),
|
|
87
|
+
});
|
|
88
|
+
export type WorkerPhase = z.infer<typeof WorkerPhaseV1>;
|
|
89
|
+
|
|
90
|
+
export const ArtifactSchema = z.object({
|
|
91
|
+
path: z.string().min(1),
|
|
92
|
+
type: z.string().min(1),
|
|
93
|
+
size_bytes: z.number().nonnegative().optional(),
|
|
94
|
+
});
|
|
95
|
+
export type Artifact = z.infer<typeof ArtifactSchema>;
|
|
96
|
+
|
|
97
|
+
export const WorkerEventV1 = z.object({
|
|
98
|
+
kind: EventKindEnum,
|
|
99
|
+
severity: SeverityEnum,
|
|
100
|
+
message: z.string().min(1),
|
|
101
|
+
request_id: z.string().uuid().optional(),
|
|
102
|
+
data: z.record(z.unknown()).optional(),
|
|
103
|
+
});
|
|
104
|
+
export type WorkerEvent = z.infer<typeof WorkerEventV1>;
|
|
105
|
+
|
|
106
|
+
export const WorkerHeartbeatV1 = z.object({
|
|
107
|
+
// ── Existing fields (now all optional for backward compat) ──
|
|
108
|
+
current_phase: PhaseEnum.optional(),
|
|
109
|
+
time_in_phase_ms: z.number().nonnegative().optional(),
|
|
110
|
+
tokens_used: z.number().nonnegative().optional(),
|
|
111
|
+
cost_usd: z.number().nonnegative().optional(),
|
|
112
|
+
last_event_id: z.string().uuid().nullable().optional(),
|
|
113
|
+
active_sub_workers: z.array(z.string()).optional(),
|
|
114
|
+
|
|
115
|
+
// ── New fields (v0.7.12+ heartbeat-as-conversation) ──
|
|
116
|
+
kind: HeartbeatKindEnum.optional(),
|
|
117
|
+
summary: z.string().optional(),
|
|
118
|
+
current_action: z.string().optional(),
|
|
119
|
+
duration_ms: z.number().nonnegative().optional(),
|
|
120
|
+
tokens_in: z.number().nonnegative().optional(),
|
|
121
|
+
tokens_out: z.number().nonnegative().optional(),
|
|
122
|
+
total_cost_usd: z.number().nonnegative().optional(),
|
|
123
|
+
total_duration_ms: z.number().nonnegative().optional(),
|
|
124
|
+
total_tool_calls: z.number().nonnegative().optional(),
|
|
125
|
+
captured_at: z.string().datetime().optional(),
|
|
126
|
+
correlation_id: z.string().optional(),
|
|
127
|
+
error_detail: z.string().optional(),
|
|
128
|
+
approach_detail: z.array(z.string()).optional(),
|
|
129
|
+
});
|
|
130
|
+
export type WorkerHeartbeat = z.infer<typeof WorkerHeartbeatV1>;
|
|
131
|
+
|
|
132
|
+
export const WorkerCompleteV1 = z.object({
|
|
133
|
+
result: ResultEnum,
|
|
134
|
+
summary: z.string().min(1).optional(),
|
|
135
|
+
artifacts: z.array(ArtifactSchema).optional(),
|
|
136
|
+
phases_completed: z.array(PhaseEnum).optional(),
|
|
137
|
+
total_tokens: z.number().nonnegative().optional(),
|
|
138
|
+
total_cost_usd: z.number().nonnegative().optional(),
|
|
139
|
+
duration_ms: z.number().nonnegative().optional(),
|
|
140
|
+
});
|
|
141
|
+
export type WorkerComplete = z.infer<typeof WorkerCompleteV1>;
|
|
142
|
+
|
|
143
|
+
// ── Command schemas ────────────────────────────────────────────────────────
|
|
144
|
+
|
|
145
|
+
export const CmdApproveV1 = z.object({
|
|
146
|
+
correlation_id: z.string().uuid(),
|
|
147
|
+
payload: z.record(z.unknown()).optional(),
|
|
148
|
+
});
|
|
149
|
+
export type CmdApprove = z.infer<typeof CmdApproveV1>;
|
|
150
|
+
|
|
151
|
+
export const CmdRejectV1 = z.object({
|
|
152
|
+
correlation_id: z.string().uuid(),
|
|
153
|
+
reason: z.string().min(1),
|
|
154
|
+
});
|
|
155
|
+
export type CmdReject = z.infer<typeof CmdRejectV1>;
|
|
156
|
+
|
|
157
|
+
export const CmdAbortV1 = z.object({
|
|
158
|
+
reason: z.string().min(1),
|
|
159
|
+
});
|
|
160
|
+
export type CmdAbort = z.infer<typeof CmdAbortV1>;
|
|
161
|
+
|
|
162
|
+
export const CmdPauseV1 = z.object({});
|
|
163
|
+
export type CmdPause = z.infer<typeof CmdPauseV1>;
|
|
164
|
+
|
|
165
|
+
export const CmdResumeV1 = z.object({});
|
|
166
|
+
export type CmdResume = z.infer<typeof CmdResumeV1>;
|
|
167
|
+
|
|
168
|
+
export const CmdSetPhaseV1 = z.object({
|
|
169
|
+
phase: PhaseEnum,
|
|
170
|
+
reason: z.string().min(1),
|
|
171
|
+
});
|
|
172
|
+
export type CmdSetPhase = z.infer<typeof CmdSetPhaseV1>;
|
|
173
|
+
|
|
174
|
+
export const CmdSpawnV1 = z.object({
|
|
175
|
+
name: z.string().min(1),
|
|
176
|
+
mission: z.string().min(1),
|
|
177
|
+
model: z.string().optional(),
|
|
178
|
+
});
|
|
179
|
+
export type CmdSpawn = z.infer<typeof CmdSpawnV1>;
|
|
180
|
+
|
|
181
|
+
export const CmdInjectTextV1 = z.object({
|
|
182
|
+
text: z.string(),
|
|
183
|
+
paste: z.boolean().optional(),
|
|
184
|
+
});
|
|
185
|
+
export type CmdInjectText = z.infer<typeof CmdInjectTextV1>;
|
|
186
|
+
|
|
187
|
+
// ── System event schemas (server-emitted, not published by clients) ────────
|
|
188
|
+
|
|
189
|
+
export const SystemPeerJoinedV1 = z.object({
|
|
190
|
+
peerId: z.string().min(1),
|
|
191
|
+
role: ClawsRoleEnum,
|
|
192
|
+
peerName: z.string().min(1),
|
|
193
|
+
ts: z.string().datetime(),
|
|
194
|
+
});
|
|
195
|
+
export type SystemPeerJoined = z.infer<typeof SystemPeerJoinedV1>;
|
|
196
|
+
|
|
197
|
+
export const SystemPeerLeftV1 = z.object({
|
|
198
|
+
peerId: z.string().min(1),
|
|
199
|
+
role: ClawsRoleEnum,
|
|
200
|
+
reason: z.enum(['clean', 'crash', 'timeout']),
|
|
201
|
+
});
|
|
202
|
+
export type SystemPeerLeft = z.infer<typeof SystemPeerLeftV1>;
|
|
203
|
+
|
|
204
|
+
export const SystemPeerStaleV1 = z.object({
|
|
205
|
+
peerId: z.string().min(1),
|
|
206
|
+
last_seen: z.number().nonnegative(),
|
|
207
|
+
missed_heartbeats: z.number().nonnegative(),
|
|
208
|
+
});
|
|
209
|
+
export type SystemPeerStale = z.infer<typeof SystemPeerStaleV1>;
|
|
210
|
+
|
|
211
|
+
export const SystemGateFiredV1 = z.object({
|
|
212
|
+
tool: z.string().min(1),
|
|
213
|
+
reason: z.string().min(1),
|
|
214
|
+
peerId: z.string().min(1),
|
|
215
|
+
});
|
|
216
|
+
export type SystemGateFired = z.infer<typeof SystemGateFiredV1>;
|
|
217
|
+
|
|
218
|
+
export const SystemBudgetWarningV1 = z.object({
|
|
219
|
+
current_usd: z.number().nonnegative(),
|
|
220
|
+
threshold_usd: z.number().nonnegative(),
|
|
221
|
+
});
|
|
222
|
+
export type SystemBudgetWarning = z.infer<typeof SystemBudgetWarningV1>;
|
|
223
|
+
|
|
224
|
+
export const SystemMalformedReceivedV1 = z.object({
|
|
225
|
+
from: z.string().min(1),
|
|
226
|
+
topic: z.string().min(1),
|
|
227
|
+
error: z.unknown(),
|
|
228
|
+
});
|
|
229
|
+
export type SystemMalformedReceived = z.infer<typeof SystemMalformedReceivedV1>;
|
|
230
|
+
|
|
231
|
+
// ── Terminal close schemas (server-emitted on every close) ───────────────
|
|
232
|
+
|
|
233
|
+
export const TerminalCloseOriginEnum = z.enum([
|
|
234
|
+
'marker', // worker printed completion marker
|
|
235
|
+
'error', // worker printed error_marker
|
|
236
|
+
'timeout', // watcher timed out
|
|
237
|
+
'orchestrator', // claws_close called by MCP client
|
|
238
|
+
'user', // user clicked X in VS Code (or VS Code reload)
|
|
239
|
+
'pub_complete', // worker published complete event
|
|
240
|
+
'wave_violation', // sub-worker silent past threshold; auto-closed by WaveRegistry
|
|
241
|
+
'idle_timeout', // LH-9: no PTY activity within idle TTL window
|
|
242
|
+
'ttl_max', // LH-9: hard ceiling exceeded since spawn
|
|
243
|
+
]);
|
|
244
|
+
export type TerminalCloseOrigin = z.infer<typeof TerminalCloseOriginEnum>;
|
|
245
|
+
|
|
246
|
+
export const TerminalClosedV1 = z.object({
|
|
247
|
+
terminal_id: z.string(),
|
|
248
|
+
close_origin: TerminalCloseOriginEnum,
|
|
249
|
+
closed_at: z.string().datetime(),
|
|
250
|
+
correlation_id: z.string().optional(),
|
|
251
|
+
marker_line: z.string().nullable().optional(),
|
|
252
|
+
duration_ms: z.number().nonnegative().optional(),
|
|
253
|
+
status: z.enum(['completed', 'failed', 'timeout', 'closed']).optional(),
|
|
254
|
+
});
|
|
255
|
+
export type TerminalClosed = z.infer<typeof TerminalClosedV1>;
|
|
256
|
+
|
|
257
|
+
// ── Vehicle state schemas (server-emitted, not published by clients) ──────
|
|
258
|
+
|
|
259
|
+
export const VEHICLE_STATES = [
|
|
260
|
+
'PROVISIONING', 'BOOTING', 'READY', 'BUSY', 'IDLE', 'CLOSING', 'CLOSED',
|
|
261
|
+
] as const;
|
|
262
|
+
export const VehicleStateEnum = z.enum(VEHICLE_STATES);
|
|
263
|
+
export type VehicleStateName = z.infer<typeof VehicleStateEnum>;
|
|
264
|
+
|
|
265
|
+
export const VehicleStateV1 = z.object({
|
|
266
|
+
terminalId: z.string().min(1),
|
|
267
|
+
from: VehicleStateEnum.nullable(),
|
|
268
|
+
to: VehicleStateEnum,
|
|
269
|
+
ts: z.string().datetime(),
|
|
270
|
+
});
|
|
271
|
+
export type VehicleState = z.infer<typeof VehicleStateV1>;
|
|
272
|
+
|
|
273
|
+
// ── Vehicle content schemas (L5 content detection) ────────────────────────
|
|
274
|
+
|
|
275
|
+
export const CONTENT_TYPES = [
|
|
276
|
+
'shell', 'claude', 'python', 'node', 'vim', 'htop', 'unknown',
|
|
277
|
+
] as const;
|
|
278
|
+
export const ContentTypeEnum = z.enum(CONTENT_TYPES);
|
|
279
|
+
export type ContentType = z.infer<typeof ContentTypeEnum>;
|
|
280
|
+
|
|
281
|
+
export const VehicleContentV1 = z.object({
|
|
282
|
+
terminalId: z.string().min(1),
|
|
283
|
+
contentType: ContentTypeEnum,
|
|
284
|
+
foregroundPid: z.number().int().nonnegative().nullable(),
|
|
285
|
+
basename: z.string().nullable().optional(),
|
|
286
|
+
detectedAt: z.string().datetime(),
|
|
287
|
+
confidence: z.enum(['high', 'low', 'unknown']).optional(),
|
|
288
|
+
});
|
|
289
|
+
export type VehicleContent = z.infer<typeof VehicleContentV1>;
|
|
290
|
+
|
|
291
|
+
// ── Command lifecycle schemas (L6 event taxonomy) ─────────────────────────
|
|
292
|
+
|
|
293
|
+
export const CommandStartV1 = z.object({
|
|
294
|
+
terminalId: z.string().min(1),
|
|
295
|
+
command: z.string().min(1),
|
|
296
|
+
startedAt: z.string().datetime(),
|
|
297
|
+
});
|
|
298
|
+
export type CommandStart = z.infer<typeof CommandStartV1>;
|
|
299
|
+
|
|
300
|
+
export const CommandEndV1 = z.object({
|
|
301
|
+
terminalId: z.string().min(1),
|
|
302
|
+
command: z.string().min(1),
|
|
303
|
+
exitCode: z.number().int().nullable(),
|
|
304
|
+
durationMs: z.number().nonnegative(),
|
|
305
|
+
degraded: z.boolean().optional(),
|
|
306
|
+
endedAt: z.string().datetime(),
|
|
307
|
+
});
|
|
308
|
+
export type CommandEnd = z.infer<typeof CommandEndV1>;
|
|
309
|
+
|
|
310
|
+
// ── Wave army event schemas ────────────────────────────────────────────────
|
|
311
|
+
|
|
312
|
+
export const SUB_WORKER_ROLES = ['lead', 'tester', 'reviewer', 'auditor', 'bench', 'doc'] as const;
|
|
313
|
+
export const SubWorkerRoleEnum = z.enum(SUB_WORKER_ROLES);
|
|
314
|
+
|
|
315
|
+
export const WaveLeadBootV1 = z.object({
|
|
316
|
+
waveId: z.string().min(1),
|
|
317
|
+
peerName: z.string().min(1),
|
|
318
|
+
layers: z.array(z.string()),
|
|
319
|
+
manifest: z.array(SubWorkerRoleEnum),
|
|
320
|
+
started_at: z.string().datetime(),
|
|
321
|
+
});
|
|
322
|
+
export type WaveLeadBoot = z.infer<typeof WaveLeadBootV1>;
|
|
323
|
+
|
|
324
|
+
export const WaveLeadCompleteV1 = z.object({
|
|
325
|
+
waveId: z.string().min(1),
|
|
326
|
+
status: z.enum(['ok', 'failed', 'partial']),
|
|
327
|
+
commits: z.array(z.string()),
|
|
328
|
+
regression_clean: z.boolean(),
|
|
329
|
+
duration_sec: z.number().nonnegative().optional(),
|
|
330
|
+
});
|
|
331
|
+
export type WaveLeadComplete = z.infer<typeof WaveLeadCompleteV1>;
|
|
332
|
+
|
|
333
|
+
export const WaveTesterRedCompleteV1 = z.object({
|
|
334
|
+
waveId: z.string().min(1),
|
|
335
|
+
test_file: z.string().min(1),
|
|
336
|
+
failing_tests: z.number().nonnegative(),
|
|
337
|
+
ts: z.string().datetime(),
|
|
338
|
+
});
|
|
339
|
+
export type WaveTesterRedComplete = z.infer<typeof WaveTesterRedCompleteV1>;
|
|
340
|
+
|
|
341
|
+
export const WaveReviewFindingV1 = z.object({
|
|
342
|
+
waveId: z.string().min(1),
|
|
343
|
+
severity: z.enum(['CRITICAL', 'HIGH', 'MEDIUM', 'LOW']),
|
|
344
|
+
file: z.string().min(1),
|
|
345
|
+
line: z.number().int().nonnegative().optional(),
|
|
346
|
+
message: z.string().min(1),
|
|
347
|
+
suggested_fix: z.string().optional(),
|
|
348
|
+
});
|
|
349
|
+
export type WaveReviewFinding = z.infer<typeof WaveReviewFindingV1>;
|
|
350
|
+
|
|
351
|
+
export const WaveAuditFindingV1 = z.object({
|
|
352
|
+
waveId: z.string().min(1),
|
|
353
|
+
severity: z.enum(['CRITICAL', 'HIGH', 'MEDIUM', 'LOW']),
|
|
354
|
+
category: z.enum(['race_condition', 'schema', 'error_handling', 'regression', 'security']),
|
|
355
|
+
file: z.string().min(1),
|
|
356
|
+
finding: z.string().min(1),
|
|
357
|
+
recommendation: z.string().optional(),
|
|
358
|
+
});
|
|
359
|
+
export type WaveAuditFinding = z.infer<typeof WaveAuditFindingV1>;
|
|
360
|
+
|
|
361
|
+
export const WaveBenchMetricV1 = z.object({
|
|
362
|
+
waveId: z.string().min(1),
|
|
363
|
+
name: z.string().min(1),
|
|
364
|
+
value: z.number(),
|
|
365
|
+
unit: z.string().min(1),
|
|
366
|
+
baseline: z.number().optional(),
|
|
367
|
+
});
|
|
368
|
+
export type WaveBenchMetric = z.infer<typeof WaveBenchMetricV1>;
|
|
369
|
+
|
|
370
|
+
export const WaveDocCompleteV1 = z.object({
|
|
371
|
+
waveId: z.string().min(1),
|
|
372
|
+
files_updated: z.array(z.string()),
|
|
373
|
+
ts: z.string().datetime(),
|
|
374
|
+
});
|
|
375
|
+
export type WaveDocComplete = z.infer<typeof WaveDocCompleteV1>;
|
|
376
|
+
|
|
377
|
+
export const WaveHarvestedV1 = z.object({
|
|
378
|
+
waveId: z.string().min(1),
|
|
379
|
+
orphaned_count: z.number().int().nonnegative(),
|
|
380
|
+
closed_terminals: z.array(z.string()),
|
|
381
|
+
already_closed: z.array(z.string()),
|
|
382
|
+
ts: z.string().datetime(),
|
|
383
|
+
});
|
|
384
|
+
export type WaveHarvested = z.infer<typeof WaveHarvestedV1>;
|
|
385
|
+
|
|
386
|
+
// ── Structured control schemas (L10 deliver-cmd / cmd.ack) ───────────────────
|
|
387
|
+
|
|
388
|
+
export const CmdDeliverV1 = z.object({
|
|
389
|
+
targetPeerId: z.string().min(1),
|
|
390
|
+
cmdTopic: z.string().min(1),
|
|
391
|
+
payload: EnvelopeV1,
|
|
392
|
+
idempotencyKey: z.string().uuid(),
|
|
393
|
+
seq: z.number().int().nonnegative(),
|
|
394
|
+
});
|
|
395
|
+
export type CmdDeliver = z.infer<typeof CmdDeliverV1>;
|
|
396
|
+
|
|
397
|
+
export const CmdAckV1 = z.object({
|
|
398
|
+
seq: z.number().int().nonnegative(),
|
|
399
|
+
status: z.enum(['executed', 'rejected', 'duplicate']),
|
|
400
|
+
correlation_id: z.string().uuid().optional(),
|
|
401
|
+
});
|
|
402
|
+
export type CmdAck = z.infer<typeof CmdAckV1>;
|
|
403
|
+
|
|
404
|
+
// ── Typed RPC schemas (L16) ───────────────────────────────────────────────
|
|
405
|
+
|
|
406
|
+
export const RpcRequestV1 = z.object({
|
|
407
|
+
requestId: z.string().uuid(),
|
|
408
|
+
method: z.string().min(1),
|
|
409
|
+
params: z.record(z.unknown()).optional(),
|
|
410
|
+
callerPeerId: z.string().min(1),
|
|
411
|
+
});
|
|
412
|
+
export type RpcRequest = z.infer<typeof RpcRequestV1>;
|
|
413
|
+
|
|
414
|
+
export const RpcResponseV1 = z.object({
|
|
415
|
+
requestId: z.string().uuid(),
|
|
416
|
+
ok: z.boolean(),
|
|
417
|
+
result: z.unknown().optional(),
|
|
418
|
+
error: z.string().optional(),
|
|
419
|
+
});
|
|
420
|
+
export type RpcResponse = z.infer<typeof RpcResponseV1>;
|
|
421
|
+
|
|
422
|
+
// ── Pipeline schemas (L11 composition) ────────────────────────────────────
|
|
423
|
+
|
|
424
|
+
export const PIPELINE_STEP_STATES = ['active', 'degraded', 'closed'] as const;
|
|
425
|
+
export const PipelineStepStateEnum = z.enum(PIPELINE_STEP_STATES);
|
|
426
|
+
export type PipelineStepStateName = z.infer<typeof PipelineStepStateEnum>;
|
|
427
|
+
|
|
428
|
+
export const PipelineStepV1 = z.object({
|
|
429
|
+
pipelineId: z.string().min(1),
|
|
430
|
+
stepId: z.string().min(1),
|
|
431
|
+
role: z.enum(['source', 'sink']),
|
|
432
|
+
terminalId: z.string().min(1),
|
|
433
|
+
state: PipelineStepStateEnum,
|
|
434
|
+
ts: z.string().datetime(),
|
|
435
|
+
});
|
|
436
|
+
export type PipelineStep = z.infer<typeof PipelineStepV1>;
|
|
437
|
+
|
|
438
|
+
// ── Schema name → Zod schema map (for server validation and SDK use) ───────
|
|
439
|
+
|
|
440
|
+
export const SCHEMA_BY_NAME: Record<string, z.ZodTypeAny> = {
|
|
441
|
+
'worker-boot-v1': WorkerBootV1,
|
|
442
|
+
'worker-phase-v1': WorkerPhaseV1,
|
|
443
|
+
'worker-event-v1': WorkerEventV1,
|
|
444
|
+
'worker-heartbeat-v1': WorkerHeartbeatV1,
|
|
445
|
+
'worker-complete-v1': WorkerCompleteV1,
|
|
446
|
+
'cmd-approve-v1': CmdApproveV1,
|
|
447
|
+
'cmd-reject-v1': CmdRejectV1,
|
|
448
|
+
'cmd-abort-v1': CmdAbortV1,
|
|
449
|
+
'cmd-pause-v1': CmdPauseV1,
|
|
450
|
+
'cmd-resume-v1': CmdResumeV1,
|
|
451
|
+
'cmd-set-phase-v1': CmdSetPhaseV1,
|
|
452
|
+
'cmd-spawn-v1': CmdSpawnV1,
|
|
453
|
+
'cmd-inject-text-v1': CmdInjectTextV1,
|
|
454
|
+
'system-peer-joined-v1': SystemPeerJoinedV1,
|
|
455
|
+
'system-peer-left-v1': SystemPeerLeftV1,
|
|
456
|
+
'system-peer-stale-v1': SystemPeerStaleV1,
|
|
457
|
+
'system-gate-fired-v1': SystemGateFiredV1,
|
|
458
|
+
'system-budget-warning-v1': SystemBudgetWarningV1,
|
|
459
|
+
'system-malformed-received-v1': SystemMalformedReceivedV1,
|
|
460
|
+
'vehicle-state-v1': VehicleStateV1,
|
|
461
|
+
'vehicle-content-v1': VehicleContentV1,
|
|
462
|
+
'command-start-v1': CommandStartV1,
|
|
463
|
+
'command-end-v1': CommandEndV1,
|
|
464
|
+
'wave-lead-boot-v1': WaveLeadBootV1,
|
|
465
|
+
'wave-lead-complete-v1': WaveLeadCompleteV1,
|
|
466
|
+
'wave-tester-red-complete-v1': WaveTesterRedCompleteV1,
|
|
467
|
+
'wave-review-finding-v1': WaveReviewFindingV1,
|
|
468
|
+
'wave-audit-finding-v1': WaveAuditFindingV1,
|
|
469
|
+
'wave-bench-metric-v1': WaveBenchMetricV1,
|
|
470
|
+
'wave-doc-complete-v1': WaveDocCompleteV1,
|
|
471
|
+
'cmd-deliver-v1': CmdDeliverV1,
|
|
472
|
+
'cmd-ack-v1': CmdAckV1,
|
|
473
|
+
'pipeline-step-v1': PipelineStepV1,
|
|
474
|
+
'rpc-request-v1': RpcRequestV1,
|
|
475
|
+
'rpc-response-v1': RpcResponseV1,
|
|
476
|
+
'wave-harvested-v1': WaveHarvestedV1,
|
|
477
|
+
'terminal-closed-v1': TerminalClosedV1,
|
|
478
|
+
};
|