@aiwg/cli 2026.10.15 → 2026.10.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/agentic/code/providers/pi/aiwg-bridge.ts +45 -7
  2. package/dist/src/artifacts/citation-parser.js +7 -6
  3. package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
  4. package/dist/src/artifacts/corpus-tools/cli.js +8 -3
  5. package/dist/src/artifacts/corpus-tools/discovery-log.js +26 -24
  6. package/dist/src/artifacts/corpus-tools/expand-cli.js +3 -2
  7. package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
  8. package/dist/src/artifacts/corpus-tools/expand-queue.js +4 -1
  9. package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
  10. package/dist/src/artifacts/corpus-tools/expand-state.js +17 -1
  11. package/dist/src/artifacts/corpus-tools/expand.js +16 -17
  12. package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
  13. package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
  14. package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
  15. package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
  16. package/dist/src/artifacts/corpus-tools/resolve-cli.js +11 -3
  17. package/dist/src/artifacts/corpus-tools/resolve.js +23 -9
  18. package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
  19. package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
  20. package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
  21. package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
  22. package/dist/src/artifacts/graph-query.js +5 -3
  23. package/dist/src/artifacts/hybrid-query.js +11 -2
  24. package/dist/src/artifacts/index-refresh.js +2 -0
  25. package/dist/src/cli/handlers/daemon.js +17 -1
  26. package/dist/src/cli/handlers/doctor-args.js +10 -5
  27. package/dist/src/cli/handlers/doctor-help.js +4 -1
  28. package/dist/src/cli/handlers/index.js +2 -2
  29. package/dist/src/cli/handlers/models-resource-sample.js +10 -0
  30. package/dist/src/cli/handlers/models.js +3 -2
  31. package/dist/src/cli/handlers/regenerate.js +8 -16
  32. package/dist/src/cli/handlers/sessions.js +7 -7
  33. package/dist/src/cli/handlers/subcommands.js +8 -0
  34. package/dist/src/cli/handlers/update.js +157 -0
  35. package/dist/src/cli/handlers/use.js +14 -4
  36. package/dist/src/cli/handlers/utilities.js +3 -560
  37. package/dist/src/cli/handlers/utility-doctor.js +412 -0
  38. package/dist/src/cli/services/deployment-verification.js +0 -1
  39. package/dist/src/config/aiwg-config.js +2 -1
  40. package/dist/src/config/authorization-cli.js +7 -3
  41. package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
  42. package/dist/src/config/dispatch-thresholds-runtime.mjs +17 -7
  43. package/dist/src/config/framework-aliases.js +12 -0
  44. package/dist/src/config/host-resource-report.d.mts +19 -0
  45. package/dist/src/config/host-resource-report.mjs +80 -0
  46. package/dist/src/config/host-resource-runtime.d.mts +34 -0
  47. package/dist/src/config/host-resource-runtime.mjs +293 -0
  48. package/dist/src/config/installed-selection.js +22 -0
  49. package/dist/src/config/worker-invocation-marker.d.mts +1 -0
  50. package/dist/src/config/worker-invocation-marker.mjs +2 -0
  51. package/dist/src/decision/heldout/access.js +74 -0
  52. package/dist/src/decision/heldout/calibration.js +1 -0
  53. package/dist/src/decision/heldout/collector.js +8 -1
  54. package/dist/src/effects/verifiers/file.js +22 -5
  55. package/dist/src/extensions/claude-attribution.js +82 -0
  56. package/dist/src/extensions/claude-hooks-installer.js +115 -69
  57. package/dist/src/extensions/commands/daemon.js +109 -0
  58. package/dist/src/extensions/commands/definitions.js +5 -89
  59. package/dist/src/gates/heldout.js +17 -7
  60. package/dist/src/lint/check-patterns.js +163 -0
  61. package/dist/src/lint/checks.js +268 -0
  62. package/dist/src/lint/reference-resolution.js +54 -0
  63. package/dist/src/lint/runner.js +3 -465
  64. package/dist/src/mcp/helpers.mjs +11 -1
  65. package/dist/src/memory/project-registry.js +44 -4
  66. package/dist/src/models/worker-plan.js +36 -5
  67. package/dist/src/models/wrapper-deployment.js +25 -12
  68. package/dist/src/models/wrapper-enforcement.js +47 -7
  69. package/dist/src/network-analysis/research.js +2 -1
  70. package/dist/src/policy/hitl-check.js +14 -4
  71. package/dist/src/policy/hitl-consume.js +54 -0
  72. package/dist/src/policy/hitl-receipt.js +2 -0
  73. package/dist/src/policy/hitl.js +11 -3
  74. package/dist/src/providers/provider-context-contracts.js +162 -0
  75. package/dist/src/providers/provider-definition-schema.js +136 -0
  76. package/dist/src/providers/provider-definitions.js +8 -1298
  77. package/dist/src/providers/provider-seeds-1.js +360 -0
  78. package/dist/src/providers/provider-seeds-2.js +387 -0
  79. package/dist/src/providers/provider-seeds-3.js +262 -0
  80. package/dist/src/research/clients/arxiv.js +4 -30
  81. package/dist/src/research/clients/base.js +48 -22
  82. package/dist/src/research/identity.js +34 -2
  83. package/dist/src/research/query-cli.js +3 -87
  84. package/dist/src/research/query-options.js +87 -0
  85. package/dist/src/research/reference-match.js +70 -24
  86. package/dist/src/research/services/acquisition.js +9 -7
  87. package/dist/src/research/services/citation.js +5 -2
  88. package/dist/src/research/types.js +2 -0
  89. package/dist/src/serve/mission-conductor.js +48 -4
  90. package/dist/src/sessions/adapters/grok-build-native.js +23 -0
  91. package/dist/src/sessions/adapters/grok-build.js +14 -7
  92. package/dist/src/sessions/workspace-discovery.js +5 -5
  93. package/dist/src/smiths/context-pipeline/aiwg-md.js +16 -46
  94. package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
  95. package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
  96. package/dist/src/smiths/context-pipeline/finalization.js +81 -51
  97. package/dist/src/smiths/context-pipeline/generator.js +9 -10
  98. package/dist/src/smiths/context-pipeline/managed-hook.js +1 -1
  99. package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
  100. package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
  101. package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
  102. package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
  103. package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
  104. package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
  105. package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
  106. package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
  107. package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
  108. package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
  109. package/package.json +10 -1
  110. package/schemas/decision/D29Study.v10.schema.json +65 -0
  111. package/tools/agents/deploy-agents.mjs +10 -0
  112. package/tools/agents/providers/claude-post-deploy.mjs +12 -1
  113. package/tools/agents/providers/context-write.mjs +4 -0
  114. package/tools/agents/providers/pi.mjs +3 -1
  115. package/tools/agents/providers/rule-delivery-surface.mjs +332 -0
  116. package/tools/agents/providers/rule-delivery.mjs +20 -1144
  117. package/tools/agents/providers/rule-deployment-commit.mjs +144 -0
  118. package/tools/agents/providers/rule-deployment-prepare.mjs +452 -0
  119. package/tools/agents/providers/rule-deployment-state.mjs +300 -0
  120. package/tools/daemon/README.md +511 -0
  121. package/tools/daemon/adapters/base-adapter.mjs +84 -0
  122. package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
  123. package/tools/daemon/agent-supervisor.mjs +299 -0
  124. package/tools/daemon/automation-engine.mjs +310 -0
  125. package/tools/daemon/autonomous-engine.mjs +346 -0
  126. package/tools/daemon/behavior-loader.mjs +316 -0
  127. package/tools/daemon/behavior.mjs +174 -0
  128. package/tools/daemon/concierge/intent-router.mjs +401 -0
  129. package/tools/daemon/concierge/orchestrator.mjs +272 -0
  130. package/tools/daemon/concierge/response-translator.mjs +462 -0
  131. package/tools/daemon/config.mjs +377 -0
  132. package/tools/daemon/cron-scheduler.mjs +178 -0
  133. package/tools/daemon/daemon-main.mjs +1169 -0
  134. package/tools/daemon/event-router.mjs +84 -0
  135. package/tools/daemon/file-watcher.mjs +383 -0
  136. package/tools/daemon/index.mjs +1181 -0
  137. package/tools/daemon/init-profile.mjs +124 -0
  138. package/tools/daemon/ipc-client.mjs +197 -0
  139. package/tools/daemon/ipc-ops-handlers.mjs +236 -0
  140. package/tools/daemon/ipc-server.mjs +275 -0
  141. package/tools/daemon/maintenance-owner.mjs +79 -0
  142. package/tools/daemon/memory-manager.mjs +386 -0
  143. package/tools/daemon/message-router.mjs +194 -0
  144. package/tools/daemon/provider-watcher.mjs +585 -0
  145. package/tools/daemon/pty-adapter.mjs +420 -0
  146. package/tools/daemon/repl-chat.mjs +359 -0
  147. package/tools/daemon/resource-bounds.mjs +88 -0
  148. package/tools/daemon/sandbox-transport.mjs +295 -0
  149. package/tools/daemon/scheduled-task-runner.mjs +535 -0
  150. package/tools/daemon/task-store.mjs +450 -0
  151. package/tools/daemon/tmux-manager.mjs +324 -0
  152. package/tools/daemon/update-policy.mjs +517 -0
  153. package/tools/daemon/web-server.mjs +399 -0
  154. package/tools/daemon/web-ui/index.html +585 -0
  155. package/tools/daemon/web-ui/styles.css +156 -0
  156. package/tools/docker/Dockerfile.daemon +35 -0
  157. package/tools/docker/container-manager.mjs +291 -0
  158. package/tools/messaging/adapter-registry.mjs +230 -0
  159. package/tools/messaging/adapters/base.mjs +326 -0
  160. package/tools/messaging/adapters/discord.mjs +462 -0
  161. package/tools/messaging/adapters/slack.mjs +402 -0
  162. package/tools/messaging/adapters/telegram.mjs +552 -0
  163. package/tools/messaging/chat-handler.mjs +297 -0
  164. package/tools/messaging/command-router.mjs +269 -0
  165. package/tools/messaging/event-bus.mjs +199 -0
  166. package/tools/messaging/index.mjs +456 -0
  167. package/tools/messaging/message-formatter.mjs +320 -0
  168. package/tools/messaging/room-manager.mjs +277 -0
  169. package/tools/messaging/types.mjs +94 -0
  170. package/tools/providers/pi-bridge-policy.mjs +4 -0
  171. package/tools/ralph-external/daemon-supervisor.mjs +394 -0
  172. package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
  173. package/tools/ralph-external/lib/worker-invocation-processes.mjs +3 -2
  174. package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
  175. package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
  176. package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
  177. package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
  178. package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
  179. package/tools/ralph-external/session-launcher.mjs +7 -7
  180. package/tools/scripts/resource-preflight.mjs +3 -242
