@codyswann/lisa 4.108.3 → 4.109.1
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/dist/cli/gate-commands.d.ts +11 -10
- package/dist/cli/gate-commands.d.ts.map +1 -1
- package/dist/cli/gate-commands.js +23 -0
- package/dist/cli/gate-commands.js.map +1 -1
- package/dist/cli/learnings-retire-cmd.d.ts +26 -0
- package/dist/cli/learnings-retire-cmd.d.ts.map +1 -0
- package/dist/cli/learnings-retire-cmd.js +64 -0
- package/dist/cli/learnings-retire-cmd.js.map +1 -0
- package/dist/core/learnings-document.d.ts +35 -2
- package/dist/core/learnings-document.d.ts.map +1 -1
- package/dist/core/learnings-document.js +89 -17
- package/dist/core/learnings-document.js.map +1 -1
- package/dist/core/learnings-file-safety.d.ts +5 -2
- package/dist/core/learnings-file-safety.d.ts.map +1 -1
- package/dist/core/learnings-file-safety.js +34 -13
- package/dist/core/learnings-file-safety.js.map +1 -1
- package/dist/core/learnings-retire.d.ts +7 -0
- package/dist/core/learnings-retire.d.ts.map +1 -1
- package/dist/core/learnings-retire.js +41 -9
- package/dist/core/learnings-retire.js.map +1 -1
- package/dist/core/learnings-writer.d.ts.map +1 -1
- package/dist/core/learnings-writer.js +117 -17
- package/dist/core/learnings-writer.js.map +1 -1
- package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +7 -1
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/package.json +4 -4
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-learnings-audit/SKILL.md +4 -0
- package/plugins/lisa/skills/lisa-learnings-audit/SKILL.md +4 -0
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-agy/skills/lisa-learnings-audit/SKILL.md +4 -0
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/skills/lisa-learnings-audit/SKILL.md +4 -0
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/skills/lisa-learnings-audit/SKILL.md +4 -0
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/skills/lisa-learnings-audit/SKILL.md +4 -0
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/src/base/skills/lisa-learnings-audit/SKILL.md +4 -0
|
@@ -5,15 +5,16 @@ import type { FileUpstreamOptions } from "./file-upstream-cmd.js";
|
|
|
5
5
|
* Gate runners kept structural to avoid importing the whole CLI dependency
|
|
6
6
|
* record.
|
|
7
7
|
*
|
|
8
|
-
* `merge-learnings`, `install-merge-driver`,
|
|
9
|
-
* deliberately NOT members. They are invoked by git, by
|
|
10
|
-
* repository, or by the gardener draining its buffer
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
8
|
+
* `merge-learnings`, `install-merge-driver`, `learnings-overflow`, and
|
|
9
|
+
* `learnings-retire` are deliberately NOT members. They are invoked by git, by
|
|
10
|
+
* an operator repairing a repository, or by the gardener draining its buffer
|
|
11
|
+
* or retiring a ledger entry — never substituted by the root CLI — and all
|
|
12
|
+
* four mutate real state: the merge driver overwrites the file git hands it,
|
|
13
|
+
* the installer writes local git config, the drain removes entries from the
|
|
14
|
+
* only durable copy of a dropped capture, and the retire removes a ledger
|
|
15
|
+
* entry. An optional, defaulted field would be the worst shape here: a caller
|
|
16
|
+
* that believed it had stubbed every gate command would silently run the real
|
|
17
|
+
* driver against real files. Leaving them off the record makes non-injectability
|
|
17
18
|
* explicit; they are covered directly by unit tests and by end-to-end tests
|
|
18
19
|
* that drive real `git merge`.
|
|
19
20
|
*/
|
|
@@ -30,7 +31,7 @@ export interface GateCommandDependencies {
|
|
|
30
31
|
* ledger, so a network update check would stall the merge and pollute the
|
|
31
32
|
* driver's output.
|
|
32
33
|
*/
|
|
33
|
-
export declare const GATE_COMMAND_NAMES: readonly ["check-learnings-budget", "file-upstream", "learnings-overflow", "merge-learnings", "install-merge-driver"];
|
|
34
|
+
export declare const GATE_COMMAND_NAMES: readonly ["check-learnings-budget", "file-upstream", "learnings-overflow", "learnings-retire", "merge-learnings", "install-merge-driver"];
|
|
34
35
|
/**
|
|
35
36
|
* Register all non-project gate commands.
|
|
36
37
|
* @param program - Commander program
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gate-commands.d.ts","sourceRoot":"","sources":["../../src/cli/gate-commands.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"gate-commands.d.ts","sourceRoot":"","sources":["../../src/cli/gate-commands.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAelE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,uBAAuB;IACtC,uBAAuB,EAAE,CACvB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,KACtC,OAAO,CAAC,MAAM,CAAC,CAAC;IACrB,eAAe,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACpE;AAED;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,2IAOrB,CAAC;AAyJX;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,uBAAuB,GACpC,IAAI,CAON"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { runInstallMergeDriver } from "./install-merge-driver-cmd.js";
|
|
2
2
|
import { runLearningsOverflow, } from "./learnings-overflow-cmd.js";
|
|
3
|
+
import { runLearningsRetire, } from "./learnings-retire-cmd.js";
|
|
3
4
|
import { runMergeLearnings, } from "./merge-learnings-cmd.js";
|
|
4
5
|
/**
|
|
5
6
|
* Gate commands skip the root npm update check.
|
|
@@ -12,6 +13,7 @@ export const GATE_COMMAND_NAMES = [
|
|
|
12
13
|
"check-learnings-budget",
|
|
13
14
|
"file-upstream",
|
|
14
15
|
"learnings-overflow",
|
|
16
|
+
"learnings-retire",
|
|
15
17
|
"merge-learnings",
|
|
16
18
|
"install-merge-driver",
|
|
17
19
|
];
|
|
@@ -68,6 +70,26 @@ function addLearningsOverflowCommand(program) {
|
|
|
68
70
|
process.exitCode = code;
|
|
69
71
|
});
|
|
70
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Register the fingerprint-guarded ledger retire the gardener uses.
|
|
75
|
+
*
|
|
76
|
+
* Not injectable, for the same reason as the overflow drain: it removes a
|
|
77
|
+
* ledger entry, so a caller must never be able to stub it away.
|
|
78
|
+
* @param program - Commander program
|
|
79
|
+
*/
|
|
80
|
+
function addLearningsRetireCommand(program) {
|
|
81
|
+
program
|
|
82
|
+
.command("learnings-retire")
|
|
83
|
+
.description("Remove one fingerprint-stamped entry from the learnings ledger (JSON output)")
|
|
84
|
+
.requiredOption("--id <id>", "Stable id of the entry to retire")
|
|
85
|
+
.requiredOption("--fingerprint <fingerprint>", "Fingerprint observed at that id; a mismatch refuses and writes nothing")
|
|
86
|
+
.requiredOption("--reason <text>", "Why the entry is retired (echoed into the JSON proof record)")
|
|
87
|
+
.action(async (options) => {
|
|
88
|
+
const code = await runLearningsRetire(options);
|
|
89
|
+
if (code !== 0)
|
|
90
|
+
process.exitCode = code;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
71
93
|
/**
|
|
72
94
|
* Register the project-learnings union merge driver.
|
|
73
95
|
*
|
|
@@ -114,6 +136,7 @@ export function addGateCommands(program, dependencies) {
|
|
|
114
136
|
addCheckLearningsBudgetCommand(program, dependencies);
|
|
115
137
|
addFileUpstreamCommand(program, dependencies);
|
|
116
138
|
addLearningsOverflowCommand(program);
|
|
139
|
+
addLearningsRetireCommand(program);
|
|
117
140
|
addMergeLearningsCommand(program);
|
|
118
141
|
addInstallMergeDriverCommand(program);
|
|
119
142
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gate-commands.js","sourceRoot":"","sources":["../../src/cli/gate-commands.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EACL,oBAAoB,GAErB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,iBAAiB,GAElB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"gate-commands.js","sourceRoot":"","sources":["../../src/cli/gate-commands.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EACL,oBAAoB,GAErB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,kBAAkB,GAEnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,iBAAiB,GAElB,MAAM,0BAA0B,CAAC;AA2BlC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,wBAAwB;IACxB,eAAe;IACf,oBAAoB;IACpB,kBAAkB;IAClB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,OAAgB;IACpD,OAAO;SACJ,OAAO,CAAC,sBAAsB,CAAC;SAC/B,WAAW,CACV,uEAAuE,CACxE;SACA,QAAQ,CAAC,QAAQ,EAAE,gDAAgD,CAAC;SACpE,MAAM,CAAC,KAAK,EAAE,UAA8B,EAAE,EAAE;QAC/C,MAAM,IAAI,GAAG,MAAM,qBAAqB,CAAC,UAAU,CAAC,CAAC;QACrD,IAAI,IAAI,KAAK,CAAC;YAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC1C,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAgB,EAChB,YAAqC;IAErC,8BAA8B,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACtD,sBAAsB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9C,2BAA2B,CAAC,OAAO,CAAC,CAAC;IACrC,yBAAyB,CAAC,OAAO,CAAC,CAAC;IACnC,wBAAwB,CAAC,OAAO,CAAC,CAAC;IAClC,4BAA4B,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Command-line options for {@link runLearningsRetire}. */
|
|
2
|
+
export interface LearningsRetireOptions {
|
|
3
|
+
/** Stable id of the entry to retire. */
|
|
4
|
+
readonly id: string;
|
|
5
|
+
/** FULL fingerprint the caller observed at that id (never the marker hash). */
|
|
6
|
+
readonly fingerprint: string;
|
|
7
|
+
/** Human-readable proof, echoed into the JSON output only. */
|
|
8
|
+
readonly reason: string;
|
|
9
|
+
}
|
|
10
|
+
/** Injectable collaborators for {@link runLearningsRetire}. */
|
|
11
|
+
export interface LearningsRetireDependencies {
|
|
12
|
+
/** Working directory used to resolve the project config (defaults to cwd). */
|
|
13
|
+
readonly cwd?: string;
|
|
14
|
+
/** Sink for the JSON payload (defaults to stdout). */
|
|
15
|
+
readonly log?: (message: string) => void;
|
|
16
|
+
/** Sink for the failure diagnostic (defaults to stderr). */
|
|
17
|
+
readonly error?: (message: string) => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Retire one stamped entry and print the outcome as JSON.
|
|
21
|
+
* @param options - Parsed command-line options
|
|
22
|
+
* @param dependencies - Injectable collaborators for tests
|
|
23
|
+
* @returns Process exit code: 0 only when the entry was retired
|
|
24
|
+
*/
|
|
25
|
+
export declare function runLearningsRetire(options: LearningsRetireOptions, dependencies?: LearningsRetireDependencies): Promise<number>;
|
|
26
|
+
//# sourceMappingURL=learnings-retire-cmd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"learnings-retire-cmd.d.ts","sourceRoot":"","sources":["../../src/cli/learnings-retire-cmd.ts"],"names":[],"mappings":"AAsBA,2DAA2D;AAC3D,MAAM,WAAW,sBAAsB;IACrC,wCAAwC;IACxC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,+EAA+E;IAC/E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,8DAA8D;IAC9D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,+DAA+D;AAC/D,MAAM,WAAW,2BAA2B;IAC1C,8EAA8E;IAC9E,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,sDAAsD;IACtD,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,4DAA4D;IAC5D,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,sBAAsB,EAC/B,YAAY,GAAE,2BAAgC,GAC7C,OAAO,CAAC,MAAM,CAAC,CA4BjB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `lisa learnings-retire` — remove one fingerprint-stamped entry from the
|
|
3
|
+
* project learnings ledger (CodySwannGT/lisa#4536), through the
|
|
4
|
+
* fingerprint-guarded `retireLearningEntry` API (CodySwannGT/lisa#4530).
|
|
5
|
+
*
|
|
6
|
+
* This is the gardener's RETIRE handle. The audit skill is forbidden from
|
|
7
|
+
* hand-parsing or hand-editing any learnings surface, so a RETIRE verdict needs
|
|
8
|
+
* a command that carries the contract's containment checks, cross-process lock,
|
|
9
|
+
* fingerprint guard, and atomic write — exactly as `learnings-overflow` ships
|
|
10
|
+
* the drain. It also works on a ledger that is already over its cap, which is
|
|
11
|
+
* the state a retire most often exists to repair.
|
|
12
|
+
*
|
|
13
|
+
* Output is JSON because the consumer is an agent. Only an applied retire exits
|
|
14
|
+
* 0: a stale fingerprint or an unknown id writes nothing and exits 1, so a
|
|
15
|
+
* script cannot mistake a refused retire for a completed one.
|
|
16
|
+
* @module cli/learnings-retire-cmd
|
|
17
|
+
*/
|
|
18
|
+
import { retireLearningEntry, } from "../core/learnings-retire.js";
|
|
19
|
+
/**
|
|
20
|
+
* Retire one stamped entry and print the outcome as JSON.
|
|
21
|
+
* @param options - Parsed command-line options
|
|
22
|
+
* @param dependencies - Injectable collaborators for tests
|
|
23
|
+
* @returns Process exit code: 0 only when the entry was retired
|
|
24
|
+
*/
|
|
25
|
+
export async function runLearningsRetire(options, dependencies = {}) {
|
|
26
|
+
const cwd = dependencies.cwd ?? process.cwd();
|
|
27
|
+
const log = dependencies.log ?? ((message) => console.log(message));
|
|
28
|
+
const error = dependencies.error ?? ((message) => console.error(message));
|
|
29
|
+
try {
|
|
30
|
+
if (typeof options.reason !== "string" || options.reason.trim() === "") {
|
|
31
|
+
throw new Error("Invalid --reason: expected a non-empty proof string");
|
|
32
|
+
}
|
|
33
|
+
const result = await retireLearningEntry(cwd, options.id, options.fingerprint);
|
|
34
|
+
// The reason is the caller's proof record, not ledger content: it is
|
|
35
|
+
// echoed for the deleting PR to cite and never written anywhere.
|
|
36
|
+
log(JSON.stringify({ ...result, reason: options.reason }, null, 2));
|
|
37
|
+
const refusal = describeRefusal(result);
|
|
38
|
+
if (refusal === undefined) {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
error(`learnings-retire: ${refusal}`);
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
catch (caught) {
|
|
45
|
+
const detail = caught instanceof Error ? caught.message : String(caught);
|
|
46
|
+
error(`learnings-retire: ${detail}`);
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Explain a no-write outcome in one line, or nothing for an applied retire.
|
|
52
|
+
* @param result - Structured retire outcome
|
|
53
|
+
* @returns Operator-readable refusal, or undefined when the entry was retired
|
|
54
|
+
*/
|
|
55
|
+
function describeRefusal(result) {
|
|
56
|
+
if (result.status === "stale") {
|
|
57
|
+
return `entry '${result.id}' is stale: expected fingerprint ${result.expectedFingerprint} but the ledger holds ${result.actualFingerprint}. Nothing was written; re-read the ledger and retry with the current fingerprint.`;
|
|
58
|
+
}
|
|
59
|
+
if (result.status === "not-found") {
|
|
60
|
+
return `entry '${result.id}' not found in the project learnings ledger. Nothing was written.`;
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=learnings-retire-cmd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"learnings-retire-cmd.js","sourceRoot":"","sources":["../../src/cli/learnings-retire-cmd.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACL,mBAAmB,GAEpB,MAAM,6BAA6B,CAAC;AAsBrC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAA+B,EAC/B,eAA4C,EAAE;IAE9C,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC9C,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,IAAI,CAAC,CA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OAAO,EAAE,CAAC;QAC9B,OAAO,UAAU,MAAM,CAAC,EAAE,oCAAoC,MAAM,CAAC,mBAAmB,yBAAyB,MAAM,CAAC,iBAAiB,mFAAmF,CAAC;IAC/N,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,UAAU,MAAM,CAAC,EAAE,mEAAmE,CAAC;IAChG,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -22,19 +22,42 @@ export interface ParsedLearningsDocument {
|
|
|
22
22
|
/** Byte ceiling that governed the source version before normalization. */
|
|
23
23
|
readonly sourceMaxTokens: number;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Hard ceiling for a deliberately tolerant, over-budget ledger read.
|
|
27
|
+
*
|
|
28
|
+
* A ledger that slipped over `maxTokens` (two merges that each fit, racing)
|
|
29
|
+
* must stay openable by the writers that would SHRINK it — otherwise the state
|
|
30
|
+
* they exist to repair locks them out (CodySwannGT/lisa#4536). The tolerance is
|
|
31
|
+
* bounded rather than open-ended: four times the cap is far past any real race
|
|
32
|
+
* yet still keeps a hostile or runaway file from being loaded wholesale.
|
|
33
|
+
*/
|
|
34
|
+
export declare const LEARNINGS_OVER_BUDGET_READ_CEILING: number;
|
|
35
|
+
/** Read policy shared by the ledger reader and parser. */
|
|
36
|
+
export interface LearningsReadOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Accept a document above `maxTokens` (up to
|
|
39
|
+
* {@link LEARNINGS_OVER_BUDGET_READ_CEILING}) and skip the document budget.
|
|
40
|
+
* Only shrink-only writers — retire, and supersede on an over-cap ledger —
|
|
41
|
+
* pass this; conflict markers, format, entry schema, and identity uniqueness
|
|
42
|
+
* are still enforced.
|
|
43
|
+
*/
|
|
44
|
+
readonly allowOverBudget?: boolean;
|
|
45
|
+
}
|
|
25
46
|
/**
|
|
26
47
|
* Parse and revalidate an existing file before it participates in a write.
|
|
27
48
|
* @param content - Existing learnings document
|
|
49
|
+
* @param options - Read policy; defaults to the strict in-budget read
|
|
28
50
|
* @returns Revalidated entries from the document
|
|
29
51
|
*/
|
|
30
|
-
export declare function parseLearningsFile(content: string): LearningEntry[];
|
|
52
|
+
export declare function parseLearningsFile(content: string, options?: LearningsReadOptions): LearningEntry[];
|
|
31
53
|
/**
|
|
32
54
|
* Parse a v1 or v2 document while retaining the source-version facts writers
|
|
33
55
|
* need to migrate only when they already have a reason to mutate.
|
|
34
56
|
* @param content - Existing learnings document
|
|
57
|
+
* @param options - Read policy; defaults to the strict in-budget read
|
|
35
58
|
* @returns Normalized entries plus source-version and canonicality metadata
|
|
36
59
|
*/
|
|
37
|
-
export declare function parseLearningsDocument(content: string): ParsedLearningsDocument;
|
|
60
|
+
export declare function parseLearningsDocument(content: string, options?: LearningsReadOptions): ParsedLearningsDocument;
|
|
38
61
|
/**
|
|
39
62
|
* A document that does not fit the hard entry-count or token budget.
|
|
40
63
|
*
|
|
@@ -53,6 +76,16 @@ export declare class LearningsBudgetError extends Error {
|
|
|
53
76
|
*/
|
|
54
77
|
constructor(message: string);
|
|
55
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* The one definition of "this ledger is over its hard budget" that every
|
|
81
|
+
* shrink-only writer shares (CodySwannGT/lisa#4536): over the byte cap OR over
|
|
82
|
+
* the entry cap. Retire and over-cap supersede must agree on it, or one writer
|
|
83
|
+
* can repair a ledger the other refuses to touch.
|
|
84
|
+
* @param bytes - Measured document size
|
|
85
|
+
* @param count - Number of entries in the document
|
|
86
|
+
* @returns True when either hard budget is exceeded
|
|
87
|
+
*/
|
|
88
|
+
export declare function isLedgerOverBudget(bytes: number, count: number): boolean;
|
|
56
89
|
/**
|
|
57
90
|
* Enforce the shared entry-count and model-agnostic token upper bounds.
|
|
58
91
|
* @param content - Canonical document
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"learnings-document.d.ts","sourceRoot":"","sources":["../../src/core/learnings-document.ts"],"names":[],"mappings":"AAAA,+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;IACnC;;;;;;OAMG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;CACpC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,oBAAyB,GACjC,aAAa,EAAE,CAEjB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,oBAAyB,GACjC,uBAAuB,CAqDzB;AAsHD;;;;;;;;;;GAUG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C;;;OAGG;gBACS,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAKxE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,MAAqC,GAC/C,IAAI,CAYN;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK1E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAIvD;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,UAAU,GACjB,MAAM,GAAG,SAAS,CAEpB"}
|
|
@@ -43,21 +43,33 @@ export function renderLearningsFile(entries) {
|
|
|
43
43
|
const lines = entries.map(entry => JSON.stringify(entry)).join("\n");
|
|
44
44
|
return `${FILE_HEADER}${JSON_FENCE_START}${lines}${JSON_FENCE_END}`;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Hard ceiling for a deliberately tolerant, over-budget ledger read.
|
|
48
|
+
*
|
|
49
|
+
* A ledger that slipped over `maxTokens` (two merges that each fit, racing)
|
|
50
|
+
* must stay openable by the writers that would SHRINK it — otherwise the state
|
|
51
|
+
* they exist to repair locks them out (CodySwannGT/lisa#4536). The tolerance is
|
|
52
|
+
* bounded rather than open-ended: four times the cap is far past any real race
|
|
53
|
+
* yet still keeps a hostile or runaway file from being loaded wholesale.
|
|
54
|
+
*/
|
|
55
|
+
export const LEARNINGS_OVER_BUDGET_READ_CEILING = 4 * LEARNINGS_CONTRACT.maxTokens;
|
|
46
56
|
/**
|
|
47
57
|
* Parse and revalidate an existing file before it participates in a write.
|
|
48
58
|
* @param content - Existing learnings document
|
|
59
|
+
* @param options - Read policy; defaults to the strict in-budget read
|
|
49
60
|
* @returns Revalidated entries from the document
|
|
50
61
|
*/
|
|
51
|
-
export function parseLearningsFile(content) {
|
|
52
|
-
return [...parseLearningsDocument(content).entries];
|
|
62
|
+
export function parseLearningsFile(content, options = {}) {
|
|
63
|
+
return [...parseLearningsDocument(content, options).entries];
|
|
53
64
|
}
|
|
54
65
|
/**
|
|
55
66
|
* Parse a v1 or v2 document while retaining the source-version facts writers
|
|
56
67
|
* need to migrate only when they already have a reason to mutate.
|
|
57
68
|
* @param content - Existing learnings document
|
|
69
|
+
* @param options - Read policy; defaults to the strict in-budget read
|
|
58
70
|
* @returns Normalized entries plus source-version and canonicality metadata
|
|
59
71
|
*/
|
|
60
|
-
export function parseLearningsDocument(content) {
|
|
72
|
+
export function parseLearningsDocument(content, options = {}) {
|
|
61
73
|
// Diagnose concurrent-write corruption BEFORE the byte budget. A conflicted
|
|
62
74
|
// merge duplicates the whole JSONL block, so a nearly-full ledger lands over
|
|
63
75
|
// budget and would otherwise report "exceeds maxTokens" — advice that sends
|
|
@@ -66,15 +78,18 @@ export function parseLearningsDocument(content) {
|
|
|
66
78
|
if (conflictLine !== undefined) {
|
|
67
79
|
throw conflictMarkerError(conflictLine);
|
|
68
80
|
}
|
|
69
|
-
|
|
70
|
-
|
|
81
|
+
const tolerant = options.allowOverBudget === true;
|
|
82
|
+
const sizeError = readableSizeError(content, LEARNINGS_CONTRACT.maxTokens, tolerant);
|
|
83
|
+
if (sizeError !== undefined) {
|
|
84
|
+
throw sizeError;
|
|
71
85
|
}
|
|
72
86
|
const sourceVersion = readSourceVersion(content);
|
|
73
87
|
const sourceMaxTokens = sourceVersion === 1
|
|
74
88
|
? LEGACY_LEARNINGS_MAX_TOKENS
|
|
75
89
|
: LEARNINGS_CONTRACT.maxTokens;
|
|
76
|
-
|
|
77
|
-
|
|
90
|
+
const sourceSizeError = readableSizeError(content, sourceMaxTokens, tolerant);
|
|
91
|
+
if (sourceSizeError !== undefined) {
|
|
92
|
+
throw sourceSizeError;
|
|
78
93
|
}
|
|
79
94
|
const sourceHeader = fileHeader(sourceVersion);
|
|
80
95
|
if (!content.startsWith(`${sourceHeader}${JSON_FENCE_START}`) ||
|
|
@@ -84,26 +99,70 @@ export function parseLearningsDocument(content) {
|
|
|
84
99
|
const jsonStart = sourceHeader.length + JSON_FENCE_START.length;
|
|
85
100
|
const jsonEnd = content.length - JSON_FENCE_END.length;
|
|
86
101
|
const entries = validateEveryParsedEntry(parseJsonLines(content.slice(jsonStart, jsonEnd)), sourceVersion);
|
|
102
|
+
const identityError = duplicateIdentityError(entries);
|
|
103
|
+
if (identityError !== undefined) {
|
|
104
|
+
throw identityError;
|
|
105
|
+
}
|
|
106
|
+
if (!tolerant) {
|
|
107
|
+
assertSourceBudget(content, entries, sourceVersion, sourceMaxTokens);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
sourceVersion,
|
|
111
|
+
entries,
|
|
112
|
+
canonicalSource: content === renderLearningsSource(entries, sourceVersion),
|
|
113
|
+
sourceMaxTokens,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Diagnose a document larger than the read policy allows, before JSONL parsing.
|
|
118
|
+
*
|
|
119
|
+
* Typed as a budget breach (CodySwannGT/lisa#4536): the plain `Error` this used
|
|
120
|
+
* to be made a capture against an over-cap ledger fail outright instead of
|
|
121
|
+
* reaching the overflow, which is exactly where a budget refusal belongs.
|
|
122
|
+
* @param content - Untrusted document bytes
|
|
123
|
+
* @param maxTokens - Byte cap for the declared (or current) source version
|
|
124
|
+
* @param tolerant - Whether the bounded over-budget ceiling applies instead
|
|
125
|
+
* @returns The budget refusal to throw, or undefined when the size is readable
|
|
126
|
+
*/
|
|
127
|
+
function readableSizeError(content, maxTokens, tolerant) {
|
|
128
|
+
const measured = estimateLearningTokens(content);
|
|
129
|
+
if (!tolerant && measured > maxTokens) {
|
|
130
|
+
return new LearningsBudgetError(`Project learnings payload exceeds maxTokens ${maxTokens}`);
|
|
131
|
+
}
|
|
132
|
+
if (measured > LEARNINGS_OVER_BUDGET_READ_CEILING) {
|
|
133
|
+
return new LearningsBudgetError(`Project learnings payload exceeds the over-budget read ceiling ${LEARNINGS_OVER_BUDGET_READ_CEILING} (maxTokens ${maxTokens})`);
|
|
134
|
+
}
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Diagnose duplicate ids or fingerprints, which no read policy may tolerate.
|
|
139
|
+
* @param entries - Validated entries in document order
|
|
140
|
+
* @returns The refusal to throw, or undefined when every identity is unique
|
|
141
|
+
*/
|
|
142
|
+
function duplicateIdentityError(entries) {
|
|
87
143
|
if (new Set(entries.map(entry => entry.id)).size !== entries.length) {
|
|
88
|
-
|
|
144
|
+
return new Error("Invalid project learnings payload: duplicate ids");
|
|
89
145
|
}
|
|
90
146
|
if (new Set(entries.map(entry => entry.fingerprint)).size !== entries.length) {
|
|
91
|
-
|
|
147
|
+
return new Error("Invalid project learnings payload: duplicate fingerprints");
|
|
92
148
|
}
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Enforce the source and (for v1) normalized document budgets on a strict read.
|
|
153
|
+
* @param content - Source document bytes
|
|
154
|
+
* @param entries - Validated entries
|
|
155
|
+
* @param sourceVersion - Declared contract version
|
|
156
|
+
* @param sourceMaxTokens - Byte ceiling of the declared version
|
|
157
|
+
*/
|
|
158
|
+
function assertSourceBudget(content, entries, sourceVersion, sourceMaxTokens) {
|
|
93
159
|
assertDocumentBudget(content, entries.length, "Project learnings payload", sourceMaxTokens);
|
|
94
160
|
if (sourceVersion === 1) {
|
|
95
161
|
// Compatibility is migration-closed, not merely readable: accepting a v1
|
|
96
162
|
// shape that cannot be published as bounded v2 would defer a guaranteed
|
|
97
163
|
// failure until the next legitimate append, confirmation, drain, or merge.
|
|
98
|
-
|
|
99
|
-
assertDocumentBudget(normalized, entries.length, "Normalized v1 project learnings payload");
|
|
164
|
+
assertDocumentBudget(renderLearningsFile(entries), entries.length, "Normalized v1 project learnings payload");
|
|
100
165
|
}
|
|
101
|
-
return {
|
|
102
|
-
sourceVersion,
|
|
103
|
-
entries,
|
|
104
|
-
canonicalSource: content === renderLearningsSource(entries, sourceVersion),
|
|
105
|
-
sourceMaxTokens,
|
|
106
|
-
};
|
|
107
166
|
}
|
|
108
167
|
/**
|
|
109
168
|
* Determine which compatibility contract the source declares.
|
|
@@ -155,6 +214,19 @@ export class LearningsBudgetError extends Error {
|
|
|
155
214
|
this.name = "LearningsBudgetError";
|
|
156
215
|
}
|
|
157
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* The one definition of "this ledger is over its hard budget" that every
|
|
219
|
+
* shrink-only writer shares (CodySwannGT/lisa#4536): over the byte cap OR over
|
|
220
|
+
* the entry cap. Retire and over-cap supersede must agree on it, or one writer
|
|
221
|
+
* can repair a ledger the other refuses to touch.
|
|
222
|
+
* @param bytes - Measured document size
|
|
223
|
+
* @param count - Number of entries in the document
|
|
224
|
+
* @returns True when either hard budget is exceeded
|
|
225
|
+
*/
|
|
226
|
+
export function isLedgerOverBudget(bytes, count) {
|
|
227
|
+
return (bytes > LEARNINGS_CONTRACT.maxTokens ||
|
|
228
|
+
count > LEARNINGS_CONTRACT.maxEntries);
|
|
229
|
+
}
|
|
158
230
|
/**
|
|
159
231
|
* Enforce the shared entry-count and model-agnostic token upper bounds.
|
|
160
232
|
* @param content - Canonical document
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"learnings-document.js","sourceRoot":"","sources":["../../src/core/learnings-document.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,sBAAsB,GAEvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,sBAAsB,CAAC;AAE9B,MAAM,UAAU,GAAG;;CAElB,CAAC;AACF,MAAM,UAAU,GAAG,CACjB,OAAe,EACP,EAAE,CAAC,GAAG,UAAU,iCAAiC,OAAO;;CAEjE,CAAC;AACF,MAAM,WAAW,GAAG,UAAU,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;AAC3D,MAAM,gBAAgB,GAAG,YAAY,CAAC;AACtC,MAAM,cAAc,GAAG,SAAS,CAAC;AAEjC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,eAAe,GAAG,uCAAuC,CAAC;AAEhE;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GACpC,uDAAuD,CAAC;AAE1D;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAiC;IACnE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrE,OAAO,GAAG,WAAW,GAAG,gBAAgB,GAAG,KAAK,GAAG,cAAc,EAAE,CAAC;AACtE,CAAC;AAcD
|
|
1
|
+
{"version":3,"file":"learnings-document.js","sourceRoot":"","sources":["../../src/core/learnings-document.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,sBAAsB,GAEvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,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AAC,UAAU,CAAC,KAAK;QAClB,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,OAAe;IACrC,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QACnB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY,CAAC,CAAC;IACtE,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type LearningsReadOptions } from "./learnings-document.js";
|
|
1
2
|
/**
|
|
2
3
|
* Resolve the configured target without permitting project-root escape, and
|
|
3
4
|
* without permitting an auto-loaded rules tree.
|
|
@@ -22,9 +23,10 @@ export declare function resolveSafeLearningTarget(projectRoot: string, relativeF
|
|
|
22
23
|
/**
|
|
23
24
|
* Read only a bounded regular file from the inode that was safety-checked.
|
|
24
25
|
* @param target - Resolved learnings file path
|
|
26
|
+
* @param options - Read policy; only shrink-only writers relax the cap
|
|
25
27
|
* @returns Existing content, or undefined when the file does not exist
|
|
26
28
|
*/
|
|
27
|
-
export declare function readExistingLearnings(target: string): Promise<string | undefined>;
|
|
29
|
+
export declare function readExistingLearnings(target: string, options?: LearningsReadOptions): Promise<string | undefined>;
|
|
28
30
|
/** A locked ledger transaction found its read-image already overwritten. */
|
|
29
31
|
export declare class LearningsConcurrentWriteError extends Error {
|
|
30
32
|
/**
|
|
@@ -46,8 +48,9 @@ export declare class LearningsConcurrentWriteError extends Error {
|
|
|
46
48
|
* silent lost learning into a failed capture the caller can retry.
|
|
47
49
|
* @param target - Resolved learnings file path
|
|
48
50
|
* @param preImage - Content this transaction read under the lock
|
|
51
|
+
* @param options - The read policy the transaction read its pre-image with
|
|
49
52
|
*/
|
|
50
|
-
export declare function assertLearningsUnchanged(target: string, preImage: string | undefined): Promise<void>;
|
|
53
|
+
export declare function assertLearningsUnchanged(target: string, preImage: string | undefined, options?: LearningsReadOptions): Promise<void>;
|
|
51
54
|
/**
|
|
52
55
|
* Reject parent-directory symlinks that resolve outside the project root.
|
|
53
56
|
* @param root - Resolved project root
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"learnings-file-safety.d.ts","sourceRoot":"","sources":["../../src/core/learnings-file-safety.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"learnings-file-safety.d.ts","sourceRoot":"","sources":["../../src/core/learnings-file-safety.ts"],"names":[],"mappings":"AAKA,OAAO,EAKL,KAAK,oBAAoB,EAC1B,MAAM,yBAAyB,CAAC;AAMjC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GACnB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAkBpD;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA+B7B;AAsCD,4EAA4E;AAC5E,qBAAa,6BAA8B,SAAQ,KAAK;IACtD;;;OAGG;gBACS,MAAM,EAAE,MAAM;CAS3B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC,CAKf;AAkBD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAYf"}
|
|
@@ -3,7 +3,7 @@ import * as fse from "fs-extra";
|
|
|
3
3
|
import { lstat, open, realpath } from "node:fs/promises";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import { LEARNINGS_CONTRACT } from "./learnings-contract.js";
|
|
6
|
-
import { conflictMarkerError, findConflictMarkerInBytes, } from "./learnings-document.js";
|
|
6
|
+
import { LEARNINGS_OVER_BUDGET_READ_CEILING, LearningsBudgetError, conflictMarkerError, findConflictMarkerInBytes, } from "./learnings-document.js";
|
|
7
7
|
import { eagerContextRejection, findEagerContextSurface, } from "./learnings-location.js";
|
|
8
8
|
/**
|
|
9
9
|
* Resolve the configured target without permitting project-root escape, and
|
|
@@ -40,9 +40,10 @@ export function resolveSafeLearningTarget(projectRoot, relativeFile) {
|
|
|
40
40
|
/**
|
|
41
41
|
* Read only a bounded regular file from the inode that was safety-checked.
|
|
42
42
|
* @param target - Resolved learnings file path
|
|
43
|
+
* @param options - Read policy; only shrink-only writers relax the cap
|
|
43
44
|
* @returns Existing content, or undefined when the file does not exist
|
|
44
45
|
*/
|
|
45
|
-
export async function readExistingLearnings(target) {
|
|
46
|
+
export async function readExistingLearnings(target, options = {}) {
|
|
46
47
|
try {
|
|
47
48
|
const beforeOpen = await lstat(target);
|
|
48
49
|
if (!beforeOpen.isFile()) {
|
|
@@ -56,15 +57,7 @@ export async function readExistingLearnings(target) {
|
|
|
56
57
|
opened.ino !== beforeOpen.ino) {
|
|
57
58
|
throw new Error("Unsafe project learnings path: target changed during open");
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
// Diagnose conflict corruption before reporting size. A conflicted
|
|
61
|
-
// merge roughly doubles the ledger, so this branch is exactly where a
|
|
62
|
-
// real corruption lands — reporting "exceeds maxTokens" here would
|
|
63
|
-
// send the writer's caller off shortening entries instead of
|
|
64
|
-
// recompacting the duplicated block.
|
|
65
|
-
await assertNoConflictMarkerPrefix(handle);
|
|
66
|
-
throw new Error(`Project learnings payload exceeds maxTokens ${LEARNINGS_CONTRACT.maxTokens}`);
|
|
67
|
-
}
|
|
60
|
+
await assertReadableLedgerSize(handle, opened.size, options);
|
|
68
61
|
return handle.readFile({ encoding: "utf8" });
|
|
69
62
|
}
|
|
70
63
|
finally {
|
|
@@ -78,6 +71,33 @@ export async function readExistingLearnings(target) {
|
|
|
78
71
|
throw error;
|
|
79
72
|
}
|
|
80
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Refuse an opened ledger larger than the read policy allows.
|
|
76
|
+
*
|
|
77
|
+
* Conflict corruption is diagnosed before size: a conflicted merge roughly
|
|
78
|
+
* doubles the ledger, so this branch is exactly where a real corruption lands —
|
|
79
|
+
* reporting "exceeds maxTokens" here would send the writer's caller off
|
|
80
|
+
* shortening entries instead of recompacting the duplicated block.
|
|
81
|
+
*
|
|
82
|
+
* The refusal is a {@link LearningsBudgetError} (CodySwannGT/lisa#4536) so a
|
|
83
|
+
* capture against an over-cap ledger reaches the overflow instead of failing
|
|
84
|
+
* as an unclassified error.
|
|
85
|
+
* @param handle - Open handle to the verified regular file
|
|
86
|
+
* @param size - Byte size of the opened inode
|
|
87
|
+
* @param options - Read policy
|
|
88
|
+
*/
|
|
89
|
+
async function assertReadableLedgerSize(handle, size, options) {
|
|
90
|
+
if (size <= LEARNINGS_CONTRACT.maxTokens) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
await assertNoConflictMarkerPrefix(handle);
|
|
94
|
+
if (options.allowOverBudget !== true) {
|
|
95
|
+
throw new LearningsBudgetError(`Project learnings payload exceeds maxTokens ${LEARNINGS_CONTRACT.maxTokens}`);
|
|
96
|
+
}
|
|
97
|
+
if (size > LEARNINGS_OVER_BUDGET_READ_CEILING) {
|
|
98
|
+
throw new LearningsBudgetError(`Project learnings payload exceeds the over-budget read ceiling ${LEARNINGS_OVER_BUDGET_READ_CEILING} (maxTokens ${LEARNINGS_CONTRACT.maxTokens})`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
81
101
|
/** A locked ledger transaction found its read-image already overwritten. */
|
|
82
102
|
export class LearningsConcurrentWriteError extends Error {
|
|
83
103
|
/**
|
|
@@ -105,9 +125,10 @@ export class LearningsConcurrentWriteError extends Error {
|
|
|
105
125
|
* silent lost learning into a failed capture the caller can retry.
|
|
106
126
|
* @param target - Resolved learnings file path
|
|
107
127
|
* @param preImage - Content this transaction read under the lock
|
|
128
|
+
* @param options - The read policy the transaction read its pre-image with
|
|
108
129
|
*/
|
|
109
|
-
export async function assertLearningsUnchanged(target, preImage) {
|
|
110
|
-
const current = await readExistingLearnings(target);
|
|
130
|
+
export async function assertLearningsUnchanged(target, preImage, options = {}) {
|
|
131
|
+
const current = await readExistingLearnings(target, options);
|
|
111
132
|
if (current !== preImage) {
|
|
112
133
|
throw new LearningsConcurrentWriteError(target);
|
|
113
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"learnings-file-safety.js","sourceRoot":"","sources":["../../src/core/learnings-file-safety.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAmB,MAAM,kBAAkB,CAAC;AAC1E,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACL,mBAAmB,EACnB,yBAAyB,
|
|
1
|
+
{"version":3,"file":"learnings-file-safety.js","sourceRoot":"","sources":["../../src/core/learnings-file-safety.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAmB,MAAM,kBAAkB,CAAC;AAC1E,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO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