@aiwg/cli 2026.10.14 → 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 (210) hide show
  1. package/agentic/code/addons/aiwg-utils/rules/anti-laziness.core.md +13 -0
  2. package/agentic/code/addons/aiwg-utils/rules/anti-laziness.md +118 -0
  3. package/agentic/code/providers/pi/aiwg-bridge.ts +45 -7
  4. package/dist/src/artifacts/citation-parser.js +7 -6
  5. package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
  6. package/dist/src/artifacts/corpus-tools/cli.js +37 -0
  7. package/dist/src/artifacts/corpus-tools/discovery-log.js +27 -25
  8. package/dist/src/artifacts/corpus-tools/expand-cli.js +90 -0
  9. package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
  10. package/dist/src/artifacts/corpus-tools/expand-queue.js +41 -0
  11. package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
  12. package/dist/src/artifacts/corpus-tools/expand-state.js +56 -0
  13. package/dist/src/artifacts/corpus-tools/expand.js +124 -0
  14. package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
  15. package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
  16. package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
  17. package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
  18. package/dist/src/artifacts/corpus-tools/resolve-cli.js +99 -0
  19. package/dist/src/artifacts/corpus-tools/resolve-corpus.js +41 -0
  20. package/dist/src/artifacts/corpus-tools/resolve.js +119 -0
  21. package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
  22. package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
  23. package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
  24. package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
  25. package/dist/src/artifacts/graph-query.js +5 -3
  26. package/dist/src/artifacts/hybrid-query.js +11 -2
  27. package/dist/src/artifacts/index-refresh.js +2 -0
  28. package/dist/src/cli/handlers/daemon.js +17 -1
  29. package/dist/src/cli/handlers/doctor-args.js +45 -0
  30. package/dist/src/cli/handlers/doctor-help.js +8 -3
  31. package/dist/src/cli/handlers/index.js +2 -2
  32. package/dist/src/cli/handlers/models-resource-sample.js +10 -0
  33. package/dist/src/cli/handlers/models.js +3 -2
  34. package/dist/src/cli/handlers/regenerate.js +8 -16
  35. package/dist/src/cli/handlers/sessions.js +7 -7
  36. package/dist/src/cli/handlers/subcommands.js +8 -0
  37. package/dist/src/cli/handlers/update.js +157 -0
  38. package/dist/src/cli/handlers/use.js +14 -4
  39. package/dist/src/cli/handlers/utilities.js +3 -586
  40. package/dist/src/cli/handlers/utility-doctor.js +412 -0
  41. package/dist/src/cli/services/deployment-verification.js +0 -1
  42. package/dist/src/config/aiwg-config.js +2 -1
  43. package/dist/src/config/authorization-cli.js +7 -3
  44. package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
  45. package/dist/src/config/dispatch-thresholds-runtime.mjs +17 -7
  46. package/dist/src/config/framework-aliases.js +12 -0
  47. package/dist/src/config/host-resource-report.d.mts +19 -0
  48. package/dist/src/config/host-resource-report.mjs +80 -0
  49. package/dist/src/config/host-resource-runtime.d.mts +34 -0
  50. package/dist/src/config/host-resource-runtime.mjs +293 -0
  51. package/dist/src/config/installed-selection.js +22 -0
  52. package/dist/src/config/worker-context.js +33 -4
  53. package/dist/src/config/worker-invocation-marker.d.mts +1 -0
  54. package/dist/src/config/worker-invocation-marker.mjs +2 -0
  55. package/dist/src/decision/heldout/access.js +74 -0
  56. package/dist/src/decision/heldout/calibration.js +1 -0
  57. package/dist/src/decision/heldout/collector.js +9 -2
  58. package/dist/src/effects/verifiers/file.js +22 -5
  59. package/dist/src/extensions/claude-attribution.js +82 -0
  60. package/dist/src/extensions/claude-hooks-installer.js +115 -69
  61. package/dist/src/extensions/commands/daemon.js +109 -0
  62. package/dist/src/extensions/commands/definitions.js +5 -89
  63. package/dist/src/features/catalog.js +1 -1
  64. package/dist/src/gates/evaluate.js +2 -2
  65. package/dist/src/gates/heldout.js +52 -0
  66. package/dist/src/gates/index.js +2 -1
  67. package/dist/src/lint/check-patterns.js +163 -0
  68. package/dist/src/lint/checks.js +268 -0
  69. package/dist/src/lint/reference-resolution.js +54 -0
  70. package/dist/src/lint/runner.js +3 -465
  71. package/dist/src/mcp/helpers.mjs +11 -1
  72. package/dist/src/memory/project-registry.js +44 -4
  73. package/dist/src/models/worker-installation-store.mjs +228 -0
  74. package/dist/src/models/worker-installation.mjs +7 -162
  75. package/dist/src/models/worker-plan.js +36 -5
  76. package/dist/src/models/wrapper-deployment.js +25 -12
  77. package/dist/src/models/wrapper-enforcement.js +47 -7
  78. package/dist/src/network-analysis/research.js +2 -1
  79. package/dist/src/policy/hitl-check.js +14 -4
  80. package/dist/src/policy/hitl-consume.js +54 -0
  81. package/dist/src/policy/hitl-receipt.js +2 -0
  82. package/dist/src/policy/hitl.js +11 -3
  83. package/dist/src/providers/provider-context-contracts.js +162 -0
  84. package/dist/src/providers/provider-definition-schema.js +136 -0
  85. package/dist/src/providers/provider-definitions.js +8 -1298
  86. package/dist/src/providers/provider-seeds-1.js +360 -0
  87. package/dist/src/providers/provider-seeds-2.js +387 -0
  88. package/dist/src/providers/provider-seeds-3.js +262 -0
  89. package/dist/src/research/clients/arxiv.js +14 -34
  90. package/dist/src/research/clients/base.js +53 -26
  91. package/dist/src/research/clients/crossref.js +9 -1
  92. package/dist/src/research/clients/semantic-scholar.js +73 -44
  93. package/dist/src/research/identity.js +117 -0
  94. package/dist/src/research/index.js +1 -0
  95. package/dist/src/research/query-cli.js +3 -87
  96. package/dist/src/research/query-options.js +87 -0
  97. package/dist/src/research/reference-match.js +135 -0
  98. package/dist/src/research/services/acquisition.js +9 -7
  99. package/dist/src/research/services/citation.js +5 -2
  100. package/dist/src/research/types.js +2 -0
  101. package/dist/src/rules/core-startup.d.mts +2 -0
  102. package/dist/src/rules/core-startup.mjs +31 -0
  103. package/dist/src/serve/mission-conductor.js +48 -4
  104. package/dist/src/sessions/adapters/grok-build-native.js +23 -0
  105. package/dist/src/sessions/adapters/grok-build.js +14 -7
  106. package/dist/src/sessions/workspace-discovery.js +5 -5
  107. package/dist/src/smiths/context-pipeline/agents-md.js +34 -0
  108. package/dist/src/smiths/context-pipeline/aiwg-md.js +19 -46
  109. package/dist/src/smiths/context-pipeline/bridge-ownership.js +50 -0
  110. package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
  111. package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
  112. package/dist/src/smiths/context-pipeline/finalization.js +81 -51
  113. package/dist/src/smiths/context-pipeline/generator.js +49 -114
  114. package/dist/src/smiths/context-pipeline/managed-hook.js +11 -1
  115. package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
  116. package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
  117. package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
  118. package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
  119. package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
  120. package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
  121. package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
  122. package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
  123. package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
  124. package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
  125. package/package.json +13 -2
  126. package/schemas/decision/D29Study.v10.schema.json +65 -0
  127. package/tools/agents/deploy-agents.mjs +12 -123
  128. package/tools/agents/providers/antigravity.mjs +1 -1
  129. package/tools/agents/providers/claude-post-deploy.mjs +12 -1
  130. package/tools/agents/providers/context-write.mjs +16 -0
  131. package/tools/agents/providers/grok-build.mjs +8 -5
  132. package/tools/agents/providers/hermes-skill-lifecycle.mjs +144 -0
  133. package/tools/agents/providers/hermes-startup.mjs +209 -0
  134. package/tools/agents/providers/hermes.mjs +9 -359
  135. package/tools/agents/providers/model-wrapper.mjs +5 -1
  136. package/tools/agents/providers/muse.mjs +3 -3
  137. package/tools/agents/providers/pi.mjs +4 -2
  138. package/tools/agents/providers/rule-delivery-surface.mjs +332 -0
  139. package/tools/agents/providers/rule-delivery.mjs +20 -1346
  140. package/tools/agents/providers/rule-deployment-commit.mjs +144 -0
  141. package/tools/agents/providers/rule-deployment-prepare.mjs +452 -0
  142. package/tools/agents/providers/rule-deployment-state.mjs +300 -0
  143. package/tools/agents/providers/rule-presentation.mjs +13 -4
  144. package/tools/agents/providers/rule-projection.mjs +119 -0
  145. package/tools/agents/providers/rule-startup.mjs +70 -0
  146. package/tools/agents/providers/stale-artifact-prune.mjs +128 -0
  147. package/tools/agents/providers/warp.mjs +2 -2
  148. package/tools/agents/providers/windsurf.mjs +11 -57
  149. package/tools/daemon/README.md +511 -0
  150. package/tools/daemon/adapters/base-adapter.mjs +84 -0
  151. package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
  152. package/tools/daemon/agent-supervisor.mjs +299 -0
  153. package/tools/daemon/automation-engine.mjs +310 -0
  154. package/tools/daemon/autonomous-engine.mjs +346 -0
  155. package/tools/daemon/behavior-loader.mjs +316 -0
  156. package/tools/daemon/behavior.mjs +174 -0
  157. package/tools/daemon/concierge/intent-router.mjs +401 -0
  158. package/tools/daemon/concierge/orchestrator.mjs +272 -0
  159. package/tools/daemon/concierge/response-translator.mjs +462 -0
  160. package/tools/daemon/config.mjs +377 -0
  161. package/tools/daemon/cron-scheduler.mjs +178 -0
  162. package/tools/daemon/daemon-main.mjs +1169 -0
  163. package/tools/daemon/event-router.mjs +84 -0
  164. package/tools/daemon/file-watcher.mjs +383 -0
  165. package/tools/daemon/index.mjs +1181 -0
  166. package/tools/daemon/init-profile.mjs +124 -0
  167. package/tools/daemon/ipc-client.mjs +197 -0
  168. package/tools/daemon/ipc-ops-handlers.mjs +236 -0
  169. package/tools/daemon/ipc-server.mjs +275 -0
  170. package/tools/daemon/maintenance-owner.mjs +79 -0
  171. package/tools/daemon/memory-manager.mjs +386 -0
  172. package/tools/daemon/message-router.mjs +194 -0
  173. package/tools/daemon/provider-watcher.mjs +585 -0
  174. package/tools/daemon/pty-adapter.mjs +420 -0
  175. package/tools/daemon/repl-chat.mjs +359 -0
  176. package/tools/daemon/resource-bounds.mjs +88 -0
  177. package/tools/daemon/sandbox-transport.mjs +295 -0
  178. package/tools/daemon/scheduled-task-runner.mjs +535 -0
  179. package/tools/daemon/task-store.mjs +450 -0
  180. package/tools/daemon/tmux-manager.mjs +324 -0
  181. package/tools/daemon/update-policy.mjs +517 -0
  182. package/tools/daemon/web-server.mjs +399 -0
  183. package/tools/daemon/web-ui/index.html +585 -0
  184. package/tools/daemon/web-ui/styles.css +156 -0
  185. package/tools/docker/Dockerfile.daemon +35 -0
  186. package/tools/docker/container-manager.mjs +291 -0
  187. package/tools/messaging/adapter-registry.mjs +230 -0
  188. package/tools/messaging/adapters/base.mjs +326 -0
  189. package/tools/messaging/adapters/discord.mjs +462 -0
  190. package/tools/messaging/adapters/slack.mjs +402 -0
  191. package/tools/messaging/adapters/telegram.mjs +552 -0
  192. package/tools/messaging/chat-handler.mjs +297 -0
  193. package/tools/messaging/command-router.mjs +269 -0
  194. package/tools/messaging/event-bus.mjs +199 -0
  195. package/tools/messaging/index.mjs +456 -0
  196. package/tools/messaging/message-formatter.mjs +320 -0
  197. package/tools/messaging/room-manager.mjs +277 -0
  198. package/tools/messaging/types.mjs +94 -0
  199. package/tools/plugin/plugin-links.mjs +3 -0
  200. package/tools/providers/pi-bridge-policy.mjs +4 -0
  201. package/tools/ralph-external/daemon-supervisor.mjs +394 -0
  202. package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
  203. package/tools/ralph-external/lib/worker-invocation-processes.mjs +3 -2
  204. package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
  205. package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
  206. package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
  207. package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
  208. package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
  209. package/tools/ralph-external/session-launcher.mjs +7 -7
  210. package/tools/scripts/resource-preflight.mjs +3 -242
