@aiwg/cli 2026.10.15 → 2026.10.18
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/agentic/code/providers/pi/aiwg-bridge.ts +45 -7
- package/dist/src/artifacts/citation-parser.js +7 -6
- package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
- package/dist/src/artifacts/corpus-tools/cli.js +8 -3
- package/dist/src/artifacts/corpus-tools/discovery-log.js +26 -24
- package/dist/src/artifacts/corpus-tools/expand-cli.js +3 -2
- package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
- package/dist/src/artifacts/corpus-tools/expand-queue.js +4 -1
- package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
- package/dist/src/artifacts/corpus-tools/expand-state.js +17 -1
- package/dist/src/artifacts/corpus-tools/expand.js +16 -17
- package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
- package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
- package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
- package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
- package/dist/src/artifacts/corpus-tools/resolve-cli.js +11 -3
- package/dist/src/artifacts/corpus-tools/resolve.js +42 -11
- package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
- package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
- package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
- package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
- package/dist/src/artifacts/graph-query.js +5 -3
- package/dist/src/artifacts/hybrid-query.js +11 -2
- package/dist/src/artifacts/index-refresh.js +2 -0
- package/dist/src/artifacts/query-engine-corpus.js +217 -0
- package/dist/src/artifacts/query-engine-discover-output.js +229 -0
- package/dist/src/artifacts/query-engine-discover.js +285 -0
- package/dist/src/artifacts/query-engine-entries.js +188 -0
- package/dist/src/artifacts/query-engine-index.js +249 -0
- package/dist/src/artifacts/query-engine-matching.js +143 -0
- package/dist/src/artifacts/query-engine-options.js +2 -0
- package/dist/src/artifacts/query-engine-rules.js +202 -0
- package/dist/src/artifacts/query-engine-scoring.js +436 -0
- package/dist/src/artifacts/query-engine-show-card.js +194 -0
- package/dist/src/artifacts/query-engine-show-load.js +211 -0
- package/dist/src/artifacts/query-engine-show.js +300 -0
- package/dist/src/artifacts/query-engine.js +7 -2576
- package/dist/src/cli/handlers/daemon.js +17 -1
- package/dist/src/cli/handlers/doctor-args.js +10 -5
- package/dist/src/cli/handlers/doctor-help.js +4 -1
- package/dist/src/cli/handlers/index.js +2 -2
- package/dist/src/cli/handlers/mc-agents.js +111 -0
- package/dist/src/cli/handlers/mc-args.js +54 -0
- package/dist/src/cli/handlers/mc-control.js +227 -0
- package/dist/src/cli/handlers/mc-dispatch.js +203 -0
- package/dist/src/cli/handlers/mc-help.js +171 -0
- package/dist/src/cli/handlers/mc-run.js +343 -0
- package/dist/src/cli/handlers/mc-session.js +138 -0
- package/dist/src/cli/handlers/mc-status.js +258 -0
- package/dist/src/cli/handlers/mc-summary.js +43 -0
- package/dist/src/cli/handlers/mc-types.js +3 -0
- package/dist/src/cli/handlers/mc-worker.js +205 -0
- package/dist/src/cli/handlers/mc.js +12 -1665
- package/dist/src/cli/handlers/models-refusal.js +13 -0
- package/dist/src/cli/handlers/models-resource-sample.js +10 -0
- package/dist/src/cli/handlers/models.js +5 -3
- package/dist/src/cli/handlers/regenerate.js +8 -16
- package/dist/src/cli/handlers/remove-bundled.js +133 -0
- package/dist/src/cli/handlers/remove-options.js +31 -0
- package/dist/src/cli/handlers/remove-user.js +174 -0
- package/dist/src/cli/handlers/remove.js +201 -0
- package/dist/src/cli/handlers/sessions.js +7 -7
- package/dist/src/cli/handlers/subcommands-bundles.js +257 -0
- package/dist/src/cli/handlers/subcommands-discovery.js +165 -0
- package/dist/src/cli/handlers/subcommands-list-format.js +129 -0
- package/dist/src/cli/handlers/subcommands-list.js +250 -0
- package/dist/src/cli/handlers/subcommands-plugins.js +213 -0
- package/dist/src/cli/handlers/subcommands-quickref.js +58 -0
- package/dist/src/cli/handlers/subcommands-rlm.js +113 -0
- package/dist/src/cli/handlers/subcommands-services.js +66 -0
- package/dist/src/cli/handlers/subcommands-storage.js +259 -0
- package/dist/src/cli/handlers/subcommands.js +18 -1976
- package/dist/src/cli/handlers/update.js +157 -0
- package/dist/src/cli/handlers/use.js +14 -4
- package/dist/src/cli/handlers/utilities.js +3 -560
- package/dist/src/cli/handlers/utility-doctor.js +412 -0
- package/dist/src/cli/scope-resolver.js +1 -142
- package/dist/src/cli/services/deployment-verification.js +0 -1
- package/dist/src/cli/user-scope-mirror.js +173 -0
- package/dist/src/config/aiwg-config.js +2 -1
- package/dist/src/config/authorization-cli.js +7 -3
- package/dist/src/config/dispatch-host-thresholds.js +2 -0
- package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
- package/dist/src/config/dispatch-thresholds-runtime.mjs +21 -7
- package/dist/src/config/framework-aliases.js +12 -0
- package/dist/src/config/host-resource-report.d.mts +24 -0
- package/dist/src/config/host-resource-report.mjs +110 -0
- package/dist/src/config/host-resource-runtime.d.mts +37 -0
- package/dist/src/config/host-resource-runtime.mjs +296 -0
- package/dist/src/config/installed-selection.js +22 -0
- package/dist/src/config/worker-invocation-marker.d.mts +1 -0
- package/dist/src/config/worker-invocation-marker.mjs +2 -0
- package/dist/src/decision/ensemble-study/artifacts.js +7 -0
- package/dist/src/decision/ensemble-study/gate-policy.js +58 -0
- package/dist/src/decision/ensemble-study/gates.js +78 -0
- package/dist/src/decision/ensemble-study/protocol.js +18 -21
- package/dist/src/decision/ensemble-study/score.js +3 -2
- package/dist/src/decision/ensemble-study/statistics.js +7 -26
- package/dist/src/decision/heldout/access.js +74 -0
- package/dist/src/decision/heldout/calibration.js +1 -0
- package/dist/src/decision/heldout/collector.js +8 -1
- package/dist/src/decision/sensitivity/comparative-gates.js +135 -0
- package/dist/src/decision/sensitivity/comparative.js +18 -41
- package/dist/src/effects/verifiers/file.js +22 -5
- package/dist/src/extensions/claude-attribution.js +82 -0
- package/dist/src/extensions/claude-hooks-installer.js +133 -69
- package/dist/src/extensions/commands/daemon.js +109 -0
- package/dist/src/extensions/commands/definitions.js +5 -89
- package/dist/src/gates/evaluate.js +2 -358
- package/dist/src/gates/heldout.js +17 -7
- package/dist/src/gates/observations.js +363 -0
- package/dist/src/gates/pack-composition.js +270 -0
- package/dist/src/gates/pack-tightening.js +197 -0
- package/dist/src/gates/pack-validation.js +262 -0
- package/dist/src/gates/registry-error.js +5 -0
- package/dist/src/gates/registry.js +13 -685
- package/dist/src/lint/check-patterns.js +163 -0
- package/dist/src/lint/checks.js +268 -0
- package/dist/src/lint/reference-resolution.js +54 -0
- package/dist/src/lint/runner.js +3 -465
- package/dist/src/mcp/helpers.mjs +11 -1
- package/dist/src/mcp/json-document.mjs +29 -0
- package/dist/src/mcp/muse-native-config.mjs +1 -28
- package/dist/src/memory/project-registry.js +44 -4
- package/dist/src/mission-protocol/worker-review-gate.js +7 -0
- package/dist/src/models/worker-plan.js +36 -5
- package/dist/src/models/wrapper-deployment.js +25 -12
- package/dist/src/models/wrapper-enforcement.js +47 -7
- package/dist/src/network-analysis/research.js +2 -1
- package/dist/src/plugin/command-ownership.js +34 -0
- package/dist/src/plugin/skill-command-frontmatter.js +197 -0
- package/dist/src/plugin/skill-command-translator.js +6 -232
- package/dist/src/policy/hitl-check.js +14 -4
- package/dist/src/policy/hitl-consume.js +54 -0
- package/dist/src/policy/hitl-receipt.js +2 -0
- package/dist/src/policy/hitl.js +11 -3
- package/dist/src/providers/context-output-ownership.js +26 -0
- package/dist/src/providers/deployment-ownership.d.mts +19 -0
- package/dist/src/providers/deployment-ownership.mjs +226 -0
- package/dist/src/providers/deployment-removal.js +200 -0
- package/dist/src/providers/provider-context-contracts.js +162 -0
- package/dist/src/providers/provider-definition-schema.js +136 -0
- package/dist/src/providers/provider-definitions.js +8 -1298
- package/dist/src/providers/provider-seeds-1.js +360 -0
- package/dist/src/providers/provider-seeds-2.js +387 -0
- package/dist/src/providers/provider-seeds-3.js +262 -0
- package/dist/src/providers/removal-transaction.js +86 -0
- package/dist/src/providers/settings-document.d.mts +3 -0
- package/dist/src/providers/settings-document.mjs +47 -0
- package/dist/src/providers/settings-removal.js +190 -0
- package/dist/src/providers/skill-ownership.d.mts +19 -2
- package/dist/src/providers/skill-ownership.mjs +12 -4
- package/dist/src/providers/transformation-receipt-integration.js +15 -271
- package/dist/src/providers/transformation-receipt-outputs.js +99 -0
- package/dist/src/providers/transformation-receipt-source.js +194 -0
- package/dist/src/research/clients/arxiv.js +4 -30
- package/dist/src/research/clients/base.js +48 -22
- package/dist/src/research/identity.js +42 -4
- package/dist/src/research/query-cli.js +3 -87
- package/dist/src/research/query-options.js +87 -0
- package/dist/src/research/reference-match.js +105 -24
- package/dist/src/research/services/acquisition.js +9 -7
- package/dist/src/research/services/citation.js +5 -2
- package/dist/src/research/types.js +2 -0
- package/dist/src/rules/activation.mjs +15 -6
- package/dist/src/rules/core-startup.mjs +2 -2
- package/dist/src/serve/mission-conductor.js +52 -4
- package/dist/src/serve/mission-summary.js +56 -0
- package/dist/src/sessions/adapters/grok-build-native.js +23 -0
- package/dist/src/sessions/adapters/grok-build.js +14 -7
- package/dist/src/sessions/workspace-discovery.js +5 -5
- package/dist/src/smiths/context-pipeline/aiwg-md.js +39 -46
- package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
- package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
- package/dist/src/smiths/context-pipeline/context-file-safety.js +3 -0
- package/dist/src/smiths/context-pipeline/finalization.js +81 -51
- package/dist/src/smiths/context-pipeline/generator.js +10 -11
- package/dist/src/smiths/context-pipeline/managed-hook.js +1 -1
- package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
- package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
- package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
- package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
- package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
- package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
- package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
- package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
- package/dist/src/smiths/hook-bridge/index.js +9 -0
- package/package.json +13 -1
- package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
- package/schemas/decision/D29Study.v10.schema.json +65 -0
- package/tools/agents/deploy-agents.mjs +24 -675
- package/tools/agents/deploy-command-mirrors.mjs +229 -0
- package/tools/agents/deploy-options.mjs +258 -0
- package/tools/agents/deploy-support.mjs +165 -0
- package/tools/agents/providers/base-addon-discovery.mjs +139 -0
- package/tools/agents/providers/base-behaviors.mjs +168 -0
- package/tools/agents/providers/base-context.mjs +205 -0
- package/tools/agents/providers/base-contract.mjs +116 -0
- package/tools/agents/providers/base-files.mjs +252 -0
- package/tools/agents/providers/base-flat-artifacts.mjs +233 -0
- package/tools/agents/providers/base-framework-discovery.mjs +309 -0
- package/tools/agents/providers/base-frontmatter.mjs +196 -0
- package/tools/agents/providers/base-inventory.mjs +269 -0
- package/tools/agents/providers/base-kernel-skills.mjs +354 -0
- package/tools/agents/providers/base-migrations.mjs +258 -0
- package/tools/agents/providers/base-models-platforms.mjs +273 -0
- package/tools/agents/providers/base-rule-index.mjs +450 -0
- package/tools/agents/providers/base-runtime.mjs +60 -0
- package/tools/agents/providers/base-skill-copy.mjs +273 -0
- package/tools/agents/providers/base.mjs +16 -3364
- package/tools/agents/providers/claude-post-deploy.mjs +20 -1
- package/tools/agents/providers/context-write.mjs +4 -0
- package/tools/agents/providers/hermes-startup.mjs +0 -5
- package/tools/agents/providers/muse.mjs +7 -2
- package/tools/agents/providers/pi.mjs +3 -1
- package/tools/agents/providers/rule-delivery-surface.mjs +359 -0
- package/tools/agents/providers/rule-delivery.mjs +20 -1144
- package/tools/agents/providers/rule-deployment-commit.mjs +148 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +461 -0
- package/tools/agents/providers/rule-deployment-state.mjs +300 -0
- package/tools/agents/providers/rule-projection.mjs +3 -0
- package/tools/daemon/README.md +511 -0
- package/tools/daemon/adapters/base-adapter.mjs +84 -0
- package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
- package/tools/daemon/agent-supervisor.mjs +299 -0
- package/tools/daemon/automation-engine.mjs +310 -0
- package/tools/daemon/autonomous-engine.mjs +346 -0
- package/tools/daemon/behavior-loader.mjs +316 -0
- package/tools/daemon/behavior.mjs +174 -0
- package/tools/daemon/concierge/intent-router.mjs +401 -0
- package/tools/daemon/concierge/orchestrator.mjs +272 -0
- package/tools/daemon/concierge/response-translator.mjs +462 -0
- package/tools/daemon/config.mjs +377 -0
- package/tools/daemon/cron-scheduler.mjs +178 -0
- package/tools/daemon/daemon-main.mjs +1169 -0
- package/tools/daemon/event-router.mjs +84 -0
- package/tools/daemon/file-watcher.mjs +383 -0
- package/tools/daemon/index.mjs +1181 -0
- package/tools/daemon/init-profile.mjs +124 -0
- package/tools/daemon/ipc-client.mjs +197 -0
- package/tools/daemon/ipc-ops-handlers.mjs +236 -0
- package/tools/daemon/ipc-server.mjs +275 -0
- package/tools/daemon/maintenance-owner.mjs +79 -0
- package/tools/daemon/memory-manager.mjs +386 -0
- package/tools/daemon/message-router.mjs +194 -0
- package/tools/daemon/provider-watcher.mjs +585 -0
- package/tools/daemon/pty-adapter.mjs +420 -0
- package/tools/daemon/repl-chat.mjs +359 -0
- package/tools/daemon/resource-bounds.mjs +88 -0
- package/tools/daemon/sandbox-transport.mjs +295 -0
- package/tools/daemon/scheduled-task-runner.mjs +535 -0
- package/tools/daemon/task-store.mjs +450 -0
- package/tools/daemon/tmux-manager.mjs +324 -0
- package/tools/daemon/update-policy.mjs +517 -0
- package/tools/daemon/web-server.mjs +399 -0
- package/tools/daemon/web-ui/index.html +585 -0
- package/tools/daemon/web-ui/styles.css +156 -0
- package/tools/docker/Dockerfile.daemon +35 -0
- package/tools/docker/container-manager.mjs +291 -0
- package/tools/messaging/adapter-registry.mjs +230 -0
- package/tools/messaging/adapters/base.mjs +326 -0
- package/tools/messaging/adapters/discord.mjs +462 -0
- package/tools/messaging/adapters/slack.mjs +402 -0
- package/tools/messaging/adapters/telegram.mjs +552 -0
- package/tools/messaging/chat-handler.mjs +297 -0
- package/tools/messaging/command-router.mjs +269 -0
- package/tools/messaging/event-bus.mjs +199 -0
- package/tools/messaging/index.mjs +456 -0
- package/tools/messaging/message-formatter.mjs +320 -0
- package/tools/messaging/room-manager.mjs +277 -0
- package/tools/messaging/types.mjs +94 -0
- package/tools/providers/pi-bridge-policy.mjs +4 -0
- package/tools/ralph-external/daemon-supervisor.mjs +394 -0
- package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +7 -4
- package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
- package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
- package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
- package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
- package/tools/ralph-external/lib/worker-termination.mjs +15 -8
- package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
- package/tools/ralph-external/session-launcher.mjs +7 -7
- package/tools/scripts/resource-preflight.mjs +3 -242
- package/vscode-extension/schemas/aiwg.config.v1.json +2 -4
|
@@ -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
|
+
}
|