@tangle-network/braid 0.3.8 → 0.3.9

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.
Files changed (97) hide show
  1. package/README.md +1 -0
  2. package/THIRD_PARTY_LICENSES.json +1 -1
  3. package/dist/adapters/analysis/managed-analysis-runtime.js +1 -1
  4. package/dist/adapters/tui/learning-dispatch.d.ts.map +1 -1
  5. package/dist/adapters/tui/learning-dispatch.js +20 -3
  6. package/dist/adapters/tui/learning-dispatch.js.map +1 -1
  7. package/dist/app/canary/canary-ledger.d.ts +72 -0
  8. package/dist/app/canary/canary-ledger.d.ts.map +1 -0
  9. package/dist/app/canary/canary-ledger.js +161 -0
  10. package/dist/app/canary/canary-ledger.js.map +1 -0
  11. package/dist/app/canary/canary-observe.d.ts +58 -0
  12. package/dist/app/canary/canary-observe.d.ts.map +1 -0
  13. package/dist/app/canary/canary-observe.js +115 -0
  14. package/dist/app/canary/canary-observe.js.map +1 -0
  15. package/dist/app/canary/canary-pack.d.ts +53 -0
  16. package/dist/app/canary/canary-pack.d.ts.map +1 -0
  17. package/dist/app/canary/canary-pack.js +100 -0
  18. package/dist/app/canary/canary-pack.js.map +1 -0
  19. package/dist/app/canary/canary-protocol.d.ts +111 -0
  20. package/dist/app/canary/canary-protocol.d.ts.map +1 -0
  21. package/dist/app/canary/canary-protocol.js +260 -0
  22. package/dist/app/canary/canary-protocol.js.map +1 -0
  23. package/dist/app/learning/instruction-blocks.d.ts +100 -0
  24. package/dist/app/learning/instruction-blocks.d.ts.map +1 -0
  25. package/dist/app/learning/instruction-blocks.js +373 -0
  26. package/dist/app/learning/instruction-blocks.js.map +1 -0
  27. package/dist/app/learning/learner-measure.d.ts.map +1 -1
  28. package/dist/app/learning/learner-measure.js +3 -0
  29. package/dist/app/learning/learner-measure.js.map +1 -1
  30. package/dist/app/learning/learner-profile.d.ts +3 -1
  31. package/dist/app/learning/learner-profile.d.ts.map +1 -1
  32. package/dist/app/learning/learner-profile.js +12 -7
  33. package/dist/app/learning/learner-profile.js.map +1 -1
  34. package/dist/app/learning/learning-actions.d.ts +3 -1
  35. package/dist/app/learning/learning-actions.d.ts.map +1 -1
  36. package/dist/app/learning/learning-actions.js +23 -3
  37. package/dist/app/learning/learning-actions.js.map +1 -1
  38. package/dist/app/learning/learning-candidates.d.ts +11 -2
  39. package/dist/app/learning/learning-candidates.d.ts.map +1 -1
  40. package/dist/app/learning/learning-candidates.js +119 -9
  41. package/dist/app/learning/learning-candidates.js.map +1 -1
  42. package/dist/app/learning/learning-profile.d.ts +2 -0
  43. package/dist/app/learning/learning-profile.d.ts.map +1 -1
  44. package/dist/app/learning/learning-profile.js +2 -2
  45. package/dist/app/learning/learning-profile.js.map +1 -1
  46. package/dist/app/learning/learning-sources.d.ts +4 -2
  47. package/dist/app/learning/learning-sources.d.ts.map +1 -1
  48. package/dist/app/learning/learning-sources.js +3 -3
  49. package/dist/app/learning/learning-sources.js.map +1 -1
  50. package/dist/app/learning/learning-types.d.ts +16 -1
  51. package/dist/app/learning/learning-types.d.ts.map +1 -1
  52. package/dist/app/run-event-mapper.d.ts.map +1 -1
  53. package/dist/app/run-event-mapper.js +6 -0
  54. package/dist/app/run-event-mapper.js.map +1 -1
  55. package/dist/app/run-execution.d.ts.map +1 -1
  56. package/dist/app/run-execution.js +4 -2
  57. package/dist/app/run-execution.js.map +1 -1
  58. package/dist/app/run-ingestion.d.ts.map +1 -1
  59. package/dist/app/run-ingestion.js +27 -3
  60. package/dist/app/run-ingestion.js.map +1 -1
  61. package/dist/app/run-stream-coalescing.d.ts +16 -0
  62. package/dist/app/run-stream-coalescing.d.ts.map +1 -0
  63. package/dist/app/run-stream-coalescing.js +185 -0
  64. package/dist/app/run-stream-coalescing.js.map +1 -0
  65. package/dist/bin/args.d.ts +1 -1
  66. package/dist/bin/args.d.ts.map +1 -1
  67. package/dist/bin/args.js +2 -0
  68. package/dist/bin/args.js.map +1 -1
  69. package/dist/bin/braid.js +5 -0
  70. package/dist/bin/braid.js.map +1 -1
  71. package/dist/bin/canary-command.d.ts +16 -0
  72. package/dist/bin/canary-command.d.ts.map +1 -0
  73. package/dist/bin/canary-command.js +192 -0
  74. package/dist/bin/canary-command.js.map +1 -0
  75. package/dist/bin/production-setup-application.d.ts +6 -0
  76. package/dist/bin/production-setup-application.d.ts.map +1 -1
  77. package/dist/bin/production-setup-application.js +4 -0
  78. package/dist/bin/production-setup-application.js.map +1 -1
  79. package/dist/domain/events-legacy.d.ts +2 -0
  80. package/dist/domain/events-legacy.d.ts.map +1 -1
  81. package/dist/domain/reducer-support.d.ts.map +1 -1
  82. package/dist/domain/reducer-support.js +5 -3
  83. package/dist/domain/reducer-support.js.map +1 -1
  84. package/dist/domain/runtime-events.d.ts +5 -0
  85. package/dist/domain/runtime-events.d.ts.map +1 -1
  86. package/dist/domain/runtime-events.js.map +1 -1
  87. package/dist/testing/learning-fixture.d.ts +5 -2
  88. package/dist/testing/learning-fixture.d.ts.map +1 -1
  89. package/dist/testing/learning-fixture.js +8 -3
  90. package/dist/testing/learning-fixture.js.map +1 -1
  91. package/dist/views/headless/rpc-parser.d.ts.map +1 -1
  92. package/dist/views/headless/rpc-parser.js +1 -0
  93. package/dist/views/headless/rpc-parser.js.map +1 -1
  94. package/dist/views/tui/transcript.d.ts.map +1 -1
  95. package/dist/views/tui/transcript.js +15 -3
  96. package/dist/views/tui/transcript.js.map +1 -1
  97. package/package.json +2 -2
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Learn a procedure pack per skill from the user's past sessions.
3
+ *
4
+ * A procedure contract states procedures as trace-contract rules over what an
5
+ * agent ran and said, for example "a check's output is never piped into
6
+ * `tail`". Braid reads every Claude Code and Codex session in the window,
7
+ * checks each against the contract while reading it, and for each skill
8
+ * counts the sessions that used the skill and broke each rule. A skill's pack
9
+ * is the procedures its own sessions broke most, each with how often, in the
10
+ * words the procedure catalog gives the rule. A skill whose sessions broke no
11
+ * rule often enough gets no pack, so a brief naming it is not eligible.
12
+ */
13
+ import type { TraceContractSpec } from '@tangle-network/agent-eval';
14
+ import { type HarnessSessionPaths } from '../learning/learning-sources.js';
15
+ import type { PackManifest } from './canary-protocol.js';
16
+ export interface LearnPacksOptions {
17
+ readonly contract: TraceContractSpec;
18
+ /** Each rule label of the contract, as the procedure to follow. */
19
+ readonly procedures: Readonly<Record<string, string>>;
20
+ readonly out: string;
21
+ readonly sinceMs: number;
22
+ readonly untilMs: number;
23
+ readonly paths: HarnessSessionPaths;
24
+ /** Only these skills; default every skill the sessions invoked. */
25
+ readonly skills?: readonly string[];
26
+ /** A skill needs this many checked sessions to get a pack. Default 5. */
27
+ readonly minSessions?: number;
28
+ /** A procedure enters a pack when this many of the skill's sessions broke it. Default 2. */
29
+ readonly minRuleSessions?: number;
30
+ /** Procedures per pack. Default 6. */
31
+ readonly maxProcedures?: number;
32
+ }
33
+ export interface LearnedSkill {
34
+ readonly sessions: number;
35
+ /** Sessions whose check could not evaluate a rule; they are left out of `sessions`. */
36
+ readonly unchecked: number;
37
+ readonly rules: readonly {
38
+ readonly rule: string;
39
+ readonly sessions: number;
40
+ }[];
41
+ readonly file: string | null;
42
+ readonly digest: string | null;
43
+ }
44
+ export interface LearnedPacks extends PackManifest {
45
+ readonly since: string;
46
+ readonly until: string;
47
+ readonly contract: string;
48
+ readonly contractDigest: string;
49
+ readonly sessionsRead: number;
50
+ readonly learned: Readonly<Record<string, LearnedSkill>>;
51
+ }
52
+ export declare function learnPacks(options: LearnPacksOptions): Promise<LearnedPacks>;
53
+ //# sourceMappingURL=canary-pack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canary-pack.d.ts","sourceRoot":"","sources":["../../../src/app/canary/canary-pack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAGnE,OAAO,EACL,KAAK,mBAAmB,EAGzB,MAAM,iCAAiC,CAAA;AAExC,OAAO,KAAK,EAAE,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Q,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAA;CACzD;AAsBD,wBAAsB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CA+ElF"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Learn a procedure pack per skill from the user's past sessions.
3
+ *
4
+ * A procedure contract states procedures as trace-contract rules over what an
5
+ * agent ran and said, for example "a check's output is never piped into
6
+ * `tail`". Braid reads every Claude Code and Codex session in the window,
7
+ * checks each against the contract while reading it, and for each skill
8
+ * counts the sessions that used the skill and broke each rule. A skill's pack
9
+ * is the procedures its own sessions broke most, each with how often, in the
10
+ * words the procedure catalog gives the rule. A skill whose sessions broke no
11
+ * rule often enough gets no pack, so a brief naming it is not eligible.
12
+ */
13
+ import { chmodSync, mkdirSync, writeFileSync } from 'node:fs';
14
+ import { join } from 'node:path';
15
+ import { canonicalJson } from '../../domain/canonical.js';
16
+ import { AppError } from '../errors.js';
17
+ import { readHarnessSessions, sessionsInvoking, } from '../learning/learning-sources.js';
18
+ import { canaryDigest } from './canary-ledger.js';
19
+ function packText(skill, sessions, since, until, lines) {
20
+ return [
21
+ `## Procedures learned from past ${skill} sessions`,
22
+ '',
23
+ `Braid read ${sessions} sessions from ${since.slice(0, 10)} to ${until.slice(0, 10)} that used ${skill}.`,
24
+ 'Agents in them broke these procedures. Follow each one in this task.',
25
+ '',
26
+ ...lines.map((line) => `- ${line.procedure} (broken in ${line.sessions} of ${sessions} sessions)`),
27
+ '',
28
+ ].join('\n');
29
+ }
30
+ export async function learnPacks(options) {
31
+ const { compileTraceContractSpec } = await import('@tangle-network/agent-eval');
32
+ const contract = compileTraceContractSpec(options.contract);
33
+ const labels = (options.contract.rules ?? []).map((rule) => rule.label);
34
+ if (labels.length === 0 || labels.some((label) => typeof label !== 'string'))
35
+ throw new AppError('CANARY_CONTRACT_INVALID', 'Every procedure rule needs a label');
36
+ for (const label of labels)
37
+ if (typeof options.procedures[label] !== 'string' || options.procedures[label] === '')
38
+ throw new AppError('CANARY_PROCEDURE_MISSING', `The catalog gives no procedure for ${label}`);
39
+ const minSessions = options.minSessions ?? 5;
40
+ const minRuleSessions = options.minRuleSessions ?? 2;
41
+ const maxProcedures = options.maxProcedures ?? 6;
42
+ const since = new Date(options.sinceMs).toISOString();
43
+ const until = new Date(options.untilMs).toISOString();
44
+ const read = await readHarnessSessions(options.paths, options.sinceMs, { contracts: [contract] });
45
+ const window = read.sessions.filter((session) => session.endedAt === null || Date.parse(session.endedAt) < options.untilMs);
46
+ const skills = options.skills ?? [...new Set((read.usage?.rows ?? []).map((row) => row.skill))].sort();
47
+ mkdirSync(options.out, { recursive: true, mode: 0o700 });
48
+ chmodSync(options.out, 0o700);
49
+ const manifest = {};
50
+ const learned = {};
51
+ for (const skill of skills) {
52
+ const invoking = sessionsInvoking(window, skill, options.sinceMs);
53
+ const checks = invoking.map((session) => session.contractChecks?.[0]);
54
+ const checked = checks.filter((check) => check !== undefined && check.status !== 'error');
55
+ const counts = new Map();
56
+ for (const check of checked)
57
+ for (const [rule, violations] of Object.entries(check?.violations ?? {}))
58
+ if (violations > 0)
59
+ counts.set(rule, (counts.get(rule) ?? 0) + 1);
60
+ const rules = [...counts]
61
+ .map(([rule, sessions]) => ({ rule, sessions }))
62
+ .sort((a, b) => b.sessions - a.sessions || a.rule.localeCompare(b.rule));
63
+ const chosen = checked.length < minSessions
64
+ ? []
65
+ : rules.filter((rule) => rule.sessions >= minRuleSessions).slice(0, maxProcedures);
66
+ let file = null;
67
+ let digest = null;
68
+ if (chosen.length > 0) {
69
+ const text = packText(skill, checked.length, since, until, chosen.map((rule) => ({
70
+ procedure: options.procedures[rule.rule],
71
+ sessions: rule.sessions,
72
+ })));
73
+ file = `${skill.replace(/[^A-Za-z0-9_.-]/gu, '_')}.md`;
74
+ digest = canaryDigest(text);
75
+ writeFileSync(join(options.out, file), text, { mode: 0o600 });
76
+ manifest[skill] = { file, digest };
77
+ }
78
+ learned[skill] = {
79
+ sessions: checked.length,
80
+ unchecked: invoking.length - checked.length,
81
+ rules,
82
+ file,
83
+ digest,
84
+ };
85
+ }
86
+ const result = {
87
+ since,
88
+ until,
89
+ contract: options.contract.name,
90
+ contractDigest: canaryDigest(canonicalJson(options.contract)),
91
+ sessionsRead: window.length,
92
+ skills: manifest,
93
+ learned,
94
+ };
95
+ writeFileSync(join(options.out, 'manifest.json'), `${JSON.stringify(result, null, 2)}\n`, {
96
+ mode: 0o600,
97
+ });
98
+ return result;
99
+ }
100
+ //# sourceMappingURL=canary-pack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canary-pack.js","sourceRoot":"","sources":["../../../src/app/canary/canary-pack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAEL,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAuCjD,SAAS,QAAQ,CACf,KAAa,EACb,QAAgB,EAChB,KAAa,EACb,KAAa,EACb,KAA2E;IAE3E,OAAO;QACL,mCAAmC,KAAK,WAAW;QACnD,EAAE;QACF,cAAc,QAAQ,kBAAkB,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,cAAc,KAAK,GAAG;QACzG,sEAAsE;QACtE,EAAE;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AI,EAAE;QACxF,IAAI,EAAE,KAAK;KACZ,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * The randomized canary of learned procedure packs.
3
+ *
4
+ * A delegated task brief is the assignment unit and the repository it changes
5
+ * is the cluster. Control gets the brief as written; candidate gets the brief
6
+ * followed by the pack Braid learned from the named skill's past sessions.
7
+ * Both arms carry one line that the task's pull requests repeat, so the
8
+ * outcome checker can find them.
9
+ *
10
+ * The protocol is sealed into the ledger's first entry before any assignment:
11
+ * the eligibility rule, the randomizer's seed commitment, every pack's digest,
12
+ * the served revision, the outcome checker, the cutoff and the maturity. The
13
+ * analysis rule inside it is sealed by agent-eval, so the readout's decision
14
+ * refuses any protocol other than this one.
15
+ */
16
+ import type { RandomizedCanaryRule } from '@tangle-network/agent-eval/experiment';
17
+ import { type CanaryArm } from './canary-ledger.js';
18
+ export declare const PROTOCOL_SCHEMA = "braid.canary-protocol.v1";
19
+ export declare const ASSIGNMENT_LINE_PREFIX = "Braid-Assignment:";
20
+ /** What the operator writes; Braid adds the digests it can compute and seals the rest. */
21
+ export interface CanaryProtocolInput {
22
+ readonly experimentId: string;
23
+ readonly question: string;
24
+ /** The eligibility rule in words, beyond what Braid enforces: which briefs are routed here. */
25
+ readonly eligibility: {
26
+ readonly unit: string;
27
+ readonly repositoryCap: number;
28
+ };
29
+ readonly served: {
30
+ readonly braidVersion: string;
31
+ readonly braidCommit: string;
32
+ };
33
+ /** The registered outcome: its definition, the checker's revision and digest. */
34
+ readonly outcome: Readonly<Record<string, unknown>> & {
35
+ readonly checkerDigest: string;
36
+ };
37
+ readonly secondary?: Readonly<Record<string, unknown>>;
38
+ readonly power?: Readonly<Record<string, unknown>>;
39
+ readonly readoutAt: string;
40
+ /** The analysis rule's registered fields; Braid supplies every digest field. */
41
+ readonly analysis: Omit<RandomizedCanaryRule, 'experimentId' | 'eligibilityRuleDigest' | 'controlProfileDigest' | 'candidateProfileDigest' | 'servedCodeRevisionDigest' | 'outcomeCheckerDigest' | 'assignmentUnit' | 'clusterUnit'>;
42
+ }
43
+ /** The pack set a seal freezes: one file per skill, named by its digest. */
44
+ export interface PackManifest {
45
+ readonly skills: Readonly<Record<string, {
46
+ readonly file: string;
47
+ readonly digest: string;
48
+ }>>;
49
+ }
50
+ export interface CanaryConfig {
51
+ /** The ledger file, inside a git checkout whose `origin` is the ledger's remote. */
52
+ readonly ledger: string;
53
+ /** The randomizer's secret seed: 32 or more bytes, readable only by its owner. */
54
+ readonly seed: string;
55
+ /** The directory holding the sealed packs and their `manifest.json`. */
56
+ readonly packs: string;
57
+ }
58
+ export declare function readCanaryConfig(path: string): CanaryConfig;
59
+ /** The seed's commitment; revealing the seed at readout lets anyone recompute every arm. */
60
+ export declare function seedDigest(seed: Buffer): string;
61
+ /** One fair bit per task: the low bit of HMAC-SHA256(seed, experiment NUL task). */
62
+ export declare function armFor(seed: Buffer, experimentId: string, taskId: string): CanaryArm;
63
+ /** Names the assignment in both arms without revealing which. */
64
+ export declare function assignmentIdFor(experimentId: string, taskId: string): string;
65
+ export interface SealResult {
66
+ readonly experimentId: string;
67
+ readonly protocolDigest: string;
68
+ readonly entryDigest: string;
69
+ readonly skills: readonly string[];
70
+ }
71
+ /** Seal the protocol as the ledger's first entry. Refuses a ledger that already holds one. */
72
+ export declare function sealCanary(config: CanaryConfig, input: CanaryProtocolInput, now?: () => Date): Promise<SealResult>;
73
+ export interface AssignResult {
74
+ readonly status: 'assigned' | 'existing' | 'ineligible';
75
+ readonly experimentId: string;
76
+ readonly assignmentId: string | null;
77
+ readonly arm: CanaryArm | null;
78
+ readonly skill: string;
79
+ readonly repository: string;
80
+ readonly packDigest: string | null;
81
+ /** The pack text, in the candidate arm only. */
82
+ readonly pack: string | null;
83
+ /** The line every pull request of the task repeats; null when ineligible. */
84
+ readonly assignmentLine: string | null;
85
+ /** What to append to the brief: the pack in the candidate arm, then the assignment instruction. */
86
+ readonly append: string | null;
87
+ readonly reason: string | null;
88
+ }
89
+ /** Assign one task, or return the assignment it already holds. Every arrival is recorded. */
90
+ export declare function assignTask(config: CanaryConfig, request: {
91
+ readonly taskId: string;
92
+ readonly skill: string;
93
+ readonly repository: string;
94
+ }, now?: () => Date): AssignResult;
95
+ export interface CanaryStatus {
96
+ readonly experimentId: string;
97
+ readonly protocolDigest: string;
98
+ readonly sealedAt: string;
99
+ readonly acceptsUntil: string;
100
+ readonly readoutAt: string;
101
+ readonly entries: number;
102
+ readonly tipDigest: string;
103
+ readonly assignments: {
104
+ readonly control: number;
105
+ readonly candidate: number;
106
+ };
107
+ readonly repositories: number;
108
+ readonly dispositions: number;
109
+ }
110
+ export declare function canaryStatus(config: CanaryConfig): CanaryStatus;
111
+ //# sourceMappingURL=canary-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canary-protocol.d.ts","sourceRoot":"","sources":["../../../src/app/canary/canary-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAA;AAGjF,OAAO,EAGL,KAAK,SAAS,EAMf,MAAM,oBAAoB,CAAA;AAE3B,eAAO,MAAM,eAAe,6BAA6B,CAAA;AACzD,eAAO,MAAM,sBAAsB,sBAAsB,CAAA;AAEzD,0FAA0F;AAC1F,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,+FAA+F;IAC/F,QAAQ,CAAC,WAAW,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAA;IAC/E,QAAQ,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAA;IAChF,iF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gB,UAAU,CACxB,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,EACzF,GAAG,GAAE,MAAM,IAAuB,GACjC,YAAY,CA8Fd;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,WAAW,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAA;IAC9E,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAC9B;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAsB/D"}
@@ -0,0 +1,260 @@
1
+ /**
2
+ * The randomized canary of learned procedure packs.
3
+ *
4
+ * A delegated task brief is the assignment unit and the repository it changes
5
+ * is the cluster. Control gets the brief as written; candidate gets the brief
6
+ * followed by the pack Braid learned from the named skill's past sessions.
7
+ * Both arms carry one line that the task's pull requests repeat, so the
8
+ * outcome checker can find them.
9
+ *
10
+ * The protocol is sealed into the ledger's first entry before any assignment:
11
+ * the eligibility rule, the randomizer's seed commitment, every pack's digest,
12
+ * the served revision, the outcome checker, the cutoff and the maturity. The
13
+ * analysis rule inside it is sealed by agent-eval, so the readout's decision
14
+ * refuses any protocol other than this one.
15
+ */
16
+ import { createHmac } from 'node:crypto';
17
+ import { existsSync, readFileSync, statSync } from 'node:fs';
18
+ import { join } from 'node:path';
19
+ import { canonicalJson } from '../../domain/canonical.js';
20
+ import { AppError } from '../errors.js';
21
+ import { appendLedger, readLedger, canaryDigest, syncLedger, } from './canary-ledger.js';
22
+ export const PROTOCOL_SCHEMA = 'braid.canary-protocol.v1';
23
+ export const ASSIGNMENT_LINE_PREFIX = 'Braid-Assignment:';
24
+ export function readCanaryConfig(path) {
25
+ let value;
26
+ try {
27
+ value = JSON.parse(readFileSync(path, 'utf8'));
28
+ }
29
+ catch (error) {
30
+ throw new AppError('CANARY_CONFIG_UNREADABLE', `Cannot read the canary configuration ${path}: ${error instanceof Error ? error.message : String(error)}`);
31
+ }
32
+ const config = value;
33
+ for (const key of ['ledger', 'seed', 'packs'])
34
+ if (typeof config[key] !== 'string' || config[key] === '')
35
+ throw new AppError('CANARY_CONFIG_INVALID', `The canary configuration needs "${key}"`);
36
+ return config;
37
+ }
38
+ function readSeed(path) {
39
+ const mode = statSync(path).mode & 0o077;
40
+ if (mode !== 0)
41
+ throw new AppError('CANARY_SEED_EXPOSED', `The seed ${path} is readable by others`);
42
+ const seed = readFileSync(path);
43
+ if (seed.byteLength < 32)
44
+ throw new AppError('CANARY_SEED_SHORT', 'The seed needs 32 or more bytes');
45
+ return seed;
46
+ }
47
+ /** The seed's commitment; revealing the seed at readout lets anyone recompute every arm. */
48
+ export function seedDigest(seed) {
49
+ return `sha256:${createHmac('sha256', seed).update('braid-canary-seed-commitment').digest('hex')}`;
50
+ }
51
+ /** One fair bit per task: the low bit of HMAC-SHA256(seed, experiment NUL task). */
52
+ export function armFor(seed, experimentId, taskId) {
53
+ const mac = createHmac('sha256', seed).update(`${experimentId}\u0000${taskId}`).digest();
54
+ return (mac[0] & 1) === 1 ? 'candidate' : 'control';
55
+ }
56
+ /** Names the assignment in both arms without revealing which. */
57
+ export function assignmentIdFor(experimentId, taskId) {
58
+ return `ba-${canaryDigest(`${experimentId}\u0000${taskId}`).slice('sha256:'.length, 'sha256:'.length + 16)}`;
59
+ }
60
+ function readManifest(directory) {
61
+ const path = join(directory, 'manifest.json');
62
+ if (!existsSync(path))
63
+ throw new AppError('CANARY_PACKS_MISSING', `No pack manifest at ${path}`);
64
+ return JSON.parse(readFileSync(path, 'utf8'));
65
+ }
66
+ function packText(directory, file, digest) {
67
+ const text = readFileSync(join(directory, file), 'utf8');
68
+ if (canaryDigest(text) !== digest)
69
+ throw new AppError('CANARY_PACK_CHANGED', `The pack ${file} no longer matches its sealed digest`);
70
+ return text;
71
+ }
72
+ /** Seal the protocol as the ledger's first entry. Refuses a ledger that already holds one. */
73
+ export async function sealCanary(config, input, now = () => new Date()) {
74
+ const { sealRandomizedCanaryRule } = await import('@tangle-network/agent-eval/experiment');
75
+ const seed = readSeed(config.seed);
76
+ const manifest = readManifest(config.packs);
77
+ const skills = Object.keys(manifest.skills).sort();
78
+ if (skills.length === 0)
79
+ throw new AppError('CANARY_PACKS_EMPTY', 'The pack manifest names no skill');
80
+ const packs = {};
81
+ for (const skill of skills) {
82
+ const pack = manifest.skills[skill];
83
+ packText(config.packs, pack.file, pack.digest);
84
+ packs[skill] = pack.digest;
85
+ }
86
+ if (!Number.isSafeInteger(input.eligibility.repositoryCap) || input.eligibility.repositoryCap < 1)
87
+ throw new AppError('CANARY_PROTOCOL_INVALID', 'repositoryCap must be a positive integer');
88
+ const eligibility = {
89
+ unit: input.eligibility.unit,
90
+ skills: packs,
91
+ repositoryCap: input.eligibility.repositoryCap,
92
+ acceptsUntil: input.analysis.analysisCutoff,
93
+ };
94
+ const randomizer = {
95
+ method: 'hmac-sha256-low-bit',
96
+ input: 'experimentId NUL taskId',
97
+ candidateShare: 0.5,
98
+ seedDigest: seedDigest(seed),
99
+ };
100
+ const sealed = sealRandomizedCanaryRule({
101
+ ...input.analysis,
102
+ experimentId: input.experimentId,
103
+ eligibilityRuleDigest: canaryDigest(canonicalJson({ eligibility, randomizer })),
104
+ controlProfileDigest: canaryDigest(canonicalJson({ packs: {} })),
105
+ candidateProfileDigest: canaryDigest(canonicalJson({ packs })),
106
+ servedCodeRevisionDigest: `git:${input.served.braidCommit}`,
107
+ outcomeCheckerDigest: input.outcome.checkerDigest,
108
+ assignmentUnit: 'task',
109
+ clusterUnit: 'repository',
110
+ });
111
+ const protocol = {
112
+ schema: PROTOCOL_SCHEMA,
113
+ question: input.question,
114
+ eligibility,
115
+ randomizer,
116
+ arms: {
117
+ control: 'the brief as written, with the assignment line',
118
+ candidate: "the brief followed by the skill's sealed pack, with the assignment line",
119
+ },
120
+ assignmentLine: `${ASSIGNMENT_LINE_PREFIX} <assignmentId>`,
121
+ served: input.served,
122
+ outcome: input.outcome,
123
+ ...(input.secondary === undefined ? {} : { secondary: input.secondary }),
124
+ ...(input.power === undefined ? {} : { power: input.power }),
125
+ readoutAt: input.readoutAt,
126
+ rule: sealed.rule,
127
+ };
128
+ appendLedger(config.ledger, (entries) => {
129
+ if (entries.length > 0)
130
+ throw new AppError('CANARY_ALREADY_SEALED', 'The ledger already holds a sealed protocol');
131
+ return {
132
+ append: {
133
+ kind: 'protocol',
134
+ experimentId: input.experimentId,
135
+ protocolDigest: sealed.digest,
136
+ protocol,
137
+ },
138
+ result: null,
139
+ };
140
+ }, now);
141
+ const first = readLedger(config.ledger)[0];
142
+ return {
143
+ experimentId: input.experimentId,
144
+ protocolDigest: sealed.digest,
145
+ entryDigest: first.digest,
146
+ skills,
147
+ };
148
+ }
149
+ function protocolOf(entries) {
150
+ const first = entries[0];
151
+ if (first === undefined || first.kind !== 'protocol')
152
+ throw new AppError('CANARY_NOT_SEALED', 'The ledger holds no sealed protocol; nothing is assigned before the seal');
153
+ return first;
154
+ }
155
+ const REPOSITORY = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u;
156
+ function instruction(line) {
157
+ return `Put this exact line in the body of every pull request this task opens:\n${line}`;
158
+ }
159
+ /** Assign one task, or return the assignment it already holds. Every arrival is recorded. */
160
+ export function assignTask(config, request, now = () => new Date()) {
161
+ const taskId = request.taskId.trim();
162
+ if (taskId === '' || taskId.length > 200)
163
+ throw new AppError('CANARY_TASK_INVALID', 'A task id is 1 to 200 characters');
164
+ if (!REPOSITORY.test(request.repository))
165
+ throw new AppError('CANARY_REPOSITORY_INVALID', 'The repository is owner/name');
166
+ const seed = readSeed(config.seed);
167
+ return appendLedger(config.ledger, (entries) => {
168
+ const sealed = protocolOf(entries);
169
+ const experimentId = sealed.experimentId;
170
+ const eligibility = sealed.protocol.eligibility;
171
+ const held = entries.find((entry) => entry.kind === 'assignment' && entry.taskId === taskId);
172
+ const result = (status, entry) => {
173
+ const manifest = readManifest(config.packs);
174
+ const file = manifest.skills[entry.skill]?.file;
175
+ const pack = entry.arm === 'candidate'
176
+ ? packText(config.packs, file ?? `${entry.skill}.md`, entry.packDigest)
177
+ : null;
178
+ const line = `${ASSIGNMENT_LINE_PREFIX} ${entry.assignmentId}`;
179
+ return {
180
+ status,
181
+ experimentId,
182
+ assignmentId: entry.assignmentId,
183
+ arm: entry.arm,
184
+ skill: entry.skill,
185
+ repository: entry.repository,
186
+ packDigest: entry.packDigest,
187
+ pack,
188
+ assignmentLine: line,
189
+ append: pack === null ? instruction(line) : `${pack.trimEnd()}\n\n${instruction(line)}`,
190
+ reason: null,
191
+ };
192
+ };
193
+ if (held !== undefined)
194
+ return { append: null, result: result('existing', held) };
195
+ const turnedAway = (reason) => ({
196
+ append: {
197
+ kind: 'disposition',
198
+ experimentId,
199
+ taskId,
200
+ skill: request.skill,
201
+ repository: request.repository,
202
+ reason,
203
+ },
204
+ result: {
205
+ status: 'ineligible',
206
+ experimentId,
207
+ assignmentId: null,
208
+ arm: null,
209
+ skill: request.skill,
210
+ repository: request.repository,
211
+ packDigest: null,
212
+ pack: null,
213
+ assignmentLine: null,
214
+ append: null,
215
+ reason,
216
+ },
217
+ });
218
+ if (now().getTime() >= Date.parse(eligibility.acceptsUntil))
219
+ return turnedAway(`the cutoff ${eligibility.acceptsUntil} has passed`);
220
+ const packDigest = eligibility.skills[request.skill];
221
+ if (packDigest === undefined)
222
+ return turnedAway(`no sealed pack for the skill ${request.skill}`);
223
+ const inRepository = entries.filter((entry) => entry.kind === 'assignment' && entry.repository === request.repository).length;
224
+ if (inRepository >= eligibility.repositoryCap)
225
+ return turnedAway(`${request.repository} already holds ${inRepository} assignments, the cap`);
226
+ const assignment = {
227
+ kind: 'assignment',
228
+ experimentId,
229
+ assignmentId: assignmentIdFor(experimentId, taskId),
230
+ taskId,
231
+ skill: request.skill,
232
+ repository: request.repository,
233
+ arm: armFor(seed, experimentId, taskId),
234
+ packDigest,
235
+ };
236
+ return { append: assignment, result: result('assigned', assignment) };
237
+ }, now);
238
+ }
239
+ export function canaryStatus(config) {
240
+ syncLedger(config.ledger);
241
+ const entries = readLedger(config.ledger);
242
+ const sealed = protocolOf(entries);
243
+ const assignments = entries.filter((entry) => entry.kind === 'assignment');
244
+ return {
245
+ experimentId: sealed.experimentId,
246
+ protocolDigest: sealed.protocolDigest,
247
+ sealedAt: sealed.at,
248
+ acceptsUntil: sealed.protocol.eligibility.acceptsUntil,
249
+ readoutAt: String(sealed.protocol.readoutAt),
250
+ entries: entries.length,
251
+ tipDigest: entries.at(-1).digest,
252
+ assignments: {
253
+ control: assignments.filter((entry) => entry.arm === 'control').length,
254
+ candidate: assignments.filter((entry) => entry.arm === 'candidate').length,
255
+ },
256
+ repositories: new Set(assignments.map((entry) => entry.repository)).size,
257
+ dispositions: entries.filter((entry) => entry.kind === 'disposition').length,
258
+ };
259
+ }
260
+ //# sourceMappingURL=canary-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canary-protocol.js","sourceRoot":"","sources":["../../../src/app/canary/canary-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,Y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