@@ -0,0 +1,359 @@
1
+ /**
2
+ * REPL Chat Interface - Interactive conversation with claude -p streaming
3
+ *
4
+ * Provides a readline-based chat interface that spawns claude -p for AI reasoning,
5
+ * streams output back to the user, and handles agent notifications.
6
+ *
7
+ * @implements @.aiwg/requirements/use-cases/UC-REPL-001.md
8
+ * @tests @test/unit/daemon/repl-chat.test.js
9
+ */
10
+
11
+ import { importImpl } from '../_resolve-impl.mjs';
12
+ import { spawn } from 'node:child_process';
13
+ import { EventEmitter } from 'node:events';
14
+ const { signalChild } = await importImpl(import.meta.url, 'process/signal-child.mjs');
15
+
16
+ export class REPLChat extends EventEmitter {
17
+ constructor(options = {}) {
18
+ super();
19
+ this.agentCommand = options.agentCommand || 'claude';
20
+ this.agentArgs = options.agentArgs || [];
21
+ this.cwd = options.cwd || process.cwd();
22
+ this.activeProcess = null;
23
+ this.running = false;
24
+ this.inputQueue = [];
25
+ this.history = [];
26
+ this.maxHistory = options.maxHistory || 100;
27
+ this.readline = null;
28
+ this.outputHandler = options.outputHandler || null;
29
+ this.promptString = options.prompt || 'aiwg> ';
30
+ this.supervisor = options.supervisor || null;
31
+ }
32
+
33
+ /**
34
+ * Start the REPL chat interface
35
+ * @param {object} rlInterface - A readline.Interface instance (injected for testability)
36
+ */
37
+ async start(rlInterface) {
38
+ if (this.running) return;
39
+ this.running = true;
40
+
41
+ this.readline = rlInterface;
42
+
43
+ if (this.readline) {
44
+ this.readline.on('line', (line) => {
45
+ this._handleInput(line.trim());
46
+ });
47
+
48
+ this.readline.on('close', () => {
49
+ this.stop();
50
+ });
51
+
52
+ this.readline.setPrompt(this.promptString);
53
+ this.readline.prompt();
54
+ }
55
+
56
+ this.emit('started');
57
+ }
58
+
59
+ /**
60
+ * Stop the REPL chat interface
61
+ */
62
+ stop() {
63
+ if (!this.running) return;
64
+ this.running = false;
65
+
66
+ if (this.activeProcess) {
67
+ try {
68
+ signalChild(this.activeProcess, 'SIGTERM');
69
+ } catch {
70
+ // Process may have already exited
71
+ }
72
+ this.activeProcess = null;
73
+ }
74
+
75
+ if (this.readline) {
76
+ this.readline.close();
77
+ this.readline = null;
78
+ }
79
+
80
+ this.emit('stopped');
81
+ }
82
+
83
+ /**
84
+ * Send a message to be processed by the AI
85
+ * Can be called programmatically (e.g., from IPC)
86
+ */
87
+ async sendMessage(message) {
88
+ if (!this.running) {
89
+ throw new Error('REPL is not running');
90
+ }
91
+
92
+ if (this.activeProcess) {
93
+ this.inputQueue.push(message);
94
+ this.emit('queued', { message, queueSize: this.inputQueue.length });
95
+ return;
96
+ }
97
+
98
+ await this._processMessage(message);
99
+ }
100
+
101
+ /**
102
+ * Get chat history
103
+ */
104
+ getHistory() {
105
+ return [...this.history];
106
+ }
107
+
108
+ /**
109
+ * Check if AI is currently processing
110
+ */
111
+ get isProcessing() {
112
+ return this.activeProcess !== null;
113
+ }
114
+
115
+ /**
116
+ * Get queue size
117
+ */
118
+ get queueSize() {
119
+ return this.inputQueue.length;
120
+ }
121
+
122
+ // --- Private methods ---
123
+
124
+ _handleInput(input) {
125
+ if (!input) {
126
+ if (this.readline) this.readline.prompt();
127
+ return;
128
+ }
129
+
130
+ // Handle built-in commands
131
+ if (input.startsWith('/')) {
132
+ this._handleCommand(input);
133
+ return;
134
+ }
135
+
136
+ this.sendMessage(input);
137
+ }
138
+
139
+ _handleCommand(input) {
140
+ const parts = input.slice(1).split(/\s+/);
141
+ const command = parts[0].toLowerCase();
142
+ const args = parts.slice(1);
143
+
144
+ switch (command) {
145
+ case 'quit':
146
+ case 'exit':
147
+ this.stop();
148
+ return;
149
+
150
+ case 'cancel':
151
+ if (this.activeProcess) {
152
+ try {
153
+ signalChild(this.activeProcess, 'SIGTERM');
154
+ } catch {
155
+ // Already dead
156
+ }
157
+ this._write('\n[Cancelled]\n');
158
+ } else {
159
+ this._write('No active process to cancel\n');
160
+ }
161
+ break;
162
+
163
+ case 'status':
164
+ this._showStatus();
165
+ break;
166
+
167
+ case 'history':
168
+ this._showHistory();
169
+ break;
170
+
171
+ case 'tasks':
172
+ this._showTasks();
173
+ break;
174
+
175
+ case 'run': {
176
+ const prompt = args.join(' ');
177
+ if (!prompt) {
178
+ this._write('Usage: /run <prompt>\n');
179
+ } else if (this.supervisor) {
180
+ const task = this.supervisor.submit(prompt);
181
+ this._write(`Task submitted: ${task.id}\n`);
182
+ } else {
183
+ this._write('No agent supervisor available\n');
184
+ }
185
+ break;
186
+ }
187
+
188
+ case 'help':
189
+ this._showHelp();
190
+ break;
191
+
192
+ default:
193
+ this._write(`Unknown command: /${command}. Type /help for available commands.\n`);
194
+ }
195
+
196
+ if (this.readline && this.running) {
197
+ this.readline.prompt();
198
+ }
199
+ }
200
+
201
+ async _processMessage(message) {
202
+ this.history.push({ role: 'user', content: message, timestamp: new Date().toISOString() });
203
+
204
+ if (this.history.length > this.maxHistory) {
205
+ this.history.shift();
206
+ }
207
+
208
+ this.emit('message:sent', { message });
209
+
210
+ const args = [...this.agentArgs, '-p', message];
211
+ let stdout = '';
212
+
213
+ try {
214
+ this.activeProcess = spawn(this.agentCommand, args, {
215
+ cwd: this.cwd,
216
+ stdio: ['ignore', 'pipe', 'pipe'],
217
+ env: { ...process.env },
218
+ });
219
+
220
+ this.emit('processing:start', { message });
221
+
222
+ this.activeProcess.stdout.on('data', (chunk) => {
223
+ const text = chunk.toString();
224
+ stdout += text;
225
+ this._write(text);
226
+ this.emit('output', { chunk: text, stream: 'stdout' });
227
+ });
228
+
229
+ this.activeProcess.stderr.on('data', (chunk) => {
230
+ const text = chunk.toString();
231
+ this.emit('output', { chunk: text, stream: 'stderr' });
232
+ });
233
+
234
+ await new Promise((resolve, reject) => {
235
+ this.activeProcess.on('exit', (code, signal) => {
236
+ this.activeProcess = null;
237
+
238
+ if (signal === 'SIGTERM' || signal === 'SIGKILL') {
239
+ resolve();
240
+ } else if (code === 0) {
241
+ this.history.push({
242
+ role: 'assistant',
243
+ content: stdout,
244
+ timestamp: new Date().toISOString(),
245
+ });
246
+
247
+ if (this.history.length > this.maxHistory) {
248
+ this.history.shift();
249
+ }
250
+ resolve();
251
+ } else {
252
+ reject(new Error(`Process exited with code ${code}`));
253
+ }
254
+ });
255
+
256
+ this.activeProcess.on('error', (err) => {
257
+ this.activeProcess = null;
258
+ reject(err);
259
+ });
260
+ });
261
+ } catch (err) {
262
+ this._write(`\n[Error: ${err.message}]\n`);
263
+ this.emit('error', err);
264
+ }
265
+
266
+ this.emit('processing:end');
267
+ this._write('\n');
268
+
269
+ // Process next queued message
270
+ if (this.inputQueue.length > 0) {
271
+ const next = this.inputQueue.shift();
272
+ await this._processMessage(next);
273
+ } else if (this.readline && this.running) {
274
+ this.readline.prompt();
275
+ }
276
+ }
277
+
278
+ _write(text) {
279
+ if (this.outputHandler) {
280
+ this.outputHandler(text);
281
+ } else {
282
+ process.stdout.write(text);
283
+ }
284
+ }
285
+
286
+ _showStatus() {
287
+ const lines = [
288
+ '--- Status ---',
289
+ `Running: ${this.running}`,
290
+ `Processing: ${this.isProcessing}`,
291
+ `Queue: ${this.inputQueue.length} message(s)`,
292
+ `History: ${this.history.length} entries`,
293
+ ];
294
+
295
+ if (this.supervisor) {
296
+ const status = this.supervisor.getStatus();
297
+ lines.push(`Agents running: ${status.running}`);
298
+ lines.push(`Agents queued: ${status.queued}`);
299
+ }
300
+
301
+ this._write(lines.join('\n') + '\n');
302
+ }
303
+
304
+ _showHistory() {
305
+ if (this.history.length === 0) {
306
+ this._write('No chat history\n');
307
+ return;
308
+ }
309
+
310
+ const recent = this.history.slice(-10);
311
+ for (const entry of recent) {
312
+ const prefix = entry.role === 'user' ? 'You' : 'AI';
313
+ const preview = entry.content.slice(0, 80).replace(/\n/g, ' ');
314
+ this._write(`[${prefix}] ${preview}${entry.content.length > 80 ? '...' : ''}\n`);
315
+ }
316
+ }
317
+
318
+ _showTasks() {
319
+ if (!this.supervisor) {
320
+ this._write('No agent supervisor available\n');
321
+ return;
322
+ }
323
+
324
+ const status = this.supervisor.getStatus();
325
+
326
+ if (status.tasks.running.length === 0 && status.tasks.queued.length === 0) {
327
+ this._write('No active tasks\n');
328
+ return;
329
+ }
330
+
331
+ if (status.tasks.running.length > 0) {
332
+ this._write('Running:\n');
333
+ for (const t of status.tasks.running) {
334
+ this._write(` ${t.id}: ${t.prompt} (PID ${t.pid})\n`);
335
+ }
336
+ }
337
+
338
+ if (status.tasks.queued.length > 0) {
339
+ this._write('Queued:\n');
340
+ for (const t of status.tasks.queued) {
341
+ this._write(` ${t.id}: ${t.prompt}\n`);
342
+ }
343
+ }
344
+ }
345
+
346
+ _showHelp() {
347
+ this._write([
348
+ '--- Commands ---',
349
+ '/help - Show this help',
350
+ '/status - Show REPL and agent status',
351
+ '/history - Show recent chat history',
352
+ '/tasks - Show running and queued agent tasks',
353
+ '/run <msg> - Submit background agent task',
354
+ '/cancel - Cancel current AI processing',
355
+ '/quit - Exit the REPL',
356
+ '',
357
+ ].join('\n'));
358
+ }
359
+ }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Validated resource bounds for the housekeeper profile (epic #3353 slice B6).
3
+ *
4
+ * Single source of truth for safe defaults; the runner (concurrency, queue,
5
+ * timeout clamp, child niceness) and the file watcher (watch-handle cap)
6
+ * enforce the normalized values, and `tools/daemon/config.mjs` validates the
7
+ * `resources` config block against the same ranges.
8
+ */
9
+
10
+ import os from 'node:os';
11
+ import { spawnSync } from 'node:child_process';
12
+ import { importImpl } from '../_resolve-impl.mjs';
13
+
14
+ const { helperEnvironment } = await importImpl(import.meta.url, 'process/cli-command.mjs');
15
+
16
+ export const RESOURCE_DEFAULTS = Object.freeze({
17
+ /** Max owner executions in flight at once; further runs wait in the queue. */
18
+ maxConcurrentJobs: 2,
19
+ /** Max runs waiting for a slot; beyond it the run overflows (deferred). */
20
+ maxQueueDepth: 16,
21
+ /** Global ceiling clamped over every per-job timeoutMs. */
22
+ maxTimeoutMs: 600000,
23
+ /** CPU niceness applied to job children (higher = lower priority). */
24
+ jobNiceness: 10,
25
+ /** Max native watch handles; beyond it roots fall back to polling. */
26
+ maxWatchHandles: 64,
27
+ });
28
+
29
+ const RANGES = {
30
+ maxConcurrentJobs: [1, 8],
31
+ maxQueueDepth: [0, 1024],
32
+ maxTimeoutMs: [1000, 3600000],
33
+ jobNiceness: [-20, 19],
34
+ maxWatchHandles: [1, 512],
35
+ };
36
+
37
+ /** Validate a raw `resources` block. Returns `{ config, errors }`. */
38
+ export function normalizeResources(raw) {
39
+ const errors = [];
40
+ const source = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
41
+ if (raw !== undefined && (typeof raw !== 'object' || Array.isArray(raw) || raw === null)) {
42
+ return { config: { ...RESOURCE_DEFAULTS }, errors: ['resources must be an object'] };
43
+ }
44
+ const config = { ...RESOURCE_DEFAULTS };
45
+ for (const [key, [min, max]] of Object.entries(RANGES)) {
46
+ if (source[key] === undefined) continue;
47
+ const value = source[key];
48
+ if (!Number.isInteger(value) || value < min || value > max) {
49
+ errors.push(`resources.${key} must be an integer between ${min} and ${max}`);
50
+ continue;
51
+ }
52
+ config[key] = value;
53
+ }
54
+ for (const key of Object.keys(source)) {
55
+ if (!Object.hasOwn(RANGES, key)) errors.push(`resources.${key} is not a known resource bound`);
56
+ }
57
+ return { config, errors };
58
+ }
59
+
60
+ /**
61
+ * Lower a job child's scheduling priority best-effort. CPU niceness via
62
+ * `os.setPriority`; on Linux additionally request the idle IO class. Never
63
+ * throws: a child that keeps default priority still runs under the timeout
64
+ * and concurrency bounds.
65
+ */
66
+ export function applyChildNiceness(pid, { niceness = RESOURCE_DEFAULTS.jobNiceness } = {}) {
67
+ if (!Number.isSafeInteger(pid) || pid <= 0) return { applied: false, reason: 'invalid-pid' };
68
+ if (!Number.isInteger(niceness) || niceness < -20 || niceness > 19) {
69
+ return { applied: false, reason: 'invalid-niceness' };
70
+ }
71
+ try {
72
+ os.setPriority(pid, niceness);
73
+ } catch {
74
+ return { applied: false, reason: 'setpriority-unavailable' };
75
+ }
76
+ if (process.platform === 'linux') {
77
+ try {
78
+ const probe = spawnSync('ionice', ['-c', '3', '-p', String(pid)], {
79
+ timeout: 5000, killSignal: 'SIGKILL', env: helperEnvironment(),
80
+ });
81
+ if (probe.error || probe.status !== 0) return { applied: true, ioIdle: false };
82
+ return { applied: true, ioIdle: true };
83
+ } catch {
84
+ return { applied: true, ioIdle: false };
85
+ }
86
+ }
87
+ return { applied: true, ioIdle: false };
88
+ }