@codyswann/lisa 2.217.7 → 2.218.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/dist/cli/apply.d.ts.map +1 -1
  2. package/dist/cli/apply.js +18 -1
  3. package/dist/cli/apply.js.map +1 -1
  4. package/dist/core/config.d.ts +11 -0
  5. package/dist/core/config.d.ts.map +1 -1
  6. package/dist/core/config.js +13 -0
  7. package/dist/core/config.js.map +1 -1
  8. package/dist/core/learnings-contract.d.ts +38 -0
  9. package/dist/core/learnings-contract.d.ts.map +1 -0
  10. package/dist/core/learnings-contract.js +36 -0
  11. package/dist/core/learnings-contract.js.map +1 -0
  12. package/dist/core/learnings-entry.d.ts +9 -0
  13. package/dist/core/learnings-entry.d.ts.map +1 -0
  14. package/dist/core/learnings-entry.js +233 -0
  15. package/dist/core/learnings-entry.js.map +1 -0
  16. package/dist/core/learnings-file-safety.d.ts +23 -0
  17. package/dist/core/learnings-file-safety.d.ts.map +1 -0
  18. package/dist/core/learnings-file-safety.js +84 -0
  19. package/dist/core/learnings-file-safety.js.map +1 -0
  20. package/dist/core/learnings-lock.d.ts +8 -0
  21. package/dist/core/learnings-lock.d.ts.map +1 -0
  22. package/dist/core/learnings-lock.js +227 -0
  23. package/dist/core/learnings-lock.js.map +1 -0
  24. package/dist/core/learnings-writer.d.ts +22 -0
  25. package/dist/core/learnings-writer.d.ts.map +1 -0
  26. package/dist/core/learnings-writer.js +128 -0
  27. package/dist/core/learnings-writer.js.map +1 -0
  28. package/dist/core/learnings.d.ts +4 -0
  29. package/dist/core/learnings.d.ts.map +1 -0
  30. package/dist/core/learnings.js +4 -0
  31. package/dist/core/learnings.js.map +1 -0
  32. package/dist/core/lisa.d.ts +17 -1
  33. package/dist/core/lisa.d.ts.map +1 -1
  34. package/dist/core/lisa.js +39 -3
  35. package/dist/core/lisa.js.map +1 -1
  36. package/dist/core/project-config.d.ts +43 -2
  37. package/dist/core/project-config.d.ts.map +1 -1
  38. package/dist/core/project-config.js +121 -11
  39. package/dist/core/project-config.js.map +1 -1
  40. package/dist/core/self-apply.d.ts +10 -0
  41. package/dist/core/self-apply.d.ts.map +1 -0
  42. package/dist/core/self-apply.js +29 -0
  43. package/dist/core/self-apply.js.map +1 -0
  44. package/dist/migrations/ensure-lisa-postinstall.d.ts.map +1 -1
  45. package/dist/migrations/ensure-lisa-postinstall.js +7 -0
  46. package/dist/migrations/ensure-lisa-postinstall.js.map +1 -1
  47. package/dist/strategies/package-lisa.d.ts +24 -4
  48. package/dist/strategies/package-lisa.d.ts.map +1 -1
  49. package/dist/strategies/package-lisa.js +148 -6
  50. package/dist/strategies/package-lisa.js.map +1 -1
  51. package/dist/sync/registry.d.ts +0 -12
  52. package/dist/sync/registry.d.ts.map +1 -1
  53. package/dist/sync/registry.js +18 -0
  54. package/dist/sync/registry.js.map +1 -1
  55. package/package.json +2 -1
  56. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  57. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  58. package/plugins/lisa/.codex-plugin/skills/lisa-debrief-apply/SKILL.md +3 -3
  59. package/plugins/lisa/rules/eager/config-resolution.md +9 -0
  60. package/plugins/lisa/rules/reference/config-resolution.md +2 -0
  61. package/plugins/lisa/skills/lisa-debrief-apply/SKILL.md +3 -3
  62. package/plugins/lisa-agy/plugin.json +1 -1
  63. package/plugins/lisa-agy/skills/lisa-debrief-apply/SKILL.md +3 -3
  64. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  65. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  66. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  67. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  68. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  69. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  70. package/plugins/lisa-copilot/rules/eager/config-resolution.md +9 -0
  71. package/plugins/lisa-copilot/rules/reference/config-resolution.md +2 -0
  72. package/plugins/lisa-copilot/skills/lisa-debrief-apply/SKILL.md +3 -3
  73. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  74. package/plugins/lisa-cursor/rules/config-resolution-reference.mdc +2 -0
  75. package/plugins/lisa-cursor/rules/config-resolution.mdc +9 -0
  76. package/plugins/lisa-cursor/skills/lisa-debrief-apply/SKILL.md +3 -3
  77. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  78. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  79. package/plugins/lisa-expo-agy/plugin.json +1 -1
  80. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  81. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  82. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  83. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  84. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  85. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  86. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  87. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  88. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  89. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  90. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  91. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  92. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  93. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  94. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  95. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  96. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  97. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  98. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  99. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  100. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  101. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  102. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  103. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  104. package/plugins/lisa-rails-agy/plugin.json +1 -1
  105. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  106. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  107. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  108. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  109. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  110. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  111. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  112. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  113. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  114. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  115. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  116. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  117. package/plugins/src/base/rules/eager/config-resolution.md +9 -0
  118. package/plugins/src/base/rules/reference/config-resolution.md +2 -0
  119. package/plugins/src/base/skills/lisa-debrief-apply/SKILL.md +3 -3
