@caupulican/pi-adaptative 0.84.1 → 0.85.3
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/CHANGELOG.md +53 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +14 -8
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +14 -8
- package/dist/bundled-resources/runtimes/pi-shell-engine/arithmetic.py +364 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +2 -1
- package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +16 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +137 -14
- package/dist/bundled-resources/runtimes/pi-shell-engine/nodes.py +23 -2
- package/dist/bundled-resources/runtimes/pi-shell-engine/parser.py +134 -6
- package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +25 -2
- package/dist/bundled-resources/skills/deduplicate-by-evidence/SKILL.md +7 -5
- package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +63 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +8 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +4 -2
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +3 -0
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +6 -0
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/compaction-controller.d.ts +2 -0
- package/dist/core/compaction-controller.d.ts.map +1 -1
- package/dist/core/compaction-controller.js +35 -13
- package/dist/core/compaction-controller.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +1 -0
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +7 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +28 -0
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.d.ts +2 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.js +46 -11
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
- package/dist/core/doctor.d.ts +1 -1
- package/dist/core/doctor.d.ts.map +1 -1
- package/dist/core/doctor.js +5 -4
- package/dist/core/doctor.js.map +1 -1
- package/dist/core/failure-corpus.d.ts +26 -1
- package/dist/core/failure-corpus.d.ts.map +1 -1
- package/dist/core/failure-corpus.js +17 -0
- package/dist/core/failure-corpus.js.map +1 -1
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +1 -0
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-tool-protocol.d.ts +3 -2
- package/dist/core/model-tool-protocol.d.ts.map +1 -1
- package/dist/core/model-tool-protocol.js +5 -1
- package/dist/core/model-tool-protocol.js.map +1 -1
- package/dist/core/models/runtime-process.d.ts +7 -1
- package/dist/core/models/runtime-process.d.ts.map +1 -1
- package/dist/core/models/runtime-process.js +4 -2
- package/dist/core/models/runtime-process.js.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.js +6 -1
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
- package/dist/core/orchestration/session-task-profile-store.d.ts +31 -0
- package/dist/core/orchestration/session-task-profile-store.d.ts.map +1 -0
- package/dist/core/orchestration/session-task-profile-store.js +138 -0
- package/dist/core/orchestration/session-task-profile-store.js.map +1 -0
- package/dist/core/orchestration/task-profile-writer.d.ts +58 -0
- package/dist/core/orchestration/task-profile-writer.d.ts.map +1 -0
- package/dist/core/orchestration/task-profile-writer.js +165 -0
- package/dist/core/orchestration/task-profile-writer.js.map +1 -0
- package/dist/core/process-matrix/runtime.js +43 -11
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/resource-loader.d.ts +2 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +18 -6
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +3 -1
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +14 -0
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
- package/dist/core/security/untrusted-boundary.js +4 -6
- package/dist/core/security/untrusted-boundary.js.map +1 -1
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +1 -0
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +21 -23
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tool-capability-policy.js +1 -1
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/tool-recovery-log-records.d.ts +33 -1
- package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
- package/dist/core/tool-recovery-log-records.js +59 -12
- package/dist/core/tool-recovery-log-records.js.map +1 -1
- package/dist/core/tool-recovery-logger.d.ts +12 -1
- package/dist/core/tool-recovery-logger.d.ts.map +1 -1
- package/dist/core/tool-recovery-logger.js +24 -1
- package/dist/core/tool-recovery-logger.js.map +1 -1
- package/dist/core/tool-repair-health.d.ts.map +1 -1
- package/dist/core/tool-repair-health.js +6 -0
- package/dist/core/tool-repair-health.js.map +1 -1
- package/dist/core/tools/bash.d.ts +3 -8
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +4 -28
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate.js +4 -4
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +32 -5
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +137 -69
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +22 -7
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +128 -55
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-intent.d.ts +70 -0
- package/dist/core/tools/file-mutation-intent.d.ts.map +1 -0
- package/dist/core/tools/file-mutation-intent.js +325 -0
- package/dist/core/tools/file-mutation-intent.js.map +1 -0
- package/dist/core/tools/find.d.ts +2 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +2 -6
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +41 -18
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/grep.d.ts +2 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +2 -6
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +3 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +31 -8
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/managed-search-tool.d.ts +8 -0
- package/dist/core/tools/managed-search-tool.d.ts.map +1 -0
- package/dist/core/tools/managed-search-tool.js +10 -0
- package/dist/core/tools/managed-search-tool.js.map +1 -0
- package/dist/core/tools/profile-writer.d.ts +33 -0
- package/dist/core/tools/profile-writer.d.ts.map +1 -0
- package/dist/core/tools/profile-writer.js +67 -0
- package/dist/core/tools/profile-writer.js.map +1 -0
- package/dist/core/tools/shell-command-parser.d.ts +4 -3
- package/dist/core/tools/shell-command-parser.d.ts.map +1 -1
- package/dist/core/tools/shell-command-parser.js +32 -7
- package/dist/core/tools/shell-command-parser.js.map +1 -1
- package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
- package/dist/core/tools/shell-contract-router.js +23 -1
- package/dist/core/tools/shell-contract-router.js.map +1 -1
- package/dist/core/tools/task-steps.d.ts.map +1 -1
- package/dist/core/tools/task-steps.js +6 -11
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tmux-dispatch.d.ts +2 -0
- package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
- package/dist/core/tools/tmux-dispatch.js +16 -2
- package/dist/core/tools/tmux-dispatch.js.map +1 -1
- package/dist/core/tools/windows-shell-engine.js +1 -1
- package/dist/core/tools/windows-shell-engine.js.map +1 -1
- package/dist/core/tools/write.d.ts +24 -7
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +182 -107
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/jscpd-cli.d.ts +3 -0
- package/dist/jscpd-cli.d.ts.map +1 -0
- package/dist/jscpd-cli.js +22 -0
- package/dist/jscpd-cli.js.map +1 -0
- package/dist/modes/interactive/components/profile-resource-editor.js +2 -2
- package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +85 -3
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/bundled-jscpd.d.ts +20 -0
- package/dist/utils/bundled-jscpd.d.ts.map +1 -0
- package/dist/utils/bundled-jscpd.js +154 -0
- package/dist/utils/bundled-jscpd.js.map +1 -0
- package/dist/utils/paths.js +1 -1
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +11 -0
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/tools-manager.d.ts +19 -2
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +92 -40
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/index.md +3 -0
- package/docs/managed-data-tools.md +15 -0
- package/docs/models.md +1 -1
- package/docs/quickstart.md +2 -2
- package/docs/settings.md +1 -1
- package/docs/tool-boundary-performance-roadmap-2026-08-02.md +166 -0
- package/docs/tool-repair.md +4 -4
- package/docs/windows.md +7 -5
- package/docs/worker-profiles.md +16 -0
- package/examples/extensions/built-in-tool-renderer.ts +12 -5
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/minimal-mode.ts +8 -7
- package/examples/extensions/prompt-customizer.ts +4 -2
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/ssh.ts +113 -24
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +112 -12
- package/package.json +7 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ToolArgumentValidationTelemetryEvent } from "@caupulican/pi-ai";
|
|
2
|
-
import {
|
|
2
|
+
import type { ToolFailurePhase } from "@caupulican/pi-ai/tool-repair-registry";
|
|
3
|
+
import { type ToolArgumentValidationLogRecord, type ToolExecutionFailureLogRecord } from "./tool-recovery-log-records.ts";
|
|
3
4
|
export interface ToolRecoveryLoggerStats {
|
|
4
5
|
enabled: boolean;
|
|
5
6
|
queued: number;
|
|
@@ -9,6 +10,8 @@ export interface ToolRecoveryLoggerStats {
|
|
|
9
10
|
workerStarts: number;
|
|
10
11
|
workerCrashes: number;
|
|
11
12
|
respawns: number;
|
|
13
|
+
executionFailures: number;
|
|
14
|
+
failurePhases: Partial<Record<ToolFailurePhase, number>>;
|
|
12
15
|
}
|
|
13
16
|
export interface ToolRecoveryLoggerOptions {
|
|
14
17
|
enabled: boolean;
|
|
@@ -44,10 +47,18 @@ export declare class ToolRecoveryLogger {
|
|
|
44
47
|
private workerStarts;
|
|
45
48
|
private workerCrashes;
|
|
46
49
|
private respawns;
|
|
50
|
+
private executionFailures;
|
|
51
|
+
private readonly failurePhases;
|
|
47
52
|
private respawnAttempted;
|
|
48
53
|
private shuttingDown;
|
|
49
54
|
constructor(options: ToolRecoveryLoggerOptions);
|
|
50
55
|
recordToolArgumentValidation(event: ToolArgumentValidationTelemetryEvent): ToolArgumentValidationLogRecord | undefined;
|
|
56
|
+
recordToolExecutionFailure(args: {
|
|
57
|
+
provider?: string;
|
|
58
|
+
model?: string;
|
|
59
|
+
tool: string;
|
|
60
|
+
details: unknown;
|
|
61
|
+
}): ToolExecutionFailureLogRecord | undefined;
|
|
51
62
|
getStats(): ToolRecoveryLoggerStats;
|
|
52
63
|
flush(timeoutMs?: number): Promise<void>;
|
|
53
64
|
shutdown(timeoutMs?: number): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-recovery-logger.d.ts","sourceRoot":"","sources":["../../src/core/tool-recovery-logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tool-recovery-logger.d.ts","sourceRoot":"","sources":["../../src/core/tool-recovery-logger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAGN,KAAK,+BAA+B,EACpC,KAAK,6BAA6B,EAElC,MAAM,gCAAgC,CAAC;AASxC,MAAM,WAAW,uBAAuB;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EA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,CAAC,cAAc,CAAqB;IAC3C,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiD;IAC/E,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,YAAY,CAAS;IAE7B,YAAY,OAAO,EAAE,yBAAyB,EAU7C;IAED,4BAA4B,CAC3B,KAAK,EAAE,oCAAoC,GACzC,+BAA+B,GAAG,SAAS,CAU7C;IAED,0BAA0B,CAAC,IAAI,EAAE;QAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,OAAO,CAAC;KACjB,GAAG,6BAA6B,GAAG,SAAS,CAe5C;IAED,QAAQ,IAAI,uBAAuB,CAalC;IAED,KAAK,CAAC,SAAS,GAAE,MAAiC,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBjE;IAEK,QAAQ,CAAC,SAAS,GAAE,MAAiC,GAAG,OAAO,CAAC,IAAI,CAAC,CAU1E;IAED,OAAO,CAAC,OAAO;IAUf,OAAO,CAAC,IAAI;IAiBZ,OAAO,CAAC,YAAY;IAuBpB,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,mBAAmB;IAoB3B,OAAO,CAAC,yBAAyB;CAKjC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Worker } from "node:worker_threads";
|
|
2
|
-
import {
|
|
2
|
+
import { readToolFailureTelemetry } from "@caupulican/pi-agent-core";
|
|
3
|
+
import { createToolArgumentValidationLogRecord, createToolExecutionFailureLogRecord, } from "./tool-recovery-log-records.js";
|
|
3
4
|
const DEFAULT_MAX_QUEUE = 1000;
|
|
4
5
|
const DEFAULT_BATCH_SIZE = 50;
|
|
5
6
|
const DEFAULT_FLUSH_TIMEOUT_MS = 200;
|
|
@@ -28,6 +29,8 @@ export class ToolRecoveryLogger {
|
|
|
28
29
|
this.workerStarts = 0;
|
|
29
30
|
this.workerCrashes = 0;
|
|
30
31
|
this.respawns = 0;
|
|
32
|
+
this.executionFailures = 0;
|
|
33
|
+
this.failurePhases = {};
|
|
31
34
|
this.respawnAttempted = false;
|
|
32
35
|
this.shuttingDown = false;
|
|
33
36
|
this.enabled = options.enabled;
|
|
@@ -52,6 +55,24 @@ export class ToolRecoveryLogger {
|
|
|
52
55
|
this.enqueue({ eventLogPath: this.eventLogPath, failureCorpusPath: this.failureCorpusPath, record });
|
|
53
56
|
return record;
|
|
54
57
|
}
|
|
58
|
+
recordToolExecutionFailure(args) {
|
|
59
|
+
if (!this.enabled)
|
|
60
|
+
return undefined;
|
|
61
|
+
const failure = readToolFailureTelemetry(args.details);
|
|
62
|
+
if (!failure)
|
|
63
|
+
return undefined;
|
|
64
|
+
const record = createToolExecutionFailureLogRecord({
|
|
65
|
+
...args,
|
|
66
|
+
...failure,
|
|
67
|
+
recordId: `${this.sessionId}:${this.recordSequence++}`,
|
|
68
|
+
sessionId: this.sessionId,
|
|
69
|
+
ts: this.now().toISOString(),
|
|
70
|
+
});
|
|
71
|
+
this.executionFailures++;
|
|
72
|
+
this.failurePhases[failure.phase] = (this.failurePhases[failure.phase] ?? 0) + 1;
|
|
73
|
+
this.enqueue({ eventLogPath: this.eventLogPath, failureCorpusPath: this.failureCorpusPath, record });
|
|
74
|
+
return record;
|
|
75
|
+
}
|
|
55
76
|
getStats() {
|
|
56
77
|
return {
|
|
57
78
|
enabled: this.enabled,
|
|
@@ -62,6 +83,8 @@ export class ToolRecoveryLogger {
|
|
|
62
83
|
workerStarts: this.workerStarts,
|
|
63
84
|
workerCrashes: this.workerCrashes,
|
|
64
85
|
respawns: this.respawns,
|
|
86
|
+
executionFailures: this.executionFailures,
|
|
87
|
+
failurePhases: { ...this.failurePhases },
|
|
65
88
|
};
|
|
66
89
|
}
|
|
67
90
|
flush(timeoutMs = DEFAULT_FLUSH_TIMEOUT_MS) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-recovery-logger.js","sourceRoot":"","sources":["../../src/core/tool-recovery-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EACN,qCAAqC,GAGrC,MAAM,gCAAgC,CAAC;AAgCxC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAC/B,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC,SAAS,2BAA2B,CAAC,KAAc;IAClD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,OAAO,GAAG,KAA2C,CAAC;IAC5D,OAAO,CACN,OAAO,CAAC,IAAI,KAAK,KAAK;QACtB,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ;QACnC,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ;QACnC,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,CAClC,CAAC;AACH,CAAC;AAED,SAAS,4BAA4B;IACpC,MAAM,mBAAmB,GAAG,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC5D,OAAO,IAAI,GAAG,CACb,mBAAmB,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,+BAA+B,EACvF,OAAO,IAAI,CAAC,GAAG,CACf,CAAC;AACH,CAAC;AAED,MAAM,OAAO,kBAAkB;IA0B9B,YAAY,OAAkC;QAhB7B,UAAK,GAAkC,EAAE,CAAC;QAC1C,iBAAY,GAAsB,EAAE,CAAC;QAE9C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I,CAAC,IAAI,EAAE,CAAC;QACb,CAAC;QACD,IAAI,CAAC,yBAAyB,EAAE,CAAC;IAClC,CAAC;IAEO,yBAAyB;QAChC,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO;QAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC5C,KAAK,MAAM,MAAM,IAAI,OAAO;YAAE,MAAM,EAAE,CAAC;IACxC,CAAC;CACD","sourcesContent":["import { Worker } from \"node:worker_threads\";\nimport type { ToolArgumentValidationTelemetryEvent } from \"@caupulican/pi-ai\";\nimport {\n\tcreateToolArgumentValidationLogRecord,\n\ttype ToolArgumentValidationLogRecord,\n\ttype ToolRecoveryLogWorkerRecord,\n} from \"./tool-recovery-log-records.ts\";\n\ninterface ToolRecoveryLogAckMessage {\n\ttype: \"ack\";\n\tbatchId: number;\n\twritten: number;\n\tfailed: number;\n}\n\nexport interface ToolRecoveryLoggerStats {\n\tenabled: boolean;\n\tqueued: number;\n\tinFlight: number;\n\tdropped: number;\n\tfailures: number;\n\tworkerStarts: number;\n\tworkerCrashes: number;\n\trespawns: number;\n}\n\nexport interface ToolRecoveryLoggerOptions {\n\tenabled: boolean;\n\tsessionId: string;\n\teventLogPath: string;\n\tfailureCorpusPath: string;\n\tmaxQueue?: number;\n\tbatchSize?: number;\n\tnow?: () => Date;\n\tdebug?: (message: string) => void;\n\tworkerSpecifier?: string | URL;\n}\n\nconst DEFAULT_MAX_QUEUE = 1000;\nconst DEFAULT_BATCH_SIZE = 50;\nconst DEFAULT_FLUSH_TIMEOUT_MS = 200;\n\nfunction isToolRecoveryLogAckMessage(value: unknown): value is ToolRecoveryLogAckMessage {\n\tif (!value || typeof value !== \"object\") return false;\n\tconst message = value as Partial<ToolRecoveryLogAckMessage>;\n\treturn (\n\t\tmessage.type === \"ack\" &&\n\t\ttypeof message.batchId === \"number\" &&\n\t\ttypeof message.written === \"number\" &&\n\t\ttypeof message.failed === \"number\"\n\t);\n}\n\nfunction createDefaultWorkerSpecifier(): URL {\n\tconst isTypeScriptRuntime = import.meta.url.endsWith(\".ts\");\n\treturn new URL(\n\t\tisTypeScriptRuntime ? \"./tool-recovery-log-worker.ts\" : \"./tool-recovery-log-worker.js\",\n\t\timport.meta.url,\n\t);\n}\n\nexport class ToolRecoveryLogger {\n\tprivate readonly enabled: boolean;\n\tprivate readonly sessionId: string;\n\tprivate readonly eventLogPath: string;\n\tprivate readonly failureCorpusPath: string;\n\tprivate readonly maxQueue: number;\n\tprivate readonly batchSize: number;\n\tprivate readonly now: () => Date;\n\tprivate readonly debug: (message: string) => void;\n\tprivate readonly workerSpecifier: string | URL;\n\tprivate readonly queue: ToolRecoveryLogWorkerRecord[] = [];\n\tprivate readonly flushWaiters: Array<() => void> = [];\n\tprivate worker: Worker | undefined;\n\tprivate inFlight: ToolRecoveryLogWorkerRecord[] = [];\n\tprivate inFlightBatchId: number | undefined;\n\tprivate inFlightWorker: Worker | undefined;\n\tprivate batchId = 0;\n\tprivate recordSequence = 0;\n\tprivate dropped = 0;\n\tprivate failures = 0;\n\tprivate workerStarts = 0;\n\tprivate workerCrashes = 0;\n\tprivate respawns = 0;\n\tprivate respawnAttempted = false;\n\tprivate shuttingDown = false;\n\n\tconstructor(options: ToolRecoveryLoggerOptions) {\n\t\tthis.enabled = options.enabled;\n\t\tthis.sessionId = options.sessionId;\n\t\tthis.eventLogPath = options.eventLogPath;\n\t\tthis.failureCorpusPath = options.failureCorpusPath;\n\t\tthis.maxQueue = options.maxQueue ?? DEFAULT_MAX_QUEUE;\n\t\tthis.batchSize = options.batchSize ?? DEFAULT_BATCH_SIZE;\n\t\tthis.now = options.now ?? (() => new Date());\n\t\tthis.debug = options.debug ?? (() => {});\n\t\tthis.workerSpecifier = options.workerSpecifier ?? createDefaultWorkerSpecifier();\n\t}\n\n\trecordToolArgumentValidation(\n\t\tevent: ToolArgumentValidationTelemetryEvent,\n\t): ToolArgumentValidationLogRecord | undefined {\n\t\tif (!this.enabled || event.outcome === \"clean\") return undefined;\n\t\tconst record = createToolArgumentValidationLogRecord({\n\t\t\tevent,\n\t\t\trecordId: `${this.sessionId}:${this.recordSequence++}`,\n\t\t\tsessionId: this.sessionId,\n\t\t\tts: this.now().toISOString(),\n\t\t});\n\t\tthis.enqueue({ eventLogPath: this.eventLogPath, failureCorpusPath: this.failureCorpusPath, record });\n\t\treturn record;\n\t}\n\n\tgetStats(): ToolRecoveryLoggerStats {\n\t\treturn {\n\t\t\tenabled: this.enabled,\n\t\t\tqueued: this.queue.length,\n\t\t\tinFlight: this.inFlight.length,\n\t\t\tdropped: this.dropped,\n\t\t\tfailures: this.failures,\n\t\t\tworkerStarts: this.workerStarts,\n\t\t\tworkerCrashes: this.workerCrashes,\n\t\t\trespawns: this.respawns,\n\t\t};\n\t}\n\n\tflush(timeoutMs: number = DEFAULT_FLUSH_TIMEOUT_MS): Promise<void> {\n\t\tif (!this.enabled || (!this.worker && this.queue.length === 0 && this.inFlight.length === 0)) {\n\t\t\treturn Promise.resolve();\n\t\t}\n\t\tthis.pump();\n\t\treturn new Promise((resolve) => {\n\t\t\tlet settled = false;\n\t\t\tlet timeout: NodeJS.Timeout;\n\t\t\tconst finish = (): void => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tresolve();\n\t\t\t};\n\t\t\tconst waiter = (): void => {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\tfinish();\n\t\t\t};\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\tconst index = this.flushWaiters.indexOf(waiter);\n\t\t\t\tif (index !== -1) this.flushWaiters.splice(index, 1);\n\t\t\t\tfinish();\n\t\t\t}, timeoutMs);\n\t\t\tthis.flushWaiters.push(waiter);\n\t\t\tthis.resolveFlushWaitersIfIdle();\n\t\t});\n\t}\n\n\tasync shutdown(timeoutMs: number = DEFAULT_FLUSH_TIMEOUT_MS): Promise<void> {\n\t\tawait this.flush(timeoutMs);\n\t\tthis.shuttingDown = true;\n\t\tconst worker = this.worker;\n\t\tthis.worker = undefined;\n\t\tif (!worker) return;\n\t\ttry {\n\t\t\tworker.postMessage({ type: \"shutdown\" });\n\t\t} catch {}\n\t\tvoid worker.terminate().catch(() => undefined);\n\t}\n\n\tprivate enqueue(record: ToolRecoveryLogWorkerRecord): void {\n\t\tif (!this.enabled) return;\n\t\tthis.queue.push(record);\n\t\twhile (this.queue.length > this.maxQueue) {\n\t\t\tthis.queue.shift();\n\t\t\tthis.dropped++;\n\t\t}\n\t\tthis.pump();\n\t}\n\n\tprivate pump(): void {\n\t\tif (!this.enabled || this.shuttingDown || this.inFlight.length > 0 || this.queue.length === 0) return;\n\t\tconst worker = this.ensureWorker();\n\t\tif (!worker) return;\n\t\tconst records = this.queue.splice(0, this.batchSize);\n\t\tthis.inFlight = records;\n\t\tconst batchId = this.batchId++;\n\t\tthis.inFlightBatchId = batchId;\n\t\tthis.inFlightWorker = worker;\n\t\ttry {\n\t\t\tworker.postMessage({ type: \"records\", batchId, records });\n\t\t} catch (error) {\n\t\t\tthis.debug(`tool recovery logger post failed: ${error instanceof Error ? error.message : String(error)}`);\n\t\t\tthis.handleWorkerFailure(worker, error instanceof Error ? error : new Error(String(error)));\n\t\t}\n\t}\n\n\tprivate ensureWorker(): Worker | undefined {\n\t\tif (this.worker) return this.worker;\n\t\ttry {\n\t\t\tconst worker = new Worker(this.workerSpecifier);\n\t\t\tworker.unref();\n\t\t\tthis.worker = worker;\n\t\t\tthis.workerStarts++;\n\t\t\tworker.on(\"message\", (message: unknown) => this.handleWorkerMessage(worker, message));\n\t\t\tworker.on(\"error\", (error) => this.handleWorkerFailure(worker, error));\n\t\t\tworker.on(\"exit\", (code) => {\n\t\t\t\tif (this.shuttingDown || this.worker !== worker) return;\n\t\t\t\tthis.handleWorkerFailure(worker, new Error(`tool recovery logger worker exited with code ${code}`));\n\t\t\t});\n\t\t\treturn worker;\n\t\t} catch (error) {\n\t\t\tthis.failures++;\n\t\t\tthis.debug(\n\t\t\t\t`tool recovery logger worker start failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tprivate handleWorkerMessage(worker: Worker, message: unknown): void {\n\t\tif (!isToolRecoveryLogAckMessage(message)) return;\n\t\tif (this.worker !== worker || this.inFlightWorker !== worker || this.inFlightBatchId !== message.batchId) {\n\t\t\treturn;\n\t\t}\n\t\tif (message.failed > 0) {\n\t\t\tthis.failures += message.failed;\n\t\t}\n\t\tthis.inFlight = [];\n\t\tthis.inFlightBatchId = undefined;\n\t\tthis.inFlightWorker = undefined;\n\t\tthis.respawnAttempted = false;\n\t\tthis.pump();\n\t\tthis.resolveFlushWaitersIfIdle();\n\t}\n\n\tprivate handleWorkerFailure(worker: Worker, error: Error): void {\n\t\tif (this.worker !== worker) return;\n\t\tthis.failures++;\n\t\tthis.workerCrashes++;\n\t\tif (this.inFlightWorker === worker) {\n\t\t\tthis.dropped += this.inFlight.length;\n\t\t\tthis.inFlight = [];\n\t\t\tthis.inFlightBatchId = undefined;\n\t\t\tthis.inFlightWorker = undefined;\n\t\t}\n\t\tthis.worker = undefined;\n\t\tthis.debug(`tool recovery logger worker failed: ${error.message}`);\n\t\tif (!this.respawnAttempted && !this.shuttingDown) {\n\t\t\tthis.respawnAttempted = true;\n\t\t\tthis.respawns++;\n\t\t\tthis.pump();\n\t\t}\n\t\tthis.resolveFlushWaitersIfIdle();\n\t}\n\n\tprivate resolveFlushWaitersIfIdle(): void {\n\t\tif (this.queue.length > 0 || this.inFlight.length > 0) return;\n\t\tconst waiters = this.flushWaiters.splice(0);\n\t\tfor (const waiter of waiters) waiter();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tool-recovery-logger.js","sourceRoot":"","sources":["../../src/core/tool-recovery-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,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CAAC;IAClC,CAAC;IAEO,mBAAmB,CAAC,MAAc,EAAE,KAAY;QACvD,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM;YAAE,OAAO;QACnC,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,IAAI,CAAC,cAAc,KAAK,MAAM,EAAE,CAAC;YACpC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YACrC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;YACnB,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;YACjC,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;QACjC,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,IAAI,CAAC,KAAK,CAAC,uCAAuC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACnE,IAAI,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YAClD,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAC7B,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,IAAI,CAAC,IAAI,EAAE,CAAC;QACb,CAAC;QACD,IAAI,CAAC,yBAAyB,EAAE,CAAC;IAClC,CAAC;IAEO,yBAAyB;QAChC,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO;QAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC5C,KAAK,MAAM,MAAM,IAAI,OAAO;YAAE,MAAM,EAAE,CAAC;IACxC,CAAC;CACD","sourcesContent":["import { Worker } from \"node:worker_threads\";\nimport { readToolFailureTelemetry } from \"@caupulican/pi-agent-core\";\nimport type { ToolArgumentValidationTelemetryEvent } from \"@caupulican/pi-ai\";\nimport type { ToolFailurePhase } from \"@caupulican/pi-ai/tool-repair-registry\";\nimport {\n\tcreateToolArgumentValidationLogRecord,\n\tcreateToolExecutionFailureLogRecord,\n\ttype ToolArgumentValidationLogRecord,\n\ttype ToolExecutionFailureLogRecord,\n\ttype ToolRecoveryLogWorkerRecord,\n} from \"./tool-recovery-log-records.ts\";\n\ninterface ToolRecoveryLogAckMessage {\n\ttype: \"ack\";\n\tbatchId: number;\n\twritten: number;\n\tfailed: number;\n}\n\nexport interface ToolRecoveryLoggerStats {\n\tenabled: boolean;\n\tqueued: number;\n\tinFlight: number;\n\tdropped: number;\n\tfailures: number;\n\tworkerStarts: number;\n\tworkerCrashes: number;\n\trespawns: number;\n\texecutionFailures: number;\n\tfailurePhases: Partial<Record<ToolFailurePhase, number>>;\n}\n\nexport interface ToolRecoveryLoggerOptions {\n\tenabled: boolean;\n\tsessionId: string;\n\teventLogPath: string;\n\tfailureCorpusPath: string;\n\tmaxQueue?: number;\n\tbatchSize?: number;\n\tnow?: () => Date;\n\tdebug?: (message: string) => void;\n\tworkerSpecifier?: string | URL;\n}\n\nconst DEFAULT_MAX_QUEUE = 1000;\nconst DEFAULT_BATCH_SIZE = 50;\nconst DEFAULT_FLUSH_TIMEOUT_MS = 200;\n\nfunction isToolRecoveryLogAckMessage(value: unknown): value is ToolRecoveryLogAckMessage {\n\tif (!value || typeof value !== \"object\") return false;\n\tconst message = value as Partial<ToolRecoveryLogAckMessage>;\n\treturn (\n\t\tmessage.type === \"ack\" &&\n\t\ttypeof message.batchId === \"number\" &&\n\t\ttypeof message.written === \"number\" &&\n\t\ttypeof message.failed === \"number\"\n\t);\n}\n\nfunction createDefaultWorkerSpecifier(): URL {\n\tconst isTypeScriptRuntime = import.meta.url.endsWith(\".ts\");\n\treturn new URL(\n\t\tisTypeScriptRuntime ? \"./tool-recovery-log-worker.ts\" : \"./tool-recovery-log-worker.js\",\n\t\timport.meta.url,\n\t);\n}\n\nexport class ToolRecoveryLogger {\n\tprivate readonly enabled: boolean;\n\tprivate readonly sessionId: string;\n\tprivate readonly eventLogPath: string;\n\tprivate readonly failureCorpusPath: string;\n\tprivate readonly maxQueue: number;\n\tprivate readonly batchSize: number;\n\tprivate readonly now: () => Date;\n\tprivate readonly debug: (message: string) => void;\n\tprivate readonly workerSpecifier: string | URL;\n\tprivate readonly queue: ToolRecoveryLogWorkerRecord[] = [];\n\tprivate readonly flushWaiters: Array<() => void> = [];\n\tprivate worker: Worker | undefined;\n\tprivate inFlight: ToolRecoveryLogWorkerRecord[] = [];\n\tprivate inFlightBatchId: number | undefined;\n\tprivate inFlightWorker: Worker | undefined;\n\tprivate batchId = 0;\n\tprivate recordSequence = 0;\n\tprivate dropped = 0;\n\tprivate failures = 0;\n\tprivate workerStarts = 0;\n\tprivate workerCrashes = 0;\n\tprivate respawns = 0;\n\tprivate executionFailures = 0;\n\tprivate readonly failurePhases: Partial<Record<ToolFailurePhase, number>> = {};\n\tprivate respawnAttempted = false;\n\tprivate shuttingDown = false;\n\n\tconstructor(options: ToolRecoveryLoggerOptions) {\n\t\tthis.enabled = options.enabled;\n\t\tthis.sessionId = options.sessionId;\n\t\tthis.eventLogPath = options.eventLogPath;\n\t\tthis.failureCorpusPath = options.failureCorpusPath;\n\t\tthis.maxQueue = options.maxQueue ?? DEFAULT_MAX_QUEUE;\n\t\tthis.batchSize = options.batchSize ?? DEFAULT_BATCH_SIZE;\n\t\tthis.now = options.now ?? (() => new Date());\n\t\tthis.debug = options.debug ?? (() => {});\n\t\tthis.workerSpecifier = options.workerSpecifier ?? createDefaultWorkerSpecifier();\n\t}\n\n\trecordToolArgumentValidation(\n\t\tevent: ToolArgumentValidationTelemetryEvent,\n\t): ToolArgumentValidationLogRecord | undefined {\n\t\tif (!this.enabled || event.outcome === \"clean\") return undefined;\n\t\tconst record = createToolArgumentValidationLogRecord({\n\t\t\tevent,\n\t\t\trecordId: `${this.sessionId}:${this.recordSequence++}`,\n\t\t\tsessionId: this.sessionId,\n\t\t\tts: this.now().toISOString(),\n\t\t});\n\t\tthis.enqueue({ eventLogPath: this.eventLogPath, failureCorpusPath: this.failureCorpusPath, record });\n\t\treturn record;\n\t}\n\n\trecordToolExecutionFailure(args: {\n\t\tprovider?: string;\n\t\tmodel?: string;\n\t\ttool: string;\n\t\tdetails: unknown;\n\t}): ToolExecutionFailureLogRecord | undefined {\n\t\tif (!this.enabled) return undefined;\n\t\tconst failure = readToolFailureTelemetry(args.details);\n\t\tif (!failure) return undefined;\n\t\tconst record = createToolExecutionFailureLogRecord({\n\t\t\t...args,\n\t\t\t...failure,\n\t\t\trecordId: `${this.sessionId}:${this.recordSequence++}`,\n\t\t\tsessionId: this.sessionId,\n\t\t\tts: this.now().toISOString(),\n\t\t});\n\t\tthis.executionFailures++;\n\t\tthis.failurePhases[failure.phase] = (this.failurePhases[failure.phase] ?? 0) + 1;\n\t\tthis.enqueue({ eventLogPath: this.eventLogPath, failureCorpusPath: this.failureCorpusPath, record });\n\t\treturn record;\n\t}\n\n\tgetStats(): ToolRecoveryLoggerStats {\n\t\treturn {\n\t\t\tenabled: this.enabled,\n\t\t\tqueued: this.queue.length,\n\t\t\tinFlight: this.inFlight.length,\n\t\t\tdropped: this.dropped,\n\t\t\tfailures: this.failures,\n\t\t\tworkerStarts: this.workerStarts,\n\t\t\tworkerCrashes: this.workerCrashes,\n\t\t\trespawns: this.respawns,\n\t\t\texecutionFailures: this.executionFailures,\n\t\t\tfailurePhases: { ...this.failurePhases },\n\t\t};\n\t}\n\n\tflush(timeoutMs: number = DEFAULT_FLUSH_TIMEOUT_MS): Promise<void> {\n\t\tif (!this.enabled || (!this.worker && this.queue.length === 0 && this.inFlight.length === 0)) {\n\t\t\treturn Promise.resolve();\n\t\t}\n\t\tthis.pump();\n\t\treturn new Promise((resolve) => {\n\t\t\tlet settled = false;\n\t\t\tlet timeout: NodeJS.Timeout;\n\t\t\tconst finish = (): void => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tresolve();\n\t\t\t};\n\t\t\tconst waiter = (): void => {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\tfinish();\n\t\t\t};\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\tconst index = this.flushWaiters.indexOf(waiter);\n\t\t\t\tif (index !== -1) this.flushWaiters.splice(index, 1);\n\t\t\t\tfinish();\n\t\t\t}, timeoutMs);\n\t\t\tthis.flushWaiters.push(waiter);\n\t\t\tthis.resolveFlushWaitersIfIdle();\n\t\t});\n\t}\n\n\tasync shutdown(timeoutMs: number = DEFAULT_FLUSH_TIMEOUT_MS): Promise<void> {\n\t\tawait this.flush(timeoutMs);\n\t\tthis.shuttingDown = true;\n\t\tconst worker = this.worker;\n\t\tthis.worker = undefined;\n\t\tif (!worker) return;\n\t\ttry {\n\t\t\tworker.postMessage({ type: \"shutdown\" });\n\t\t} catch {}\n\t\tvoid worker.terminate().catch(() => undefined);\n\t}\n\n\tprivate enqueue(record: ToolRecoveryLogWorkerRecord): void {\n\t\tif (!this.enabled) return;\n\t\tthis.queue.push(record);\n\t\twhile (this.queue.length > this.maxQueue) {\n\t\t\tthis.queue.shift();\n\t\t\tthis.dropped++;\n\t\t}\n\t\tthis.pump();\n\t}\n\n\tprivate pump(): void {\n\t\tif (!this.enabled || this.shuttingDown || this.inFlight.length > 0 || this.queue.length === 0) return;\n\t\tconst worker = this.ensureWorker();\n\t\tif (!worker) return;\n\t\tconst records = this.queue.splice(0, this.batchSize);\n\t\tthis.inFlight = records;\n\t\tconst batchId = this.batchId++;\n\t\tthis.inFlightBatchId = batchId;\n\t\tthis.inFlightWorker = worker;\n\t\ttry {\n\t\t\tworker.postMessage({ type: \"records\", batchId, records });\n\t\t} catch (error) {\n\t\t\tthis.debug(`tool recovery logger post failed: ${error instanceof Error ? error.message : String(error)}`);\n\t\t\tthis.handleWorkerFailure(worker, error instanceof Error ? error : new Error(String(error)));\n\t\t}\n\t}\n\n\tprivate ensureWorker(): Worker | undefined {\n\t\tif (this.worker) return this.worker;\n\t\ttry {\n\t\t\tconst worker = new Worker(this.workerSpecifier);\n\t\t\tworker.unref();\n\t\t\tthis.worker = worker;\n\t\t\tthis.workerStarts++;\n\t\t\tworker.on(\"message\", (message: unknown) => this.handleWorkerMessage(worker, message));\n\t\t\tworker.on(\"error\", (error) => this.handleWorkerFailure(worker, error));\n\t\t\tworker.on(\"exit\", (code) => {\n\t\t\t\tif (this.shuttingDown || this.worker !== worker) return;\n\t\t\t\tthis.handleWorkerFailure(worker, new Error(`tool recovery logger worker exited with code ${code}`));\n\t\t\t});\n\t\t\treturn worker;\n\t\t} catch (error) {\n\t\t\tthis.failures++;\n\t\t\tthis.debug(\n\t\t\t\t`tool recovery logger worker start failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tprivate handleWorkerMessage(worker: Worker, message: unknown): void {\n\t\tif (!isToolRecoveryLogAckMessage(message)) return;\n\t\tif (this.worker !== worker || this.inFlightWorker !== worker || this.inFlightBatchId !== message.batchId) {\n\t\t\treturn;\n\t\t}\n\t\tif (message.failed > 0) {\n\t\t\tthis.failures += message.failed;\n\t\t}\n\t\tthis.inFlight = [];\n\t\tthis.inFlightBatchId = undefined;\n\t\tthis.inFlightWorker = undefined;\n\t\tthis.respawnAttempted = false;\n\t\tthis.pump();\n\t\tthis.resolveFlushWaitersIfIdle();\n\t}\n\n\tprivate handleWorkerFailure(worker: Worker, error: Error): void {\n\t\tif (this.worker !== worker) return;\n\t\tthis.failures++;\n\t\tthis.workerCrashes++;\n\t\tif (this.inFlightWorker === worker) {\n\t\t\tthis.dropped += this.inFlight.length;\n\t\t\tthis.inFlight = [];\n\t\t\tthis.inFlightBatchId = undefined;\n\t\t\tthis.inFlightWorker = undefined;\n\t\t}\n\t\tthis.worker = undefined;\n\t\tthis.debug(`tool recovery logger worker failed: ${error.message}`);\n\t\tif (!this.respawnAttempted && !this.shuttingDown) {\n\t\t\tthis.respawnAttempted = true;\n\t\t\tthis.respawns++;\n\t\t\tthis.pump();\n\t\t}\n\t\tthis.resolveFlushWaitersIfIdle();\n\t}\n\n\tprivate resolveFlushWaitersIfIdle(): void {\n\t\tif (this.queue.length > 0 || this.inFlight.length > 0) return;\n\t\tconst waiters = this.flushWaiters.splice(0);\n\t\tfor (const waiter of waiters) waiter();\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-repair-health.d.ts","sourceRoot":"","sources":["../../src/core/tool-repair-health.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAyB,MAAM,8BAA8B,CAAC;AAChG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-repair-health.d.ts","sourceRoot":"","sources":["../../src/core/tool-repair-health.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAyB,MAAM,8BAA8B,CAAC;AAChG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AA0BzE,wBAAgB,4BAA4B,CAC3C,KAAK,EAAE,oBAAoB,EAC3B,GAAG,GAAE,IAAiB,EACtB,WAAW,CAAC,EAAE,uBAAuB,GACnC,MAAM,CAwDR"}
|
|
@@ -12,8 +12,14 @@ function sortProfiles(profiles) {
|
|
|
12
12
|
function formatLoggerStats(stats) {
|
|
13
13
|
if (!stats)
|
|
14
14
|
return [];
|
|
15
|
+
const phaseCounts = Object.entries(stats.failurePhases)
|
|
16
|
+
.filter((entry) => entry[1] !== undefined && entry[1] > 0)
|
|
17
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
18
|
+
.map(([phase, count]) => `${phase}=${count}`)
|
|
19
|
+
.join(" ");
|
|
15
20
|
return [
|
|
16
21
|
`recovery logging: ${stats.enabled ? "enabled" : "disabled"} queued=${stats.queued} inFlight=${stats.inFlight} dropped=${stats.dropped} failures=${stats.failures} workerStarts=${stats.workerStarts} crashes=${stats.workerCrashes} respawns=${stats.respawns}`,
|
|
22
|
+
`execution failures: total=${stats.executionFailures}${phaseCounts ? ` ${phaseCounts}` : ""}`,
|
|
17
23
|
];
|
|
18
24
|
}
|
|
19
25
|
export function formatToolRepairHealthReport(store, now = new Date(), loggerStats) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-repair-health.js","sourceRoot":"","sources":["../../src/core/tool-repair-health.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,SAAS,aAAa,CAAC,GAAW,EAAE,GAAS;IAC5C,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QAAE,OAAO,aAAa,CAAC;IAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACnF,OAAO,GAAG,IAAI,OAAO,CAAC;AACvB,CAAC;AAED,SAAS,YAAY,CAAC,QAAiC;IACtD,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AACnF,CAAC;AAED,SAAS,iBAAiB,CAAC,KAA0C;IACpE,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,OAAO;QACN,qBAAqB,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,WAAW,KAAK,CAAC,MAAM,aAAa,KAAK,CAAC,QAAQ,YAAY,KAAK,CAAC,OAAO,aAAa,KAAK,C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I,YAAY,EAAE,CAAC;gBAC1C,KAAK,CAAC,IAAI,CACT,SAAS,IAAI,YAAY,KAAK,CAAC,MAAM,WAAW,KAAK,CAAC,gBAAgB,UAAU,KAAK,CAAC,eAAe,EAAE,CACvG,CAAC;YACH,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import chalk from \"chalk\";\nimport type { ModelAdaptationStore, StoredModelAdaptation } from \"./models/adaptation-store.ts\";\nimport type { ToolRecoveryLoggerStats } from \"./tool-recovery-logger.ts\";\n\nfunction formatAgeDays(iso: string, now: Date): string {\n\tconst ms = Date.parse(iso);\n\tif (!Number.isFinite(ms)) return \"age unknown\";\n\tconst days = Math.max(0, Math.floor((now.getTime() - ms) / (24 * 60 * 60 * 1000)));\n\treturn `${days}d ago`;\n}\n\nfunction sortProfiles(profiles: StoredModelAdaptation[]): StoredModelAdaptation[] {\n\treturn [...profiles].sort((left, right) => left.model.localeCompare(right.model));\n}\n\nfunction formatLoggerStats(stats: ToolRecoveryLoggerStats | undefined): string[] {\n\tif (!stats) return [];\n\tconst phaseCounts = Object.entries(stats.failurePhases)\n\t\t.filter((entry): entry is [string, number] => entry[1] !== undefined && entry[1] > 0)\n\t\t.sort(([left], [right]) => left.localeCompare(right))\n\t\t.map(([phase, count]) => `${phase}=${count}`)\n\t\t.join(\" \");\n\treturn [\n\t\t`recovery logging: ${stats.enabled ? \"enabled\" : \"disabled\"} queued=${stats.queued} inFlight=${stats.inFlight} dropped=${stats.dropped} failures=${stats.failures} workerStarts=${stats.workerStarts} crashes=${stats.workerCrashes} respawns=${stats.respawns}`,\n\t\t`execution failures: total=${stats.executionFailures}${phaseCounts ? ` ${phaseCounts}` : \"\"}`,\n\t];\n}\n\nexport function formatToolRepairHealthReport(\n\tstore: ModelAdaptationStore,\n\tnow: Date = new Date(),\n\tloggerStats?: ToolRecoveryLoggerStats,\n): string {\n\tconst profiles = sortProfiles(store.getForHost());\n\tif (profiles.length === 0) {\n\t\tconst loggerLines = formatLoggerStats(loggerStats);\n\t\treturn [\"Tool repair health: no model adaptation records for this host.\", ...loggerLines].join(\"\\n\");\n\t}\n\n\tconst lines = [chalk.bold(\"Tool repair health\"), ...formatLoggerStats(loggerStats)];\n\tfor (const entry of profiles) {\n\t\tlines.push(`${entry.model}`);\n\t\tconst toolProbe = entry.profile.toolProbe;\n\t\tif (!toolProbe) {\n\t\t\tlines.push(\" tool probe: none\");\n\t\t} else {\n\t\t\tconst variant = toolProbe.variant ? ` (${toolProbe.variant})` : \"\";\n\t\t\tconst nativeGrade = toolProbe.nativeGrade ? ` native=${toolProbe.nativeGrade}` : \"\";\n\t\t\tlines.push(\n\t\t\t\t` tool probe: v${toolProbe.version} ${toolProbe.status}${variant}${nativeGrade} ${formatAgeDays(toolProbe.probedAt, now)}`,\n\t\t\t);\n\t\t\tif (toolProbe.diagnostic) lines.push(` probe diagnostic: ${toolProbe.diagnostic}`);\n\t\t}\n\t\tconst protocol = entry.profile.protocol;\n\t\tif (!protocol) {\n\t\t\tlines.push(\" protocol: none\");\n\t\t} else if (protocol.status === \"failed\") {\n\t\t\tlines.push(` protocol: v${protocol.version} failed ${formatAgeDays(protocol.attemptedAt, now)}`);\n\t\t\tlines.push(` variants tried: ${protocol.variantsTried.join(\", \")}`);\n\t\t\tlines.push(` reset: /toolprotocol-reset ${entry.model}`);\n\t\t} else {\n\t\t\tlines.push(\n\t\t\t\t` protocol: v${protocol.version} ${protocol.variant} calibrated ${formatAgeDays(protocol.calibratedAt, now)}`,\n\t\t\t);\n\t\t}\n\t\tif (entry.profile.rules.length === 0) {\n\t\t\tlines.push(\" rules: none\");\n\t\t} else {\n\t\t\tlines.push(\" rules:\");\n\t\t\tfor (const rule of [...entry.profile.rules].sort((left, right) => left.mode.localeCompare(right.mode))) {\n\t\t\t\tlines.push(` - ${rule.mode} (${formatAgeDays(rule.lastFiredAt, now)}): ${rule.text}`);\n\t\t\t}\n\t\t}\n\t\tconst teachEntries = Object.entries(entry.profile.teachStats).sort(([left], [right]) =>\n\t\t\tleft.localeCompare(right),\n\t\t);\n\t\tif (teachEntries.length === 0) {\n\t\t\tlines.push(\" teach stats: none\");\n\t\t} else {\n\t\t\tlines.push(\" teach stats:\");\n\t\t\tfor (const [mode, stats] of teachEntries) {\n\t\t\t\tlines.push(\n\t\t\t\t\t` - ${mode}: taught=${stats.taught} before=${stats.recurrenceBefore} after=${stats.recurrenceAfter}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\treturn lines.join(\"\\n\");\n}\n"]}
|
|
@@ -72,7 +72,7 @@ export declare function createLocalPlatformShellOperations(options?: {
|
|
|
72
72
|
commandPrefix?: string;
|
|
73
73
|
operations?: BashOperations;
|
|
74
74
|
sessionKey?: string;
|
|
75
|
-
/** Route complex/state-mutating Bash constructs to the Python engine on Windows. Default: true. */
|
|
75
|
+
/** Route complex/state-mutating Bash constructs and portable builtins to the Python engine on Windows. Default: true. */
|
|
76
76
|
pythonEngine?: boolean;
|
|
77
77
|
/** Test/embedding hook: overrides the engine tier's runtime/spawn/state resolution. */
|
|
78
78
|
engineOptions?: WindowsShellEngineOptions;
|
|
@@ -100,19 +100,14 @@ export interface BashToolOptions {
|
|
|
100
100
|
* tool instances (subagents) auto-generate their own key and stay isolated.
|
|
101
101
|
*/
|
|
102
102
|
sessionKey?: string;
|
|
103
|
-
/** Route complex/state-mutating Bash constructs to the Python engine on Windows. Default: true. */
|
|
103
|
+
/** Route complex/state-mutating Bash constructs and portable builtins to the Python engine on Windows. Default: true. */
|
|
104
104
|
windowsShellPythonEngine?: boolean;
|
|
105
105
|
/** Test/embedding hook: overrides the engine tier's runtime/spawn/state resolution. */
|
|
106
106
|
windowsShellEngineOptions?: WindowsShellEngineOptions;
|
|
107
107
|
/** Test/embedding hook: override the managed directory used for complete command output. */
|
|
108
108
|
outputDirectory?: string;
|
|
109
109
|
}
|
|
110
|
-
|
|
111
|
-
startedAt: number | undefined;
|
|
112
|
-
endedAt: number | undefined;
|
|
113
|
-
interval: NodeJS.Timeout | undefined;
|
|
114
|
-
};
|
|
115
|
-
export declare function createBashToolDefinition(cwd: string, options?: BashToolOptions): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState>;
|
|
110
|
+
export declare function createBashToolDefinition(cwd: string, options?: BashToolOptions): ToolDefinition<typeof bashSchema, BashToolDetails | undefined>;
|
|
116
111
|
export declare function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema>;
|
|
117
112
|
export {};
|
|
118
113
|
//# sourceMappingURL=bash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAIN,KAAK,gBAAgB,EACrB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAc5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAOtF,OAAO,EAGN,KAAK,4BAA4B,EACjC,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAsC,KAAK,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAK/G,qGAAqG;AACrG,eAAO,MAAM,+BAA+B,MAAM,CAAC;AACnD,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAKhD,kGAAkG;AAClG,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAExE;AAED,mGAAmG;AACnG,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAExE;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAKhF;AAED,QAAA,MAAM,UAAU;;;;E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C1C,cAAc,CAuChB;AAED,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;CACvB;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,gBAAgB,KAAK,gBAAgB,CAAC;AAO5E,MAAM,WAAW,eAAe;IAC/B,qGAAqG;IACrG,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC3B,6EAA6E;IAC7E,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,mFAAmF;IACnF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yHAAyH;IACzH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,uFAAuF;IACvF,yBAAyB,CAAC,EAAE,yBAAyB,CAAC;IACtD,4FAA4F;IAC5F,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAggBD,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAGhE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG"}
|
package/dist/core/tools/bash.js
CHANGED
|
@@ -225,9 +225,6 @@ class BashResultRenderComponent extends Container {
|
|
|
225
225
|
};
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
function formatDuration(ms) {
|
|
229
|
-
return `${(ms / 1000).toFixed(1)}s`;
|
|
230
|
-
}
|
|
231
228
|
function formatBashCall(args, shellName) {
|
|
232
229
|
const command = str(args?.command);
|
|
233
230
|
const timeout = args?.timeout;
|
|
@@ -236,7 +233,7 @@ function formatBashCall(args, shellName) {
|
|
|
236
233
|
const prompt = shellName === "powershell" ? "PS>" : "$";
|
|
237
234
|
return theme.fg("toolTitle", theme.bold(`${prompt} ${commandDisplay}`)) + timeoutSuffix;
|
|
238
235
|
}
|
|
239
|
-
function rebuildBashResultRenderComponent(component, result, options, showImages
|
|
236
|
+
function rebuildBashResultRenderComponent(component, result, options, showImages) {
|
|
240
237
|
const state = component.state;
|
|
241
238
|
component.clear();
|
|
242
239
|
const renderPreview = !options.expanded ? result.details?.preview : undefined;
|
|
@@ -300,11 +297,6 @@ function rebuildBashResultRenderComponent(component, result, options, showImages
|
|
|
300
297
|
}
|
|
301
298
|
component.addChild(new Text(`\n${theme.fg("warning", `[${warnings.join(". ")}]`)}`, 0, 0));
|
|
302
299
|
}
|
|
303
|
-
if (startedAt !== undefined) {
|
|
304
|
-
const label = options.isPartial ? "Elapsed" : "Took";
|
|
305
|
-
const endTime = endedAt ?? Date.now();
|
|
306
|
-
component.addChild(new Text(`\n${theme.fg("muted", `${label} ${formatDuration(endTime - startedAt)}`)}`, 0, 0));
|
|
307
|
-
}
|
|
308
300
|
}
|
|
309
301
|
function createShellToolDefinition(cwd, backendShell, contractPlatform, options) {
|
|
310
302
|
const toolName = "bash";
|
|
@@ -323,7 +315,7 @@ function createShellToolDefinition(cwd, backendShell, contractPlatform, options)
|
|
|
323
315
|
? createWindowsShellEngineOperations(sessionKey, options?.windowsShellEngineOptions)
|
|
324
316
|
: undefined;
|
|
325
317
|
const contractDescription = routesWindowsContract
|
|
326
|
-
? "Execute Pi's stable Bash-like command contract in a persistent per-agent shell session (current directory and environment variables persist across calls, including across the PowerShell and Python engine tiers). On Windows, a deterministic router converts simple commands directly to PowerShell and routes pipelines, redirection, expansion, chaining, and state-mutating commands (cd/export/unset) through a bundled Python engine that implements the supported Bash grammar; named unsupported constructs (job control, process substitution, heredocs, nested shells, and similar) fail closed instead of being guessed."
|
|
318
|
+
? "Execute Pi's stable Bash-like command contract in a persistent per-agent shell session (current directory and environment variables persist across calls, including across the PowerShell and Python engine tiers). On Windows, a deterministic router converts simple commands directly to PowerShell and routes word-list and arithmetic for loops, break/continue, portable builtins such as printf, pipelines, redirection, expansion, chaining, and state-mutating commands (cd/export/unset) through a bundled Python engine that implements the supported Bash grammar; named unsupported constructs (job control, process substitution, heredocs, nested shells, and similar) fail closed instead of being guessed."
|
|
327
319
|
: "Execute a Bash command in a persistent per-agent shell session: the current directory and environment variables persist across calls, and a timed-out or aborted command resets the session.";
|
|
328
320
|
return {
|
|
329
321
|
name: toolName,
|
|
@@ -335,7 +327,7 @@ function createShellToolDefinition(cwd, backendShell, contractPlatform, options)
|
|
|
335
327
|
promptGuidelines: routesWindowsContract
|
|
336
328
|
? [
|
|
337
329
|
"Use ordinary Bash-like commands on Windows; do not write PowerShell or ask the user to choose a shell.",
|
|
338
|
-
"
|
|
330
|
+
"Word-list and arithmetic for loops, nested break/continue, printf and the documented portable builtins, pipelines, redirection, expansion (variables, command substitution, globs), chaining (&&/||/;), and cd/export/unset are supported and routed to a bundled Python engine; shell arithmetic expansion outside a for header, job control, process substitution, heredocs, nested shells, and other named constructs fail closed with an actionable message instead of being guessed.",
|
|
339
331
|
"Working directory and environment changes from cd/export/unset persist across subsequent bash calls, including calls that route to the PowerShell tier.",
|
|
340
332
|
"Supported Bash-like file commands are converted with literal-path operations; verify targets before recursive rm, cp, or mv calls.",
|
|
341
333
|
`Keep searches scoped and purpose-driven: discover paths first, pass an explicit root and filters, and prefer the bounded grep/find tools. Broad shell searches are rejected; use broadSearch="${BROAD_SEARCH_OUTPUT_ROUTE}" only for an unavoidable exhaustive scan, then inspect the returned file with bounded reads or narrower searches.`,
|
|
@@ -649,29 +641,13 @@ function createShellToolDefinition(cwd, backendShell, contractPlatform, options)
|
|
|
649
641
|
}
|
|
650
642
|
},
|
|
651
643
|
renderCall(args, _theme, context) {
|
|
652
|
-
const state = context.state;
|
|
653
|
-
if (context.executionStarted && state.startedAt === undefined) {
|
|
654
|
-
state.startedAt = Date.now();
|
|
655
|
-
state.endedAt = undefined;
|
|
656
|
-
}
|
|
657
644
|
const text = context.lastComponent ?? new Text("", 0, 0);
|
|
658
645
|
text.setText(formatBashCall(args, toolName));
|
|
659
646
|
return text;
|
|
660
647
|
},
|
|
661
648
|
renderResult(result, options, _theme, context) {
|
|
662
|
-
const state = context.state;
|
|
663
|
-
if (state.startedAt !== undefined && options.isPartial && !state.interval) {
|
|
664
|
-
state.interval = setInterval(() => context.invalidate(), 1000);
|
|
665
|
-
}
|
|
666
|
-
if (!options.isPartial || context.isError) {
|
|
667
|
-
state.endedAt ??= Date.now();
|
|
668
|
-
if (state.interval) {
|
|
669
|
-
clearInterval(state.interval);
|
|
670
|
-
state.interval = undefined;
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
649
|
const component = context.lastComponent ?? new BashResultRenderComponent();
|
|
674
|
-
rebuildBashResultRenderComponent(component, result, options, context.showImages
|
|
650
|
+
rebuildBashResultRenderComponent(component, result, options, context.showImages);
|
|
675
651
|
component.invalidate();
|
|
676
652
|
return component;
|
|
677
653
|
},
|