@hassangameryt/freeflow 0.4.0 → 0.6.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +2 -1
- package/.codex-plugin/plugin.json +2 -1
- package/README.md +150 -155
- package/capabilities/cognitive-routing/SKILL.md +229 -0
- package/capabilities/context-virtualization/SKILL.md +103 -0
- package/capabilities/conversation-history/SKILL.md +53 -0
- package/command-surface.json +17 -13
- package/hooks/freeflow-runtime-context.mjs +393 -159
- package/hooks/hooks.json +26 -1
- package/hooks/tests/check-runtime-context-hook.sh +223 -54
- package/package.json +25 -16
- package/pi-extension/dist/cognitive-routing/commands.js +96 -0
- package/pi-extension/dist/cognitive-routing/config.js +236 -0
- package/pi-extension/dist/cognitive-routing/controller.js +862 -0
- package/pi-extension/dist/cognitive-routing/history.js +439 -0
- package/pi-extension/dist/cognitive-routing/host.js +126 -0
- package/pi-extension/dist/cognitive-routing/runtime.js +43 -0
- package/pi-extension/dist/cognitive-routing/tool.js +211 -0
- package/pi-extension/dist/cognitive-routing/types.js +6 -0
- package/pi-extension/dist/context-virtualization/commands.js +89 -0
- package/pi-extension/dist/context-virtualization/projector.js +42 -0
- package/pi-extension/dist/context-virtualization/runtime.js +356 -0
- package/pi-extension/dist/context-virtualization/state.js +57 -0
- package/pi-extension/dist/context-virtualization/types.js +10 -0
- package/pi-extension/dist/conversation-history/passages.js +66 -0
- package/pi-extension/dist/conversation-history/ranking.js +105 -0
- package/pi-extension/dist/conversation-history/runtime.js +226 -0
- package/pi-extension/dist/conversation-history/search.js +56 -0
- package/pi-extension/dist/conversation-history/types.js +1 -0
- package/pi-extension/dist/freeflow-context/resolver.js +120 -0
- package/pi-extension/dist/freeflow-context/runtime.js +80 -0
- package/pi-extension/dist/freeflow-context/source-projector.js +95 -0
- package/pi-extension/dist/freeflow-context/tool.js +308 -0
- package/pi-extension/dist/freeflow-context/types.js +12 -0
- package/pi-extension/dist/freeflow-context/visibility.js +28 -0
- package/pi-extension/dist/index.js +516 -98
- package/pi-extension/dist/runtime/runtime-context.js +318 -271
- package/pi-extension/dist/runtime/runtime-identity.js +5 -0
- package/pi-extension/dist/settings/settings-tui.js +78 -0
- package/pi-extension/dist/settings/settings-ui.js +593 -563
- package/pi-extension/dist/ui/text-component.js +57 -0
- package/pi-extension/src/cognitive-routing/commands.ts +119 -0
- package/pi-extension/src/cognitive-routing/config.ts +307 -0
- package/pi-extension/src/cognitive-routing/controller.ts +1118 -0
- package/pi-extension/src/cognitive-routing/history.ts +638 -0
- package/pi-extension/src/cognitive-routing/host.ts +172 -0
- package/pi-extension/src/cognitive-routing/runtime.ts +57 -0
- package/pi-extension/src/cognitive-routing/tool.ts +272 -0
- package/pi-extension/src/cognitive-routing/types.ts +89 -0
- package/pi-extension/src/context-virtualization/commands.ts +111 -0
- package/pi-extension/src/context-virtualization/projector.ts +62 -0
- package/pi-extension/src/context-virtualization/runtime.ts +406 -0
- package/pi-extension/src/context-virtualization/state.ts +79 -0
- package/pi-extension/src/context-virtualization/types.ts +92 -0
- package/pi-extension/src/conversation-history/passages.ts +81 -0
- package/pi-extension/src/conversation-history/ranking.ts +155 -0
- package/pi-extension/src/conversation-history/runtime.ts +250 -0
- package/pi-extension/src/conversation-history/search.ts +79 -0
- package/pi-extension/src/conversation-history/types.ts +31 -0
- package/pi-extension/src/freeflow-context/resolver.ts +139 -0
- package/pi-extension/src/freeflow-context/runtime.ts +100 -0
- package/pi-extension/src/freeflow-context/source-projector.ts +106 -0
- package/pi-extension/src/freeflow-context/tool.ts +360 -0
- package/pi-extension/src/freeflow-context/types.ts +70 -0
- package/pi-extension/src/freeflow-context/visibility.ts +53 -0
- package/pi-extension/src/index.ts +553 -101
- package/pi-extension/src/runtime/runtime-context.ts +339 -281
- package/pi-extension/src/runtime/runtime-identity.ts +8 -0
- package/pi-extension/src/settings/settings-tui.ts +93 -0
- package/pi-extension/src/settings/settings-ui.ts +700 -613
- package/pi-extension/src/ui/text-component.ts +66 -0
- package/pi-extension/tests/cognitive-routing/commands.test.js +134 -0
- package/pi-extension/tests/cognitive-routing/controller.test.js +1099 -0
- package/pi-extension/tests/cognitive-routing/extension-lifecycle.test.js +1071 -0
- package/pi-extension/tests/cognitive-routing/history.test.js +274 -0
- package/pi-extension/tests/cognitive-routing/host-fixture.js +4 -0
- package/pi-extension/tests/cognitive-routing/host-identity.test.js +63 -0
- package/pi-extension/tests/cognitive-routing/profile-resolution.test.js +236 -0
- package/pi-extension/tests/cognitive-routing/tool.test.js +230 -0
- package/pi-extension/tests/context-virtualization/extension.test.js +749 -0
- package/pi-extension/tests/context-virtualization/projector.test.js +110 -0
- package/pi-extension/tests/context-virtualization/runtime.test.js +216 -0
- package/pi-extension/tests/conversation-history/runtime.test.js +98 -0
- package/pi-extension/tests/conversation-history/search.test.js +97 -0
- package/pi-extension/tests/integration/pi-extension.test.js +928 -2047
- package/pi-extension/tests/integration/prompt-architecture.test.js +305 -0
- package/runtime/prompts/cognitive-routing.md +9 -0
- package/runtime/prompts/context-virtualization.md +3 -0
- package/runtime/prompts/conversation-history.md +3 -0
- package/runtime/prompts/core.md +13 -0
- package/runtime/prompts/interaction-contract.md +7 -0
- package/runtime/prompts/skills.md +65 -0
- package/skills/action-selection/SKILL.md +91 -0
- package/skills/bypass/SKILL.md +3 -2
- package/skills/commit-work/SKILL.md +1 -1
- package/skills/commit-work/references/staging-decisions.md +1 -1
- package/skills/decision-gate/SKILL.md +1 -1
- package/skills/design-for-depth/SKILL.md +14 -33
- package/skills/design-for-depth/references/design-pressure-signals.md +1 -1
- package/skills/design-for-depth/references/interface-design-loop.md +1 -1
- package/skills/design-for-depth/references/software-design-philosophy.md +1 -1
- package/skills/diagnose-failure/SKILL.md +20 -14
- package/skills/diagnose-failure/references/diagnostic-loop-catalog.md +1 -3
- package/skills/diagnose-failure/references/{flaky-and-performance.md → flaky-and-performance-diagnosis.md} +1 -1
- package/skills/discuss/SKILL.md +34 -22
- package/skills/discuss/references/discussion-continuity.md +71 -0
- package/skills/evaluate-skill/SKILL.md +5 -5
- package/skills/evaluate-skill/references/{definition-schema.md → evaluation-definition-schema.md} +42 -2
- package/skills/evaluate-skill/references/execution-and-evidence.md +8 -3
- package/skills/evaluate-skill/scripts/lib/definitions.mjs +114 -3
- package/skills/evaluate-skill/scripts/lib/grade-interaction.mjs +156 -1
- package/skills/evaluate-skill/scripts/lib/grade.mjs +9 -1
- package/skills/evaluate-skill/scripts/lib/pi.mjs +147 -32
- package/skills/evaluate-skill/scripts/lib/rpc.mjs +4 -4
- package/skills/evaluate-skill/scripts/lib/runner.mjs +36 -14
- package/skills/evaluate-skill/scripts/lib/sandbox.mjs +92 -0
- package/skills/evaluate-skill/scripts/pi-guard.mjs +1 -1
- package/skills/evaluate-skill/scripts/pi-observer.mjs +66 -0
- package/skills/evaluate-skill/scripts/skill-eval.mjs +6 -5
- package/skills/execute-work/SKILL.md +18 -15
- package/skills/execute-work/references/code-practices.md +1 -1
- package/skills/execute-work/references/execute-work-edges.md +42 -0
- package/skills/finish-branch/SKILL.md +2 -2
- package/skills/finish-branch/references/integration-options.md +1 -1
- package/skills/handoff/SKILL.md +3 -3
- package/skills/launch-work/SKILL.md +1 -1
- package/skills/launch-work/references/launch-readiness.md +2 -2
- package/skills/migration-work/SKILL.md +2 -2
- package/skills/migration-work/references/migration-lifecycle.md +1 -1
- package/skills/mode-contract/SKILL.md +32 -10
- package/skills/release-work/SKILL.md +1 -1
- package/skills/release-work/references/release-evidence.md +1 -1
- package/skills/review-artifact/SKILL.md +28 -26
- package/skills/review-work/SKILL.md +28 -26
- package/skills/review-work/references/{reviewer-prompt.md → independent-work-reviewer-contract.md} +1 -1
- package/skills/review-work/references/security-risk-lens.md +1 -1
- package/skills/setup-freeflow/SKILL.md +6 -10
- package/skills/setup-freeflow/references/activation-contract.md +5 -10
- package/skills/setup-freeflow/references/host-setup.md +3 -7
- package/skills/simplify-code/SKILL.md +1 -1
- package/skills/simplify-code/references/simplification-patterns.md +1 -1
- package/skills/tdd/SKILL.md +18 -38
- package/skills/tdd/references/test-design.md +2 -2
- package/skills/track-work/SKILL.md +362 -58
- package/skills/track-work/scripts/lib/codec.mjs +570 -0
- package/skills/track-work/scripts/lib/commands.mjs +568 -0
- package/skills/track-work/scripts/lib/contract.mjs +303 -0
- package/skills/track-work/scripts/lib/model.mjs +506 -0
- package/skills/track-work/scripts/lib/operations.mjs +965 -0
- package/skills/track-work/scripts/lib/record-store.mjs +264 -0
- package/skills/track-work/scripts/lib/result.mjs +37 -0
- package/skills/track-work/scripts/lib/rewrites.mjs +740 -0
- package/skills/track-work/scripts/lib/schema.mjs +277 -0
- package/skills/track-work/scripts/lib/source-inventory.mjs +162 -0
- package/skills/track-work/scripts/lib/views.mjs +443 -0
- package/skills/track-work/scripts/lib/workspace.mjs +134 -0
- package/skills/track-work/scripts/working-record.mjs +122 -0
- package/skills/verify-work/SKILL.md +14 -2
- package/skills/verify-work/references/browser-runtime-evidence.md +1 -1
- package/skills/verify-work/references/integration-evidence.md +1 -1
- package/skills/verify-work/references/performance-evidence.md +1 -1
- package/skills/workflow/SKILL.md +105 -53
- package/skills/workflow/references/domain-skill-composition.md +22 -42
- package/skills/write-plan/SKILL.md +1 -1
- package/skills/write-skill/SKILL.md +3 -2
- package/skills/write-skill/references/progressive-disclosure.md +17 -3
- package/pi-extension/dist/output-router/host-producer-identification.js +0 -232
- package/pi-extension/dist/output-router/native-safety-net.js +0 -216
- package/pi-extension/dist/output-router/observed-tool-routing.js +0 -122
- package/pi-extension/dist/output-router/renderers.js +0 -1023
- package/pi-extension/dist/output-router/router-tools.js +0 -554
- package/pi-extension/dist/output-router/schemas.js +0 -383
- package/pi-extension/dist/output-router/status.js +0 -744
- package/pi-extension/dist/output-router/utils.js +0 -502
- package/pi-extension/src/output-router/host-producer-identification.ts +0 -256
- package/pi-extension/src/output-router/native-safety-net.ts +0 -248
- package/pi-extension/src/output-router/observed-tool-routing.ts +0 -134
- package/pi-extension/src/output-router/renderers.ts +0 -1108
- package/pi-extension/src/output-router/router-tools.ts +0 -579
- package/pi-extension/src/output-router/schemas.ts +0 -387
- package/pi-extension/src/output-router/status.ts +0 -791
- package/pi-extension/src/output-router/utils.ts +0 -554
- package/pi-extension/tests/output-router/observed-producers.test.js +0 -132
- package/pi-extension/tests/output-router/search.test.js +0 -722
- package/router/dist/benchmarks/benchmark-harness.d.ts +0 -35
- package/router/dist/benchmarks/benchmark-harness.js +0 -92
- package/router/dist/benchmarks/benchmarks.d.ts +0 -109
- package/router/dist/benchmarks/benchmarks.js +0 -979
- package/router/dist/benchmarks/codex-qa-benchmarks.d.ts +0 -95
- package/router/dist/benchmarks/codex-qa-benchmarks.js +0 -500
- package/router/dist/benchmarks/command-benchmarks.d.ts +0 -143
- package/router/dist/benchmarks/command-benchmarks.js +0 -698
- package/router/dist/benchmarks/context-mode-normalized-benchmarks.d.ts +0 -82
- package/router/dist/benchmarks/context-mode-normalized-benchmarks.js +0 -773
- package/router/dist/benchmarks/context-mode-real-deep-benchmark.d.ts +0 -132
- package/router/dist/benchmarks/context-mode-real-deep-benchmark.js +0 -1380
- package/router/dist/benchmarks/context-saving-baseline.d.ts +0 -60
- package/router/dist/benchmarks/context-saving-baseline.js +0 -470
- package/router/dist/benchmarks/index-benchmarks.d.ts +0 -103
- package/router/dist/benchmarks/index-benchmarks.js +0 -862
- package/router/dist/benchmarks/storage-policy-benchmarks.d.ts +0 -101
- package/router/dist/benchmarks/storage-policy-benchmarks.js +0 -618
- package/router/dist/benchmarks/vault-index-benchmarks.d.ts +0 -56
- package/router/dist/benchmarks/vault-index-benchmarks.js +0 -322
- package/router/dist/config/config.d.ts +0 -103
- package/router/dist/config/config.js +0 -632
- package/router/dist/config/router-contract.d.ts +0 -10
- package/router/dist/config/router-contract.js +0 -54
- package/router/dist/config/schema.d.ts +0 -27
- package/router/dist/config/schema.js +0 -648
- package/router/dist/config/types.d.ts +0 -573
- package/router/dist/config/types.js +0 -41
- package/router/dist/evidence/bounded-evidence.d.ts +0 -40
- package/router/dist/evidence/bounded-evidence.js +0 -323
- package/router/dist/evidence/evidence-range-selector.d.ts +0 -24
- package/router/dist/evidence/evidence-range-selector.js +0 -232
- package/router/dist/evidence/evidence-search.d.ts +0 -27
- package/router/dist/evidence/evidence-search.js +0 -490
- package/router/dist/evidence/evidence.d.ts +0 -38
- package/router/dist/evidence/evidence.js +0 -200
- package/router/dist/evidence/failure-contracts.d.ts +0 -37
- package/router/dist/evidence/failure-contracts.js +0 -166
- package/router/dist/evidence/line-ranges.d.ts +0 -24
- package/router/dist/evidence/line-ranges.js +0 -22
- package/router/dist/experiments/local-index.d.ts +0 -64
- package/router/dist/experiments/local-index.js +0 -581
- package/router/dist/index.d.ts +0 -30
- package/router/dist/index.js +0 -32
- package/router/dist/local/local-traversal.d.ts +0 -18
- package/router/dist/local/local-traversal.js +0 -334
- package/router/dist/processing/engine.d.ts +0 -132
- package/router/dist/processing/engine.js +0 -533
- package/router/dist/processing/reducers.d.ts +0 -280
- package/router/dist/processing/reducers.js +0 -1673
- package/router/dist/processing/renderers.d.ts +0 -31
- package/router/dist/processing/renderers.js +0 -195
- package/router/dist/processing/scripts.d.ts +0 -91
- package/router/dist/processing/scripts.js +0 -386
- package/router/dist/repo/repo-traversal.d.ts +0 -18
- package/router/dist/repo/repo-traversal.js +0 -245
- package/router/dist/routing/observed-reducers.d.ts +0 -41
- package/router/dist/routing/observed-reducers.js +0 -661
- package/router/dist/routing/observed-routing.d.ts +0 -26
- package/router/dist/routing/observed-routing.js +0 -378
- package/router/dist/routing/parsers.d.ts +0 -16
- package/router/dist/routing/parsers.js +0 -521
- package/router/dist/routing/run-filters.d.ts +0 -60
- package/router/dist/routing/run-filters.js +0 -238
- package/router/dist/routing/run-reducers.d.ts +0 -49
- package/router/dist/routing/run-reducers.js +0 -122
- package/router/dist/sandbox/adapter-roots.d.ts +0 -46
- package/router/dist/sandbox/adapter-roots.js +0 -66
- package/router/dist/sandbox/eryx-python-adapter.d.ts +0 -13
- package/router/dist/sandbox/eryx-python-adapter.js +0 -868
- package/router/dist/sandbox/jq-wasm-adapter.d.ts +0 -9
- package/router/dist/sandbox/jq-wasm-adapter.js +0 -429
- package/router/dist/sandbox/quickjs-wasi-adapter.d.ts +0 -13
- package/router/dist/sandbox/quickjs-wasi-adapter.js +0 -384
- package/router/dist/sandbox/script-sandbox.d.ts +0 -134
- package/router/dist/sandbox/script-sandbox.js +0 -337
- package/router/dist/setup/script-transform-adapters.d.ts +0 -32
- package/router/dist/setup/script-transform-adapters.js +0 -278
- package/router/dist/tools/batch.d.ts +0 -33
- package/router/dist/tools/batch.js +0 -586
- package/router/dist/tools/run.d.ts +0 -62
- package/router/dist/tools/run.js +0 -1304
- package/router/dist/tools/search.d.ts +0 -66
- package/router/dist/tools/search.js +0 -1364
- package/router/dist/transform/engine.d.ts +0 -168
- package/router/dist/transform/engine.js +0 -2072
- package/router/dist/vault/vault-index.d.ts +0 -125
- package/router/dist/vault/vault-index.js +0 -416
- package/router/dist/vault/vault.d.ts +0 -138
- package/router/dist/vault/vault.js +0 -630
- package/runtime/interaction-contract.md +0 -16
- package/skills/discuss/references/checkpoints.md +0 -66
- package/skills/execute-work/references/execution-loop.md +0 -77
- package/skills/output-router/SKILL.md +0 -206
- package/skills/output-router/references/safety-policy.md +0 -40
- package/skills/setup-freeflow/references/output-router-setup.md +0 -110
- package/skills/track-work/references/working-record-schema.md +0 -378
- package/skills/workflow/references/workflow-loop.md +0 -92
- /package/skills/handoff/references/{templates.md → handoff-templates.md} +0 -0
- /package/skills/review-artifact/references/{reviewer-prompt.md → independent-artifact-reviewer-contract.md} +0 -0
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_SCRIPT_TRANSFORM_CONFIG, SCRIPT_TRANSFORM_LANGUAGES } from "../config/config.js";
|
|
2
|
-
export const SCRIPT_SANDBOX_ADAPTER_CONTRACT_VERSION = 1;
|
|
3
|
-
export const SCRIPT_SANDBOX_REQUIRED_PROOFS = [
|
|
4
|
-
"env_access_denied",
|
|
5
|
-
"home_access_denied",
|
|
6
|
-
"repo_access_denied",
|
|
7
|
-
"vault_access_denied",
|
|
8
|
-
"network_access_denied",
|
|
9
|
-
"input_read_only",
|
|
10
|
-
"output_escape_denied",
|
|
11
|
-
"stdout_stderr_bounded",
|
|
12
|
-
"timeout_enforced",
|
|
13
|
-
];
|
|
14
|
-
export const SCRIPT_SANDBOX_PROOF_FIXTURES = [
|
|
15
|
-
{
|
|
16
|
-
proof: "env_access_denied",
|
|
17
|
-
description: "Guest code attempts to read ambient environment variables.",
|
|
18
|
-
expected: "The adapter exposes no ambient environment and no secret-bearing host variables.",
|
|
19
|
-
adapterAssertion:
|
|
20
|
-
"Do not forward host env; if a runtime requires env, provide only fixed non-secret adapter values.",
|
|
21
|
-
programs: {
|
|
22
|
-
javascript:
|
|
23
|
-
"writeText(typeof process === 'undefined' ? String(globalThis.env ?? '') : JSON.stringify(process.env));",
|
|
24
|
-
python: "import os\nprint(dict(os.environ))",
|
|
25
|
-
jq: "env",
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
proof: "home_access_denied",
|
|
30
|
-
description: "Guest code attempts to read common home-directory secrets.",
|
|
31
|
-
expected: "The adapter denies home directory access and returns bounded failure output.",
|
|
32
|
-
adapterAssertion: "Do not mount the user's home directory or host credential paths.",
|
|
33
|
-
programs: {
|
|
34
|
-
javascript:
|
|
35
|
-
"const fs = globalThis.require?.('node:fs'); writeText(fs ? fs.readFileSync('/home/user/.ssh/id_rsa', 'utf8') : 'fs unavailable');",
|
|
36
|
-
python: "from pathlib import Path\nprint(Path.home())\nprint(Path('~/.ssh/id_rsa').expanduser().read_text())",
|
|
37
|
-
jq: 'include "home_escape"; .',
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
proof: "repo_access_denied",
|
|
42
|
-
description: "Guest code attempts to read repo files outside mounted vault-source inputs.",
|
|
43
|
-
expected: "The adapter denies repo-root access unless repo content was explicitly captured into vault input.",
|
|
44
|
-
adapterAssertion: "Do not mount the repo root; mount copied input files only.",
|
|
45
|
-
programs: {
|
|
46
|
-
javascript:
|
|
47
|
-
"const fs = globalThis.require?.('node:fs'); writeText(fs ? fs.readFileSync('/workspace/package.json', 'utf8') : 'fs unavailable');",
|
|
48
|
-
python: "from pathlib import Path\nprint(Path('/workspace/package.json').read_text())",
|
|
49
|
-
jq: 'include "repo_escape"; .',
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
proof: "vault_access_denied",
|
|
54
|
-
description: "Guest code attempts to read Freeflow vault records directly instead of copied inputs.",
|
|
55
|
-
expected: "The adapter denies direct vault-root access.",
|
|
56
|
-
adapterAssertion: "Never mount the vault root; copy selected source streams into the sandbox input surface.",
|
|
57
|
-
programs: {
|
|
58
|
-
javascript:
|
|
59
|
-
"const fs = globalThis.require?.('node:fs'); writeText(fs ? fs.readdirSync('/vault').join('\\n') : 'fs unavailable');",
|
|
60
|
-
python: "from pathlib import Path\nprint(list(Path('/vault').glob('**/*'))) ",
|
|
61
|
-
jq: 'include "vault_escape"; .',
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
proof: "network_access_denied",
|
|
66
|
-
description: "Guest code attempts outbound HTTP/DNS/network access.",
|
|
67
|
-
expected: "The adapter provides no fetch/socket/network capability and outbound attempts fail boundedly.",
|
|
68
|
-
adapterAssertion:
|
|
69
|
-
"Disable fetch/network host APIs and use a runtime/container policy that denies outbound network.",
|
|
70
|
-
programs: {
|
|
71
|
-
javascript:
|
|
72
|
-
"if (typeof fetch === 'undefined') { writeText('fetch unavailable'); } else { throw new Error('fetch exposed'); }",
|
|
73
|
-
python: "import urllib.request\nprint(urllib.request.urlopen('https://example.com', timeout=1).read())",
|
|
74
|
-
jq: 'def fetch($url): error("network unavailable"); fetch("https://example.com")',
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
proof: "input_read_only",
|
|
79
|
-
description: "Guest code attempts to mutate mounted input files.",
|
|
80
|
-
expected: "The adapter keeps input files read-only or presents immutable virtual input helpers.",
|
|
81
|
-
adapterAssertion: "Mount input as read-only or expose read-only host helpers; mutation attempts must fail.",
|
|
82
|
-
programs: {
|
|
83
|
-
javascript:
|
|
84
|
-
"const fs = globalThis.require?.('node:fs'); if (fs) { fs.writeFileSync('/input/test_log.txt', 'mutated'); writeText('mutated'); } else { writeText('fs unavailable'); }",
|
|
85
|
-
python: "from pathlib import Path\nPath('/input/test_log.txt').write_text('mutated')\nprint('mutated')",
|
|
86
|
-
jq: 'include "input_mutation_escape"; .',
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
proof: "output_escape_denied",
|
|
91
|
-
description: "Guest code attempts to write outside output/work or create symlink escapes.",
|
|
92
|
-
expected: "The adapter collects only regular bounded files under output and rejects/ignores escapes.",
|
|
93
|
-
adapterAssertion: "Write collection must resolve real paths and ignore symlinks or files outside output.",
|
|
94
|
-
programs: {
|
|
95
|
-
javascript:
|
|
96
|
-
"const fs = globalThis.require?.('node:fs'); if (fs) { fs.symlinkSync('/etc/passwd', '/output/result.txt'); writeText('escape attempted'); } else { writeText('fs unavailable'); }",
|
|
97
|
-
python:
|
|
98
|
-
"from pathlib import Path\nPath('/output/result.txt').symlink_to('/etc/passwd')\nprint('escape attempted')",
|
|
99
|
-
jq: 'include "output_escape"; .',
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
proof: "stdout_stderr_bounded",
|
|
104
|
-
description: "Guest code floods stdout and stderr.",
|
|
105
|
-
expected: "The adapter enforces stdout/stderr/output byte caps before routing or context injection.",
|
|
106
|
-
adapterAssertion:
|
|
107
|
-
"Capture raw output into bounded buffers and mark over-cap results as partial/failed without full exact recovery claims.",
|
|
108
|
-
programs: {
|
|
109
|
-
javascript: "for (let i = 0; i < 1000; i++) { console.log('x'.repeat(100)); console.error('e'.repeat(100)); }",
|
|
110
|
-
python: "import sys\nfor _ in range(1000):\n print('x' * 100)\n print('e' * 100, file=sys.stderr)",
|
|
111
|
-
jq: 'range(0; 1000) | ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"), ("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" | debug | empty)',
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
proof: "timeout_enforced",
|
|
116
|
-
description: "Guest code loops or runs longer than the configured wall-clock timeout.",
|
|
117
|
-
expected:
|
|
118
|
-
"The adapter terminates execution at or before the configured timeout and returns structured timeout failure.",
|
|
119
|
-
adapterAssertion:
|
|
120
|
-
"Use runtime fuel/interrupts, process timeout, or container kill semantics that cannot be bypassed by guest code.",
|
|
121
|
-
programs: {
|
|
122
|
-
javascript: "while (true) {}",
|
|
123
|
-
python: "while True:\n pass",
|
|
124
|
-
jq: "def loop: loop; loop",
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
];
|
|
128
|
-
export function scriptSandboxProofFixturesForLanguage(language) {
|
|
129
|
-
return SCRIPT_SANDBOX_PROOF_FIXTURES.map((fixture) => ({
|
|
130
|
-
proof: fixture.proof,
|
|
131
|
-
description: fixture.description,
|
|
132
|
-
expected: fixture.expected,
|
|
133
|
-
adapterAssertion: fixture.adapterAssertion,
|
|
134
|
-
program: fixture.programs[language],
|
|
135
|
-
}));
|
|
136
|
-
}
|
|
137
|
-
export const SCRIPT_SANDBOX_CANDIDATE_MECHANISMS = [
|
|
138
|
-
{
|
|
139
|
-
id: "node-vm",
|
|
140
|
-
languages: ["javascript"],
|
|
141
|
-
status: "rejected",
|
|
142
|
-
reason:
|
|
143
|
-
"Node vm or an unsandboxed Node subprocess does not isolate filesystem, environment, child process, or network access to the Freeflow contract.",
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
id: "plain-python-subprocess",
|
|
147
|
-
languages: ["python"],
|
|
148
|
-
status: "rejected",
|
|
149
|
-
reason:
|
|
150
|
-
"A Python subprocess without OS isolation can access ambient filesystem, environment, imports, and network.",
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
id: "plain-jq-subprocess",
|
|
154
|
-
languages: ["jq"],
|
|
155
|
-
status: "rejected",
|
|
156
|
-
reason:
|
|
157
|
-
"A jq subprocess still needs an OS sandbox before Freeflow can prove filesystem, output, and network boundaries.",
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
id: "os-sandbox-adapter",
|
|
161
|
-
languages: [...SCRIPT_TRANSFORM_LANGUAGES],
|
|
162
|
-
status: "candidate_unproven",
|
|
163
|
-
reason:
|
|
164
|
-
"An OS-level sandbox may be acceptable only after an adapter implementation passes all required adversarial proofs on the target platform.",
|
|
165
|
-
},
|
|
166
|
-
];
|
|
167
|
-
export async function probeScriptSandboxAdapters(options = {}) {
|
|
168
|
-
const config = cloneScriptTransformConfig(options.config ?? DEFAULT_SCRIPT_TRANSFORM_CONFIG);
|
|
169
|
-
const adapters = options.adapters ?? [];
|
|
170
|
-
const statuses = [];
|
|
171
|
-
for (const language of config.languages) {
|
|
172
|
-
statuses.push(await probeLanguage(language, config, adapters));
|
|
173
|
-
}
|
|
174
|
-
const availableLanguages = statuses
|
|
175
|
-
.filter((status) => status.status === "available")
|
|
176
|
-
.map((status) => status.language);
|
|
177
|
-
const unavailableLanguages = statuses.filter((status) => status.status === "unavailable");
|
|
178
|
-
return {
|
|
179
|
-
contractVersion: SCRIPT_SANDBOX_ADAPTER_CONTRACT_VERSION,
|
|
180
|
-
sandbox: config.sandbox,
|
|
181
|
-
network: config.network,
|
|
182
|
-
configuredLanguages: [...config.languages],
|
|
183
|
-
adapterAvailable: availableLanguages.length > 0,
|
|
184
|
-
adapterStatus: availableLanguages.length > 0 ? "available" : "unavailable",
|
|
185
|
-
availableLanguages,
|
|
186
|
-
unavailableLanguages,
|
|
187
|
-
languages: statuses,
|
|
188
|
-
registeredAdapters: adapters.map((adapter) => ({
|
|
189
|
-
id: adapter.id,
|
|
190
|
-
version: adapter.version,
|
|
191
|
-
languages: [...adapter.languages],
|
|
192
|
-
})),
|
|
193
|
-
requiredProofs: [...SCRIPT_SANDBOX_REQUIRED_PROOFS],
|
|
194
|
-
candidateMechanisms: SCRIPT_SANDBOX_CANDIDATE_MECHANISMS.map((candidate) => ({
|
|
195
|
-
...candidate,
|
|
196
|
-
languages: [...candidate.languages],
|
|
197
|
-
})),
|
|
198
|
-
notes: [
|
|
199
|
-
"Script transform has no unsandboxed fallback.",
|
|
200
|
-
"Languages remain unavailable until a registered adapter passes every required proof.",
|
|
201
|
-
"Adapter availability alone does not execute scripts while scriptTransform.enabled is false.",
|
|
202
|
-
],
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
export async function selectScriptSandboxAdapter(language, config, adapters = []) {
|
|
206
|
-
const status = await probeLanguage(language, cloneScriptTransformConfig(config), adapters);
|
|
207
|
-
if (status.status !== "available" || !status.adapterId) {
|
|
208
|
-
return { ok: false, status };
|
|
209
|
-
}
|
|
210
|
-
const adapter = adapters.find((candidate) => candidate.id === status.adapterId);
|
|
211
|
-
if (!adapter) {
|
|
212
|
-
return {
|
|
213
|
-
ok: false,
|
|
214
|
-
status: {
|
|
215
|
-
...status,
|
|
216
|
-
status: "unavailable",
|
|
217
|
-
reason: `Adapter ${status.adapterId} passed probing but is not registered for execution.`,
|
|
218
|
-
failedProofs: [...SCRIPT_SANDBOX_REQUIRED_PROOFS],
|
|
219
|
-
},
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
return { ok: true, adapter, status };
|
|
223
|
-
}
|
|
224
|
-
async function probeLanguage(language, config, adapters) {
|
|
225
|
-
if (!config.languages.includes(language)) {
|
|
226
|
-
return unavailableLanguageStatus(language, `Language ${language} is not enabled by scriptTransform.languages.`);
|
|
227
|
-
}
|
|
228
|
-
const matchingAdapters = adapters.filter((adapter) => adapter.languages.includes(language));
|
|
229
|
-
if (matchingAdapters.length === 0) {
|
|
230
|
-
return unavailableLanguageStatus(
|
|
231
|
-
language,
|
|
232
|
-
`No script transform sandbox adapter is registered for language ${language}.`,
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
const failedStatuses = [];
|
|
236
|
-
for (const adapter of matchingAdapters) {
|
|
237
|
-
try {
|
|
238
|
-
const probe = await adapter.probe(language, config);
|
|
239
|
-
if (probe.status === "available" && hasEveryRequiredProof(probe.passedProofs)) {
|
|
240
|
-
const status = {
|
|
241
|
-
language,
|
|
242
|
-
status: "available",
|
|
243
|
-
reason: probe.reason,
|
|
244
|
-
adapterId: adapter.id,
|
|
245
|
-
adapterVersion: adapter.version,
|
|
246
|
-
requiredProofs: [...SCRIPT_SANDBOX_REQUIRED_PROOFS],
|
|
247
|
-
passedProofs: [...SCRIPT_SANDBOX_REQUIRED_PROOFS],
|
|
248
|
-
failedProofs: [],
|
|
249
|
-
};
|
|
250
|
-
if (probe.runtime) {
|
|
251
|
-
status.runtime = probe.runtime;
|
|
252
|
-
}
|
|
253
|
-
return status;
|
|
254
|
-
}
|
|
255
|
-
const failedProofs = missingRequiredProofs(probe.passedProofs, probe.failedProofs);
|
|
256
|
-
const status = {
|
|
257
|
-
language,
|
|
258
|
-
status: "unavailable",
|
|
259
|
-
reason: probe.reason || `Adapter ${adapter.id} did not pass every required proof for ${language}.`,
|
|
260
|
-
adapterId: adapter.id,
|
|
261
|
-
adapterVersion: adapter.version,
|
|
262
|
-
requiredProofs: [...SCRIPT_SANDBOX_REQUIRED_PROOFS],
|
|
263
|
-
passedProofs: dedupeProofs(probe.passedProofs),
|
|
264
|
-
failedProofs,
|
|
265
|
-
};
|
|
266
|
-
if (probe.runtime) {
|
|
267
|
-
status.runtime = probe.runtime;
|
|
268
|
-
}
|
|
269
|
-
failedStatuses.push(status);
|
|
270
|
-
} catch (error) {
|
|
271
|
-
failedStatuses.push({
|
|
272
|
-
...unavailableLanguageStatus(
|
|
273
|
-
language,
|
|
274
|
-
`Adapter ${adapter.id} probe failed for ${language}: ${errorMessage(error)}`,
|
|
275
|
-
),
|
|
276
|
-
adapterId: adapter.id,
|
|
277
|
-
adapterVersion: adapter.version,
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
const bestFailure = bestUnavailableStatus(failedStatuses);
|
|
282
|
-
if (bestFailure) {
|
|
283
|
-
return {
|
|
284
|
-
...bestFailure,
|
|
285
|
-
reason: `No script transform sandbox adapter passed required proofs for language ${language}. Best failure from ${bestFailure.adapterId ?? "unknown adapter"}: ${bestFailure.reason}`,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
return unavailableLanguageStatus(
|
|
289
|
-
language,
|
|
290
|
-
`No script transform sandbox adapter passed required proofs for language ${language}.`,
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
function bestUnavailableStatus(statuses) {
|
|
294
|
-
let best;
|
|
295
|
-
for (const status of statuses) {
|
|
296
|
-
if (!best || status.passedProofs.length > best.passedProofs.length) {
|
|
297
|
-
best = status;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
return best;
|
|
301
|
-
}
|
|
302
|
-
function unavailableLanguageStatus(language, reason) {
|
|
303
|
-
return {
|
|
304
|
-
language,
|
|
305
|
-
status: "unavailable",
|
|
306
|
-
reason,
|
|
307
|
-
requiredProofs: [...SCRIPT_SANDBOX_REQUIRED_PROOFS],
|
|
308
|
-
passedProofs: [],
|
|
309
|
-
failedProofs: [...SCRIPT_SANDBOX_REQUIRED_PROOFS],
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
function hasEveryRequiredProof(proofs) {
|
|
313
|
-
return SCRIPT_SANDBOX_REQUIRED_PROOFS.every((proof) => proofs.includes(proof));
|
|
314
|
-
}
|
|
315
|
-
function missingRequiredProofs(passedProofs, failedProofs = []) {
|
|
316
|
-
const missing = SCRIPT_SANDBOX_REQUIRED_PROOFS.filter((proof) => !passedProofs.includes(proof));
|
|
317
|
-
return dedupeProofs([...failedProofs, ...missing]);
|
|
318
|
-
}
|
|
319
|
-
function dedupeProofs(proofs) {
|
|
320
|
-
const result = [];
|
|
321
|
-
for (const proof of proofs) {
|
|
322
|
-
if (SCRIPT_SANDBOX_REQUIRED_PROOFS.includes(proof) && !result.includes(proof)) {
|
|
323
|
-
result.push(proof);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return result;
|
|
327
|
-
}
|
|
328
|
-
function cloneScriptTransformConfig(config) {
|
|
329
|
-
return {
|
|
330
|
-
...config,
|
|
331
|
-
languages: [...config.languages],
|
|
332
|
-
limits: { ...config.limits },
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
function errorMessage(error) {
|
|
336
|
-
return error instanceof Error ? error.message : String(error);
|
|
337
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import type { ScriptTransformLanguage } from "../config/types.js";
|
|
3
|
-
import { type ScriptTransformAdapterLanguage } from "../sandbox/adapter-roots.js";
|
|
4
|
-
interface InstallerOptions {
|
|
5
|
-
command: "install" | "status";
|
|
6
|
-
home: string;
|
|
7
|
-
configPath?: string;
|
|
8
|
-
writeConfig: boolean;
|
|
9
|
-
languages: ScriptTransformAdapterLanguage[];
|
|
10
|
-
json: boolean;
|
|
11
|
-
}
|
|
12
|
-
interface InstallReport {
|
|
13
|
-
adapterHome: string;
|
|
14
|
-
installed: boolean;
|
|
15
|
-
installSpecs: string[];
|
|
16
|
-
envFile: string;
|
|
17
|
-
configPath?: string;
|
|
18
|
-
configUpdated: boolean;
|
|
19
|
-
configuredLanguages: ScriptTransformLanguage[];
|
|
20
|
-
availableLanguages: ScriptTransformLanguage[];
|
|
21
|
-
unavailableLanguages: Array<{
|
|
22
|
-
language: string;
|
|
23
|
-
reason?: string;
|
|
24
|
-
}>;
|
|
25
|
-
notes: string[];
|
|
26
|
-
}
|
|
27
|
-
export declare function installOrInspect(options: InstallerOptions): Promise<InstallReport>;
|
|
28
|
-
export declare function enableScriptTransformConfig(
|
|
29
|
-
configPath: string,
|
|
30
|
-
languages: readonly ScriptTransformLanguage[],
|
|
31
|
-
): Promise<void>;
|
|
32
|
-
export {};
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { spawn } from "node:child_process";
|
|
3
|
-
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
|
-
import { dirname, resolve } from "node:path";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
import { DEFAULT_SCRIPT_TRANSFORM_CONFIG, SCRIPT_TRANSFORM_LANGUAGES } from "../config/config.js";
|
|
7
|
-
import {
|
|
8
|
-
defaultScriptTransformAdaptersHome,
|
|
9
|
-
scriptTransformAdapterEnvExports,
|
|
10
|
-
scriptTransformAdapterInstallSpecs,
|
|
11
|
-
} from "../sandbox/adapter-roots.js";
|
|
12
|
-
import { discoverEryxPythonSandboxAdaptersFromEnv } from "../sandbox/eryx-python-adapter.js";
|
|
13
|
-
import { discoverJqWasmSandboxAdaptersFromEnv } from "../sandbox/jq-wasm-adapter.js";
|
|
14
|
-
import { discoverQuickJsWasiSandboxAdaptersFromEnv } from "../sandbox/quickjs-wasi-adapter.js";
|
|
15
|
-
import { probeScriptSandboxAdapters } from "../sandbox/script-sandbox.js";
|
|
16
|
-
const DEFAULT_LANGUAGES = ["javascript", "jq", "python"];
|
|
17
|
-
async function main(argv) {
|
|
18
|
-
const options = parseArgs(argv);
|
|
19
|
-
const report = await installOrInspect(options);
|
|
20
|
-
if (options.json) {
|
|
21
|
-
console.log(JSON.stringify(report, null, 2));
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
printHumanReport(report);
|
|
25
|
-
}
|
|
26
|
-
export async function installOrInspect(options) {
|
|
27
|
-
const adapterHome = resolve(options.home);
|
|
28
|
-
const installSpecs = scriptTransformAdapterInstallSpecs(options.languages);
|
|
29
|
-
if (options.command === "install") {
|
|
30
|
-
await installAdapterPackages(adapterHome, installSpecs);
|
|
31
|
-
} else {
|
|
32
|
-
await mkdir(adapterHome, { recursive: true });
|
|
33
|
-
}
|
|
34
|
-
const envFile = await writeAdapterEnvFile(adapterHome);
|
|
35
|
-
const probe = await probeInstalledAdapters(options.languages);
|
|
36
|
-
const availableLanguages = probe.availableLanguages.filter(isScriptTransformLanguage);
|
|
37
|
-
const unavailableLanguages = probe.unavailableLanguages.map((status) => ({
|
|
38
|
-
language: status.language,
|
|
39
|
-
...(status.reason !== undefined ? { reason: status.reason } : {}),
|
|
40
|
-
}));
|
|
41
|
-
let configUpdated = false;
|
|
42
|
-
const configuredLanguages = availableLanguages;
|
|
43
|
-
if (options.command === "install" && options.writeConfig && options.configPath && configuredLanguages.length > 0) {
|
|
44
|
-
await enableScriptTransformConfig(resolve(options.configPath), configuredLanguages);
|
|
45
|
-
configUpdated = true;
|
|
46
|
-
}
|
|
47
|
-
const notes = [
|
|
48
|
-
"Adapters are installed in a user-global Freeflow cache, not in the repo.",
|
|
49
|
-
"Freeflow auto-discovers this global cache; the env file is provided for shells or hosts that prefer explicit roots.",
|
|
50
|
-
];
|
|
51
|
-
if (unavailableLanguages.some((entry) => entry.language === "python")) {
|
|
52
|
-
notes.push(
|
|
53
|
-
"Python/Eryx uses a child Node process launched with --experimental-wasm-jspi; if this Node binary cannot run that flag, setup reports Python unavailable instead of enabling it.",
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
if (configuredLanguages.length === 0) {
|
|
57
|
-
notes.push("No adapter passed sandbox proofs, so scriptTransform config was not enabled.");
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
adapterHome,
|
|
61
|
-
installed: options.command === "install",
|
|
62
|
-
installSpecs,
|
|
63
|
-
envFile,
|
|
64
|
-
...(options.configPath !== undefined ? { configPath: resolve(options.configPath) } : {}),
|
|
65
|
-
configUpdated,
|
|
66
|
-
configuredLanguages,
|
|
67
|
-
availableLanguages,
|
|
68
|
-
unavailableLanguages,
|
|
69
|
-
notes,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
async function installAdapterPackages(adapterHome, installSpecs) {
|
|
73
|
-
await mkdir(adapterHome, { recursive: true });
|
|
74
|
-
const packageJson = resolve(adapterHome, "package.json");
|
|
75
|
-
if (!(await exists(packageJson))) {
|
|
76
|
-
await writeFile(packageJson, JSON.stringify({ private: true, type: "module" }, null, 2) + "\n", "utf8");
|
|
77
|
-
}
|
|
78
|
-
await run("npm", ["install", "--no-fund", "--no-audit", ...installSpecs], adapterHome);
|
|
79
|
-
}
|
|
80
|
-
async function writeAdapterEnvFile(adapterHome) {
|
|
81
|
-
const envFile = resolve(adapterHome, "freeflow-adapter-env.sh");
|
|
82
|
-
const exports = scriptTransformAdapterEnvExports(adapterHome);
|
|
83
|
-
const lines = [
|
|
84
|
-
"# Source this file before launching hosts that do not use Freeflow global adapter auto-discovery.",
|
|
85
|
-
...Object.entries(exports).map(([key, value]) => `export ${key}=${shellQuote(value)}`),
|
|
86
|
-
"",
|
|
87
|
-
];
|
|
88
|
-
await writeFile(envFile, lines.join("\n"), "utf8");
|
|
89
|
-
return envFile;
|
|
90
|
-
}
|
|
91
|
-
async function probeInstalledAdapters(languages) {
|
|
92
|
-
const adapters = [
|
|
93
|
-
...(languages.includes("javascript") ? await discoverQuickJsWasiSandboxAdaptersFromEnv() : []),
|
|
94
|
-
...(languages.includes("jq") ? await discoverJqWasmSandboxAdaptersFromEnv() : []),
|
|
95
|
-
...(languages.includes("python") ? await discoverEryxPythonSandboxAdaptersFromEnv() : []),
|
|
96
|
-
];
|
|
97
|
-
return probeScriptSandboxAdapters({
|
|
98
|
-
config: {
|
|
99
|
-
...DEFAULT_SCRIPT_TRANSFORM_CONFIG,
|
|
100
|
-
enabled: true,
|
|
101
|
-
languages: languages.filter(isScriptTransformLanguage),
|
|
102
|
-
},
|
|
103
|
-
adapters,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
export async function enableScriptTransformConfig(configPath, languages) {
|
|
107
|
-
await mkdir(dirname(configPath), { recursive: true });
|
|
108
|
-
const parsed = await readJsonObject(configPath);
|
|
109
|
-
if (parsed.defaultMode === undefined) {
|
|
110
|
-
parsed.defaultMode = "workflow";
|
|
111
|
-
}
|
|
112
|
-
const outputRouter = isRecord(parsed.outputRouter) ? { ...parsed.outputRouter } : {};
|
|
113
|
-
const existingScriptTransform = isRecord(outputRouter.scriptTransform)
|
|
114
|
-
? outputRouter.scriptTransform
|
|
115
|
-
: isRecord(parsed.scriptTransform)
|
|
116
|
-
? parsed.scriptTransform
|
|
117
|
-
: {};
|
|
118
|
-
outputRouter.enabled = true;
|
|
119
|
-
outputRouter.scriptTransform = {
|
|
120
|
-
...existingScriptTransform,
|
|
121
|
-
enabled: true,
|
|
122
|
-
languages: [...languages],
|
|
123
|
-
};
|
|
124
|
-
parsed.outputRouter = outputRouter;
|
|
125
|
-
delete parsed.scriptTransform;
|
|
126
|
-
await writeFile(configPath, JSON.stringify(parsed, null, 2) + "\n", "utf8");
|
|
127
|
-
}
|
|
128
|
-
async function readJsonObject(path) {
|
|
129
|
-
try {
|
|
130
|
-
const raw = await readFile(path, "utf8");
|
|
131
|
-
const parsed = JSON.parse(raw);
|
|
132
|
-
return isRecord(parsed) ? parsed : {};
|
|
133
|
-
} catch (error) {
|
|
134
|
-
if (isNodeError(error) && error.code === "ENOENT") {
|
|
135
|
-
return {};
|
|
136
|
-
}
|
|
137
|
-
throw error;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
function parseArgs(argv) {
|
|
141
|
-
let command = "install";
|
|
142
|
-
let home = defaultScriptTransformAdaptersHome();
|
|
143
|
-
let configPath;
|
|
144
|
-
let writeConfig = false;
|
|
145
|
-
let languages = [...DEFAULT_LANGUAGES];
|
|
146
|
-
let json = false;
|
|
147
|
-
const args = [...argv];
|
|
148
|
-
if (args[0] === "install" || args[0] === "status") {
|
|
149
|
-
command = args.shift();
|
|
150
|
-
}
|
|
151
|
-
for (let index = 0; index < args.length; index += 1) {
|
|
152
|
-
const arg = args[index];
|
|
153
|
-
if (arg === "--home") {
|
|
154
|
-
home = requiredValue(args, ++index, arg);
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
if (arg === "--config") {
|
|
158
|
-
configPath = requiredValue(args, ++index, arg);
|
|
159
|
-
writeConfig = true;
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
if (arg === "--no-config") {
|
|
163
|
-
writeConfig = false;
|
|
164
|
-
configPath = undefined;
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
if (arg === "--languages") {
|
|
168
|
-
languages = parseLanguages(requiredValue(args, ++index, arg));
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
if (arg === "--json") {
|
|
172
|
-
json = true;
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
if (arg === "--help" || arg === "-h") {
|
|
176
|
-
printUsageAndExit();
|
|
177
|
-
}
|
|
178
|
-
throw new Error(`Unknown argument: ${arg}`);
|
|
179
|
-
}
|
|
180
|
-
const result = { command, home, writeConfig, languages, json };
|
|
181
|
-
if (configPath !== undefined) {
|
|
182
|
-
result.configPath = configPath;
|
|
183
|
-
}
|
|
184
|
-
return result;
|
|
185
|
-
}
|
|
186
|
-
function parseLanguages(value) {
|
|
187
|
-
const requested = value
|
|
188
|
-
.split(",")
|
|
189
|
-
.map((entry) => entry.trim())
|
|
190
|
-
.filter(Boolean);
|
|
191
|
-
const invalid = requested.filter((entry) => !isScriptTransformAdapterLanguage(entry));
|
|
192
|
-
if (invalid.length > 0) {
|
|
193
|
-
throw new Error(`Unsupported script transform adapter language(s): ${invalid.join(", ")}`);
|
|
194
|
-
}
|
|
195
|
-
return [...new Set(requested)];
|
|
196
|
-
}
|
|
197
|
-
function isScriptTransformLanguage(value) {
|
|
198
|
-
return SCRIPT_TRANSFORM_LANGUAGES.includes(value);
|
|
199
|
-
}
|
|
200
|
-
function isScriptTransformAdapterLanguage(value) {
|
|
201
|
-
return value === "javascript" || value === "jq" || value === "python";
|
|
202
|
-
}
|
|
203
|
-
function requiredValue(args, index, flag) {
|
|
204
|
-
const value = args[index];
|
|
205
|
-
if (!value) {
|
|
206
|
-
throw new Error(`${flag} requires a value.`);
|
|
207
|
-
}
|
|
208
|
-
return value;
|
|
209
|
-
}
|
|
210
|
-
async function run(command, args, cwd) {
|
|
211
|
-
return new Promise((resolvePromise, reject) => {
|
|
212
|
-
const child = spawn(command, [...args], { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
213
|
-
let stdout = "";
|
|
214
|
-
let stderr = "";
|
|
215
|
-
child.stdout.setEncoding("utf8");
|
|
216
|
-
child.stderr.setEncoding("utf8");
|
|
217
|
-
child.stdout.on("data", (chunk) => {
|
|
218
|
-
stdout += chunk;
|
|
219
|
-
});
|
|
220
|
-
child.stderr.on("data", (chunk) => {
|
|
221
|
-
stderr += chunk;
|
|
222
|
-
});
|
|
223
|
-
child.on("error", reject);
|
|
224
|
-
child.on("close", (code) => {
|
|
225
|
-
if (code === 0) {
|
|
226
|
-
resolvePromise({ stdout, stderr });
|
|
227
|
-
} else {
|
|
228
|
-
reject(new Error(`${command} ${args.join(" ")} failed with exitCode=${code}. ${stderr || stdout}`));
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
async function exists(path) {
|
|
234
|
-
try {
|
|
235
|
-
await access(path);
|
|
236
|
-
return true;
|
|
237
|
-
} catch {
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
function isRecord(value) {
|
|
242
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
243
|
-
}
|
|
244
|
-
function isNodeError(error) {
|
|
245
|
-
return typeof error === "object" && error !== null && "code" in error;
|
|
246
|
-
}
|
|
247
|
-
function shellQuote(value) {
|
|
248
|
-
return `'${value.replaceAll("'", `'\\''`)}'`;
|
|
249
|
-
}
|
|
250
|
-
function printHumanReport(report) {
|
|
251
|
-
console.log(`Freeflow script transform adapters: ${report.installed ? "installed" : "status"}`);
|
|
252
|
-
console.log(`adapterHome=${report.adapterHome}`);
|
|
253
|
-
console.log(`envFile=${report.envFile}`);
|
|
254
|
-
console.log(`available=${report.availableLanguages.join(",") || "none"}`);
|
|
255
|
-
if (report.configPath) {
|
|
256
|
-
console.log(
|
|
257
|
-
`config=${report.configPath} updated=${String(report.configUpdated)} languages=${report.configuredLanguages.join(",") || "none"}`,
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
for (const unavailable of report.unavailableLanguages) {
|
|
261
|
-
console.log(`unavailable ${unavailable.language}: ${unavailable.reason ?? "unknown"}`);
|
|
262
|
-
}
|
|
263
|
-
report.notes.forEach((note) => console.log(`note: ${note}`));
|
|
264
|
-
}
|
|
265
|
-
function printUsageAndExit() {
|
|
266
|
-
console.log(
|
|
267
|
-
`Usage: node router/dist/setup/script-transform-adapters.js [install|status] [--config .freeflow/config.json] [--home PATH] [--languages javascript,jq,python] [--json]\n\nInstalls Freeflow script transform adapters into a user-global cache and optionally enables scriptTransform for proof-passing languages in a repo config.`,
|
|
268
|
-
);
|
|
269
|
-
process.exit(0);
|
|
270
|
-
}
|
|
271
|
-
const isCli = process.argv[1] ? resolve(process.argv[1]) === fileURLToPath(import.meta.url) : false;
|
|
272
|
-
if (isCli) {
|
|
273
|
-
main(process.argv.slice(2)).catch((error) => {
|
|
274
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
275
|
-
console.error(message);
|
|
276
|
-
process.exit(1);
|
|
277
|
-
});
|
|
278
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { type HostCommandRunner } from "./run.js";
|
|
2
|
-
import type {
|
|
3
|
-
BatchRoutedResult,
|
|
4
|
-
BatchStepKind,
|
|
5
|
-
PreserveMode,
|
|
6
|
-
RouterThresholds,
|
|
7
|
-
ScriptTransformConfig,
|
|
8
|
-
StoragePolicyMode,
|
|
9
|
-
VaultRetentionPolicy,
|
|
10
|
-
} from "../config/types.js";
|
|
11
|
-
import type { ScriptSandboxAdapter } from "../sandbox/script-sandbox.js";
|
|
12
|
-
export interface FreeflowBatchStepInput {
|
|
13
|
-
id?: string;
|
|
14
|
-
kind: BatchStepKind;
|
|
15
|
-
input: Record<string, unknown>;
|
|
16
|
-
}
|
|
17
|
-
export interface FreeflowBatchOptions {
|
|
18
|
-
sessionId: string;
|
|
19
|
-
steps: readonly FreeflowBatchStepInput[];
|
|
20
|
-
concurrency?: number;
|
|
21
|
-
preserve?: PreserveMode;
|
|
22
|
-
vaultRoot?: string;
|
|
23
|
-
vaultRetention?: VaultRetentionPolicy;
|
|
24
|
-
thresholds?: Partial<RouterThresholds>;
|
|
25
|
-
scriptTransform?: ScriptTransformConfig;
|
|
26
|
-
scriptSandboxAdapters?: readonly ScriptSandboxAdapter[];
|
|
27
|
-
storagePolicy?: StoragePolicyMode;
|
|
28
|
-
queries?: readonly string[];
|
|
29
|
-
}
|
|
30
|
-
export declare function freeflowBatch(
|
|
31
|
-
options: FreeflowBatchOptions,
|
|
32
|
-
runner: HostCommandRunner,
|
|
33
|
-
): Promise<BatchRoutedResult>;
|