@@ -0,0 +1,227 @@
1
+ /** Cross-process serialization for project learnings writes. */
2
+ import { link, lstat, readFile, unlink, writeFile } from "node:fs/promises";
3
+ const MAX_LOCK_ATTEMPTS = 200;
4
+ const LOCK_RETRY_DELAY_MS = 10;
5
+ const STALE_LOCK_MS = 30_000;
6
+ /**
7
+ * Serialize same-target writers across processes with an exclusive hard link.
8
+ * @param target - Absolute learnings target
9
+ * @param operation - Complete read, validate, and atomic-write transaction
10
+ * @returns Operation result
11
+ */
12
+ export async function withLearningTargetLock(target, operation) {
13
+ const lockPath = `${target}.lock`;
14
+ const owner = {
15
+ token: crypto.randomUUID(),
16
+ pid: process.pid,
17
+ createdAt: Date.now(),
18
+ };
19
+ const lease = await acquireLock(lockPath, owner, 0);
20
+ try {
21
+ return await operation();
22
+ }
23
+ finally {
24
+ await releaseLock(lockPath, lease);
25
+ }
26
+ }
27
+ /**
28
+ * Publish complete owner metadata atomically via a hard link.
29
+ * @param lockPath - Shared lock path
30
+ * @param owner - Unique owner metadata
31
+ * @param attempt - Current retry count
32
+ * @returns Acquired lock lease
33
+ */
34
+ async function acquireLock(lockPath, owner, attempt) {
35
+ const ownerPath = `${lockPath}.${owner.token}.owner`;
36
+ await writeFile(ownerPath, JSON.stringify(owner), {
37
+ encoding: "utf8",
38
+ flag: "wx",
39
+ });
40
+ const acquired = await publishOwnerLink(ownerPath, lockPath);
41
+ if (acquired) {
42
+ return { owner, ownerPath };
43
+ }
44
+ await removeFileIfPresent(ownerPath);
45
+ if (attempt >= MAX_LOCK_ATTEMPTS) {
46
+ throw new Error(`Timed out waiting for learnings lock: ${lockPath}`);
47
+ }
48
+ await reclaimStaleLock(lockPath);
49
+ await delay(LOCK_RETRY_DELAY_MS);
50
+ return acquireLock(lockPath, owner, attempt + 1);
51
+ }
52
+ /**
53
+ * Try to hard-link fully written owner metadata into the lock path.
54
+ * @param ownerPath - Fully written owner metadata file
55
+ * @param lockPath - Destination lock path
56
+ * @returns Whether publication acquired the lock
57
+ */
58
+ async function publishOwnerLink(ownerPath, lockPath) {
59
+ try {
60
+ await link(ownerPath, lockPath);
61
+ return true;
62
+ }
63
+ catch (error) {
64
+ if (error.code === "EEXIST" ||
65
+ error.code === "ENOENT") {
66
+ return false;
67
+ }
68
+ throw error;
69
+ }
70
+ }
71
+ /**
72
+ * Remove only the lock inode still linked to this lease's owner file.
73
+ * @param lockPath - Shared lock path
74
+ * @param lease - Owner lease retaining the same inode
75
+ */
76
+ async function releaseLock(lockPath, lease) {
77
+ try {
78
+ if (await sameFile(lockPath, lease.ownerPath)) {
79
+ await unlink(lockPath);
80
+ }
81
+ }
82
+ finally {
83
+ await removeFileIfPresent(lease.ownerPath);
84
+ }
85
+ }
86
+ /**
87
+ * Reclaim an expired lock only when its declared process is no longer live.
88
+ * @param lockPath - Shared lock path
89
+ */
90
+ async function reclaimStaleLock(lockPath) {
91
+ const before = await statFile(lockPath);
92
+ if (before === undefined || !before.isFile()) {
93
+ return;
94
+ }
95
+ const owner = await readLockOwner(lockPath);
96
+ const timestamp = owner?.createdAt ?? Number(before.mtimeMs);
97
+ if (Date.now() - timestamp <= STALE_LOCK_MS ||
98
+ (owner !== undefined && isProcessLive(owner.pid))) {
99
+ return;
100
+ }
101
+ const retainedOwnerPath = owner === undefined ? undefined : `${lockPath}.${owner.token}.owner`;
102
+ const quarantine = retainedOwnerPath !== undefined &&
103
+ (await sameFile(lockPath, retainedOwnerPath))
104
+ ? retainedOwnerPath
105
+ : `${lockPath}.${crypto.randomUUID()}.stale`;
106
+ const linked = quarantine === retainedOwnerPath
107
+ ? true
108
+ : await publishOwnerLink(lockPath, quarantine);
109
+ if (!linked) {
110
+ return;
111
+ }
112
+ try {
113
+ if (await sameFile(lockPath, quarantine)) {
114
+ await removeFileIfPresent(lockPath);
115
+ }
116
+ }
117
+ finally {
118
+ await removeFileIfPresent(quarantine);
119
+ }
120
+ }
121
+ /**
122
+ * Read bounded owner metadata; partial or special lock files are unowned.
123
+ * @param lockPath - Shared lock path
124
+ * @returns Parsed owner or undefined
125
+ */
126
+ async function readLockOwner(lockPath) {
127
+ const metadata = await statFile(lockPath);
128
+ if (metadata === undefined || !metadata.isFile() || metadata.size > 512) {
129
+ return undefined;
130
+ }
131
+ try {
132
+ const parsed = JSON.parse(await readFile(lockPath, "utf8"));
133
+ return isLockOwner(parsed) ? parsed : undefined;
134
+ }
135
+ catch {
136
+ return undefined;
137
+ }
138
+ }
139
+ /**
140
+ * Compare two regular-file paths by device and inode.
141
+ * @param left - First file path
142
+ * @param right - Second file path
143
+ * @returns Whether both paths retain the same regular-file inode
144
+ */
145
+ async function sameFile(left, right) {
146
+ const [leftStat, rightStat] = await Promise.all([
147
+ statFile(left),
148
+ statFile(right),
149
+ ]);
150
+ return (leftStat !== undefined &&
151
+ rightStat !== undefined &&
152
+ leftStat.isFile() &&
153
+ rightStat.isFile() &&
154
+ leftStat.dev === rightStat.dev &&
155
+ leftStat.ino === rightStat.ino);
156
+ }
157
+ /**
158
+ * Read file metadata without treating an absent path as an error.
159
+ * @param filePath - Filesystem path
160
+ * @returns File metadata or undefined
161
+ */
162
+ async function statFile(filePath) {
163
+ try {
164
+ return await lstat(filePath);
165
+ }
166
+ catch (error) {
167
+ if (error.code === "ENOENT") {
168
+ return undefined;
169
+ }
170
+ throw error;
171
+ }
172
+ }
173
+ /**
174
+ * Remove one path without recursive deletion.
175
+ * @param filePath - Regular file or hard-link path
176
+ */
177
+ async function removeFileIfPresent(filePath) {
178
+ try {
179
+ await unlink(filePath);
180
+ }
181
+ catch (error) {
182
+ if (error.code !== "ENOENT") {
183
+ throw error;
184
+ }
185
+ }
186
+ }
187
+ /**
188
+ * Narrow parsed lock metadata to the exact ownership shape.
189
+ * @param value - Parsed metadata
190
+ * @returns Whether the metadata is a lock owner
191
+ */
192
+ function isLockOwner(value) {
193
+ if (value === null || typeof value !== "object") {
194
+ return false;
195
+ }
196
+ const owner = value;
197
+ return (typeof owner.token === "string" &&
198
+ typeof owner.pid === "number" &&
199
+ Number.isSafeInteger(owner.pid) &&
200
+ owner.pid > 0 &&
201
+ typeof owner.createdAt === "number" &&
202
+ Number.isSafeInteger(owner.createdAt));
203
+ }
204
+ /**
205
+ * Treat permission-denied PID probes as live and missing PIDs as dead.
206
+ * @param pid - Declared owner process id
207
+ * @returns Whether the process may still be alive
208
+ */
209
+ function isProcessLive(pid) {
210
+ try {
211
+ process.kill(pid, 0);
212
+ return true;
213
+ }
214
+ catch (error) {
215
+ return error.code !== "ESRCH";
216
+ }
217
+ }
218
+ /**
219
+ * Await a short retry delay without blocking the event loop.
220
+ * @param milliseconds - Delay duration
221
+ */
222
+ async function delay(milliseconds) {
223
+ await new Promise(resolve => {
224
+ setTimeout(resolve, milliseconds);
225
+ });
226
+ }
227
+ //# sourceMappingURL=learnings-lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learnings-lock.js","sourceRoot":"","sources":["../../src/core/learnings-lock.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE5E,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,aAAa,GAAG,MAAM,CAAC;AAe7B;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,MAAc,EACd,SAA2B;IAE3B,MAAM,QAAQ,GAAG,GAAG,MAAM,OAAO,CAAC;IAClC,MAAM,KAAK,GAAG;QACZ,KAAK,EAAE,MAAM,CAAC,UAAU,EAAE;QAC1B,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACb,CAAC;IACX,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IACpD,IAAI,CAAC;QACH,OAAO,MAAM,SAAS,EAAE,CAAC;IAC3B,CAAC;YAAS,CAAC;QACT,MAAM,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,WAAW,CACxB,QAAgB,EAChB,KAAgB,EAChB,OAAe;IAEf,MAAM,SAAS,GAAG,GAAG,QAAQ,IAAI,KAAK,CAAC,KAAK,QAAQ,CAAC;IACrD,MAAM,SAAS,CAAC,SAAS,EAAE,IAAI,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AC,IAAI,KAAK,OAAO,CAAC;IAC3D,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,KAAK,CAAC,YAAoB;IACvC,MAAM,IAAI,OAAO,CAAO,OAAO,CAAC,EAAE;QAChC,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { type LearningEntry } from "./learnings-contract.js";
2
+ /**
3
+ * Persist one already-selected learning without generating or truncating it.
4
+ * @param projectRoot - Absolute path to the host project root
5
+ * @param candidate - Untrusted seven-field learning entry
6
+ * @returns Absolute path to the persisted learnings file
7
+ */
8
+ export declare function persistLearningEntry(projectRoot: string, candidate: unknown): Promise<string>;
9
+ /**
10
+ * Render the complete file in one stable, machine-readable Markdown form.
11
+ * @param entries - Validated entries to serialize
12
+ * @returns Canonical Markdown plus JSONL document
13
+ */
14
+ export declare function renderLearningsFile(entries: readonly LearningEntry[]): string;
15
+ /**
16
+ * Parse and revalidate an existing file before it participates in a write.
17
+ * @param content - Existing learnings document
18
+ * @returns Revalidated entries from the document
19
+ */
20
+ export declare function parseLearningsFile(content: string): LearningEntry[];
21
+ export { validateLearningEntry } from "./learnings-entry.js";
22
+ //# sourceMappingURL=learnings-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learnings-writer.d.ts","sourceRoot":"","sources":["../../src/core/learnings-writer.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,yBAAyB,CAAC;AAqBjC;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,MAAM,CAAC,CA6BjB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,GAAG,MAAM,CAG7E;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,EAAE,CAsBnE;AAED,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,128 @@
1
+ /** Deterministic persistence for project-local learnings. */
2
+ import * as fse from "fs-extra";
3
+ import { rename, writeFile } from "node:fs/promises";
4
+ import * as path from "node:path";
5
+ import { LEARNINGS_CONTRACT, estimateLearningTokens, } from "./learnings-contract.js";
6
+ import { validateLearningEntry } from "./learnings-entry.js";
7
+ import { assertSafeLearningParents, readExistingLearnings, resolveSafeLearningTarget, } from "./learnings-file-safety.js";
8
+ import { withLearningTargetLock } from "./learnings-lock.js";
9
+ import { readProjectConfig, resolveProjectLearningsFile, } from "./project-config.js";
10
+ const FILE_HEADER = `# Project Learnings
11
+
12
+ <!-- lisa-learnings-contract:v${LEARNINGS_CONTRACT.version} -->
13
+
14
+ `;
15
+ const JSON_FENCE_START = "```jsonl\n";
16
+ const JSON_FENCE_END = "\n```\n";
17
+ /**
18
+ * Persist one already-selected learning without generating or truncating it.
19
+ * @param projectRoot - Absolute path to the host project root
20
+ * @param candidate - Untrusted seven-field learning entry
21
+ * @returns Absolute path to the persisted learnings file
22
+ */
23
+ export async function persistLearningEntry(projectRoot, candidate) {
24
+ const entry = validateLearningEntry(candidate);
25
+ const initialDocument = buildNextDocument([], entry);
26
+ const config = await readProjectConfig(projectRoot);
27
+ const relativeFile = resolveProjectLearningsFile(config);
28
+ const { root, target } = resolveSafeLearningTarget(projectRoot, relativeFile);
29
+ await assertSafeLearningParents(root, path.dirname(target));
30
+ await fse.ensureDir(path.dirname(target));
31
+ return withLearningTargetLock(target, async () => {
32
+ await assertSafeLearningParents(root, path.dirname(target));
33
+ const existing = await readExistingLearnings(target);
34
+ const entries = existing === undefined ? [] : parseLearningsFile(existing);
35
+ const rendered = existing === undefined
36
+ ? initialDocument
37
+ : buildNextDocument(entries, entry);
38
+ const temporary = path.join(path.dirname(target), `.${path.basename(target)}.${process.pid}.${crypto.randomUUID()}.tmp`);
39
+ try {
40
+ await writeFile(temporary, rendered, { encoding: "utf8", flag: "wx" });
41
+ await assertSafeLearningParents(root, path.dirname(target));
42
+ await rename(temporary, target);
43
+ }
44
+ finally {
45
+ await fse.remove(temporary);
46
+ }
47
+ return target;
48
+ });
49
+ }
50
+ /**
51
+ * Render the complete file in one stable, machine-readable Markdown form.
52
+ * @param entries - Validated entries to serialize
53
+ * @returns Canonical Markdown plus JSONL document
54
+ */
55
+ export function renderLearningsFile(entries) {
56
+ const lines = entries.map(entry => JSON.stringify(entry)).join("\n");
57
+ return `${FILE_HEADER}${JSON_FENCE_START}${lines}${JSON_FENCE_END}`;
58
+ }
59
+ /**
60
+ * Parse and revalidate an existing file before it participates in a write.
61
+ * @param content - Existing learnings document
62
+ * @returns Revalidated entries from the document
63
+ */
64
+ export function parseLearningsFile(content) {
65
+ if (estimateLearningTokens(content) > LEARNINGS_CONTRACT.maxTokens) {
66
+ throw new Error(`Project learnings payload exceeds maxTokens ${LEARNINGS_CONTRACT.maxTokens}`);
67
+ }
68
+ if (!content.startsWith(`${FILE_HEADER}${JSON_FENCE_START}`) ||
69
+ !content.endsWith(JSON_FENCE_END)) {
70
+ throw new Error("Invalid project learnings file format");
71
+ }
72
+ const jsonStart = FILE_HEADER.length + JSON_FENCE_START.length;
73
+ const jsonEnd = content.length - JSON_FENCE_END.length;
74
+ const entries = parseJsonLines(content.slice(jsonStart, jsonEnd)).map(validateLearningEntry);
75
+ if (new Set(entries.map(entry => entry.id)).size !== entries.length) {
76
+ throw new Error("Invalid project learnings payload: duplicate ids");
77
+ }
78
+ assertDocumentBudget(content, entries.length, "Project learnings payload");
79
+ return entries;
80
+ }
81
+ export { validateLearningEntry } from "./learnings-entry.js";
82
+ /**
83
+ * Build and budget-check the next canonical document.
84
+ * @param entries - Existing validated entries
85
+ * @param entry - New validated entry
86
+ * @returns Next canonical document
87
+ */
88
+ function buildNextDocument(entries, entry) {
89
+ if (entries.some(current => current.id === entry.id)) {
90
+ throw new Error(`Duplicate learning id: ${entry.id}`);
91
+ }
92
+ const nextEntries = [...entries, entry].sort((left, right) => left.id.localeCompare(right.id));
93
+ const rendered = renderLearningsFile(nextEntries);
94
+ assertDocumentBudget(rendered, nextEntries.length, "Learnings file");
95
+ return rendered;
96
+ }
97
+ /**
98
+ * Enforce the shared entry-count and model-agnostic token upper bounds.
99
+ * @param content - Canonical document
100
+ * @param entryCount - Number of entries in the document
101
+ * @param context - Error-message prefix
102
+ */
103
+ function assertDocumentBudget(content, entryCount, context) {
104
+ if (entryCount > LEARNINGS_CONTRACT.maxEntries) {
105
+ throw new Error(`${context} exceeds maxEntries ${LEARNINGS_CONTRACT.maxEntries}`);
106
+ }
107
+ const estimatedTokens = estimateLearningTokens(content);
108
+ if (estimatedTokens > LEARNINGS_CONTRACT.maxTokens) {
109
+ throw new Error(`${context} exceeds maxTokens ${LEARNINGS_CONTRACT.maxTokens} (measured ${estimatedTokens})`);
110
+ }
111
+ }
112
+ /**
113
+ * Parse the strict JSONL payload with a stable, user-facing error.
114
+ * @param payload - JSONL payload
115
+ * @returns Parsed unknown entry values
116
+ */
117
+ function parseJsonLines(payload) {
118
+ if (payload === "") {
119
+ return [];
120
+ }
121
+ try {
122
+ return payload.split("\n").map(line => JSON.parse(line));
123
+ }
124
+ catch {
125
+ throw new Error("Invalid project learnings JSONL payload");
126
+ }
127
+ }
128
+ //# sourceMappingURL=learnings-writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learnings-writer.js","sourceRoot":"","sources":["../../src/core/learnings-writer.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,kBAAkB,EAClB,sBAAsB,GAEvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM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learnings-contract.js";
2
+ export * from "./learnings-writer.js";
3
+ export { DEFAULT_PROJECT_RULES_FILE, PROJECT_LEARNINGS_FILENAME, resolveProjectLearningsFile, resolveProjectRulesFile, type ProjectConfig, } from "./project-config.js";
4
+ //# sourceMappingURL=learnings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learnings.d.ts","sourceRoot":"","sources":["../../src/core/learnings.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,2BAA2B,EAC3B,uBAAuB,EACvB,KAAK,aAAa,GACnB,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./learnings-contract.js";
2
+ export * from "./learnings-writer.js";
3
+ export { DEFAULT_PROJECT_RULES_FILE, PROJECT_LEARNINGS_FILENAME, resolveProjectLearningsFile, resolveProjectRulesFile, } from "./project-config.js";
4
+ //# sourceMappingURL=learnings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learnings.js","sourceRoot":"","sources":["../../src/core/learnings.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,2BAA2B,EAC3B,uBAAuB,GAExB,MAAM,qBAAqB,CAAC"}
@@ -78,6 +78,12 @@ export declare class Lisa {
78
78
  private copyOverwriteOwnership;
79
79
  private readonly separator;
80
80
  private readonly lisaignoreSuffix;
81
+ /**
82
+ * True when the destination is the Lisa source repo itself. A self-apply
83
+ * skips deletions, template application, and postinstall injection while
84
+ * still applying package.lisa.json dependency governance. See {@link isLisaSourceRepo}.
85
+ */
86
+ private selfApply;
81
87
  /**
82
88
  * Initialize Lisa orchestrator
83
89
  * @param config - Configuration for the apply operation
@@ -88,7 +94,9 @@ export declare class Lisa {
88
94
  * Postinstall applies are intentionally narrow: they refresh governance
89
95
  * templates that must track dependency updates, but they must not regenerate
90
96
  * project-scoped agent surfaces. Agent trees are large, committed outputs and
91
- * are updated through an explicit `lisa apply` or cross-pollinate run.
97
+ * are updated through an explicit `lisa apply` or cross-pollinate run. A
98
+ * self-apply against the Lisa source repo also skips emit — those agent
99
+ * surfaces are built from `plugins/src`, not regenerated by apply.
92
100
  * @returns True when the current apply should avoid agent-surface writes.
93
101
  */
94
102
  private shouldSkipAgentEmitDuringPostinstall;
@@ -100,6 +108,14 @@ export declare class Lisa {
100
108
  * Detect and confirm project types
101
109
  */
102
110
  private detectTypes;
111
+ /**
112
+ * Detect whether this apply targets the Lisa source repo itself and, if so,
113
+ * announce the narrowed behavior. A self-apply skips deletions, template
114
+ * application, and agent-surface emit, but still applies package.lisa.json
115
+ * dependency governance so Lisa's own deps track the floors it forces
116
+ * downstream. See {@link isLisaSourceRepo}.
117
+ */
118
+ private detectSelfApply;
103
119
  /**
104
120
  * Process all configurations
105
121
  */
@@ -1 +1 @@
1
- {"version":3,"file":"lisa.d.ts","sourceRoot":"","sources":["../../src/core/lisa.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAyBnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAMzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EACL,iBAAiB,EAGlB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAwB,MAAM,wBAAwB,CAAC;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAc9D,OAAO,KAAK,EAIV,UAAU,EACV,UAAU,EAGX,MAAM,aAAa,CAAC;AAOrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAQpD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,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;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAgB1B;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAYrB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAmB1B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA6BxB;;OAEG;IACH,OAAO,CAAC,eAAe;IA6BvB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAezB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAazB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAgB7B;;OAEG;IACH,OAAO,CAAC,YAAY;IAOpB;;;;;OAKG;YACW,WAAW;IAQzB;;;;;OAKG;YACW,qBAAqB;CAqDpC"}
package/dist/core/lisa.js CHANGED
@@ -18,6 +18,7 @@ import { installOpencodeMcpConfig, resolveOpencodeConfigPath, } from "../opencod
18
18
  import { discoverAndInstallAgents as installOpencodeAgents } from "../opencode/agent-installer.js";
19
19
  import { discoverAndInstallCommands as installOpencodeCommands } from "../opencode/command-installer.js";
20
20
  import { installClaudeMd } from "../claude/claude-md-installer.js";
21
+ import { isLisaSourceRepo } from "./self-apply.js";
21
22
  import { DestinationNotDirectoryError, DestinationNotFoundError, UserAbortedError, } from "../errors/index.js";
22
23
  import { listFilesRecursive } from "../utils/file-operations.js";
23
24
  import { loadIgnorePatterns, } from "../utils/ignore-patterns.js";
@@ -92,6 +93,12 @@ export class Lisa {
92
93
  copyOverwriteOwnership = new Map();
93
94
  separator = "========================================";
94
95
  lisaignoreSuffix = "(.lisaignore)";
96
+ /**
97
+ * True when the destination is the Lisa source repo itself. A self-apply
98
+ * skips deletions, template application, and postinstall injection while
99
+ * still applying package.lisa.json dependency governance. See {@link isLisaSourceRepo}.
100
+ */
101
+ selfApply = false;
95
102
  /**
96
103
  * Initialize Lisa orchestrator
97
104
  * @param config - Configuration for the apply operation
@@ -105,11 +112,13 @@ export class Lisa {
105
112
  * Postinstall applies are intentionally narrow: they refresh governance
106
113
  * templates that must track dependency updates, but they must not regenerate
107
114
  * project-scoped agent surfaces. Agent trees are large, committed outputs and
108
- * are updated through an explicit `lisa apply` or cross-pollinate run.
115
+ * are updated through an explicit `lisa apply` or cross-pollinate run. A
116
+ * self-apply against the Lisa source repo also skips emit — those agent
117
+ * surfaces are built from `plugins/src`, not regenerated by apply.
109
118
  * @returns True when the current apply should avoid agent-surface writes.
110
119
  */
111
120
  shouldSkipAgentEmitDuringPostinstall() {
112
- return this.config.skipGitCheck;
121
+ return this.config.skipGitCheck || this.selfApply;
113
122
  }
114
123
  /**
115
124
  * Initialize services
@@ -131,6 +140,21 @@ export class Lisa {
131
140
  ...(await prompter.confirmProjectTypes(this.detectedTypes)),
132
141
  ];
133
142
  }
143
+ /**
144
+ * Detect whether this apply targets the Lisa source repo itself and, if so,
145
+ * announce the narrowed behavior. A self-apply skips deletions, template
146
+ * application, and agent-surface emit, but still applies package.lisa.json
147
+ * dependency governance so Lisa's own deps track the floors it forces
148
+ * downstream. See {@link isLisaSourceRepo}.
149
+ */
150
+ async detectSelfApply() {
151
+ this.selfApply = await isLisaSourceRepo(this.config.destDir);
152
+ if (this.selfApply) {
153
+ this.deps.logger.info(pc.yellow("Detected Lisa source repo — self-apply mode: applying only " +
154
+ "package.lisa.json dependency governance (skipping template " +
155
+ "application, deletions, postinstall injection, and agent emit)."));
156
+ }
157
+ }
134
158
  /**
135
159
  * Process all configurations
136
160
  */
@@ -539,13 +563,19 @@ export class Lisa {
539
563
  this.printHeader();
540
564
  await this.initServices();
541
565
  await this.detectTypes();
566
+ await this.detectSelfApply();
542
567
  await this.loadPendingDeletions();
543
568
  await this.loadCreateOnlyOwnership();
544
569
  await this.loadCopyOverwriteOwnership();
545
570
  await this.runMigrationsBeforeStrategies();
546
571
  const prePackageJsonHash = hashFile(path.join(this.config.destDir, "package.json"));
547
572
  await this.processConfigurations();
548
- await this.processDeletions();
573
+ if (this.selfApply) {
574
+ this.deps.logger.info(pc.gray("Self-apply (Lisa source repo): skipped deletions.json processing"));
575
+ }
576
+ else {
577
+ await this.processDeletions();
578
+ }
549
579
  await this.processMigrations();
550
580
  await this.processCodexEmit();
551
581
  await this.processClaudeEmit();
@@ -950,6 +980,12 @@ export class Lisa {
950
980
  async processProjectType(type) {
951
981
  const { logger, strategyRegistry } = this.deps;
952
982
  for (const strategy of COPY_STRATEGIES) {
983
+ // Self-apply (Lisa source repo) applies ONLY dependency governance via the
984
+ // package-lisa strategy — every other strategy would overwrite Lisa's own
985
+ // hand-authored source with the templates it ships.
986
+ if (this.selfApply && strategy !== "package-lisa") {
987
+ continue;
988
+ }
953
989
  const srcDir = path.join(this.config.lisaDir, type, strategy);
954
990
  if (await fse.pathExists(srcDir)) {
955
991
  logger.info(`Processing ${type}/${strategy}...`);