@stigmer/runner 3.12.4 → 3.12.5
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/dist/.build-fingerprint +1 -1
- package/dist/activities/execute-cursor/cursor-mcp-config.d.ts +45 -0
- package/dist/activities/execute-cursor/cursor-mcp-config.js +76 -0
- package/dist/activities/execute-cursor/cursor-mcp-config.js.map +1 -0
- package/dist/activities/execute-cursor/index.d.ts +10 -1
- package/dist/activities/execute-cursor/index.js +47 -29
- package/dist/activities/execute-cursor/index.js.map +1 -1
- package/dist/activities/execute-cursor/prompt-builder.d.ts +13 -2
- package/dist/activities/execute-cursor/prompt-builder.js +11 -0
- package/dist/activities/execute-cursor/prompt-builder.js.map +1 -1
- package/dist/activities/execute-cursor/session-lifecycle.d.ts +1 -1
- package/dist/activities/execute-cursor/skill-resolver.d.ts +2 -21
- package/dist/activities/execute-cursor/skill-resolver.js +5 -108
- package/dist/activities/execute-cursor/skill-resolver.js.map +1 -1
- package/dist/activities/execute-deep-agent/approval-file-change.d.ts +9 -0
- package/dist/activities/execute-deep-agent/approval-file-change.js +2 -1
- package/dist/activities/execute-deep-agent/approval-file-change.js.map +1 -1
- package/dist/activities/execute-deep-agent/cas-capture-backend.d.ts +18 -1
- package/dist/activities/execute-deep-agent/cas-capture-backend.js +20 -3
- package/dist/activities/execute-deep-agent/cas-capture-backend.js.map +1 -1
- package/dist/activities/execute-deep-agent/index.js +57 -5
- package/dist/activities/execute-deep-agent/index.js.map +1 -1
- package/dist/activities/execute-deep-agent/prompt-builder.d.ts +9 -0
- package/dist/activities/execute-deep-agent/prompt-builder.js +10 -0
- package/dist/activities/execute-deep-agent/prompt-builder.js.map +1 -1
- package/dist/activities/execute-deep-agent/setup.js +17 -16
- package/dist/activities/execute-deep-agent/setup.js.map +1 -1
- package/dist/activities/execute-deep-agent/subagent-transformer.js +17 -11
- package/dist/activities/execute-deep-agent/subagent-transformer.js.map +1 -1
- package/dist/activities/execute-deep-agent/subagent-wiring.d.ts +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/middleware/path-normalization.d.ts +49 -49
- package/dist/middleware/path-normalization.js +73 -84
- package/dist/middleware/path-normalization.js.map +1 -1
- package/dist/middleware/types.d.ts +3 -3
- package/dist/runner-manager.d.ts +1 -1
- package/dist/runner-manager.js +22 -15
- package/dist/runner-manager.js.map +1 -1
- package/dist/runner.js +11 -0
- package/dist/runner.js.map +1 -1
- package/dist/shared/args-preview.d.ts +8 -0
- package/dist/shared/args-preview.js +14 -3
- package/dist/shared/args-preview.js.map +1 -1
- package/dist/shared/artifact-storage.d.ts +11 -1
- package/dist/shared/artifact-storage.js +10 -1
- package/dist/shared/artifact-storage.js.map +1 -1
- package/dist/shared/declared-preferences.d.ts +47 -0
- package/dist/shared/declared-preferences.js +64 -0
- package/dist/shared/declared-preferences.js.map +1 -0
- package/dist/shared/mcp-enabled-tools.d.ts +2 -3
- package/dist/shared/mcp-enabled-tools.js +2 -3
- package/dist/shared/mcp-enabled-tools.js.map +1 -1
- package/dist/shared/mcp-resolver.d.ts +20 -15
- package/dist/shared/mcp-resolver.js +11 -12
- package/dist/shared/mcp-resolver.js.map +1 -1
- package/dist/shared/placeholder-resolver.d.ts +9 -2
- package/dist/shared/placeholder-resolver.js +9 -2
- package/dist/shared/placeholder-resolver.js.map +1 -1
- package/dist/shared/plan-mode-permissions.d.ts +26 -46
- package/dist/shared/plan-mode-permissions.js +27 -55
- package/dist/shared/plan-mode-permissions.js.map +1 -1
- package/dist/shared/skill-mount.d.ts +89 -0
- package/dist/shared/skill-mount.js +142 -0
- package/dist/shared/skill-mount.js.map +1 -0
- package/dist/shared/skill-writer.d.ts +28 -26
- package/dist/shared/skill-writer.js +79 -102
- package/dist/shared/skill-writer.js.map +1 -1
- package/dist/shared/worker-shutdown.d.ts +67 -0
- package/dist/shared/worker-shutdown.js +79 -0
- package/dist/shared/worker-shutdown.js.map +1 -0
- package/dist/shared/workspace/types.d.ts +3 -2
- package/dist/workflow-engine/loader.js +38 -1
- package/dist/workflow-engine/loader.js.map +1 -1
- package/dist/workflow-engine/tasks/human-input.js +23 -2
- package/dist/workflow-engine/tasks/human-input.js.map +1 -1
- package/package.json +15 -11
- package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +50 -0
- package/src/activities/execute-cursor/__tests__/cursor-mcp-config.test.ts +111 -0
- package/src/activities/execute-cursor/__tests__/skill-resolver.test.ts +3 -94
- package/src/activities/execute-cursor/cursor-mcp-config.ts +107 -0
- package/src/activities/execute-cursor/index.ts +63 -35
- package/src/activities/execute-cursor/prompt-builder.ts +29 -2
- package/src/activities/execute-cursor/session-lifecycle.ts +1 -1
- package/src/activities/execute-cursor/skill-resolver.ts +10 -137
- package/src/activities/execute-deep-agent/__tests__/approval-file-change.test.ts +15 -0
- package/src/activities/execute-deep-agent/__tests__/cas-capture-backend.test.ts +75 -0
- package/src/activities/execute-deep-agent/__tests__/hitl-reject.test.ts +1 -0
- package/src/activities/execute-deep-agent/__tests__/hitl-resume-approve-all.test.ts +1 -0
- package/src/activities/execute-deep-agent/__tests__/hitl-resume-history.test.ts +1 -0
- package/src/activities/execute-deep-agent/__tests__/index.test.ts +1 -0
- package/src/activities/execute-deep-agent/__tests__/plan-mode-path-normalization.test.ts +42 -29
- package/src/activities/execute-deep-agent/__tests__/prompt-builder.test.ts +52 -0
- package/src/activities/execute-deep-agent/__tests__/sequential-gate-resume.test.ts +1 -0
- package/src/activities/execute-deep-agent/__tests__/subagent-plan-mode-permissions.test.ts +11 -8
- package/src/activities/execute-deep-agent/approval-file-change.ts +11 -1
- package/src/activities/execute-deep-agent/cas-capture-backend.ts +20 -3
- package/src/activities/execute-deep-agent/index.ts +57 -5
- package/src/activities/execute-deep-agent/prompt-builder.ts +22 -0
- package/src/activities/execute-deep-agent/setup.ts +21 -19
- package/src/activities/execute-deep-agent/subagent-transformer.ts +19 -12
- package/src/activities/execute-deep-agent/subagent-wiring.ts +3 -3
- package/src/index.ts +1 -1
- package/src/middleware/__tests__/path-normalization.test.ts +32 -32
- package/src/middleware/path-normalization.ts +78 -90
- package/src/middleware/types.ts +3 -3
- package/src/runner-manager.ts +26 -16
- package/src/runner.ts +14 -0
- package/src/shared/__tests__/artifact-storage.test.ts +28 -0
- package/src/shared/__tests__/bedrock-seam.test.ts +5 -5
- package/src/shared/__tests__/declared-preferences.test.ts +109 -0
- package/src/shared/__tests__/foundry-seam.test.ts +5 -5
- package/src/shared/__tests__/plan-mode-permissions.test.ts +15 -44
- package/src/shared/__tests__/skill-mount.test.ts +238 -0
- package/src/shared/__tests__/skill-writer.test.ts +151 -128
- package/src/shared/__tests__/vertex-adapter.test.ts +30 -3
- package/src/shared/__tests__/vertex-seam.test.ts +5 -5
- package/src/shared/__tests__/worker-shutdown.test.ts +101 -0
- package/src/shared/args-preview.ts +17 -3
- package/src/shared/artifact-storage.ts +20 -1
- package/src/shared/declared-preferences.ts +84 -0
- package/src/shared/mcp-enabled-tools.ts +2 -3
- package/src/shared/mcp-resolver.ts +20 -20
- package/src/shared/placeholder-resolver.ts +9 -2
- package/src/shared/plan-mode-permissions.ts +27 -58
- package/src/shared/skill-mount.ts +179 -0
- package/src/shared/skill-writer.ts +96 -130
- package/src/shared/worker-shutdown.ts +99 -0
- package/src/shared/workspace/types.ts +3 -2
- package/src/workflow-engine/__tests__/loader.test.ts +51 -0
- package/src/workflow-engine/__tests__/tasks/human-input.test.ts +117 -0
- package/src/workflow-engine/loader.ts +46 -1
- package/src/workflow-engine/tasks/human-input.ts +33 -5
- package/dist/activities/execute-cursor/connect-backfill.d.ts +0 -19
- package/dist/activities/execute-cursor/connect-backfill.js +0 -27
- package/dist/activities/execute-cursor/connect-backfill.js.map +0 -1
- package/dist/activities/execute-cursor/mcp-resolver.d.ts +0 -120
- package/dist/activities/execute-cursor/mcp-resolver.js +0 -194
- package/dist/activities/execute-cursor/mcp-resolver.js.map +0 -1
- package/dist/activities/execute-cursor/placeholder-resolver.d.ts +0 -34
- package/dist/activities/execute-cursor/placeholder-resolver.js +0 -82
- package/dist/activities/execute-cursor/placeholder-resolver.js.map +0 -1
- package/src/activities/execute-cursor/__tests__/mcp-resolver.test.ts +0 -125
- package/src/activities/execute-cursor/connect-backfill.ts +0 -52
- package/src/activities/execute-cursor/mcp-resolver.ts +0 -324
- package/src/activities/execute-cursor/placeholder-resolver.ts +0 -109
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
resolveCallerIdentity,
|
|
33
33
|
} from "../../shared/caller-identity.js";
|
|
34
34
|
import { readSessionContext } from "../../shared/session-context.js";
|
|
35
|
+
import { readDeclaredPreferences } from "../../shared/declared-preferences.js";
|
|
35
36
|
import { connectMcpServers, type McpConnectionResult } from "../../shared/mcp-manager.js";
|
|
36
37
|
import { mergeMcpServerUsages, resolveMcpServers } from "../../shared/mcp-resolver.js";
|
|
37
38
|
import { resolveMcpTransportPosture } from "../../shared/mcp-transport-guard.js";
|
|
@@ -88,12 +89,9 @@ import type { ToolApprovalCategory } from "../../shared/tool-kind.js";
|
|
|
88
89
|
import {
|
|
89
90
|
mergeSkillRefs,
|
|
90
91
|
fetchSkillsByRefs,
|
|
91
|
-
|
|
92
|
-
computeSkillPaths,
|
|
93
|
-
checkSkillIntegrity,
|
|
92
|
+
mountSkills,
|
|
94
93
|
generatePromptSection,
|
|
95
94
|
generateAlsoAvailableSection,
|
|
96
|
-
fetchSkillArtifacts,
|
|
97
95
|
} from "../../shared/skill-writer.js";
|
|
98
96
|
import { filterSkills, SKILL_COUNT_THRESHOLD } from "../../shared/skill-relevance.js";
|
|
99
97
|
import { injectAttachments } from "./attachment-injector.js";
|
|
@@ -478,8 +476,11 @@ export async function performSetup(deps: SetupDependencies): Promise<SetupResult
|
|
|
478
476
|
const skills = await fetchSkillsByRefs(client, skillRefs);
|
|
479
477
|
|
|
480
478
|
if (skills.length > 0) {
|
|
481
|
-
|
|
482
|
-
|
|
479
|
+
// platformDir is an invariant of this path: provisionWorkspace below
|
|
480
|
+
// threads ensurePlatformDir into every backend it constructs.
|
|
481
|
+
const { paths: skillPaths } = await mountSkills(
|
|
482
|
+
client, skills, workspaceBackend.platformDir!,
|
|
483
|
+
);
|
|
483
484
|
|
|
484
485
|
const userMessage = execution.spec!.message || "";
|
|
485
486
|
const skillNames = skills.map(s => s.spec?.name || s.metadata?.slug || "unknown");
|
|
@@ -573,6 +574,9 @@ export async function performSetup(deps: SetupDependencies): Promise<SetupResult
|
|
|
573
574
|
contextBridge: readContextBridge(session.spec!.metadata),
|
|
574
575
|
senderIdentity: readSenderIdentity(session.spec!.metadata),
|
|
575
576
|
sessionContext: readSessionContext(session.spec!.metadata),
|
|
577
|
+
declaredPreferences: readDeclaredPreferences(
|
|
578
|
+
execution.spec!.declaredPreferences,
|
|
579
|
+
),
|
|
576
580
|
});
|
|
577
581
|
|
|
578
582
|
// Step 9: Construct the LLM model. Resolution to the provider API id
|
|
@@ -606,16 +610,13 @@ export async function performSetup(deps: SetupDependencies): Promise<SetupResult
|
|
|
606
610
|
const execConfig = execution.spec!.executionConfig;
|
|
607
611
|
const isPlanMode = execConfig?.interactionMode === InteractionMode.PLAN;
|
|
608
612
|
const shellEnv = isPlanMode ? undefined : buildShellEnv(envResult.mergedEnvVars);
|
|
609
|
-
// Plan mode's filesystem permission rules, hoisted once: the parent graph
|
|
610
|
-
// every sub-agent graph
|
|
611
|
-
//
|
|
612
|
-
//
|
|
613
|
-
//
|
|
614
|
-
//
|
|
615
|
-
|
|
616
|
-
const planModePermissions = isPlanMode
|
|
617
|
-
? buildPlanModePermissions(workspaceBackend.rootDir)
|
|
618
|
-
: undefined;
|
|
613
|
+
// Plan mode's filesystem permission rules, hoisted once: the parent graph
|
|
614
|
+
// and every sub-agent graph carry this single value. The rules are the
|
|
615
|
+
// write-deny half of plan mode only — the read boundary is structural
|
|
616
|
+
// (virtual-rooted backends, issue #754), and the path-normalization shim
|
|
617
|
+
// is no longer tied to the rules: every native graph installs it (see
|
|
618
|
+
// buildMiddlewareStack below) so the whole harness speaks one dialect.
|
|
619
|
+
const planModePermissions = isPlanMode ? buildPlanModePermissions() : undefined;
|
|
619
620
|
|
|
620
621
|
const toolServerMap = new Map<string, string>();
|
|
621
622
|
if (mcpConnection) {
|
|
@@ -729,9 +730,10 @@ export async function performSetup(deps: SetupDependencies): Promise<SetupResult
|
|
|
729
730
|
} : null,
|
|
730
731
|
otelSpans: { toolServerMap },
|
|
731
732
|
approvalGate: approvalGateConfig,
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
733
|
+
// Every graph, every mode (issue #754): the dialect-repair seam that
|
|
734
|
+
// keeps model-supplied paths canonical for the virtual-rooted backend
|
|
735
|
+
// and every downstream consumer (gate, capture, spans).
|
|
736
|
+
pathNormalization: { rootDir: workspaceBackend.rootDir },
|
|
735
737
|
});
|
|
736
738
|
timing.mark("build_middleware");
|
|
737
739
|
|
|
@@ -42,8 +42,7 @@ import { SubAgentGate } from "../../shared/subagent-gate.js";
|
|
|
42
42
|
import { isModelRegistered } from "../../shared/model-registry.js";
|
|
43
43
|
import {
|
|
44
44
|
fetchSkillsByRefs,
|
|
45
|
-
|
|
46
|
-
writeSkills,
|
|
45
|
+
mountSkills,
|
|
47
46
|
generatePromptSection,
|
|
48
47
|
} from "../../shared/skill-writer.js";
|
|
49
48
|
|
|
@@ -493,6 +492,10 @@ export function resolveSubagentSkillPrompt(
|
|
|
493
492
|
* (approval-gated by the sub-agent's own middleware). Absent (plan mode),
|
|
494
493
|
* the backend is filesystem-only — read-only by construction, matching the
|
|
495
494
|
* parent.
|
|
495
|
+
*
|
|
496
|
+
* Every variant is virtual-rooted (`virtualMode: true`) like the parent's —
|
|
497
|
+
* see the cas-capture-backend.ts header (issue #754): workspace confinement
|
|
498
|
+
* is structural on every graph, sub-agents included.
|
|
496
499
|
*/
|
|
497
500
|
async function buildSubagentBackend(opts: {
|
|
498
501
|
readonly workspaceRootDir: string;
|
|
@@ -508,11 +511,12 @@ async function buildSubagentBackend(opts: {
|
|
|
508
511
|
}
|
|
509
512
|
|
|
510
513
|
if (opts.shellEnv === undefined) {
|
|
511
|
-
return new FilesystemBackend({ rootDir: opts.workspaceRootDir });
|
|
514
|
+
return new FilesystemBackend({ rootDir: opts.workspaceRootDir, virtualMode: true });
|
|
512
515
|
}
|
|
513
516
|
|
|
514
517
|
const shellBackend = new LocalShellBackend({
|
|
515
518
|
rootDir: opts.workspaceRootDir,
|
|
519
|
+
virtualMode: true,
|
|
516
520
|
env: opts.shellEnv,
|
|
517
521
|
});
|
|
518
522
|
await shellBackend.initialize();
|
|
@@ -554,17 +558,14 @@ export async function compileSubagents(
|
|
|
554
558
|
// Structural coupling (DD-19): a sub-agent gate flows gitignored writes into
|
|
555
559
|
// CAS iff a CAS observer backs that sub-agent's filesystem backend. Deriving
|
|
556
560
|
// both from the same `casObserver` makes "unobserved unreviewable bytes"
|
|
557
|
-
// impossible by construction.
|
|
558
|
-
// (issue #
|
|
559
|
-
//
|
|
560
|
-
// prompt-compliant relative paths from dying in rule validation.
|
|
561
|
+
// impossible by construction. Path normalization is unconditional
|
|
562
|
+
// (issue #754): every graph speaks the virtual dialect, so every graph
|
|
563
|
+
// carries the repair seam — matching the parent's composition.
|
|
561
564
|
const middleware = buildSubAgentMiddleware({
|
|
562
565
|
costCap: opts.costCap,
|
|
563
566
|
approvalGate: opts.approvalGate,
|
|
564
567
|
captureIgnored: !!opts.casObserver,
|
|
565
|
-
|
|
566
|
-
? { pathNormalization: { rootDir: opts.workspaceRootDir } }
|
|
567
|
-
: {}),
|
|
568
|
+
pathNormalization: { rootDir: opts.workspaceRootDir },
|
|
568
569
|
});
|
|
569
570
|
|
|
570
571
|
const modelName = spec.model ?? opts.parentModelName;
|
|
@@ -679,8 +680,14 @@ export async function transformAndCompileSubagents(
|
|
|
679
680
|
const skills = await fetchSkillsByRefs(skillClient, refs);
|
|
680
681
|
|
|
681
682
|
if (skills.length > 0) {
|
|
682
|
-
|
|
683
|
-
|
|
683
|
+
// Runs after the parent's setup step 7b mounted its skills, so any
|
|
684
|
+
// skill shared by parent and sub-agent is a cache hit here — the
|
|
685
|
+
// hash-keyed marker turns the old double download into a no-op.
|
|
686
|
+
// platformDir is an invariant: provisionWorkspace threads
|
|
687
|
+
// ensurePlatformDir into every backend it constructs.
|
|
688
|
+
const { paths: skillPaths } = await mountSkills(
|
|
689
|
+
skillClient, skills, workspaceBackend.platformDir!,
|
|
690
|
+
);
|
|
684
691
|
|
|
685
692
|
for (const skill of skills) {
|
|
686
693
|
const slug = (skill as { metadata?: { slug?: string } }).metadata?.slug;
|
|
@@ -75,9 +75,9 @@ export interface SubAgentMiddlewareOptions {
|
|
|
75
75
|
*/
|
|
76
76
|
readonly captureIgnored?: boolean;
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
79
|
-
* sub-agent
|
|
80
|
-
*
|
|
78
|
+
* Virtual-dialect path normalization (issues #429/#754). Present on every
|
|
79
|
+
* sub-agent graph — the backends are virtual-rooted, so every graph
|
|
80
|
+
* carries the repair seam, matching the parent composition.
|
|
81
81
|
*/
|
|
82
82
|
readonly pathNormalization?: PathNormalizationConfig;
|
|
83
83
|
}
|
package/src/index.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* import { createStigmerRunner } from '@stigmer/runner';
|
|
15
15
|
*
|
|
16
16
|
* const runner = await createStigmerRunner({
|
|
17
|
-
* taskQueue: '
|
|
17
|
+
* taskQueue: 'stigmer_runner',
|
|
18
18
|
* temporalAddress: 'localhost:7233',
|
|
19
19
|
* stigmerEndpoint: 'http://localhost:7234',
|
|
20
20
|
* });
|
|
@@ -35,36 +35,47 @@ async function argsSeenByHandler(
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
describe("normalizeWorkspacePathArg", () => {
|
|
38
|
-
it("maps a workspace-relative path to its
|
|
39
|
-
expect(normalizeWorkspacePathArg("src/main.py", ROOT)).toBe(
|
|
38
|
+
it("maps a workspace-relative path to its virtual-absolute form", () => {
|
|
39
|
+
expect(normalizeWorkspacePathArg("src/main.py", ROOT)).toBe("/src/main.py");
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
it("strips a leading ./ before
|
|
43
|
-
expect(normalizeWorkspacePathArg("./notes.md", ROOT)).toBe(
|
|
42
|
+
it("strips a leading ./ before rooting", () => {
|
|
43
|
+
expect(normalizeWorkspacePathArg("./notes.md", ROOT)).toBe("/notes.md");
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
it("handles multi-workspace entry-relative paths", () => {
|
|
47
47
|
expect(normalizeWorkspacePathArg("entry-1/src/main.py", ROOT)).toBe(
|
|
48
|
-
|
|
48
|
+
"/entry-1/src/main.py",
|
|
49
49
|
);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
it("resolves interior .. segments that stay inside the root", () => {
|
|
53
|
-
expect(normalizeWorkspacePathArg("src/../notes.md", ROOT)).toBe(
|
|
53
|
+
expect(normalizeWorkspacePathArg("src/../notes.md", ROOT)).toBe("/notes.md");
|
|
54
|
+
// Same repair on an already-virtual path: the virtual resolver rejects
|
|
55
|
+
// `..` outright, so the safe interior collapse happens at this seam.
|
|
56
|
+
expect(normalizeWorkspacePathArg("/src/../notes.md", ROOT)).toBe("/notes.md");
|
|
54
57
|
});
|
|
55
58
|
|
|
56
|
-
it("
|
|
59
|
+
it("maps a REAL-absolute in-root path to its virtual form (legacy-dialect compatibility)", () => {
|
|
60
|
+
expect(normalizeWorkspacePathArg(`${ROOT}/src/main.py`, ROOT)).toBe("/src/main.py");
|
|
61
|
+
// The root itself is the virtual root.
|
|
62
|
+
expect(normalizeWorkspacePathArg(ROOT, ROOT)).toBe("/");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("leaves canonical virtual-absolute paths untouched", () => {
|
|
66
|
+
// In the virtual dialect these are already canonical names — "/etc/hosts"
|
|
67
|
+
// means the WORKSPACE's etc/hosts, not the host file.
|
|
57
68
|
expect(normalizeWorkspacePathArg("/etc/hosts", ROOT)).toBeUndefined();
|
|
58
|
-
expect(normalizeWorkspacePathArg(`${ROOT}/src/main.py`, ROOT)).toBeUndefined();
|
|
59
69
|
expect(normalizeWorkspacePathArg("/", ROOT)).toBeUndefined();
|
|
60
70
|
});
|
|
61
71
|
|
|
62
72
|
it("refuses to rewrite relatives that escape the workspace root", () => {
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
73
|
+
// posix.normalize would silently swallow a leading ".." on an absolute
|
|
74
|
+
// path — rewriting the call onto a DIFFERENT in-root file. The escape is
|
|
75
|
+
// detected in relative form and left raw for the upstream refusal.
|
|
66
76
|
expect(normalizeWorkspacePathArg("../sibling/secret.txt", ROOT)).toBeUndefined();
|
|
67
77
|
expect(normalizeWorkspacePathArg("src/../../escape.txt", ROOT)).toBeUndefined();
|
|
78
|
+
expect(normalizeWorkspacePathArg("/src/../../escape.txt", ROOT)).toBeUndefined();
|
|
68
79
|
});
|
|
69
80
|
|
|
70
81
|
it("leaves ~-carrying paths untouched (upstream refuses them either way)", () => {
|
|
@@ -84,7 +95,7 @@ describe("createPathNormalizationMiddleware", () => {
|
|
|
84
95
|
file_path: "src/main.py",
|
|
85
96
|
content: "x",
|
|
86
97
|
});
|
|
87
|
-
expect(args.file_path).toBe(
|
|
98
|
+
expect(args.file_path).toBe("/src/main.py");
|
|
88
99
|
// Sibling args ride along untouched.
|
|
89
100
|
expect(args.content).toBe("x");
|
|
90
101
|
}
|
|
@@ -93,27 +104,26 @@ describe("createPathNormalizationMiddleware", () => {
|
|
|
93
104
|
it("rewrites the base path on ls/glob/grep", async () => {
|
|
94
105
|
for (const tool of ["ls", "glob", "grep"]) {
|
|
95
106
|
const args = await argsSeenByHandler(tool, { path: "src", pattern: "**/*.py" });
|
|
96
|
-
expect(args.path).toBe(
|
|
107
|
+
expect(args.path).toBe("/src");
|
|
97
108
|
// The pattern is never a path — byte-untouched.
|
|
98
109
|
expect(args.pattern).toBe("**/*.py");
|
|
99
110
|
}
|
|
100
111
|
});
|
|
101
112
|
|
|
102
|
-
it("passes
|
|
113
|
+
it("passes canonical virtual paths through byte-untouched", async () => {
|
|
103
114
|
const args = await argsSeenByHandler("read_file", { file_path: "/etc/hosts" });
|
|
104
115
|
expect(args.file_path).toBe("/etc/hosts");
|
|
105
116
|
});
|
|
106
117
|
|
|
107
|
-
it("
|
|
108
|
-
// Deliberate reversal of the
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
// already knows.
|
|
118
|
+
it("leaves an omitted base path alone — the tools' '/' default IS the workspace root now", async () => {
|
|
119
|
+
// Deliberate reversal of the #528 injection: under the legacy backend the
|
|
120
|
+
// schema default "/" meant the OS ROOT, so the middleware had to fill the
|
|
121
|
+
// omission. Under the virtual root (issue #754) the default already means
|
|
122
|
+
// the workspace root — filling it would just duplicate the tool's own
|
|
123
|
+
// behavior.
|
|
114
124
|
for (const tool of ["ls", "glob", "grep"]) {
|
|
115
125
|
const args = await argsSeenByHandler(tool, { pattern: "TOKEN" });
|
|
116
|
-
expect(args.path).
|
|
126
|
+
expect(args.path).toBeUndefined();
|
|
117
127
|
expect(args.pattern).toBe("TOKEN");
|
|
118
128
|
}
|
|
119
129
|
});
|
|
@@ -125,16 +135,6 @@ describe("createPathNormalizationMiddleware", () => {
|
|
|
125
135
|
expect(args.file_path).toBeUndefined();
|
|
126
136
|
});
|
|
127
137
|
|
|
128
|
-
it("leaves an explicit '/' untouched on the dir tools — the rules answer it honestly", async () => {
|
|
129
|
-
// The model asked for the OS root; under plan mode's read boundary the
|
|
130
|
-
// honest answer is the rules' denial, not silently substituted workspace
|
|
131
|
-
// contents (the #429 never-convert-a-refusal-into-an-allowance doctrine).
|
|
132
|
-
for (const tool of ["ls", "glob", "grep"]) {
|
|
133
|
-
const args = await argsSeenByHandler(tool, { path: "/" });
|
|
134
|
-
expect(args.path).toBe("/");
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
|
|
138
138
|
it("never touches tools outside the built-in filesystem set", async () => {
|
|
139
139
|
// An MCP tool could plausibly carry a same-named arg with different
|
|
140
140
|
// semantics; only the six built-in names are rewritten.
|
|
@@ -1,55 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* (issues #429, #528).
|
|
2
|
+
* Canonical virtual-path normalization for the native harness's built-in
|
|
3
|
+
* filesystem tools (issues #429, #528, #754).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* the shape the multi-workspace prompt explicitly mandates, and one models
|
|
11
|
-
* routinely choose in single-workspace sessions — fails with
|
|
12
|
-
* `path must be absolute` instead of just working, burning tool rounds until
|
|
13
|
-
* the model adapts by switching to absolute paths.
|
|
5
|
+
* The native harness speaks ONE path dialect end to end: the VIRTUAL ROOT,
|
|
6
|
+
* where "/" denotes the workspace root (backends are constructed with
|
|
7
|
+
* `virtualMode: true` — see execute-deep-agent/cas-capture-backend.ts). This
|
|
8
|
+
* middleware is the dialect-repair seam at the model boundary. It rewrites,
|
|
9
|
+
* on the deepagents built-in filesystem tools only:
|
|
14
10
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
11
|
+
* - workspace-relative paths ("src/x.py", "./notes.md") to their virtual
|
|
12
|
+
* absolute form ("/src/x.py") — deepagents' permission validation refuses
|
|
13
|
+
* non-absolute shapes on rule-bearing graphs (plan mode), and the prompt
|
|
14
|
+
* explicitly mandates entry-relative paths, so without this seam a
|
|
15
|
+
* prompt-compliant call would die with `path must be absolute`;
|
|
16
|
+
* - REAL-absolute paths under the workspace root ("{root}/src/x.py") to
|
|
17
|
+
* their virtual form ("/src/x.py") — the compatibility mapping for the
|
|
18
|
+
* pre-#754 dialect, where tool results and transcripts surfaced real
|
|
19
|
+
* filesystem paths that a model may still echo back;
|
|
20
|
+
* - interior `..` segments that stay inside the root ("src/../notes.md" →
|
|
21
|
+
* "/notes.md") — the virtual resolver rejects `..` outright, so a safe
|
|
22
|
+
* interior collapse is repaired here rather than burning a tool round.
|
|
22
23
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* (the same first-turn degradation class #429 fixed). An EXPLICIT "/" is
|
|
29
|
-
* deliberately NOT rewritten: the model asked for the OS root, and the
|
|
30
|
-
* honest answer under plan mode's read boundary is the rules' denial —
|
|
31
|
-
* silently substituting workspace contents would be an answer to a
|
|
32
|
-
* different question.
|
|
24
|
+
* Nothing becomes newly reachable: escaping relatives ("../x") and
|
|
25
|
+
* `~`-carrying paths are left raw so the upstream refusal keeps speaking,
|
|
26
|
+
* and every rewritten path is workspace-confined by the virtual resolver
|
|
27
|
+
* regardless. The middleware converts false errors into correct behavior —
|
|
28
|
+
* never a refusal into an allowance.
|
|
33
29
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* injection
|
|
42
|
-
* to the workspace, granting nothing the rules would refuse.)
|
|
30
|
+
* Installed on EVERY native graph (parent and sub-agent, act and plan mode)
|
|
31
|
+
* so all downstream consumers — the approval gate's capturability checks,
|
|
32
|
+
* the CAS observer, otel spans — observe one canonical dialect. The pre-#754
|
|
33
|
+
* version was installed only beside permission rules and also injected the
|
|
34
|
+
* workspace root when `ls`/`glob`/`grep` omitted their path (the tools'
|
|
35
|
+
* schema default "/" was the OS ROOT under the legacy backend); under the
|
|
36
|
+
* virtual root that default already MEANS the workspace root, so the
|
|
37
|
+
* injection is retired.
|
|
43
38
|
*
|
|
44
39
|
* Tool matching is by bare built-in name, the house doctrine (an MCP server
|
|
45
40
|
* is not expected to shadow a built-in name — see shared/tool-kind.ts); the
|
|
46
41
|
* rewrite touches only the tool's path-bearing argument, never glob/grep
|
|
47
42
|
* patterns. Install FIRST in the stack so every downstream middleware
|
|
48
|
-
*
|
|
43
|
+
* observes canonical paths.
|
|
49
44
|
*/
|
|
50
45
|
|
|
51
|
-
import { isAbsolute, relative } from "node:path";
|
|
52
|
-
import { resolveWorkspacePath } from "../shared/file-change.js";
|
|
46
|
+
import { isAbsolute, relative, posix } from "node:path";
|
|
53
47
|
import type { StigmerMiddleware } from "./types.js";
|
|
54
48
|
|
|
55
49
|
/**
|
|
@@ -66,55 +60,65 @@ const PATH_ARG_BY_TOOL: ReadonlyMap<string, string> = new Map([
|
|
|
66
60
|
["edit_file", "file_path"],
|
|
67
61
|
]);
|
|
68
62
|
|
|
69
|
-
/**
|
|
70
|
-
* The tools whose path argument is optional with an OS-root ("/") schema
|
|
71
|
-
* default. When the model omits it, this middleware supplies the workspace
|
|
72
|
-
* root instead (issue #528). The file tools are deliberately excluded: an
|
|
73
|
-
* absent `file_path` is a genuine model error, and the tool's own input
|
|
74
|
-
* validation gives the better message.
|
|
75
|
-
*/
|
|
76
|
-
const DIR_DEFAULTING_TOOLS: ReadonlySet<string> = new Set(["ls", "glob", "grep"]);
|
|
77
|
-
|
|
78
63
|
export interface PathNormalizationConfig {
|
|
79
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* The REAL workspace root the graph's backend is rooted at — used only for
|
|
66
|
+
* the legacy-dialect compatibility mapping (real-absolute in-root paths →
|
|
67
|
+
* virtual). The virtual rewrite itself needs no root.
|
|
68
|
+
*/
|
|
80
69
|
readonly rootDir: string;
|
|
81
70
|
}
|
|
82
71
|
|
|
83
72
|
/**
|
|
84
|
-
* Rewrite `raw` to its
|
|
85
|
-
* value must be left untouched
|
|
86
|
-
* the
|
|
73
|
+
* Rewrite `raw` to its canonical virtual-absolute form, or return undefined
|
|
74
|
+
* when the value must be left untouched. Exported for direct unit testing of
|
|
75
|
+
* the mapping table.
|
|
76
|
+
*
|
|
77
|
+
* Left raw (undefined): empty strings, `~`-carrying paths (refused upstream
|
|
78
|
+
* in every mode), escaping relatives ("../x" — the refusal is the honest
|
|
79
|
+
* answer), real-absolute paths OUTSIDE the root (virtual dialect: they name
|
|
80
|
+
* an in-workspace path that simply does not exist — resolution answers
|
|
81
|
+
* honestly), and paths already in canonical virtual form.
|
|
87
82
|
*/
|
|
88
83
|
export function normalizeWorkspacePathArg(
|
|
89
84
|
raw: string,
|
|
90
85
|
rootDir: string,
|
|
91
86
|
): string | undefined {
|
|
92
|
-
if (raw.length === 0
|
|
93
|
-
// Upstream validation refuses `~` segments
|
|
94
|
-
//
|
|
95
|
-
// therefore the honest refusal) intact.
|
|
87
|
+
if (raw.length === 0) return undefined;
|
|
88
|
+
// Upstream validation refuses `~` segments in every position, and a rewrite
|
|
89
|
+
// could not make such a call succeed — leave the honest refusal intact.
|
|
96
90
|
if (raw.split("/").includes("~")) return undefined;
|
|
97
91
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
92
|
+
// Legacy-dialect compatibility: a REAL absolute path under the workspace
|
|
93
|
+
// root maps to its virtual form. Any other absolute path is already a
|
|
94
|
+
// virtual-dialect name — reduced to relative form for canonicalization.
|
|
95
|
+
let candidate: string;
|
|
96
|
+
if (isAbsolute(raw)) {
|
|
97
|
+
const rel = relative(rootDir, raw);
|
|
98
|
+
if (rel === "") return "/";
|
|
99
|
+
candidate =
|
|
100
|
+
rel && !rel.startsWith("..") && !isAbsolute(rel)
|
|
101
|
+
? rel
|
|
102
|
+
: raw.replace(/^\/+/, "");
|
|
103
|
+
} else {
|
|
104
|
+
candidate = raw;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Canonicalize in RELATIVE form first: posix.normalize keeps a leading
|
|
108
|
+
// ".." on relative paths but silently swallows it on absolute ones, and a
|
|
109
|
+
// swallowed escape would rewrite the call onto a DIFFERENT in-root path —
|
|
110
|
+
// a refusal converted into an allowance. Detect the escape while it is
|
|
111
|
+
// still visible, and leave it raw for the upstream refusal.
|
|
112
|
+
const normalizedRel = posix.normalize(candidate);
|
|
113
|
+
if (normalizedRel === ".." || normalizedRel.startsWith("../")) return undefined;
|
|
114
|
+
|
|
115
|
+
const virtual = normalizedRel === "." ? "/" : `/${normalizedRel}`;
|
|
116
|
+
return virtual === raw ? undefined : virtual;
|
|
108
117
|
}
|
|
109
118
|
|
|
110
119
|
/**
|
|
111
|
-
* Create
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* Installed only on graphs that carry filesystem permission rules — derive
|
|
115
|
-
* the install condition from the same expression that supplies the rules
|
|
116
|
-
* (setup.ts / compileSubagents) so the rules and their normalization shim
|
|
117
|
-
* cannot drift apart.
|
|
120
|
+
* Create the dialect-repair middleware (see module header). Stateless per
|
|
121
|
+
* request; safe on every graph.
|
|
118
122
|
*/
|
|
119
123
|
export function createPathNormalizationMiddleware(
|
|
120
124
|
config: PathNormalizationConfig,
|
|
@@ -129,22 +133,6 @@ export function createPathNormalizationMiddleware(
|
|
|
129
133
|
if (!argKey) return handler(request);
|
|
130
134
|
|
|
131
135
|
const raw = request.toolCall.args[argKey];
|
|
132
|
-
|
|
133
|
-
// Absent base directory on ls/glob/grep: the middleware sees the
|
|
134
|
-
// model's raw args, BEFORE the tool's zod parse applies the "/"
|
|
135
|
-
// (OS root) schema default — so the omission must be filled here,
|
|
136
|
-
// where the workspace root is known. An explicit "/" is not this
|
|
137
|
-
// case and flows through to an honest rule denial (header doctrine).
|
|
138
|
-
if (raw == null && DIR_DEFAULTING_TOOLS.has(request.toolCall.name)) {
|
|
139
|
-
return handler({
|
|
140
|
-
...request,
|
|
141
|
-
toolCall: {
|
|
142
|
-
...request.toolCall,
|
|
143
|
-
args: { ...request.toolCall.args, [argKey]: rootDir },
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
136
|
if (typeof raw !== "string") return handler(request);
|
|
149
137
|
|
|
150
138
|
const normalized = normalizeWorkspacePathArg(raw, rootDir);
|
package/src/middleware/types.ts
CHANGED
|
@@ -117,9 +117,9 @@ export interface MiddlewareStackConfig {
|
|
|
117
117
|
readonly otelSpans?: Partial<OtelSpansConfig>;
|
|
118
118
|
readonly approvalGate?: ApprovalGateConfig | null;
|
|
119
119
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
120
|
+
* Virtual-dialect path normalization (issues #429/#754). Set on every
|
|
121
|
+
* native graph: the backends are virtual-rooted, so every graph carries
|
|
122
|
+
* the repair seam that keeps model-supplied paths canonical.
|
|
123
123
|
*/
|
|
124
124
|
readonly pathNormalization?: PathNormalizationConfig | null;
|
|
125
125
|
}
|
package/src/runner-manager.ts
CHANGED
|
@@ -49,6 +49,10 @@ import {
|
|
|
49
49
|
setQueueDrainCallback,
|
|
50
50
|
forgetQueue,
|
|
51
51
|
} from "./in-flight.js";
|
|
52
|
+
import {
|
|
53
|
+
registerWorkerShutdownSignal,
|
|
54
|
+
unregisterWorkerShutdownSignal,
|
|
55
|
+
} from "./shared/worker-shutdown.js";
|
|
52
56
|
|
|
53
57
|
const SESSION_QUEUE_PREFIX = "session:";
|
|
54
58
|
const WFEXEC_QUEUE_PREFIX = "wfexec:";
|
|
@@ -57,16 +61,10 @@ const WFEXEC_QUEUE_PREFIX = "wfexec:";
|
|
|
57
61
|
// Mirrors SessionDispatchService's convention: lowercase kind, colon, id.
|
|
58
62
|
const POOL_CONTROL_QUEUE_PREFIX = "sandbox:";
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*/
|
|
65
|
-
const _shutdownSignalRegistry = new Map<string, AbortSignal>();
|
|
66
|
-
|
|
67
|
-
export function getShutdownSignalForQueue(taskQueue: string): AbortSignal | undefined {
|
|
68
|
-
return _shutdownSignalRegistry.get(taskQueue);
|
|
69
|
-
}
|
|
64
|
+
// Re-export for existing importers; the registry itself lives in
|
|
65
|
+
// shared/worker-shutdown.ts so the static runner (runner.ts) and the
|
|
66
|
+
// activities can share it without importing this manager module.
|
|
67
|
+
export { getShutdownSignalForQueue } from "./shared/worker-shutdown.js";
|
|
70
68
|
|
|
71
69
|
export interface RunnerManagerOptions {
|
|
72
70
|
/**
|
|
@@ -411,15 +409,12 @@ export async function createStigmerRunnerManager(
|
|
|
411
409
|
|
|
412
410
|
const sessions = new Map<string, ManagedSession>();
|
|
413
411
|
const workflowExecutions = new Map<string, ManagedSession>();
|
|
414
|
-
const shutdownSignals = new Map<string, AbortController>();
|
|
415
412
|
// At most one per process: a pool member IS its control worker's identity.
|
|
416
413
|
let poolControl: { taskQueue: string; managed: ManagedSession } | null = null;
|
|
417
414
|
let shuttingDown = false;
|
|
418
415
|
|
|
419
416
|
async function createWorkerOnQueue(taskQueue: string): Promise<ManagedSession> {
|
|
420
|
-
const shutdownController =
|
|
421
|
-
shutdownSignals.set(taskQueue, shutdownController);
|
|
422
|
-
_shutdownSignalRegistry.set(taskQueue, shutdownController.signal);
|
|
417
|
+
const shutdownController = registerWorkerShutdownSignal(taskQueue);
|
|
423
418
|
|
|
424
419
|
const worker = await Worker.create({
|
|
425
420
|
connection,
|
|
@@ -481,8 +476,7 @@ export async function createStigmerRunnerManager(
|
|
|
481
476
|
managed.worker.shutdown();
|
|
482
477
|
await managed.runPromise;
|
|
483
478
|
registry.delete(id);
|
|
484
|
-
|
|
485
|
-
_shutdownSignalRegistry.delete(taskQueue);
|
|
479
|
+
unregisterWorkerShutdownSignal(taskQueue);
|
|
486
480
|
forgetQueue(taskQueue);
|
|
487
481
|
console.log(`[runner-manager] Removed ${kind} ${id} (active=${registry.size})`);
|
|
488
482
|
}
|
|
@@ -620,6 +614,22 @@ export async function createStigmerRunnerManager(
|
|
|
620
614
|
`[runner-manager] Shutting down ${totalWorkers} workers (${sessions.size} sessions, ${workflowExecutions.size} workflow executions)...`,
|
|
621
615
|
);
|
|
622
616
|
|
|
617
|
+
// Mark every queue's shutdown signal BEFORE draining, so an in-flight
|
|
618
|
+
// activity cancelled by the drain classifies it as a worker shutdown
|
|
619
|
+
// rather than a user pause (issue #776 — a SIGTERM'd pool member used
|
|
620
|
+
// to persist EXECUTION_PAUSED and let raw Temporal drain text reach
|
|
621
|
+
// status.error). Aborting is classification-only: it stops nothing;
|
|
622
|
+
// worker.shutdown() below still owns the drain. This is deliberately
|
|
623
|
+
// NOT done in teardownManaged — single-worker teardowns only run once
|
|
624
|
+
// the queue is idle, and aborting there is the old view-close bug.
|
|
625
|
+
for (const session of sessions.values()) {
|
|
626
|
+
session.shutdownController.abort();
|
|
627
|
+
}
|
|
628
|
+
for (const execution of workflowExecutions.values()) {
|
|
629
|
+
execution.shutdownController.abort();
|
|
630
|
+
}
|
|
631
|
+
poolControl?.managed.shutdownController.abort();
|
|
632
|
+
|
|
623
633
|
const shutdownPromises = [
|
|
624
634
|
...Array.from(sessions.entries()).map(
|
|
625
635
|
async ([id, session]) => {
|