@archmax-ai/harness 0.0.0
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/LICENSE +21 -0
- package/README.md +219 -0
- package/dist/agent.d.ts +174 -0
- package/dist/agent.js +140 -0
- package/dist/agent.js.map +1 -0
- package/dist/assembly/compose.d.ts +170 -0
- package/dist/assembly/compose.js +391 -0
- package/dist/assembly/compose.js.map +1 -0
- package/dist/assembly/delegation-registry.d.ts +5 -0
- package/dist/assembly/delegation-registry.js +118 -0
- package/dist/assembly/delegation-registry.js.map +1 -0
- package/dist/assembly/index.d.ts +192 -0
- package/dist/assembly/index.js +265 -0
- package/dist/assembly/index.js.map +1 -0
- package/dist/assembly/plain.d.ts +7 -0
- package/dist/assembly/plain.js +41 -0
- package/dist/assembly/plain.js.map +1 -0
- package/dist/authoring-skill/archmax-harness/README.md +76 -0
- package/dist/authoring-skill/archmax-harness/SKILL.md +241 -0
- package/dist/authoring-skill/archmax-harness/references/backend-integration.md +626 -0
- package/dist/authoring-skill/archmax-harness/references/cases.md +41 -0
- package/dist/authoring-skill/archmax-harness/references/diagnostics.md +51 -0
- package/dist/authoring-skill/archmax-harness/references/hook-and-test-scripts.md +1070 -0
- package/dist/authoring-skill/archmax-harness/references/hooks-and-scripts.md +82 -0
- package/dist/authoring-skill/archmax-harness/references/wiring.md +101 -0
- package/dist/authoring-skill/archmax-harness/references/workflow-schema.md +1631 -0
- package/dist/authoring-skill/archmax-harness/references/workflow-yaml.md +241 -0
- package/dist/behaviour/support.d.ts +232 -0
- package/dist/behaviour/support.js +339 -0
- package/dist/behaviour/support.js.map +1 -0
- package/dist/cli/banner.d.ts +11 -0
- package/dist/cli/banner.js +29 -0
- package/dist/cli/banner.js.map +1 -0
- package/dist/cli/bootstrap.d.ts +33 -0
- package/dist/cli/bootstrap.js +153 -0
- package/dist/cli/bootstrap.js.map +1 -0
- package/dist/cli/command.d.ts +39 -0
- package/dist/cli/command.js +97 -0
- package/dist/cli/command.js.map +1 -0
- package/dist/cli/state-flow.d.ts +46 -0
- package/dist/cli/state-flow.js +268 -0
- package/dist/cli/state-flow.js.map +1 -0
- package/dist/cli/style.d.ts +41 -0
- package/dist/cli/style.js +64 -0
- package/dist/cli/style.js.map +1 -0
- package/dist/cli/turn.d.ts +41 -0
- package/dist/cli/turn.js +161 -0
- package/dist/cli/turn.js.map +1 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.js +426 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/code-description.d.ts +22 -0
- package/dist/core/code-description.js +38 -0
- package/dist/core/code-description.js.map +1 -0
- package/dist/core/deepagents.d.ts +183 -0
- package/dist/core/deepagents.js +128 -0
- package/dist/core/deepagents.js.map +1 -0
- package/dist/core/events.d.ts +350 -0
- package/dist/core/events.js +205 -0
- package/dist/core/events.js.map +1 -0
- package/dist/core/frontmatter.d.ts +15 -0
- package/dist/core/frontmatter.js +32 -0
- package/dist/core/frontmatter.js.map +1 -0
- package/dist/core/listing-redact.d.ts +37 -0
- package/dist/core/listing-redact.js +88 -0
- package/dist/core/listing-redact.js.map +1 -0
- package/dist/core/match.d.ts +26 -0
- package/dist/core/match.js +75 -0
- package/dist/core/match.js.map +1 -0
- package/dist/core/message-readers.d.ts +84 -0
- package/dist/core/message-readers.js +159 -0
- package/dist/core/message-readers.js.map +1 -0
- package/dist/core/messages.d.ts +49 -0
- package/dist/core/messages.js +85 -0
- package/dist/core/messages.js.map +1 -0
- package/dist/core/mount-prompt.d.ts +28 -0
- package/dist/core/mount-prompt.js +55 -0
- package/dist/core/mount-prompt.js.map +1 -0
- package/dist/core/mount-redact.d.ts +28 -0
- package/dist/core/mount-redact.js +32 -0
- package/dist/core/mount-redact.js.map +1 -0
- package/dist/core/mounts.d.ts +88 -0
- package/dist/core/mounts.js +147 -0
- package/dist/core/mounts.js.map +1 -0
- package/dist/core/path-mapping.d.ts +52 -0
- package/dist/core/path-mapping.js +113 -0
- package/dist/core/path-mapping.js.map +1 -0
- package/dist/core/platform-prompt.generated.d.ts +2 -0
- package/dist/core/platform-prompt.generated.js +4 -0
- package/dist/core/platform-prompt.generated.js.map +1 -0
- package/dist/core/prompt.d.ts +42 -0
- package/dist/core/prompt.js +75 -0
- package/dist/core/prompt.js.map +1 -0
- package/dist/core/session-id.d.ts +38 -0
- package/dist/core/session-id.js +61 -0
- package/dist/core/session-id.js.map +1 -0
- package/dist/core/session-store.d.ts +85 -0
- package/dist/core/session-store.js +149 -0
- package/dist/core/session-store.js.map +1 -0
- package/dist/core/session-zone.d.ts +54 -0
- package/dist/core/session-zone.js +82 -0
- package/dist/core/session-zone.js.map +1 -0
- package/dist/core/skill-prompt.d.ts +31 -0
- package/dist/core/skill-prompt.js +54 -0
- package/dist/core/skill-prompt.js.map +1 -0
- package/dist/core/skill-redact.d.ts +15 -0
- package/dist/core/skill-redact.js +27 -0
- package/dist/core/skill-redact.js.map +1 -0
- package/dist/core/skills.d.ts +172 -0
- package/dist/core/skills.js +214 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/tool-mocks.d.ts +23 -0
- package/dist/core/tool-mocks.js +39 -0
- package/dist/core/tool-mocks.js.map +1 -0
- package/dist/core/tool-telemetry.d.ts +16 -0
- package/dist/core/tool-telemetry.js +40 -0
- package/dist/core/tool-telemetry.js.map +1 -0
- package/dist/core/usage.d.ts +114 -0
- package/dist/core/usage.js +226 -0
- package/dist/core/usage.js.map +1 -0
- package/dist/core/workspace-context.d.ts +136 -0
- package/dist/core/workspace-context.js +178 -0
- package/dist/core/workspace-context.js.map +1 -0
- package/dist/core/workspace-prompt.d.ts +7 -0
- package/dist/core/workspace-prompt.js +102 -0
- package/dist/core/workspace-prompt.js.map +1 -0
- package/dist/core/workspace-router.d.ts +61 -0
- package/dist/core/workspace-router.js +145 -0
- package/dist/core/workspace-router.js.map +1 -0
- package/dist/core/workspace.d.ts +85 -0
- package/dist/core/workspace.js +193 -0
- package/dist/core/workspace.js.map +1 -0
- package/dist/core/zones.d.ts +181 -0
- package/dist/core/zones.js +202 -0
- package/dist/core/zones.js.map +1 -0
- package/dist/env.d.ts +99 -0
- package/dist/env.js +271 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +265 -0
- package/dist/index.js +197 -0
- package/dist/index.js.map +1 -0
- package/dist/kernel/kernel.d.ts +192 -0
- package/dist/kernel/kernel.js +751 -0
- package/dist/kernel/kernel.js.map +1 -0
- package/dist/lifecycle/hook-shape.d.ts +44 -0
- package/dist/lifecycle/hook-shape.js +66 -0
- package/dist/lifecycle/hook-shape.js.map +1 -0
- package/dist/lifecycle/runner.d.ts +177 -0
- package/dist/lifecycle/runner.js +372 -0
- package/dist/lifecycle/runner.js.map +1 -0
- package/dist/lifecycle/transcript.d.ts +27 -0
- package/dist/lifecycle/transcript.js +43 -0
- package/dist/lifecycle/transcript.js.map +1 -0
- package/dist/machine/allow.d.ts +65 -0
- package/dist/machine/allow.js +107 -0
- package/dist/machine/allow.js.map +1 -0
- package/dist/machine/delegation.d.ts +9 -0
- package/dist/machine/delegation.js +10 -0
- package/dist/machine/delegation.js.map +1 -0
- package/dist/machine/diagnostic.d.ts +14 -0
- package/dist/machine/diagnostic.js +2 -0
- package/dist/machine/diagnostic.js.map +1 -0
- package/dist/machine/lint-spec.d.ts +4 -0
- package/dist/machine/lint-spec.js +266 -0
- package/dist/machine/lint-spec.js.map +1 -0
- package/dist/machine/load-spec.d.ts +90 -0
- package/dist/machine/load-spec.js +120 -0
- package/dist/machine/load-spec.js.map +1 -0
- package/dist/machine/machine.d.ts +273 -0
- package/dist/machine/machine.js +551 -0
- package/dist/machine/machine.js.map +1 -0
- package/dist/machine/mount-grants.d.ts +25 -0
- package/dist/machine/mount-grants.js +24 -0
- package/dist/machine/mount-grants.js.map +1 -0
- package/dist/machine/slug.d.ts +14 -0
- package/dist/machine/slug.js +17 -0
- package/dist/machine/slug.js.map +1 -0
- package/dist/machine/spec-schema.d.ts +662 -0
- package/dist/machine/spec-schema.js +717 -0
- package/dist/machine/spec-schema.js.map +1 -0
- package/dist/machine/tool-names.d.ts +98 -0
- package/dist/machine/tool-names.js +144 -0
- package/dist/machine/tool-names.js.map +1 -0
- package/dist/machine/triggers.d.ts +114 -0
- package/dist/machine/triggers.js +165 -0
- package/dist/machine/triggers.js.map +1 -0
- package/dist/machine/types.d.ts +186 -0
- package/dist/machine/types.js +12 -0
- package/dist/machine/types.js.map +1 -0
- package/dist/machine/validate-spec.d.ts +42 -0
- package/dist/machine/validate-spec.js +29 -0
- package/dist/machine/validate-spec.js.map +1 -0
- package/dist/machine/variables.d.ts +196 -0
- package/dist/machine/variables.js +415 -0
- package/dist/machine/variables.js.map +1 -0
- package/dist/public/cli.d.ts +15 -0
- package/dist/public/cli.js +14 -0
- package/dist/public/cli.js.map +1 -0
- package/dist/public/messages.d.ts +33 -0
- package/dist/public/messages.js +33 -0
- package/dist/public/messages.js.map +1 -0
- package/dist/public/sandbox.d.ts +99 -0
- package/dist/public/sandbox.js +32 -0
- package/dist/public/sandbox.js.map +1 -0
- package/dist/public/spec.d.ts +147 -0
- package/dist/public/spec.js +149 -0
- package/dist/public/spec.js.map +1 -0
- package/dist/public/testing.d.ts +71 -0
- package/dist/public/testing.js +39 -0
- package/dist/public/testing.js.map +1 -0
- package/dist/rubrics/rubrics.d.ts +135 -0
- package/dist/rubrics/rubrics.js +145 -0
- package/dist/rubrics/rubrics.js.map +1 -0
- package/dist/runtime/contract.d.ts +73 -0
- package/dist/runtime/contract.js +96 -0
- package/dist/runtime/contract.js.map +1 -0
- package/dist/sandbox/assets/parts/core.js +22 -0
- package/dist/sandbox/assets/parts/lifecycle-hook.js +47 -0
- package/dist/sandbox/bridge.d.ts +16 -0
- package/dist/sandbox/bridge.js +95 -0
- package/dist/sandbox/bridge.js.map +1 -0
- package/dist/sandbox/executor.d.ts +46 -0
- package/dist/sandbox/executor.js +119 -0
- package/dist/sandbox/executor.js.map +1 -0
- package/dist/sandbox/imports.d.ts +33 -0
- package/dist/sandbox/imports.js +67 -0
- package/dist/sandbox/imports.js.map +1 -0
- package/dist/sandbox/prelude.d.ts +12 -0
- package/dist/sandbox/prelude.js +51 -0
- package/dist/sandbox/prelude.js.map +1 -0
- package/dist/sandbox/ptc-gateway.d.ts +104 -0
- package/dist/sandbox/ptc-gateway.js +167 -0
- package/dist/sandbox/ptc-gateway.js.map +1 -0
- package/dist/sandbox/runtime.d.ts +59 -0
- package/dist/sandbox/runtime.js +51 -0
- package/dist/sandbox/runtime.js.map +1 -0
- package/dist/sandbox/tools.d.ts +34 -0
- package/dist/sandbox/tools.js +147 -0
- package/dist/sandbox/tools.js.map +1 -0
- package/dist/sessions/operations.d.ts +79 -0
- package/dist/sessions/operations.js +121 -0
- package/dist/sessions/operations.js.map +1 -0
- package/dist/sessions/resolve.d.ts +97 -0
- package/dist/sessions/resolve.js +145 -0
- package/dist/sessions/resolve.js.map +1 -0
- package/dist/sessions/resume.d.ts +242 -0
- package/dist/sessions/resume.js +288 -0
- package/dist/sessions/resume.js.map +1 -0
- package/dist/sessions/scope.d.ts +99 -0
- package/dist/sessions/scope.js +145 -0
- package/dist/sessions/scope.js.map +1 -0
- package/dist/sessions/summary.d.ts +65 -0
- package/dist/sessions/summary.js +56 -0
- package/dist/sessions/summary.js.map +1 -0
- package/dist/testing/assertions.d.ts +30 -0
- package/dist/testing/assertions.js +231 -0
- package/dist/testing/assertions.js.map +1 -0
- package/dist/testing/case-document.d.ts +141 -0
- package/dist/testing/case-document.js +51 -0
- package/dist/testing/case-document.js.map +1 -0
- package/dist/testing/case-schema.d.ts +29 -0
- package/dist/testing/case-schema.js +519 -0
- package/dist/testing/case-schema.js.map +1 -0
- package/dist/testing/discovery.d.ts +10 -0
- package/dist/testing/discovery.js +24 -0
- package/dist/testing/discovery.js.map +1 -0
- package/dist/testing/driver.d.ts +78 -0
- package/dist/testing/driver.js +117 -0
- package/dist/testing/driver.js.map +1 -0
- package/dist/testing/grade.d.ts +116 -0
- package/dist/testing/grade.js +261 -0
- package/dist/testing/grade.js.map +1 -0
- package/dist/testing/interpreter.d.ts +55 -0
- package/dist/testing/interpreter.js +103 -0
- package/dist/testing/interpreter.js.map +1 -0
- package/dist/testing/mock-middleware.d.ts +5 -0
- package/dist/testing/mock-middleware.js +33 -0
- package/dist/testing/mock-middleware.js.map +1 -0
- package/dist/testing/runner.d.ts +205 -0
- package/dist/testing/runner.js +266 -0
- package/dist/testing/runner.js.map +1 -0
- package/dist/testing/target.d.ts +27 -0
- package/dist/testing/target.js +21 -0
- package/dist/testing/target.js.map +1 -0
- package/dist/validate/validate.d.ts +41 -0
- package/dist/validate/validate.js +669 -0
- package/dist/validate/validate.js.map +1 -0
- package/dist/workflow/agent-tools.d.ts +10 -0
- package/dist/workflow/agent-tools.js +10 -0
- package/dist/workflow/agent-tools.js.map +1 -0
- package/dist/workflow/checkpointer.d.ts +52 -0
- package/dist/workflow/checkpointer.js +200 -0
- package/dist/workflow/checkpointer.js.map +1 -0
- package/dist/workflow/control-tools.d.ts +174 -0
- package/dist/workflow/control-tools.js +468 -0
- package/dist/workflow/control-tools.js.map +1 -0
- package/dist/workflow/governance.d.ts +104 -0
- package/dist/workflow/governance.js +546 -0
- package/dist/workflow/governance.js.map +1 -0
- package/dist/workflow/middleware.d.ts +85 -0
- package/dist/workflow/middleware.js +283 -0
- package/dist/workflow/middleware.js.map +1 -0
- package/dist/workflow/on-error.d.ts +25 -0
- package/dist/workflow/on-error.js +58 -0
- package/dist/workflow/on-error.js.map +1 -0
- package/dist/workflow/parks.d.ts +46 -0
- package/dist/workflow/parks.js +513 -0
- package/dist/workflow/parks.js.map +1 -0
- package/dist/workflow/paths.d.ts +67 -0
- package/dist/workflow/paths.js +108 -0
- package/dist/workflow/paths.js.map +1 -0
- package/dist/workflow/prompt-cache.d.ts +70 -0
- package/dist/workflow/prompt-cache.js +103 -0
- package/dist/workflow/prompt-cache.js.map +1 -0
- package/dist/workflow/prompt-pruning.d.ts +20 -0
- package/dist/workflow/prompt-pruning.js +83 -0
- package/dist/workflow/prompt-pruning.js.map +1 -0
- package/dist/workflow/render-prompt.d.ts +45 -0
- package/dist/workflow/render-prompt.js +140 -0
- package/dist/workflow/render-prompt.js.map +1 -0
- package/dist/workflow/runtime-config.d.ts +7 -0
- package/dist/workflow/runtime-config.js +9 -0
- package/dist/workflow/runtime-config.js.map +1 -0
- package/dist/workflow/session-artifacts.d.ts +90 -0
- package/dist/workflow/session-artifacts.js +134 -0
- package/dist/workflow/session-artifacts.js.map +1 -0
- package/dist/workflow/session-view.d.ts +31 -0
- package/dist/workflow/session-view.js +94 -0
- package/dist/workflow/session-view.js.map +1 -0
- package/dist/workflow/snapshot.d.ts +14 -0
- package/dist/workflow/snapshot.js +97 -0
- package/dist/workflow/snapshot.js.map +1 -0
- package/dist/workflow/state.d.ts +347 -0
- package/dist/workflow/state.js +322 -0
- package/dist/workflow/state.js.map +1 -0
- package/dist/workflow/sub-workflow.d.ts +174 -0
- package/dist/workflow/sub-workflow.js +392 -0
- package/dist/workflow/sub-workflow.js.map +1 -0
- package/dist/workflow/tool-service.d.ts +48 -0
- package/dist/workflow/tool-service.js +291 -0
- package/dist/workflow/tool-service.js.map +1 -0
- package/dist/workflow/turn-boundary.d.ts +39 -0
- package/dist/workflow/turn-boundary.js +128 -0
- package/dist/workflow/turn-boundary.js.map +1 -0
- package/dist/workflow/turn-runner.d.ts +40 -0
- package/dist/workflow/turn-runner.js +122 -0
- package/dist/workflow/turn-runner.js.map +1 -0
- package/dist/workflow/workflow-tools.d.ts +46 -0
- package/dist/workflow/workflow-tools.js +90 -0
- package/dist/workflow/workflow-tools.js.map +1 -0
- package/package.json +119 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { SESSION_INTERNAL_DIRS, SESSION_OFFLOAD_DIRS, SESSION_OPEN_DIR, SESSION_AGNOSTIC_PREFIX, } from "../core/zones.js";
|
|
2
|
+
/** Default workflow slug when none is supplied. */
|
|
3
|
+
export const DEFAULT_WORKFLOW = "order-lookup";
|
|
4
|
+
/**
|
|
5
|
+
* Where a workspace may override the platform system prompt. Nothing needs to be
|
|
6
|
+
* served there: the runtime ships the default prompt in its code.
|
|
7
|
+
*/
|
|
8
|
+
export const PLATFORM_PROMPT_PATH = ".platform/system/GRAPH_STATE.md";
|
|
9
|
+
export { PLATFORM_PROMPT_PATH as PLATFORM_BACKEND_PROMPT_PATH };
|
|
10
|
+
/** Workspace-relative paths for a named workflow (the read-only authored zone). */
|
|
11
|
+
export function workflowPaths(workflow) {
|
|
12
|
+
const base = `workflows/${workflow}`;
|
|
13
|
+
return {
|
|
14
|
+
platformPrompt: PLATFORM_PROMPT_PATH,
|
|
15
|
+
agentsPrompt: "AGENTS.md",
|
|
16
|
+
/** The machine spec: a pure YAML mapping. */
|
|
17
|
+
workflowYaml: `${base}/workflow.yaml`,
|
|
18
|
+
/** Optional prose addendum, appended after the spec-rendered prompt section. Never a machine source. */
|
|
19
|
+
workflow: `${base}/WORKFLOW.md`,
|
|
20
|
+
testsDir: `${base}/tests`,
|
|
21
|
+
/** Lifecycle hook scripts: the runtime's code, which the agent can neither read nor execute. */
|
|
22
|
+
hooksDir: `${base}/hooks`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Where a hook script must live, relative to its workflow directory. */
|
|
26
|
+
export const HOOKS_DIR = "hooks";
|
|
27
|
+
/**
|
|
28
|
+
* Resolve a hook's declared `script:` to an authoring-backend path. A hook path
|
|
29
|
+
* is workflow-relative and confined to the workflow's own `hooks/`; anything
|
|
30
|
+
* leaving it is refused with a reason. This keeps the two script classes
|
|
31
|
+
* disjoint: a hook can never be an `archmax_run` target.
|
|
32
|
+
*/
|
|
33
|
+
export function resolveHookScript(workflow, declared) {
|
|
34
|
+
const raw = declared.trim();
|
|
35
|
+
if (raw === "")
|
|
36
|
+
return { ok: false, reason: "hook script path is empty" };
|
|
37
|
+
if (raw.startsWith("/")) {
|
|
38
|
+
return {
|
|
39
|
+
ok: false,
|
|
40
|
+
reason: `hook script '${declared}' is an absolute path; a hook script path is relative to its ` +
|
|
41
|
+
`workflow directory (e.g. '${HOOKS_DIR}/check.js')`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const segments = [];
|
|
45
|
+
for (const segment of raw.split("/")) {
|
|
46
|
+
if (segment === "" || segment === ".")
|
|
47
|
+
continue;
|
|
48
|
+
// A `..` climb that leaves `hooks/` is caught by the prefix check below.
|
|
49
|
+
if (segment === "..")
|
|
50
|
+
segments.pop();
|
|
51
|
+
else
|
|
52
|
+
segments.push(segment);
|
|
53
|
+
}
|
|
54
|
+
const rel = segments.join("/");
|
|
55
|
+
if (rel !== HOOKS_DIR && !rel.startsWith(`${HOOKS_DIR}/`)) {
|
|
56
|
+
return {
|
|
57
|
+
ok: false,
|
|
58
|
+
reason: `hook script '${declared}' resolves outside '${HOOKS_DIR}/'; hook scripts live in ` +
|
|
59
|
+
`'workflows/${workflow}/${HOOKS_DIR}/' and are wired workflow-relative ` +
|
|
60
|
+
`(e.g. '${HOOKS_DIR}/check.js').`,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (rel === HOOKS_DIR) {
|
|
64
|
+
return { ok: false, reason: `hook script '${declared}' names the '${HOOKS_DIR}/' directory, not a file` };
|
|
65
|
+
}
|
|
66
|
+
return { ok: true, path: `workflows/${workflow}/${rel}` };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The runtime-internal layout of one session's folder. These paths carry the
|
|
70
|
+
* session id explicitly (`<sessionId>/…`) because internal writers run both
|
|
71
|
+
* inside and outside a bound turn; the agent addresses the same folders id-free.
|
|
72
|
+
*/
|
|
73
|
+
export function sessionPaths(sessionId) {
|
|
74
|
+
const base = sessionId;
|
|
75
|
+
return {
|
|
76
|
+
base,
|
|
77
|
+
/** Durable checkpoint and pending-write records, one immutable file each. */
|
|
78
|
+
checkpointsDir: `${base}/${SESSION_INTERNAL_DIRS[0]}`,
|
|
79
|
+
artifactsDir: `${base}/${SESSION_INTERNAL_DIRS[1]}`,
|
|
80
|
+
/** The run's working area (`scratchpad/…` to the agent). Durable; nothing cleans it up. */
|
|
81
|
+
scratchpadDir: `${base}/${SESSION_OPEN_DIR}`,
|
|
82
|
+
/** Deep Agents' context-offload areas: agent-readable, never agent-writable. */
|
|
83
|
+
largeToolResultsDir: `${base}/${SESSION_OFFLOAD_DIRS[0]}`,
|
|
84
|
+
conversationHistoryDir: `${base}/${SESSION_OFFLOAD_DIRS[1]}`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** Paths of a session's observability artifacts under `<sessionId>/artifacts/`. */
|
|
88
|
+
export function runArtifactPaths(sessionId) {
|
|
89
|
+
const runDir = sessionPaths(sessionId).artifactsDir;
|
|
90
|
+
return {
|
|
91
|
+
runDir,
|
|
92
|
+
graphJson: `${runDir}/graph.json`,
|
|
93
|
+
graphMermaid: `${runDir}/graph.mmd`,
|
|
94
|
+
trajectoryJson: `${runDir}/trajectory.json`,
|
|
95
|
+
metadataJson: `${runDir}/metadata.json`,
|
|
96
|
+
trailJson: `${runDir}/trail.json`,
|
|
97
|
+
variablesJson: `${runDir}/variables.json`,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Path of a content-addressed spec snapshot, keyed by `specHash`. Lives under
|
|
102
|
+
* the session-agnostic `_specs/` prefix so every session sharing a spec version
|
|
103
|
+
* shares one file; the run-zone router passes this prefix through unprefixed.
|
|
104
|
+
*/
|
|
105
|
+
export function specSnapshotPath(hash) {
|
|
106
|
+
return `${SESSION_AGNOSTIC_PREFIX}/${hash}.json`;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/workflow/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAE1B,mDAAmD;AACnD,MAAM,C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KAC7D,CAAC;AACJ,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,gBAAgB,CAAC,SAAiB;IAChD,MAAM,MAAM,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC;IACpD,OAAO;QACL,MAAM;QACN,SAAS,EAAE,GAAG,MAAM,aAAa;QACjC,YAAY,EAAE,GAAG,MAAM,YAAY;QACnC,cAAc,EAAE,GAAG,MAAM,kBAAkB;QAC3C,YAAY,EAAE,GAAG,MAAM,gBAAgB;QACvC,SAAS,EAAE,GAAG,MAAM,aAAa;QACjC,aAAa,EAAE,GAAG,MAAM,iBAAiB;KAC1C,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,GAAG,uBAAuB,IAAI,IAAI,OAAO,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider prompt caching for the stable prompt prefix (tool schemas and the
|
|
3
|
+
* static system prompt, re-sent on every model call of a turn).
|
|
4
|
+
*
|
|
5
|
+
* LangChain owns the provider mechanics where it has them: a native
|
|
6
|
+
* `ChatAnthropic` or `ChatBedrockConverse` gets LangChain's own caching
|
|
7
|
+
* middleware. The one case with no built-in is the default — Claude reached
|
|
8
|
+
* through an OpenAI-compatible endpoint — where the workflow middleware places
|
|
9
|
+
* an explicit `cache_control` breakpoint on the static system block. Anything
|
|
10
|
+
* else is a no-op (OpenAI and Gemini cache prefixes automatically).
|
|
11
|
+
*/
|
|
12
|
+
import { type AgentMiddleware } from "langchain";
|
|
13
|
+
export declare const CACHE_TTLS: readonly ["5m", "1h"];
|
|
14
|
+
export type CacheTtl = (typeof CACHE_TTLS)[number];
|
|
15
|
+
export declare const DEFAULT_CACHE_TTL: CacheTtl;
|
|
16
|
+
export declare function isCacheTtl(value: unknown): value is CacheTtl;
|
|
17
|
+
/**
|
|
18
|
+
* How caching is applied: `anthropic-native` / `bedrock-native` via LangChain's
|
|
19
|
+
* middlewares; `anthropic-compat` via an explicit marker on the static system
|
|
20
|
+
* block; `unsupported` when requested for a model with no known mechanism; `off`.
|
|
21
|
+
*/
|
|
22
|
+
export type PromptCacheStrategy = "anthropic-native" | "bedrock-native" | "anthropic-compat" | "off" | "unsupported";
|
|
23
|
+
/**
|
|
24
|
+
* The strategies LangChain implements as graph-level provider middleware. They
|
|
25
|
+
* cannot vary per model call, which is why a state whose model wants a different
|
|
26
|
+
* one is reported at assembly rather than silently mis-cached.
|
|
27
|
+
*/
|
|
28
|
+
export declare const NATIVE_CACHE_STRATEGIES: ReadonlySet<PromptCacheStrategy>;
|
|
29
|
+
export interface PromptCacheConfig {
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
ttl: CacheTtl;
|
|
32
|
+
}
|
|
33
|
+
export interface PromptCacheOptions {
|
|
34
|
+
enabled?: boolean;
|
|
35
|
+
ttl?: string;
|
|
36
|
+
}
|
|
37
|
+
/** A `cache_control` marker as Anthropic and its gateways accept it. */
|
|
38
|
+
export interface CacheControlMarker {
|
|
39
|
+
type: "ephemeral";
|
|
40
|
+
ttl: CacheTtl;
|
|
41
|
+
}
|
|
42
|
+
export declare function cacheControl(ttl: CacheTtl): CacheControlMarker;
|
|
43
|
+
/** The provider's model id, however the client exposes it. */
|
|
44
|
+
export declare function modelIdOf(model: unknown): string;
|
|
45
|
+
/**
|
|
46
|
+
* Pick the mechanism for `model`, with the same client/provider tests LangChain's
|
|
47
|
+
* middlewares apply, so a `*-native` strategy is exactly one that middleware acts on.
|
|
48
|
+
*/
|
|
49
|
+
export declare function resolveCacheStrategy(model: unknown, enabled: boolean): PromptCacheStrategy;
|
|
50
|
+
/**
|
|
51
|
+
* The LangChain provider middleware for `strategy`, or `null` when none is
|
|
52
|
+
* needed. `minMessagesToCache: 1` because the prefix is large from the first
|
|
53
|
+
* call; `unsupportedModelBehavior: "ignore"` because the strategy was already
|
|
54
|
+
* reported through `onEvent`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function createProviderCacheMiddleware(strategy: PromptCacheStrategy, ttl: CacheTtl): AgentMiddleware | null;
|
|
57
|
+
/** The assembly-time diagnostic for an unsupported model. */
|
|
58
|
+
export declare function unsupportedCacheMessage(model: unknown): string;
|
|
59
|
+
/** Precedence host option → workflow spec → env → default (on, 5m). A bad `ttl` falls back rather than failing a run. */
|
|
60
|
+
export declare function resolvePromptCacheConfig(sources: {
|
|
61
|
+
option?: PromptCacheOptions | undefined;
|
|
62
|
+
spec?: {
|
|
63
|
+
enabled?: boolean;
|
|
64
|
+
ttl?: string;
|
|
65
|
+
} | undefined;
|
|
66
|
+
env?: {
|
|
67
|
+
enabled?: boolean;
|
|
68
|
+
ttl?: string;
|
|
69
|
+
} | undefined;
|
|
70
|
+
}): PromptCacheConfig;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider prompt caching for the stable prompt prefix (tool schemas and the
|
|
3
|
+
* static system prompt, re-sent on every model call of a turn).
|
|
4
|
+
*
|
|
5
|
+
* LangChain owns the provider mechanics where it has them: a native
|
|
6
|
+
* `ChatAnthropic` or `ChatBedrockConverse` gets LangChain's own caching
|
|
7
|
+
* middleware. The one case with no built-in is the default — Claude reached
|
|
8
|
+
* through an OpenAI-compatible endpoint — where the workflow middleware places
|
|
9
|
+
* an explicit `cache_control` breakpoint on the static system block. Anything
|
|
10
|
+
* else is a no-op (OpenAI and Gemini cache prefixes automatically).
|
|
11
|
+
*/
|
|
12
|
+
import { anthropicPromptCachingMiddleware, bedrockPromptCachingMiddleware, } from "langchain";
|
|
13
|
+
export const CACHE_TTLS = ["5m", "1h"];
|
|
14
|
+
export const DEFAULT_CACHE_TTL = "5m";
|
|
15
|
+
export function isCacheTtl(value) {
|
|
16
|
+
return typeof value === "string" && CACHE_TTLS.includes(value);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The strategies LangChain implements as graph-level provider middleware. They
|
|
20
|
+
* cannot vary per model call, which is why a state whose model wants a different
|
|
21
|
+
* one is reported at assembly rather than silently mis-cached.
|
|
22
|
+
*/
|
|
23
|
+
export const NATIVE_CACHE_STRATEGIES = new Set([
|
|
24
|
+
"anthropic-native",
|
|
25
|
+
"bedrock-native",
|
|
26
|
+
]);
|
|
27
|
+
export function cacheControl(ttl) {
|
|
28
|
+
return { type: "ephemeral", ttl };
|
|
29
|
+
}
|
|
30
|
+
function modelName(model) {
|
|
31
|
+
const named = model;
|
|
32
|
+
try {
|
|
33
|
+
return typeof named?.getName === "function" ? named.getName() : "";
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** The provider's model id, however the client exposes it. */
|
|
40
|
+
export function modelIdOf(model) {
|
|
41
|
+
const candidate = model;
|
|
42
|
+
for (const value of [candidate?.model, candidate?.modelName, candidate?._defaultConfig?.model]) {
|
|
43
|
+
if (typeof value === "string" && value.trim())
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
return "";
|
|
47
|
+
}
|
|
48
|
+
const ANTHROPIC_MODEL_ID = /claude|anthropic/i;
|
|
49
|
+
/** Bedrock caches only these model families (mirrors LangChain's own check). */
|
|
50
|
+
const BEDROCK_CACHEABLE_ID = /anthropic\.claude|amazon\.nova/i;
|
|
51
|
+
/**
|
|
52
|
+
* Pick the mechanism for `model`, with the same client/provider tests LangChain's
|
|
53
|
+
* middlewares apply, so a `*-native` strategy is exactly one that middleware acts on.
|
|
54
|
+
*/
|
|
55
|
+
export function resolveCacheStrategy(model, enabled) {
|
|
56
|
+
if (!enabled || !model)
|
|
57
|
+
return "off";
|
|
58
|
+
const name = modelName(model);
|
|
59
|
+
const provider = model?._defaultConfig
|
|
60
|
+
?.modelProvider;
|
|
61
|
+
const id = modelIdOf(model);
|
|
62
|
+
if (name === "ChatAnthropic" || (name === "ConfigurableModel" && provider === "anthropic")) {
|
|
63
|
+
return "anthropic-native";
|
|
64
|
+
}
|
|
65
|
+
const isBedrock = name === "ChatBedrockConverse" ||
|
|
66
|
+
(name === "ConfigurableModel" && (provider === "bedrock" || provider === "aws"));
|
|
67
|
+
if (isBedrock)
|
|
68
|
+
return BEDROCK_CACHEABLE_ID.test(id) ? "bedrock-native" : "unsupported";
|
|
69
|
+
if (ANTHROPIC_MODEL_ID.test(id) || ANTHROPIC_MODEL_ID.test(name))
|
|
70
|
+
return "anthropic-compat";
|
|
71
|
+
return "unsupported";
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The LangChain provider middleware for `strategy`, or `null` when none is
|
|
75
|
+
* needed. `minMessagesToCache: 1` because the prefix is large from the first
|
|
76
|
+
* call; `unsupportedModelBehavior: "ignore"` because the strategy was already
|
|
77
|
+
* reported through `onEvent`.
|
|
78
|
+
*/
|
|
79
|
+
export function createProviderCacheMiddleware(strategy, ttl) {
|
|
80
|
+
const options = { ttl, minMessagesToCache: 1, unsupportedModelBehavior: "ignore" };
|
|
81
|
+
if (strategy === "anthropic-native") {
|
|
82
|
+
return anthropicPromptCachingMiddleware(options);
|
|
83
|
+
}
|
|
84
|
+
if (strategy === "bedrock-native") {
|
|
85
|
+
return bedrockPromptCachingMiddleware(options);
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
/** The assembly-time diagnostic for an unsupported model. */
|
|
90
|
+
export function unsupportedCacheMessage(model) {
|
|
91
|
+
const id = modelIdOf(model) || modelName(model) || "the configured model";
|
|
92
|
+
return (`prompt caching is inactive for '${id}': no cache-breakpoint mechanism is known for it ` +
|
|
93
|
+
`(supported: Anthropic natively or over an OpenAI-compatible endpoint, and Bedrock Converse ` +
|
|
94
|
+
`Claude/Nova). Providers with automatic prefix caching still benefit from the stable prefix.`);
|
|
95
|
+
}
|
|
96
|
+
/** Precedence host option → workflow spec → env → default (on, 5m). A bad `ttl` falls back rather than failing a run. */
|
|
97
|
+
export function resolvePromptCacheConfig(sources) {
|
|
98
|
+
const { option, spec, env } = sources;
|
|
99
|
+
const enabled = option?.enabled ?? spec?.enabled ?? env?.enabled ?? true;
|
|
100
|
+
const ttlCandidate = option?.ttl ?? spec?.ttl ?? env?.ttl;
|
|
101
|
+
return { enabled, ttl: isCacheTtl(ttlCandidate) ? ttlCandidate : DEFAULT_CACHE_TTL };
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=prompt-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-cache.js","sourceRoot":"","sources":["../../src/workflow/prompt-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,gCAAgC,EAChC,8BAA8B,GAE/B,MAAM,WAAW,CAAC;AAEnB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,IAAI,CAAU,CAAC;AAGhD,MAAM,CAAC,MAAM,iBAAiB,GAAa,IAAI,CAAC;AAEhD,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAK,UAAgC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxF,CAAC;AAcD;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAqC,IAAI,GAAG,CAAC;IAC/E,kBAAkB;IAClB,gBAAgB;CACjB,CAAC,CAAC;AAkBH,MAAM,UAAU,YAAY,CAAC,GAAa;IACxC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC;AACpC,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,MAAM,KAAK,GAAG,KAAmC,CAAC;IAClD,IAAI,CAAC;QACH,OAAO,OAAO,KAAK,EAAE,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACrE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,8DAA8D;AAC9D,MAAM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@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pruning of upstream Deep Agents prompt guidance for built-in tools an
|
|
3
|
+
* assembly withholds: guidance for a tool the model cannot call only teaches it
|
|
4
|
+
* to try.
|
|
5
|
+
*/
|
|
6
|
+
/** The upstream headings that document `tool`'s guidance (empty when unknown). */
|
|
7
|
+
export declare function upstreamSectionsFor(tool: string): readonly string[];
|
|
8
|
+
export interface PruneResult {
|
|
9
|
+
/** The prompt text with matched sections removed. */
|
|
10
|
+
text: string;
|
|
11
|
+
/** Headings that were found and removed. */
|
|
12
|
+
removed: string[];
|
|
13
|
+
/**
|
|
14
|
+
* Tools whose guidance was found nowhere. A partial match is a successful
|
|
15
|
+
* prune (upstream may carry only some of a tool's sections).
|
|
16
|
+
*/
|
|
17
|
+
missingTools?: string[];
|
|
18
|
+
}
|
|
19
|
+
/** Prune the upstream guidance for every tool in `undisclosed`; tools with no known sections are ignored. */
|
|
20
|
+
export declare function pruneUndisclosedToolSections(text: string, undisclosed: readonly string[]): PruneResult;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pruning of upstream Deep Agents prompt guidance for built-in tools an
|
|
3
|
+
* assembly withholds: guidance for a tool the model cannot call only teaches it
|
|
4
|
+
* to try.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Upstream section headings owned by a built-in tool's guidance.
|
|
8
|
+
*
|
|
9
|
+
* `task`'s guidance is two sections, and both must be named: the spawner
|
|
10
|
+
* overview carries the bulk of it, and the notes section follows. A partial
|
|
11
|
+
* match counts as a successful prune, so listing only one of them silently ships
|
|
12
|
+
* the other.
|
|
13
|
+
*/
|
|
14
|
+
const SECTIONS_BY_TOOL = {
|
|
15
|
+
task: ["## `task` (subagent spawner)", "## Important Task Tool Usage Notes to Remember"],
|
|
16
|
+
};
|
|
17
|
+
/** The upstream headings that document `tool`'s guidance (empty when unknown). */
|
|
18
|
+
export function upstreamSectionsFor(tool) {
|
|
19
|
+
return SECTIONS_BY_TOOL[tool] ?? [];
|
|
20
|
+
}
|
|
21
|
+
/** A section spans its heading line to the next heading of the same or higher level. */
|
|
22
|
+
function sectionEnd(lines, start, level) {
|
|
23
|
+
for (let i = start + 1; i < lines.length; i++) {
|
|
24
|
+
const match = /^(#{1,6})\s/.exec(lines[i]);
|
|
25
|
+
if (match && match[1].length <= level)
|
|
26
|
+
return i;
|
|
27
|
+
}
|
|
28
|
+
return lines.length;
|
|
29
|
+
}
|
|
30
|
+
function headingLevel(heading) {
|
|
31
|
+
return /^(#{1,6})\s/.exec(heading)?.[1].length ?? 2;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Put a target heading on its own line when composition glued it to the end of
|
|
35
|
+
* the previous one.
|
|
36
|
+
*
|
|
37
|
+
* Upstream concatenates its prompt fragments without a separating newline, so a
|
|
38
|
+
* section can arrive as `…within files## \`task\` (subagent spawner)`. Matching is
|
|
39
|
+
* line-anchored (a `##` mid-sentence is prose, not a heading), so without this
|
|
40
|
+
* the section is silently kept and billed on every call. Narrow by construction:
|
|
41
|
+
* only a heading we were asked to remove is ever split out.
|
|
42
|
+
*/
|
|
43
|
+
function unglueHeadings(text, headings) {
|
|
44
|
+
let out = text;
|
|
45
|
+
for (const heading of headings) {
|
|
46
|
+
let at = out.indexOf(heading);
|
|
47
|
+
while (at > 0) {
|
|
48
|
+
if (out[at - 1] !== "\n") {
|
|
49
|
+
out = `${out.slice(0, at)}\n${out.slice(at)}`;
|
|
50
|
+
at += 1;
|
|
51
|
+
}
|
|
52
|
+
at = out.indexOf(heading, at + heading.length);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
/** Remove each heading's section. Matching is exact on the trimmed heading line. */
|
|
58
|
+
function pruneSections(text, headings) {
|
|
59
|
+
if (!text || headings.length === 0)
|
|
60
|
+
return { text, removed: [] };
|
|
61
|
+
const removed = [];
|
|
62
|
+
let lines = unglueHeadings(text, headings).split("\n");
|
|
63
|
+
for (const heading of headings) {
|
|
64
|
+
const index = lines.findIndex((line) => line.trim() === heading);
|
|
65
|
+
if (index === -1)
|
|
66
|
+
continue;
|
|
67
|
+
const end = sectionEnd(lines, index, headingLevel(heading));
|
|
68
|
+
lines = [...lines.slice(0, index), ...lines.slice(end)];
|
|
69
|
+
removed.push(heading);
|
|
70
|
+
}
|
|
71
|
+
// Collapse the blank runs left behind so the result is byte-stable however many sections were cut.
|
|
72
|
+
return { text: lines.join("\n").replace(/\n{3,}/g, "\n\n").trim(), removed };
|
|
73
|
+
}
|
|
74
|
+
/** Prune the upstream guidance for every tool in `undisclosed`; tools with no known sections are ignored. */
|
|
75
|
+
export function pruneUndisclosedToolSections(text, undisclosed) {
|
|
76
|
+
const result = pruneSections(text, undisclosed.flatMap((tool) => [...upstreamSectionsFor(tool)]));
|
|
77
|
+
const missingTools = undisclosed.filter((tool) => {
|
|
78
|
+
const owned = upstreamSectionsFor(tool);
|
|
79
|
+
return owned.length > 0 && !owned.some((heading) => result.removed.includes(heading));
|
|
80
|
+
});
|
|
81
|
+
return { ...result, ...(missingTools.length > 0 ? { missingTools } : {}) };
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=prompt-pruning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-pruning.js","sourceRoot":"","sources":["../../src/workflow/prompt-pruning.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,MAAM,gBAAgB,GAAsC;IAC1D,IAAI,EAAE,CAAC,8BAA8B,EAAE,gDAAgD,CAAC;CACzF,CAAC;AAEF,kFAAkF;AAClF,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;AACtC,CAAC;AAcD,wFAAwF;AACxF,SAAS,UAAU,CAAC,KAAe,EAAE,KAAa,EAAE,KAAa;IAC/D,KAAK,IAAI,CAA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K,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic rendering of the two spec-derived prompt sections, both pure
|
|
3
|
+
* functions of the machine, so what the agent reads cannot drift from what the
|
|
4
|
+
* runtime enforces.
|
|
5
|
+
*
|
|
6
|
+
* The graph is disclosed the way the tool surface is — only from where the agent
|
|
7
|
+
* stands — which puts the two halves on opposite sides of the cache boundary:
|
|
8
|
+
*
|
|
9
|
+
* - {@link renderWorkflowPrompt} is the **cacheable** half: the workflow's
|
|
10
|
+
* `title` and root `instructions`, and no state of the graph. It is a
|
|
11
|
+
* function of the header alone, so the prefix does not grow with the state
|
|
12
|
+
* count. Authored `WORKFLOW.md` prose is appended after it by the caller.
|
|
13
|
+
* - {@link renderStateGraph} is the **volatile** half, re-rendered per model
|
|
14
|
+
* call for the state in force: its outgoing edges, its own markers and hooks,
|
|
15
|
+
* and the run's trigger signature.
|
|
16
|
+
*
|
|
17
|
+
* No other state's slug, `title`, `summary`, hooks, budget or transitions is
|
|
18
|
+
* rendered anywhere, and neither is a count of the states: a state the agent
|
|
19
|
+
* cannot advance to is a state it cannot name. A state's `instructions` body is
|
|
20
|
+
* surfaced only for the active state, by the caller.
|
|
21
|
+
*/
|
|
22
|
+
import type { WorkflowMachine } from "../machine/machine.js";
|
|
23
|
+
/** What {@link renderStateGraph} needs about the run, beyond the state it is in. */
|
|
24
|
+
export interface StateGraphContext {
|
|
25
|
+
/** The id of the trigger this session was started by, when one is recorded. */
|
|
26
|
+
trigger?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The active state's half of the graph: its hooks, the run's trigger signature,
|
|
30
|
+
* and either its outgoing edges or the statement that it has none.
|
|
31
|
+
*
|
|
32
|
+
* Terminality is stated rather than left to be inferred from an absent list —
|
|
33
|
+
* the old whole-graph section taught "a state listed with no transitions is
|
|
34
|
+
* terminal", and with the listing gone there is nothing to read that from.
|
|
35
|
+
* Returns `null` when the state discloses nothing at all.
|
|
36
|
+
*/
|
|
37
|
+
export declare function renderStateGraph(machine: WorkflowMachine, state: string, ctx?: StateGraphContext): string | null;
|
|
38
|
+
/**
|
|
39
|
+
* The cacheable half: the workflow's `title` and its root `instructions`. No
|
|
40
|
+
* state is named — see the module docstring for why, and
|
|
41
|
+
* {@link renderStateGraph} for what the agent is told instead.
|
|
42
|
+
*/
|
|
43
|
+
export declare function renderWorkflowPrompt(machine: WorkflowMachine): string;
|
|
44
|
+
/** Strip HTML comments from authored prose; the model would be charged for them on every call. */
|
|
45
|
+
export declare function stripHtmlComments(text: string): string;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic rendering of the two spec-derived prompt sections, both pure
|
|
3
|
+
* functions of the machine, so what the agent reads cannot drift from what the
|
|
4
|
+
* runtime enforces.
|
|
5
|
+
*
|
|
6
|
+
* The graph is disclosed the way the tool surface is — only from where the agent
|
|
7
|
+
* stands — which puts the two halves on opposite sides of the cache boundary:
|
|
8
|
+
*
|
|
9
|
+
* - {@link renderWorkflowPrompt} is the **cacheable** half: the workflow's
|
|
10
|
+
* `title` and root `instructions`, and no state of the graph. It is a
|
|
11
|
+
* function of the header alone, so the prefix does not grow with the state
|
|
12
|
+
* count. Authored `WORKFLOW.md` prose is appended after it by the caller.
|
|
13
|
+
* - {@link renderStateGraph} is the **volatile** half, re-rendered per model
|
|
14
|
+
* call for the state in force: its outgoing edges, its own markers and hooks,
|
|
15
|
+
* and the run's trigger signature.
|
|
16
|
+
*
|
|
17
|
+
* No other state's slug, `title`, `summary`, hooks, budget or transitions is
|
|
18
|
+
* rendered anywhere, and neither is a count of the states: a state the agent
|
|
19
|
+
* cannot advance to is a state it cannot name. A state's `instructions` body is
|
|
20
|
+
* surfaced only for the active state, by the caller.
|
|
21
|
+
*/
|
|
22
|
+
import { afterHookLabel, hookKind, normalizeHooks } from "../lifecycle/hook-shape.js";
|
|
23
|
+
import { ADVANCE_TOOL, SET_VARIABLES_TOOL } from "../machine/tool-names.js";
|
|
24
|
+
/**
|
|
25
|
+
* One outgoing edge: the target's slug (the exact token `archmax_advance` takes),
|
|
26
|
+
* its declared `type`, and the required `description` the agent routes on.
|
|
27
|
+
*
|
|
28
|
+
* The two markers a target may carry are disclosed because each changes what the
|
|
29
|
+
* call must carry or what follows it — `evidence` is accepted only when the
|
|
30
|
+
* target is a human state, and both markers mean *stop* rather than *continue*.
|
|
31
|
+
* They disclose the **consequence of taking the edge**, not the state on the
|
|
32
|
+
* other side of it: nothing of the target's own title, summary, instructions,
|
|
33
|
+
* hooks or transitions is rendered.
|
|
34
|
+
*/
|
|
35
|
+
function renderTransition(machine, edge) {
|
|
36
|
+
const notes = [];
|
|
37
|
+
if (edge.type && edge.type !== "none")
|
|
38
|
+
notes.push(edge.type);
|
|
39
|
+
if (machine.isHumanState(edge.to))
|
|
40
|
+
notes.push("human decision node");
|
|
41
|
+
if (machine.isTerminal(edge.to))
|
|
42
|
+
notes.push("terminal");
|
|
43
|
+
const suffix = notes.length ? ` (${notes.join(", ")})` : "";
|
|
44
|
+
return `- to \`${edge.to}\`${suffix} — ${edge.description.trim()}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The active state's hooks, by phase. A **rubric** hook renders as its bare kind
|
|
48
|
+
* — never the rubric's name, and never any of its declaration.
|
|
49
|
+
*
|
|
50
|
+
* Presence is disclosed because it is actionable: a graded exit can come back
|
|
51
|
+
* with a correction the agent must act on. Identity is withheld because it is
|
|
52
|
+
* not: no disclosed tool takes a rubric name, and the name is a handle into
|
|
53
|
+
* content the agent may not read. Nothing here can reach the criteria, the
|
|
54
|
+
* budget or the model — they live in a block this renderer never reads.
|
|
55
|
+
*/
|
|
56
|
+
function renderHooks(state) {
|
|
57
|
+
const parts = [];
|
|
58
|
+
for (const phase of ["before", "after"]) {
|
|
59
|
+
const hooks = normalizeHooks(state[phase]);
|
|
60
|
+
if (hooks.length === 0)
|
|
61
|
+
continue;
|
|
62
|
+
const labels = hooks.map((hook, index) => hookKind(hook) === "rubric" ? "rubric" : afterHookLabel(hook, index));
|
|
63
|
+
parts.push(`${phase}: ${labels.join(", ")}`);
|
|
64
|
+
}
|
|
65
|
+
return parts.length ? parts.join("; ") : null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The signature of the trigger this run was started by — and only that one. The
|
|
69
|
+
* triggers of states this run did not enter are not disclosed, and the id needs
|
|
70
|
+
* no label: there is one trigger and it is this run's.
|
|
71
|
+
*/
|
|
72
|
+
function renderSignature(machine, trigger) {
|
|
73
|
+
if (!trigger)
|
|
74
|
+
return [];
|
|
75
|
+
const lines = [];
|
|
76
|
+
const requires = machine.requiresForTrigger(trigger) ?? [];
|
|
77
|
+
const returns = machine.returnsForTrigger(trigger) ?? [];
|
|
78
|
+
if (requires.length > 0) {
|
|
79
|
+
lines.push(`This run was started with: ${requires.join(", ")}.`);
|
|
80
|
+
}
|
|
81
|
+
if (returns.length > 0) {
|
|
82
|
+
lines.push(`This run must set ${returns.join(", ")} with \`${SET_VARIABLES_TOOL}\` — it does not ` +
|
|
83
|
+
`complete until every one is set.`);
|
|
84
|
+
}
|
|
85
|
+
return lines;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The active state's half of the graph: its hooks, the run's trigger signature,
|
|
89
|
+
* and either its outgoing edges or the statement that it has none.
|
|
90
|
+
*
|
|
91
|
+
* Terminality is stated rather than left to be inferred from an absent list —
|
|
92
|
+
* the old whole-graph section taught "a state listed with no transitions is
|
|
93
|
+
* terminal", and with the listing gone there is nothing to read that from.
|
|
94
|
+
* Returns `null` when the state discloses nothing at all.
|
|
95
|
+
*/
|
|
96
|
+
export function renderStateGraph(machine, state, ctx = {}) {
|
|
97
|
+
const declared = machine.spec.states[state];
|
|
98
|
+
if (!declared)
|
|
99
|
+
return null;
|
|
100
|
+
const sections = [];
|
|
101
|
+
const hooks = renderHooks(declared);
|
|
102
|
+
if (hooks)
|
|
103
|
+
sections.push(`Hooks: ${hooks}`);
|
|
104
|
+
sections.push(...renderSignature(machine, ctx.trigger));
|
|
105
|
+
const transitions = declared.transitions ?? [];
|
|
106
|
+
sections.push(transitions.length > 0
|
|
107
|
+
? [
|
|
108
|
+
`Transitions — choose one with \`${ADVANCE_TOOL}\` when this state's work is done:`,
|
|
109
|
+
...transitions.map((edge) => renderTransition(machine, edge)),
|
|
110
|
+
].join("\n")
|
|
111
|
+
: `This state is terminal: no transition leads out of it. Finish its work and stop.`);
|
|
112
|
+
return sections.length > 0 ? sections.join("\n\n") : null;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The cacheable half: the workflow's `title` and its root `instructions`. No
|
|
116
|
+
* state is named — see the module docstring for why, and
|
|
117
|
+
* {@link renderStateGraph} for what the agent is told instead.
|
|
118
|
+
*/
|
|
119
|
+
export function renderWorkflowPrompt(machine) {
|
|
120
|
+
const { spec } = machine;
|
|
121
|
+
const lines = [];
|
|
122
|
+
const title = spec.title?.trim();
|
|
123
|
+
lines.push(`# Workflow${title ? `: ${title}` : ""}`);
|
|
124
|
+
// Standing instructions apply to every turn, so they belong in the static, cacheable prefix.
|
|
125
|
+
if (spec.instructions?.trim()) {
|
|
126
|
+
lines.push("", "## Instructions", "", spec.instructions.trim());
|
|
127
|
+
}
|
|
128
|
+
return lines.join("\n");
|
|
129
|
+
}
|
|
130
|
+
/** Strip HTML comments from authored prose; the model would be charged for them on every call. */
|
|
131
|
+
export function stripHtmlComments(text) {
|
|
132
|
+
if (!text.includes("<!--"))
|
|
133
|
+
return text;
|
|
134
|
+
return text
|
|
135
|
+
.replace(/<!--[\s\S]*?-->/g, "")
|
|
136
|
+
.replace(/[ \t]+$/gm, "")
|
|
137
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
138
|
+
.trim();
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=render-prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-prompt.js","sourceRoot":"","sources":["../../src/workflow/render-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEtF,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG5E;;;;;;;;;;GAUG;AACH,SAAS,gBAAgB,CAAC,OAAwB,EAAE,IAAuB;IACzE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7D,IAAI,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACrE,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACxD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5D,OAAO,UAAU,IAAI,CAAC,EAAE,KAAK,MAAM,M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AC,IAAI,CAAC;AAC5D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAwB;IAC3D,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IACzB,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC;IACjC,KAAK,CAAC,IAAI,CAAC,aAAa,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACrD,6FAA6F;IAC7F,IAAI,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE,EAAE,CAAC;QAC9B,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IACxC,OAAO,IAAI;SACR,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;SAC/B,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;SACxB,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC;SAC1B,IAAI,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RunnableConfig } from "@langchain/core/runnables";
|
|
2
|
+
/** The runnable config a hook's or request's runtime stands for. */
|
|
3
|
+
export declare function buildRunnableConfig(runtime: {
|
|
4
|
+
configurable?: Record<string, unknown>;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
store?: unknown;
|
|
7
|
+
}): RunnableConfig;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The runnable config a hook's or request's runtime stands for. */
|
|
2
|
+
export function buildRunnableConfig(runtime) {
|
|
3
|
+
return {
|
|
4
|
+
configurable: runtime?.configurable ?? {},
|
|
5
|
+
signal: runtime?.signal,
|
|
6
|
+
...(runtime?.store !== undefined ? { store: runtime.store } : {}),
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=runtime-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-config.js","sourceRoot":"","sources":["../../src/workflow/runtime-config.ts"],"names":[],"mappings":"AAEA,oEAAoE;AACpE,MAAM,UAAU,mBAAmB,CAAC,OAInC;IACC,OAAO;QACL,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,EAAE;QACzC,MAAM,EAAE,OAAO,EAAE,MAAM;QACvB,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAClE,CAAC;AACJ,CAAC"}
|