opencode-swarm 7.76.1 → 7.76.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +265 -249
- package/dist/commands/registry.d.ts +7 -0
- package/dist/config/bundled-skills.d.ts +9 -3
- package/dist/index.js +441 -415
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -52,7 +52,7 @@ var package_default;
|
|
|
52
52
|
var init_package = __esm(() => {
|
|
53
53
|
package_default = {
|
|
54
54
|
name: "opencode-swarm",
|
|
55
|
-
version: "7.76.
|
|
55
|
+
version: "7.76.2",
|
|
56
56
|
description: "Architect-centric agentic swarm plugin for OpenCode - hub-and-spoke orchestration with SME consultation, code generation, and QA review",
|
|
57
57
|
main: "dist/index.js",
|
|
58
58
|
types: "dist/index.d.ts",
|
|
@@ -154,43 +154,56 @@ var init_package = __esm(() => {
|
|
|
154
154
|
|
|
155
155
|
// src/config/bundled-skills.ts
|
|
156
156
|
import * as fs from "fs";
|
|
157
|
+
import * as fsp from "fs/promises";
|
|
157
158
|
import * as path from "path";
|
|
158
|
-
function
|
|
159
|
+
function getSyncCacheKey(projectDirectory, packageRoot) {
|
|
160
|
+
return `${path.resolve(projectDirectory)}\x00${path.resolve(packageRoot)}`;
|
|
161
|
+
}
|
|
162
|
+
function warnBundledSkillSyncFailure(err) {
|
|
163
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
164
|
+
console.warn(`[opencode-swarm] Could not install bundled project skills; continuing without sync: ${message}`);
|
|
165
|
+
}
|
|
166
|
+
async function isSymbolicLinkAsync(p) {
|
|
159
167
|
try {
|
|
160
|
-
return
|
|
168
|
+
return (await fsp.lstat(p)).isSymbolicLink();
|
|
161
169
|
} catch {
|
|
162
170
|
return false;
|
|
163
171
|
}
|
|
164
172
|
}
|
|
165
|
-
function
|
|
173
|
+
async function ensureNotSymlinkedDirectoryAsync(p) {
|
|
166
174
|
try {
|
|
167
|
-
const
|
|
168
|
-
return
|
|
175
|
+
const stat2 = await fsp.lstat(p);
|
|
176
|
+
return stat2.isDirectory() && !stat2.isSymbolicLink();
|
|
169
177
|
} catch (err) {
|
|
170
178
|
return err.code === "ENOENT";
|
|
171
179
|
}
|
|
172
180
|
}
|
|
173
|
-
function
|
|
174
|
-
|
|
181
|
+
async function pathExistsAsync(p) {
|
|
182
|
+
try {
|
|
183
|
+
await fsp.access(p);
|
|
184
|
+
return true;
|
|
185
|
+
} catch {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
175
188
|
}
|
|
176
|
-
function
|
|
189
|
+
async function collectBundledSkillFilesBoundedAsync(sourceDir, state, relativeDir = "") {
|
|
177
190
|
const currentSource = path.join(sourceDir, relativeDir);
|
|
178
|
-
const entries =
|
|
191
|
+
const entries = await fsp.readdir(currentSource, { withFileTypes: true });
|
|
179
192
|
const files = [];
|
|
180
193
|
for (const entry of entries) {
|
|
181
194
|
const relativeEntry = path.join(relativeDir, entry.name);
|
|
182
195
|
const sourcePath = path.join(sourceDir, relativeEntry);
|
|
183
|
-
if (entry.isSymbolicLink() ||
|
|
196
|
+
if (entry.isSymbolicLink() || await isSymbolicLinkAsync(sourcePath))
|
|
184
197
|
continue;
|
|
185
198
|
if (entry.isDirectory()) {
|
|
186
|
-
files.push(...
|
|
199
|
+
files.push(...await collectBundledSkillFilesBoundedAsync(sourceDir, state, relativeEntry));
|
|
187
200
|
continue;
|
|
188
201
|
}
|
|
189
202
|
if (!entry.isFile())
|
|
190
203
|
continue;
|
|
191
|
-
const
|
|
204
|
+
const stat2 = await fsp.stat(sourcePath);
|
|
192
205
|
const nextFiles = state.files + 1;
|
|
193
|
-
const nextBytes = state.bytes +
|
|
206
|
+
const nextBytes = state.bytes + stat2.size;
|
|
194
207
|
if (nextFiles > MAX_SKILL_FILES || nextBytes > MAX_SKILL_BYTES) {
|
|
195
208
|
throw new Error("bundled skill package exceeds copy bounds");
|
|
196
209
|
}
|
|
@@ -200,7 +213,7 @@ function collectBundledSkillFilesBounded(sourceDir, state, relativeDir = "") {
|
|
|
200
213
|
}
|
|
201
214
|
return files;
|
|
202
215
|
}
|
|
203
|
-
function
|
|
216
|
+
async function rollbackCopiedFilesAsync(copiedFiles, destDir) {
|
|
204
217
|
const safeDestDir = path.resolve(destDir);
|
|
205
218
|
const dirs = new Set;
|
|
206
219
|
for (const copiedFile of copiedFiles) {
|
|
@@ -209,7 +222,7 @@ function rollbackCopiedFiles(copiedFiles, destDir) {
|
|
|
209
222
|
if (relative2.startsWith("..") || path.isAbsolute(relative2))
|
|
210
223
|
continue;
|
|
211
224
|
try {
|
|
212
|
-
|
|
225
|
+
await fsp.rm(resolvedFile, { force: true });
|
|
213
226
|
} catch {}
|
|
214
227
|
dirs.add(path.dirname(resolvedFile));
|
|
215
228
|
}
|
|
@@ -218,12 +231,12 @@ function rollbackCopiedFiles(copiedFiles, destDir) {
|
|
|
218
231
|
if (relative2.startsWith("..") || path.isAbsolute(relative2))
|
|
219
232
|
continue;
|
|
220
233
|
try {
|
|
221
|
-
|
|
234
|
+
await fsp.rmdir(dir);
|
|
222
235
|
} catch {}
|
|
223
236
|
}
|
|
224
237
|
}
|
|
225
|
-
function
|
|
226
|
-
const files =
|
|
238
|
+
async function copyBundledDirectoryBoundedAsync(sourceDir, destDir) {
|
|
239
|
+
const files = await collectBundledSkillFilesBoundedAsync(sourceDir, {
|
|
227
240
|
files: 0,
|
|
228
241
|
bytes: 0
|
|
229
242
|
});
|
|
@@ -232,9 +245,9 @@ function copyBundledDirectoryBounded(sourceDir, destDir) {
|
|
|
232
245
|
for (const file of files) {
|
|
233
246
|
const sourcePath = path.join(sourceDir, file.relativePath);
|
|
234
247
|
const destPath = path.join(destDir, file.relativePath);
|
|
235
|
-
|
|
248
|
+
await fsp.mkdir(path.dirname(destPath), { recursive: true });
|
|
236
249
|
try {
|
|
237
|
-
|
|
250
|
+
await fsp.copyFile(sourcePath, destPath, fs.constants.COPYFILE_EXCL);
|
|
238
251
|
copiedFiles.push(destPath);
|
|
239
252
|
} catch (err) {
|
|
240
253
|
if (err.code !== "EEXIST")
|
|
@@ -242,15 +255,11 @@ function copyBundledDirectoryBounded(sourceDir, destDir) {
|
|
|
242
255
|
}
|
|
243
256
|
}
|
|
244
257
|
} catch (err) {
|
|
245
|
-
|
|
258
|
+
await rollbackCopiedFilesAsync(copiedFiles, destDir);
|
|
246
259
|
throw err;
|
|
247
260
|
}
|
|
248
261
|
}
|
|
249
|
-
function
|
|
250
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
251
|
-
console.warn(`[opencode-swarm] Could not install bundled project skills; continuing without sync: ${message}`);
|
|
252
|
-
}
|
|
253
|
-
function syncBundledProjectSkillsIfMissing(projectDirectory, packageRoot, quiet = false) {
|
|
262
|
+
async function syncBundledProjectSkillsIfMissingAsync(projectDirectory, packageRoot, quiet = false) {
|
|
254
263
|
try {
|
|
255
264
|
const cacheKey = getSyncCacheKey(projectDirectory, packageRoot);
|
|
256
265
|
if (syncedProjectSkillTargets.has(cacheKey))
|
|
@@ -259,23 +268,23 @@ function syncBundledProjectSkillsIfMissing(projectDirectory, packageRoot, quiet
|
|
|
259
268
|
const opencodeDir = path.join(projectDirectory, ".opencode");
|
|
260
269
|
const skillsDir = path.join(opencodeDir, "skills");
|
|
261
270
|
let sawBundledSource = false;
|
|
262
|
-
if (!
|
|
271
|
+
if (!await ensureNotSymlinkedDirectoryAsync(opencodeDir))
|
|
263
272
|
return;
|
|
264
|
-
if (!
|
|
273
|
+
if (!await ensureNotSymlinkedDirectoryAsync(skillsDir))
|
|
265
274
|
return;
|
|
266
275
|
for (const slug of BUNDLED_PROJECT_SKILLS) {
|
|
267
276
|
const sourceDir = path.join(sourceRoot, slug);
|
|
268
277
|
const sourceSkill = path.join(sourceDir, "SKILL.md");
|
|
269
278
|
const destDir = path.join(skillsDir, slug);
|
|
270
279
|
const destSkill = path.join(destDir, "SKILL.md");
|
|
271
|
-
if (!
|
|
280
|
+
if (!await pathExistsAsync(sourceSkill))
|
|
272
281
|
continue;
|
|
273
282
|
sawBundledSource = true;
|
|
274
|
-
if (
|
|
283
|
+
if (await pathExistsAsync(destSkill))
|
|
275
284
|
continue;
|
|
276
|
-
if (!
|
|
285
|
+
if (!await ensureNotSymlinkedDirectoryAsync(destDir))
|
|
277
286
|
continue;
|
|
278
|
-
|
|
287
|
+
await copyBundledDirectoryBoundedAsync(sourceDir, destDir);
|
|
279
288
|
if (!quiet) {
|
|
280
289
|
console.warn(`[opencode-swarm] Installed bundled skill .opencode/skills/${slug}/SKILL.md for first-class /swarm command support`);
|
|
281
290
|
}
|
|
@@ -15027,21 +15036,21 @@ function hash2(content) {
|
|
|
15027
15036
|
return createHash("sha256").update(content, "utf-8").digest("hex");
|
|
15028
15037
|
}
|
|
15029
15038
|
function readTextBounded(absPath) {
|
|
15030
|
-
const
|
|
15031
|
-
if (!
|
|
15039
|
+
const stat3 = fs2.lstatSync(absPath);
|
|
15040
|
+
if (!stat3.isFile() || stat3.size > MAX_SOURCE_BYTES) {
|
|
15032
15041
|
return null;
|
|
15033
15042
|
}
|
|
15034
15043
|
return fs2.readFileSync(absPath, "utf-8");
|
|
15035
15044
|
}
|
|
15036
15045
|
function fileArtifact(root, absPath) {
|
|
15037
15046
|
try {
|
|
15038
|
-
const
|
|
15039
|
-
if (!
|
|
15047
|
+
const stat3 = fs2.lstatSync(absPath);
|
|
15048
|
+
if (!stat3.isFile() || stat3.size > MAX_SOURCE_BYTES)
|
|
15040
15049
|
return null;
|
|
15041
15050
|
return {
|
|
15042
15051
|
relPath: toPosix(path4.relative(root, absPath)),
|
|
15043
|
-
bytes:
|
|
15044
|
-
mtimeMs:
|
|
15052
|
+
bytes: stat3.size,
|
|
15053
|
+
mtimeMs: stat3.mtimeMs
|
|
15045
15054
|
};
|
|
15046
15055
|
} catch {
|
|
15047
15056
|
return null;
|
|
@@ -15332,14 +15341,14 @@ function readEffectiveSpecSync(directory) {
|
|
|
15332
15341
|
const root = path4.resolve(directory);
|
|
15333
15342
|
const swSpecPath = path4.join(root, SWARM_SPEC_REL);
|
|
15334
15343
|
try {
|
|
15335
|
-
const
|
|
15336
|
-
if (
|
|
15344
|
+
const stat3 = fs2.lstatSync(swSpecPath);
|
|
15345
|
+
if (stat3.isFile() && stat3.size <= MAX_SPEC_BYTES) {
|
|
15337
15346
|
const content = fs2.readFileSync(swSpecPath, "utf-8");
|
|
15338
15347
|
return {
|
|
15339
15348
|
source: "swarm",
|
|
15340
15349
|
content,
|
|
15341
15350
|
hash: hash2(content),
|
|
15342
|
-
mtime:
|
|
15351
|
+
mtime: stat3.mtime.toISOString(),
|
|
15343
15352
|
sourcePaths: [toPosix(SWARM_SPEC_REL)],
|
|
15344
15353
|
warnings: []
|
|
15345
15354
|
};
|
|
@@ -15878,9 +15887,9 @@ var init_ledger = __esm(() => {
|
|
|
15878
15887
|
|
|
15879
15888
|
// src/plan/manager.ts
|
|
15880
15889
|
import {
|
|
15881
|
-
copyFileSync
|
|
15882
|
-
existsSync as
|
|
15883
|
-
readdirSync as
|
|
15890
|
+
copyFileSync,
|
|
15891
|
+
existsSync as existsSync3,
|
|
15892
|
+
readdirSync as readdirSync2,
|
|
15884
15893
|
renameSync as renameSync3,
|
|
15885
15894
|
unlinkSync
|
|
15886
15895
|
} from "fs";
|
|
@@ -16324,7 +16333,7 @@ async function savePlan(directory, plan, options) {
|
|
|
16324
16333
|
const oldLedgerPath = path6.join(swarmDir2, "plan-ledger.jsonl");
|
|
16325
16334
|
const oldLedgerBackupPath = path6.join(swarmDir2, `plan-ledger.backup-${Date.now()}-${Math.floor(Math.random() * 1e9)}.jsonl`);
|
|
16326
16335
|
let backupExists = false;
|
|
16327
|
-
if (
|
|
16336
|
+
if (existsSync3(oldLedgerPath)) {
|
|
16328
16337
|
try {
|
|
16329
16338
|
renameSync3(oldLedgerPath, oldLedgerBackupPath);
|
|
16330
16339
|
backupExists = true;
|
|
@@ -16341,15 +16350,15 @@ async function savePlan(directory, plan, options) {
|
|
|
16341
16350
|
const errorMessage = String(initErr);
|
|
16342
16351
|
if (errorMessage.includes("already initialized")) {
|
|
16343
16352
|
try {
|
|
16344
|
-
if (
|
|
16353
|
+
if (existsSync3(oldLedgerBackupPath))
|
|
16345
16354
|
unlinkSync(oldLedgerBackupPath);
|
|
16346
16355
|
} catch {}
|
|
16347
16356
|
} else {
|
|
16348
|
-
if (
|
|
16357
|
+
if (existsSync3(oldLedgerBackupPath)) {
|
|
16349
16358
|
try {
|
|
16350
16359
|
renameSync3(oldLedgerBackupPath, oldLedgerPath);
|
|
16351
16360
|
} catch {
|
|
16352
|
-
|
|
16361
|
+
copyFileSync(oldLedgerBackupPath, oldLedgerPath);
|
|
16353
16362
|
try {
|
|
16354
16363
|
unlinkSync(oldLedgerBackupPath);
|
|
16355
16364
|
} catch {}
|
|
@@ -16367,19 +16376,19 @@ async function savePlan(directory, plan, options) {
|
|
|
16367
16376
|
} catch (renameErr) {
|
|
16368
16377
|
warn(`[savePlan] Could not archive old ledger (rename failed: ${renameErr instanceof Error ? renameErr.message : String(renameErr)}). Old ledger may still exist at ${oldLedgerBackupPath}.`);
|
|
16369
16378
|
try {
|
|
16370
|
-
if (
|
|
16379
|
+
if (existsSync3(oldLedgerBackupPath))
|
|
16371
16380
|
unlinkSync(oldLedgerBackupPath);
|
|
16372
16381
|
} catch {}
|
|
16373
16382
|
}
|
|
16374
16383
|
} else if (!initSucceeded && backupExists) {
|
|
16375
16384
|
try {
|
|
16376
|
-
if (
|
|
16385
|
+
if (existsSync3(oldLedgerBackupPath))
|
|
16377
16386
|
unlinkSync(oldLedgerBackupPath);
|
|
16378
16387
|
} catch {}
|
|
16379
16388
|
}
|
|
16380
16389
|
const MAX_ARCHIVED_SIBLINGS = 5;
|
|
16381
16390
|
try {
|
|
16382
|
-
const allFiles =
|
|
16391
|
+
const allFiles = readdirSync2(swarmDir2);
|
|
16383
16392
|
const archivedSiblings = allFiles.filter((f) => f.startsWith("plan-ledger.archived-") && f.endsWith(".jsonl")).sort();
|
|
16384
16393
|
if (archivedSiblings.length > MAX_ARCHIVED_SIBLINGS) {
|
|
16385
16394
|
const toRemove = archivedSiblings.slice(0, archivedSiblings.length - MAX_ARCHIVED_SIBLINGS);
|
|
@@ -19203,11 +19212,11 @@ function handleAgentsCommand(agents, guardrails) {
|
|
|
19203
19212
|
const temp = agent.config.temperature !== undefined ? agent.config.temperature.toString() : "default";
|
|
19204
19213
|
const tools = agent.config.tools || {};
|
|
19205
19214
|
const isReadOnly = tools.write === false || tools.edit === false;
|
|
19206
|
-
const
|
|
19215
|
+
const access3 = isReadOnly ? "\uD83D\uDD12 read-only" : "\u270F\uFE0F read-write";
|
|
19207
19216
|
const desc = agent.description || agent.config.description || "";
|
|
19208
19217
|
const hasCustomProfile = guardrails?.profiles?.[key] !== undefined;
|
|
19209
19218
|
const profileIndicator = hasCustomProfile ? " | \u26A1 custom limits" : "";
|
|
19210
|
-
lines.push(`- **${key}** | model: \`${model}\` | temp: ${temp} | ${
|
|
19219
|
+
lines.push(`- **${key}** | model: \`${model}\` | temp: ${temp} | ${access3}${profileIndicator}`);
|
|
19211
19220
|
if (desc) {
|
|
19212
19221
|
lines.push(` ${desc}`);
|
|
19213
19222
|
}
|
|
@@ -20252,8 +20261,8 @@ GFS4: `);
|
|
|
20252
20261
|
}
|
|
20253
20262
|
var fs$copyFile = fs6.copyFile;
|
|
20254
20263
|
if (fs$copyFile)
|
|
20255
|
-
fs6.copyFile =
|
|
20256
|
-
function
|
|
20264
|
+
fs6.copyFile = copyFile2;
|
|
20265
|
+
function copyFile2(src, dest, flags, cb) {
|
|
20257
20266
|
if (typeof flags === "function") {
|
|
20258
20267
|
cb = flags;
|
|
20259
20268
|
flags = 0;
|
|
@@ -20271,9 +20280,9 @@ GFS4: `);
|
|
|
20271
20280
|
}
|
|
20272
20281
|
}
|
|
20273
20282
|
var fs$readdir = fs6.readdir;
|
|
20274
|
-
fs6.readdir =
|
|
20283
|
+
fs6.readdir = readdir2;
|
|
20275
20284
|
var noReaddirOptionVersions = /^v[0-5]\./;
|
|
20276
|
-
function
|
|
20285
|
+
function readdir2(path8, options, cb) {
|
|
20277
20286
|
if (typeof options === "function")
|
|
20278
20287
|
cb = options, options = null;
|
|
20279
20288
|
var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path9, options2, cb2, startTime) {
|
|
@@ -20862,11 +20871,11 @@ var require_mtime_precision = __commonJS((exports, module) => {
|
|
|
20862
20871
|
function probe(file2, fs5, callback) {
|
|
20863
20872
|
const cachedPrecision = fs5[cacheSymbol];
|
|
20864
20873
|
if (cachedPrecision) {
|
|
20865
|
-
return fs5.stat(file2, (err,
|
|
20874
|
+
return fs5.stat(file2, (err, stat3) => {
|
|
20866
20875
|
if (err) {
|
|
20867
20876
|
return callback(err);
|
|
20868
20877
|
}
|
|
20869
|
-
callback(null,
|
|
20878
|
+
callback(null, stat3.mtime, cachedPrecision);
|
|
20870
20879
|
});
|
|
20871
20880
|
}
|
|
20872
20881
|
const mtime = new Date(Math.ceil(Date.now() / 1000) * 1000 + 5);
|
|
@@ -20874,13 +20883,13 @@ var require_mtime_precision = __commonJS((exports, module) => {
|
|
|
20874
20883
|
if (err) {
|
|
20875
20884
|
return callback(err);
|
|
20876
20885
|
}
|
|
20877
|
-
fs5.stat(file2, (err2,
|
|
20886
|
+
fs5.stat(file2, (err2, stat3) => {
|
|
20878
20887
|
if (err2) {
|
|
20879
20888
|
return callback(err2);
|
|
20880
20889
|
}
|
|
20881
|
-
const precision =
|
|
20890
|
+
const precision = stat3.mtime.getTime() % 1000 === 0 ? "s" : "ms";
|
|
20882
20891
|
Object.defineProperty(fs5, cacheSymbol, { value: precision });
|
|
20883
|
-
callback(null,
|
|
20892
|
+
callback(null, stat3.mtime, precision);
|
|
20884
20893
|
});
|
|
20885
20894
|
});
|
|
20886
20895
|
}
|
|
@@ -20930,14 +20939,14 @@ var require_lockfile = __commonJS((exports, module) => {
|
|
|
20930
20939
|
if (options.stale <= 0) {
|
|
20931
20940
|
return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file: file2 }));
|
|
20932
20941
|
}
|
|
20933
|
-
options.fs.stat(lockfilePath, (err2,
|
|
20942
|
+
options.fs.stat(lockfilePath, (err2, stat3) => {
|
|
20934
20943
|
if (err2) {
|
|
20935
20944
|
if (err2.code === "ENOENT") {
|
|
20936
20945
|
return acquireLock(file2, { ...options, stale: 0 }, callback);
|
|
20937
20946
|
}
|
|
20938
20947
|
return callback(err2);
|
|
20939
20948
|
}
|
|
20940
|
-
if (!isLockStale(
|
|
20949
|
+
if (!isLockStale(stat3, options)) {
|
|
20941
20950
|
return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file: file2 }));
|
|
20942
20951
|
}
|
|
20943
20952
|
removeLock(file2, options, (err3) => {
|
|
@@ -20949,8 +20958,8 @@ var require_lockfile = __commonJS((exports, module) => {
|
|
|
20949
20958
|
});
|
|
20950
20959
|
});
|
|
20951
20960
|
}
|
|
20952
|
-
function isLockStale(
|
|
20953
|
-
return
|
|
20961
|
+
function isLockStale(stat3, options) {
|
|
20962
|
+
return stat3.mtime.getTime() < Date.now() - options.stale;
|
|
20954
20963
|
}
|
|
20955
20964
|
function removeLock(file2, options, callback) {
|
|
20956
20965
|
options.fs.rmdir(getLockFile(file2, options), (err) => {
|
|
@@ -20968,7 +20977,7 @@ var require_lockfile = __commonJS((exports, module) => {
|
|
|
20968
20977
|
lock2.updateDelay = lock2.updateDelay || options.update;
|
|
20969
20978
|
lock2.updateTimeout = setTimeout(() => {
|
|
20970
20979
|
lock2.updateTimeout = null;
|
|
20971
|
-
options.fs.stat(lock2.lockfilePath, (err,
|
|
20980
|
+
options.fs.stat(lock2.lockfilePath, (err, stat3) => {
|
|
20972
20981
|
const isOverThreshold = lock2.lastUpdate + options.stale < Date.now();
|
|
20973
20982
|
if (err) {
|
|
20974
20983
|
if (err.code === "ENOENT" || isOverThreshold) {
|
|
@@ -20977,7 +20986,7 @@ var require_lockfile = __commonJS((exports, module) => {
|
|
|
20977
20986
|
lock2.updateDelay = 1000;
|
|
20978
20987
|
return updateLock(file2, options);
|
|
20979
20988
|
}
|
|
20980
|
-
const isMtimeOurs = lock2.mtime.getTime() ===
|
|
20989
|
+
const isMtimeOurs = lock2.mtime.getTime() === stat3.mtime.getTime();
|
|
20981
20990
|
if (!isMtimeOurs) {
|
|
20982
20991
|
return setLockAsCompromised(file2, lock2, Object.assign(new Error("Unable to update lock within the stale threshold"), { code: "ECOMPROMISED" }));
|
|
20983
20992
|
}
|
|
@@ -21095,11 +21104,11 @@ var require_lockfile = __commonJS((exports, module) => {
|
|
|
21095
21104
|
if (err) {
|
|
21096
21105
|
return callback(err);
|
|
21097
21106
|
}
|
|
21098
|
-
options.fs.stat(getLockFile(file3, options), (err2,
|
|
21107
|
+
options.fs.stat(getLockFile(file3, options), (err2, stat3) => {
|
|
21099
21108
|
if (err2) {
|
|
21100
21109
|
return err2.code === "ENOENT" ? callback(null, false) : callback(err2);
|
|
21101
21110
|
}
|
|
21102
|
-
return callback(null, !isLockStale(
|
|
21111
|
+
return callback(null, !isLockStale(stat3, options));
|
|
21103
21112
|
});
|
|
21104
21113
|
});
|
|
21105
21114
|
}
|
|
@@ -21407,11 +21416,11 @@ var init_task_id = __esm(() => {
|
|
|
21407
21416
|
|
|
21408
21417
|
// src/evidence/manager.ts
|
|
21409
21418
|
import {
|
|
21410
|
-
mkdirSync as
|
|
21411
|
-
readdirSync as
|
|
21419
|
+
mkdirSync as mkdirSync4,
|
|
21420
|
+
readdirSync as readdirSync4,
|
|
21412
21421
|
realpathSync,
|
|
21413
|
-
rmSync
|
|
21414
|
-
statSync as
|
|
21422
|
+
rmSync,
|
|
21423
|
+
statSync as statSync4
|
|
21415
21424
|
} from "fs";
|
|
21416
21425
|
import * as fs6 from "fs/promises";
|
|
21417
21426
|
import * as path9 from "path";
|
|
@@ -21437,11 +21446,11 @@ function validateProjectRoot(directory) {
|
|
|
21437
21446
|
break;
|
|
21438
21447
|
const parentSwarm = path9.join(parent, ".swarm");
|
|
21439
21448
|
try {
|
|
21440
|
-
if (
|
|
21449
|
+
if (statSync4(parentSwarm).isDirectory()) {
|
|
21441
21450
|
let hasProjectIndicator = false;
|
|
21442
21451
|
for (const indicator of PROJECT_INDICATORS) {
|
|
21443
21452
|
try {
|
|
21444
|
-
const indicatorStat =
|
|
21453
|
+
const indicatorStat = statSync4(path9.join(parent, indicator));
|
|
21445
21454
|
if (indicatorStat.isFile() || indicatorStat.isDirectory()) {
|
|
21446
21455
|
hasProjectIndicator = true;
|
|
21447
21456
|
break;
|
|
@@ -21515,14 +21524,14 @@ async function saveEvidence(directory, taskId, evidence) {
|
|
|
21515
21524
|
if (bundleJson.length > EVIDENCE_MAX_JSON_BYTES) {
|
|
21516
21525
|
throw new Error(`Evidence bundle size (${bundleJson.length} bytes) exceeds maximum (${EVIDENCE_MAX_JSON_BYTES} bytes)`);
|
|
21517
21526
|
}
|
|
21518
|
-
|
|
21527
|
+
mkdirSync4(evidenceDir, { recursive: true });
|
|
21519
21528
|
const tempPath = path9.join(evidenceDir, `evidence.json.tmp.${Date.now()}.${process.pid}`);
|
|
21520
21529
|
try {
|
|
21521
21530
|
await bunWrite(tempPath, bundleJson);
|
|
21522
21531
|
await fs6.rename(tempPath, evidencePath);
|
|
21523
21532
|
} catch (error49) {
|
|
21524
21533
|
try {
|
|
21525
|
-
|
|
21534
|
+
rmSync(tempPath, { force: true });
|
|
21526
21535
|
} catch {}
|
|
21527
21536
|
throw error49;
|
|
21528
21537
|
}
|
|
@@ -21581,7 +21590,7 @@ async function loadEvidence(directory, taskId) {
|
|
|
21581
21590
|
await fs6.rename(tempPath, evidencePath);
|
|
21582
21591
|
} catch (writeError) {
|
|
21583
21592
|
try {
|
|
21584
|
-
|
|
21593
|
+
rmSync(tempPath, { force: true });
|
|
21585
21594
|
} catch {}
|
|
21586
21595
|
warn(`Failed to persist repaired flat retrospective for task ${sanitizedTaskId}: ${writeError instanceof Error ? writeError.message : String(writeError)}`);
|
|
21587
21596
|
}
|
|
@@ -21608,13 +21617,13 @@ async function loadEvidence(directory, taskId) {
|
|
|
21608
21617
|
async function listEvidenceTaskIds(directory) {
|
|
21609
21618
|
const evidenceBasePath = validateSwarmPath(directory, "evidence");
|
|
21610
21619
|
try {
|
|
21611
|
-
|
|
21620
|
+
statSync4(evidenceBasePath);
|
|
21612
21621
|
} catch {
|
|
21613
21622
|
return [];
|
|
21614
21623
|
}
|
|
21615
21624
|
let entries;
|
|
21616
21625
|
try {
|
|
21617
|
-
entries =
|
|
21626
|
+
entries = readdirSync4(evidenceBasePath);
|
|
21618
21627
|
} catch {
|
|
21619
21628
|
return [];
|
|
21620
21629
|
}
|
|
@@ -21622,7 +21631,7 @@ async function listEvidenceTaskIds(directory) {
|
|
|
21622
21631
|
for (const entry of entries) {
|
|
21623
21632
|
const entryPath = path9.join(evidenceBasePath, entry);
|
|
21624
21633
|
try {
|
|
21625
|
-
const stats =
|
|
21634
|
+
const stats = statSync4(entryPath);
|
|
21626
21635
|
if (!stats.isDirectory()) {
|
|
21627
21636
|
continue;
|
|
21628
21637
|
}
|
|
@@ -21641,12 +21650,12 @@ async function deleteEvidence(directory, taskId) {
|
|
|
21641
21650
|
const relativePath = path9.join("evidence", sanitizedTaskId);
|
|
21642
21651
|
const evidenceDir = validateSwarmPath(directory, relativePath);
|
|
21643
21652
|
try {
|
|
21644
|
-
|
|
21653
|
+
statSync4(evidenceDir);
|
|
21645
21654
|
} catch {
|
|
21646
21655
|
return false;
|
|
21647
21656
|
}
|
|
21648
21657
|
try {
|
|
21649
|
-
|
|
21658
|
+
rmSync(evidenceDir, { recursive: true, force: true });
|
|
21650
21659
|
return true;
|
|
21651
21660
|
} catch (error49) {
|
|
21652
21661
|
warn(`Failed to delete evidence for task ${sanitizedTaskId}: ${error49 instanceof Error ? error49.message : String(error49)}`);
|
|
@@ -21832,7 +21841,7 @@ var init_archive = __esm(() => {
|
|
|
21832
21841
|
});
|
|
21833
21842
|
|
|
21834
21843
|
// src/db/project-db.ts
|
|
21835
|
-
import { existsSync as
|
|
21844
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync5 } from "fs";
|
|
21836
21845
|
import { createRequire } from "module";
|
|
21837
21846
|
import { join as join9, resolve as resolve7 } from "path";
|
|
21838
21847
|
function loadDatabaseCtor() {
|
|
@@ -21867,7 +21876,7 @@ function projectDbPath(directory) {
|
|
|
21867
21876
|
return join9(resolve7(directory), ".swarm", "swarm.db");
|
|
21868
21877
|
}
|
|
21869
21878
|
function projectDbExists(directory) {
|
|
21870
|
-
return
|
|
21879
|
+
return existsSync6(projectDbPath(directory));
|
|
21871
21880
|
}
|
|
21872
21881
|
function getProjectDb(directory) {
|
|
21873
21882
|
const key = resolve7(directory);
|
|
@@ -21875,7 +21884,7 @@ function getProjectDb(directory) {
|
|
|
21875
21884
|
if (existing)
|
|
21876
21885
|
return existing;
|
|
21877
21886
|
const swarmDir = join9(key, ".swarm");
|
|
21878
|
-
|
|
21887
|
+
mkdirSync5(swarmDir, { recursive: true });
|
|
21879
21888
|
const Db = loadDatabaseCtor();
|
|
21880
21889
|
const db = new Db(join9(swarmDir, "swarm.db"));
|
|
21881
21890
|
db.run("PRAGMA journal_mode = WAL;");
|
|
@@ -37644,8 +37653,8 @@ var init_task_file = __esm(() => {
|
|
|
37644
37653
|
});
|
|
37645
37654
|
|
|
37646
37655
|
// src/hooks/knowledge-events.ts
|
|
37647
|
-
import { existsSync as
|
|
37648
|
-
import { appendFile as appendFile2, mkdir as
|
|
37656
|
+
import { existsSync as existsSync8 } from "fs";
|
|
37657
|
+
import { appendFile as appendFile2, mkdir as mkdir3, readFile as readFile2, stat as stat3 } from "fs/promises";
|
|
37649
37658
|
import * as path13 from "path";
|
|
37650
37659
|
function resolveKnowledgeEventsPath(directory) {
|
|
37651
37660
|
return path13.join(directory, ".swarm", "knowledge-events.jsonl");
|
|
@@ -37658,7 +37667,7 @@ function resolveLegacyApplicationLogPath(directory) {
|
|
|
37658
37667
|
}
|
|
37659
37668
|
async function readKnowledgeEvents(directory) {
|
|
37660
37669
|
const filePath = resolveKnowledgeEventsPath(directory);
|
|
37661
|
-
if (!
|
|
37670
|
+
if (!existsSync8(filePath))
|
|
37662
37671
|
return [];
|
|
37663
37672
|
const content = await readFile2(filePath, "utf-8");
|
|
37664
37673
|
return parseEventLines(content.split(`
|
|
@@ -37666,7 +37675,7 @@ async function readKnowledgeEvents(directory) {
|
|
|
37666
37675
|
}
|
|
37667
37676
|
async function readLegacyApplicationRecords(directory) {
|
|
37668
37677
|
const filePath = resolveLegacyApplicationLogPath(directory);
|
|
37669
|
-
if (!
|
|
37678
|
+
if (!existsSync8(filePath))
|
|
37670
37679
|
return [];
|
|
37671
37680
|
const content = await readFile2(filePath, "utf-8");
|
|
37672
37681
|
const out = [];
|
|
@@ -37736,7 +37745,7 @@ function maxIso(current, candidate) {
|
|
|
37736
37745
|
}
|
|
37737
37746
|
async function readCounterBaseline(directory) {
|
|
37738
37747
|
const filePath = resolveKnowledgeCounterBaselinePath(directory);
|
|
37739
|
-
if (!
|
|
37748
|
+
if (!existsSync8(filePath))
|
|
37740
37749
|
return new Map;
|
|
37741
37750
|
const raw = JSON.parse(await readFile2(filePath, "utf-8"));
|
|
37742
37751
|
const map3 = new Map;
|
|
@@ -37747,7 +37756,7 @@ async function readCounterBaseline(directory) {
|
|
|
37747
37756
|
}
|
|
37748
37757
|
async function statCacheKey(filePath) {
|
|
37749
37758
|
try {
|
|
37750
|
-
const fileStat = await
|
|
37759
|
+
const fileStat = await stat3(filePath);
|
|
37751
37760
|
return `${fileStat.mtimeMs}:${fileStat.ctimeMs}:${fileStat.size}`;
|
|
37752
37761
|
} catch (err) {
|
|
37753
37762
|
if (err?.code === "ENOENT")
|
|
@@ -37932,8 +37941,8 @@ var init_knowledge_events = __esm(() => {
|
|
|
37932
37941
|
});
|
|
37933
37942
|
|
|
37934
37943
|
// src/hooks/knowledge-store.ts
|
|
37935
|
-
import { existsSync as
|
|
37936
|
-
import { appendFile as appendFile3, mkdir as
|
|
37944
|
+
import { existsSync as existsSync9 } from "fs";
|
|
37945
|
+
import { appendFile as appendFile3, mkdir as mkdir4, readFile as readFile3 } from "fs/promises";
|
|
37937
37946
|
import * as os4 from "os";
|
|
37938
37947
|
import * as path14 from "path";
|
|
37939
37948
|
function resolveSwarmKnowledgePath(directory) {
|
|
@@ -37963,7 +37972,7 @@ function resolveHiveRejectedPath() {
|
|
|
37963
37972
|
return path14.join(path14.dirname(hivePath), "shared-learnings-rejected.jsonl");
|
|
37964
37973
|
}
|
|
37965
37974
|
async function readKnowledge(filePath) {
|
|
37966
|
-
if (!
|
|
37975
|
+
if (!existsSync9(filePath))
|
|
37967
37976
|
return [];
|
|
37968
37977
|
const content = await readFile3(filePath, "utf-8");
|
|
37969
37978
|
const results = [];
|
|
@@ -38058,7 +38067,7 @@ async function appendRetractionRecord(directory, record3) {
|
|
|
38058
38067
|
}
|
|
38059
38068
|
async function appendKnowledge(filePath, entry) {
|
|
38060
38069
|
const dir = path14.dirname(filePath);
|
|
38061
|
-
await
|
|
38070
|
+
await mkdir4(dir, { recursive: true });
|
|
38062
38071
|
let release = null;
|
|
38063
38072
|
try {
|
|
38064
38073
|
release = await import_proper_lockfile4.default.lock(dir, {
|
|
@@ -38077,7 +38086,7 @@ async function appendKnowledge(filePath, entry) {
|
|
|
38077
38086
|
}
|
|
38078
38087
|
async function rewriteKnowledge(filePath, entries) {
|
|
38079
38088
|
const dir = path14.dirname(filePath);
|
|
38080
|
-
await
|
|
38089
|
+
await mkdir4(dir, { recursive: true });
|
|
38081
38090
|
let release = null;
|
|
38082
38091
|
try {
|
|
38083
38092
|
release = await import_proper_lockfile4.default.lock(dir, {
|
|
@@ -38099,7 +38108,7 @@ async function rewriteKnowledge(filePath, entries) {
|
|
|
38099
38108
|
async function transactFile(filePath, read, write, mutate) {
|
|
38100
38109
|
const dir = path14.dirname(filePath);
|
|
38101
38110
|
try {
|
|
38102
|
-
await
|
|
38111
|
+
await mkdir4(dir, { recursive: true });
|
|
38103
38112
|
} catch {
|
|
38104
38113
|
return false;
|
|
38105
38114
|
}
|
|
@@ -38290,7 +38299,7 @@ async function applyConfidenceDeltas(filePath, deltas) {
|
|
|
38290
38299
|
let release = null;
|
|
38291
38300
|
try {
|
|
38292
38301
|
const dir = path14.dirname(filePath);
|
|
38293
|
-
await
|
|
38302
|
+
await mkdir4(dir, { recursive: true });
|
|
38294
38303
|
release = await import_proper_lockfile4.default.lock(dir, {
|
|
38295
38304
|
retries: { retries: 5, minTimeout: 100, maxTimeout: 500 },
|
|
38296
38305
|
stale: 5000
|
|
@@ -38748,7 +38757,7 @@ var init_learning_metrics = __esm(() => {
|
|
|
38748
38757
|
});
|
|
38749
38758
|
|
|
38750
38759
|
// src/hooks/knowledge-validator.ts
|
|
38751
|
-
import { appendFile as appendFile4, mkdir as
|
|
38760
|
+
import { appendFile as appendFile4, mkdir as mkdir5 } from "fs/promises";
|
|
38752
38761
|
import * as path15 from "path";
|
|
38753
38762
|
function normalizeText(text) {
|
|
38754
38763
|
return text.normalize("NFKC").toLowerCase().replace(/[^\w\s]/g, " ").replace(/\s+/g, " ").trim();
|
|
@@ -39019,7 +39028,7 @@ function resolveUnactionablePath(directory) {
|
|
|
39019
39028
|
async function appendUnactionable(directory, entry, reason) {
|
|
39020
39029
|
const filePath = resolveUnactionablePath(directory);
|
|
39021
39030
|
const dirPath = path15.dirname(filePath);
|
|
39022
|
-
await
|
|
39031
|
+
await mkdir5(dirPath, { recursive: true });
|
|
39023
39032
|
await transactKnowledge(filePath, (existing) => {
|
|
39024
39033
|
const record3 = {
|
|
39025
39034
|
...entry,
|
|
@@ -39056,7 +39065,7 @@ async function quarantineEntry(directory, entryId, reason, reportedBy) {
|
|
|
39056
39065
|
const quarantinePath = path15.join(directory, ".swarm", "knowledge-quarantined.jsonl");
|
|
39057
39066
|
const rejectedPath = path15.join(directory, ".swarm", "knowledge-rejected.jsonl");
|
|
39058
39067
|
const swarmDir = path15.join(directory, ".swarm");
|
|
39059
|
-
await
|
|
39068
|
+
await mkdir5(swarmDir, { recursive: true });
|
|
39060
39069
|
let release;
|
|
39061
39070
|
try {
|
|
39062
39071
|
release = await import_proper_lockfile5.default.lock(swarmDir, {
|
|
@@ -39120,7 +39129,7 @@ async function restoreEntry(directory, entryId) {
|
|
|
39120
39129
|
const quarantinePath = path15.join(directory, ".swarm", "knowledge-quarantined.jsonl");
|
|
39121
39130
|
const rejectedPath = path15.join(directory, ".swarm", "knowledge-rejected.jsonl");
|
|
39122
39131
|
const swarmDir = path15.join(directory, ".swarm");
|
|
39123
|
-
await
|
|
39132
|
+
await mkdir5(swarmDir, { recursive: true });
|
|
39124
39133
|
let release;
|
|
39125
39134
|
try {
|
|
39126
39135
|
release = await import_proper_lockfile5.default.lock(swarmDir, {
|
|
@@ -39298,7 +39307,7 @@ var init_knowledge_validator = __esm(() => {
|
|
|
39298
39307
|
});
|
|
39299
39308
|
|
|
39300
39309
|
// src/services/skill-changelog.ts
|
|
39301
|
-
import { appendFile as appendFile5, mkdir as
|
|
39310
|
+
import { appendFile as appendFile5, mkdir as mkdir6, readFile as readFile4, writeFile as writeFile3 } from "fs/promises";
|
|
39302
39311
|
import * as path16 from "path";
|
|
39303
39312
|
function resolveSkillChangelogPath(directory, slug) {
|
|
39304
39313
|
if (slug.includes("..") || slug.includes("/") || slug.includes("\\")) {
|
|
@@ -39309,7 +39318,7 @@ function resolveSkillChangelogPath(directory, slug) {
|
|
|
39309
39318
|
async function appendSkillChangelog(directory, slug, entry) {
|
|
39310
39319
|
const filePath = resolveSkillChangelogPath(directory, slug);
|
|
39311
39320
|
const dirPath = path16.dirname(filePath);
|
|
39312
|
-
await
|
|
39321
|
+
await mkdir6(dirPath, { recursive: true });
|
|
39313
39322
|
await appendFile5(filePath, `${JSON.stringify(entry)}
|
|
39314
39323
|
`, "utf-8");
|
|
39315
39324
|
try {
|
|
@@ -39332,8 +39341,8 @@ var init_skill_changelog = __esm(() => {
|
|
|
39332
39341
|
});
|
|
39333
39342
|
|
|
39334
39343
|
// src/services/skill-generator.ts
|
|
39335
|
-
import { existsSync as
|
|
39336
|
-
import { mkdir as
|
|
39344
|
+
import { existsSync as existsSync10, unlinkSync as unlinkSync5 } from "fs";
|
|
39345
|
+
import { mkdir as mkdir7, readFile as readFile5, rename as rename3, writeFile as writeFile4 } from "fs/promises";
|
|
39337
39346
|
import * as path17 from "path";
|
|
39338
39347
|
function sanitizeSlug(input) {
|
|
39339
39348
|
const lc = input.toLowerCase().trim();
|
|
@@ -39356,7 +39365,7 @@ function activeRepoRelativePath(slug) {
|
|
|
39356
39365
|
async function selectCandidateEntries(directory, opts) {
|
|
39357
39366
|
const swarm = await readKnowledge(resolveSwarmKnowledgePath(directory));
|
|
39358
39367
|
const hivePath = resolveHiveKnowledgePath();
|
|
39359
|
-
const hive =
|
|
39368
|
+
const hive = existsSync10(hivePath) ? await readKnowledge(hivePath) : [];
|
|
39360
39369
|
const all = [...swarm, ...hive];
|
|
39361
39370
|
const counterRollups = await readKnowledgeCounterRollups(directory);
|
|
39362
39371
|
const selected = [];
|
|
@@ -39557,7 +39566,7 @@ function escapeMarkdown(s) {
|
|
|
39557
39566
|
return s.replace(/[\r\n]+/g, " ").slice(0, 280);
|
|
39558
39567
|
}
|
|
39559
39568
|
async function atomicWrite(p, content) {
|
|
39560
|
-
await
|
|
39569
|
+
await mkdir7(path17.dirname(p), { recursive: true });
|
|
39561
39570
|
const tmp = `${p}.tmp-${process.pid}-${Date.now()}`;
|
|
39562
39571
|
await writeFile4(tmp, content, "utf-8");
|
|
39563
39572
|
await rename3(tmp, p);
|
|
@@ -39574,7 +39583,7 @@ async function generateSkills(req) {
|
|
|
39574
39583
|
const idSet = new Set(req.sourceKnowledgeIds);
|
|
39575
39584
|
const swarm = await readKnowledge(resolveSwarmKnowledgePath(req.directory));
|
|
39576
39585
|
const hivePath = resolveHiveKnowledgePath();
|
|
39577
|
-
const hive =
|
|
39586
|
+
const hive = existsSync10(hivePath) ? await readKnowledge(hivePath) : [];
|
|
39578
39587
|
pool = [...swarm, ...hive].filter((e) => idSet.has(e.id) && e.status !== "archived");
|
|
39579
39588
|
} else {
|
|
39580
39589
|
pool = candidates;
|
|
@@ -39611,7 +39620,7 @@ async function generateSkills(req) {
|
|
|
39611
39620
|
continue;
|
|
39612
39621
|
}
|
|
39613
39622
|
let preserved = false;
|
|
39614
|
-
if (req.mode === "active" &&
|
|
39623
|
+
if (req.mode === "active" && existsSync10(targetPath) && !req.force) {
|
|
39615
39624
|
const existing = await readFile5(targetPath, "utf-8");
|
|
39616
39625
|
if (!existing.includes("generated by opencode-swarm skill-generator")) {
|
|
39617
39626
|
preserved = true;
|
|
@@ -39656,7 +39665,7 @@ async function stampSourceEntries(directory, slug, ids) {
|
|
|
39656
39665
|
if (touched)
|
|
39657
39666
|
await rewriteKnowledge(swarmPath, swarm);
|
|
39658
39667
|
const hivePath = resolveHiveKnowledgePath();
|
|
39659
|
-
if (!
|
|
39668
|
+
if (!existsSync10(hivePath))
|
|
39660
39669
|
return;
|
|
39661
39670
|
const hive = await readKnowledge(hivePath);
|
|
39662
39671
|
let touchedHive = false;
|
|
@@ -39754,7 +39763,7 @@ async function activateProposal(directory, slug, force = false) {
|
|
|
39754
39763
|
}
|
|
39755
39764
|
const from = proposalPath(directory, cleanSlug);
|
|
39756
39765
|
const to = activePath(directory, cleanSlug);
|
|
39757
|
-
if (!
|
|
39766
|
+
if (!existsSync10(from)) {
|
|
39758
39767
|
return {
|
|
39759
39768
|
activated: false,
|
|
39760
39769
|
from,
|
|
@@ -39762,7 +39771,7 @@ async function activateProposal(directory, slug, force = false) {
|
|
|
39762
39771
|
reason: `proposal not found: ${from}`
|
|
39763
39772
|
};
|
|
39764
39773
|
}
|
|
39765
|
-
if (
|
|
39774
|
+
if (existsSync10(to) && !force) {
|
|
39766
39775
|
const existing = await readFile5(to, "utf-8");
|
|
39767
39776
|
if (!existing.includes("generated by opencode-swarm skill-generator")) {
|
|
39768
39777
|
return {
|
|
@@ -39826,7 +39835,7 @@ async function listSkills(directory) {
|
|
|
39826
39835
|
const proposalsDir = path17.join(directory, ".swarm", "skills", "proposals");
|
|
39827
39836
|
const activeDir = path17.join(directory, ".opencode", "skills", "generated");
|
|
39828
39837
|
const fs9 = await import("fs/promises");
|
|
39829
|
-
if (
|
|
39838
|
+
if (existsSync10(proposalsDir)) {
|
|
39830
39839
|
const entries = await fs9.readdir(proposalsDir);
|
|
39831
39840
|
for (const f of entries) {
|
|
39832
39841
|
if (!f.endsWith(".md"))
|
|
@@ -39838,16 +39847,16 @@ async function listSkills(directory) {
|
|
|
39838
39847
|
});
|
|
39839
39848
|
}
|
|
39840
39849
|
}
|
|
39841
|
-
if (
|
|
39850
|
+
if (existsSync10(activeDir)) {
|
|
39842
39851
|
const entries = await fs9.readdir(activeDir, { withFileTypes: true });
|
|
39843
39852
|
for (const e of entries) {
|
|
39844
39853
|
if (!e.isDirectory())
|
|
39845
39854
|
continue;
|
|
39846
39855
|
const retiredMarker = path17.join(activeDir, e.name, "retired.marker");
|
|
39847
|
-
if (
|
|
39856
|
+
if (existsSync10(retiredMarker))
|
|
39848
39857
|
continue;
|
|
39849
39858
|
const skillPath = path17.join(activeDir, e.name, "SKILL.md");
|
|
39850
|
-
if (
|
|
39859
|
+
if (existsSync10(skillPath)) {
|
|
39851
39860
|
result.active.push({
|
|
39852
39861
|
slug: e.name,
|
|
39853
39862
|
path: skillPath
|
|
@@ -39926,7 +39935,7 @@ async function inspectSkill(directory, slug, prefer = "auto") {
|
|
|
39926
39935
|
if (prefer === "proposal" || prefer === "auto")
|
|
39927
39936
|
candidates.push({ p: proposalPath(directory, cleanSlug), m: "draft" });
|
|
39928
39937
|
for (const c of candidates) {
|
|
39929
|
-
if (
|
|
39938
|
+
if (existsSync10(c.p)) {
|
|
39930
39939
|
const content = await readFile5(c.p, "utf-8");
|
|
39931
39940
|
return { found: true, path: c.p, content, mode: c.m };
|
|
39932
39941
|
}
|
|
@@ -39944,7 +39953,7 @@ async function retireSkill(directory, slug, reason) {
|
|
|
39944
39953
|
};
|
|
39945
39954
|
}
|
|
39946
39955
|
const skillPath = activePath(directory, cleanSlug);
|
|
39947
|
-
if (!
|
|
39956
|
+
if (!existsSync10(skillPath)) {
|
|
39948
39957
|
return {
|
|
39949
39958
|
retired: false,
|
|
39950
39959
|
path: skillPath,
|
|
@@ -39958,7 +39967,7 @@ async function retireSkill(directory, slug, reason) {
|
|
|
39958
39967
|
retiredAt: new Date().toISOString(),
|
|
39959
39968
|
reason: reason ?? "manual_retire"
|
|
39960
39969
|
});
|
|
39961
|
-
await
|
|
39970
|
+
await mkdir7(markerDir, { recursive: true });
|
|
39962
39971
|
await writeFile4(markerPath, markerContent, "utf-8");
|
|
39963
39972
|
return {
|
|
39964
39973
|
retired: true,
|
|
@@ -39978,7 +39987,7 @@ async function regenerateSkill(directory, slug) {
|
|
|
39978
39987
|
};
|
|
39979
39988
|
}
|
|
39980
39989
|
const skillPath = activePath(directory, cleanSlug);
|
|
39981
|
-
if (!
|
|
39990
|
+
if (!existsSync10(skillPath)) {
|
|
39982
39991
|
return {
|
|
39983
39992
|
regenerated: false,
|
|
39984
39993
|
path: skillPath,
|
|
@@ -40003,7 +40012,7 @@ async function regenerateSkill(directory, slug) {
|
|
|
40003
40012
|
try {
|
|
40004
40013
|
const swarm = await readKnowledge(resolveSwarmKnowledgePath(directory));
|
|
40005
40014
|
const hivePath = resolveHiveKnowledgePath();
|
|
40006
|
-
const hive =
|
|
40015
|
+
const hive = existsSync10(hivePath) ? await readKnowledge(hivePath) : [];
|
|
40007
40016
|
const all = [...swarm, ...hive];
|
|
40008
40017
|
const idSet = new Set(fm.sourceKnowledgeIds);
|
|
40009
40018
|
matchedEntries = all.filter((e) => idSet.has(e.id));
|
|
@@ -40152,8 +40161,8 @@ var init_skill_generator = __esm(() => {
|
|
|
40152
40161
|
});
|
|
40153
40162
|
|
|
40154
40163
|
// src/services/skill-improver-quota.ts
|
|
40155
|
-
import { existsSync as
|
|
40156
|
-
import { mkdir as
|
|
40164
|
+
import { existsSync as existsSync11 } from "fs";
|
|
40165
|
+
import { mkdir as mkdir8, readFile as readFile6, rename as rename4, writeFile as writeFile5 } from "fs/promises";
|
|
40157
40166
|
import * as path18 from "path";
|
|
40158
40167
|
async function acquireLock(dir) {
|
|
40159
40168
|
const acquire = import_proper_lockfile6.default.lock(dir, LOCK_RETRY_OPTS);
|
|
@@ -40185,7 +40194,7 @@ function todayKey(window, now = new Date) {
|
|
|
40185
40194
|
return `${yr}-${m}-${d}`;
|
|
40186
40195
|
}
|
|
40187
40196
|
async function readState(filePath) {
|
|
40188
|
-
if (!
|
|
40197
|
+
if (!existsSync11(filePath))
|
|
40189
40198
|
return null;
|
|
40190
40199
|
try {
|
|
40191
40200
|
const raw = await readFile6(filePath, "utf-8");
|
|
@@ -40199,7 +40208,7 @@ async function readState(filePath) {
|
|
|
40199
40208
|
}
|
|
40200
40209
|
}
|
|
40201
40210
|
async function writeState(filePath, state) {
|
|
40202
|
-
await
|
|
40211
|
+
await mkdir8(path18.dirname(filePath), { recursive: true });
|
|
40203
40212
|
const tmp = `${filePath}.tmp-${process.pid}`;
|
|
40204
40213
|
await writeFile5(tmp, JSON.stringify(state, null, 2), "utf-8");
|
|
40205
40214
|
await rename4(tmp, filePath);
|
|
@@ -40222,7 +40231,7 @@ async function getQuotaState(directory, opts) {
|
|
|
40222
40231
|
}
|
|
40223
40232
|
async function reserveQuota(directory, opts) {
|
|
40224
40233
|
const filePath = resolveQuotaPath(directory, opts.scope);
|
|
40225
|
-
await
|
|
40234
|
+
await mkdir8(path18.dirname(filePath), { recursive: true });
|
|
40226
40235
|
let release = null;
|
|
40227
40236
|
try {
|
|
40228
40237
|
release = await acquireLock(path18.dirname(filePath));
|
|
@@ -40252,7 +40261,7 @@ async function reserveQuota(directory, opts) {
|
|
|
40252
40261
|
}
|
|
40253
40262
|
async function releaseQuota(directory, opts) {
|
|
40254
40263
|
const filePath = resolveQuotaPath(directory, opts.scope);
|
|
40255
|
-
await
|
|
40264
|
+
await mkdir8(path18.dirname(filePath), { recursive: true });
|
|
40256
40265
|
let release = null;
|
|
40257
40266
|
try {
|
|
40258
40267
|
release = await acquireLock(path18.dirname(filePath));
|
|
@@ -40437,8 +40446,8 @@ function appendSkillUsageEntry(directory, entry) {
|
|
|
40437
40446
|
_internals16.appendFileSync(resolved, `${JSON.stringify(fullEntry)}
|
|
40438
40447
|
`, "utf-8");
|
|
40439
40448
|
try {
|
|
40440
|
-
const
|
|
40441
|
-
if (
|
|
40449
|
+
const stat4 = _internals16.statSync(resolved);
|
|
40450
|
+
if (stat4.size > SKILL_USAGE_LOG_ROTATE_BYTES) {
|
|
40442
40451
|
_internals16.pruneSkillUsageLog(directory, SKILL_USAGE_LOG_MAX_ENTRIES_PER_SKILL);
|
|
40443
40452
|
}
|
|
40444
40453
|
} catch {}
|
|
@@ -40492,11 +40501,11 @@ function readSkillUsageEntriesTail(directory, filters, maxBytes = TAIL_BYTES_DEF
|
|
|
40492
40501
|
try {
|
|
40493
40502
|
const normalizedMaxBytes = Number.isFinite(maxBytes) ? maxBytes : TAIL_BYTES_DEFAULT;
|
|
40494
40503
|
const boundedMaxBytes = Math.min(Math.max(1, normalizedMaxBytes), MAX_TAIL_BYTES);
|
|
40495
|
-
const
|
|
40496
|
-
const start = Math.max(0,
|
|
40504
|
+
const stat4 = _internals16.statSync(logPath);
|
|
40505
|
+
const start = Math.max(0, stat4.size - boundedMaxBytes);
|
|
40497
40506
|
const fd = _internals16.openSync(logPath, "r");
|
|
40498
40507
|
try {
|
|
40499
|
-
const readLen =
|
|
40508
|
+
const readLen = stat4.size - start;
|
|
40500
40509
|
if (readLen === 0)
|
|
40501
40510
|
return [];
|
|
40502
40511
|
const buf = Buffer.alloc(readLen);
|
|
@@ -41039,10 +41048,10 @@ var init_hive_promoter = __esm(() => {
|
|
|
41039
41048
|
|
|
41040
41049
|
// src/services/synonym-map.ts
|
|
41041
41050
|
import {
|
|
41042
|
-
mkdir as
|
|
41051
|
+
mkdir as mkdir9,
|
|
41043
41052
|
readFile as readFile7,
|
|
41044
41053
|
rename as rename5,
|
|
41045
|
-
stat as
|
|
41054
|
+
stat as stat4,
|
|
41046
41055
|
unlink as unlink2,
|
|
41047
41056
|
writeFile as writeFile6
|
|
41048
41057
|
} from "fs/promises";
|
|
@@ -41185,7 +41194,7 @@ async function readSynonymMap(directory, maxPairs = DEFAULT_MAX_PAIRS) {
|
|
|
41185
41194
|
}
|
|
41186
41195
|
try {
|
|
41187
41196
|
const ceiling = Math.max(MIN_READ_CEILING_BYTES, Math.floor(maxPairs) * APPROX_BYTES_PER_PAIR);
|
|
41188
|
-
const st = await
|
|
41197
|
+
const st = await stat4(filePath);
|
|
41189
41198
|
if (st.size > ceiling)
|
|
41190
41199
|
return emptySynonymMap();
|
|
41191
41200
|
const raw = await readFile7(filePath, "utf-8");
|
|
@@ -41195,7 +41204,7 @@ async function readSynonymMap(directory, maxPairs = DEFAULT_MAX_PAIRS) {
|
|
|
41195
41204
|
}
|
|
41196
41205
|
}
|
|
41197
41206
|
async function writeSynonymMapAtomic(filePath, map3) {
|
|
41198
|
-
await
|
|
41207
|
+
await mkdir9(path21.dirname(filePath), { recursive: true });
|
|
41199
41208
|
const tmp = `${filePath}.tmp.${Date.now()}.${Math.floor(Math.random() * 1e9)}`;
|
|
41200
41209
|
try {
|
|
41201
41210
|
await writeFile6(tmp, JSON.stringify(map3, null, 2), "utf-8");
|
|
@@ -41209,7 +41218,7 @@ async function writeSynonymMapAtomic(filePath, map3) {
|
|
|
41209
41218
|
async function rebuildSynonymMap(directory, entries, maxPairs = DEFAULT_MAX_PAIRS) {
|
|
41210
41219
|
const filePath = resolveSynonymMapPath(directory);
|
|
41211
41220
|
const dir = path21.dirname(filePath);
|
|
41212
|
-
await
|
|
41221
|
+
await mkdir9(dir, { recursive: true });
|
|
41213
41222
|
let release = null;
|
|
41214
41223
|
try {
|
|
41215
41224
|
release = await import_proper_lockfile7.default.lock(dir, {
|
|
@@ -41498,8 +41507,8 @@ function formatSkillIndexWithContext(skills, directory) {
|
|
|
41498
41507
|
const usageLogPath = path22.join(directory, ".swarm", "skill-usage.jsonl");
|
|
41499
41508
|
let hasHistory = false;
|
|
41500
41509
|
try {
|
|
41501
|
-
const
|
|
41502
|
-
hasHistory =
|
|
41510
|
+
const stat5 = fs10.statSync(usageLogPath);
|
|
41511
|
+
hasHistory = stat5.size > 0;
|
|
41503
41512
|
} catch {}
|
|
41504
41513
|
if (!hasHistory) {
|
|
41505
41514
|
return skills.map((sp) => {
|
|
@@ -42195,7 +42204,7 @@ var init_skill_propagation_gate = __esm(() => {
|
|
|
42195
42204
|
});
|
|
42196
42205
|
|
|
42197
42206
|
// src/hooks/micro-reflector.ts
|
|
42198
|
-
import { existsSync as
|
|
42207
|
+
import { existsSync as existsSync14 } from "fs";
|
|
42199
42208
|
import { readFile as readFile8, writeFile as writeFile7 } from "fs/promises";
|
|
42200
42209
|
import * as path24 from "path";
|
|
42201
42210
|
function resolveInsightCandidatesPath(directory) {
|
|
@@ -42205,7 +42214,7 @@ async function readTaskTrajectory(directory, taskId) {
|
|
|
42205
42214
|
try {
|
|
42206
42215
|
const rel = path24.join("evidence", sanitizeTaskId2(taskId), "trajectory.jsonl");
|
|
42207
42216
|
const filePath = validateSwarmPath(directory, rel);
|
|
42208
|
-
if (!
|
|
42217
|
+
if (!existsSync14(filePath))
|
|
42209
42218
|
return [];
|
|
42210
42219
|
const content = await readFile8(filePath, "utf-8");
|
|
42211
42220
|
const out = [];
|
|
@@ -42242,8 +42251,8 @@ var init_micro_reflector = __esm(() => {
|
|
|
42242
42251
|
});
|
|
42243
42252
|
|
|
42244
42253
|
// src/hooks/knowledge-curator.ts
|
|
42245
|
-
import { existsSync as
|
|
42246
|
-
import { appendFile as appendFile6, mkdir as
|
|
42254
|
+
import { existsSync as existsSync15 } from "fs";
|
|
42255
|
+
import { appendFile as appendFile6, mkdir as mkdir10, readFile as readFile9, writeFile as writeFile8 } from "fs/promises";
|
|
42247
42256
|
import * as path25 from "path";
|
|
42248
42257
|
function pruneSeenRetroSections() {
|
|
42249
42258
|
const cutoff = Date.now() - 86400000;
|
|
@@ -42505,7 +42514,7 @@ RETRY: your last output was missing ${result.missing.join("; ")}; produce valid
|
|
|
42505
42514
|
async function appendCuratorSkippedEvent(directory, record3) {
|
|
42506
42515
|
try {
|
|
42507
42516
|
const filePath = path25.join(directory, ".swarm", "events.jsonl");
|
|
42508
|
-
await
|
|
42517
|
+
await mkdir10(path25.dirname(filePath), { recursive: true });
|
|
42509
42518
|
await appendFile6(filePath, `${JSON.stringify({
|
|
42510
42519
|
timestamp: new Date().toISOString(),
|
|
42511
42520
|
event: "curator_skipped",
|
|
@@ -42532,7 +42541,7 @@ function readInsightJsonl(content) {
|
|
|
42532
42541
|
async function consumeInsightCandidates(directory, batchLimit = MESO_INSIGHT_BATCH_LIMIT) {
|
|
42533
42542
|
try {
|
|
42534
42543
|
const filePath = resolveInsightCandidatesPath(directory);
|
|
42535
|
-
if (!
|
|
42544
|
+
if (!existsSync15(filePath))
|
|
42536
42545
|
return [];
|
|
42537
42546
|
const consumed = [];
|
|
42538
42547
|
await transactFile(filePath, async (p) => readInsightJsonl(await readFile9(p, "utf-8").catch(() => "")), async (p, data) => {
|
|
@@ -43062,7 +43071,7 @@ var init_skill_improver_llm_factory = __esm(() => {
|
|
|
43062
43071
|
});
|
|
43063
43072
|
|
|
43064
43073
|
// src/services/trajectory-cluster.ts
|
|
43065
|
-
import { mkdir as
|
|
43074
|
+
import { mkdir as mkdir11, writeFile as writeFile9 } from "fs/promises";
|
|
43066
43075
|
import * as path26 from "path";
|
|
43067
43076
|
function failureKind(e) {
|
|
43068
43077
|
const tool3 = (e.tool ?? "").toLowerCase();
|
|
@@ -43193,7 +43202,7 @@ async function writeMotifProposals(directory, opts = {}) {
|
|
|
43193
43202
|
return result;
|
|
43194
43203
|
const max = opts.maxProposals ?? 10;
|
|
43195
43204
|
const proposalsDir = validateSwarmPath(directory, path26.join("skills", "proposals"));
|
|
43196
|
-
await
|
|
43205
|
+
await mkdir11(proposalsDir, { recursive: true });
|
|
43197
43206
|
for (const motif of motifs.slice(0, max)) {
|
|
43198
43207
|
const slug = `motif-${slugify2(motif.signature)}`;
|
|
43199
43208
|
const filePath = path26.join(proposalsDir, `${slug}.md`);
|
|
@@ -43337,7 +43346,7 @@ async function writeSuccessMotifProposals(directory, opts = {}) {
|
|
|
43337
43346
|
return result;
|
|
43338
43347
|
const max = opts.maxProposals ?? 10;
|
|
43339
43348
|
const proposalsDir = validateSwarmPath(directory, path26.join("skills", "proposals"));
|
|
43340
|
-
await
|
|
43349
|
+
await mkdir11(proposalsDir, { recursive: true });
|
|
43341
43350
|
for (const motif of motifs.slice(0, max)) {
|
|
43342
43351
|
const slug = workflowSlug(motif.signature);
|
|
43343
43352
|
const filePath = path26.join(proposalsDir, `${slug}.md`);
|
|
@@ -43359,12 +43368,12 @@ var init_trajectory_cluster = __esm(() => {
|
|
|
43359
43368
|
});
|
|
43360
43369
|
|
|
43361
43370
|
// src/services/unactionable-hardening.ts
|
|
43362
|
-
import { existsSync as
|
|
43371
|
+
import { existsSync as existsSync16 } from "fs";
|
|
43363
43372
|
async function hardenUnactionableEntries(params) {
|
|
43364
43373
|
const result = { hardened: 0, retired: 0, remaining: 0 };
|
|
43365
43374
|
try {
|
|
43366
43375
|
const queuePath = resolveUnactionablePath(params.directory);
|
|
43367
|
-
if (!
|
|
43376
|
+
if (!existsSync16(queuePath))
|
|
43368
43377
|
return result;
|
|
43369
43378
|
const limit = params.batchLimit ?? HARDENING_BATCH_LIMIT;
|
|
43370
43379
|
const dedupThreshold = params.dedupThreshold ?? 0.6;
|
|
@@ -43471,14 +43480,14 @@ var init_unactionable_hardening = __esm(() => {
|
|
|
43471
43480
|
});
|
|
43472
43481
|
|
|
43473
43482
|
// src/services/skill-improver.ts
|
|
43474
|
-
import { existsSync as
|
|
43475
|
-
import { mkdir as
|
|
43483
|
+
import { existsSync as existsSync17 } from "fs";
|
|
43484
|
+
import { mkdir as mkdir12, readFile as readFile10, rename as rename6, writeFile as writeFile10 } from "fs/promises";
|
|
43476
43485
|
import * as path27 from "path";
|
|
43477
43486
|
function timestampSlug(d) {
|
|
43478
43487
|
return d.toISOString().replace(/[:.]/g, "-");
|
|
43479
43488
|
}
|
|
43480
43489
|
async function atomicWrite2(p, content) {
|
|
43481
|
-
await
|
|
43490
|
+
await mkdir12(path27.dirname(p), { recursive: true });
|
|
43482
43491
|
const tmp = `${p}.tmp-${process.pid}-${Date.now()}`;
|
|
43483
43492
|
await writeFile10(tmp, content, "utf-8");
|
|
43484
43493
|
await rename6(tmp, p);
|
|
@@ -43486,7 +43495,7 @@ async function atomicWrite2(p, content) {
|
|
|
43486
43495
|
async function gatherInventory(directory) {
|
|
43487
43496
|
const swarm = await readKnowledge(resolveSwarmKnowledgePath(directory));
|
|
43488
43497
|
const hivePath = resolveHiveKnowledgePath();
|
|
43489
|
-
const hive =
|
|
43498
|
+
const hive = existsSync17(hivePath) ? await readKnowledge(hivePath) : [];
|
|
43490
43499
|
const archived = [...swarm, ...hive].filter((e) => e.status === "archived").length;
|
|
43491
43500
|
const skills = await listSkills(directory);
|
|
43492
43501
|
const knowledgeById = new Map([...swarm, ...hive].map((entry) => [entry.id, entry]));
|
|
@@ -44252,7 +44261,7 @@ __export(exports_curator_postmortem, {
|
|
|
44252
44261
|
runCuratorPostMortem: () => runCuratorPostMortem,
|
|
44253
44262
|
_internals: () => _internals21
|
|
44254
44263
|
});
|
|
44255
|
-
import { existsSync as
|
|
44264
|
+
import { existsSync as existsSync18, readdirSync as readdirSync6, readFileSync as readFileSync9 } from "fs";
|
|
44256
44265
|
import * as path28 from "path";
|
|
44257
44266
|
async function collectKnowledgeSummary(directory) {
|
|
44258
44267
|
const entries = await readKnowledge(resolveSwarmKnowledgePath(directory));
|
|
@@ -44292,7 +44301,7 @@ async function collectKnowledgeSummary(directory) {
|
|
|
44292
44301
|
}
|
|
44293
44302
|
function readJsonlFile(filePath) {
|
|
44294
44303
|
try {
|
|
44295
|
-
if (!
|
|
44304
|
+
if (!existsSync18(filePath))
|
|
44296
44305
|
return [];
|
|
44297
44306
|
const content = readFileSync9(filePath, "utf-8");
|
|
44298
44307
|
const results = [];
|
|
@@ -44313,12 +44322,12 @@ function collectRetrospectives(directory) {
|
|
|
44313
44322
|
const results = [];
|
|
44314
44323
|
const evidenceDir = path28.join(directory, ".swarm", "evidence");
|
|
44315
44324
|
try {
|
|
44316
|
-
if (!
|
|
44325
|
+
if (!existsSync18(evidenceDir))
|
|
44317
44326
|
return results;
|
|
44318
|
-
for (const entry of
|
|
44327
|
+
for (const entry of readdirSync6(evidenceDir, { withFileTypes: true })) {
|
|
44319
44328
|
if (entry.isDirectory() && entry.name.startsWith("retro-")) {
|
|
44320
44329
|
const retroPath = path28.join(evidenceDir, entry.name, "evidence.json");
|
|
44321
|
-
if (
|
|
44330
|
+
if (existsSync18(retroPath)) {
|
|
44322
44331
|
try {
|
|
44323
44332
|
results.push(readFileSync9(retroPath, "utf-8"));
|
|
44324
44333
|
} catch {}
|
|
@@ -44332,9 +44341,9 @@ function collectDriftReports(directory) {
|
|
|
44332
44341
|
const results = [];
|
|
44333
44342
|
const swarmDir = path28.join(directory, ".swarm");
|
|
44334
44343
|
try {
|
|
44335
|
-
if (!
|
|
44344
|
+
if (!existsSync18(swarmDir))
|
|
44336
44345
|
return results;
|
|
44337
|
-
for (const entry of
|
|
44346
|
+
for (const entry of readdirSync6(swarmDir)) {
|
|
44338
44347
|
if (entry.startsWith("drift-report-phase-") && entry.endsWith(".json")) {
|
|
44339
44348
|
try {
|
|
44340
44349
|
results.push(readFileSync9(path28.join(swarmDir, entry), "utf-8"));
|
|
@@ -44347,7 +44356,7 @@ function collectDriftReports(directory) {
|
|
|
44347
44356
|
function collectPendingProposals(directory) {
|
|
44348
44357
|
const results = [];
|
|
44349
44358
|
const insightPath = path28.join(directory, ".swarm", "insight-candidates.jsonl");
|
|
44350
|
-
if (
|
|
44359
|
+
if (existsSync18(insightPath)) {
|
|
44351
44360
|
try {
|
|
44352
44361
|
results.push({
|
|
44353
44362
|
source: "insight-candidates",
|
|
@@ -44357,8 +44366,8 @@ function collectPendingProposals(directory) {
|
|
|
44357
44366
|
}
|
|
44358
44367
|
const proposalsDir = path28.join(directory, ".swarm", "skills", "proposals");
|
|
44359
44368
|
try {
|
|
44360
|
-
if (
|
|
44361
|
-
for (const entry of
|
|
44369
|
+
if (existsSync18(proposalsDir)) {
|
|
44370
|
+
for (const entry of readdirSync6(proposalsDir)) {
|
|
44362
44371
|
if (entry.endsWith(".md") || entry.endsWith(".json")) {
|
|
44363
44372
|
try {
|
|
44364
44373
|
results.push({
|
|
@@ -44512,7 +44521,7 @@ async function runCuratorPostMortem(directory, options = {}) {
|
|
|
44512
44521
|
warnings: [...warnings, "Invalid report path."]
|
|
44513
44522
|
};
|
|
44514
44523
|
}
|
|
44515
|
-
if (!options.force &&
|
|
44524
|
+
if (!options.force && existsSync18(reportPath)) {
|
|
44516
44525
|
return {
|
|
44517
44526
|
success: true,
|
|
44518
44527
|
planId,
|
|
@@ -44575,8 +44584,8 @@ ${llmOutput}`;
|
|
|
44575
44584
|
reportContent = buildDataOnlyReport(planId, planSummary, knowledgeSummary, curatorDigest, proposals, unactionable, retrospectives, driftReports);
|
|
44576
44585
|
}
|
|
44577
44586
|
try {
|
|
44578
|
-
const { mkdirSync:
|
|
44579
|
-
|
|
44587
|
+
const { mkdirSync: mkdirSync10, writeFileSync: writeFileSync7 } = await import("fs");
|
|
44588
|
+
mkdirSync10(path28.dirname(reportPath), { recursive: true });
|
|
44580
44589
|
writeFileSync7(reportPath, reportContent, "utf-8");
|
|
44581
44590
|
} catch (err) {
|
|
44582
44591
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -44666,8 +44675,8 @@ async function copyDirRecursive(src, dest) {
|
|
|
44666
44675
|
const srcEntry = path29.join(src, entry);
|
|
44667
44676
|
const destEntry = path29.join(dest, entry);
|
|
44668
44677
|
try {
|
|
44669
|
-
const
|
|
44670
|
-
if (
|
|
44678
|
+
const stat5 = await fs12.stat(srcEntry);
|
|
44679
|
+
if (stat5.isDirectory()) {
|
|
44671
44680
|
const subCount = await copyDirRecursive(srcEntry, destEntry).catch(() => 0);
|
|
44672
44681
|
count += subCount;
|
|
44673
44682
|
} else {
|
|
@@ -44703,8 +44712,8 @@ function guaranteeAllPlansComplete(planData) {
|
|
|
44703
44712
|
async function handleCloseCommand(directory, args, options = {}) {
|
|
44704
44713
|
const swarmDir = path29.join(directory, ".swarm");
|
|
44705
44714
|
try {
|
|
44706
|
-
const
|
|
44707
|
-
if (
|
|
44715
|
+
const stat5 = fsSync2.lstatSync(swarmDir);
|
|
44716
|
+
if (stat5.isSymbolicLink()) {
|
|
44708
44717
|
return `\u274C Refused: .swarm/ is a symlink or junction. Refusing to operate on a redirected directory for safety.`;
|
|
44709
44718
|
}
|
|
44710
44719
|
} catch (err) {
|
|
@@ -45689,7 +45698,7 @@ var init_curate = __esm(() => {
|
|
|
45689
45698
|
// src/tools/co-change-analyzer.ts
|
|
45690
45699
|
import * as child_process3 from "child_process";
|
|
45691
45700
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
45692
|
-
import { readdir, readFile as readFile11, stat as
|
|
45701
|
+
import { readdir as readdir2, readFile as readFile11, stat as stat5 } from "fs/promises";
|
|
45693
45702
|
import * as path31 from "path";
|
|
45694
45703
|
import { promisify } from "util";
|
|
45695
45704
|
function getExecFileAsync() {
|
|
@@ -45792,7 +45801,7 @@ async function scanSourceFiles(dir) {
|
|
|
45792
45801
|
const results = [];
|
|
45793
45802
|
const skipDirs = new Set(["node_modules", ".swarm", "dist", "build"]);
|
|
45794
45803
|
try {
|
|
45795
|
-
const entries = await
|
|
45804
|
+
const entries = await readdir2(dir, { withFileTypes: true });
|
|
45796
45805
|
for (const entry of entries) {
|
|
45797
45806
|
const fullPath = path31.join(dir, entry.name);
|
|
45798
45807
|
if (entry.isDirectory()) {
|
|
@@ -45840,7 +45849,7 @@ async function getStaticEdges(directory) {
|
|
|
45840
45849
|
for (const ext of extensions) {
|
|
45841
45850
|
const testPath = resolvedPath + ext;
|
|
45842
45851
|
try {
|
|
45843
|
-
const testStat = await
|
|
45852
|
+
const testStat = await stat5(testPath);
|
|
45844
45853
|
if (testStat.isFile()) {
|
|
45845
45854
|
targetFile = testPath;
|
|
45846
45855
|
break;
|
|
@@ -46490,7 +46499,7 @@ function getPluginLockFilePaths() {
|
|
|
46490
46499
|
var init_cache_paths = () => {};
|
|
46491
46500
|
|
|
46492
46501
|
// src/gate-evidence.ts
|
|
46493
|
-
import { mkdirSync as
|
|
46502
|
+
import { mkdirSync as mkdirSync10, readFileSync as readFileSync10, realpathSync as realpathSync3 } from "fs";
|
|
46494
46503
|
function isValidTaskId(taskId) {
|
|
46495
46504
|
return isStrictTaskId(taskId);
|
|
46496
46505
|
}
|
|
@@ -46666,7 +46675,7 @@ var init_gate_bridge = __esm(() => {
|
|
|
46666
46675
|
});
|
|
46667
46676
|
|
|
46668
46677
|
// src/services/version-check.ts
|
|
46669
|
-
import { existsSync as
|
|
46678
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync11, readFileSync as readFileSync11, writeFileSync as writeFileSync7 } from "fs";
|
|
46670
46679
|
import { homedir as homedir5 } from "os";
|
|
46671
46680
|
import { join as join30 } from "path";
|
|
46672
46681
|
function cacheDir() {
|
|
@@ -46680,7 +46689,7 @@ function cacheFile() {
|
|
|
46680
46689
|
function readVersionCache() {
|
|
46681
46690
|
try {
|
|
46682
46691
|
const path34 = cacheFile();
|
|
46683
|
-
if (!
|
|
46692
|
+
if (!existsSync19(path34))
|
|
46684
46693
|
return null;
|
|
46685
46694
|
const raw = readFileSync11(path34, "utf-8");
|
|
46686
46695
|
const parsed = JSON.parse(raw);
|
|
@@ -46720,10 +46729,10 @@ var init_version_check = __esm(() => {
|
|
|
46720
46729
|
});
|
|
46721
46730
|
|
|
46722
46731
|
// src/services/knowledge-diagnostics.ts
|
|
46723
|
-
import { existsSync as
|
|
46732
|
+
import { existsSync as existsSync20 } from "fs";
|
|
46724
46733
|
import { readFile as readFile12 } from "fs/promises";
|
|
46725
46734
|
async function readRawLines(filePath) {
|
|
46726
|
-
if (!
|
|
46735
|
+
if (!existsSync20(filePath))
|
|
46727
46736
|
return { entries: [], corrupt: 0 };
|
|
46728
46737
|
const content = await readFile12(filePath, "utf-8");
|
|
46729
46738
|
const entries = [];
|
|
@@ -46848,7 +46857,7 @@ async function computeKnowledgeDebug(directory) {
|
|
|
46848
46857
|
};
|
|
46849
46858
|
}
|
|
46850
46859
|
async function safeJsonlCount(filePath) {
|
|
46851
|
-
if (!filePath || !
|
|
46860
|
+
if (!filePath || !existsSync20(filePath))
|
|
46852
46861
|
return 0;
|
|
46853
46862
|
try {
|
|
46854
46863
|
const content = await readFile12(filePath, "utf-8");
|
|
@@ -46931,7 +46940,7 @@ var init_knowledge_diagnostics = __esm(() => {
|
|
|
46931
46940
|
|
|
46932
46941
|
// src/services/diagnose-service.ts
|
|
46933
46942
|
import * as child_process4 from "child_process";
|
|
46934
|
-
import { existsSync as
|
|
46943
|
+
import { existsSync as existsSync21, readdirSync as readdirSync7, readFileSync as readFileSync12, statSync as statSync9 } from "fs";
|
|
46935
46944
|
import path34 from "path";
|
|
46936
46945
|
import { fileURLToPath } from "url";
|
|
46937
46946
|
function validateTaskDag(plan) {
|
|
@@ -47148,7 +47157,7 @@ async function checkPlanSync(directory, plan) {
|
|
|
47148
47157
|
}
|
|
47149
47158
|
async function checkConfigBackups(directory) {
|
|
47150
47159
|
try {
|
|
47151
|
-
const files =
|
|
47160
|
+
const files = readdirSync7(directory);
|
|
47152
47161
|
const backupCount = files.filter((f) => /\.opencode-swarm\.yaml\.bak/.test(f)).length;
|
|
47153
47162
|
if (backupCount <= 5) {
|
|
47154
47163
|
return {
|
|
@@ -47179,7 +47188,7 @@ async function checkConfigBackups(directory) {
|
|
|
47179
47188
|
}
|
|
47180
47189
|
async function checkGitRepository(directory) {
|
|
47181
47190
|
try {
|
|
47182
|
-
if (!
|
|
47191
|
+
if (!existsSync21(directory) || !statSync9(directory).isDirectory()) {
|
|
47183
47192
|
return {
|
|
47184
47193
|
name: "Git Repository",
|
|
47185
47194
|
status: "\u274C",
|
|
@@ -47244,7 +47253,7 @@ async function checkSpecStaleness(directory, plan) {
|
|
|
47244
47253
|
}
|
|
47245
47254
|
async function checkConfigParseability(directory) {
|
|
47246
47255
|
const configPath = path34.join(directory, ".opencode/opencode-swarm.json");
|
|
47247
|
-
if (!
|
|
47256
|
+
if (!existsSync21(configPath)) {
|
|
47248
47257
|
return {
|
|
47249
47258
|
name: "Config Parseability",
|
|
47250
47259
|
status: "\u2705",
|
|
@@ -47299,11 +47308,11 @@ async function checkGrammarWasmFiles() {
|
|
|
47299
47308
|
const thisDir = path34.dirname(fileURLToPath(import.meta.url));
|
|
47300
47309
|
const grammarDir = resolveGrammarDir(thisDir);
|
|
47301
47310
|
const missing = [];
|
|
47302
|
-
if (!
|
|
47311
|
+
if (!existsSync21(path34.join(grammarDir, "tree-sitter.wasm"))) {
|
|
47303
47312
|
missing.push("tree-sitter.wasm (core runtime)");
|
|
47304
47313
|
}
|
|
47305
47314
|
for (const file3 of grammarFiles) {
|
|
47306
|
-
if (!
|
|
47315
|
+
if (!existsSync21(path34.join(grammarDir, file3))) {
|
|
47307
47316
|
missing.push(file3);
|
|
47308
47317
|
}
|
|
47309
47318
|
}
|
|
@@ -47322,7 +47331,7 @@ async function checkGrammarWasmFiles() {
|
|
|
47322
47331
|
}
|
|
47323
47332
|
async function checkCheckpointManifest(directory) {
|
|
47324
47333
|
const manifestPath = path34.join(directory, ".swarm/checkpoints.json");
|
|
47325
|
-
if (!
|
|
47334
|
+
if (!existsSync21(manifestPath)) {
|
|
47326
47335
|
return {
|
|
47327
47336
|
name: "Checkpoint Manifest",
|
|
47328
47337
|
status: "\u2705",
|
|
@@ -47374,7 +47383,7 @@ async function checkCheckpointManifest(directory) {
|
|
|
47374
47383
|
}
|
|
47375
47384
|
async function checkEventStreamIntegrity(directory) {
|
|
47376
47385
|
const eventsPath = path34.join(directory, ".swarm/events.jsonl");
|
|
47377
|
-
if (!
|
|
47386
|
+
if (!existsSync21(eventsPath)) {
|
|
47378
47387
|
return {
|
|
47379
47388
|
name: "Event Stream",
|
|
47380
47389
|
status: "\u2705",
|
|
@@ -47415,7 +47424,7 @@ async function checkEventStreamIntegrity(directory) {
|
|
|
47415
47424
|
}
|
|
47416
47425
|
async function checkSteeringDirectives(directory) {
|
|
47417
47426
|
const eventsPath = path34.join(directory, ".swarm/events.jsonl");
|
|
47418
|
-
if (!
|
|
47427
|
+
if (!existsSync21(eventsPath)) {
|
|
47419
47428
|
return {
|
|
47420
47429
|
name: "Steering Directives",
|
|
47421
47430
|
status: "\u2705",
|
|
@@ -47471,7 +47480,7 @@ async function checkCurator(directory) {
|
|
|
47471
47480
|
};
|
|
47472
47481
|
}
|
|
47473
47482
|
const summaryPath = path34.join(directory, ".swarm/curator-summary.json");
|
|
47474
|
-
if (!
|
|
47483
|
+
if (!existsSync21(summaryPath)) {
|
|
47475
47484
|
return {
|
|
47476
47485
|
name: "Curator",
|
|
47477
47486
|
status: "\u2705",
|
|
@@ -47638,7 +47647,7 @@ async function getDiagnoseData(directory) {
|
|
|
47638
47647
|
checks5.push(await checkKnowledgeHealth(directory));
|
|
47639
47648
|
try {
|
|
47640
47649
|
const evidenceDir = path34.join(directory, ".swarm", "evidence");
|
|
47641
|
-
const snapshotFiles =
|
|
47650
|
+
const snapshotFiles = existsSync21(evidenceDir) ? readdirSync7(evidenceDir).filter((f) => f.startsWith("agent-tools-") && f.endsWith(".json")) : [];
|
|
47642
47651
|
if (snapshotFiles.length > 0) {
|
|
47643
47652
|
const latest = snapshotFiles.sort().pop();
|
|
47644
47653
|
checks5.push({
|
|
@@ -47671,7 +47680,7 @@ async function getDiagnoseData(directory) {
|
|
|
47671
47680
|
const cacheRows = [];
|
|
47672
47681
|
for (const cachePath of cachePaths) {
|
|
47673
47682
|
try {
|
|
47674
|
-
if (!
|
|
47683
|
+
if (!existsSync21(cachePath)) {
|
|
47675
47684
|
cacheRows.push(`\u2B1C ${cachePath} \u2014 absent`);
|
|
47676
47685
|
continue;
|
|
47677
47686
|
}
|
|
@@ -50048,7 +50057,7 @@ var init_profiles = __esm(() => {
|
|
|
50048
50057
|
});
|
|
50049
50058
|
|
|
50050
50059
|
// src/lang/detector.ts
|
|
50051
|
-
import { access as
|
|
50060
|
+
import { access as access4, readdir as readdir3 } from "fs/promises";
|
|
50052
50061
|
import { extname as extname3, join as join32 } from "path";
|
|
50053
50062
|
async function detectProjectLanguages(projectDir) {
|
|
50054
50063
|
const detected = new Set;
|
|
@@ -50056,7 +50065,7 @@ async function detectProjectLanguages(projectDir) {
|
|
|
50056
50065
|
let dirEntries;
|
|
50057
50066
|
let entries;
|
|
50058
50067
|
try {
|
|
50059
|
-
dirEntries = await
|
|
50068
|
+
dirEntries = await readdir3(dir, { withFileTypes: true });
|
|
50060
50069
|
entries = dirEntries.map((e) => e.name);
|
|
50061
50070
|
} catch {
|
|
50062
50071
|
return;
|
|
@@ -50072,7 +50081,7 @@ async function detectProjectLanguages(projectDir) {
|
|
|
50072
50081
|
continue;
|
|
50073
50082
|
}
|
|
50074
50083
|
try {
|
|
50075
|
-
await
|
|
50084
|
+
await access4(join32(dir, detectFile));
|
|
50076
50085
|
detected.add(profile.id);
|
|
50077
50086
|
break;
|
|
50078
50087
|
} catch {}
|
|
@@ -50090,7 +50099,7 @@ async function detectProjectLanguages(projectDir) {
|
|
|
50090
50099
|
}
|
|
50091
50100
|
await scanDir(projectDir);
|
|
50092
50101
|
try {
|
|
50093
|
-
const topEntries = await
|
|
50102
|
+
const topEntries = await readdir3(projectDir, { withFileTypes: true });
|
|
50094
50103
|
for (const entry of topEntries) {
|
|
50095
50104
|
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules") {
|
|
50096
50105
|
await scanDir(join32(projectDir, entry.name));
|
|
@@ -52094,7 +52103,7 @@ var init_handoff_service = __esm(() => {
|
|
|
52094
52103
|
});
|
|
52095
52104
|
|
|
52096
52105
|
// src/session/snapshot-writer.ts
|
|
52097
|
-
import { closeSync as closeSync5, fsyncSync as fsyncSync2, mkdirSync as
|
|
52106
|
+
import { closeSync as closeSync5, fsyncSync as fsyncSync2, mkdirSync as mkdirSync14, openSync as openSync5, renameSync as renameSync10 } from "fs";
|
|
52098
52107
|
import * as path38 from "path";
|
|
52099
52108
|
function serializeAgentSession(s) {
|
|
52100
52109
|
const gateLog = {};
|
|
@@ -52202,7 +52211,7 @@ async function writeSnapshot(directory, state) {
|
|
|
52202
52211
|
const content = JSON.stringify(snapshot, null, 2);
|
|
52203
52212
|
const resolvedPath = validateSwarmPath(directory, "session/state.json");
|
|
52204
52213
|
const dir = path38.dirname(resolvedPath);
|
|
52205
|
-
|
|
52214
|
+
mkdirSync14(dir, { recursive: true });
|
|
52206
52215
|
const tempPath = `${resolvedPath}.tmp.${Date.now()}.${Math.random().toString(36).slice(2)}`;
|
|
52207
52216
|
await bunWrite(tempPath, content);
|
|
52208
52217
|
try {
|
|
@@ -52741,8 +52750,8 @@ var KNOWLEDGE_SCHEMA_VERSION = 2;
|
|
|
52741
52750
|
|
|
52742
52751
|
// src/hooks/knowledge-migrator.ts
|
|
52743
52752
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
52744
|
-
import { existsSync as
|
|
52745
|
-
import { mkdir as
|
|
52753
|
+
import { existsSync as existsSync25, readFileSync as readFileSync16 } from "fs";
|
|
52754
|
+
import { mkdir as mkdir13, readFile as readFile13, writeFile as writeFile11 } from "fs/promises";
|
|
52746
52755
|
import * as os8 from "os";
|
|
52747
52756
|
import * as path39 from "path";
|
|
52748
52757
|
async function migrateKnowledgeToExternal(_directory, _config) {
|
|
@@ -52758,7 +52767,7 @@ async function migrateContextToKnowledge(directory, config3) {
|
|
|
52758
52767
|
const sentinelPath = path39.join(directory, ".swarm", ".knowledge-migrated");
|
|
52759
52768
|
const contextPath = path39.join(directory, ".swarm", "context.md");
|
|
52760
52769
|
const knowledgePath = resolveSwarmKnowledgePath(directory);
|
|
52761
|
-
if (
|
|
52770
|
+
if (existsSync25(sentinelPath)) {
|
|
52762
52771
|
return {
|
|
52763
52772
|
migrated: false,
|
|
52764
52773
|
entriesMigrated: 0,
|
|
@@ -52767,7 +52776,7 @@ async function migrateContextToKnowledge(directory, config3) {
|
|
|
52767
52776
|
skippedReason: "sentinel-exists"
|
|
52768
52777
|
};
|
|
52769
52778
|
}
|
|
52770
|
-
if (!
|
|
52779
|
+
if (!existsSync25(contextPath)) {
|
|
52771
52780
|
return {
|
|
52772
52781
|
migrated: false,
|
|
52773
52782
|
entriesMigrated: 0,
|
|
@@ -52859,7 +52868,7 @@ async function migrateHiveKnowledgeLegacy(config3) {
|
|
|
52859
52868
|
const legacyHivePath = _internals29.resolveLegacyHiveKnowledgePath();
|
|
52860
52869
|
const canonicalHivePath = resolveHiveKnowledgePath();
|
|
52861
52870
|
const sentinelPath = path39.join(path39.dirname(canonicalHivePath), ".hive-knowledge-migrated");
|
|
52862
|
-
if (
|
|
52871
|
+
if (existsSync25(sentinelPath)) {
|
|
52863
52872
|
return {
|
|
52864
52873
|
migrated: false,
|
|
52865
52874
|
entriesMigrated: 0,
|
|
@@ -52868,7 +52877,7 @@ async function migrateHiveKnowledgeLegacy(config3) {
|
|
|
52868
52877
|
skippedReason: "sentinel-exists"
|
|
52869
52878
|
};
|
|
52870
52879
|
}
|
|
52871
|
-
if (!
|
|
52880
|
+
if (!existsSync25(legacyHivePath)) {
|
|
52872
52881
|
return {
|
|
52873
52882
|
migrated: false,
|
|
52874
52883
|
entriesMigrated: 0,
|
|
@@ -53070,7 +53079,7 @@ function truncateLesson2(text) {
|
|
|
53070
53079
|
}
|
|
53071
53080
|
function inferProjectName(directory) {
|
|
53072
53081
|
const packageJsonPath = path39.join(directory, "package.json");
|
|
53073
|
-
if (
|
|
53082
|
+
if (existsSync25(packageJsonPath)) {
|
|
53074
53083
|
try {
|
|
53075
53084
|
const pkg = JSON.parse(readFileSync16(packageJsonPath, "utf-8"));
|
|
53076
53085
|
if (pkg.name && typeof pkg.name === "string") {
|
|
@@ -53090,7 +53099,7 @@ async function writeSentinel(sentinelPath, migrated, dropped) {
|
|
|
53090
53099
|
schema_version: 1,
|
|
53091
53100
|
migration_tool: "knowledge-migrator.ts"
|
|
53092
53101
|
};
|
|
53093
|
-
await
|
|
53102
|
+
await mkdir13(path39.dirname(sentinelPath), { recursive: true });
|
|
53094
53103
|
await writeFile11(sentinelPath, JSON.stringify(sentinel, null, 2), "utf-8");
|
|
53095
53104
|
}
|
|
53096
53105
|
function resolveLegacyHiveKnowledgePath() {
|
|
@@ -54278,10 +54287,10 @@ var init_scoring = __esm(() => {
|
|
|
54278
54287
|
|
|
54279
54288
|
// src/memory/local-jsonl-provider.ts
|
|
54280
54289
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
54281
|
-
import { existsSync as
|
|
54290
|
+
import { existsSync as existsSync26 } from "fs";
|
|
54282
54291
|
import {
|
|
54283
54292
|
appendFile as appendFile7,
|
|
54284
|
-
mkdir as
|
|
54293
|
+
mkdir as mkdir14,
|
|
54285
54294
|
readFile as readFile14,
|
|
54286
54295
|
rename as rename7,
|
|
54287
54296
|
writeFile as writeFile12
|
|
@@ -54629,7 +54638,7 @@ function validateLoadedProposals(values, config3) {
|
|
|
54629
54638
|
return { records, invalidCount };
|
|
54630
54639
|
}
|
|
54631
54640
|
async function readJsonl(filePath) {
|
|
54632
|
-
if (!
|
|
54641
|
+
if (!existsSync26(filePath))
|
|
54633
54642
|
return [];
|
|
54634
54643
|
const content = await readFile14(filePath, "utf-8");
|
|
54635
54644
|
const records = [];
|
|
@@ -54685,12 +54694,12 @@ function parseRecallUsageEvent(event) {
|
|
|
54685
54694
|
}
|
|
54686
54695
|
}
|
|
54687
54696
|
async function appendJsonl(filePath, value) {
|
|
54688
|
-
await
|
|
54697
|
+
await mkdir14(path40.dirname(filePath), { recursive: true });
|
|
54689
54698
|
await appendFile7(filePath, `${JSON.stringify(value)}
|
|
54690
54699
|
`, "utf-8");
|
|
54691
54700
|
}
|
|
54692
54701
|
async function writeJsonlAtomic(filePath, values) {
|
|
54693
|
-
await
|
|
54702
|
+
await mkdir14(path40.dirname(filePath), { recursive: true });
|
|
54694
54703
|
const tmp = `${filePath}.tmp.${randomUUID4()}`;
|
|
54695
54704
|
const content = values.map((value) => JSON.stringify(value)).join(`
|
|
54696
54705
|
`) + (values.length > 0 ? `
|
|
@@ -54715,8 +54724,8 @@ var init_prompt_block = __esm(() => {
|
|
|
54715
54724
|
});
|
|
54716
54725
|
|
|
54717
54726
|
// src/memory/jsonl-migration.ts
|
|
54718
|
-
import { existsSync as
|
|
54719
|
-
import { copyFile, mkdir as
|
|
54727
|
+
import { existsSync as existsSync27 } from "fs";
|
|
54728
|
+
import { copyFile as copyFile2, mkdir as mkdir15, readFile as readFile15, stat as stat6, writeFile as writeFile13 } from "fs/promises";
|
|
54720
54729
|
import * as path41 from "path";
|
|
54721
54730
|
function resolveMemoryStorageDir(rootDirectory, config3 = {}) {
|
|
54722
54731
|
const resolved = resolveConfig(config3);
|
|
@@ -54743,25 +54752,25 @@ async function readLegacyJsonl(rootDirectory, config3 = {}) {
|
|
|
54743
54752
|
async function backupLegacyJsonl(rootDirectory, config3 = {}) {
|
|
54744
54753
|
const storageDir = resolveMemoryStorageDir(rootDirectory, config3);
|
|
54745
54754
|
const backupDir = path41.join(storageDir, "backups");
|
|
54746
|
-
await
|
|
54755
|
+
await mkdir15(backupDir, { recursive: true });
|
|
54747
54756
|
const results = [];
|
|
54748
54757
|
for (const filename of ["memories.jsonl", "proposals.jsonl"]) {
|
|
54749
54758
|
const source = path41.join(storageDir, filename);
|
|
54750
|
-
if (!
|
|
54759
|
+
if (!existsSync27(source))
|
|
54751
54760
|
continue;
|
|
54752
54761
|
const backup = path41.join(backupDir, `${filename}.pre-sqlite-migration`);
|
|
54753
|
-
if (
|
|
54762
|
+
if (existsSync27(backup)) {
|
|
54754
54763
|
results.push({ source, backup, created: false });
|
|
54755
54764
|
continue;
|
|
54756
54765
|
}
|
|
54757
|
-
await
|
|
54766
|
+
await copyFile2(source, backup);
|
|
54758
54767
|
results.push({ source, backup, created: true });
|
|
54759
54768
|
}
|
|
54760
54769
|
return results;
|
|
54761
54770
|
}
|
|
54762
54771
|
async function writeJsonlExport(rootDirectory, config3, memories, proposals) {
|
|
54763
54772
|
const exportDir = path41.join(resolveMemoryStorageDir(rootDirectory, config3), "export");
|
|
54764
|
-
await
|
|
54773
|
+
await mkdir15(exportDir, { recursive: true });
|
|
54765
54774
|
const memoriesPath = path41.join(exportDir, "memories.jsonl");
|
|
54766
54775
|
const proposalsPath = path41.join(exportDir, "proposals.jsonl");
|
|
54767
54776
|
await writeFile13(memoriesPath, toJsonl(memories), "utf-8");
|
|
@@ -54770,14 +54779,14 @@ async function writeJsonlExport(rootDirectory, config3, memories, proposals) {
|
|
|
54770
54779
|
}
|
|
54771
54780
|
async function writeMigrationReport(rootDirectory, report, config3 = {}) {
|
|
54772
54781
|
const reportPath = path41.join(resolveMemoryStorageDir(rootDirectory, config3), "migration-report.json");
|
|
54773
|
-
await
|
|
54782
|
+
await mkdir15(path41.dirname(reportPath), { recursive: true });
|
|
54774
54783
|
await writeFile13(reportPath, `${JSON.stringify(report, null, 2)}
|
|
54775
54784
|
`, "utf-8");
|
|
54776
54785
|
return reportPath;
|
|
54777
54786
|
}
|
|
54778
54787
|
async function readMigrationReport(rootDirectory, config3 = {}) {
|
|
54779
54788
|
const reportPath = path41.join(resolveMemoryStorageDir(rootDirectory, config3), "migration-report.json");
|
|
54780
|
-
if (!
|
|
54789
|
+
if (!existsSync27(reportPath))
|
|
54781
54790
|
return null;
|
|
54782
54791
|
try {
|
|
54783
54792
|
return JSON.parse(await readFile15(reportPath, "utf-8"));
|
|
@@ -54791,13 +54800,13 @@ async function getLegacyJsonlFileStatus(rootDirectory, config3 = {}) {
|
|
|
54791
54800
|
for (const file3 of ["memories.jsonl", "proposals.jsonl"]) {
|
|
54792
54801
|
const filePath = path41.join(storageDir, file3);
|
|
54793
54802
|
let sizeBytes = 0;
|
|
54794
|
-
if (
|
|
54795
|
-
sizeBytes = (await
|
|
54803
|
+
if (existsSync27(filePath)) {
|
|
54804
|
+
sizeBytes = (await stat6(filePath)).size;
|
|
54796
54805
|
}
|
|
54797
54806
|
statuses.push({
|
|
54798
54807
|
file: file3,
|
|
54799
54808
|
path: filePath,
|
|
54800
|
-
exists:
|
|
54809
|
+
exists: existsSync27(filePath),
|
|
54801
54810
|
sizeBytes
|
|
54802
54811
|
});
|
|
54803
54812
|
}
|
|
@@ -54878,7 +54887,7 @@ async function readProposalJsonl(filePath, config3) {
|
|
|
54878
54887
|
return { records, invalidRows, totalRows: rows.totalRows };
|
|
54879
54888
|
}
|
|
54880
54889
|
async function readJsonlRows(filePath) {
|
|
54881
|
-
if (!
|
|
54890
|
+
if (!existsSync27(filePath)) {
|
|
54882
54891
|
return { rows: [], invalidRows: [], totalRows: 0 };
|
|
54883
54892
|
}
|
|
54884
54893
|
const content = await readFile15(filePath, "utf-8");
|
|
@@ -54916,7 +54925,7 @@ var init_jsonl_migration = __esm(() => {
|
|
|
54916
54925
|
|
|
54917
54926
|
// src/memory/sqlite-provider.ts
|
|
54918
54927
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
54919
|
-
import { mkdirSync as
|
|
54928
|
+
import { mkdirSync as mkdirSync15 } from "fs";
|
|
54920
54929
|
import { createRequire as createRequire2 } from "module";
|
|
54921
54930
|
import * as path42 from "path";
|
|
54922
54931
|
function loadDatabaseCtor2() {
|
|
@@ -54976,7 +54985,7 @@ class SQLiteMemoryProvider {
|
|
|
54976
54985
|
if (this.initialized)
|
|
54977
54986
|
return;
|
|
54978
54987
|
const dbPath = this.databasePath();
|
|
54979
|
-
|
|
54988
|
+
mkdirSync15(path42.dirname(dbPath), { recursive: true });
|
|
54980
54989
|
const Db = loadDatabaseCtor2();
|
|
54981
54990
|
this.db = new Db(dbPath);
|
|
54982
54991
|
this.db.run("PRAGMA journal_mode = WAL;");
|
|
@@ -56255,7 +56264,7 @@ var init_memory = __esm(() => {
|
|
|
56255
56264
|
});
|
|
56256
56265
|
|
|
56257
56266
|
// src/commands/memory.ts
|
|
56258
|
-
import { existsSync as
|
|
56267
|
+
import { existsSync as existsSync28 } from "fs";
|
|
56259
56268
|
import * as path44 from "path";
|
|
56260
56269
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
56261
56270
|
async function handleMemoryCommand(_directory, _args) {
|
|
@@ -56287,7 +56296,7 @@ async function handleMemoryStatusCommand(directory, _args) {
|
|
|
56287
56296
|
`- Provider: \`${config3.provider}\``,
|
|
56288
56297
|
`- Storage: \`${storageDir}\``,
|
|
56289
56298
|
`- SQLite path: \`${sqlitePath}\``,
|
|
56290
|
-
`- SQLite database exists: \`${
|
|
56299
|
+
`- SQLite database exists: \`${existsSync28(sqlitePath)}\``,
|
|
56291
56300
|
`- Automatic destructive cleanup: \`disabled\``,
|
|
56292
56301
|
"",
|
|
56293
56302
|
"### Legacy JSONL"
|
|
@@ -58086,11 +58095,11 @@ function createRedactedContext(line, findings) {
|
|
|
58086
58095
|
function scanFileForSecrets(filePath) {
|
|
58087
58096
|
const findings = [];
|
|
58088
58097
|
try {
|
|
58089
|
-
const
|
|
58090
|
-
if (
|
|
58098
|
+
const lstat2 = fs19.lstatSync(filePath);
|
|
58099
|
+
if (lstat2.isSymbolicLink()) {
|
|
58091
58100
|
return findings;
|
|
58092
58101
|
}
|
|
58093
|
-
if (
|
|
58102
|
+
if (lstat2.size > MAX_FILE_SIZE_BYTES) {
|
|
58094
58103
|
return findings;
|
|
58095
58104
|
}
|
|
58096
58105
|
let buffer;
|
|
@@ -58178,18 +58187,18 @@ function findScannableFiles(dir, excludeExact, excludeGlobs, scanDir, visited, s
|
|
|
58178
58187
|
stats.skippedDirs++;
|
|
58179
58188
|
continue;
|
|
58180
58189
|
}
|
|
58181
|
-
let
|
|
58190
|
+
let lstat2;
|
|
58182
58191
|
try {
|
|
58183
|
-
|
|
58192
|
+
lstat2 = fs19.lstatSync(fullPath);
|
|
58184
58193
|
} catch {
|
|
58185
58194
|
stats.fileErrors++;
|
|
58186
58195
|
continue;
|
|
58187
58196
|
}
|
|
58188
|
-
if (
|
|
58197
|
+
if (lstat2.isSymbolicLink()) {
|
|
58189
58198
|
stats.symlinkSkipped++;
|
|
58190
58199
|
continue;
|
|
58191
58200
|
}
|
|
58192
|
-
if (
|
|
58201
|
+
if (lstat2.isDirectory()) {
|
|
58193
58202
|
let realPath;
|
|
58194
58203
|
try {
|
|
58195
58204
|
realPath = fs19.realpathSync(fullPath);
|
|
@@ -58207,7 +58216,7 @@ function findScannableFiles(dir, excludeExact, excludeGlobs, scanDir, visited, s
|
|
|
58207
58216
|
}
|
|
58208
58217
|
const subFiles = findScannableFiles(fullPath, excludeExact, excludeGlobs, scanDir, visited, stats);
|
|
58209
58218
|
files.push(...subFiles);
|
|
58210
|
-
} else if (
|
|
58219
|
+
} else if (lstat2.isFile()) {
|
|
58211
58220
|
const ext = path47.extname(fullPath).toLowerCase();
|
|
58212
58221
|
if (!DEFAULT_EXCLUDE_EXTENSIONS.has(ext)) {
|
|
58213
58222
|
files.push(fullPath);
|
|
@@ -58538,8 +58547,8 @@ var init_secretscan = __esm(() => {
|
|
|
58538
58547
|
break;
|
|
58539
58548
|
const fileFindings = scanFileForSecrets(filePath);
|
|
58540
58549
|
try {
|
|
58541
|
-
const
|
|
58542
|
-
if (
|
|
58550
|
+
const stat7 = fs19.statSync(filePath);
|
|
58551
|
+
if (stat7.size > MAX_FILE_SIZE_BYTES) {
|
|
58543
58552
|
skippedFiles++;
|
|
58544
58553
|
continue;
|
|
58545
58554
|
}
|
|
@@ -59349,8 +59358,8 @@ function sharedTrailingSegments(a, b) {
|
|
|
59349
59358
|
function isCacheStale(impactMap, generatedAtMs) {
|
|
59350
59359
|
for (const sourcePath of Object.keys(impactMap)) {
|
|
59351
59360
|
try {
|
|
59352
|
-
const
|
|
59353
|
-
if (
|
|
59361
|
+
const stat7 = fs23.statSync(sourcePath);
|
|
59362
|
+
if (stat7.mtimeMs > generatedAtMs) {
|
|
59354
59363
|
return true;
|
|
59355
59364
|
}
|
|
59356
59365
|
} catch {
|
|
@@ -60651,8 +60660,8 @@ function manifestHash(dir) {
|
|
|
60651
60660
|
if (!entries.has(name))
|
|
60652
60661
|
continue;
|
|
60653
60662
|
try {
|
|
60654
|
-
const
|
|
60655
|
-
parts.push(`${name}:${
|
|
60663
|
+
const stat7 = fs28.statSync(path56.join(dir, name));
|
|
60664
|
+
parts.push(`${name}:${stat7.size}:${stat7.mtimeMs}:${stat7.ino}`);
|
|
60656
60665
|
} catch {}
|
|
60657
60666
|
}
|
|
60658
60667
|
return parts.join("|");
|
|
@@ -65133,8 +65142,8 @@ async function countProposals(directory) {
|
|
|
65133
65142
|
const proposalsDir = validateSwarmPath(directory, "skills/proposals");
|
|
65134
65143
|
if (!fsSync3.existsSync(proposalsDir))
|
|
65135
65144
|
return 0;
|
|
65136
|
-
const { readdir:
|
|
65137
|
-
const entries = await
|
|
65145
|
+
const { readdir: readdir5 } = await import("fs/promises");
|
|
65146
|
+
const entries = await readdir5(proposalsDir);
|
|
65138
65147
|
return entries.filter((f) => f.endsWith(".md")).length;
|
|
65139
65148
|
} catch {
|
|
65140
65149
|
return 0;
|
|
@@ -66241,7 +66250,7 @@ Showing full help:
|
|
|
66241
66250
|
}
|
|
66242
66251
|
async function handleModeCommandWithBundledSkills(ctx, handler) {
|
|
66243
66252
|
if (ctx.packageRoot) {
|
|
66244
|
-
|
|
66253
|
+
await syncBundledProjectSkillsIfMissingAsync(ctx.directory, ctx.packageRoot);
|
|
66245
66254
|
}
|
|
66246
66255
|
return Promise.resolve(handler(ctx.directory, ctx.args));
|
|
66247
66256
|
}
|
|
@@ -66441,6 +66450,13 @@ var init_registry = __esm(() => {
|
|
|
66441
66450
|
description: "Run tool registration coherence check",
|
|
66442
66451
|
category: "diagnostics"
|
|
66443
66452
|
},
|
|
66453
|
+
"doctor-tools": {
|
|
66454
|
+
handler: (ctx) => handleDoctorToolsCommand(ctx.directory, ctx.args),
|
|
66455
|
+
description: "Run tool registration coherence check",
|
|
66456
|
+
category: "diagnostics",
|
|
66457
|
+
aliasOf: "doctor tools",
|
|
66458
|
+
deprecated: true
|
|
66459
|
+
},
|
|
66444
66460
|
diagnose: {
|
|
66445
66461
|
handler: (ctx) => handleDiagnoseCommand(ctx.directory, ctx.args),
|
|
66446
66462
|
description: "Run health check on swarm state",
|