@ashlr/hub 3.2.7 → 3.3.2
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/CHANGELOG.md +314 -2
- package/README.md +54 -38
- package/dist/build-identity.json +2 -2
- package/dist/cli/audit.js +18 -0
- package/dist/cli/audit.js.map +1 -1
- package/dist/cli/backlog.d.ts +0 -5
- package/dist/cli/backlog.js +18 -0
- package/dist/cli/backlog.js.map +1 -1
- package/dist/cli/comms.js +20 -0
- package/dist/cli/comms.js.map +1 -1
- package/dist/cli/completions.d.ts +6 -1
- package/dist/cli/completions.js +33 -10
- package/dist/cli/completions.js.map +1 -1
- package/dist/cli/daemon.js +10 -3
- package/dist/cli/daemon.js.map +1 -1
- package/dist/cli/dashboard.js +5 -4
- package/dist/cli/dashboard.js.map +1 -1
- package/dist/cli/demo.d.ts +0 -27
- package/dist/cli/demo.js +17 -0
- package/dist/cli/demo.js.map +1 -1
- package/dist/cli/help.js +22 -9
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/inbox.d.ts +14 -2
- package/dist/cli/inbox.js +137 -23
- package/dist/cli/inbox.js.map +1 -1
- package/dist/cli/onboard.d.ts +0 -13
- package/dist/cli/onboard.js +20 -0
- package/dist/cli/onboard.js.map +1 -1
- package/dist/cli/resources.js +15 -0
- package/dist/cli/resources.js.map +1 -1
- package/dist/cli/run.js +1 -1
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/sandbox.js +43 -0
- package/dist/cli/sandbox.js.map +1 -1
- package/dist/cli/serve.js +7 -3
- package/dist/cli/serve.js.map +1 -1
- package/dist/cli/setup.d.ts +5 -3
- package/dist/cli/setup.js +14 -7
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli/tui.d.ts +0 -6
- package/dist/cli/tui.js +14 -0
- package/dist/cli/tui.js.map +1 -1
- package/dist/cli/update.js +3 -1
- package/dist/cli/update.js.map +1 -1
- package/dist/core/config.js +70 -0
- package/dist/core/config.js.map +1 -1
- package/dist/core/daemon/loop.js +83 -3
- package/dist/core/daemon/loop.js.map +1 -1
- package/dist/core/daemon/runtime-activation-resident-start-protocol.d.ts +141 -0
- package/dist/core/daemon/runtime-activation-resident-start-protocol.js +462 -0
- package/dist/core/daemon/runtime-activation-resident-start-protocol.js.map +1 -0
- package/dist/core/daemon/runtime-activation-resident-start-runtime.d.ts +27 -0
- package/dist/core/daemon/runtime-activation-resident-start-runtime.js +28 -0
- package/dist/core/daemon/runtime-activation-resident-start-runtime.js.map +1 -0
- package/dist/core/daemon/runtime-activation-stopped-consumer.d.ts +139 -0
- package/dist/core/daemon/runtime-activation-stopped-consumer.js +995 -0
- package/dist/core/daemon/runtime-activation-stopped-consumer.js.map +1 -0
- package/dist/core/daemon/runtime-activation-stopped-runtime.d.ts +36 -0
- package/dist/core/daemon/runtime-activation-stopped-runtime.js +134 -0
- package/dist/core/daemon/runtime-activation-stopped-runtime.js.map +1 -0
- package/dist/core/daemon/runtime-activation-transaction.d.ts +41 -17
- package/dist/core/daemon/runtime-activation-transaction.js +80 -11
- package/dist/core/daemon/runtime-activation-transaction.js.map +1 -1
- package/dist/core/daemon/runtime-release-dependency-inventory.js +1 -0
- package/dist/core/daemon/runtime-release-dependency-inventory.js.map +1 -1
- package/dist/core/daemon/service-install-authority.d.ts +1 -1
- package/dist/core/daemon/service-install-authority.js +4 -2
- package/dist/core/daemon/service-install-authority.js.map +1 -1
- package/dist/core/dashboard.d.ts +10 -0
- package/dist/core/dashboard.js +103 -28
- package/dist/core/dashboard.js.map +1 -1
- package/dist/core/effective-config.js +7 -0
- package/dist/core/effective-config.js.map +1 -1
- package/dist/core/fleet/automerge-pass.js +57 -73
- package/dist/core/fleet/automerge-pass.js.map +1 -1
- package/dist/core/fleet/decisions-ledger.js +36 -13
- package/dist/core/fleet/decisions-ledger.js.map +1 -1
- package/dist/core/fleet/external-skill-git-capture.js +9 -1
- package/dist/core/fleet/external-skill-git-capture.js.map +1 -1
- package/dist/core/fleet/judge-decision-metadata.d.ts +8 -1
- package/dist/core/fleet/judge-decision-metadata.js +14 -1
- package/dist/core/fleet/judge-decision-metadata.js.map +1 -1
- package/dist/core/fleet/judge-trace.js +2 -1
- package/dist/core/fleet/judge-trace.js.map +1 -1
- package/dist/core/fleet/manager.d.ts +21 -1
- package/dist/core/fleet/manager.js +137 -41
- package/dist/core/fleet/manager.js.map +1 -1
- package/dist/core/fleet/post-merge-credit-label.d.ts +10 -0
- package/dist/core/fleet/post-merge-credit-label.js +13 -0
- package/dist/core/fleet/post-merge-credit-label.js.map +1 -0
- package/dist/core/fleet/post-merge-credit.d.ts +119 -12
- package/dist/core/fleet/post-merge-credit.js +353 -14
- package/dist/core/fleet/post-merge-credit.js.map +1 -1
- package/dist/core/fleet/self-improve.d.ts +38 -5
- package/dist/core/fleet/self-improve.js +201 -12
- package/dist/core/fleet/self-improve.js.map +1 -1
- package/dist/core/fleet/skill-library.d.ts +21 -2
- package/dist/core/fleet/skill-library.js +54 -12
- package/dist/core/fleet/skill-library.js.map +1 -1
- package/dist/core/fleet/worked-ledger.d.ts +22 -0
- package/dist/core/fleet/worked-ledger.js +32 -0
- package/dist/core/fleet/worked-ledger.js.map +1 -1
- package/dist/core/goals/store.js +60 -6
- package/dist/core/goals/store.js.map +1 -1
- package/dist/core/inbox/apply.js +2 -1
- package/dist/core/inbox/apply.js.map +1 -1
- package/dist/core/inbox/merge.d.ts +10 -1
- package/dist/core/inbox/merge.js +97 -18
- package/dist/core/inbox/merge.js.map +1 -1
- package/dist/core/integrations/github.d.ts +2 -0
- package/dist/core/integrations/github.js +2 -1
- package/dist/core/integrations/github.js.map +1 -1
- package/dist/core/learn/reflect.d.ts +42 -4
- package/dist/core/learn/reflect.js +66 -5
- package/dist/core/learn/reflect.js.map +1 -1
- package/dist/core/onboard.d.ts +2 -0
- package/dist/core/onboard.js +9 -3
- package/dist/core/onboard.js.map +1 -1
- package/dist/core/run/engines.d.ts +8 -0
- package/dist/core/run/engines.js +9 -1
- package/dist/core/run/engines.js.map +1 -1
- package/dist/core/run/learned-router.js +28 -3
- package/dist/core/run/learned-router.js.map +1 -1
- package/dist/core/run/orchestrator.d.ts +7 -2
- package/dist/core/run/orchestrator.js +88 -60
- package/dist/core/run/orchestrator.js.map +1 -1
- package/dist/core/swarm/rollback.d.ts +11 -0
- package/dist/core/swarm/rollback.js +54 -0
- package/dist/core/swarm/rollback.js.map +1 -1
- package/dist/core/swarm/runner.js +94 -8
- package/dist/core/swarm/runner.js.map +1 -1
- package/dist/core/types.d.ts +103 -3
- package/dist/core/types.js.map +1 -1
- package/dist/core/web/api.d.ts +6 -0
- package/dist/core/web/api.js +174 -18
- package/dist/core/web/api.js.map +1 -1
- package/dist/core/web/control.d.ts +20 -0
- package/dist/core/web/control.js +44 -32
- package/dist/core/web/control.js.map +1 -1
- package/dist/core/web/fleet-status-cache.d.ts +68 -0
- package/dist/core/web/fleet-status-cache.js +120 -0
- package/dist/core/web/fleet-status-cache.js.map +1 -0
- package/dist/core/web/public/app.js +5 -1
- package/dist/core/web/public/next/assets/index-CDHQraxS.css +1 -0
- package/dist/core/web/public/next/assets/index-zVKD9krw.js +69 -0
- package/dist/core/web/public/next/assets/index-zVKD9krw.js.map +1 -0
- package/dist/core/web/public/next/index.html +15 -0
- package/dist/core/web/read-session-revocations.d.ts +26 -0
- package/dist/core/web/read-session-revocations.js +48 -0
- package/dist/core/web/read-session-revocations.js.map +1 -0
- package/dist/core/web/server.js +73 -27
- package/dist/core/web/server.js.map +1 -1
- package/dist/core/web/static.d.ts +1 -1
- package/dist/core/web/static.js +54 -20
- package/dist/core/web/static.js.map +1 -1
- package/dist/release-dependency-inventory.json +1 -1
- package/docs/RUNTIME_ACTIVATION_AUTHORITY.md +115 -21
- package/docs/contracts/CONTRACT-M521.md +102 -0
- package/node_modules/fast-uri/index.js +201 -48
- package/node_modules/fast-uri/lib/schemes.js +9 -4
- package/node_modules/fast-uri/lib/utils.js +388 -91
- package/node_modules/fast-uri/package.json +1 -1
- package/node_modules/fast-uri/test/component-safe-serialization.test.js +105 -0
- package/node_modules/fast-uri/test/equal.test.js +31 -3
- package/node_modules/fast-uri/test/fixtures/uri-js-parse.json +2 -0
- package/node_modules/fast-uri/test/ipv6-canonical.test.js +34 -0
- package/node_modules/fast-uri/test/ipv6-validation.test.js +90 -0
- package/node_modules/fast-uri/test/malformed-percent.test.js +77 -0
- package/node_modules/fast-uri/test/malformed-urn.test.js +61 -0
- package/node_modules/fast-uri/test/parse.test.js +7 -3
- package/node_modules/fast-uri/test/query-fragment-normalization.test.js +33 -0
- package/node_modules/fast-uri/test/reserved-path-normalization.test.js +109 -0
- package/node_modules/fast-uri/test/scheme-validation.test.js +124 -0
- package/node_modules/fast-uri/test/security-normalization.test.js +101 -0
- package/node_modules/fast-uri/test/security.test.js +75 -3
- package/node_modules/fast-uri/test/urn-full-input.test.js +29 -0
- package/node_modules/fast-uri/test/websocket-query-preservation.test.js +24 -0
- package/node_modules/qs/.github/THREAT_MODEL.md +3 -3
- package/node_modules/qs/CHANGELOG.md +26 -0
- package/node_modules/qs/README.md +19 -1
- package/node_modules/qs/dist/qs.js +25 -25
- package/node_modules/qs/eslint.config.mjs +1 -1
- package/node_modules/qs/lib/parse.js +16 -6
- package/node_modules/qs/lib/stringify.js +23 -8
- package/node_modules/qs/lib/utils.js +57 -11
- package/node_modules/qs/package.json +8 -7
- package/node_modules/qs/test/parse.js +419 -0
- package/node_modules/qs/test/stringify.js +317 -0
- package/node_modules/qs/test/utils.js +206 -0
- package/package.json +24 -6
- package/schema/config.schema.json +800 -5
- package/node_modules/which/CHANGELOG.md +0 -166
|
@@ -1,18 +1,125 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Post-merge learning evidence — report-only release protocol.
|
|
3
3
|
*
|
|
4
|
-
* A realized merge is an immutable operational fact, not proof that the
|
|
5
|
-
* remained beneficial.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* A realized merge is an immutable operational fact, not proof that the
|
|
5
|
+
* change remained beneficial. This module is the only prospective release
|
|
6
|
+
* boundary, but it mints no operational authority while the observation source
|
|
7
|
+
* remains adverse-only:
|
|
8
|
+
*
|
|
9
|
+
* 1. The proposal must carry an AUTHENTICATED realized-merge witness
|
|
10
|
+
* (authenticatedRealizedMergeOf — binds to this exact proposal via a
|
|
11
|
+
* local receipt HMAC or host reconciliation; shape alone is never
|
|
12
|
+
* authority).
|
|
13
|
+
* 2. At least MIN_POST_MERGE_OBSERVATION_WINDOW_MS must have elapsed since
|
|
14
|
+
* the merge was observed. The regression sentinel / outcome watcher
|
|
15
|
+
* (outcome-watcher.ts) sweeps merged proposals on a 6h throttle with a
|
|
16
|
+
* 7-day follow-up window; 14 days gives ~2x that follow-up window and
|
|
17
|
+
* dozens of scan cycles of headroom before we trust the silence.
|
|
18
|
+
* 3. The signed, observation-only post-merge-observations ledger
|
|
19
|
+
* (post-merge-observations.ts) must contain NO adverse record
|
|
20
|
+
* ('regressed' | 'reverted' | 'followed-up') for this exact
|
|
21
|
+
* (repo, proposalId, mergeCommit) event, and the ledger must have read
|
|
22
|
+
* back healthy/complete (a degraded read fails closed — we never treat
|
|
23
|
+
* "couldn't check" as "checked clean").
|
|
24
|
+
*
|
|
25
|
+
* That ledger never records a positive "we checked, it's clean" row. Silence
|
|
26
|
+
* after a conservative window is diagnostic only, not positive confirmation;
|
|
27
|
+
* evaluation returns report-only and does not mint a label.
|
|
28
|
+
*
|
|
29
|
+
* HISTORICAL TOKEN SHAPE: the verifier remains fail-closed even for formerly
|
|
30
|
+
* valid HMAC-shaped values while operational release is disabled.
|
|
31
|
+
* isPostMergeCreditReleaseLabel() remains
|
|
32
|
+
* "structural recognition only" — matching the bare literal — for the
|
|
33
|
+
* existing defensive filters elsewhere that specifically reject the
|
|
34
|
+
* unauthenticated literal (e.g. skill-records.ts, decisions-ledger.ts).
|
|
8
35
|
*/
|
|
36
|
+
import type { Proposal, SkillCard } from '../types.js';
|
|
37
|
+
export { POST_MERGE_CREDIT_RELEASE_LABEL, isPostMergeCreditReleaseLabel, } from './post-merge-credit-label.js';
|
|
9
38
|
export declare const POST_MERGE_CREDIT_POLICY_VERSION: "post-merge-credit-v1";
|
|
10
|
-
export declare const POST_MERGE_CREDIT_RELEASE_LABEL: "post-merge-credit-release-v1";
|
|
11
|
-
/** Structural recognition only; this string is not release authority. */
|
|
12
|
-
export declare function isPostMergeCreditReleaseLabel(labelBasis: unknown): boolean;
|
|
13
39
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
40
|
+
* Minimum wall-clock time since the realized merge before credit MAY be
|
|
41
|
+
* released. See module doc for rationale (~2x the outcome-watcher follow-up
|
|
42
|
+
* window, dozens of throttled scan cycles of headroom).
|
|
43
|
+
*/
|
|
44
|
+
export declare const MIN_POST_MERGE_OBSERVATION_WINDOW_MS: number;
|
|
45
|
+
/**
|
|
46
|
+
* Verify that `labelBasis` is a validly-signed post-merge-credit release
|
|
47
|
+
* token minted by evaluatePostMergeCreditRelease. Pure, synchronous
|
|
48
|
+
* (host-local key read only), never throws. Deliberately rejects the bare
|
|
49
|
+
* POST_MERGE_CREDIT_RELEASE_LABEL literal and any other string that is not a
|
|
50
|
+
* correctly-formed, correctly-signed token — so raw ledgers, injected
|
|
51
|
+
* dependencies, and caller-controlled metadata cannot mint credit.
|
|
52
|
+
*/
|
|
53
|
+
export declare function hasReleasedPostMergeCredit(labelBasis: unknown): boolean;
|
|
54
|
+
export type PostMergeCreditEligibilityReason = 'clean-window-elapsed' | 'no-authenticated-merge-witness' | 'invalid-merge-timestamp' | 'observation-window-not-elapsed' | 'observation-ledger-degraded' | 'adverse-outcome-observed' | 'report-only-no-positive-stability-witness' | 'signing-unavailable' | 'error';
|
|
55
|
+
export interface PostMergeCreditEligibility {
|
|
56
|
+
eligible: boolean;
|
|
57
|
+
/** Signed token to persist as labelBasis when eligible; null otherwise. */
|
|
58
|
+
label: string | null;
|
|
59
|
+
reason: PostMergeCreditEligibilityReason;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Determine whether `proposal` has reportable post-merge evidence RIGHT NOW.
|
|
63
|
+
* Operational eligibility remains false until a positive stability witness
|
|
64
|
+
* exists. Fail-closed on every
|
|
65
|
+
* ambiguous path (missing witness, unparseable timestamp, window not yet
|
|
66
|
+
* elapsed, degraded/incomplete observation-ledger read, any adverse
|
|
67
|
+
* observation for this exact merge event, signing failure). Never throws.
|
|
68
|
+
*
|
|
69
|
+
* This function does NOT persist anything — see sweepPostMergeCreditReleases
|
|
70
|
+
* for the write-back that records a minted label to the decisions ledger.
|
|
71
|
+
*/
|
|
72
|
+
export declare function evaluatePostMergeCreditRelease(proposal: Proposal, opts?: {
|
|
73
|
+
nowMs?: number;
|
|
74
|
+
}): PostMergeCreditEligibility;
|
|
75
|
+
export interface PostMergeCreditSweepResult {
|
|
76
|
+
/** Applied proposals inspected this pass. */
|
|
77
|
+
scanned: number;
|
|
78
|
+
/** Proposals for which a new credit-release decision row was recorded. */
|
|
79
|
+
released: number;
|
|
80
|
+
/** Proposals inspected but not released this pass (not yet eligible, or a
|
|
81
|
+
* transient error) — never a reason to trust the negative permanently. */
|
|
82
|
+
skipped: number;
|
|
83
|
+
/** False when the proposal or decisions source was incomplete/degraded, or
|
|
84
|
+
* the candidate cap was hit — a hint the pass should be retried. */
|
|
85
|
+
sourceComplete: boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Sweep applied proposals for post-merge diagnostics. No operational release
|
|
89
|
+
* row is recorded while positive stability witnesses are unavailable.
|
|
90
|
+
*
|
|
91
|
+
* The post-merge-observations ledger only records adverse outcomes. Closing
|
|
92
|
+
* the release path requires a positive, complete "swept clean" witness bound
|
|
93
|
+
* to the exact merge event; elapsed time and silence are insufficient.
|
|
94
|
+
*
|
|
95
|
+
* SCALING NOTE: unlike outcome-watcher.ts, this sweep has no persistent
|
|
96
|
+
* cursor — it re-scans applied proposals from the top of listProposalsDetailed
|
|
97
|
+
* every pass, bounded by MAX_SWEEP_CANDIDATES. At small-to-moderate applied-
|
|
98
|
+
* proposal counts this converges fine (already-released proposals are
|
|
99
|
+
* skipped instantly via the decisions-ledger dedup check, so the cap mostly
|
|
100
|
+
* matters for proposals still awaiting their window). At very large scale a
|
|
101
|
+
* persistent cursor (mirroring monitoring-cursor.ts) would be needed to
|
|
102
|
+
* guarantee every proposal eventually gets swept; out of scope here.
|
|
103
|
+
*
|
|
104
|
+
* Never throws.
|
|
105
|
+
*/
|
|
106
|
+
export declare function sweepPostMergeCreditReleases(opts?: {
|
|
107
|
+
nowMs?: number;
|
|
108
|
+
listProposals?: () => Proposal[];
|
|
109
|
+
}): PostMergeCreditSweepResult;
|
|
110
|
+
/**
|
|
111
|
+
* Sign a SkillCard that legitimately carries released post-merge credit.
|
|
112
|
+
*
|
|
113
|
+
* skill-attestation.ts's generic attestSkillCard() deliberately refuses any
|
|
114
|
+
* card for which hasReleasedPostMergeCredit(card.labelBasis) is true — its
|
|
115
|
+
* signature payload doesn't cover the credit-release claim, so it must not
|
|
116
|
+
* be the thing vouching for it. This module owns that proof, so it owns this
|
|
117
|
+
* signing boundary too: same crypto primitive (signSkillCardAttestation),
|
|
118
|
+
* same payload shape, so verifyAttestedSkillCard() on the read side still
|
|
119
|
+
* validates cards signed here — only the gating differs (this function signs
|
|
120
|
+
* ONLY when hasReleasedPostMergeCredit is true; attestSkillCard signs only
|
|
121
|
+
* when it is false).
|
|
122
|
+
*
|
|
123
|
+
* Never throws.
|
|
17
124
|
*/
|
|
18
|
-
export declare function
|
|
125
|
+
export declare function attestPostMergeCreditSkillCard(card: SkillCard): SkillCard | null;
|
|
@@ -1,23 +1,362 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Post-merge learning evidence — report-only release protocol.
|
|
3
3
|
*
|
|
4
|
-
* A realized merge is an immutable operational fact, not proof that the
|
|
5
|
-
* remained beneficial.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* A realized merge is an immutable operational fact, not proof that the
|
|
5
|
+
* change remained beneficial. This module is the only prospective release
|
|
6
|
+
* boundary, but it mints no operational authority while the observation source
|
|
7
|
+
* remains adverse-only:
|
|
8
|
+
*
|
|
9
|
+
* 1. The proposal must carry an AUTHENTICATED realized-merge witness
|
|
10
|
+
* (authenticatedRealizedMergeOf — binds to this exact proposal via a
|
|
11
|
+
* local receipt HMAC or host reconciliation; shape alone is never
|
|
12
|
+
* authority).
|
|
13
|
+
* 2. At least MIN_POST_MERGE_OBSERVATION_WINDOW_MS must have elapsed since
|
|
14
|
+
* the merge was observed. The regression sentinel / outcome watcher
|
|
15
|
+
* (outcome-watcher.ts) sweeps merged proposals on a 6h throttle with a
|
|
16
|
+
* 7-day follow-up window; 14 days gives ~2x that follow-up window and
|
|
17
|
+
* dozens of scan cycles of headroom before we trust the silence.
|
|
18
|
+
* 3. The signed, observation-only post-merge-observations ledger
|
|
19
|
+
* (post-merge-observations.ts) must contain NO adverse record
|
|
20
|
+
* ('regressed' | 'reverted' | 'followed-up') for this exact
|
|
21
|
+
* (repo, proposalId, mergeCommit) event, and the ledger must have read
|
|
22
|
+
* back healthy/complete (a degraded read fails closed — we never treat
|
|
23
|
+
* "couldn't check" as "checked clean").
|
|
24
|
+
*
|
|
25
|
+
* That ledger never records a positive "we checked, it's clean" row. Silence
|
|
26
|
+
* after a conservative window is diagnostic only, not positive confirmation;
|
|
27
|
+
* evaluation returns report-only and does not mint a label.
|
|
28
|
+
*
|
|
29
|
+
* HISTORICAL TOKEN SHAPE: the verifier remains fail-closed even for formerly
|
|
30
|
+
* valid HMAC-shaped values while operational release is disabled.
|
|
31
|
+
* isPostMergeCreditReleaseLabel() remains
|
|
32
|
+
* "structural recognition only" — matching the bare literal — for the
|
|
33
|
+
* existing defensive filters elsewhere that specifically reject the
|
|
34
|
+
* unauthenticated literal (e.g. skill-records.ts, decisions-ledger.ts).
|
|
8
35
|
*/
|
|
36
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
37
|
+
import { resolve } from 'node:path';
|
|
38
|
+
import { loadOrCreateKey, signSkillCardAttestation } from '../foundry/provenance.js';
|
|
39
|
+
import { authenticatedRealizedMergeOf } from '../inbox/realized-merge.js';
|
|
40
|
+
import { listProposalsDetailed } from '../inbox/store.js';
|
|
41
|
+
import { causalMetadataFromProposal } from '../learning/causal.js';
|
|
42
|
+
import { readDecisions, recordDecision } from './decisions-ledger.js';
|
|
43
|
+
import { postMergeObservationEventId, readPostMergeObservations } from './post-merge-observations.js';
|
|
44
|
+
import { skillCardContentHash } from './skill-attestation.js';
|
|
45
|
+
import { POST_MERGE_CREDIT_RELEASE_LABEL } from './post-merge-credit-label.js';
|
|
46
|
+
export { POST_MERGE_CREDIT_RELEASE_LABEL, isPostMergeCreditReleaseLabel, } from './post-merge-credit-label.js';
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// Structural constants
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
9
50
|
export const POST_MERGE_CREDIT_POLICY_VERSION = 'post-merge-credit-v1';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Operational release remains disabled until a positive, complete stability
|
|
53
|
+
* witness exists. The current adverse-only ledger supports reporting, not
|
|
54
|
+
* authority to steer routing or promote reusable skills.
|
|
55
|
+
*/
|
|
56
|
+
const POST_MERGE_CREDIT_OPERATIONAL_RELEASE = false;
|
|
57
|
+
/**
|
|
58
|
+
* Minimum wall-clock time since the realized merge before credit MAY be
|
|
59
|
+
* released. See module doc for rationale (~2x the outcome-watcher follow-up
|
|
60
|
+
* window, dozens of throttled scan cycles of headroom).
|
|
61
|
+
*/
|
|
62
|
+
export const MIN_POST_MERGE_OBSERVATION_WINDOW_MS = 14 * 24 * 60 * 60 * 1000;
|
|
63
|
+
/** Domain-separated HMAC payload prefix for minted credit tokens. */
|
|
64
|
+
const CREDIT_TOKEN_DOMAIN = 'ashlr:post-merge-credit-release:v1';
|
|
65
|
+
/**
|
|
66
|
+
* Both segments are truncated to 24 hex chars (96 bits each) — plenty for
|
|
67
|
+
* MAC-forgery infeasibility and event-identifier collision-resistance at
|
|
68
|
+
* fleet scale, and DELIBERATELY short for two independent reasons discovered
|
|
69
|
+
* empirically (see test/post-merge-credit-release.test.ts):
|
|
70
|
+
* 1. decisions-ledger.ts's generic secret-scrubber (util/scrub.ts) redacts
|
|
71
|
+
* any bare 64+ char hex run as a likely API key/hash — a 64-char segment
|
|
72
|
+
* would be silently corrupted the moment it passed through
|
|
73
|
+
* recordDecision().
|
|
74
|
+
* 2. recordDecision() -> sanitizeDecisionEntry() unconditionally ends with
|
|
75
|
+
* normalizeDecisionLearningFields() (learning/causal.ts), which re-runs
|
|
76
|
+
* causalMetadata() and applies boundedText(labelBasis, 80) — ANY
|
|
77
|
+
* labelBasis over 80 chars is silently truncated, with no way to opt
|
|
78
|
+
* out from a caller outside that module. The full token
|
|
79
|
+
* ("post-merge-credit-release-v1:" (30 chars) + eventRef + ':' + mac)
|
|
80
|
+
* must fit in 80 chars total, so each hex segment is capped at 24
|
|
81
|
+
* (30 + 24 + 1 + 24 = 79).
|
|
82
|
+
* Neither constraint is owned by this module; 24 hex chars satisfies both
|
|
83
|
+
* with margin.
|
|
84
|
+
*/
|
|
85
|
+
const CREDIT_REF_HEX_CHARS = 24;
|
|
86
|
+
/** `post-merge-credit-release-v1:<event-ref-hex32>:<hmac-hex32>` */
|
|
87
|
+
const CREDIT_TOKEN_RE = new RegExp(`^post-merge-credit-release-v1:([a-f0-9]{${CREDIT_REF_HEX_CHARS}}):([a-f0-9]{${CREDIT_REF_HEX_CHARS}})$`);
|
|
88
|
+
/** Truncate a full sha256 eventId to the reference used inside the token. */
|
|
89
|
+
function creditEventRef(eventId) {
|
|
90
|
+
return eventId.slice(0, CREDIT_REF_HEX_CHARS);
|
|
91
|
+
}
|
|
92
|
+
function computeCreditMac(eventRef) {
|
|
93
|
+
try {
|
|
94
|
+
return createHmac('sha256', loadOrCreateKey())
|
|
95
|
+
.update(`${CREDIT_TOKEN_DOMAIN}:${eventRef}`)
|
|
96
|
+
.digest('hex')
|
|
97
|
+
.slice(0, CREDIT_REF_HEX_CHARS);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function equalHex(left, right) {
|
|
104
|
+
try {
|
|
105
|
+
const a = Buffer.from(left, 'hex');
|
|
106
|
+
const b = Buffer.from(right, 'hex');
|
|
107
|
+
return a.length === b.length && a.length > 0 && timingSafeEqual(a, b);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Verify that `labelBasis` is a validly-signed post-merge-credit release
|
|
115
|
+
* token minted by evaluatePostMergeCreditRelease. Pure, synchronous
|
|
116
|
+
* (host-local key read only), never throws. Deliberately rejects the bare
|
|
117
|
+
* POST_MERGE_CREDIT_RELEASE_LABEL literal and any other string that is not a
|
|
118
|
+
* correctly-formed, correctly-signed token — so raw ledgers, injected
|
|
119
|
+
* dependencies, and caller-controlled metadata cannot mint credit.
|
|
120
|
+
*/
|
|
121
|
+
export function hasReleasedPostMergeCredit(labelBasis) {
|
|
122
|
+
try {
|
|
123
|
+
if (!POST_MERGE_CREDIT_OPERATIONAL_RELEASE)
|
|
124
|
+
return false;
|
|
125
|
+
if (typeof labelBasis !== 'string')
|
|
126
|
+
return false;
|
|
127
|
+
const match = CREDIT_TOKEN_RE.exec(labelBasis);
|
|
128
|
+
if (!match)
|
|
129
|
+
return false;
|
|
130
|
+
const eventRef = match[1];
|
|
131
|
+
const mac = match[2];
|
|
132
|
+
const expected = computeCreditMac(eventRef);
|
|
133
|
+
if (!expected)
|
|
134
|
+
return false;
|
|
135
|
+
return equalHex(mac, expected);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
14
140
|
}
|
|
15
141
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
142
|
+
* Determine whether `proposal` has reportable post-merge evidence RIGHT NOW.
|
|
143
|
+
* Operational eligibility remains false until a positive stability witness
|
|
144
|
+
* exists. Fail-closed on every
|
|
145
|
+
* ambiguous path (missing witness, unparseable timestamp, window not yet
|
|
146
|
+
* elapsed, degraded/incomplete observation-ledger read, any adverse
|
|
147
|
+
* observation for this exact merge event, signing failure). Never throws.
|
|
148
|
+
*
|
|
149
|
+
* This function does NOT persist anything — see sweepPostMergeCreditReleases
|
|
150
|
+
* for the write-back that records a minted label to the decisions ledger.
|
|
151
|
+
*/
|
|
152
|
+
export function evaluatePostMergeCreditRelease(proposal, opts = {}) {
|
|
153
|
+
try {
|
|
154
|
+
if (!proposal || typeof proposal.id !== 'string' || proposal.id.length === 0) {
|
|
155
|
+
return { eligible: false, label: null, reason: 'no-authenticated-merge-witness' };
|
|
156
|
+
}
|
|
157
|
+
const evidence = authenticatedRealizedMergeOf(proposal);
|
|
158
|
+
if (!evidence || typeof proposal.repo !== 'string' || proposal.repo.length === 0) {
|
|
159
|
+
return { eligible: false, label: null, reason: 'no-authenticated-merge-witness' };
|
|
160
|
+
}
|
|
161
|
+
const observedAtIso = evidence.source === 'github-host'
|
|
162
|
+
? evidence.reconciliation.observedAt
|
|
163
|
+
: evidence.observedAt;
|
|
164
|
+
const mergedAtMs = Date.parse(observedAtIso);
|
|
165
|
+
if (!Number.isFinite(mergedAtMs)) {
|
|
166
|
+
return { eligible: false, label: null, reason: 'invalid-merge-timestamp' };
|
|
167
|
+
}
|
|
168
|
+
const nowMs = opts.nowMs ?? Date.now();
|
|
169
|
+
if (nowMs < mergedAtMs || nowMs - mergedAtMs < MIN_POST_MERGE_OBSERVATION_WINDOW_MS) {
|
|
170
|
+
return { eligible: false, label: null, reason: 'observation-window-not-elapsed' };
|
|
171
|
+
}
|
|
172
|
+
let repoAbs;
|
|
173
|
+
try {
|
|
174
|
+
repoAbs = resolve(proposal.repo);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return { eligible: false, label: null, reason: 'no-authenticated-merge-witness' };
|
|
178
|
+
}
|
|
179
|
+
const eventId = postMergeObservationEventId({
|
|
180
|
+
repo: repoAbs,
|
|
181
|
+
proposalId: proposal.id,
|
|
182
|
+
mergeCommit: evidence.mergeCommitOid.toLowerCase(),
|
|
183
|
+
});
|
|
184
|
+
// Adverse-only ledger: absence of a row is the only "clean" signal it can
|
|
185
|
+
// ever give us. A degraded/incomplete read must NOT be treated as clean.
|
|
186
|
+
const read = readPostMergeObservations({ requireComplete: true });
|
|
187
|
+
if (read.sourceState === 'degraded' || !read.complete) {
|
|
188
|
+
return { eligible: false, label: null, reason: 'observation-ledger-degraded' };
|
|
189
|
+
}
|
|
190
|
+
if (read.observations.some((observation) => observation.eventId === eventId)) {
|
|
191
|
+
return { eligible: false, label: null, reason: 'adverse-outcome-observed' };
|
|
192
|
+
}
|
|
193
|
+
// Silence in an adverse-only ledger is useful diagnostic evidence, but it
|
|
194
|
+
// is not positive proof that this exact merge was observed stable. Keep
|
|
195
|
+
// the entire release path report-only until such a witness exists.
|
|
196
|
+
if (!POST_MERGE_CREDIT_OPERATIONAL_RELEASE) {
|
|
197
|
+
return {
|
|
198
|
+
eligible: false,
|
|
199
|
+
label: null,
|
|
200
|
+
reason: 'report-only-no-positive-stability-witness',
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const eventRef = creditEventRef(eventId);
|
|
204
|
+
const mac = computeCreditMac(eventRef);
|
|
205
|
+
if (!mac)
|
|
206
|
+
return { eligible: false, label: null, reason: 'signing-unavailable' };
|
|
207
|
+
return {
|
|
208
|
+
eligible: true,
|
|
209
|
+
label: `${POST_MERGE_CREDIT_RELEASE_LABEL}:${eventRef}:${mac}`,
|
|
210
|
+
reason: 'clean-window-elapsed',
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
return { eligible: false, label: null, reason: 'error' };
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// ---------------------------------------------------------------------------
|
|
218
|
+
// sweepPostMergeCreditReleases — periodic write-back
|
|
219
|
+
// ---------------------------------------------------------------------------
|
|
220
|
+
/**
|
|
221
|
+
* Bound on candidates inspected per sweep pass — mirrors outcome-watcher.ts's
|
|
222
|
+
* own bounding so a large backlog degrades gracefully instead of blocking.
|
|
223
|
+
*/
|
|
224
|
+
const MAX_SWEEP_CANDIDATES = 200;
|
|
225
|
+
/**
|
|
226
|
+
* Sweep applied proposals for post-merge diagnostics. No operational release
|
|
227
|
+
* row is recorded while positive stability witnesses are unavailable.
|
|
228
|
+
*
|
|
229
|
+
* The post-merge-observations ledger only records adverse outcomes. Closing
|
|
230
|
+
* the release path requires a positive, complete "swept clean" witness bound
|
|
231
|
+
* to the exact merge event; elapsed time and silence are insufficient.
|
|
232
|
+
*
|
|
233
|
+
* SCALING NOTE: unlike outcome-watcher.ts, this sweep has no persistent
|
|
234
|
+
* cursor — it re-scans applied proposals from the top of listProposalsDetailed
|
|
235
|
+
* every pass, bounded by MAX_SWEEP_CANDIDATES. At small-to-moderate applied-
|
|
236
|
+
* proposal counts this converges fine (already-released proposals are
|
|
237
|
+
* skipped instantly via the decisions-ledger dedup check, so the cap mostly
|
|
238
|
+
* matters for proposals still awaiting their window). At very large scale a
|
|
239
|
+
* persistent cursor (mirroring monitoring-cursor.ts) would be needed to
|
|
240
|
+
* guarantee every proposal eventually gets swept; out of scope here.
|
|
241
|
+
*
|
|
242
|
+
* Never throws.
|
|
243
|
+
*/
|
|
244
|
+
export function sweepPostMergeCreditReleases(opts = {}) {
|
|
245
|
+
const result = {
|
|
246
|
+
scanned: 0, released: 0, skipped: 0, sourceComplete: true,
|
|
247
|
+
};
|
|
248
|
+
try {
|
|
249
|
+
const nowMs = opts.nowMs ?? Date.now();
|
|
250
|
+
let proposals;
|
|
251
|
+
if (typeof opts.listProposals === 'function') {
|
|
252
|
+
try {
|
|
253
|
+
proposals = opts.listProposals();
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
proposals = [];
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
const read = listProposalsDetailed({ status: 'applied', requireComplete: true });
|
|
261
|
+
if (!read.complete || read.sourceState === 'degraded') {
|
|
262
|
+
result.sourceComplete = false;
|
|
263
|
+
return result;
|
|
264
|
+
}
|
|
265
|
+
proposals = read.proposals;
|
|
266
|
+
}
|
|
267
|
+
let inspected = 0;
|
|
268
|
+
for (const proposal of proposals) {
|
|
269
|
+
if (proposal.status !== 'applied')
|
|
270
|
+
continue;
|
|
271
|
+
if (inspected >= MAX_SWEEP_CANDIDATES) {
|
|
272
|
+
result.sourceComplete = false;
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
inspected++;
|
|
276
|
+
result.scanned++;
|
|
277
|
+
try {
|
|
278
|
+
const existing = readDecisions({ proposalId: proposal.id, requireComplete: true });
|
|
279
|
+
const existingQuality = existing.sourceQuality;
|
|
280
|
+
if (existingQuality && (existingQuality.sourceState === 'degraded' || existingQuality.complete === false)) {
|
|
281
|
+
result.skipped++;
|
|
282
|
+
result.sourceComplete = false;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
const alreadyReleased = existing.some((entry) => entry.action === 'merged' && hasReleasedPostMergeCredit(entry.labelBasis));
|
|
286
|
+
if (alreadyReleased)
|
|
287
|
+
continue;
|
|
288
|
+
const eligibility = evaluatePostMergeCreditRelease(proposal, { nowMs });
|
|
289
|
+
if (!eligibility.eligible || !eligibility.label) {
|
|
290
|
+
result.skipped++;
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
const ts = new Date(nowMs).toISOString();
|
|
294
|
+
recordDecision({
|
|
295
|
+
ts,
|
|
296
|
+
proposalId: proposal.id,
|
|
297
|
+
// NOTE: labelBasis is intentionally NOT routed through
|
|
298
|
+
// causalMetadataFromProposal's `input.labelBasis` — causalMetadata()
|
|
299
|
+
// (learning/causal.ts) applies boundedText(value, 80) to that field,
|
|
300
|
+
// which would silently truncate our signed token (>80 chars) into
|
|
301
|
+
// an unverifiable fragment. Set it directly below instead, after the
|
|
302
|
+
// spread, so the full token survives.
|
|
303
|
+
...causalMetadataFromProposal(proposal, { ts, learningSource: 'outcome-record' }),
|
|
304
|
+
action: 'merged',
|
|
305
|
+
verdict: 'applied',
|
|
306
|
+
labelBasis: eligibility.label,
|
|
307
|
+
repo: proposal.repo ?? '',
|
|
308
|
+
engine: proposal.engineModel ?? '',
|
|
309
|
+
model: '',
|
|
310
|
+
});
|
|
311
|
+
result.released++;
|
|
312
|
+
}
|
|
313
|
+
catch {
|
|
314
|
+
result.skipped++;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return result;
|
|
318
|
+
}
|
|
319
|
+
catch {
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
// ---------------------------------------------------------------------------
|
|
324
|
+
// attestPostMergeCreditSkillCard — dedicated signing boundary
|
|
325
|
+
// ---------------------------------------------------------------------------
|
|
326
|
+
/**
|
|
327
|
+
* Sign a SkillCard that legitimately carries released post-merge credit.
|
|
328
|
+
*
|
|
329
|
+
* skill-attestation.ts's generic attestSkillCard() deliberately refuses any
|
|
330
|
+
* card for which hasReleasedPostMergeCredit(card.labelBasis) is true — its
|
|
331
|
+
* signature payload doesn't cover the credit-release claim, so it must not
|
|
332
|
+
* be the thing vouching for it. This module owns that proof, so it owns this
|
|
333
|
+
* signing boundary too: same crypto primitive (signSkillCardAttestation),
|
|
334
|
+
* same payload shape, so verifyAttestedSkillCard() on the read side still
|
|
335
|
+
* validates cards signed here — only the gating differs (this function signs
|
|
336
|
+
* ONLY when hasReleasedPostMergeCredit is true; attestSkillCard signs only
|
|
337
|
+
* when it is false).
|
|
338
|
+
*
|
|
339
|
+
* Never throws.
|
|
19
340
|
*/
|
|
20
|
-
export function
|
|
21
|
-
|
|
341
|
+
export function attestPostMergeCreditSkillCard(card) {
|
|
342
|
+
try {
|
|
343
|
+
if (!hasReleasedPostMergeCredit(card.labelBasis))
|
|
344
|
+
return null;
|
|
345
|
+
const diffHash = card.verification?.diffHash;
|
|
346
|
+
if (!card.proposalId || !diffHash)
|
|
347
|
+
return null;
|
|
348
|
+
const contentHash = skillCardContentHash(card);
|
|
349
|
+
const attestation = signSkillCardAttestation({
|
|
350
|
+
contentHash,
|
|
351
|
+
skillId: card.skillId,
|
|
352
|
+
revision: card.revision,
|
|
353
|
+
proposalId: card.proposalId,
|
|
354
|
+
diffHash,
|
|
355
|
+
});
|
|
356
|
+
return attestation ? { ...card, contentHash, attestation } : null;
|
|
357
|
+
}
|
|
358
|
+
catch {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
22
361
|
}
|
|
23
362
|
//# sourceMappingURL=post-merge-credit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-merge-credit.js","sourceRoot":"","sources":["../../../src/core/fleet/post-merge-credit.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"post-merge-credit.js","sourceRoot":"","sources":["../../../src/core/fleet/post-merge-credit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,8BA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,IAAI,CAAC,OAAO;YACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,QAAQ;SACT,CAAC,CAAC;QACH,OAAO,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACpE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* policy file.
|
|
11
11
|
* - FIRE-AND-FORGET: learnFromRejection() never throws, never awaits
|
|
12
12
|
* anything on the critical path. All I/O is wrapped in try/catch.
|
|
13
|
-
* - GATED: every code path checks cfg.foundry?.selfImprove
|
|
14
|
-
* (default
|
|
13
|
+
* - GATED: every code path checks cfg.foundry?.selfImprove === true
|
|
14
|
+
* (default OFF). Unless the flag is explicitly true the function returns
|
|
15
15
|
* immediately — byte-identical to having no call at all.
|
|
16
16
|
* - ADDITIVE: the genome entry is informational grounding for future runs.
|
|
17
17
|
* It is NOT an execution directive; it does not alter the merge gate,
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* - TELEMETRY: a usage counter is appended to the decisions ledger under
|
|
24
24
|
* action 'self-improve:written' for observability (no PII, no secrets).
|
|
25
25
|
*/
|
|
26
|
-
import type { AshlrConfig, GenomeEntry } from '../types.js';
|
|
26
|
+
import type { AshlrConfig, DecisionEntry, GenomeEntry } from '../types.js';
|
|
27
27
|
/** Hard cap on total characters injected from anti-playbook entries per run. */
|
|
28
28
|
export declare const ANTI_PLAYBOOK_INJECT_CAP = 800;
|
|
29
29
|
type RejectionVerdict = 'review' | 'noise' | 'harmful';
|
|
@@ -42,7 +42,7 @@ export declare function deriveLesson(verdict: RejectionVerdict, _reasoning: stri
|
|
|
42
42
|
* 2. A decisions-ledger entry for telemetry/observability.
|
|
43
43
|
*
|
|
44
44
|
* NEVER THROWS. NEVER BLOCKS (all I/O is synchronous JSONL append behind
|
|
45
|
-
* try/catch). Gated on cfg.foundry?.selfImprove
|
|
45
|
+
* try/catch). Gated on cfg.foundry?.selfImprove === true.
|
|
46
46
|
*
|
|
47
47
|
* @param proposalId The proposal id (for ledger correlation).
|
|
48
48
|
* @param proposalTitle Legacy compatibility input; deliberately discarded.
|
|
@@ -50,7 +50,40 @@ export declare function deriveLesson(verdict: RejectionVerdict, _reasoning: stri
|
|
|
50
50
|
* @param reasoning Legacy compatibility input; deliberately discarded.
|
|
51
51
|
* @param cfg Fleet config.
|
|
52
52
|
*/
|
|
53
|
-
export declare function learnFromRejection(proposalId: string, proposalTitle: string, verdict: string, reasoning: string, cfg: AshlrConfig):
|
|
53
|
+
export declare function learnFromRejection(proposalId: string, proposalTitle: string, verdict: string, reasoning: string, cfg: AshlrConfig): boolean;
|
|
54
|
+
export interface RejectionLearningSweepResult {
|
|
55
|
+
/** Distinct proposals with a rejection-shaped judge verdict inspected. */
|
|
56
|
+
scanned: number;
|
|
57
|
+
/** Proposals for which learnFromRejection actually wrote a lesson. */
|
|
58
|
+
written: number;
|
|
59
|
+
/** Proposals inspected but skipped (already written, or a transient error). */
|
|
60
|
+
skipped: number;
|
|
61
|
+
/** False when the decisions source was incomplete/degraded, or the
|
|
62
|
+
* candidate cap was hit — a hint the pass should be retried. */
|
|
63
|
+
sourceComplete: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Sweep the decisions ledger for considered judged rejection verdicts (review
|
|
67
|
+
* | noise | harmful with their matching judgeReasonCode) and call
|
|
68
|
+
* learnFromRejection() for each one that hasn't already produced a lesson.
|
|
69
|
+
*
|
|
70
|
+
* learnFromRejection's ONLY prior caller was automerge-pass.ts, reached
|
|
71
|
+
* exclusively from inside the auto-merge pass (cfg.foundry.autoMerge.enabled
|
|
72
|
+
* === true). With auto-merge off — the default — a judge verdict could still
|
|
73
|
+
* be recorded (manual `ashlr judge`, a shadow/observe-only judge pass, etc.)
|
|
74
|
+
* but the fleet never learned from it. This sweep reads the SAME
|
|
75
|
+
* decisions-ledger 'judged' rows regardless of what produced them, so a
|
|
76
|
+
* rejected or failed run teaches the fleet whether or not auto-merge is on.
|
|
77
|
+
*
|
|
78
|
+
* Idempotent: a proposalId that already has a 'self-improve:written'
|
|
79
|
+
* telemetry row is skipped. Bounded, fail-open-on-nothing-to-do,
|
|
80
|
+
* fail-closed-on-source-degradation (sourceComplete:false signals "retry
|
|
81
|
+
* later", never treated as "nothing to learn"). Never throws.
|
|
82
|
+
*/
|
|
83
|
+
export declare function sweepRejectionLearning(cfg: AshlrConfig, opts?: {
|
|
84
|
+
sinceMs?: number;
|
|
85
|
+
listDecisions?: () => DecisionEntry[];
|
|
86
|
+
}): RejectionLearningSweepResult;
|
|
54
87
|
/**
|
|
55
88
|
* Filter a list of genome entries to anti-playbook entries suitable for
|
|
56
89
|
* inject-time grounding. Applies:
|