@eir-labs/coltrane 0.4.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 +201 -0
- package/README.md +85 -0
- package/agents/anticipation-mapper.json +34 -0
- package/agents/claim-amender.json +34 -0
- package/agents/claim-architect.json +34 -0
- package/agents/claim-rewriter.json +32 -0
- package/agents/delivery-finalizer.json +40 -0
- package/agents/diamond-cutter.json +33 -0
- package/agents/disclosure-analyst.json +26 -0
- package/agents/domain-explorer.json +37 -0
- package/agents/e2e-runner.json +34 -0
- package/agents/e2e-suite-judge.json +26 -0
- package/agents/event-clusterer.json +29 -0
- package/agents/novelty-searcher.json +40 -0
- package/agents/patent-browser-scout.json +49 -0
- package/agents/patent-examiner.json +36 -0
- package/agents/phase_agents/claim-rewriter.md +44 -0
- package/agents/phase_agents/delivery-finalizer.md +30 -0
- package/agents/phase_agents/diamond-cutter.md +47 -0
- package/agents/phase_agents/domain-explorer.md +27 -0
- package/agents/phase_agents/novelty-searcher.md +50 -0
- package/agents/phase_agents/problem-definer.md +32 -0
- package/agents/phase_agents/solution-developer.md +26 -0
- package/agents/phase_agents/verdict-judger.md +70 -0
- package/agents/players/audience-modeler.md +40 -0
- package/agents/players/chain-audit-keeper.md +41 -0
- package/agents/players/illumination-reviewer.md +42 -0
- package/agents/players/methodology-cadence-keeper.md +42 -0
- package/agents/players/substrate-edge-keeper.md +45 -0
- package/agents/prior-art-scout.json +45 -0
- package/agents/problem-definer.json +35 -0
- package/agents/seeds/steve_seed_a.json +12 -0
- package/agents/seeds/steve_seed_b.json +12 -0
- package/agents/seeds/steve_seed_c.json +12 -0
- package/agents/seeds/steve_seed_d.json +12 -0
- package/agents/sensor.json +22 -0
- package/agents/solution-developer.json +35 -0
- package/agents/source-walker.json +38 -0
- package/agents/spec-drafter.json +31 -0
- package/agents/sub_thread_soft_judge.json +26 -0
- package/agents/sub_thread_trace_sensor.json +22 -0
- package/agents/summarizer.json +25 -0
- package/agents/synthesis-writer.json +29 -0
- package/agents/triage-judge.json +39 -0
- package/agents/user_flow_judge.json +26 -0
- package/agents/user_flow_sensor.json +22 -0
- package/agents/verdict-judger.json +39 -0
- package/core_types/artifact.json +17 -0
- package/core_types/interpretation.json +16 -0
- package/core_types/judgment.json +16 -0
- package/core_types/plan.json +16 -0
- package/core_types/signal.json +16 -0
- package/core_types/verdict.json +27 -0
- package/dist/src/access_grant.d.ts +46 -0
- package/dist/src/access_grant.js +76 -0
- package/dist/src/access_grant.js.map +1 -0
- package/dist/src/acoustics.d.ts +9 -0
- package/dist/src/acoustics.js +65 -0
- package/dist/src/acoustics.js.map +1 -0
- package/dist/src/agent_profile.d.ts +36 -0
- package/dist/src/agent_profile.js +57 -0
- package/dist/src/agent_profile.js.map +1 -0
- package/dist/src/bifrost_invoker.d.ts +33 -0
- package/dist/src/bifrost_invoker.js +85 -0
- package/dist/src/bifrost_invoker.js.map +1 -0
- package/dist/src/canonical_core_types.d.ts +2 -0
- package/dist/src/canonical_core_types.js +111 -0
- package/dist/src/canonical_core_types.js.map +1 -0
- package/dist/src/canonical_form.d.ts +55 -0
- package/dist/src/canonical_form.js +93 -0
- package/dist/src/canonical_form.js.map +1 -0
- package/dist/src/charter.d.ts +37 -0
- package/dist/src/charter.js +86 -0
- package/dist/src/charter.js.map +1 -0
- package/dist/src/circle_of_fifths.d.ts +27 -0
- package/dist/src/circle_of_fifths.js +78 -0
- package/dist/src/circle_of_fifths.js.map +1 -0
- package/dist/src/claude_invoker.d.ts +102 -0
- package/dist/src/claude_invoker.js +760 -0
- package/dist/src/claude_invoker.js.map +1 -0
- package/dist/src/coltrane_profile.d.ts +87 -0
- package/dist/src/coltrane_profile.js +132 -0
- package/dist/src/coltrane_profile.js.map +1 -0
- package/dist/src/composition.d.ts +57 -0
- package/dist/src/composition.js +447 -0
- package/dist/src/composition.js.map +1 -0
- package/dist/src/core_types.d.ts +6 -0
- package/dist/src/core_types.js +25 -0
- package/dist/src/core_types.js.map +1 -0
- package/dist/src/document_factory.d.ts +89 -0
- package/dist/src/document_factory.js +176 -0
- package/dist/src/document_factory.js.map +1 -0
- package/dist/src/genome_schema.d.ts +512 -0
- package/dist/src/genome_schema.js +168 -0
- package/dist/src/genome_schema.js.map +1 -0
- package/dist/src/genome_writer.d.ts +67 -0
- package/dist/src/genome_writer.js +179 -0
- package/dist/src/genome_writer.js.map +1 -0
- package/dist/src/gig_song.d.ts +29 -0
- package/dist/src/gig_song.js +56 -0
- package/dist/src/gig_song.js.map +1 -0
- package/dist/src/gig_tracker.d.ts +54 -0
- package/dist/src/gig_tracker.js +109 -0
- package/dist/src/gig_tracker.js.map +1 -0
- package/dist/src/harmonic_validation.d.ts +11 -0
- package/dist/src/harmonic_validation.js +35 -0
- package/dist/src/harmonic_validation.js.map +1 -0
- package/dist/src/hooks.d.ts +27 -0
- package/dist/src/hooks.js +2 -0
- package/dist/src/hooks.js.map +1 -0
- package/dist/src/index.d.ts +36 -0
- package/dist/src/index.js +37 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/jsong.d.ts +47 -0
- package/dist/src/jsong.js +130 -0
- package/dist/src/jsong.js.map +1 -0
- package/dist/src/judges/user_flow_judge.d.ts +89 -0
- package/dist/src/judges/user_flow_judge.js +200 -0
- package/dist/src/judges/user_flow_judge.js.map +1 -0
- package/dist/src/learner.d.ts +37 -0
- package/dist/src/learner.js +30 -0
- package/dist/src/learner.js.map +1 -0
- package/dist/src/ledger.d.ts +225 -0
- package/dist/src/ledger.js +306 -0
- package/dist/src/ledger.js.map +1 -0
- package/dist/src/loader.d.ts +87 -0
- package/dist/src/loader.js +504 -0
- package/dist/src/loader.js.map +1 -0
- package/dist/src/mcp.d.ts +23 -0
- package/dist/src/mcp.js +125 -0
- package/dist/src/mcp.js.map +1 -0
- package/dist/src/modulation_path.d.ts +42 -0
- package/dist/src/modulation_path.js +60 -0
- package/dist/src/modulation_path.js.map +1 -0
- package/dist/src/output_validation.d.ts +19 -0
- package/dist/src/output_validation.js +51 -0
- package/dist/src/output_validation.js.map +1 -0
- package/dist/src/outputs.d.ts +125 -0
- package/dist/src/outputs.js +452 -0
- package/dist/src/outputs.js.map +1 -0
- package/dist/src/overtones.d.ts +42 -0
- package/dist/src/overtones.js +98 -0
- package/dist/src/overtones.js.map +1 -0
- package/dist/src/player_to_claude_code.d.ts +17 -0
- package/dist/src/player_to_claude_code.js +141 -0
- package/dist/src/player_to_claude_code.js.map +1 -0
- package/dist/src/playwright_cage.d.ts +28 -0
- package/dist/src/playwright_cage.js +47 -0
- package/dist/src/playwright_cage.js.map +1 -0
- package/dist/src/polyphony.d.ts +46 -0
- package/dist/src/polyphony.js +91 -0
- package/dist/src/polyphony.js.map +1 -0
- package/dist/src/portfolio.d.ts +52 -0
- package/dist/src/portfolio.js +186 -0
- package/dist/src/portfolio.js.map +1 -0
- package/dist/src/pricing.d.ts +23 -0
- package/dist/src/pricing.js +16 -0
- package/dist/src/pricing.js.map +1 -0
- package/dist/src/registry.d.ts +46 -0
- package/dist/src/registry.js +199 -0
- package/dist/src/registry.js.map +1 -0
- package/dist/src/runtime.d.ts +304 -0
- package/dist/src/runtime.js +1099 -0
- package/dist/src/runtime.js.map +1 -0
- package/dist/src/server.d.ts +88 -0
- package/dist/src/server.js +1692 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/server_entry.d.ts +2 -0
- package/dist/src/server_entry.js +40 -0
- package/dist/src/server_entry.js.map +1 -0
- package/dist/src/server_relay.d.ts +82 -0
- package/dist/src/server_relay.js +341 -0
- package/dist/src/server_relay.js.map +1 -0
- package/dist/src/simulate.d.ts +60 -0
- package/dist/src/simulate.js +72 -0
- package/dist/src/simulate.js.map +1 -0
- package/dist/src/skill_runner.mjs +34 -0
- package/dist/src/skill_subprocess.d.ts +65 -0
- package/dist/src/skill_subprocess.js +132 -0
- package/dist/src/skill_subprocess.js.map +1 -0
- package/dist/src/skills.d.ts +85 -0
- package/dist/src/skills.js +258 -0
- package/dist/src/skills.js.map +1 -0
- package/dist/src/subthread_recorder.d.ts +68 -0
- package/dist/src/subthread_recorder.js +166 -0
- package/dist/src/subthread_recorder.js.map +1 -0
- package/dist/src/tensor_read.d.ts +38 -0
- package/dist/src/tensor_read.js +60 -0
- package/dist/src/tensor_read.js.map +1 -0
- package/dist/src/test_honest_broker.d.ts +34 -0
- package/dist/src/test_honest_broker.js +155 -0
- package/dist/src/test_honest_broker.js.map +1 -0
- package/dist/src/test_topology.d.ts +22 -0
- package/dist/src/test_topology.js +137 -0
- package/dist/src/test_topology.js.map +1 -0
- package/dist/src/tones.d.ts +20 -0
- package/dist/src/tones.js +81 -0
- package/dist/src/tones.js.map +1 -0
- package/dist/src/tool_providers.d.ts +45 -0
- package/dist/src/tool_providers.js +104 -0
- package/dist/src/tool_providers.js.map +1 -0
- package/dist/src/type_versioning.d.ts +23 -0
- package/dist/src/type_versioning.js +31 -0
- package/dist/src/type_versioning.js.map +1 -0
- package/dist/src/version.d.ts +28 -0
- package/dist/src/version.js +86 -0
- package/dist/src/version.js.map +1 -0
- package/domain_types/claim-draft.json +34 -0
- package/domain_types/coverage-report.json +31 -0
- package/domain_types/draft-agent-profile.json +31 -0
- package/domain_types/draft-domain-type.json +28 -0
- package/domain_types/draft-standard.json +46 -0
- package/domain_types/e2e-observation.json +32 -0
- package/domain_types/e2e-report.json +30 -0
- package/domain_types/e2e-target.json +26 -0
- package/domain_types/e2e-verdict.json +26 -0
- package/domain_types/examine-round-record.json +40 -0
- package/domain_types/examiner-rejection.json +28 -0
- package/domain_types/failure-modes.json +31 -0
- package/domain_types/invention-analysis.json +34 -0
- package/domain_types/invention-spec.json +34 -0
- package/domain_types/novelty-analysis.json +28 -0
- package/domain_types/novelty-verdict.json +35 -0
- package/domain_types/parsed-conversation-trace.json +38 -0
- package/domain_types/pattern-extraction.json +62 -0
- package/domain_types/prior-art-hit.json +50 -0
- package/domain_types/project-charter.json +71 -0
- package/domain_types/provisional-draft.json +34 -0
- package/domain_types/raw-note.json +19 -0
- package/domain_types/repo-survey.json +28 -0
- package/domain_types/seeding-verdict.json +70 -0
- package/domain_types/soft-verdict.json +55 -0
- package/domain_types/summary.json +19 -0
- package/domain_types/triage-verdict.json +59 -0
- package/domain_types/user-flow-transcript.json +43 -0
- package/domain_types/user-flow-verdict.json +60 -0
- package/domain_types/verdict-record.json +39 -0
- package/package.json +82 -0
- package/skills/citation-verify/fixtures/basic.json +14 -0
- package/skills/citation-verify/meta.json +10 -0
- package/skills/citation-verify/skill.mjs +26 -0
- package/skills/claim-element-decompose/fixtures/basic.json +11 -0
- package/skills/claim-element-decompose/meta.json +10 -0
- package/skills/claim-element-decompose/skill.mjs +14 -0
- package/skills/diamond-cutting-discipline/fixtures/basic.json +13 -0
- package/skills/diamond-cutting-discipline/meta.json +19 -0
- package/skills/diamond-cutting-discipline/skill.md +46 -0
- package/skills/element-mapping-matrix/fixtures/basic.json +13 -0
- package/skills/element-mapping-matrix/meta.json +10 -0
- package/skills/element-mapping-matrix/skill.mjs +20 -0
- package/skills/number-adder/fixtures/basic.json +9 -0
- package/skills/number-adder/meta.json +10 -0
- package/skills/number-adder/skill.mjs +12 -0
- package/skills/patent-fetch/fixtures/parse.json +18 -0
- package/skills/patent-fetch/meta.json +11 -0
- package/skills/patent-fetch/skill.mjs +34 -0
- package/skills/query-expand/fixtures/basic.json +14 -0
- package/skills/query-expand/meta.json +10 -0
- package/skills/query-expand/skill.mjs +29 -0
- package/skills/run-vitest-band/fixtures/basic.json +9 -0
- package/skills/run-vitest-band/meta.json +18 -0
- package/skills/run-vitest-band/skill.mjs +22 -0
- package/skills/statutory-checklist/fixtures/basic.json +16 -0
- package/skills/statutory-checklist/meta.json +10 -0
- package/skills/statutory-checklist/skill.mjs +25 -0
- package/skills/summarize-tight/fixtures/basic.json +13 -0
- package/skills/summarize-tight/meta.json +20 -0
- package/skills/summarize-tight/skill.md +1 -0
- package/skills/verdict-gate/fixtures/basic.json +9 -0
- package/skills/verdict-gate/meta.json +10 -0
- package/skills/verdict-gate/skill.mjs +82 -0
- package/standards/e2e-suite-v0.json +44 -0
- package/standards/patent-triage-v0.json +98 -0
- package/standards/patent-triage-v1.json +84 -0
- package/standards/seed-from-local-repos-v0.json +115 -0
- package/standards/sub_thread_invocation.json +50 -0
- package/standards/summarize.json +40 -0
- package/standards/synthesis-walk-v0.json +108 -0
- package/standards/user_flow_correctness.json +57 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export * from "./version.js";
|
|
2
|
+
export * from "./core_types.js";
|
|
3
|
+
export * from "./type_versioning.js";
|
|
4
|
+
export * from "./composition.js";
|
|
5
|
+
export * from "./tool_providers.js";
|
|
6
|
+
export * from "./playwright_cage.js";
|
|
7
|
+
export * from "./mcp.js";
|
|
8
|
+
export * from "./pricing.js";
|
|
9
|
+
export * from "./access_grant.js";
|
|
10
|
+
export * from "./agent_profile.js";
|
|
11
|
+
export * from "./output_validation.js";
|
|
12
|
+
export * from "./simulate.js";
|
|
13
|
+
export * from "./coltrane_profile.js";
|
|
14
|
+
export * from "./learner.js";
|
|
15
|
+
export * from "./registry.js";
|
|
16
|
+
export * from "./loader.js";
|
|
17
|
+
export * from "./canonical_core_types.js";
|
|
18
|
+
export * from "./canonical_form.js";
|
|
19
|
+
export * from "./ledger.js";
|
|
20
|
+
export * from "./outputs.js";
|
|
21
|
+
export * from "./charter.js";
|
|
22
|
+
export * from "./server.js";
|
|
23
|
+
export * from "./runtime.js";
|
|
24
|
+
export * from "./claude_invoker.js";
|
|
25
|
+
export * from "./bifrost_invoker.js";
|
|
26
|
+
export * from "./circle_of_fifths.js";
|
|
27
|
+
export * from "./modulation_path.js";
|
|
28
|
+
export * from "./tensor_read.js";
|
|
29
|
+
export * from "./jsong.js";
|
|
30
|
+
export * from "./tones.js";
|
|
31
|
+
export * from "./gig_song.js";
|
|
32
|
+
export * from "./overtones.js";
|
|
33
|
+
export * from "./polyphony.js";
|
|
34
|
+
export * from "./harmonic_validation.js";
|
|
35
|
+
export * from "./acoustics.js";
|
|
36
|
+
export * from "./document_factory.js";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export * from "./version.js";
|
|
2
|
+
export * from "./core_types.js";
|
|
3
|
+
export * from "./type_versioning.js";
|
|
4
|
+
export * from "./composition.js";
|
|
5
|
+
export * from "./tool_providers.js";
|
|
6
|
+
export * from "./playwright_cage.js";
|
|
7
|
+
export * from "./mcp.js";
|
|
8
|
+
export * from "./pricing.js";
|
|
9
|
+
export * from "./access_grant.js";
|
|
10
|
+
export * from "./agent_profile.js";
|
|
11
|
+
export * from "./output_validation.js";
|
|
12
|
+
export * from "./simulate.js";
|
|
13
|
+
export * from "./coltrane_profile.js";
|
|
14
|
+
export * from "./learner.js";
|
|
15
|
+
export * from "./registry.js";
|
|
16
|
+
export * from "./loader.js";
|
|
17
|
+
export * from "./canonical_core_types.js";
|
|
18
|
+
export * from "./canonical_form.js";
|
|
19
|
+
export * from "./ledger.js";
|
|
20
|
+
export * from "./outputs.js";
|
|
21
|
+
export * from "./charter.js";
|
|
22
|
+
export * from "./server.js";
|
|
23
|
+
export * from "./runtime.js";
|
|
24
|
+
export * from "./claude_invoker.js";
|
|
25
|
+
export * from "./bifrost_invoker.js";
|
|
26
|
+
export * from "./circle_of_fifths.js";
|
|
27
|
+
export * from "./modulation_path.js";
|
|
28
|
+
export * from "./tensor_read.js";
|
|
29
|
+
export * from "./jsong.js";
|
|
30
|
+
export * from "./tones.js";
|
|
31
|
+
export * from "./gig_song.js";
|
|
32
|
+
export * from "./overtones.js";
|
|
33
|
+
export * from "./polyphony.js";
|
|
34
|
+
export * from "./harmonic_validation.js";
|
|
35
|
+
export * from "./acoustics.js";
|
|
36
|
+
export * from "./document_factory.js";
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export declare const MAGIC: Uint8Array<ArrayBuffer>;
|
|
2
|
+
export declare const FILE_HEADER_SIZE = 48;
|
|
3
|
+
export declare const TICK_RECORD_SIZE = 280;
|
|
4
|
+
export declare const STATE_DIM = 59;
|
|
5
|
+
export declare const SLUG_SIZE = 20;
|
|
6
|
+
export declare const ROLE_OBSERVATION = 0;
|
|
7
|
+
export declare const ROLE_SPEC = 1;
|
|
8
|
+
export declare const ROLE_VERDICT = 2;
|
|
9
|
+
export declare const FLAG_MUSICAL: number;
|
|
10
|
+
export declare const FLAG_ANOMALY: number;
|
|
11
|
+
export declare const FLAG_BOUNDARY: number;
|
|
12
|
+
export declare const FLAG_CLAIM_NUMERIC: number;
|
|
13
|
+
export declare const FLAG_CLAIM_STRING: number;
|
|
14
|
+
export declare const FLAG_CLAIM_IMPORT_REQUIRED: number;
|
|
15
|
+
export declare const FLAG_CLAIM_IMPORT_FORBIDDEN: number;
|
|
16
|
+
export declare const FLAG_CLAIM_NO_CYCLES: number;
|
|
17
|
+
export declare const FLAG_BAND_PROFILE: number;
|
|
18
|
+
export declare class JsongError extends Error {
|
|
19
|
+
}
|
|
20
|
+
export interface FileHeader {
|
|
21
|
+
version: number;
|
|
22
|
+
gig_id: Uint8Array;
|
|
23
|
+
agent_id: Uint8Array;
|
|
24
|
+
start_us: bigint;
|
|
25
|
+
}
|
|
26
|
+
export interface TickRecord {
|
|
27
|
+
tick_idx: number;
|
|
28
|
+
delta_us: number;
|
|
29
|
+
role: number;
|
|
30
|
+
flags: number;
|
|
31
|
+
state_59: number[];
|
|
32
|
+
score: number;
|
|
33
|
+
slug: string;
|
|
34
|
+
}
|
|
35
|
+
export declare function packHeader(h: FileHeader): Uint8Array;
|
|
36
|
+
export declare function unpackHeader(buf: Uint8Array): FileHeader;
|
|
37
|
+
export declare function packTick(rec: TickRecord): Uint8Array;
|
|
38
|
+
export declare function unpackTick(buf: Uint8Array): TickRecord;
|
|
39
|
+
/** Decode a whole JSONG buffer (header + N ticks). Mirrors Python read_all. */
|
|
40
|
+
export declare function readAll(data: Uint8Array): {
|
|
41
|
+
header: FileHeader;
|
|
42
|
+
ticks: TickRecord[];
|
|
43
|
+
};
|
|
44
|
+
/** Encode a header + ticks into a single JSONG buffer. */
|
|
45
|
+
export declare function writeAll(header: FileHeader, ticks: readonly TickRecord[]): Uint8Array;
|
|
46
|
+
/** A zero-valued 59-float state vector (Python empty_state). */
|
|
47
|
+
export declare function emptyState(): number[];
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// JSONG — the substrate's binary tick-log, ported pure-TS + zero-dep from the
|
|
2
|
+
// Python reference (sim-in-a-box/sib/jsong.py). Telemetry, NOT genome: a JSONG file
|
|
3
|
+
// is referenced by the ledger via its sha256, never imported into the canonical_form
|
|
4
|
+
// contract. Fixed little-endian layout: 48-byte file header + N × 280-byte records.
|
|
5
|
+
//
|
|
6
|
+
// Python struct formats (the source of truth this port reproduces byte-for-byte):
|
|
7
|
+
// header: "<4sHH16s16sQ" magic, version, reserved, gig_id, agent_id, start_us
|
|
8
|
+
// tick: "<II HH I 59f d 20s" tick_idx, delta_us, role, reserved, flags, state_59, score, slug
|
|
9
|
+
export const MAGIC = new Uint8Array([0x6a, 0x53, 0x4e, 0x47]); // b"jSNG"
|
|
10
|
+
export const FILE_HEADER_SIZE = 48;
|
|
11
|
+
export const TICK_RECORD_SIZE = 280;
|
|
12
|
+
export const STATE_DIM = 59;
|
|
13
|
+
export const SLUG_SIZE = 20;
|
|
14
|
+
export const ROLE_OBSERVATION = 0;
|
|
15
|
+
export const ROLE_SPEC = 1;
|
|
16
|
+
export const ROLE_VERDICT = 2;
|
|
17
|
+
export const FLAG_MUSICAL = 1 << 0;
|
|
18
|
+
export const FLAG_ANOMALY = 1 << 1;
|
|
19
|
+
export const FLAG_BOUNDARY = 1 << 2;
|
|
20
|
+
export const FLAG_CLAIM_NUMERIC = 1 << 3;
|
|
21
|
+
export const FLAG_CLAIM_STRING = 1 << 4;
|
|
22
|
+
export const FLAG_CLAIM_IMPORT_REQUIRED = 1 << 5;
|
|
23
|
+
export const FLAG_CLAIM_IMPORT_FORBIDDEN = 1 << 6;
|
|
24
|
+
export const FLAG_CLAIM_NO_CYCLES = 1 << 7;
|
|
25
|
+
export const FLAG_BAND_PROFILE = 1 << 8;
|
|
26
|
+
export class JsongError extends Error {
|
|
27
|
+
}
|
|
28
|
+
function fitBytes(src, n) {
|
|
29
|
+
// left-justified, null-padded/truncated to exactly n bytes (Python "<16s"/"<20s")
|
|
30
|
+
const out = new Uint8Array(n);
|
|
31
|
+
out.set(src.subarray(0, n));
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
const enc = new TextEncoder();
|
|
35
|
+
const dec = new TextDecoder();
|
|
36
|
+
export function packHeader(h) {
|
|
37
|
+
const buf = new Uint8Array(FILE_HEADER_SIZE);
|
|
38
|
+
const dv = new DataView(buf.buffer);
|
|
39
|
+
buf.set(MAGIC, 0);
|
|
40
|
+
dv.setUint16(4, h.version, true);
|
|
41
|
+
dv.setUint16(6, 0, true); // reserved
|
|
42
|
+
buf.set(fitBytes(h.gig_id, 16), 8);
|
|
43
|
+
buf.set(fitBytes(h.agent_id, 16), 24);
|
|
44
|
+
dv.setBigUint64(40, h.start_us, true);
|
|
45
|
+
return buf;
|
|
46
|
+
}
|
|
47
|
+
export function unpackHeader(buf) {
|
|
48
|
+
if (buf.length < FILE_HEADER_SIZE)
|
|
49
|
+
throw new JsongError(`header truncated: ${buf.length} < ${FILE_HEADER_SIZE}`);
|
|
50
|
+
for (let i = 0; i < 4; i++) {
|
|
51
|
+
if (buf[i] !== MAGIC[i])
|
|
52
|
+
throw new JsongError("bad magic (expected jSNG)");
|
|
53
|
+
}
|
|
54
|
+
const dv = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
55
|
+
return {
|
|
56
|
+
version: dv.getUint16(4, true),
|
|
57
|
+
gig_id: buf.slice(8, 24),
|
|
58
|
+
agent_id: buf.slice(24, 40),
|
|
59
|
+
start_us: dv.getBigUint64(40, true),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export function packTick(rec) {
|
|
63
|
+
if (rec.state_59.length !== STATE_DIM)
|
|
64
|
+
throw new JsongError(`state_59 must be ${STATE_DIM} floats, got ${rec.state_59.length}`);
|
|
65
|
+
if (rec.role !== ROLE_OBSERVATION && rec.role !== ROLE_SPEC && rec.role !== ROLE_VERDICT) {
|
|
66
|
+
throw new JsongError(`invalid role ${rec.role}`);
|
|
67
|
+
}
|
|
68
|
+
const buf = new Uint8Array(TICK_RECORD_SIZE);
|
|
69
|
+
const dv = new DataView(buf.buffer);
|
|
70
|
+
dv.setUint32(0, rec.tick_idx, true);
|
|
71
|
+
dv.setUint32(4, rec.delta_us, true);
|
|
72
|
+
dv.setUint16(8, rec.role, true);
|
|
73
|
+
dv.setUint16(10, 0, true); // reserved
|
|
74
|
+
dv.setUint32(12, rec.flags, true);
|
|
75
|
+
for (let i = 0; i < STATE_DIM; i++)
|
|
76
|
+
dv.setFloat32(16 + i * 4, rec.state_59[i], true);
|
|
77
|
+
dv.setFloat64(252, rec.score, true);
|
|
78
|
+
buf.set(fitBytes(enc.encode(rec.slug), SLUG_SIZE), 260);
|
|
79
|
+
return buf;
|
|
80
|
+
}
|
|
81
|
+
export function unpackTick(buf) {
|
|
82
|
+
if (buf.length < TICK_RECORD_SIZE)
|
|
83
|
+
throw new JsongError(`tick truncated: ${buf.length} < ${TICK_RECORD_SIZE}`);
|
|
84
|
+
const dv = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
85
|
+
const role = dv.getUint16(8, true);
|
|
86
|
+
if (role !== ROLE_OBSERVATION && role !== ROLE_SPEC && role !== ROLE_VERDICT)
|
|
87
|
+
throw new JsongError(`invalid role ${role}`);
|
|
88
|
+
const state_59 = new Array(STATE_DIM);
|
|
89
|
+
for (let i = 0; i < STATE_DIM; i++)
|
|
90
|
+
state_59[i] = dv.getFloat32(16 + i * 4, true);
|
|
91
|
+
const slugBytes = buf.slice(260, 280);
|
|
92
|
+
let end = slugBytes.length;
|
|
93
|
+
while (end > 0 && slugBytes[end - 1] === 0)
|
|
94
|
+
end--; // strip null padding
|
|
95
|
+
return {
|
|
96
|
+
tick_idx: dv.getUint32(0, true),
|
|
97
|
+
delta_us: dv.getUint32(4, true),
|
|
98
|
+
role,
|
|
99
|
+
flags: dv.getUint32(12, true),
|
|
100
|
+
state_59,
|
|
101
|
+
score: dv.getFloat64(252, true),
|
|
102
|
+
slug: dec.decode(slugBytes.subarray(0, end)),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** Decode a whole JSONG buffer (header + N ticks). Mirrors Python read_all. */
|
|
106
|
+
export function readAll(data) {
|
|
107
|
+
if (data.length < FILE_HEADER_SIZE)
|
|
108
|
+
throw new JsongError(`file truncated: ${data.length} < ${FILE_HEADER_SIZE}`);
|
|
109
|
+
const header = unpackHeader(data.subarray(0, FILE_HEADER_SIZE));
|
|
110
|
+
const body = data.subarray(FILE_HEADER_SIZE);
|
|
111
|
+
if (body.length % TICK_RECORD_SIZE !== 0)
|
|
112
|
+
throw new JsongError(`body size ${body.length} not a multiple of ${TICK_RECORD_SIZE}`);
|
|
113
|
+
const ticks = [];
|
|
114
|
+
for (let off = 0; off < body.length; off += TICK_RECORD_SIZE) {
|
|
115
|
+
ticks.push(unpackTick(body.subarray(off, off + TICK_RECORD_SIZE)));
|
|
116
|
+
}
|
|
117
|
+
return { header, ticks };
|
|
118
|
+
}
|
|
119
|
+
/** Encode a header + ticks into a single JSONG buffer. */
|
|
120
|
+
export function writeAll(header, ticks) {
|
|
121
|
+
const out = new Uint8Array(FILE_HEADER_SIZE + ticks.length * TICK_RECORD_SIZE);
|
|
122
|
+
out.set(packHeader(header), 0);
|
|
123
|
+
ticks.forEach((t, i) => out.set(packTick(t), FILE_HEADER_SIZE + i * TICK_RECORD_SIZE));
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
/** A zero-valued 59-float state vector (Python empty_state). */
|
|
127
|
+
export function emptyState() {
|
|
128
|
+
return new Array(STATE_DIM).fill(0);
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=jsong.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsong.js","sourceRoot":"","sources":["../../src/jsong.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,oFAAoF;AACpF,qFAAqF;AACrF,oFAAoF;AACpF,EAAE;AACF,kFAAkF;AAClF,kFAAkF;AAClF,mGAAmG;AAEnG,MAA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-aware extractor, whose docstring named
|
|
4
|
+
* the shared one as broken. That fix was never back-ported, and the copy was itself only a
|
|
5
|
+
* half-fix: it enumerated candidate END positions from a FIXED start, so it still threw on
|
|
6
|
+
* `The set {a,b} matters.\n{"ok":true}` and still silently returned the illustrative
|
|
7
|
+
* preamble object for `For example {"foo":"bar"} … {"title":"REAL"}`. Its step-3 fallback
|
|
8
|
+
* then re-invoked the broken shared extractor.
|
|
9
|
+
*
|
|
10
|
+
* There is now ONE implementation (claude_invoker.ts), consumed by all four production
|
|
11
|
+
* call sites. Re-exported so existing importers of the judge's `extractJson` keep working
|
|
12
|
+
* — they now get the shared, fully-fixed function.
|
|
13
|
+
*/
|
|
14
|
+
export { extractJson };
|
|
15
|
+
/** One turn of a user-flow transcript — the raw signal the SENSE phase parses. */
|
|
16
|
+
export interface UserFlowTurn {
|
|
17
|
+
/** What the user (Eugene's intent surrogate) actually asked for in this turn. */
|
|
18
|
+
user_intent: string;
|
|
19
|
+
/** Claude's natural-language response (no parsing — verbatim text). */
|
|
20
|
+
claude_response: string;
|
|
21
|
+
/** The coltrane MCP tools claude invoked during this turn. May be empty. */
|
|
22
|
+
tool_calls: Array<{
|
|
23
|
+
tool_name: string;
|
|
24
|
+
args?: Record<string, unknown> | null;
|
|
25
|
+
}>;
|
|
26
|
+
/** Snapshot of the genome state AFTER this turn — null for read-only turns. */
|
|
27
|
+
post_turn_genome_state?: Record<string, unknown> | null;
|
|
28
|
+
/** Marker: the user_intent was deliberately malformed (typo/garbage/contradiction). */
|
|
29
|
+
malformed_input?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** A full user-flow transcript — sequence of turns scored as one flow. */
|
|
32
|
+
export type UserFlowTranscript = UserFlowTurn[];
|
|
33
|
+
/** The five criteria the standard defines. Adding one here requires updating the standard. */
|
|
34
|
+
export declare const USER_FLOW_CRITERIA: readonly ["tool_pick_appropriate", "response_faithful", "genome_state_valid", "typed_error_on_malformed", "multi_turn_continuity"];
|
|
35
|
+
export type UserFlowCriterion = (typeof USER_FLOW_CRITERIA)[number];
|
|
36
|
+
export interface CriterionScore {
|
|
37
|
+
score: number | null;
|
|
38
|
+
rationale: string;
|
|
39
|
+
}
|
|
40
|
+
export interface JudgeVerdict {
|
|
41
|
+
criteria: Record<UserFlowCriterion, CriterionScore>;
|
|
42
|
+
/** Sum of non-null scores, range [0.0, 5.0], or null if all null. */
|
|
43
|
+
overall_score: number | null;
|
|
44
|
+
/** True iff overall_score >= pass_threshold_sum (from the standard's scoring block). */
|
|
45
|
+
overall_pass: boolean;
|
|
46
|
+
/** The single most load-bearing observation, grounded in a specific turn. */
|
|
47
|
+
top_finding: string;
|
|
48
|
+
/** Raw outputs of each phase — kept for debug + REPRO comparison. */
|
|
49
|
+
raw: {
|
|
50
|
+
sense: Record<string, unknown> | null;
|
|
51
|
+
interpret: Record<string, unknown> | null;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Minimal shape of the standard JSON we read (we don't pin every key). */
|
|
55
|
+
export interface SoftJudgeStandard {
|
|
56
|
+
slug: string;
|
|
57
|
+
prompt_templates: {
|
|
58
|
+
sense: string;
|
|
59
|
+
interpret: string;
|
|
60
|
+
};
|
|
61
|
+
scoring?: {
|
|
62
|
+
pass_threshold_per_criterion?: number;
|
|
63
|
+
overall_pass_threshold_sum?: number;
|
|
64
|
+
overall_pass_threshold_max?: number;
|
|
65
|
+
noise_band_repro?: number;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** Options for the LLM-subprocess invocation. */
|
|
69
|
+
export interface ScoreUserFlowOptions {
|
|
70
|
+
/** Claude CLI binary. Default "claude". */
|
|
71
|
+
bin?: string;
|
|
72
|
+
/** Per-phase timeout in ms. Default 240_000 (4 min — judges can take time). */
|
|
73
|
+
timeoutMs?: number;
|
|
74
|
+
/** Inject a custom run() to test the prompt-building path without the subprocess. */
|
|
75
|
+
run?: (bin: string, args: string[]) => string;
|
|
76
|
+
}
|
|
77
|
+
/** Load a soft-judge standard from disk. Thin convenience over readFileSync+JSON.parse. */
|
|
78
|
+
export declare function loadStandard(path: string): SoftJudgeStandard;
|
|
79
|
+
export declare function lastRawStdout(): {
|
|
80
|
+
sense: string;
|
|
81
|
+
interpret: string;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Score a user-flow transcript against a soft-judge standard. Runs SENSE + INTERPRET
|
|
85
|
+
* phases via real `claude -p` subprocesses, returns a structured verdict.
|
|
86
|
+
*
|
|
87
|
+
* NOT mocked. Each call spawns claude twice (one per phase). Allow ~30-90s wall time.
|
|
88
|
+
*/
|
|
89
|
+
export declare function scoreUserFlow(transcript: UserFlowTranscript, standard: SoftJudgeStandard, opts?: ScoreUserFlowOptions): Promise<JudgeVerdict>;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// user_flow_judge — LLM-judge module for user-flow behavioral correctness.
|
|
2
|
+
//
|
|
3
|
+
// Extends groove/phase16's soft-judge pattern (sub_thread_invocation) to score
|
|
4
|
+
// USER-FLOW behavioral correctness rather than sub-thread invocation. Gap-1 in the
|
|
5
|
+
// phase-15 ecosystem: every deterministic spec asserts hard outcomes; zero tests
|
|
6
|
+
// score whether claude PICKED the right coltrane tool for a fuzzy user intent.
|
|
7
|
+
//
|
|
8
|
+
// API:
|
|
9
|
+
// scoreUserFlow(transcript, standard) -> JudgeVerdict
|
|
10
|
+
//
|
|
11
|
+
// The judge invokes a real `claude -p` subprocess (no mocks). It reads the
|
|
12
|
+
// standard's prompt_templates and feeds them — SENSE first to normalize the
|
|
13
|
+
// transcript, INTERPRET second to score the criteria. Returns a structured
|
|
14
|
+
// verdict with per-criterion score + rationale + overall pass/fail at the
|
|
15
|
+
// configured threshold.
|
|
16
|
+
import { execFileSync } from "node:child_process";
|
|
17
|
+
import { writeFileSync, unlinkSync, readFileSync } from "node:fs";
|
|
18
|
+
import { tmpdir } from "node:os";
|
|
19
|
+
import { join } from "node:path";
|
|
20
|
+
import { randomUUID } from "node:crypto";
|
|
21
|
+
import { extractJson } from "../claude_invoker.js";
|
|
22
|
+
/**
|
|
23
|
+
* #226 — this module used to carry its OWN string-aware extractor, whose docstring named
|
|
24
|
+
* the shared one as broken. That fix was never back-ported, and the copy was itself only a
|
|
25
|
+
* half-fix: it enumerated candidate END positions from a FIXED start, so it still threw on
|
|
26
|
+
* `The set {a,b} matters.\n{"ok":true}` and still silently returned the illustrative
|
|
27
|
+
* preamble object for `For example {"foo":"bar"} … {"title":"REAL"}`. Its step-3 fallback
|
|
28
|
+
* then re-invoked the broken shared extractor.
|
|
29
|
+
*
|
|
30
|
+
* There is now ONE implementation (claude_invoker.ts), consumed by all four production
|
|
31
|
+
* call sites. Re-exported so existing importers of the judge's `extractJson` keep working
|
|
32
|
+
* — they now get the shared, fully-fixed function.
|
|
33
|
+
*/
|
|
34
|
+
export { extractJson };
|
|
35
|
+
/** The five criteria the standard defines. Adding one here requires updating the standard. */
|
|
36
|
+
export const USER_FLOW_CRITERIA = [
|
|
37
|
+
"tool_pick_appropriate",
|
|
38
|
+
"response_faithful",
|
|
39
|
+
"genome_state_valid",
|
|
40
|
+
"typed_error_on_malformed",
|
|
41
|
+
"multi_turn_continuity",
|
|
42
|
+
];
|
|
43
|
+
// ──────────────────────────── helpers ────────────────────────────
|
|
44
|
+
/** Load a soft-judge standard from disk. Thin convenience over readFileSync+JSON.parse. */
|
|
45
|
+
export function loadStandard(path) {
|
|
46
|
+
const raw = JSON.parse(readFileSync(path, "utf-8"));
|
|
47
|
+
if (!raw.prompt_templates || typeof raw.prompt_templates.sense !== "string" || typeof raw.prompt_templates.interpret !== "string") {
|
|
48
|
+
throw new Error(`standard at ${path} missing prompt_templates.sense/interpret`);
|
|
49
|
+
}
|
|
50
|
+
return raw;
|
|
51
|
+
}
|
|
52
|
+
function buildSensePrompt(template, transcript) {
|
|
53
|
+
return [
|
|
54
|
+
`# Standard: user_flow_correctness`,
|
|
55
|
+
`# Phase: sense`,
|
|
56
|
+
``,
|
|
57
|
+
`## Phase prompt_template`,
|
|
58
|
+
template,
|
|
59
|
+
``,
|
|
60
|
+
`## Gig input`,
|
|
61
|
+
JSON.stringify({ transcript_json: JSON.stringify(transcript) }, null, 2),
|
|
62
|
+
``,
|
|
63
|
+
`## Raw transcript (already JSON; included for direct reference)`,
|
|
64
|
+
"```json",
|
|
65
|
+
JSON.stringify(transcript, null, 2),
|
|
66
|
+
"```",
|
|
67
|
+
``,
|
|
68
|
+
`Respond with ONLY a single JSON object — no prose, no code fence, no markdown.`,
|
|
69
|
+
].join("\n");
|
|
70
|
+
}
|
|
71
|
+
function buildInterpretPrompt(template, senseOutput) {
|
|
72
|
+
return [
|
|
73
|
+
`# Standard: user_flow_correctness`,
|
|
74
|
+
`# Phase: interpret`,
|
|
75
|
+
``,
|
|
76
|
+
`## Phase prompt_template`,
|
|
77
|
+
template,
|
|
78
|
+
``,
|
|
79
|
+
`## Gig input`,
|
|
80
|
+
JSON.stringify({ trace: senseOutput }, null, 2),
|
|
81
|
+
``,
|
|
82
|
+
`## Upstream output (user-flow-transcript from SENSE)`,
|
|
83
|
+
"```json",
|
|
84
|
+
JSON.stringify(senseOutput, null, 2),
|
|
85
|
+
"```",
|
|
86
|
+
``,
|
|
87
|
+
`Respond with ONLY a single JSON object — no prose, no code fence, no markdown.`,
|
|
88
|
+
].join("\n");
|
|
89
|
+
}
|
|
90
|
+
/** Invoke claude CLI once with a prompt, return raw stdout. */
|
|
91
|
+
function invokeClaude(prompt, opts) {
|
|
92
|
+
const cfgPath = join(tmpdir(), `coltrane-uf-judge-mcp-${randomUUID()}.json`);
|
|
93
|
+
writeFileSync(cfgPath, JSON.stringify({ mcpServers: {} }));
|
|
94
|
+
try {
|
|
95
|
+
const args = ["-p", prompt, "--mcp-config", cfgPath, "--strict-mcp-config"];
|
|
96
|
+
if (opts.run)
|
|
97
|
+
return opts.run(opts.bin, args);
|
|
98
|
+
return execFileSync(opts.bin, args, {
|
|
99
|
+
encoding: "utf-8",
|
|
100
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
101
|
+
timeout: opts.timeoutMs,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
try {
|
|
106
|
+
unlinkSync(cfgPath);
|
|
107
|
+
}
|
|
108
|
+
catch { /* best-effort */ }
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Stash the most-recent raw stdout for each phase, for debug + REPRO inspection. */
|
|
112
|
+
const RAW_STDOUT_LOG = { sense: "", interpret: "" };
|
|
113
|
+
export function lastRawStdout() {
|
|
114
|
+
return { ...RAW_STDOUT_LOG };
|
|
115
|
+
}
|
|
116
|
+
/** Build an empty criteria block (used when SENSE produces no turns). */
|
|
117
|
+
function unjudgeableCriteria(reason) {
|
|
118
|
+
const out = {};
|
|
119
|
+
for (const c of USER_FLOW_CRITERIA) {
|
|
120
|
+
out[c] = { score: null, rationale: reason };
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
/** Normalize whatever the LLM returned into a JudgeVerdict, defensively. */
|
|
125
|
+
function normalizeInterpretOutput(raw, sense, passThresholdSum) {
|
|
126
|
+
const rawCriteria = (raw["criteria"] ?? {});
|
|
127
|
+
const criteria = {};
|
|
128
|
+
let sum = 0;
|
|
129
|
+
let anyNonNull = false;
|
|
130
|
+
for (const c of USER_FLOW_CRITERIA) {
|
|
131
|
+
const entry = rawCriteria[c] ?? {};
|
|
132
|
+
const score = typeof entry.score === "number" ? entry.score : null;
|
|
133
|
+
const rationale = typeof entry.rationale === "string" ? entry.rationale : "(no rationale returned)";
|
|
134
|
+
criteria[c] = { score, rationale };
|
|
135
|
+
if (score !== null) {
|
|
136
|
+
sum += score;
|
|
137
|
+
anyNonNull = true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const overall_score = anyNonNull ? sum : null;
|
|
141
|
+
const overall_pass = overall_score !== null && overall_score >= passThresholdSum;
|
|
142
|
+
const top_finding = typeof raw["top_finding"] === "string" ? raw["top_finding"] : "(no top finding returned)";
|
|
143
|
+
return {
|
|
144
|
+
criteria,
|
|
145
|
+
overall_score,
|
|
146
|
+
overall_pass,
|
|
147
|
+
top_finding,
|
|
148
|
+
raw: { sense, interpret: raw },
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
// ───────────────────────────── public API ─────────────────────────────
|
|
152
|
+
/**
|
|
153
|
+
* Score a user-flow transcript against a soft-judge standard. Runs SENSE + INTERPRET
|
|
154
|
+
* phases via real `claude -p` subprocesses, returns a structured verdict.
|
|
155
|
+
*
|
|
156
|
+
* NOT mocked. Each call spawns claude twice (one per phase). Allow ~30-90s wall time.
|
|
157
|
+
*/
|
|
158
|
+
export async function scoreUserFlow(transcript, standard, opts = {}) {
|
|
159
|
+
const bin = opts.bin ?? "claude";
|
|
160
|
+
const timeoutMs = opts.timeoutMs ?? 240_000;
|
|
161
|
+
const passThresholdSum = standard.scoring?.overall_pass_threshold_sum ?? 3.0;
|
|
162
|
+
// SENSE
|
|
163
|
+
const sensePrompt = buildSensePrompt(standard.prompt_templates.sense, transcript);
|
|
164
|
+
let senseOut = null;
|
|
165
|
+
try {
|
|
166
|
+
const stdout = invokeClaude(sensePrompt, { bin, timeoutMs, ...(opts.run ? { run: opts.run } : {}) });
|
|
167
|
+
RAW_STDOUT_LOG.sense = stdout;
|
|
168
|
+
senseOut = extractJson(stdout);
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
172
|
+
return {
|
|
173
|
+
criteria: unjudgeableCriteria(`SENSE invocation failed: ${msg.slice(0, 200)}`),
|
|
174
|
+
overall_score: null,
|
|
175
|
+
overall_pass: false,
|
|
176
|
+
top_finding: `SENSE phase failed: ${msg.slice(0, 200)}`,
|
|
177
|
+
raw: { sense: null, interpret: null },
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
// INTERPRET
|
|
181
|
+
const interpretPrompt = buildInterpretPrompt(standard.prompt_templates.interpret, senseOut);
|
|
182
|
+
let interpretOut;
|
|
183
|
+
try {
|
|
184
|
+
const stdout = invokeClaude(interpretPrompt, { bin, timeoutMs, ...(opts.run ? { run: opts.run } : {}) });
|
|
185
|
+
RAW_STDOUT_LOG.interpret = stdout;
|
|
186
|
+
interpretOut = extractJson(stdout);
|
|
187
|
+
}
|
|
188
|
+
catch (e) {
|
|
189
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
190
|
+
return {
|
|
191
|
+
criteria: unjudgeableCriteria(`INTERPRET invocation failed: ${msg.slice(0, 200)}`),
|
|
192
|
+
overall_score: null,
|
|
193
|
+
overall_pass: false,
|
|
194
|
+
top_finding: `INTERPRET phase failed: ${msg.slice(0, 200)}`,
|
|
195
|
+
raw: { sense: senseOut, interpret: null },
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return normalizeInterpretOutput(interpretOut, senseOut, passThresholdSum);
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=user_flow_judge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user_flow_judge.js","sourceRoot":"","sources":["../../../src/judges/user_flow_judge.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,+EAA+E;AAC/E,mFAAmF;AACnF,iFAAiF;AACjF,+EAA+E;AAC/E,EAAE;AACF,OAAO;AACP,wDAAwD;AACxD,EAAE;AACF,2EAA2E;AAC3E,4EAA4E;AAC5E,2EAA2E;AAC3E,0EAA0E;AAC1E,wBAAwB;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC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;YACnB,YAAY,EAAE,KAAK;YACnB,WAAW,EAAE,2BAA2B,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;YAC3D,GAAG,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE;SAC1C,CAAC;IACJ,CAAC;IAED,OAAO,wBAAwB,CAAC,YAAY,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ModelTier } from "./pricing.js";
|
|
2
|
+
export interface GigObservation {
|
|
3
|
+
gig_id: string;
|
|
4
|
+
agent_slug: string;
|
|
5
|
+
primitive: string;
|
|
6
|
+
model_tier_used: ModelTier;
|
|
7
|
+
success: boolean;
|
|
8
|
+
cost: number;
|
|
9
|
+
duration_ms: number;
|
|
10
|
+
}
|
|
11
|
+
export interface LearnerProposeDowngradeInput {
|
|
12
|
+
agent_slug: string;
|
|
13
|
+
from_tier: ModelTier;
|
|
14
|
+
to_tier: ModelTier;
|
|
15
|
+
observations: GigObservation[];
|
|
16
|
+
auto_approve_as?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface DowngradeProposal {
|
|
19
|
+
agent_slug: string;
|
|
20
|
+
from_tier: ModelTier;
|
|
21
|
+
to_tier: ModelTier;
|
|
22
|
+
data_points: number;
|
|
23
|
+
evidence_summary: {
|
|
24
|
+
success_rate: number;
|
|
25
|
+
avg_cost: number;
|
|
26
|
+
avg_duration_ms: number;
|
|
27
|
+
};
|
|
28
|
+
requires_human_approval: boolean;
|
|
29
|
+
auto_approved: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface LearnerProposeDowngradeResult {
|
|
32
|
+
ok: boolean;
|
|
33
|
+
violation?: "insufficient_evidence";
|
|
34
|
+
proposal?: DowngradeProposal;
|
|
35
|
+
}
|
|
36
|
+
export declare function learnerProposeDowngrade(input: LearnerProposeDowngradeInput): LearnerProposeDowngradeResult;
|
|
37
|
+
export declare const learnerProposeDowngradeResult: typeof learnerProposeDowngrade;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// E5 impl — learner downgrade proposal with 50-gig floor (§8 constraint 10 applied).
|
|
2
|
+
const MIN_DATA_POINTS = 50;
|
|
3
|
+
export function learnerProposeDowngrade(input) {
|
|
4
|
+
const n = input.observations.length;
|
|
5
|
+
if (n < MIN_DATA_POINTS) {
|
|
6
|
+
return { ok: false, violation: "insufficient_evidence" };
|
|
7
|
+
}
|
|
8
|
+
const successCount = input.observations.filter((o) => o.success).length;
|
|
9
|
+
const totalCost = input.observations.reduce((a, o) => a + o.cost, 0);
|
|
10
|
+
const totalDuration = input.observations.reduce((a, o) => a + o.duration_ms, 0);
|
|
11
|
+
// §8 constraint 11: coltrane cannot self-approve
|
|
12
|
+
const approverIsColtrane = !!input.auto_approve_as &&
|
|
13
|
+
(input.auto_approve_as === "coltrane" || input.auto_approve_as.startsWith("coltrane:"));
|
|
14
|
+
const proposal = {
|
|
15
|
+
agent_slug: input.agent_slug,
|
|
16
|
+
from_tier: input.from_tier,
|
|
17
|
+
to_tier: input.to_tier,
|
|
18
|
+
data_points: n,
|
|
19
|
+
evidence_summary: {
|
|
20
|
+
success_rate: successCount / n,
|
|
21
|
+
avg_cost: totalCost / n,
|
|
22
|
+
avg_duration_ms: totalDuration / n,
|
|
23
|
+
},
|
|
24
|
+
requires_human_approval: true,
|
|
25
|
+
auto_approved: !approverIsColtrane && !!input.auto_approve_as,
|
|
26
|
+
};
|
|
27
|
+
return { ok: true, proposal };
|
|
28
|
+
}
|
|
29
|
+
export const learnerProposeDowngradeResult = learnerProposeDowngrade;
|
|
30
|
+
//# sourceMappingURL=learner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"learner.js","sourceRoot":"","sources":["../../src/learner.ts"],"names":[],"mappings":"AAAA,qFAAqF;AA0CrF,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,MAAM,UAAU,uBAAu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