@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
package/dist/env.js
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { ChatOpenAI, ChatOpenAICompletions } from "@langchain/openai";
|
|
5
|
+
import dotenv from "dotenv";
|
|
6
|
+
import { DEFAULT_PRICING_KEY } from "./core/usage.js";
|
|
7
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
/**
|
|
9
|
+
* Package install root — the directory containing this file's parent (`dist/`
|
|
10
|
+
* when published/built, `src/` in development). Used only to locate assets
|
|
11
|
+
* bundled with the package, never the consumer's workspace or configuration.
|
|
12
|
+
*/
|
|
13
|
+
export const PACKAGE_ROOT = resolve(here, "..");
|
|
14
|
+
/** Installed package implementation version, read from the package's `package.json`. */
|
|
15
|
+
export const PACKAGE_VERSION = (() => {
|
|
16
|
+
try {
|
|
17
|
+
const pkg = JSON.parse(readFileSync(resolve(PACKAGE_ROOT, "package.json"), "utf8"));
|
|
18
|
+
return typeof pkg.version === "string" ? pkg.version : "0.0.0";
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return "0.0.0";
|
|
22
|
+
}
|
|
23
|
+
})();
|
|
24
|
+
/** Return the first existing directory among the candidates, else the first. */
|
|
25
|
+
function firstExistingDir(candidates) {
|
|
26
|
+
for (const candidate of candidates) {
|
|
27
|
+
if (existsSync(candidate))
|
|
28
|
+
return candidate;
|
|
29
|
+
}
|
|
30
|
+
return candidates[0];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The authoring skill bundled with the package — the parent directory holding
|
|
34
|
+
* `archmax-harness/` (`SKILL.md` + `references/*.md`), which teaches a coding agent how
|
|
35
|
+
* to author a workspace. Resolved to `dist/authoring-skill` when built or
|
|
36
|
+
* installed, with a repo-checkout fallback to the top-level `skills/` when
|
|
37
|
+
* running from `src/`. Consumers mount it directly so the skill always matches
|
|
38
|
+
* the installed SDK version instead of a synced copy.
|
|
39
|
+
*/
|
|
40
|
+
export const BUNDLED_AUTHORING_SKILL_DIR = firstExistingDir([
|
|
41
|
+
resolve(here, "authoring-skill"),
|
|
42
|
+
resolve(here, "..", "skills"),
|
|
43
|
+
]);
|
|
44
|
+
/** @deprecated Use {@link BUNDLED_AUTHORING_SKILL_DIR}; same value, kept for one release. */
|
|
45
|
+
export const BUNDLED_SKILLS_DIR = BUNDLED_AUTHORING_SKILL_DIR;
|
|
46
|
+
/** Resolve the agent workspace root: an explicit path, else the consumer's cwd. */
|
|
47
|
+
export function resolveWorkspaceRoot(rootDir) {
|
|
48
|
+
return rootDir ? resolve(rootDir) : process.cwd();
|
|
49
|
+
}
|
|
50
|
+
let lastEnvFileLoaded = null;
|
|
51
|
+
/**
|
|
52
|
+
* Variables whose current value came from a `.env` file rather than from the
|
|
53
|
+
* real process environment. Only these may be replaced by a later `.env`.
|
|
54
|
+
*/
|
|
55
|
+
const fromEnvFile = new Set();
|
|
56
|
+
/**
|
|
57
|
+
* Load `.env` from the resolved workspace root (or cwd) if present.
|
|
58
|
+
*
|
|
59
|
+
* Two rules, in this order: the real process environment always wins, and a
|
|
60
|
+
* later `.env` wins over an earlier one. The second is why this does not just
|
|
61
|
+
* call `dotenv.config` — dotenv never overrides an already-set variable, and it
|
|
62
|
+
* cannot tell its own earlier assignment from a real environment variable. The
|
|
63
|
+
* import-time cwd load below is an earlier one, so without the distinction a
|
|
64
|
+
* stray `.env` in whatever directory the process happened to start in would
|
|
65
|
+
* silently outrank the workspace root that owns the configuration (issue #23).
|
|
66
|
+
*/
|
|
67
|
+
export function loadDotenv(rootDir) {
|
|
68
|
+
const envFile = resolve(resolveWorkspaceRoot(rootDir), ".env");
|
|
69
|
+
if (envFile === lastEnvFileLoaded)
|
|
70
|
+
return;
|
|
71
|
+
if (!existsSync(envFile))
|
|
72
|
+
return;
|
|
73
|
+
// Parsed rather than applied by dotenv, so assignment follows the rules above.
|
|
74
|
+
// Parsing also emits nothing on stdout, which the CLI reserves for its answer.
|
|
75
|
+
let parsed;
|
|
76
|
+
try {
|
|
77
|
+
parsed = dotenv.parse(readFileSync(envFile));
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
for (const [name, value] of Object.entries(parsed)) {
|
|
83
|
+
if (process.env[name] !== undefined && !fromEnvFile.has(name))
|
|
84
|
+
continue;
|
|
85
|
+
process.env[name] = value;
|
|
86
|
+
fromEnvFile.add(name);
|
|
87
|
+
}
|
|
88
|
+
lastEnvFileLoaded = envFile;
|
|
89
|
+
}
|
|
90
|
+
// Eagerly load `.env` from the consumer's working directory for the common case.
|
|
91
|
+
// A workspace-root load later in startup overrides whatever this set.
|
|
92
|
+
loadDotenv();
|
|
93
|
+
/** Resolve a config key from its canonical `ARCHMAX_*` environment name. */
|
|
94
|
+
function envValue(suffix) {
|
|
95
|
+
const name = `ARCHMAX_${suffix}`;
|
|
96
|
+
return { name, raw: process.env[name] };
|
|
97
|
+
}
|
|
98
|
+
function required(suffix) {
|
|
99
|
+
const { name, raw } = envValue(suffix);
|
|
100
|
+
if (!raw || raw.trim() === "") {
|
|
101
|
+
throw new Error(`Missing required environment variable: ${name}. Copy .env.example to .env and fill it in.`);
|
|
102
|
+
}
|
|
103
|
+
return raw.trim();
|
|
104
|
+
}
|
|
105
|
+
function optionalNumber(suffix) {
|
|
106
|
+
const { name, raw } = envValue(suffix);
|
|
107
|
+
if (raw === undefined || raw.trim() === "")
|
|
108
|
+
return undefined;
|
|
109
|
+
const parsed = Number(raw);
|
|
110
|
+
if (Number.isNaN(parsed)) {
|
|
111
|
+
throw new Error(`Environment variable ${name} must be a number, got: ${raw}`);
|
|
112
|
+
}
|
|
113
|
+
return parsed;
|
|
114
|
+
}
|
|
115
|
+
function optionalBoolean(suffix) {
|
|
116
|
+
const { name, raw } = envValue(suffix);
|
|
117
|
+
if (raw === undefined || raw.trim() === "")
|
|
118
|
+
return undefined;
|
|
119
|
+
const normalized = raw.trim().toLowerCase();
|
|
120
|
+
if (["1", "true", "yes", "on"].includes(normalized))
|
|
121
|
+
return true;
|
|
122
|
+
if (["0", "false", "no", "off"].includes(normalized))
|
|
123
|
+
return false;
|
|
124
|
+
throw new Error(`Environment variable ${name} must be a boolean, got: ${raw}`);
|
|
125
|
+
}
|
|
126
|
+
/** Read the OpenAI-compatible model configuration from the `ARCHMAX_*` environment keys. */
|
|
127
|
+
export function loadEnv() {
|
|
128
|
+
return {
|
|
129
|
+
apiBaseUrl: required("API_BASE_URL"),
|
|
130
|
+
apiKey: required("API_KEY"),
|
|
131
|
+
model: required("MODEL"),
|
|
132
|
+
temperature: optionalNumber("TEMPERATURE"),
|
|
133
|
+
maxTokens: optionalNumber("MAX_TOKENS"),
|
|
134
|
+
streaming: optionalBoolean("STREAMING"),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Pin an unnamed response role to `assistant` on both of the provider's
|
|
139
|
+
* message-conversion seams.
|
|
140
|
+
*
|
|
141
|
+
* An OpenAI-compatible endpoint is not required to name the role in what it
|
|
142
|
+
* sends back, and many do not: proxies (LiteLLM and friends) drop or null it,
|
|
143
|
+
* and providers legitimately send it only on the first streaming delta.
|
|
144
|
+
* `@langchain/openai` maps a response with no role to a *generic* `ChatMessage`
|
|
145
|
+
* / `ChatMessageChunk` instead of an `AIMessage` — and a generic **first**
|
|
146
|
+
* chunk poisons the whole reply, because every later `AIMessageChunk` merges
|
|
147
|
+
* into the receiver's class. The agent loop then gets a message that is not the
|
|
148
|
+
* assistant's turn: tool calls are invisible to it, and the framework refuses
|
|
149
|
+
* the model result outright (see `asModelCallResult` in `core/framework.ts`,
|
|
150
|
+
* which repairs what still reaches it — e.g. from a model a library user
|
|
151
|
+
* supplies rather than this factory).
|
|
152
|
+
*
|
|
153
|
+
* What comes back from a chat completion *is* the assistant's turn, so a
|
|
154
|
+
* response that names no role is read as one.
|
|
155
|
+
*/
|
|
156
|
+
function withAssistantRoleDefault(completions) {
|
|
157
|
+
// Both converters are `protected` on the provider class, so they are replaced
|
|
158
|
+
// through an index signature rather than a subclass override — that keeps this
|
|
159
|
+
// module free of the provider SDK's request/response types. Each is patched
|
|
160
|
+
// only if present: a provider release that drops the seam (both are marked
|
|
161
|
+
// deprecated upstream) leaves the model untouched rather than failing here,
|
|
162
|
+
// and the framework-level repair still covers it.
|
|
163
|
+
const seam = completions;
|
|
164
|
+
const deltaConverter = seam._convertCompletionsDeltaToBaseMessageChunk;
|
|
165
|
+
if (typeof deltaConverter === "function") {
|
|
166
|
+
const original = deltaConverter;
|
|
167
|
+
seam._convertCompletionsDeltaToBaseMessageChunk = (delta, rawResponse, defaultRole) => {
|
|
168
|
+
// `role` on a delta is sticky: the provider sends it once and the caller
|
|
169
|
+
// carries it forward as `defaultRole`. A role the provider did name as one
|
|
170
|
+
// of the protocol's own keeps deciding the class, so this changes nothing
|
|
171
|
+
// for a conforming endpoint.
|
|
172
|
+
const role = responseRole(stringRole(delta)) ?? defaultRole ?? "assistant";
|
|
173
|
+
return original.call(completions, { ...delta, role }, rawResponse, role);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
const messageConverter = seam._convertCompletionsMessageToBaseMessage;
|
|
177
|
+
if (typeof messageConverter === "function") {
|
|
178
|
+
const original = messageConverter;
|
|
179
|
+
seam._convertCompletionsMessageToBaseMessage = (message, rawResponse) => {
|
|
180
|
+
const role = responseRole(stringRole(message)) ?? "assistant";
|
|
181
|
+
return original.call(completions, { ...message, role }, rawResponse);
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return completions;
|
|
185
|
+
}
|
|
186
|
+
/** The `role` a provider named on a delta/message, if it named a non-empty one. */
|
|
187
|
+
function stringRole(payload) {
|
|
188
|
+
const role = payload?.role;
|
|
189
|
+
return typeof role === "string" && role !== "" ? role : undefined;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The roles the chat-completions protocol defines for a turn that is *not* the
|
|
193
|
+
* assistant's. A response naming one of these is left as it is — the endpoint
|
|
194
|
+
* meant it, and the provider integration maps it faithfully.
|
|
195
|
+
*/
|
|
196
|
+
const NON_ASSISTANT_ROLES = new Set(["user", "system", "developer", "tool", "function"]);
|
|
197
|
+
/**
|
|
198
|
+
* Which role a *response* should be read as. Anything the protocol does not
|
|
199
|
+
* define for another turn is the assistant's — including a role borrowed from a
|
|
200
|
+
* different API's vocabulary (`model`), which is what a proxy fronting a
|
|
201
|
+
* non-OpenAI provider tends to pass through.
|
|
202
|
+
*/
|
|
203
|
+
function responseRole(named) {
|
|
204
|
+
if (named === undefined)
|
|
205
|
+
return undefined;
|
|
206
|
+
return NON_ASSISTANT_ROLES.has(named) ? named : "assistant";
|
|
207
|
+
}
|
|
208
|
+
/** Build a `ChatOpenAI` model pointed at any OpenAI-compatible endpoint. */
|
|
209
|
+
export function createChatModel(env = loadEnv()) {
|
|
210
|
+
const fields = {
|
|
211
|
+
model: env.model,
|
|
212
|
+
apiKey: env.apiKey,
|
|
213
|
+
temperature: env.temperature,
|
|
214
|
+
maxTokens: env.maxTokens,
|
|
215
|
+
// Streaming feeds `agent-text-delta` events; `invoke` results are the
|
|
216
|
+
// same either way. `ARCHMAX_STREAMING=0` opts out.
|
|
217
|
+
streaming: env.streaming ?? true,
|
|
218
|
+
// Ask for usage in the stream: without it a streaming run (the default)
|
|
219
|
+
// reports no tokens at all, and token/cost accounting would silently be zero.
|
|
220
|
+
streamUsage: true,
|
|
221
|
+
configuration: { baseURL: env.apiBaseUrl },
|
|
222
|
+
};
|
|
223
|
+
// The chat-completions sub-model is constructed here rather than left to
|
|
224
|
+
// `ChatOpenAI` so the role normalization is part of the fields the wrapper
|
|
225
|
+
// rebuilds itself from: `withConfig()` (which the agent loop uses) makes a new
|
|
226
|
+
// wrapper out of exactly this object, and a sub-model patched afterwards would
|
|
227
|
+
// be dropped by it.
|
|
228
|
+
return new ChatOpenAI({
|
|
229
|
+
...fields,
|
|
230
|
+
completions: withAssistantRoleDefault(new ChatOpenAICompletions(fields)),
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Prompt-cache configuration from the environment: `ARCHMAX_PROMPT_CACHE`
|
|
235
|
+
* (default on) and `ARCHMAX_PROMPT_CACHE_TTL` (`5m` | `1h`).
|
|
236
|
+
*/
|
|
237
|
+
export function loadPromptCacheEnv() {
|
|
238
|
+
const enabled = optionalBoolean("PROMPT_CACHE");
|
|
239
|
+
const { raw: ttl } = envValue("PROMPT_CACHE_TTL");
|
|
240
|
+
return {
|
|
241
|
+
...(enabled !== undefined ? { enabled } : {}),
|
|
242
|
+
...(ttl?.trim() ? { ttl: ttl.trim() } : {}),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Token prices from the environment, in USD per 1M tokens, applying to whatever
|
|
247
|
+
* model is configured: `ARCHMAX_PRICE_INPUT`, `ARCHMAX_PRICE_OUTPUT`,
|
|
248
|
+
* `ARCHMAX_PRICE_CACHE_READ`, `ARCHMAX_PRICE_CACHE_WRITE`. Returns `undefined`
|
|
249
|
+
* when none are set, so cost is omitted rather than reported as zero.
|
|
250
|
+
*/
|
|
251
|
+
export function loadPricingEnv() {
|
|
252
|
+
const entry = {};
|
|
253
|
+
const input = optionalNumber("PRICE_INPUT");
|
|
254
|
+
const output = optionalNumber("PRICE_OUTPUT");
|
|
255
|
+
const cacheRead = optionalNumber("PRICE_CACHE_READ");
|
|
256
|
+
const cacheWrite = optionalNumber("PRICE_CACHE_WRITE");
|
|
257
|
+
if (input !== undefined)
|
|
258
|
+
entry.input = input;
|
|
259
|
+
if (output !== undefined)
|
|
260
|
+
entry.output = output;
|
|
261
|
+
if (cacheRead !== undefined)
|
|
262
|
+
entry.cacheRead = cacheRead;
|
|
263
|
+
if (cacheWrite !== undefined)
|
|
264
|
+
entry.cacheWrite = cacheWrite;
|
|
265
|
+
if (Object.keys(entry).length === 0)
|
|
266
|
+
return undefined;
|
|
267
|
+
return { [DEFAULT_PRICING_KEY]: entry };
|
|
268
|
+
}
|
|
269
|
+
/** The default, role-independent model factory: the env-configured `ChatOpenAI`. */
|
|
270
|
+
export const defaultModelFactory = (_role, env, requested) => createChatModel(requested === undefined ? env() : { ...env(), model: requested });
|
|
271
|
+
//# sourceMappingURL=env.js.map
|
package/dist/env.js.map
ADDED
|
@@ -0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3
|
+
* Agents. Assemble a governed agent with {@link createAgent}, point it at a
|
|
4
|
+
* workspace of authored workflows, and drive it like any Deep Agent.
|
|
5
|
+
*
|
|
6
|
+
* The runtime reads its entire agent definition (machine spec, system prompt,
|
|
7
|
+
* skills, scripts) and session state through a single Deep Agents
|
|
8
|
+
* backend, so the same code runs over a local filesystem, a store, a sandbox, or
|
|
9
|
+
* a remote backend without modification.
|
|
10
|
+
*
|
|
11
|
+
* **What is public.** This barrel is the supported surface, and every export
|
|
12
|
+
* carries a docstring saying what it is for. It is deliberately small: an export
|
|
13
|
+
* is here because a real consumer needs it, not because a module happened to
|
|
14
|
+
* expose it. Adjacent surfaces live on their own subpaths — `@archmax-ai/harness/testing`
|
|
15
|
+
* (the case engine), `@archmax-ai/harness/cli` (the state-flow renderer), and
|
|
16
|
+
* `@archmax-ai/harness/sandbox` (hook and script authoring) — so a production import never
|
|
17
|
+
* pulls in test machinery.
|
|
18
|
+
*
|
|
19
|
+
* Two **light** subpaths mirror part of this surface without the runtime behind
|
|
20
|
+
* it: `@archmax-ai/harness/spec` (the schema, the pure validator and the grammars —
|
|
21
|
+
* browser-safe) and `@archmax-ai/harness/messages` (transcript readers). A name on
|
|
22
|
+
* both is the same binding.
|
|
23
|
+
*
|
|
24
|
+
* Anything not exported here is internal and may change without a major version.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Assemble an agent: Deep Agents' own parameters plus `workflow`. Omit `workflow`
|
|
28
|
+
* for a plain Deep Agent; supply it and the same agent is governed by that
|
|
29
|
+
* machine. Returns a wrapper over the compiled graph — `invoke` / `stream` /
|
|
30
|
+
* `graph` — with governance under `.workflow`.
|
|
31
|
+
*/
|
|
32
|
+
export { createAgent } from "./assembly/index.js";
|
|
33
|
+
/** The wrapper class {@link createAgent} returns. */
|
|
34
|
+
export { ArchmaxAgent } from "./agent.js";
|
|
35
|
+
export type {
|
|
36
|
+
/** Parameters for {@link createAgent}. */
|
|
37
|
+
CreateAgentParams,
|
|
38
|
+
/** Where files come from and where sessions go (the `workspace` group). */
|
|
39
|
+
AgentWorkspaceParams, } from "./assembly/index.js";
|
|
40
|
+
export type {
|
|
41
|
+
/** What {@link createAgent} returns. */
|
|
42
|
+
Agent,
|
|
43
|
+
/** @deprecated Narrow on `agent.workflow` instead. An {@link Agent} known to be governed. */
|
|
44
|
+
GovernedAgent,
|
|
45
|
+
/** @deprecated The members live on {@link Agent} directly. */
|
|
46
|
+
AgentRunSurface,
|
|
47
|
+
/** The governance surface at `agent.workflow`, `undefined` when ungoverned. */
|
|
48
|
+
WorkflowSurface,
|
|
49
|
+
/** A turn's input to `agent.workflow.send`. */
|
|
50
|
+
TurnInput,
|
|
51
|
+
/** What `agent.workflow.send` takes: a turn or a resume. */
|
|
52
|
+
SendInput, } from "./agent.js";
|
|
53
|
+
/** Session handles over the configured session store (`agent.sessions`). */
|
|
54
|
+
export type { SessionOperations } from "./sessions/operations.js";
|
|
55
|
+
export type {
|
|
56
|
+
/** How a session is started: a trigger id. */
|
|
57
|
+
TriggerInput,
|
|
58
|
+
/** A resolved trigger: its id plus the start state it enters. */
|
|
59
|
+
ResolvedTrigger, } from "./machine/triggers.js";
|
|
60
|
+
export type {
|
|
61
|
+
/** What one `send` produced, whichever way it entered the session. */
|
|
62
|
+
Outcome,
|
|
63
|
+
/** One of the three resumes: a decision, a reply, or a delivery. */
|
|
64
|
+
ResumePayload,
|
|
65
|
+
/** The person's answer, as `agent.workflow.decide()` takes it. */
|
|
66
|
+
DecisionResolution,
|
|
67
|
+
/** A firing delivered into a parked session, as `agent.workflow.deliver()` takes it. */
|
|
68
|
+
TriggerDelivery,
|
|
69
|
+
/** The outcome of deciding a parked human state. */
|
|
70
|
+
DecideOutcome,
|
|
71
|
+
/** The outcome of replying to a session parked at a human state. */
|
|
72
|
+
ReplyOutcome,
|
|
73
|
+
/** @deprecated Older spelling of {@link ReplyOutcome}; kept for one release. */
|
|
74
|
+
RespondOutcome,
|
|
75
|
+
/** The outcome of delivering into a session parked with `archmax_wait`. */
|
|
76
|
+
DeliverOutcome,
|
|
77
|
+
/** The child a parked session's pending decision belongs to (`Outcome.delegation`). */
|
|
78
|
+
DelegatedPark, } from "./sessions/resume.js";
|
|
79
|
+
/**
|
|
80
|
+
* Read a session that must be parked in `status` — the checkpointed status **and**
|
|
81
|
+
* a live suspension — or `null`. What every resume asks before touching the graph.
|
|
82
|
+
*/
|
|
83
|
+
export { readParkedSession } from "./sessions/resume.js";
|
|
84
|
+
export {
|
|
85
|
+
/** The park record a session's checkpointed values hold, on either channel, or `null`. */
|
|
86
|
+
pendingParkOf,
|
|
87
|
+
/** The state a park record names, across the current and the deprecated spelling. */
|
|
88
|
+
parkedStateOf, } from "./workflow/state.js";
|
|
89
|
+
export type {
|
|
90
|
+
/** What `agent.workflow.resolveSession()` takes: one firing. */
|
|
91
|
+
ResolveSessionInput,
|
|
92
|
+
/** Where a firing lands: the session and its disposition. */
|
|
93
|
+
ResolvedSession, } from "./sessions/resolve.js";
|
|
94
|
+
export type {
|
|
95
|
+
/** The checkpointed record a session parked at a human state presents. */
|
|
96
|
+
PendingDecision,
|
|
97
|
+
/** The checkpointed record a session parked with `archmax_wait` presents. */
|
|
98
|
+
PendingInput, } from "./workflow/state.js";
|
|
99
|
+
/**
|
|
100
|
+
* The checkpoint-facing half of a compiled graph, for a host that drives
|
|
101
|
+
* LangGraph directly (`getState`, `updateState`) against `agent.graph`.
|
|
102
|
+
*/
|
|
103
|
+
export type { IntrospectableStateGraph } from "./core/deepagents.js";
|
|
104
|
+
/** One session's projection: status, position, variables, usage, parent. */
|
|
105
|
+
export type { SessionSummary } from "./sessions/summary.js";
|
|
106
|
+
export {
|
|
107
|
+
/** A named workflow has no loadable machine spec — assembly fails closed. */
|
|
108
|
+
WorkflowLoadError,
|
|
109
|
+
/** A turn would start a session on a workflow that declares `disabled: true`. */
|
|
110
|
+
WorkflowDisabledError, } from "./machine/load-spec.js";
|
|
111
|
+
/** A trigger id the machine does not declare. */
|
|
112
|
+
export { UnknownTriggerError } from "./machine/triggers.js";
|
|
113
|
+
/** A host tool wearing a reserved `archmax_` name. */
|
|
114
|
+
export { ReservedToolNameError } from "./machine/tool-names.js";
|
|
115
|
+
/** A seeded variable name that is not a legal identifier. */
|
|
116
|
+
export { InvalidVariableNameError } from "./machine/variables.js";
|
|
117
|
+
/** A mount key shadows a session area. */
|
|
118
|
+
export { MountCollisionError } from "./core/mounts.js";
|
|
119
|
+
export {
|
|
120
|
+
/** A custom `backend` was supplied without a `sessionStore`. */
|
|
121
|
+
SessionStoreRequiredError,
|
|
122
|
+
/** A session id that would escape its zone or shadow a reserved name. */
|
|
123
|
+
SessionStoreIdError,
|
|
124
|
+
/** A session operation the configured store cannot perform (delete, list). */
|
|
125
|
+
SessionStoreCapabilityError, } from "./core/session-store.js";
|
|
126
|
+
export {
|
|
127
|
+
/** The authoring backend was also served by a writable mount. */
|
|
128
|
+
AuthoringBackendExposedError,
|
|
129
|
+
/** @deprecated Older spelling of {@link AuthoringBackendExposedError}; kept for one release. */
|
|
130
|
+
AuthoringPlaneExposedError,
|
|
131
|
+
/** A partly composed workspace needed a filesystem default and no `rootDir` was given. */
|
|
132
|
+
WorkspaceRootRequiredError, } from "./core/workspace-context.js";
|
|
133
|
+
/** A workspace declared a `runtime.version` this build does not implement. */
|
|
134
|
+
export { UnsupportedRuntimeContractError } from "./runtime/contract.js";
|
|
135
|
+
export {
|
|
136
|
+
/** A decision or reply for a session not parked at a human state. */
|
|
137
|
+
SessionNotParkedError,
|
|
138
|
+
/** A decision naming a target the parked state does not declare. */
|
|
139
|
+
InvalidDecisionTargetError,
|
|
140
|
+
/** A reply with nothing to answer. */
|
|
141
|
+
EmptyMessageError,
|
|
142
|
+
/** A delivery to a session not parked with `archmax_wait`. */
|
|
143
|
+
SessionNotAwaitingInputError,
|
|
144
|
+
/** A delivery naming no trigger id. */
|
|
145
|
+
MissingDeliveryTriggerError, } from "./sessions/resume.js";
|
|
146
|
+
/** A firing for a session whose turn is still in progress. */
|
|
147
|
+
export { SessionNotResumableError } from "./sessions/resolve.js";
|
|
148
|
+
/** The conventional mount table for a filesystem workspace. */
|
|
149
|
+
export { defaultMounts } from "./core/mounts.js";
|
|
150
|
+
/** Rebase one backend so it can serve several mounts. */
|
|
151
|
+
export { mountSubtree } from "./core/path-mapping.js";
|
|
152
|
+
/** One mount: a backend, or `{ backend, readOnly }`. */
|
|
153
|
+
export type { MountSpec } from "./core/mounts.js";
|
|
154
|
+
export {
|
|
155
|
+
/** Filesystem session store (the zero-config default). */
|
|
156
|
+
createFilesystemSessionStore,
|
|
157
|
+
/** Session store over any Deep Agents backend (e.g. S3). */
|
|
158
|
+
createBackendSessionStore,
|
|
159
|
+
/** Ephemeral session store, for tests and one-shot sessions. */
|
|
160
|
+
createMemorySessionStore, } from "./core/session-store.js";
|
|
161
|
+
/** Physical storage for sessions. */
|
|
162
|
+
export type { SessionStore } from "./core/session-store.js";
|
|
163
|
+
/** Whether a name is reserved at the workspace root (a session area or a mount). */
|
|
164
|
+
export { isReservedRootName } from "./core/zones.js";
|
|
165
|
+
/** Why a session id cannot own a session folder, or `null` when it can — the rule every ingress applies. */
|
|
166
|
+
export { sessionIdRejection } from "./core/session-id.js";
|
|
167
|
+
/** Whether one session was dispatched by another (`<parent>~<state>:<workflow>:<n>`), at any depth. */
|
|
168
|
+
export { isChildSessionOf } from "./sessions/scope.js";
|
|
169
|
+
/** Which zone a workspace path belongs to — the kernel's own classifier (a host maps evidence paths with it). */
|
|
170
|
+
export { classifyWorkspacePath } from "./core/zones.js";
|
|
171
|
+
export type { WorkspaceZone } from "./core/zones.js";
|
|
172
|
+
/** The resolved mount keys a workspace classifies paths against. */
|
|
173
|
+
export type { MountPrefixes } from "./core/zones.js";
|
|
174
|
+
/**
|
|
175
|
+
* Build the workspace composite the assembly uses. Public because a consumer
|
|
176
|
+
* serving authored content from its own backend needs the same composition.
|
|
177
|
+
*/
|
|
178
|
+
export { createWorkspaceContext } from "./core/workspace-context.js";
|
|
179
|
+
/** What {@link createWorkspaceContext} returns: the composed backends and mounts. */
|
|
180
|
+
export type { WorkspaceContext } from "./core/workspace-context.js";
|
|
181
|
+
/** Where a workspace may override the bundled platform prompt (`.platform/system/GRAPH_STATE.md`). */
|
|
182
|
+
export { PLATFORM_BACKEND_PROMPT_PATH } from "./workflow/paths.js";
|
|
183
|
+
/** Compose the system prompt from persona, platform, zones and workflow layers. */
|
|
184
|
+
export { resolveSystemPrompt } from "./core/prompt.js";
|
|
185
|
+
/** Bind a `name → tool` map in the shape the `tools` option takes. */
|
|
186
|
+
export { toolsFromMap } from "./workflow/agent-tools.js";
|
|
187
|
+
/** A message's text, whatever content-block shape it arrived in. */
|
|
188
|
+
export { contentToString } from "./core/messages.js";
|
|
189
|
+
/** Whether a message is the assistant's turn. */
|
|
190
|
+
export { isAiMessage } from "./core/messages.js";
|
|
191
|
+
/** The last thing the agent said to the person; tool results and runtime notes are skipped. */
|
|
192
|
+
export { lastAgentText } from "./core/messages.js";
|
|
193
|
+
/**
|
|
194
|
+
* Whether the runtime wrote a transcript message rather than a person — a
|
|
195
|
+
* decision, an arrival, an error route, a completion check, a child's result.
|
|
196
|
+
* A host slicing a turn out of a session's messages, or rendering a transcript,
|
|
197
|
+
* asks this instead of inferring authorship from role.
|
|
198
|
+
*/
|
|
199
|
+
export { isRuntimeNote } from "./core/messages.js";
|
|
200
|
+
/** Which kind of runtime note a message is, or `null` if a person wrote it. */
|
|
201
|
+
export { runtimeNoteKind } from "./core/messages.js";
|
|
202
|
+
export type { RuntimeNoteKind } from "./core/messages.js";
|
|
203
|
+
/** One grading rubric, as declared inline on the hook that applies it. */
|
|
204
|
+
export type { RubricDeclaration } from "./machine/types.js";
|
|
205
|
+
/** Host data the runtime never reads, at the spec root, on a state, or on a rubric. */
|
|
206
|
+
export type { SpecMetadata } from "./machine/types.js";
|
|
207
|
+
/** Parse a sandbox script's leading description block. */
|
|
208
|
+
export { parseCodeDescription } from "./core/code-description.js";
|
|
209
|
+
/** Load and shape-check a `workflow.yaml` without assembling an agent. */
|
|
210
|
+
export { loadMachineSpec } from "./machine/load-spec.js";
|
|
211
|
+
/** A `before:`/`after:` declaration as a flat list of hooks. */
|
|
212
|
+
export { normalizeHooks } from "./lifecycle/hook-shape.js";
|
|
213
|
+
export type { MachineSpec, MachineState } from "./machine/types.js";
|
|
214
|
+
/** The compiled machine, as `agent.workflow.machine` exposes it. */
|
|
215
|
+
export { WorkflowMachine } from "./machine/machine.js";
|
|
216
|
+
/** Statically validate a workflow scaffold — no model calls. */
|
|
217
|
+
export { validateWorkflow } from "./validate/validate.js";
|
|
218
|
+
export type { ValidationResult, Diagnostic } from "./validate/validate.js";
|
|
219
|
+
/** A custom governance rule, inserted after the safety and policy rules. */
|
|
220
|
+
export type { GovernanceRule } from "./kernel/kernel.js";
|
|
221
|
+
/**
|
|
222
|
+
* The dispatcher's default delegation bounds. Public because a host configuring
|
|
223
|
+
* `bounds` needs to know what it is overriding.
|
|
224
|
+
*/
|
|
225
|
+
export { DEFAULT_SUB_WORKFLOW_DEPTH, DEFAULT_SUB_WORKFLOW_CONCURRENCY, } from "./machine/delegation.js";
|
|
226
|
+
export {
|
|
227
|
+
/** The entry trigger id (`manual`). */
|
|
228
|
+
MANUAL_TRIGGER,
|
|
229
|
+
/** The trigger applied when none is supplied (same value as `MANUAL_TRIGGER`). */
|
|
230
|
+
DEFAULT_TRIGGER_ID,
|
|
231
|
+
/** The session id a firing of a trigger resolves to under a spec, or `undefined` when the runtime mints one. */
|
|
232
|
+
sessionIdForTrigger, } from "./machine/triggers.js";
|
|
233
|
+
/** Default workflow slug when none is named. */
|
|
234
|
+
export { DEFAULT_WORKFLOW } from "./workflow/paths.js";
|
|
235
|
+
export {
|
|
236
|
+
/** Prefix of every delegation tool name. */
|
|
237
|
+
WORKFLOW_TOOL_PREFIX,
|
|
238
|
+
/** The delegation tool name for a workflow slug. */
|
|
239
|
+
workflowToolName,
|
|
240
|
+
/** The workflow slug a delegation tool name refers to. */
|
|
241
|
+
workflowSlugFromToolName, } from "./machine/tool-names.js";
|
|
242
|
+
export type {
|
|
243
|
+
/** Every runtime diagnostic, as one typed union. */
|
|
244
|
+
WorkflowLifecycleEvent,
|
|
245
|
+
/** The `onEvent` subscriber. */
|
|
246
|
+
WorkflowEventHandler, } from "./core/events.js";
|
|
247
|
+
/** Fold `model-usage` events into per-session totals and cost. */
|
|
248
|
+
export { createUsageTracker } from "./core/usage.js";
|
|
249
|
+
/** Render a usage summary for a footer or a log line. */
|
|
250
|
+
export { formatUsage } from "./core/usage.js";
|
|
251
|
+
export type { UsageSummary, PricingTable } from "./core/usage.js";
|
|
252
|
+
/** Build the env-configured chat model to pass as `model`. */
|
|
253
|
+
export { createChatModel } from "./env.js";
|
|
254
|
+
export {
|
|
255
|
+
/**
|
|
256
|
+
* The bundled authoring skill's parent directory (holding `archmax-harness/`), so an
|
|
257
|
+
* authoring agent's reference always matches the installed SDK.
|
|
258
|
+
*/
|
|
259
|
+
BUNDLED_AUTHORING_SKILL_DIR,
|
|
260
|
+
/** @deprecated Use `BUNDLED_AUTHORING_SKILL_DIR`; same value. */
|
|
261
|
+
BUNDLED_SKILLS_DIR, } from "./env.js";
|
|
262
|
+
/** This package's version, as session metadata records it. */
|
|
263
|
+
export { PACKAGE_VERSION } from "./env.js";
|
|
264
|
+
/** The resolved `runtime.version` and the surfaces it implies. */
|
|
265
|
+
export type { RuntimeContract, ResolvedRuntimeContract } from "./runtime/contract.js";
|