opencode-swarm 7.140.3 → 7.140.5
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/.opencode/skills/brainstorm/SKILL.md +1 -1
- package/.opencode/skills/ci-failure-batching/SKILL.md +11 -1
- package/.opencode/skills/ci-fix-monitor/SKILL.md +6 -4
- package/.opencode/skills/discover/SKILL.md +1 -1
- package/.opencode/skills/durable-session-state/SKILL.md +82 -0
- package/.opencode/skills/engineering-conventions/SKILL.md +1 -1
- package/.opencode/skills/issue-ingest/SKILL.md +13 -7
- package/.opencode/skills/issue-tracer/SKILL.md +1 -1
- package/.opencode/skills/orchestrating-subagents/SKILL.md +113 -0
- package/.opencode/skills/parallel-work-check/SKILL.md +1 -1
- package/.opencode/skills/plan/SKILL.md +40 -12
- package/.opencode/skills/swarm-ci-monitor/SKILL.md +5 -3
- package/.opencode/skills/swarm-pr-feedback/SKILL.md +30 -4
- package/.opencode/skills/writing-tests/SKILL.md +1 -1
- package/dist/agents/architect.d.ts +2 -1
- package/dist/agents/reviewer-directive-compliance.d.ts +19 -5
- package/dist/background/pending-delegations.d.ts +5 -0
- package/dist/cli/{config-doctor-fnmfd35x.js → config-doctor-5vzpq4qa.js} +3 -3
- package/dist/cli/{core-p5cyej3r.js → core-xjzdc56e.js} +2 -2
- package/dist/cli/{curation-policy-d52h4g8t.js → curation-policy-avvb56x2.js} +6 -8
- package/dist/cli/{curator-3zpdqt9r.js → curator-5nytvg7p.js} +38 -38
- package/dist/cli/curator-llm-factory-rds75zhj.js +61 -0
- package/dist/cli/{evidence-summary-service-nfdc1ht9.js → evidence-summary-service-zq4gyx6g.js} +15 -12
- package/dist/cli/gate-evidence-smn2wqft.js +51 -0
- package/dist/cli/guardrail-explain-an7jvam1.js +62 -0
- package/dist/cli/{guardrail-log-82da8y5a.js → guardrail-log-0hnd2k9v.js} +4 -4
- package/dist/cli/{hive-promoter-af5yaxvt.js → hive-promoter-qe8pqg79.js} +38 -38
- package/dist/cli/{index-qksjaxpd.js → index-01ggt2mj.js} +49 -18
- package/dist/cli/{index-j1xmren9.js → index-0r2m0vbq.js} +12 -10
- package/dist/cli/{index-pg7n141e.js → index-0rx9t9w8.js} +1 -1
- package/dist/cli/{index-brh827g0.js → index-2bg901qt.js} +73 -32
- package/dist/cli/{index-8n4c3vec.js → index-386ts4tm.js} +4 -4
- package/dist/cli/{index-898f16j9.js → index-8rp1y4ab.js} +2 -2
- package/dist/cli/{index-hfvxhk4z.js → index-912qz4y0.js} +88 -88
- package/dist/cli/index-affh1gtg.js +2554 -0
- package/dist/cli/{index-1m1ksyqt.js → index-c432knmy.js} +1 -1
- package/dist/cli/{index-jvk119ck.js → index-e0mpz2j3.js} +54 -19
- package/dist/cli/{index-ry0hgg3m.js → index-epvhf50h.js} +37 -3
- package/dist/cli/{index-95bj4kaw.js → index-ex7r16gc.js} +2 -2
- package/dist/cli/{index-7d5jseea.js → index-jm4cpp4n.js} +5 -2
- package/dist/cli/{index-n408rw7n.js → index-jqsfsqbx.js} +27 -2
- package/dist/cli/{index-7kdd75se.js → index-kb5q9v34.js} +11 -9
- package/dist/cli/{index-jfjnn408.js → index-m9xrdjn0.js} +1 -1
- package/dist/cli/{index-pj9h75cc.js → index-mm2egvdt.js} +40 -40
- package/dist/cli/{index-8bnzzv3b.js → index-nwrwy8eb.js} +70 -34
- package/dist/cli/index-nyjtzmsj.js +43 -0
- package/dist/cli/{index-h2waehqq.js → index-p8kk34am.js} +3 -3
- package/dist/cli/{index-wf35ka4z.js → index-ptn13xjn.js} +3 -3
- package/dist/cli/{index-1kyex7z2.js → index-qwm6vdyv.js} +32 -1
- package/dist/cli/{index-p9dsb0tw.js → index-qy1nq52t.js} +2 -19
- package/dist/cli/{index-b9rd29ge.js → index-s1v0wza5.js} +6 -2
- package/dist/cli/{index-yyyk63kk.js → index-t5pytnca.js} +2 -2
- package/dist/cli/index-tjqzr3jc.js +623 -0
- package/dist/cli/{index-rs1f1bh0.js → index-vh05t3w5.js} +1 -1
- package/dist/cli/{index-adyxbmt5.js → index-wkt9fj06.js} +4 -4
- package/dist/cli/{index-kbfsp07d.js → index-wrb0gykj.js} +217 -15
- package/dist/cli/{index-xz8f1n1a.js → index-z7h37d63.js} +2 -2
- package/dist/cli/{index-q1q8b85k.js → index-z90nvqj3.js} +49315 -47331
- package/dist/cli/{index-b8zgtz81.js → index-zsrtt42s.js} +34 -1
- package/dist/cli/{index-gtbmabws.js → index-ztgn70jz.js} +2 -2
- package/dist/cli/index.js +37 -37
- package/dist/cli/{knowledge-escalator-7q59skqg.js → knowledge-escalator-4pfrc902.js} +20 -8
- package/dist/cli/{knowledge-events-3nwfdpq7.js → knowledge-events-3zkfnksk.js} +19 -6
- package/dist/cli/{knowledge-link-q46k9adx.js → knowledge-link-m9p80f4r.js} +5 -5
- package/dist/cli/{knowledge-store-0d83rhh3.js → knowledge-store-dpqgvvjt.js} +6 -6
- package/dist/cli/{knowledge-validator-6mfx91a2.js → knowledge-validator-2c7w87dk.js} +8 -9
- package/dist/cli/{pending-delegations-qzrx38y9.js → pending-delegations-cxx9tezp.js} +4 -4
- package/dist/cli/{pr-subscriptions-5s59h4dd.js → pr-subscriptions-2sfnb599.js} +4 -4
- package/dist/cli/{runner-y78d7ryb.js → runner-mky3vvht.js} +6 -6
- package/dist/cli/{scan-cursor-rc8q12ss.js → scan-cursor-1z60gwrw.js} +7 -7
- package/dist/cli/{schema-n9eaxp3a.js → schema-vpnkwvez.js} +2 -2
- package/dist/cli/{scope-persistence-dr1msqxw.js → scope-persistence-p9dmprry.js} +10 -5
- package/dist/cli/{skill-generator-q7c6vadg.js → skill-generator-yx7ka1cj.js} +19 -10
- package/dist/cli/{telemetry-sc57xtb0.js → telemetry-0x6kszvk.js} +1 -1
- package/dist/cli/{worktree-collision-ownership-7a8e6gr9.js → worktree-collision-ownership-wm5pse49.js} +8 -8
- package/dist/cli/worktree-isolation-bwc6ra8e.js +102 -0
- package/dist/cli/worktree-provisioning-owner-sjh7te1h.js +22 -0
- package/dist/commands/acknowledge-spec-drift.d.ts +4 -5
- package/dist/commands/ci-simulate.d.ts +7 -3
- package/dist/commands/close.d.ts +8 -0
- package/dist/commands/registry.d.ts +2 -2
- package/dist/commands/sdd.d.ts +15 -0
- package/dist/config/bundled-skills.d.ts +1 -1
- package/dist/config/evidence-schema.d.ts +3 -3
- package/dist/config/index.d.ts +2 -2
- package/dist/config/plan-schema.d.ts +8 -0
- package/dist/config/schema.d.ts +4 -2
- package/dist/council/council-evidence-writer.d.ts +1 -1
- package/dist/gate-evidence.d.ts +117 -4
- package/dist/git/branch.d.ts +1 -1
- package/dist/hooks/delegate-ack-collector.d.ts +5 -0
- package/dist/hooks/delegation-gate.d.ts +21 -0
- package/dist/hooks/hive-promoter.d.ts +4 -4
- package/dist/hooks/issue-trace-reducer.d.ts +7 -1
- package/dist/hooks/issue-trace-state.d.ts +18 -0
- package/dist/hooks/issue-trace.d.ts +3 -1
- package/dist/hooks/knowledge-application-gate.d.ts +8 -3
- package/dist/hooks/knowledge-application.d.ts +8 -5
- package/dist/hooks/knowledge-escalator.d.ts +9 -5
- package/dist/hooks/knowledge-events.d.ts +21 -8
- package/dist/hooks/knowledge-injector.d.ts +9 -0
- package/dist/hooks/knowledge-receipt-ledger-storage.d.ts +49 -0
- package/dist/hooks/knowledge-receipt-ledger.d.ts +305 -0
- package/dist/hooks/knowledge-receipt-observability.d.ts +28 -0
- package/dist/hooks/knowledge-receipt-validator.d.ts +13 -50
- package/dist/hooks/knowledge-store.d.ts +6 -1
- package/dist/hooks/knowledge-types.d.ts +12 -0
- package/dist/hooks/phase-complete-directive-gate.d.ts +3 -1
- package/dist/hooks/phase-directives.d.ts +4 -4
- package/dist/hooks/pr-workflow-gate.d.ts +34 -1
- package/dist/hooks/promotion-evidence-store.d.ts +14 -8
- package/dist/hooks/reviewer-verdict-parser.d.ts +34 -10
- package/dist/index.js +823 -779
- package/dist/knowledge/curation-policy.d.ts +0 -2
- package/dist/observability/catalog.d.ts +5 -3
- package/dist/observability/legacy.d.ts +4 -3
- package/dist/plan/ledger.d.ts +55 -0
- package/dist/plan/manager.d.ts +9 -0
- package/dist/plan/planning-profile.d.ts +27 -0
- package/dist/services/spec-drift-recovery.d.ts +84 -0
- package/dist/session/snapshot-writer.d.ts +3 -1
- package/dist/state.d.ts +19 -17
- package/dist/summaries/schema.d.ts +2 -2
- package/dist/telemetry.d.ts +1 -1
- package/dist/tools/convene-council.d.ts +6 -6
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/manifest.d.ts +3 -0
- package/dist/tools/phase-complete.d.ts +9 -0
- package/dist/tools/rebind-pr-feedback-head.d.ts +17 -0
- package/dist/tools/record-implementation-review.d.ts +19 -0
- package/dist/tools/record-recurrence-sweep.d.ts +17 -0
- package/dist/tools/run-pr-feedback-stage-a.d.ts +8 -0
- package/dist/tools/save-plan.d.ts +8 -0
- package/dist/tools/submit-phase-council-verdicts.d.ts +6 -6
- package/dist/tools/tool-metadata.d.ts +40 -28
- package/dist/tools/update-task-status.d.ts +13 -0
- package/dist/tools/write-final-council-evidence.d.ts +6 -6
- package/dist/types/events.d.ts +29 -1
- package/dist/workflow/coder-settlement.d.ts +62 -0
- package/dist/workflow/task-repair.d.ts +30 -0
- package/dist/workflow/task-terminal.d.ts +52 -0
- package/package.json +3 -1
- package/dist/cli/curator-llm-factory-2h0xb62t.js +0 -61
- package/dist/cli/gate-evidence-46qeyfc1.js +0 -32
- package/dist/cli/guardrail-explain-yktan15c.js +0 -62
- package/dist/cli/index-d181x9zr.js +0 -71
- package/dist/cli/index-n0pja0qs.js +0 -239
- package/dist/cli/index-n8jncheh.js +0 -666
|
@@ -17,6 +17,8 @@ import type { IssueReference, TraceState } from './issue-trace-reducer';
|
|
|
17
17
|
declare function _defaultLoadPlanFromLedger(directory: string): Promise<Plan | null>;
|
|
18
18
|
declare function _defaultReproductionReceiptExists(directory: string, issueNumber: number): Promise<boolean>;
|
|
19
19
|
declare function _defaultPublicationReceiptExists(directory: string, issueNumber: number): Promise<boolean>;
|
|
20
|
+
declare function _defaultRecurrenceSweepReceiptExists(directory: string, issueNumber: number): Promise<boolean>;
|
|
21
|
+
declare function _defaultImplementationReviewReceiptExists(directory: string, issueNumber: number): Promise<boolean>;
|
|
20
22
|
export declare const _internals: {
|
|
21
23
|
readFileSync: typeof readFileSync;
|
|
22
24
|
writeFileSync: typeof writeFileSync;
|
|
@@ -27,6 +29,8 @@ export declare const _internals: {
|
|
|
27
29
|
loadPlanFromLedger: typeof _defaultLoadPlanFromLedger;
|
|
28
30
|
reproductionReceiptExists: typeof _defaultReproductionReceiptExists;
|
|
29
31
|
publicationReceiptExists: typeof _defaultPublicationReceiptExists;
|
|
32
|
+
recurrenceSweepReceiptExists: typeof _defaultRecurrenceSweepReceiptExists;
|
|
33
|
+
implementationReviewReceiptExists: typeof _defaultImplementationReviewReceiptExists;
|
|
30
34
|
};
|
|
31
35
|
/**
|
|
32
36
|
* Reads `.swarm/issue-reference.json` and returns the parsed object,
|
|
@@ -90,4 +94,18 @@ export declare function reproductionReceiptExists(directory: string, issueNumber
|
|
|
90
94
|
* a new trace.
|
|
91
95
|
*/
|
|
92
96
|
export declare function publicationReceiptExists(directory: string, issueNumber: number): Promise<boolean>;
|
|
97
|
+
/**
|
|
98
|
+
* Returns whether a valid recurrence-sweep receipt exists for the given issue
|
|
99
|
+
* (issue #2131 residual criterion B). Modeled on issue-tracer Phase 4.2: for a
|
|
100
|
+
* real defect class it must record search predicates, a typed disposition for
|
|
101
|
+
* every hit, and a guardrail with proof it catches the original defect; the
|
|
102
|
+
* "no defect class" fast path requires a one-line justification.
|
|
103
|
+
*/
|
|
104
|
+
export declare function recurrenceSweepReceiptExists(directory: string, issueNumber: number): Promise<boolean>;
|
|
105
|
+
/**
|
|
106
|
+
* Returns whether a valid independent implementation-review receipt exists for
|
|
107
|
+
* the given issue (issue #2131 residual criterion B): fresh reviewer AND critic
|
|
108
|
+
* contexts both recorded APPROVE verdicts for the implementation diff.
|
|
109
|
+
*/
|
|
110
|
+
export declare function implementationReviewReceiptExists(directory: string, issueNumber: number): Promise<boolean>;
|
|
93
111
|
export {};
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { error as _logErrorImpl } from '../utils/logger.js';
|
|
19
19
|
import { isPlanCriticApproved } from './delegation-gate';
|
|
20
|
-
import { publicationReceiptExists, readIssueReference, readPlanPhaseStatus, readSpecIssueNumber, readTraceState, reproductionReceiptExists, specExists, writeTraceState } from './issue-trace-state';
|
|
20
|
+
import { implementationReviewReceiptExists, publicationReceiptExists, readIssueReference, readPlanPhaseStatus, readSpecIssueNumber, readTraceState, recurrenceSweepReceiptExists, reproductionReceiptExists, specExists, writeTraceState } from './issue-trace-state';
|
|
21
21
|
export declare const _internals: {
|
|
22
22
|
readIssueReference: typeof readIssueReference;
|
|
23
23
|
readTraceState: typeof readTraceState;
|
|
@@ -27,6 +27,8 @@ export declare const _internals: {
|
|
|
27
27
|
specExists: typeof specExists;
|
|
28
28
|
reproductionReceiptExists: typeof reproductionReceiptExists;
|
|
29
29
|
publicationReceiptExists: typeof publicationReceiptExists;
|
|
30
|
+
recurrenceSweepReceiptExists: typeof recurrenceSweepReceiptExists;
|
|
31
|
+
implementationReviewReceiptExists: typeof implementationReviewReceiptExists;
|
|
30
32
|
isPlanCriticApproved: typeof isPlanCriticApproved;
|
|
31
33
|
logError: typeof _logErrorImpl;
|
|
32
34
|
};
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
*
|
|
13
13
|
* 2. `tool.execute.before` (FAIL-CLOSED chain at src/index.ts) — when a
|
|
14
14
|
* high-risk tool fires and the calling agent is the architect,
|
|
15
|
-
* consults
|
|
16
|
-
*
|
|
15
|
+
* consults the authoritative receipt ledger for critical architect
|
|
16
|
+
* directives in the current active phase/task that have been shown but
|
|
17
17
|
* not acknowledged. In `mode: 'enforce'` it THROWS to block the
|
|
18
18
|
* action (per the FAIL-CLOSED contract — `output.error` is NOT a
|
|
19
19
|
* write API at toolBefore time) — UNLESS one of two bounded escape
|
|
20
20
|
* hatches has fired first (a per-directive denial-count limit, or a
|
|
21
|
-
* staleness TTL since the directive was shown; see
|
|
21
|
+
* per-exact-pair staleness TTL since the directive was shown; see
|
|
22
22
|
* `incrementGateDenialCount`/`buildGateDenialDirectiveKey` in
|
|
23
23
|
* `../state.js`), in which case the pending directives are
|
|
24
24
|
* auto-acknowledged and an audit event is durably written before the
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
* Non-architect agents are never gated.
|
|
35
35
|
*/
|
|
36
36
|
import { type KnowledgeApplicationConfig } from './knowledge-application.js';
|
|
37
|
+
import { type ReceiptMembership } from './knowledge-receipt-ledger.js';
|
|
37
38
|
import type { MessageWithParts } from './knowledge-types.js';
|
|
38
39
|
/** Tools that require knowledge-directive acknowledgment before execution. */
|
|
39
40
|
export declare const HIGH_RISK_TOOLS: Set<string>;
|
|
@@ -42,6 +43,8 @@ export interface GateInput {
|
|
|
42
43
|
agent?: unknown;
|
|
43
44
|
sessionID?: unknown;
|
|
44
45
|
}
|
|
46
|
+
declare function selectCurrentArchitectDirectiveMemberships(memberships: ReceiptMembership[]): ReceiptMembership[];
|
|
47
|
+
declare function selectStaleUnmarkedMemberships(memberships: ReceiptMembership[], now: number, stalenessMs: number): ReceiptMembership[];
|
|
45
48
|
/**
|
|
46
49
|
* Pre-tool gate. Throws when the architect attempts a high-risk action with
|
|
47
50
|
* an unacknowledged critical directive in `enforce` mode. Always returns in
|
|
@@ -64,5 +67,7 @@ export declare const _internals: {
|
|
|
64
67
|
knowledgeApplicationTransformScan: typeof knowledgeApplicationTransformScan;
|
|
65
68
|
HIGH_RISK_TOOLS: Set<string>;
|
|
66
69
|
writeWarnEvent: typeof writeWarnEvent;
|
|
70
|
+
selectCurrentArchitectDirectiveMemberships: typeof selectCurrentArchitectDirectiveMemberships;
|
|
71
|
+
selectStaleUnmarkedMemberships: typeof selectStaleUnmarkedMemberships;
|
|
67
72
|
};
|
|
68
73
|
export {};
|
|
@@ -11,14 +11,17 @@ export declare const MAX_LEGACY_APPLICATION_LOG_ENTRIES = 5000;
|
|
|
11
11
|
/**
|
|
12
12
|
* Parse explicit knowledge-acknowledgment markers from architect/delegate text.
|
|
13
13
|
* Recognised forms (case-insensitive, line-anchored or inline):
|
|
14
|
-
* KNOWLEDGE_APPLIED: <
|
|
15
|
-
* KNOWLEDGE_IGNORED: <
|
|
16
|
-
* KNOWLEDGE_CONTRADICTED: <
|
|
17
|
-
* KNOWLEDGE_VIOLATED: <
|
|
18
|
-
* KNOWLEDGE_N_A: <
|
|
14
|
+
* KNOWLEDGE_APPLIED: <trace_id>:<entry_id>
|
|
15
|
+
* KNOWLEDGE_IGNORED: <trace_id>:<entry_id> reason=<reason>
|
|
16
|
+
* KNOWLEDGE_CONTRADICTED: <trace_id>:<entry_id> reason=<observable conflict>
|
|
17
|
+
* KNOWLEDGE_VIOLATED: <trace_id>:<entry_id> reason=<reason>
|
|
18
|
+
* KNOWLEDGE_N_A: <trace_id>:<entry_id> reason=<reason>
|
|
19
|
+
* Legacy one-token delegate markers remain parseable, but architect application
|
|
20
|
+
* reconciliation requires the exact trace token.
|
|
19
21
|
*/
|
|
20
22
|
export interface ParsedAcknowledgment {
|
|
21
23
|
id: string;
|
|
24
|
+
trace_id?: string;
|
|
22
25
|
result: 'applied' | 'ignored' | 'contradicted' | 'violated' | 'n_a';
|
|
23
26
|
reason?: string;
|
|
24
27
|
}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* Persistence goes through `rewriteKnowledge` (never a raw JSONL write). Fail-open:
|
|
12
12
|
* any error leaves the entry untouched and returns `escalated:false`.
|
|
13
13
|
*/
|
|
14
|
+
import { queryHistoricalOutcomes } from './knowledge-receipt-ledger.js';
|
|
14
15
|
import type { DirectivePriority } from './knowledge-types.js';
|
|
15
16
|
export declare const ESCALATION_WINDOW_DAYS = 30;
|
|
16
17
|
export declare const ESCALATION_THRESHOLD = 2;
|
|
@@ -25,7 +26,7 @@ export interface EscalationResult {
|
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
28
|
* Evaluate and (if warranted) apply a repeat-violation escalation to a single
|
|
28
|
-
* entry. Call AFTER the triggering `violated`
|
|
29
|
+
* entry. Call AFTER the triggering authoritative `violated` terminal commits.
|
|
29
30
|
*/
|
|
30
31
|
export declare function maybeEscalateOnViolation(directory: string, entryId: string, now?: Date): Promise<EscalationResult>;
|
|
31
32
|
export interface RecentEscalation {
|
|
@@ -58,9 +59,12 @@ export interface ContradictionQuarantineResult {
|
|
|
58
59
|
/**
|
|
59
60
|
* G3 (#1715): if an entry's `contradicted` count within `windowDays` crosses
|
|
60
61
|
* `threshold`, auto-quarantine it. Mirrors {@link maybeEscalateOnViolation}
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* skipped. Never throws.
|
|
62
|
+
* Counts exact authoritative receipt terminals, never the diagnostic FIFO or
|
|
63
|
+
* rollup cache. Idempotent: already-quarantined/archived entries are skipped.
|
|
64
|
+
* Receipt-ledger uncertainty is conservative and never quarantines.
|
|
65
65
|
*/
|
|
66
66
|
export declare function maybeQuarantineOnContradiction(directory: string, entryId: string, threshold: number, windowDays: number, now?: Date): Promise<ContradictionQuarantineResult>;
|
|
67
|
+
/** Dependency seam for authoritative-history tests; restore after each test. */
|
|
68
|
+
export declare const _internals: {
|
|
69
|
+
queryHistoricalOutcomes: typeof queryHistoricalOutcomes;
|
|
70
|
+
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bounded diagnostic knowledge lifecycle stream for opencode-swarm.
|
|
3
3
|
*
|
|
4
4
|
* `.swarm/knowledge-events.jsonl` records meaningful knowledge interactions
|
|
5
5
|
* (retrieval, receipt, outcome, archival). Recent lines stay in the event log;
|
|
6
6
|
* old lines are folded into `.swarm/knowledge-counter-baseline.json` when the
|
|
7
|
-
* log exceeds the cap. The event log plus baseline
|
|
8
|
-
*
|
|
7
|
+
* log exceeds the cap. The event log plus baseline remain the source for
|
|
8
|
+
* best-effort aggregate metrics (`retrieval_outcomes.*`), but are not receipt,
|
|
9
|
+
* membership, gate, promotion, escalation, or destructive-action authority.
|
|
10
|
+
* Correctness state lives in the canonical project-local V2 receipt ledger.
|
|
9
11
|
*
|
|
10
12
|
* Design contracts:
|
|
11
13
|
* - Append-first, bounded retention. New events use OS-level atomic append; trim
|
|
@@ -20,6 +22,7 @@
|
|
|
20
22
|
* from the process working directory.
|
|
21
23
|
*/
|
|
22
24
|
import { resolveHiveEventsPath as resolveHiveEventsPathImpl } from '../knowledge/hive-paths.js';
|
|
25
|
+
import { queryHistoricalOutcomes } from './knowledge-receipt-ledger.js';
|
|
23
26
|
import type { ConfidenceFloorOptions } from './knowledge-store.js';
|
|
24
27
|
import type { KnowledgeApplicationRecord, RetrievalOutcome } from './knowledge-types.js';
|
|
25
28
|
/** Current event-log record schema version. Bump when the on-disk shape changes. */
|
|
@@ -372,16 +375,24 @@ export declare function countEntryViolationsInWindow(directory: string, entryId:
|
|
|
372
375
|
*/
|
|
373
376
|
export declare function countEntryContradictionsInWindow(directory: string, entryId: string, windowDays: number, now?: Date): Promise<number>;
|
|
374
377
|
/**
|
|
375
|
-
* Fail-open rollup reader
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
+
* Fail-open diagnostic rollup reader. This preserves legacy metrics and
|
|
379
|
+
* postmortem views, but correctness-affecting consumers must use
|
|
380
|
+
* {@link readAuthoritativeKnowledgeCounterRollups} instead.
|
|
378
381
|
*/
|
|
379
382
|
export declare function readKnowledgeCounterRollups(directory: string): Promise<Map<string, CounterRollup>>;
|
|
383
|
+
/**
|
|
384
|
+
* Build correctness-affecting retrieval/outcome counters exclusively from the
|
|
385
|
+
* project-local receipt authority. The bounded knowledge-events FIFO remains a
|
|
386
|
+
* diagnostics/metrics source and must never influence ranking, curation,
|
|
387
|
+
* confidence floors, promotion, or generated-skill eligibility.
|
|
388
|
+
*/
|
|
389
|
+
export declare function readAuthoritativeKnowledgeCounterRollups(directory: string): Promise<Map<string, CounterRollup>>;
|
|
380
390
|
/** Merge event-derived rollups over stored outcome counters for scoring only. */
|
|
381
391
|
export declare function effectiveRetrievalOutcomes(stored: RetrievalOutcome | undefined, rollup: CounterRollup | undefined): RetrievalOutcome;
|
|
382
392
|
/**
|
|
383
|
-
* Read receipt
|
|
384
|
-
* and apply bounded confidence deltas via
|
|
393
|
+
* Read authoritative receipt terminals (applied/violated/ignored), aggregate
|
|
394
|
+
* per knowledge entry, and apply bounded confidence deltas via
|
|
395
|
+
* `bumpKnowledgeConfidenceBatch`.
|
|
385
396
|
*
|
|
386
397
|
* Complements `applySkillUsageFeedback` (skill-usage-log.ts) which bridges
|
|
387
398
|
* skill compliance → confidence. This function bridges raw knowledge verdict
|
|
@@ -407,9 +418,11 @@ export declare const _internals: {
|
|
|
407
418
|
appendKnowledgeEvent: typeof appendKnowledgeEvent;
|
|
408
419
|
recordKnowledgeEvent: typeof recordKnowledgeEvent;
|
|
409
420
|
readKnowledgeEvents: typeof readKnowledgeEvents;
|
|
421
|
+
queryHistoricalOutcomes: typeof queryHistoricalOutcomes;
|
|
410
422
|
readCounterBaseline: typeof readCounterBaseline;
|
|
411
423
|
readLegacyApplicationRecords: typeof readLegacyApplicationRecords;
|
|
412
424
|
readKnowledgeCounterRollups: typeof readKnowledgeCounterRollups;
|
|
425
|
+
readAuthoritativeKnowledgeCounterRollups: typeof readAuthoritativeKnowledgeCounterRollups;
|
|
413
426
|
effectiveRetrievalOutcomes: typeof effectiveRetrievalOutcomes;
|
|
414
427
|
recomputeCounters: typeof recomputeCounters;
|
|
415
428
|
applyKnowledgeVerdictFeedback: typeof applyKnowledgeVerdictFeedback;
|
|
@@ -5,11 +5,14 @@
|
|
|
5
5
|
* compaction. Skips for non-architect agents. Appends rejected-pattern warnings
|
|
6
6
|
* to prevent re-learning loops.
|
|
7
7
|
*/
|
|
8
|
+
import { ensureCohortIdCached } from './cohort-cache.js';
|
|
8
9
|
import { recordKnowledgeShown } from './knowledge-application.js';
|
|
9
10
|
import { buildEscalationBriefing, readRecentEscalations } from './knowledge-escalator.js';
|
|
10
11
|
import { recordKnowledgeEvent } from './knowledge-events.js';
|
|
12
|
+
import { readLinkPointer } from './knowledge-link.js';
|
|
11
13
|
import type { RankedEntry } from './knowledge-reader.js';
|
|
12
14
|
import { recordLessonsShown } from './knowledge-reader.js';
|
|
15
|
+
import { commitDisplayedMembership, commitEmptyRetrieval, queryLiveMemberships } from './knowledge-receipt-ledger.js';
|
|
13
16
|
import { confirmEntriesPhase } from './knowledge-store.js';
|
|
14
17
|
import type { DirectivePriority, KnowledgeConfig, MessageWithParts } from './knowledge-types.js';
|
|
15
18
|
import { searchKnowledge } from './search-knowledge.js';
|
|
@@ -48,6 +51,7 @@ export interface InjectForDelegateParams {
|
|
|
48
51
|
agent: string;
|
|
49
52
|
expectedTools?: string[];
|
|
50
53
|
taskTitle?: string;
|
|
54
|
+
taskId?: string;
|
|
51
55
|
sessionId?: string;
|
|
52
56
|
config: KnowledgeConfig;
|
|
53
57
|
/**
|
|
@@ -117,6 +121,11 @@ export declare const _internals: {
|
|
|
117
121
|
buildEscalationBriefing: typeof buildEscalationBriefing;
|
|
118
122
|
recordLessonsShown: typeof recordLessonsShown;
|
|
119
123
|
confirmEntriesPhase: typeof confirmEntriesPhase;
|
|
124
|
+
commitDisplayedMembership: typeof commitDisplayedMembership;
|
|
125
|
+
commitEmptyRetrieval: typeof commitEmptyRetrieval;
|
|
126
|
+
queryLiveMemberships: typeof queryLiveMemberships;
|
|
127
|
+
ensureCohortIdCached: typeof ensureCohortIdCached;
|
|
128
|
+
readLinkPointer: typeof readLinkPointer;
|
|
120
129
|
};
|
|
121
130
|
/**
|
|
122
131
|
* Tier-0 test seam (see `.opencode/skills/writing-tests/SKILL.md`). Exposes the
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import { lstat, realpath } from 'node:fs/promises';
|
|
3
|
+
export declare const RECEIPT_SCHEMA_VERSION = 2;
|
|
4
|
+
export declare const RECEIPT_CUTOVER_VERSION = 1;
|
|
5
|
+
export interface ReceiptLedgerPaths {
|
|
6
|
+
root: string;
|
|
7
|
+
swarmDir: string;
|
|
8
|
+
journal: string;
|
|
9
|
+
snapshot: string;
|
|
10
|
+
archive: string;
|
|
11
|
+
quarantine: string;
|
|
12
|
+
lockTarget: string;
|
|
13
|
+
legacyEvents: string;
|
|
14
|
+
legacyBaseline: string;
|
|
15
|
+
linkPointer: string;
|
|
16
|
+
}
|
|
17
|
+
export type ReceiptStoreErrorCode = 'lock_timeout' | 'store_unavailable' | 'store_corrupt';
|
|
18
|
+
export declare class ReceiptStoreError extends Error {
|
|
19
|
+
readonly code: ReceiptStoreErrorCode;
|
|
20
|
+
constructor(code: ReceiptStoreErrorCode, message: string);
|
|
21
|
+
}
|
|
22
|
+
export declare function resolveReceiptLedgerPaths(directory: string): ReceiptLedgerPaths;
|
|
23
|
+
interface MutationParentDependencies {
|
|
24
|
+
lstat: typeof lstat;
|
|
25
|
+
realpath: typeof realpath;
|
|
26
|
+
}
|
|
27
|
+
declare function validateMutationParent(filePath: string, dependencies?: MutationParentDependencies): Promise<string>;
|
|
28
|
+
declare function readLinuxProcStat(pid: number, signal: AbortSignal): Promise<string>;
|
|
29
|
+
declare function isProcessAlive(pid: number): Promise<boolean>;
|
|
30
|
+
declare function recoverLockIfSafe(paths: ReceiptLedgerPaths): Promise<void>;
|
|
31
|
+
export declare function withReceiptLedgerLock<T>(directory: string, action: (paths: ReceiptLedgerPaths) => Promise<T>): Promise<T>;
|
|
32
|
+
export declare function receiptRecordHash(value: unknown): string;
|
|
33
|
+
export declare function readUtf8IfPresent(filePath: string, maxBytes?: number): Promise<string | null>;
|
|
34
|
+
export declare function appendFsynced(filePath: string, line: string): Promise<void>;
|
|
35
|
+
export declare function atomicWriteFsynced(targetPath: string, content: string): Promise<void>;
|
|
36
|
+
export declare function fileMtimeMs(filePath: string): Promise<number | null>;
|
|
37
|
+
export declare const _internals: {
|
|
38
|
+
platform: () => NodeJS.Platform;
|
|
39
|
+
killProcess: (pid: number) => void;
|
|
40
|
+
readLinuxProcStat: typeof readLinuxProcStat;
|
|
41
|
+
procStateReadTimeoutMs: number;
|
|
42
|
+
isProcessAlive: typeof isProcessAlive;
|
|
43
|
+
rename: typeof fs.promises.rename;
|
|
44
|
+
rm: typeof fs.promises.rm;
|
|
45
|
+
afterRecoveryRename: (_paths: ReceiptLedgerPaths, _claimedPath: string) => Promise<void>;
|
|
46
|
+
recoverLockIfSafe: typeof recoverLockIfSafe;
|
|
47
|
+
validateMutationParent: typeof validateMutationParent;
|
|
48
|
+
};
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { atomicWriteFsynced, type ReceiptLedgerPaths, type ReceiptStoreErrorCode } from './knowledge-receipt-ledger-storage.js';
|
|
2
|
+
import { type KnowledgeReceiptTransitionObservation } from './knowledge-receipt-observability.js';
|
|
3
|
+
export type ReceiptOutcome = 'applied' | 'ignored' | 'contradicted' | 'violated' | 'n_a';
|
|
4
|
+
export interface ReceiptPredicateCheck {
|
|
5
|
+
predicate: string;
|
|
6
|
+
result: 'pass' | 'fail' | 'error';
|
|
7
|
+
detail: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ReceiptTerminal {
|
|
10
|
+
outcome: ReceiptOutcome;
|
|
11
|
+
source: string;
|
|
12
|
+
reason?: string;
|
|
13
|
+
predicate_check?: ReceiptPredicateCheck;
|
|
14
|
+
event_id: string;
|
|
15
|
+
committed_at: string;
|
|
16
|
+
authorized_transition?: {
|
|
17
|
+
actor: 'manual-override' | 'reviewer-remediation' | 'phase-override';
|
|
18
|
+
reason: string;
|
|
19
|
+
previous_event_id: string;
|
|
20
|
+
previous_outcome?: ReceiptOutcome;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface ReceiptApplicationMarker {
|
|
24
|
+
outcome: ReceiptOutcome;
|
|
25
|
+
source: string;
|
|
26
|
+
reason?: string;
|
|
27
|
+
event_id: string;
|
|
28
|
+
committed_at: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ReceiptMembership {
|
|
31
|
+
trace_id: string;
|
|
32
|
+
entry_id: string;
|
|
33
|
+
session_id: string;
|
|
34
|
+
phase?: string;
|
|
35
|
+
task_id?: string;
|
|
36
|
+
agent?: string;
|
|
37
|
+
critical: boolean;
|
|
38
|
+
rank?: number;
|
|
39
|
+
score?: number;
|
|
40
|
+
committed_at: string;
|
|
41
|
+
membership_event_id: string;
|
|
42
|
+
grace_days: number;
|
|
43
|
+
phase_close_intent_at?: string;
|
|
44
|
+
phase_closed_at?: string;
|
|
45
|
+
terminal?: ReceiptTerminal;
|
|
46
|
+
/** Append-only audited terminal transitions; `terminal` is the current gate state. */
|
|
47
|
+
terminal_history?: ReceiptTerminal[];
|
|
48
|
+
application_marker?: ReceiptApplicationMarker;
|
|
49
|
+
cohort_id?: string;
|
|
50
|
+
source_link_id?: string;
|
|
51
|
+
exposure_kind: ReceiptExposureKind;
|
|
52
|
+
origin: 'v2' | 'legacy';
|
|
53
|
+
}
|
|
54
|
+
export type ReceiptExposureKind = 'architect_directive' | 'delegate_directive' | 'manual_recall' | 'legacy_unknown';
|
|
55
|
+
interface EmptyTrace {
|
|
56
|
+
trace_id: string;
|
|
57
|
+
session_id: string;
|
|
58
|
+
phase?: string;
|
|
59
|
+
task_id?: string;
|
|
60
|
+
committed_at: string;
|
|
61
|
+
empty_event_id: string;
|
|
62
|
+
grace_days: number;
|
|
63
|
+
phase_close_intent_at?: string;
|
|
64
|
+
phase_closed_at?: string;
|
|
65
|
+
terminal_event_id?: string;
|
|
66
|
+
}
|
|
67
|
+
interface PhaseLifecycle {
|
|
68
|
+
phase: string;
|
|
69
|
+
session_id: string;
|
|
70
|
+
task_id?: string;
|
|
71
|
+
intent_event_id?: string;
|
|
72
|
+
intent_at?: string;
|
|
73
|
+
closed_event_id?: string;
|
|
74
|
+
closed_at?: string;
|
|
75
|
+
}
|
|
76
|
+
interface ReceiptAuditSummary {
|
|
77
|
+
original_seq: number;
|
|
78
|
+
original_hash: string;
|
|
79
|
+
event_id: string;
|
|
80
|
+
timestamp: string;
|
|
81
|
+
kind: ReceiptTransitionKind;
|
|
82
|
+
trace_id?: string;
|
|
83
|
+
phase?: string;
|
|
84
|
+
entry_ids?: string[];
|
|
85
|
+
reason_codes?: string[];
|
|
86
|
+
}
|
|
87
|
+
export type ReceiptTransitionKind = 'membership_committed' | 'empty_retrieval_committed' | 'terminal_committed' | 'terminal_attempt_rejected' | 'terminal_attempt_idempotent' | 'authorized_transition_committed' | 'application_marker_committed' | 'phase_close_intent' | 'phase_closed' | 'legacy_imported' | 'legacy_unverifiable' | 'cutover_completed' | 'checkpoint';
|
|
88
|
+
interface LedgerState {
|
|
89
|
+
memberships: Map<string, ReceiptMembership>;
|
|
90
|
+
traceIds: Set<string>;
|
|
91
|
+
emptyTraces: Map<string, EmptyTrace>;
|
|
92
|
+
cutoverCompleted: boolean;
|
|
93
|
+
legacyUnverifiable: boolean;
|
|
94
|
+
legacyTraceRegistry: Set<string>;
|
|
95
|
+
legacyUnverifiableTraceIds: Set<string>;
|
|
96
|
+
phaseLifecycle: Map<string, PhaseLifecycle>;
|
|
97
|
+
auditTail: ReceiptAuditSummary[];
|
|
98
|
+
lastSeq: number;
|
|
99
|
+
lastHash: string;
|
|
100
|
+
recordCount: number;
|
|
101
|
+
observations: KnowledgeReceiptTransitionObservation[];
|
|
102
|
+
}
|
|
103
|
+
export type ReceiptUnavailable = {
|
|
104
|
+
ok: false;
|
|
105
|
+
code: ReceiptStoreErrorCode | 'legacy_unverifiable';
|
|
106
|
+
detail: string;
|
|
107
|
+
/** Compatibility alias for hook responses that surface typed uncertainty. */
|
|
108
|
+
uncertainty: string;
|
|
109
|
+
};
|
|
110
|
+
export type ReceiptLedgerResult<T> = ({
|
|
111
|
+
ok: true;
|
|
112
|
+
} & T) | ReceiptUnavailable;
|
|
113
|
+
declare function writeSnapshot(paths: ReceiptLedgerPaths, state: LedgerState): Promise<void>;
|
|
114
|
+
export interface CommitDisplayedMembershipInput {
|
|
115
|
+
trace_id: string;
|
|
116
|
+
session_id: string;
|
|
117
|
+
phase?: string;
|
|
118
|
+
task_id?: string;
|
|
119
|
+
agent?: string;
|
|
120
|
+
entries: Array<{
|
|
121
|
+
entry_id: string;
|
|
122
|
+
critical: boolean;
|
|
123
|
+
rank?: number;
|
|
124
|
+
score?: number;
|
|
125
|
+
}>;
|
|
126
|
+
grace_days?: number;
|
|
127
|
+
cohort_id?: string;
|
|
128
|
+
source_link_id?: string;
|
|
129
|
+
/** Producer provenance used by application gates; omitted callers fail closed. */
|
|
130
|
+
exposure_kind?: ReceiptExposureKind;
|
|
131
|
+
}
|
|
132
|
+
export declare function commitDisplayedMembership(directory: string, input: CommitDisplayedMembershipInput): Promise<ReceiptLedgerResult<{
|
|
133
|
+
event_id: string;
|
|
134
|
+
memberships: ReceiptMembership[];
|
|
135
|
+
}>>;
|
|
136
|
+
export declare function commitEmptyRetrieval(directory: string, input: Omit<CommitDisplayedMembershipInput, 'entries'>): Promise<ReceiptLedgerResult<{
|
|
137
|
+
event_id: string;
|
|
138
|
+
terminal_event_id: string;
|
|
139
|
+
}>>;
|
|
140
|
+
export interface TerminalBatchInput {
|
|
141
|
+
trace_id: string;
|
|
142
|
+
session_id: string;
|
|
143
|
+
phase?: string;
|
|
144
|
+
task_id?: string;
|
|
145
|
+
agent?: string;
|
|
146
|
+
cohort_id?: string;
|
|
147
|
+
source_link_id?: string;
|
|
148
|
+
grace_days?: number;
|
|
149
|
+
items?: Array<{
|
|
150
|
+
entry_id: string;
|
|
151
|
+
outcome: ReceiptOutcome;
|
|
152
|
+
source?: string;
|
|
153
|
+
reason?: string;
|
|
154
|
+
predicate_check?: ReceiptPredicateCheck;
|
|
155
|
+
event_id?: string;
|
|
156
|
+
}>;
|
|
157
|
+
/** Alias used by reviewer/delegate batch producers. */
|
|
158
|
+
terminals?: Array<{
|
|
159
|
+
entry_id: string;
|
|
160
|
+
outcome: ReceiptOutcome;
|
|
161
|
+
source?: string;
|
|
162
|
+
reason?: string;
|
|
163
|
+
predicate_check?: ReceiptPredicateCheck;
|
|
164
|
+
event_id?: string;
|
|
165
|
+
}>;
|
|
166
|
+
no_relevant_knowledge?: boolean;
|
|
167
|
+
authorization?: {
|
|
168
|
+
actor: 'manual-override' | 'reviewer-remediation' | 'phase-override';
|
|
169
|
+
reason: string;
|
|
170
|
+
expected_event_id: string;
|
|
171
|
+
expected_outcome?: ReceiptOutcome;
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export declare function validateAndCommitTerminalBatch(directory: string, input: TerminalBatchInput): Promise<ReceiptLedgerResult<{
|
|
175
|
+
accepted: Array<{
|
|
176
|
+
entry_id: string;
|
|
177
|
+
outcome: ReceiptOutcome;
|
|
178
|
+
event_id: string;
|
|
179
|
+
}>;
|
|
180
|
+
committed: Array<{
|
|
181
|
+
entry_id: string;
|
|
182
|
+
outcome: ReceiptOutcome;
|
|
183
|
+
event_id: string;
|
|
184
|
+
}>;
|
|
185
|
+
idempotent: string[];
|
|
186
|
+
idempotent_events: Array<{
|
|
187
|
+
entry_id: string;
|
|
188
|
+
outcome: ReceiptOutcome;
|
|
189
|
+
event_id: string;
|
|
190
|
+
}>;
|
|
191
|
+
rejected: Array<{
|
|
192
|
+
entry_id: string;
|
|
193
|
+
reason: string;
|
|
194
|
+
}>;
|
|
195
|
+
closes_no_relevant: boolean;
|
|
196
|
+
terminal_event_id?: string;
|
|
197
|
+
}>>;
|
|
198
|
+
interface ApplicationMarkerBatchInput {
|
|
199
|
+
trace_id: string;
|
|
200
|
+
session_id: string;
|
|
201
|
+
items?: Array<{
|
|
202
|
+
entry_id: string;
|
|
203
|
+
outcome: ReceiptOutcome;
|
|
204
|
+
source?: string;
|
|
205
|
+
reason?: string;
|
|
206
|
+
}>;
|
|
207
|
+
markers?: Array<{
|
|
208
|
+
entry_id: string;
|
|
209
|
+
outcome: ReceiptOutcome;
|
|
210
|
+
source?: string;
|
|
211
|
+
reason?: string;
|
|
212
|
+
}>;
|
|
213
|
+
}
|
|
214
|
+
declare function commitApplicationMarkerBatch(directory: string, input: ApplicationMarkerBatchInput): Promise<ReceiptLedgerResult<{
|
|
215
|
+
committed: Array<{
|
|
216
|
+
entry_id: string;
|
|
217
|
+
outcome: ReceiptOutcome;
|
|
218
|
+
event_id: string;
|
|
219
|
+
}>;
|
|
220
|
+
idempotent: string[];
|
|
221
|
+
rejected: Array<{
|
|
222
|
+
entry_id: string;
|
|
223
|
+
reason: string;
|
|
224
|
+
}>;
|
|
225
|
+
}>>;
|
|
226
|
+
export interface ApplicationOutcomeBatchInput {
|
|
227
|
+
trace_id: string;
|
|
228
|
+
session_id: string;
|
|
229
|
+
grace_days?: number;
|
|
230
|
+
items: Array<{
|
|
231
|
+
entry_id: string;
|
|
232
|
+
outcome: ReceiptOutcome;
|
|
233
|
+
source?: string;
|
|
234
|
+
reason?: string;
|
|
235
|
+
}>;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Atomically commit the architect application marker and its receipt terminal.
|
|
239
|
+
* Each exact pair is validated before either state projection is staged, so a
|
|
240
|
+
* terminal conflict can never leave a marker behind. Existing same-outcome
|
|
241
|
+
* state is preserved and any missing half is repaired in the same journal row.
|
|
242
|
+
*/
|
|
243
|
+
export declare function commitApplicationOutcomeBatch(directory: string, input: ApplicationOutcomeBatchInput): Promise<ReceiptLedgerResult<{
|
|
244
|
+
committed: Array<{
|
|
245
|
+
entry_id: string;
|
|
246
|
+
outcome: ReceiptOutcome;
|
|
247
|
+
marker_event_id: string;
|
|
248
|
+
terminal_event_id: string;
|
|
249
|
+
}>;
|
|
250
|
+
idempotent: Array<{
|
|
251
|
+
entry_id: string;
|
|
252
|
+
outcome: ReceiptOutcome;
|
|
253
|
+
marker_event_id: string;
|
|
254
|
+
terminal_event_id: string;
|
|
255
|
+
}>;
|
|
256
|
+
rejected: Array<{
|
|
257
|
+
entry_id: string;
|
|
258
|
+
reason: string;
|
|
259
|
+
}>;
|
|
260
|
+
}>>;
|
|
261
|
+
export declare function queryLiveMemberships(directory: string, filters?: {
|
|
262
|
+
phase?: string;
|
|
263
|
+
task_id?: string;
|
|
264
|
+
session_id?: string;
|
|
265
|
+
include_terminal?: boolean;
|
|
266
|
+
include_phase_closed?: boolean;
|
|
267
|
+
exposure_kind?: ReceiptExposureKind;
|
|
268
|
+
grace_days?: number;
|
|
269
|
+
}): Promise<ReceiptLedgerResult<{
|
|
270
|
+
memberships: ReceiptMembership[];
|
|
271
|
+
}>>;
|
|
272
|
+
export declare function queryHistoricalOutcomes(directory: string, entryIds?: string[], graceDays?: number): Promise<ReceiptLedgerResult<{
|
|
273
|
+
memberships: ReceiptMembership[];
|
|
274
|
+
}>>;
|
|
275
|
+
/**
|
|
276
|
+
* Compact the authoritative receipt journal under its dedicated lock.
|
|
277
|
+
* Read-only queries intentionally never rewrite receipt state, so maintenance
|
|
278
|
+
* callers and focused recovery tests use this explicit mutation boundary.
|
|
279
|
+
*/
|
|
280
|
+
export declare function compactKnowledgeReceiptLedger(directory: string): Promise<ReceiptLedgerResult<{
|
|
281
|
+
compacted: true;
|
|
282
|
+
}>>;
|
|
283
|
+
export declare const recordPhaseCloseIntent: (directory: string, phase: string, sessionId?: string, taskId?: string) => Promise<ReceiptLedgerResult<{
|
|
284
|
+
event_id: string;
|
|
285
|
+
}>>;
|
|
286
|
+
export declare const commitPhaseClosed: (directory: string, phase: string, sessionId?: string, taskId?: string) => Promise<ReceiptLedgerResult<{
|
|
287
|
+
event_id: string;
|
|
288
|
+
}>>;
|
|
289
|
+
export declare function reconcilePhaseClose(directory: string, phase: string, durablePlanClosed: boolean, sessionId?: string, taskId?: string): Promise<ReceiptLedgerResult<{
|
|
290
|
+
reconciled: boolean;
|
|
291
|
+
}>>;
|
|
292
|
+
export declare function ensureLegacyCutover(directory: string, graceDays?: number): Promise<ReceiptLedgerResult<{
|
|
293
|
+
completed: true;
|
|
294
|
+
}>>;
|
|
295
|
+
export declare const _internals: {
|
|
296
|
+
nowMs: () => number;
|
|
297
|
+
writeSnapshot: typeof writeSnapshot;
|
|
298
|
+
atomicWriteFsynced: typeof atomicWriteFsynced;
|
|
299
|
+
/** Test-only migration fixture for pre-atomic marker-only state. */
|
|
300
|
+
commitApplicationMarkerBatch: typeof commitApplicationMarkerBatch;
|
|
301
|
+
maxJournalRecords: number;
|
|
302
|
+
maxArchiveRecords: number;
|
|
303
|
+
maxArchiveBytes: number;
|
|
304
|
+
};
|
|
305
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Best-effort observability projection for authoritative receipt transitions.
|
|
3
|
+
* The V2 journal remains authoritative; telemetry runs best-effort after commit.
|
|
4
|
+
*/
|
|
5
|
+
import { emit } from '../telemetry.js';
|
|
6
|
+
import type { ReceiptOutcome } from './knowledge-receipt-validator.js';
|
|
7
|
+
export type KnowledgeReceiptObservedTransition = 'membership_committed' | 'empty_retrieval_committed' | 'terminal_committed' | 'terminal_attempt_rejected' | 'terminal_attempt_idempotent' | 'authorized_transition_committed' | 'application_marker_committed' | 'phase_close_intent' | 'phase_closed' | 'legacy_imported' | 'legacy_unverifiable' | 'cutover_completed' | 'checkpoint';
|
|
8
|
+
export type KnowledgeReceiptObservationReasonCode = 'committed' | 'idempotent' | 'trace_not_found' | 'id_not_in_trace' | 'wrong_session' | 'wrong_phase' | 'wrong_task' | 'duplicate_conflicting_terminal' | 'event_id_conflict' | 'invalid_outcome' | 'empty_receipt' | 'lock_timeout' | 'store_unavailable' | 'store_corrupt' | 'legacy_unverifiable' | 'unauthorized_transition';
|
|
9
|
+
export interface KnowledgeReceiptTransitionObservation {
|
|
10
|
+
transition: KnowledgeReceiptObservedTransition;
|
|
11
|
+
reasonCode: KnowledgeReceiptObservationReasonCode;
|
|
12
|
+
schemaVersion: number;
|
|
13
|
+
knowledgeTraceId?: string;
|
|
14
|
+
knowledgeEntryId?: string;
|
|
15
|
+
sessionId?: string;
|
|
16
|
+
taskId?: string;
|
|
17
|
+
phase?: string;
|
|
18
|
+
/** Domain value only; never projected to the generic observability outcome. */
|
|
19
|
+
receiptOutcome?: ReceiptOutcome;
|
|
20
|
+
/** Bounded domain code only; arbitrary prose is deliberately rejected. */
|
|
21
|
+
receiptSource?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Emit bounded diagnostics fail-open after an authoritative transition. */
|
|
24
|
+
export declare function emitKnowledgeReceiptTransition(observation: KnowledgeReceiptTransitionObservation): void;
|
|
25
|
+
/** Dependency seam for focused fail-open tests. */
|
|
26
|
+
export declare const _internals: {
|
|
27
|
+
emit: typeof emit;
|
|
28
|
+
};
|