@@ -0,0 +1,295 @@
1
+ /**
2
+ * Sandbox gRPC Transport for PTY Adapter
3
+ *
4
+ * Implements PTY-like I/O by bridging to an agentic-sandbox management server
5
+ * via gRPC. Used when AIWG_SANDBOX_ENDPOINT is set, enabling container and VM
6
+ * execution modes for platform TUIs.
7
+ *
8
+ * Protocol mapping (agentic-sandbox proto → PTY adapter):
9
+ * CommandRequest { allocate_pty: true } → start()
10
+ * StdinChunk { data } → write()
11
+ * PtyControl { resize } → resize()
12
+ * PtyControl { signal: SIGTERM } → stop()
13
+ * OutputChunk { data } → emit('data')
14
+ * SessionQuery/SessionReport → list() / reconnect
15
+ *
16
+ * @issue #657
17
+ * @see agentic-sandbox proto/agent.proto
18
+ */
19
+
20
+ import { EventEmitter } from 'events';
21
+ import { randomUUID } from 'crypto';
22
+
23
+ /**
24
+ * SandboxTransport wraps a gRPC connection to an agentic-sandbox management
25
+ * server and exposes the same PTY-like interface as node-pty.
26
+ *
27
+ * This is NOT a full gRPC bidirectional stream implementation — it uses the
28
+ * management server's HTTP REST API (port 8122) as a simpler integration path
29
+ * that avoids requiring @grpc/grpc-js at runtime. The management server bridges
30
+ * HTTP → gRPC internally.
31
+ *
32
+ * Events:
33
+ * 'data' (chunk: string) — output from the remote PTY
34
+ * 'exit' ({ exitCode }) — remote PTY process exited
35
+ * 'error' (err: Error) — connection or protocol error
36
+ */
37
+ export class SandboxTransport extends EventEmitter {
38
+ /**
39
+ * @param {object} opts
40
+ * @param {string} opts.httpEndpoint - Management server HTTP endpoint (e.g., 'http://localhost:8122')
41
+ * @param {string} opts.agentId - Target agent ID on the sandbox
42
+ * @param {string} opts.command - Command to execute (e.g., 'claude')
43
+ * @param {string[]} [opts.args] - Command arguments
44
+ * @param {number} [opts.cols] - Terminal width (default: 120)
45
+ * @param {number} [opts.rows] - Terminal height (default: 30)
46
+ * @param {string} [opts.cwd] - Working directory on the remote agent
47
+ */
48
+ constructor({
49
+ httpEndpoint,
50
+ agentId,
51
+ command,
52
+ args = [],
53
+ cols = 120,
54
+ rows = 30,
55
+ cwd = '/home/agent',
56
+ }) {
57
+ super();
58
+ this.httpEndpoint = httpEndpoint.replace(/\/$/, '');
59
+ this.agentId = agentId;
60
+ this.command = command;
61
+ this.args = args;
62
+ this.cols = cols;
63
+ this.rows = rows;
64
+ this.cwd = cwd;
65
+ this.commandId = null;
66
+ this.taskId = null;
67
+ this._stopped = false;
68
+ this._pollTimer = null;
69
+ this._logOffset = 0;
70
+ }
71
+
72
+ /**
73
+ * Start a PTY session on the remote sandbox agent.
74
+ * Submits a task manifest and begins polling for output.
75
+ *
76
+ * @returns {Promise<string>} The command/task ID for this session
77
+ */
78
+ async start() {
79
+ // Submit task via REST API — the management server dispatches to the agent
80
+ const cmdLine = [this.command, ...this.args].join(' ');
81
+ const manifest = {
82
+ manifest_yaml: [
83
+ 'version: "1"',
84
+ 'kind: Task',
85
+ 'metadata:',
86
+ ` name: "pty-${this.agentId}-${Date.now()}"`,
87
+ ' labels:',
88
+ ' aiwg_transport: pty',
89
+ 'claude:',
90
+ ` prompt: "${cmdLine}"`,
91
+ ' headless: true',
92
+ ' skip_permissions: true',
93
+ 'vm:',
94
+ ' profile: agentic-dev',
95
+ ].join('\n'),
96
+ };
97
+
98
+ try {
99
+ const resp = await fetch(`${this.httpEndpoint}/api/v1/tasks`, {
100
+ method: 'POST',
101
+ headers: { 'Content-Type': 'application/json' },
102
+ body: JSON.stringify(manifest),
103
+ });
104
+
105
+ if (!resp.ok) {
106
+ const body = await resp.text().catch(() => '');
107
+ throw new Error(`Task submission failed: ${resp.status} ${body}`);
108
+ }
109
+
110
+ const result = await resp.json();
111
+ this.taskId = result.task_id;
112
+ this.commandId = this.taskId;
113
+
114
+ // Start polling for output via SSE log stream
115
+ this._startLogPoll();
116
+
117
+ return this.commandId;
118
+ } catch (err) {
119
+ this.emit('error', err instanceof Error ? err : new Error(String(err)));
120
+ throw err;
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Reconnect to an existing session by task ID.
126
+ * @param {string} taskId - The task ID to reconnect to
127
+ * @returns {Promise<string>} The task ID
128
+ */
129
+ async reconnect(taskId) {
130
+ this.taskId = taskId;
131
+ this.commandId = taskId;
132
+
133
+ // Verify the task exists and is still running
134
+ try {
135
+ const resp = await fetch(`${this.httpEndpoint}/api/v1/tasks/${taskId}`);
136
+ if (!resp.ok) throw new Error(`Task ${taskId} not found`);
137
+ const task = await resp.json();
138
+ if (task.state === 'completed' || task.state === 'failed' || task.state === 'cancelled') {
139
+ this.emit('exit', { exitCode: task.state === 'completed' ? 0 : 1 });
140
+ return taskId;
141
+ }
142
+ } catch (err) {
143
+ this.emit('error', err instanceof Error ? err : new Error(String(err)));
144
+ throw err;
145
+ }
146
+
147
+ this._startLogPoll();
148
+ return taskId;
149
+ }
150
+
151
+ /**
152
+ * Send input to the remote PTY (stdin).
153
+ * Uses the management server's WebSocket hub on port 8121.
154
+ * Falls back to HTTP if WS is not available.
155
+ *
156
+ * @param {string} data - Input text to send
157
+ */
158
+ write(data) {
159
+ if (this._stopped || !this.commandId) return;
160
+
161
+ // Use HTTP endpoint to send stdin via the management API
162
+ // The management server will route this to the agent's PTY via gRPC StdinChunk
163
+ const wsEndpoint = this.httpEndpoint.replace(/:\d+$/, ':8121');
164
+ // For now, send via HTTP — WS stdin requires an active WS connection
165
+ // which is handled by the browser's xterm.js connecting directly to :8121
166
+ fetch(`${this.httpEndpoint}/api/v1/tasks/${this.taskId}`, {
167
+ method: 'PATCH',
168
+ headers: { 'Content-Type': 'application/json' },
169
+ body: JSON.stringify({ stdin: data }),
170
+ }).catch(() => {
171
+ // stdin delivery failure is non-fatal — log but don't throw
172
+ });
173
+ }
174
+
175
+ /**
176
+ * Resize the remote PTY terminal.
177
+ * @param {number} cols
178
+ * @param {number} rows
179
+ */
180
+ resize(cols, rows) {
181
+ if (this._stopped || !this.commandId) return;
182
+ this.cols = cols;
183
+ this.rows = rows;
184
+ // PTY resize is handled by the WS connection from the browser
185
+ // The sandbox management server processes PtyControl { resize } messages
186
+ // from the connected WebSocket client at :8121
187
+ }
188
+
189
+ /**
190
+ * Stop the remote PTY session.
191
+ * Cancels the task on the management server.
192
+ *
193
+ * @returns {Promise<void>}
194
+ */
195
+ async stop() {
196
+ if (this._stopped) return;
197
+ this._stopped = true;
198
+ this._stopLogPoll();
199
+
200
+ if (this.taskId) {
201
+ try {
202
+ await fetch(`${this.httpEndpoint}/api/v1/tasks/${this.taskId}`, {
203
+ method: 'DELETE',
204
+ });
205
+ } catch {
206
+ // Best-effort cancellation
207
+ }
208
+ }
209
+
210
+ this.emit('exit', { exitCode: 0, signal: 'SIGTERM' });
211
+ }
212
+
213
+ /** @returns {boolean} Whether the session is active */
214
+ isActive() { return !this._stopped && this.commandId !== null; }
215
+
216
+ /** @returns {string|null} The task/command ID */
217
+ getCommandId() { return this.commandId; }
218
+
219
+ /**
220
+ * List active sessions on the remote sandbox.
221
+ * @returns {Promise<Array<{taskId, name, state, agentId}>>}
222
+ */
223
+ async listSessions() {
224
+ try {
225
+ const resp = await fetch(`${this.httpEndpoint}/api/v1/tasks?state=running`);
226
+ if (!resp.ok) return [];
227
+ const data = await resp.json();
228
+ return (data.tasks || []).map((t) => ({
229
+ taskId: t.id,
230
+ name: t.name,
231
+ state: t.state,
232
+ agentId: t.agent_id,
233
+ }));
234
+ } catch {
235
+ return [];
236
+ }
237
+ }
238
+
239
+ // ---- Internal: log polling ----
240
+
241
+ _startLogPoll() {
242
+ if (this._pollTimer) return;
243
+ this._pollTimer = setInterval(() => this._pollLogs(), 500);
244
+ // Immediate first poll
245
+ this._pollLogs();
246
+ }
247
+
248
+ _stopLogPoll() {
249
+ if (this._pollTimer) {
250
+ clearInterval(this._pollTimer);
251
+ this._pollTimer = null;
252
+ }
253
+ }
254
+
255
+ async _pollLogs() {
256
+ if (this._stopped || !this.taskId) return;
257
+
258
+ try {
259
+ const resp = await fetch(
260
+ `${this.httpEndpoint}/api/v1/tasks/${this.taskId}/logs?offset=${this._logOffset}`,
261
+ );
262
+ if (!resp.ok) {
263
+ if (resp.status === 404) {
264
+ // Task no longer exists
265
+ this._stopped = true;
266
+ this._stopLogPoll();
267
+ this.emit('exit', { exitCode: 0 });
268
+ }
269
+ return;
270
+ }
271
+
272
+ const text = await resp.text();
273
+ if (text.length > 0) {
274
+ this._logOffset += text.length;
275
+ this.emit('data', text);
276
+ }
277
+
278
+ // Check task status
279
+ const statusResp = await fetch(`${this.httpEndpoint}/api/v1/tasks/${this.taskId}`);
280
+ if (statusResp.ok) {
281
+ const task = await statusResp.json();
282
+ if (['completed', 'failed', 'cancelled'].includes(task.state)) {
283
+ this._stopped = true;
284
+ this._stopLogPoll();
285
+ this.emit('exit', {
286
+ exitCode: task.state === 'completed' ? 0 : 1,
287
+ signal: task.state === 'cancelled' ? 'SIGTERM' : undefined,
288
+ });
289
+ }
290
+ }
291
+ } catch {
292
+ // Network error — will retry on next poll
293
+ }
294
+ }
295
+ }