@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,334 +0,0 @@
|
|
|
1
|
-
import { realpath, readdir, stat } from "node:fs/promises";
|
|
2
|
-
import { homedir, tmpdir } from "node:os";
|
|
3
|
-
import { basename, isAbsolute, parse, relative, resolve } from "node:path";
|
|
4
|
-
import { matchesGeneratedPathGlob } from "../repo/repo-traversal.js";
|
|
5
|
-
const BROAD_SCAN_MAX_FILE_BYTES = 1024 * 1024;
|
|
6
|
-
const LOCAL_SCAN_MAX_DIRECTORIES = 2_000;
|
|
7
|
-
const LOCAL_SCAN_MAX_FILES = 10_000;
|
|
8
|
-
const LOCAL_SCAN_MAX_TOTAL_BYTES = 64 * 1024 * 1024;
|
|
9
|
-
const BROAD_SKIP_DIRS = new Set([
|
|
10
|
-
".git",
|
|
11
|
-
"node_modules",
|
|
12
|
-
"dist",
|
|
13
|
-
"build",
|
|
14
|
-
"out",
|
|
15
|
-
".next",
|
|
16
|
-
".nuxt",
|
|
17
|
-
"coverage",
|
|
18
|
-
"target",
|
|
19
|
-
"graphify-out",
|
|
20
|
-
".cache",
|
|
21
|
-
".tmp",
|
|
22
|
-
"tmp",
|
|
23
|
-
"temp",
|
|
24
|
-
"logs",
|
|
25
|
-
"generated",
|
|
26
|
-
]);
|
|
27
|
-
const SECRET_DIRS = new Set([".aws", ".azure", ".docker", ".gnupg", ".kube", ".password-store", ".ssh"]);
|
|
28
|
-
const BROAD_SKIP_FILE_EXTENSIONS = new Set([
|
|
29
|
-
".7z",
|
|
30
|
-
".avi",
|
|
31
|
-
".bin",
|
|
32
|
-
".bmp",
|
|
33
|
-
".br",
|
|
34
|
-
".class",
|
|
35
|
-
".db",
|
|
36
|
-
".dll",
|
|
37
|
-
".dylib",
|
|
38
|
-
".eot",
|
|
39
|
-
".exe",
|
|
40
|
-
".gif",
|
|
41
|
-
".gz",
|
|
42
|
-
".heic",
|
|
43
|
-
".icns",
|
|
44
|
-
".ico",
|
|
45
|
-
".jar",
|
|
46
|
-
".jpeg",
|
|
47
|
-
".jpg",
|
|
48
|
-
".mov",
|
|
49
|
-
".mp3",
|
|
50
|
-
".mp4",
|
|
51
|
-
".otf",
|
|
52
|
-
".parquet",
|
|
53
|
-
".pdf",
|
|
54
|
-
".png",
|
|
55
|
-
".pyc",
|
|
56
|
-
".rar",
|
|
57
|
-
".so",
|
|
58
|
-
".sqlite",
|
|
59
|
-
".sqlite3",
|
|
60
|
-
".tar",
|
|
61
|
-
".tgz",
|
|
62
|
-
".ttf",
|
|
63
|
-
".wasm",
|
|
64
|
-
".webm",
|
|
65
|
-
".webp",
|
|
66
|
-
".woff",
|
|
67
|
-
".woff2",
|
|
68
|
-
".zip",
|
|
69
|
-
".zst",
|
|
70
|
-
]);
|
|
71
|
-
const SECRET_FILE_NAMES = new Set([
|
|
72
|
-
".env",
|
|
73
|
-
".netrc",
|
|
74
|
-
".npmrc",
|
|
75
|
-
".pypirc",
|
|
76
|
-
"authorized_keys",
|
|
77
|
-
"credentials",
|
|
78
|
-
"credentials.json",
|
|
79
|
-
"id_dsa",
|
|
80
|
-
"id_ecdsa",
|
|
81
|
-
"id_ed25519",
|
|
82
|
-
"id_rsa",
|
|
83
|
-
"known_hosts",
|
|
84
|
-
]);
|
|
85
|
-
export async function collectLocalTextFileRefs(options) {
|
|
86
|
-
const root = await resolveLocalRoot(options.root);
|
|
87
|
-
const start = await resolveLocalRequestedPath(root, options.requestedPath);
|
|
88
|
-
const fileRefs = [];
|
|
89
|
-
const visitedDirectories = new Set();
|
|
90
|
-
const broadTraversal = !isExplicitRequestedPath(start.relativePath);
|
|
91
|
-
const budget = { directories: 0, files: 0, bytes: 0 };
|
|
92
|
-
await collectTextFileRefs({
|
|
93
|
-
root,
|
|
94
|
-
currentPath: start.absolutePath,
|
|
95
|
-
fileRefs,
|
|
96
|
-
broadTraversal,
|
|
97
|
-
visitedDirectories,
|
|
98
|
-
generatedPathGlobs: options.generatedPathGlobs ?? [],
|
|
99
|
-
budget,
|
|
100
|
-
});
|
|
101
|
-
return fileRefs;
|
|
102
|
-
}
|
|
103
|
-
export async function resolveLocalPath(root, requestedPath) {
|
|
104
|
-
const rootRealPath = await resolveLocalRoot(root);
|
|
105
|
-
return resolveLocalRequestedPath(rootRealPath, requestedPath);
|
|
106
|
-
}
|
|
107
|
-
async function resolveLocalRoot(root) {
|
|
108
|
-
if (typeof root !== "string" || root.trim().length === 0) {
|
|
109
|
-
throw new Error("Local source.root must be a non-empty absolute path.");
|
|
110
|
-
}
|
|
111
|
-
if (!isAbsolute(root)) {
|
|
112
|
-
throw new Error(`Local source.root must be an absolute path: ${root}`);
|
|
113
|
-
}
|
|
114
|
-
const rootRealPath = await realpath(resolve(root));
|
|
115
|
-
const rootStat = await stat(rootRealPath);
|
|
116
|
-
if (!rootStat.isDirectory()) {
|
|
117
|
-
throw new Error(`Local source.root must be a directory: ${root}`);
|
|
118
|
-
}
|
|
119
|
-
const broadRootReason = broadRootRejectionReason(rootRealPath);
|
|
120
|
-
if (broadRootReason) {
|
|
121
|
-
throw new Error(
|
|
122
|
-
`Local source.root is too broad: ${rootRealPath}. ${broadRootReason} Choose a narrower explicit docs/source directory.`,
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
return rootRealPath;
|
|
126
|
-
}
|
|
127
|
-
async function resolveLocalRequestedPath(rootRealPath, requestedPath) {
|
|
128
|
-
if (requestedPath !== undefined && requestedPath !== "" && isAbsolute(requestedPath)) {
|
|
129
|
-
throw new Error(`Local source.path must be relative to source.root: ${requestedPath}`);
|
|
130
|
-
}
|
|
131
|
-
const requestedAbsolutePath =
|
|
132
|
-
requestedPath && requestedPath !== "" ? resolve(rootRealPath, requestedPath) : rootRealPath;
|
|
133
|
-
const requestedRealPath = await realpath(requestedAbsolutePath);
|
|
134
|
-
if (!isPathInsideRoot(rootRealPath, requestedRealPath)) {
|
|
135
|
-
throw new Error(`Local path escapes root: ${requestedPath ?? "."}`);
|
|
136
|
-
}
|
|
137
|
-
return {
|
|
138
|
-
root: rootRealPath,
|
|
139
|
-
absolutePath: requestedRealPath,
|
|
140
|
-
relativePath: normalizeRelativePath(relative(rootRealPath, requestedRealPath)),
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
async function collectTextFileRefs(options) {
|
|
144
|
-
let currentRealPath;
|
|
145
|
-
try {
|
|
146
|
-
currentRealPath = await realpath(options.currentPath);
|
|
147
|
-
} catch {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (!isPathInsideRoot(options.root, currentRealPath)) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
let currentStat;
|
|
154
|
-
try {
|
|
155
|
-
currentStat = await stat(currentRealPath);
|
|
156
|
-
} catch {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const path = normalizeRelativePath(relative(options.root, currentRealPath));
|
|
160
|
-
if (isSensitivePath(path)) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
if (currentStat.isDirectory()) {
|
|
164
|
-
if (options.visitedDirectories.has(currentRealPath)) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
options.visitedDirectories.add(currentRealPath);
|
|
168
|
-
noteDirectory(options.budget);
|
|
169
|
-
if (options.broadTraversal && path !== "" && shouldSkipBroadDirectory(path, options.generatedPathGlobs)) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
const entries = await readdir(currentRealPath, { withFileTypes: true });
|
|
173
|
-
for (const entry of entries) {
|
|
174
|
-
await collectTextFileRefs({
|
|
175
|
-
...options,
|
|
176
|
-
currentPath: resolve(currentRealPath, entry.name),
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
if (!currentStat.isFile()) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
noteFile(options.budget, currentStat.size);
|
|
185
|
-
if (options.broadTraversal && shouldSkipBroadFile(path, currentStat.size, options.generatedPathGlobs)) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
options.fileRefs.push({ root: options.root, path, absolutePath: currentRealPath, sizeBytes: currentStat.size });
|
|
189
|
-
}
|
|
190
|
-
function noteDirectory(budget) {
|
|
191
|
-
budget.directories += 1;
|
|
192
|
-
if (budget.directories > LOCAL_SCAN_MAX_DIRECTORIES) {
|
|
193
|
-
throw new Error(
|
|
194
|
-
`Local broad scan exceeded directory budget (${LOCAL_SCAN_MAX_DIRECTORIES}); narrow source.root or source.path.`,
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
function noteFile(budget, size) {
|
|
199
|
-
budget.files += 1;
|
|
200
|
-
budget.bytes += size;
|
|
201
|
-
if (budget.files > LOCAL_SCAN_MAX_FILES) {
|
|
202
|
-
throw new Error(
|
|
203
|
-
`Local broad scan exceeded file budget (${LOCAL_SCAN_MAX_FILES}); narrow source.root or source.path.`,
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
if (budget.bytes > LOCAL_SCAN_MAX_TOTAL_BYTES) {
|
|
207
|
-
throw new Error(
|
|
208
|
-
`Local broad scan exceeded byte budget (${LOCAL_SCAN_MAX_TOTAL_BYTES}); narrow source.root or source.path.`,
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
function isExplicitRequestedPath(requestedRelativePath) {
|
|
213
|
-
return requestedRelativePath !== "" && requestedRelativePath !== ".";
|
|
214
|
-
}
|
|
215
|
-
function shouldSkipBroadDirectory(path, generatedPathGlobs) {
|
|
216
|
-
const name = path.split("/").at(-1)?.toLowerCase() ?? path.toLowerCase();
|
|
217
|
-
return BROAD_SKIP_DIRS.has(name) || matchesGeneratedPathHint(path, generatedPathGlobs);
|
|
218
|
-
}
|
|
219
|
-
function shouldSkipBroadFile(path, size, generatedPathGlobs) {
|
|
220
|
-
if (matchesGeneratedPathHint(path, generatedPathGlobs)) {
|
|
221
|
-
return true;
|
|
222
|
-
}
|
|
223
|
-
const name = path.split("/").at(-1)?.toLowerCase() ?? path.toLowerCase();
|
|
224
|
-
if (hasSecretFileName(name)) {
|
|
225
|
-
return true;
|
|
226
|
-
}
|
|
227
|
-
if (hasBroadSkippedFileExtension(name)) {
|
|
228
|
-
return true;
|
|
229
|
-
}
|
|
230
|
-
if (size > BROAD_SCAN_MAX_FILE_BYTES) {
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
if (name.endsWith(".min.js") || name.endsWith(".min.css") || name.endsWith(".map")) {
|
|
234
|
-
return true;
|
|
235
|
-
}
|
|
236
|
-
if (name.includes(".bundle.") || name.endsWith(".log")) {
|
|
237
|
-
return true;
|
|
238
|
-
}
|
|
239
|
-
if ((name.endsWith(".html") || name.endsWith(".json")) && size > 64_000) {
|
|
240
|
-
return true;
|
|
241
|
-
}
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
function matchesGeneratedPathHint(path, hints) {
|
|
245
|
-
if (hints.length === 0) {
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
const normalizedPath = normalizeRelativePath(path);
|
|
249
|
-
return hints.some((hint) => matchesGeneratedPathGlob(normalizedPath, hint));
|
|
250
|
-
}
|
|
251
|
-
function isSensitivePath(path) {
|
|
252
|
-
if (!path || path === ".") {
|
|
253
|
-
return false;
|
|
254
|
-
}
|
|
255
|
-
const segments = normalizeRelativePath(path)
|
|
256
|
-
.split("/")
|
|
257
|
-
.map((segment) => segment.toLowerCase());
|
|
258
|
-
return segments.some((segment) => SECRET_DIRS.has(segment)) || hasSecretFileName(segments.at(-1) ?? "");
|
|
259
|
-
}
|
|
260
|
-
function hasSecretFileName(name) {
|
|
261
|
-
return (
|
|
262
|
-
SECRET_FILE_NAMES.has(name) ||
|
|
263
|
-
name.startsWith(".env.") ||
|
|
264
|
-
name.endsWith(".pem") ||
|
|
265
|
-
name.endsWith(".key") ||
|
|
266
|
-
name.endsWith(".p12") ||
|
|
267
|
-
name.endsWith(".pfx")
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
function hasBroadSkippedFileExtension(name) {
|
|
271
|
-
for (const extension of BROAD_SKIP_FILE_EXTENSIONS) {
|
|
272
|
-
if (name.endsWith(extension)) {
|
|
273
|
-
return true;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
return false;
|
|
277
|
-
}
|
|
278
|
-
function broadRootRejectionReason(rootRealPath) {
|
|
279
|
-
const normalized = normalizeAbsolutePath(rootRealPath);
|
|
280
|
-
const filesystemRoot = normalizeAbsolutePath(parse(rootRealPath).root);
|
|
281
|
-
if (normalized === filesystemRoot) {
|
|
282
|
-
return "Filesystem root scans are not allowed.";
|
|
283
|
-
}
|
|
284
|
-
const home = safeNormalizeAbsolutePath(homedir());
|
|
285
|
-
if (home && normalized === home) {
|
|
286
|
-
return "Home directory scans are not allowed.";
|
|
287
|
-
}
|
|
288
|
-
const temp = safeNormalizeAbsolutePath(tmpdir());
|
|
289
|
-
if (temp && normalized === temp) {
|
|
290
|
-
return "System temp directory scans are not allowed.";
|
|
291
|
-
}
|
|
292
|
-
const broadRoots = [
|
|
293
|
-
"/Applications",
|
|
294
|
-
"/Library",
|
|
295
|
-
"/System",
|
|
296
|
-
"/Users",
|
|
297
|
-
"/bin",
|
|
298
|
-
"/etc",
|
|
299
|
-
"/home",
|
|
300
|
-
"/opt",
|
|
301
|
-
"/private/tmp",
|
|
302
|
-
"/sbin",
|
|
303
|
-
"/tmp",
|
|
304
|
-
"/usr",
|
|
305
|
-
"/var",
|
|
306
|
-
].map(normalizeAbsolutePath);
|
|
307
|
-
if (broadRoots.includes(normalized)) {
|
|
308
|
-
return "System or multi-user root scans are not allowed.";
|
|
309
|
-
}
|
|
310
|
-
if (SECRET_DIRS.has(basename(normalized).toLowerCase())) {
|
|
311
|
-
return "Credential/secret directory roots are not allowed.";
|
|
312
|
-
}
|
|
313
|
-
return null;
|
|
314
|
-
}
|
|
315
|
-
function safeNormalizeAbsolutePath(path) {
|
|
316
|
-
try {
|
|
317
|
-
return normalizeAbsolutePath(path);
|
|
318
|
-
} catch {
|
|
319
|
-
return null;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
function isPathInsideRoot(root, absolutePath) {
|
|
323
|
-
const relativePath = relative(root, absolutePath);
|
|
324
|
-
return (
|
|
325
|
-
relativePath === "" ||
|
|
326
|
-
(!relativePath.startsWith("..") && !relativePath.startsWith("/") && !/^[A-Za-z]:/.test(relativePath))
|
|
327
|
-
);
|
|
328
|
-
}
|
|
329
|
-
function normalizeRelativePath(path) {
|
|
330
|
-
return path.split(/[\\/]+/).join("/");
|
|
331
|
-
}
|
|
332
|
-
function normalizeAbsolutePath(path) {
|
|
333
|
-
return normalizeRelativePath(resolve(path)).replace(/\/+$/, "") || "/";
|
|
334
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { type ProcessingReducerSelection } from "./reducers.js";
|
|
2
|
-
import { type ProcessingScriptRequest, type ProcessingScriptResult } from "./scripts.js";
|
|
3
|
-
import type {
|
|
4
|
-
EvidenceLineage,
|
|
5
|
-
EvidencePersistence,
|
|
6
|
-
LocalFreeflowConfig,
|
|
7
|
-
OutputStream,
|
|
8
|
-
RecoveryHint,
|
|
9
|
-
ScriptTransformConfig,
|
|
10
|
-
SourceRef,
|
|
11
|
-
VaultRetentionPolicy,
|
|
12
|
-
} from "../config/types.js";
|
|
13
|
-
import type { ScriptSandboxAdapter } from "../sandbox/script-sandbox.js";
|
|
14
|
-
export declare const PROCESSING_ENGINE_IMPLEMENTATION = "processing-engine-skeleton-v1";
|
|
15
|
-
export interface ProcessingLimits {
|
|
16
|
-
maxSourceBytes: number;
|
|
17
|
-
maxVisibleBytes: number;
|
|
18
|
-
}
|
|
19
|
-
export interface ProcessingEngineOptions {
|
|
20
|
-
sessionId?: string;
|
|
21
|
-
vaultRoot?: string;
|
|
22
|
-
vaultRetention?: VaultRetentionPolicy;
|
|
23
|
-
goal?: string;
|
|
24
|
-
limits?: Partial<ProcessingLimits>;
|
|
25
|
-
script?: ProcessingScriptRequest;
|
|
26
|
-
scriptTransform?: ScriptTransformConfig;
|
|
27
|
-
localConfig?: LocalFreeflowConfig;
|
|
28
|
-
scriptSandboxAdapters?: readonly ScriptSandboxAdapter[];
|
|
29
|
-
}
|
|
30
|
-
export interface RepoFileProcessingSource {
|
|
31
|
-
kind: "repo-file";
|
|
32
|
-
root: string;
|
|
33
|
-
path: string;
|
|
34
|
-
}
|
|
35
|
-
export interface VaultOutputProcessingSource {
|
|
36
|
-
kind: "vault-output";
|
|
37
|
-
sessionId: string;
|
|
38
|
-
outputId: string;
|
|
39
|
-
stream?: OutputStream;
|
|
40
|
-
vaultRoot?: string;
|
|
41
|
-
}
|
|
42
|
-
export interface LocalFileProcessingSource {
|
|
43
|
-
kind: "local-file";
|
|
44
|
-
root: string;
|
|
45
|
-
path: string;
|
|
46
|
-
}
|
|
47
|
-
export interface CapturedCommandOutputProcessingSource {
|
|
48
|
-
kind: "command-output";
|
|
49
|
-
stdout?: string;
|
|
50
|
-
stderr?: string;
|
|
51
|
-
combined?: string;
|
|
52
|
-
stream?: Exclude<OutputStream, "raw">;
|
|
53
|
-
outputId?: string;
|
|
54
|
-
}
|
|
55
|
-
export type ProcessingSourceInput =
|
|
56
|
-
| RepoFileProcessingSource
|
|
57
|
-
| VaultOutputProcessingSource
|
|
58
|
-
| LocalFileProcessingSource
|
|
59
|
-
| CapturedCommandOutputProcessingSource;
|
|
60
|
-
export interface ProcessingSourceStats {
|
|
61
|
-
bytes: number;
|
|
62
|
-
lines: number;
|
|
63
|
-
sha256: string;
|
|
64
|
-
}
|
|
65
|
-
export interface ProcessingSourceDescriptor {
|
|
66
|
-
kind: ProcessingSourceInput["kind"];
|
|
67
|
-
ref: SourceRef;
|
|
68
|
-
displayPath: string;
|
|
69
|
-
stream?: OutputStream;
|
|
70
|
-
}
|
|
71
|
-
export interface LoadedProcessingSource {
|
|
72
|
-
status: "ok";
|
|
73
|
-
source: ProcessingSourceDescriptor;
|
|
74
|
-
text: string;
|
|
75
|
-
stats: ProcessingSourceStats;
|
|
76
|
-
lineage?: EvidenceLineage;
|
|
77
|
-
persistence?: EvidencePersistence;
|
|
78
|
-
recovery?: RecoveryHint;
|
|
79
|
-
}
|
|
80
|
-
export interface BlockedProcessingSource {
|
|
81
|
-
status: "blocked";
|
|
82
|
-
source: ProcessingSourceDescriptor;
|
|
83
|
-
reason: string;
|
|
84
|
-
policy: "repo_containment" | "source_limit";
|
|
85
|
-
stats?: Pick<ProcessingSourceStats, "bytes">;
|
|
86
|
-
}
|
|
87
|
-
export interface UnavailableProcessingSource {
|
|
88
|
-
status: "unavailable";
|
|
89
|
-
source: ProcessingSourceDescriptor;
|
|
90
|
-
reason: string;
|
|
91
|
-
}
|
|
92
|
-
export type ProcessingSourceLoadResult = LoadedProcessingSource | BlockedProcessingSource | UnavailableProcessingSource;
|
|
93
|
-
export interface ProcessingFact {
|
|
94
|
-
name: string;
|
|
95
|
-
value: string | number | boolean;
|
|
96
|
-
}
|
|
97
|
-
export type ReducerSelectionResult = ProcessingReducerSelection;
|
|
98
|
-
export type ScriptPolicySelectionResult = ProcessingScriptResult;
|
|
99
|
-
export interface ProcessingResultBase {
|
|
100
|
-
implementation: typeof PROCESSING_ENGINE_IMPLEMENTATION;
|
|
101
|
-
source: ProcessingSourceDescriptor;
|
|
102
|
-
visibleText: string;
|
|
103
|
-
facts: ProcessingFact[];
|
|
104
|
-
reducer: ReducerSelectionResult;
|
|
105
|
-
script: ScriptPolicySelectionResult;
|
|
106
|
-
lineage?: EvidenceLineage;
|
|
107
|
-
persistence?: EvidencePersistence;
|
|
108
|
-
recovery?: RecoveryHint;
|
|
109
|
-
}
|
|
110
|
-
export interface ProcessingOkResult extends ProcessingResultBase {
|
|
111
|
-
status: "ok";
|
|
112
|
-
stats: ProcessingSourceStats;
|
|
113
|
-
}
|
|
114
|
-
export interface ProcessingBlockedResult extends ProcessingResultBase {
|
|
115
|
-
status: "blocked";
|
|
116
|
-
reason: string;
|
|
117
|
-
policy: BlockedProcessingSource["policy"];
|
|
118
|
-
}
|
|
119
|
-
export interface ProcessingUnavailableResult extends ProcessingResultBase {
|
|
120
|
-
status: "unavailable";
|
|
121
|
-
reason: string;
|
|
122
|
-
}
|
|
123
|
-
export type ProcessingResult = ProcessingOkResult | ProcessingBlockedResult | ProcessingUnavailableResult;
|
|
124
|
-
export declare function loadProcessingSource(
|
|
125
|
-
source: ProcessingSourceInput,
|
|
126
|
-
options?: ProcessingEngineOptions,
|
|
127
|
-
): Promise<ProcessingSourceLoadResult>;
|
|
128
|
-
export declare function processSource(
|
|
129
|
-
source: ProcessingSourceInput,
|
|
130
|
-
options?: ProcessingEngineOptions,
|
|
131
|
-
): Promise<ProcessingResult>;
|
|
132
|
-
export declare function isProcessingPathInsideRoot(root: string, absolutePath: string): boolean;
|