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/index.js
CHANGED
|
@@ -69,7 +69,7 @@ var package_default;
|
|
|
69
69
|
var init_package = __esm(() => {
|
|
70
70
|
package_default = {
|
|
71
71
|
name: "opencode-swarm",
|
|
72
|
-
version: "7.76.
|
|
72
|
+
version: "7.76.2",
|
|
73
73
|
description: "Architect-centric agentic swarm plugin for OpenCode - hub-and-spoke orchestration with SME consultation, code generation, and QA review",
|
|
74
74
|
main: "dist/index.js",
|
|
75
75
|
types: "dist/index.d.ts",
|
|
@@ -17016,43 +17016,56 @@ var init_warning_buffer = __esm(() => {
|
|
|
17016
17016
|
|
|
17017
17017
|
// src/config/bundled-skills.ts
|
|
17018
17018
|
import * as fs3 from "node:fs";
|
|
17019
|
+
import * as fsp from "node:fs/promises";
|
|
17019
17020
|
import * as path2 from "node:path";
|
|
17020
|
-
function
|
|
17021
|
+
function getSyncCacheKey(projectDirectory, packageRoot) {
|
|
17022
|
+
return `${path2.resolve(projectDirectory)}\x00${path2.resolve(packageRoot)}`;
|
|
17023
|
+
}
|
|
17024
|
+
function warnBundledSkillSyncFailure(err2) {
|
|
17025
|
+
const message = err2 instanceof Error ? err2.message : String(err2);
|
|
17026
|
+
console.warn(`[opencode-swarm] Could not install bundled project skills; continuing without sync: ${message}`);
|
|
17027
|
+
}
|
|
17028
|
+
async function isSymbolicLinkAsync(p) {
|
|
17021
17029
|
try {
|
|
17022
|
-
return
|
|
17030
|
+
return (await fsp.lstat(p)).isSymbolicLink();
|
|
17023
17031
|
} catch {
|
|
17024
17032
|
return false;
|
|
17025
17033
|
}
|
|
17026
17034
|
}
|
|
17027
|
-
function
|
|
17035
|
+
async function ensureNotSymlinkedDirectoryAsync(p) {
|
|
17028
17036
|
try {
|
|
17029
|
-
const
|
|
17030
|
-
return
|
|
17037
|
+
const stat3 = await fsp.lstat(p);
|
|
17038
|
+
return stat3.isDirectory() && !stat3.isSymbolicLink();
|
|
17031
17039
|
} catch (err2) {
|
|
17032
17040
|
return err2.code === "ENOENT";
|
|
17033
17041
|
}
|
|
17034
17042
|
}
|
|
17035
|
-
function
|
|
17036
|
-
|
|
17043
|
+
async function pathExistsAsync(p) {
|
|
17044
|
+
try {
|
|
17045
|
+
await fsp.access(p);
|
|
17046
|
+
return true;
|
|
17047
|
+
} catch {
|
|
17048
|
+
return false;
|
|
17049
|
+
}
|
|
17037
17050
|
}
|
|
17038
|
-
function
|
|
17051
|
+
async function collectBundledSkillFilesBoundedAsync(sourceDir, state, relativeDir = "") {
|
|
17039
17052
|
const currentSource = path2.join(sourceDir, relativeDir);
|
|
17040
|
-
const entries =
|
|
17053
|
+
const entries = await fsp.readdir(currentSource, { withFileTypes: true });
|
|
17041
17054
|
const files = [];
|
|
17042
17055
|
for (const entry of entries) {
|
|
17043
17056
|
const relativeEntry = path2.join(relativeDir, entry.name);
|
|
17044
17057
|
const sourcePath = path2.join(sourceDir, relativeEntry);
|
|
17045
|
-
if (entry.isSymbolicLink() ||
|
|
17058
|
+
if (entry.isSymbolicLink() || await isSymbolicLinkAsync(sourcePath))
|
|
17046
17059
|
continue;
|
|
17047
17060
|
if (entry.isDirectory()) {
|
|
17048
|
-
files.push(...
|
|
17061
|
+
files.push(...await collectBundledSkillFilesBoundedAsync(sourceDir, state, relativeEntry));
|
|
17049
17062
|
continue;
|
|
17050
17063
|
}
|
|
17051
17064
|
if (!entry.isFile())
|
|
17052
17065
|
continue;
|
|
17053
|
-
const
|
|
17066
|
+
const stat3 = await fsp.stat(sourcePath);
|
|
17054
17067
|
const nextFiles = state.files + 1;
|
|
17055
|
-
const nextBytes = state.bytes +
|
|
17068
|
+
const nextBytes = state.bytes + stat3.size;
|
|
17056
17069
|
if (nextFiles > MAX_SKILL_FILES || nextBytes > MAX_SKILL_BYTES) {
|
|
17057
17070
|
throw new Error("bundled skill package exceeds copy bounds");
|
|
17058
17071
|
}
|
|
@@ -17062,7 +17075,7 @@ function collectBundledSkillFilesBounded(sourceDir, state, relativeDir = "") {
|
|
|
17062
17075
|
}
|
|
17063
17076
|
return files;
|
|
17064
17077
|
}
|
|
17065
|
-
function
|
|
17078
|
+
async function rollbackCopiedFilesAsync(copiedFiles, destDir) {
|
|
17066
17079
|
const safeDestDir = path2.resolve(destDir);
|
|
17067
17080
|
const dirs = new Set;
|
|
17068
17081
|
for (const copiedFile of copiedFiles) {
|
|
@@ -17071,7 +17084,7 @@ function rollbackCopiedFiles(copiedFiles, destDir) {
|
|
|
17071
17084
|
if (relative2.startsWith("..") || path2.isAbsolute(relative2))
|
|
17072
17085
|
continue;
|
|
17073
17086
|
try {
|
|
17074
|
-
|
|
17087
|
+
await fsp.rm(resolvedFile, { force: true });
|
|
17075
17088
|
} catch {}
|
|
17076
17089
|
dirs.add(path2.dirname(resolvedFile));
|
|
17077
17090
|
}
|
|
@@ -17080,12 +17093,12 @@ function rollbackCopiedFiles(copiedFiles, destDir) {
|
|
|
17080
17093
|
if (relative2.startsWith("..") || path2.isAbsolute(relative2))
|
|
17081
17094
|
continue;
|
|
17082
17095
|
try {
|
|
17083
|
-
|
|
17096
|
+
await fsp.rmdir(dir);
|
|
17084
17097
|
} catch {}
|
|
17085
17098
|
}
|
|
17086
17099
|
}
|
|
17087
|
-
function
|
|
17088
|
-
const files =
|
|
17100
|
+
async function copyBundledDirectoryBoundedAsync(sourceDir, destDir) {
|
|
17101
|
+
const files = await collectBundledSkillFilesBoundedAsync(sourceDir, {
|
|
17089
17102
|
files: 0,
|
|
17090
17103
|
bytes: 0
|
|
17091
17104
|
});
|
|
@@ -17094,9 +17107,9 @@ function copyBundledDirectoryBounded(sourceDir, destDir) {
|
|
|
17094
17107
|
for (const file2 of files) {
|
|
17095
17108
|
const sourcePath = path2.join(sourceDir, file2.relativePath);
|
|
17096
17109
|
const destPath = path2.join(destDir, file2.relativePath);
|
|
17097
|
-
|
|
17110
|
+
await fsp.mkdir(path2.dirname(destPath), { recursive: true });
|
|
17098
17111
|
try {
|
|
17099
|
-
|
|
17112
|
+
await fsp.copyFile(sourcePath, destPath, fs3.constants.COPYFILE_EXCL);
|
|
17100
17113
|
copiedFiles.push(destPath);
|
|
17101
17114
|
} catch (err2) {
|
|
17102
17115
|
if (err2.code !== "EEXIST")
|
|
@@ -17104,15 +17117,11 @@ function copyBundledDirectoryBounded(sourceDir, destDir) {
|
|
|
17104
17117
|
}
|
|
17105
17118
|
}
|
|
17106
17119
|
} catch (err2) {
|
|
17107
|
-
|
|
17120
|
+
await rollbackCopiedFilesAsync(copiedFiles, destDir);
|
|
17108
17121
|
throw err2;
|
|
17109
17122
|
}
|
|
17110
17123
|
}
|
|
17111
|
-
function
|
|
17112
|
-
const message = err2 instanceof Error ? err2.message : String(err2);
|
|
17113
|
-
console.warn(`[opencode-swarm] Could not install bundled project skills; continuing without sync: ${message}`);
|
|
17114
|
-
}
|
|
17115
|
-
function syncBundledProjectSkillsIfMissing(projectDirectory, packageRoot, quiet = false) {
|
|
17124
|
+
async function syncBundledProjectSkillsIfMissingAsync(projectDirectory, packageRoot, quiet = false) {
|
|
17116
17125
|
try {
|
|
17117
17126
|
const cacheKey = getSyncCacheKey(projectDirectory, packageRoot);
|
|
17118
17127
|
if (syncedProjectSkillTargets.has(cacheKey))
|
|
@@ -17121,23 +17130,23 @@ function syncBundledProjectSkillsIfMissing(projectDirectory, packageRoot, quiet
|
|
|
17121
17130
|
const opencodeDir = path2.join(projectDirectory, ".opencode");
|
|
17122
17131
|
const skillsDir = path2.join(opencodeDir, "skills");
|
|
17123
17132
|
let sawBundledSource = false;
|
|
17124
|
-
if (!
|
|
17133
|
+
if (!await ensureNotSymlinkedDirectoryAsync(opencodeDir))
|
|
17125
17134
|
return;
|
|
17126
|
-
if (!
|
|
17135
|
+
if (!await ensureNotSymlinkedDirectoryAsync(skillsDir))
|
|
17127
17136
|
return;
|
|
17128
17137
|
for (const slug of BUNDLED_PROJECT_SKILLS) {
|
|
17129
17138
|
const sourceDir = path2.join(sourceRoot, slug);
|
|
17130
17139
|
const sourceSkill = path2.join(sourceDir, "SKILL.md");
|
|
17131
17140
|
const destDir = path2.join(skillsDir, slug);
|
|
17132
17141
|
const destSkill = path2.join(destDir, "SKILL.md");
|
|
17133
|
-
if (!
|
|
17142
|
+
if (!await pathExistsAsync(sourceSkill))
|
|
17134
17143
|
continue;
|
|
17135
17144
|
sawBundledSource = true;
|
|
17136
|
-
if (
|
|
17145
|
+
if (await pathExistsAsync(destSkill))
|
|
17137
17146
|
continue;
|
|
17138
|
-
if (!
|
|
17147
|
+
if (!await ensureNotSymlinkedDirectoryAsync(destDir))
|
|
17139
17148
|
continue;
|
|
17140
|
-
|
|
17149
|
+
await copyBundledDirectoryBoundedAsync(sourceDir, destDir);
|
|
17141
17150
|
if (!quiet) {
|
|
17142
17151
|
console.warn(`[opencode-swarm] Installed bundled skill .opencode/skills/${slug}/SKILL.md for first-class /swarm command support`);
|
|
17143
17152
|
}
|
|
@@ -17918,21 +17927,21 @@ function hash2(content) {
|
|
|
17918
17927
|
return createHash("sha256").update(content, "utf-8").digest("hex");
|
|
17919
17928
|
}
|
|
17920
17929
|
function readTextBounded(absPath) {
|
|
17921
|
-
const
|
|
17922
|
-
if (!
|
|
17930
|
+
const stat4 = fs5.lstatSync(absPath);
|
|
17931
|
+
if (!stat4.isFile() || stat4.size > MAX_SOURCE_BYTES) {
|
|
17923
17932
|
return null;
|
|
17924
17933
|
}
|
|
17925
17934
|
return fs5.readFileSync(absPath, "utf-8");
|
|
17926
17935
|
}
|
|
17927
17936
|
function fileArtifact(root, absPath) {
|
|
17928
17937
|
try {
|
|
17929
|
-
const
|
|
17930
|
-
if (!
|
|
17938
|
+
const stat4 = fs5.lstatSync(absPath);
|
|
17939
|
+
if (!stat4.isFile() || stat4.size > MAX_SOURCE_BYTES)
|
|
17931
17940
|
return null;
|
|
17932
17941
|
return {
|
|
17933
17942
|
relPath: toPosix(path6.relative(root, absPath)),
|
|
17934
|
-
bytes:
|
|
17935
|
-
mtimeMs:
|
|
17943
|
+
bytes: stat4.size,
|
|
17944
|
+
mtimeMs: stat4.mtimeMs
|
|
17936
17945
|
};
|
|
17937
17946
|
} catch {
|
|
17938
17947
|
return null;
|
|
@@ -18223,14 +18232,14 @@ function readEffectiveSpecSync(directory) {
|
|
|
18223
18232
|
const root = path6.resolve(directory);
|
|
18224
18233
|
const swSpecPath = path6.join(root, SWARM_SPEC_REL);
|
|
18225
18234
|
try {
|
|
18226
|
-
const
|
|
18227
|
-
if (
|
|
18235
|
+
const stat4 = fs5.lstatSync(swSpecPath);
|
|
18236
|
+
if (stat4.isFile() && stat4.size <= MAX_SPEC_BYTES) {
|
|
18228
18237
|
const content = fs5.readFileSync(swSpecPath, "utf-8");
|
|
18229
18238
|
return {
|
|
18230
18239
|
source: "swarm",
|
|
18231
18240
|
content,
|
|
18232
18241
|
hash: hash2(content),
|
|
18233
|
-
mtime:
|
|
18242
|
+
mtime: stat4.mtime.toISOString(),
|
|
18234
18243
|
sourcePaths: [toPosix(SWARM_SPEC_REL)],
|
|
18235
18244
|
warnings: []
|
|
18236
18245
|
};
|
|
@@ -18769,9 +18778,9 @@ var init_ledger = __esm(() => {
|
|
|
18769
18778
|
|
|
18770
18779
|
// src/plan/manager.ts
|
|
18771
18780
|
import {
|
|
18772
|
-
copyFileSync
|
|
18773
|
-
existsSync as
|
|
18774
|
-
readdirSync as
|
|
18781
|
+
copyFileSync,
|
|
18782
|
+
existsSync as existsSync5,
|
|
18783
|
+
readdirSync as readdirSync2,
|
|
18775
18784
|
renameSync as renameSync4,
|
|
18776
18785
|
unlinkSync
|
|
18777
18786
|
} from "node:fs";
|
|
@@ -19215,7 +19224,7 @@ async function savePlan(directory, plan, options) {
|
|
|
19215
19224
|
const oldLedgerPath = path8.join(swarmDir2, "plan-ledger.jsonl");
|
|
19216
19225
|
const oldLedgerBackupPath = path8.join(swarmDir2, `plan-ledger.backup-${Date.now()}-${Math.floor(Math.random() * 1e9)}.jsonl`);
|
|
19217
19226
|
let backupExists = false;
|
|
19218
|
-
if (
|
|
19227
|
+
if (existsSync5(oldLedgerPath)) {
|
|
19219
19228
|
try {
|
|
19220
19229
|
renameSync4(oldLedgerPath, oldLedgerBackupPath);
|
|
19221
19230
|
backupExists = true;
|
|
@@ -19232,15 +19241,15 @@ async function savePlan(directory, plan, options) {
|
|
|
19232
19241
|
const errorMessage = String(initErr);
|
|
19233
19242
|
if (errorMessage.includes("already initialized")) {
|
|
19234
19243
|
try {
|
|
19235
|
-
if (
|
|
19244
|
+
if (existsSync5(oldLedgerBackupPath))
|
|
19236
19245
|
unlinkSync(oldLedgerBackupPath);
|
|
19237
19246
|
} catch {}
|
|
19238
19247
|
} else {
|
|
19239
|
-
if (
|
|
19248
|
+
if (existsSync5(oldLedgerBackupPath)) {
|
|
19240
19249
|
try {
|
|
19241
19250
|
renameSync4(oldLedgerBackupPath, oldLedgerPath);
|
|
19242
19251
|
} catch {
|
|
19243
|
-
|
|
19252
|
+
copyFileSync(oldLedgerBackupPath, oldLedgerPath);
|
|
19244
19253
|
try {
|
|
19245
19254
|
unlinkSync(oldLedgerBackupPath);
|
|
19246
19255
|
} catch {}
|
|
@@ -19258,19 +19267,19 @@ async function savePlan(directory, plan, options) {
|
|
|
19258
19267
|
} catch (renameErr) {
|
|
19259
19268
|
warn(`[savePlan] Could not archive old ledger (rename failed: ${renameErr instanceof Error ? renameErr.message : String(renameErr)}). Old ledger may still exist at ${oldLedgerBackupPath}.`);
|
|
19260
19269
|
try {
|
|
19261
|
-
if (
|
|
19270
|
+
if (existsSync5(oldLedgerBackupPath))
|
|
19262
19271
|
unlinkSync(oldLedgerBackupPath);
|
|
19263
19272
|
} catch {}
|
|
19264
19273
|
}
|
|
19265
19274
|
} else if (!initSucceeded && backupExists) {
|
|
19266
19275
|
try {
|
|
19267
|
-
if (
|
|
19276
|
+
if (existsSync5(oldLedgerBackupPath))
|
|
19268
19277
|
unlinkSync(oldLedgerBackupPath);
|
|
19269
19278
|
} catch {}
|
|
19270
19279
|
}
|
|
19271
19280
|
const MAX_ARCHIVED_SIBLINGS = 5;
|
|
19272
19281
|
try {
|
|
19273
|
-
const allFiles =
|
|
19282
|
+
const allFiles = readdirSync2(swarmDir2);
|
|
19274
19283
|
const archivedSiblings = allFiles.filter((f) => f.startsWith("plan-ledger.archived-") && f.endsWith(".jsonl")).sort();
|
|
19275
19284
|
if (archivedSiblings.length > MAX_ARCHIVED_SIBLINGS) {
|
|
19276
19285
|
const toRemove = archivedSiblings.slice(0, archivedSiblings.length - MAX_ARCHIVED_SIBLINGS);
|
|
@@ -20067,11 +20076,11 @@ function handleAgentsCommand(agents, guardrails) {
|
|
|
20067
20076
|
const temp = agent.config.temperature !== undefined ? agent.config.temperature.toString() : "default";
|
|
20068
20077
|
const tools = agent.config.tools || {};
|
|
20069
20078
|
const isReadOnly = tools.write === false || tools.edit === false;
|
|
20070
|
-
const
|
|
20079
|
+
const access3 = isReadOnly ? "\uD83D\uDD12 read-only" : "✏️ read-write";
|
|
20071
20080
|
const desc = agent.description || agent.config.description || "";
|
|
20072
20081
|
const hasCustomProfile = guardrails?.profiles?.[key] !== undefined;
|
|
20073
20082
|
const profileIndicator = hasCustomProfile ? " | ⚡ custom limits" : "";
|
|
20074
|
-
lines.push(`- **${key}** | model: \`${model}\` | temp: ${temp} | ${
|
|
20083
|
+
lines.push(`- **${key}** | model: \`${model}\` | temp: ${temp} | ${access3}${profileIndicator}`);
|
|
20075
20084
|
if (desc) {
|
|
20076
20085
|
lines.push(` ${desc}`);
|
|
20077
20086
|
}
|
|
@@ -20679,8 +20688,8 @@ GFS4: `);
|
|
|
20679
20688
|
}
|
|
20680
20689
|
var fs$copyFile = fs8.copyFile;
|
|
20681
20690
|
if (fs$copyFile)
|
|
20682
|
-
fs8.copyFile =
|
|
20683
|
-
function
|
|
20691
|
+
fs8.copyFile = copyFile2;
|
|
20692
|
+
function copyFile2(src, dest, flags2, cb) {
|
|
20684
20693
|
if (typeof flags2 === "function") {
|
|
20685
20694
|
cb = flags2;
|
|
20686
20695
|
flags2 = 0;
|
|
@@ -20698,9 +20707,9 @@ GFS4: `);
|
|
|
20698
20707
|
}
|
|
20699
20708
|
}
|
|
20700
20709
|
var fs$readdir = fs8.readdir;
|
|
20701
|
-
fs8.readdir =
|
|
20710
|
+
fs8.readdir = readdir2;
|
|
20702
20711
|
var noReaddirOptionVersions = /^v[0-5]\./;
|
|
20703
|
-
function
|
|
20712
|
+
function readdir2(path9, options, cb) {
|
|
20704
20713
|
if (typeof options === "function")
|
|
20705
20714
|
cb = options, options = null;
|
|
20706
20715
|
var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path10, options2, cb2, startTime) {
|
|
@@ -21289,11 +21298,11 @@ var require_mtime_precision = __commonJS((exports, module2) => {
|
|
|
21289
21298
|
function probe(file2, fs7, callback) {
|
|
21290
21299
|
const cachedPrecision = fs7[cacheSymbol];
|
|
21291
21300
|
if (cachedPrecision) {
|
|
21292
|
-
return fs7.stat(file2, (err2,
|
|
21301
|
+
return fs7.stat(file2, (err2, stat4) => {
|
|
21293
21302
|
if (err2) {
|
|
21294
21303
|
return callback(err2);
|
|
21295
21304
|
}
|
|
21296
|
-
callback(null,
|
|
21305
|
+
callback(null, stat4.mtime, cachedPrecision);
|
|
21297
21306
|
});
|
|
21298
21307
|
}
|
|
21299
21308
|
const mtime = new Date(Math.ceil(Date.now() / 1000) * 1000 + 5);
|
|
@@ -21301,13 +21310,13 @@ var require_mtime_precision = __commonJS((exports, module2) => {
|
|
|
21301
21310
|
if (err2) {
|
|
21302
21311
|
return callback(err2);
|
|
21303
21312
|
}
|
|
21304
|
-
fs7.stat(file2, (err3,
|
|
21313
|
+
fs7.stat(file2, (err3, stat4) => {
|
|
21305
21314
|
if (err3) {
|
|
21306
21315
|
return callback(err3);
|
|
21307
21316
|
}
|
|
21308
|
-
const precision =
|
|
21317
|
+
const precision = stat4.mtime.getTime() % 1000 === 0 ? "s" : "ms";
|
|
21309
21318
|
Object.defineProperty(fs7, cacheSymbol, { value: precision });
|
|
21310
|
-
callback(null,
|
|
21319
|
+
callback(null, stat4.mtime, precision);
|
|
21311
21320
|
});
|
|
21312
21321
|
});
|
|
21313
21322
|
}
|
|
@@ -21357,14 +21366,14 @@ var require_lockfile = __commonJS((exports, module2) => {
|
|
|
21357
21366
|
if (options.stale <= 0) {
|
|
21358
21367
|
return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file: file2 }));
|
|
21359
21368
|
}
|
|
21360
|
-
options.fs.stat(lockfilePath, (err3,
|
|
21369
|
+
options.fs.stat(lockfilePath, (err3, stat4) => {
|
|
21361
21370
|
if (err3) {
|
|
21362
21371
|
if (err3.code === "ENOENT") {
|
|
21363
21372
|
return acquireLock(file2, { ...options, stale: 0 }, callback);
|
|
21364
21373
|
}
|
|
21365
21374
|
return callback(err3);
|
|
21366
21375
|
}
|
|
21367
|
-
if (!isLockStale(
|
|
21376
|
+
if (!isLockStale(stat4, options)) {
|
|
21368
21377
|
return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file: file2 }));
|
|
21369
21378
|
}
|
|
21370
21379
|
removeLock(file2, options, (err4) => {
|
|
@@ -21376,8 +21385,8 @@ var require_lockfile = __commonJS((exports, module2) => {
|
|
|
21376
21385
|
});
|
|
21377
21386
|
});
|
|
21378
21387
|
}
|
|
21379
|
-
function isLockStale(
|
|
21380
|
-
return
|
|
21388
|
+
function isLockStale(stat4, options) {
|
|
21389
|
+
return stat4.mtime.getTime() < Date.now() - options.stale;
|
|
21381
21390
|
}
|
|
21382
21391
|
function removeLock(file2, options, callback) {
|
|
21383
21392
|
options.fs.rmdir(getLockFile(file2, options), (err2) => {
|
|
@@ -21395,7 +21404,7 @@ var require_lockfile = __commonJS((exports, module2) => {
|
|
|
21395
21404
|
lock2.updateDelay = lock2.updateDelay || options.update;
|
|
21396
21405
|
lock2.updateTimeout = setTimeout(() => {
|
|
21397
21406
|
lock2.updateTimeout = null;
|
|
21398
|
-
options.fs.stat(lock2.lockfilePath, (err2,
|
|
21407
|
+
options.fs.stat(lock2.lockfilePath, (err2, stat4) => {
|
|
21399
21408
|
const isOverThreshold = lock2.lastUpdate + options.stale < Date.now();
|
|
21400
21409
|
if (err2) {
|
|
21401
21410
|
if (err2.code === "ENOENT" || isOverThreshold) {
|
|
@@ -21404,7 +21413,7 @@ var require_lockfile = __commonJS((exports, module2) => {
|
|
|
21404
21413
|
lock2.updateDelay = 1000;
|
|
21405
21414
|
return updateLock(file2, options);
|
|
21406
21415
|
}
|
|
21407
|
-
const isMtimeOurs = lock2.mtime.getTime() ===
|
|
21416
|
+
const isMtimeOurs = lock2.mtime.getTime() === stat4.mtime.getTime();
|
|
21408
21417
|
if (!isMtimeOurs) {
|
|
21409
21418
|
return setLockAsCompromised(file2, lock2, Object.assign(new Error("Unable to update lock within the stale threshold"), { code: "ECOMPROMISED" }));
|
|
21410
21419
|
}
|
|
@@ -21522,11 +21531,11 @@ var require_lockfile = __commonJS((exports, module2) => {
|
|
|
21522
21531
|
if (err2) {
|
|
21523
21532
|
return callback(err2);
|
|
21524
21533
|
}
|
|
21525
|
-
options.fs.stat(getLockFile(file3, options), (err3,
|
|
21534
|
+
options.fs.stat(getLockFile(file3, options), (err3, stat4) => {
|
|
21526
21535
|
if (err3) {
|
|
21527
21536
|
return err3.code === "ENOENT" ? callback(null, false) : callback(err3);
|
|
21528
21537
|
}
|
|
21529
|
-
return callback(null, !isLockStale(
|
|
21538
|
+
return callback(null, !isLockStale(stat4, options));
|
|
21530
21539
|
});
|
|
21531
21540
|
});
|
|
21532
21541
|
}
|
|
@@ -21733,8 +21742,8 @@ function listActiveLocks(directory) {
|
|
|
21733
21742
|
continue;
|
|
21734
21743
|
const lockPath = path9.join(locksDir, file2);
|
|
21735
21744
|
try {
|
|
21736
|
-
const
|
|
21737
|
-
if (
|
|
21745
|
+
const stat4 = fs7.statSync(lockPath);
|
|
21746
|
+
if (stat4.isFile()) {
|
|
21738
21747
|
const plLockDir = `${lockPath}.lock`;
|
|
21739
21748
|
if (fs7.existsSync(plLockDir)) {
|
|
21740
21749
|
const metaPath = getMetaPath(lockPath);
|
|
@@ -22013,11 +22022,11 @@ var init_task_id = __esm(() => {
|
|
|
22013
22022
|
|
|
22014
22023
|
// src/evidence/manager.ts
|
|
22015
22024
|
import {
|
|
22016
|
-
mkdirSync as
|
|
22017
|
-
readdirSync as
|
|
22025
|
+
mkdirSync as mkdirSync5,
|
|
22026
|
+
readdirSync as readdirSync4,
|
|
22018
22027
|
realpathSync,
|
|
22019
|
-
rmSync
|
|
22020
|
-
statSync as
|
|
22028
|
+
rmSync,
|
|
22029
|
+
statSync as statSync5
|
|
22021
22030
|
} from "node:fs";
|
|
22022
22031
|
import * as fs8 from "node:fs/promises";
|
|
22023
22032
|
import * as path10 from "node:path";
|
|
@@ -22046,11 +22055,11 @@ function validateProjectRoot(directory) {
|
|
|
22046
22055
|
break;
|
|
22047
22056
|
const parentSwarm = path10.join(parent, ".swarm");
|
|
22048
22057
|
try {
|
|
22049
|
-
if (
|
|
22058
|
+
if (statSync5(parentSwarm).isDirectory()) {
|
|
22050
22059
|
let hasProjectIndicator = false;
|
|
22051
22060
|
for (const indicator of PROJECT_INDICATORS) {
|
|
22052
22061
|
try {
|
|
22053
|
-
const indicatorStat =
|
|
22062
|
+
const indicatorStat = statSync5(path10.join(parent, indicator));
|
|
22054
22063
|
if (indicatorStat.isFile() || indicatorStat.isDirectory()) {
|
|
22055
22064
|
hasProjectIndicator = true;
|
|
22056
22065
|
break;
|
|
@@ -22124,14 +22133,14 @@ async function saveEvidence(directory, taskId, evidence) {
|
|
|
22124
22133
|
if (bundleJson.length > EVIDENCE_MAX_JSON_BYTES) {
|
|
22125
22134
|
throw new Error(`Evidence bundle size (${bundleJson.length} bytes) exceeds maximum (${EVIDENCE_MAX_JSON_BYTES} bytes)`);
|
|
22126
22135
|
}
|
|
22127
|
-
|
|
22136
|
+
mkdirSync5(evidenceDir, { recursive: true });
|
|
22128
22137
|
const tempPath = path10.join(evidenceDir, `evidence.json.tmp.${Date.now()}.${process.pid}`);
|
|
22129
22138
|
try {
|
|
22130
22139
|
await bunWrite(tempPath, bundleJson);
|
|
22131
22140
|
await fs8.rename(tempPath, evidencePath);
|
|
22132
22141
|
} catch (error49) {
|
|
22133
22142
|
try {
|
|
22134
|
-
|
|
22143
|
+
rmSync(tempPath, { force: true });
|
|
22135
22144
|
} catch {}
|
|
22136
22145
|
throw error49;
|
|
22137
22146
|
}
|
|
@@ -22190,7 +22199,7 @@ async function loadEvidence(directory, taskId) {
|
|
|
22190
22199
|
await fs8.rename(tempPath, evidencePath);
|
|
22191
22200
|
} catch (writeError) {
|
|
22192
22201
|
try {
|
|
22193
|
-
|
|
22202
|
+
rmSync(tempPath, { force: true });
|
|
22194
22203
|
} catch {}
|
|
22195
22204
|
warn(`Failed to persist repaired flat retrospective for task ${sanitizedTaskId}: ${writeError instanceof Error ? writeError.message : String(writeError)}`);
|
|
22196
22205
|
}
|
|
@@ -22217,13 +22226,13 @@ async function loadEvidence(directory, taskId) {
|
|
|
22217
22226
|
async function listEvidenceTaskIds(directory) {
|
|
22218
22227
|
const evidenceBasePath = validateSwarmPath(directory, "evidence");
|
|
22219
22228
|
try {
|
|
22220
|
-
|
|
22229
|
+
statSync5(evidenceBasePath);
|
|
22221
22230
|
} catch {
|
|
22222
22231
|
return [];
|
|
22223
22232
|
}
|
|
22224
22233
|
let entries;
|
|
22225
22234
|
try {
|
|
22226
|
-
entries =
|
|
22235
|
+
entries = readdirSync4(evidenceBasePath);
|
|
22227
22236
|
} catch {
|
|
22228
22237
|
return [];
|
|
22229
22238
|
}
|
|
@@ -22231,7 +22240,7 @@ async function listEvidenceTaskIds(directory) {
|
|
|
22231
22240
|
for (const entry of entries) {
|
|
22232
22241
|
const entryPath = path10.join(evidenceBasePath, entry);
|
|
22233
22242
|
try {
|
|
22234
|
-
const stats =
|
|
22243
|
+
const stats = statSync5(entryPath);
|
|
22235
22244
|
if (!stats.isDirectory()) {
|
|
22236
22245
|
continue;
|
|
22237
22246
|
}
|
|
@@ -22250,12 +22259,12 @@ async function deleteEvidence(directory, taskId) {
|
|
|
22250
22259
|
const relativePath = path10.join("evidence", sanitizedTaskId);
|
|
22251
22260
|
const evidenceDir = validateSwarmPath(directory, relativePath);
|
|
22252
22261
|
try {
|
|
22253
|
-
|
|
22262
|
+
statSync5(evidenceDir);
|
|
22254
22263
|
} catch {
|
|
22255
22264
|
return false;
|
|
22256
22265
|
}
|
|
22257
22266
|
try {
|
|
22258
|
-
|
|
22267
|
+
rmSync(evidenceDir, { recursive: true, force: true });
|
|
22259
22268
|
return true;
|
|
22260
22269
|
} catch (error49) {
|
|
22261
22270
|
warn(`Failed to delete evidence for task ${sanitizedTaskId}: ${error49 instanceof Error ? error49.message : String(error49)}`);
|
|
@@ -22441,7 +22450,7 @@ var init_archive = __esm(() => {
|
|
|
22441
22450
|
});
|
|
22442
22451
|
|
|
22443
22452
|
// src/db/project-db.ts
|
|
22444
|
-
import { existsSync as
|
|
22453
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync6 } from "node:fs";
|
|
22445
22454
|
import { createRequire as createRequire2 } from "node:module";
|
|
22446
22455
|
import { join as join10, resolve as resolve7 } from "node:path";
|
|
22447
22456
|
function loadDatabaseCtor() {
|
|
@@ -22476,7 +22485,7 @@ function projectDbPath(directory) {
|
|
|
22476
22485
|
return join10(resolve7(directory), ".swarm", "swarm.db");
|
|
22477
22486
|
}
|
|
22478
22487
|
function projectDbExists(directory) {
|
|
22479
|
-
return
|
|
22488
|
+
return existsSync7(projectDbPath(directory));
|
|
22480
22489
|
}
|
|
22481
22490
|
function getProjectDb(directory) {
|
|
22482
22491
|
const key = resolve7(directory);
|
|
@@ -22484,7 +22493,7 @@ function getProjectDb(directory) {
|
|
|
22484
22493
|
if (existing)
|
|
22485
22494
|
return existing;
|
|
22486
22495
|
const swarmDir = join10(key, ".swarm");
|
|
22487
|
-
|
|
22496
|
+
mkdirSync6(swarmDir, { recursive: true });
|
|
22488
22497
|
const Db = loadDatabaseCtor();
|
|
22489
22498
|
const db = new Db(join10(swarmDir, "swarm.db"));
|
|
22490
22499
|
db.run("PRAGMA journal_mode = WAL;");
|
|
@@ -25557,16 +25566,16 @@ function checkWriteTargetForSymlink(targetPath, cwd) {
|
|
|
25557
25566
|
current = parent;
|
|
25558
25567
|
}
|
|
25559
25568
|
for (const ancestor of ancestors) {
|
|
25560
|
-
let
|
|
25569
|
+
let stat4 = null;
|
|
25561
25570
|
try {
|
|
25562
|
-
|
|
25571
|
+
stat4 = fsSync2.lstatSync(ancestor);
|
|
25563
25572
|
} catch (err2) {
|
|
25564
25573
|
const code = err2.code;
|
|
25565
25574
|
if (code === "ENOENT")
|
|
25566
25575
|
continue;
|
|
25567
25576
|
return `WRITE BLOCKED: lstat failed on "${ancestor}": ${String(err2)} — refusing write on unverifiable path`;
|
|
25568
25577
|
}
|
|
25569
|
-
if (
|
|
25578
|
+
if (stat4.isSymbolicLink()) {
|
|
25570
25579
|
return `WRITE BLOCKED: "${ancestor}" is a symlink — writing through a symlink could redirect the write outside the working directory`;
|
|
25571
25580
|
}
|
|
25572
25581
|
}
|
|
@@ -26359,9 +26368,9 @@ function dcLstatAncestorWalk(targetPath, cwd) {
|
|
|
26359
26368
|
current = parent;
|
|
26360
26369
|
}
|
|
26361
26370
|
for (const ancestor of ancestors) {
|
|
26362
|
-
let
|
|
26371
|
+
let stat4 = null;
|
|
26363
26372
|
try {
|
|
26364
|
-
|
|
26373
|
+
stat4 = fsSync3.lstatSync(ancestor);
|
|
26365
26374
|
} catch (err2) {
|
|
26366
26375
|
const code = err2.code;
|
|
26367
26376
|
if (code === "ENOENT") {
|
|
@@ -26369,7 +26378,7 @@ function dcLstatAncestorWalk(targetPath, cwd) {
|
|
|
26369
26378
|
}
|
|
26370
26379
|
return `lstat failed on "${ancestor}": ${String(err2)} — refusing to allow destructive operation on unverifiable path`;
|
|
26371
26380
|
}
|
|
26372
|
-
if (
|
|
26381
|
+
if (stat4.isSymbolicLink()) {
|
|
26373
26382
|
return `BLOCKED: "${ancestor}" is a symlink/junction — deleting recursively through it would destroy the link target. Use platform-specific junction deletion (fsutil reparsepoint delete, Remove-Item without -Recurse) instead.`;
|
|
26374
26383
|
}
|
|
26375
26384
|
}
|
|
@@ -28458,13 +28467,13 @@ function readScopeFromDisk(directory, taskId) {
|
|
|
28458
28467
|
}
|
|
28459
28468
|
let raw;
|
|
28460
28469
|
try {
|
|
28461
|
-
const
|
|
28462
|
-
if (!
|
|
28470
|
+
const stat4 = fs12.fstatSync(fd);
|
|
28471
|
+
if (!stat4.isFile())
|
|
28463
28472
|
return null;
|
|
28464
|
-
if (
|
|
28473
|
+
if (stat4.size > MAX_SCOPE_BYTES)
|
|
28465
28474
|
return null;
|
|
28466
|
-
const buf = Buffer.alloc(
|
|
28467
|
-
fs12.readSync(fd, buf, 0,
|
|
28475
|
+
const buf = Buffer.alloc(stat4.size);
|
|
28476
|
+
fs12.readSync(fd, buf, 0, stat4.size, 0);
|
|
28468
28477
|
raw = buf.toString("utf-8");
|
|
28469
28478
|
} catch {
|
|
28470
28479
|
return null;
|
|
@@ -28504,10 +28513,10 @@ function readPlanScope(directory, taskId) {
|
|
|
28504
28513
|
return null;
|
|
28505
28514
|
try {
|
|
28506
28515
|
const planPath = path19.join(directory, ".swarm", "plan.json");
|
|
28507
|
-
const
|
|
28508
|
-
if (!
|
|
28516
|
+
const stat4 = fs12.statSync(planPath);
|
|
28517
|
+
if (!stat4.isFile())
|
|
28509
28518
|
return null;
|
|
28510
|
-
if (
|
|
28519
|
+
if (stat4.size > MAX_PLAN_BYTES)
|
|
28511
28520
|
return null;
|
|
28512
28521
|
const raw = fs12.readFileSync(planPath, "utf-8");
|
|
28513
28522
|
const plan = JSON.parse(raw);
|
|
@@ -42397,7 +42406,7 @@ __export(exports_gate_evidence, {
|
|
|
42397
42406
|
deriveRequiredGates: () => deriveRequiredGates,
|
|
42398
42407
|
DEFAULT_REQUIRED_GATES: () => DEFAULT_REQUIRED_GATES
|
|
42399
42408
|
});
|
|
42400
|
-
import { mkdirSync as
|
|
42409
|
+
import { mkdirSync as mkdirSync10, readFileSync as readFileSync7, realpathSync as realpathSync5 } from "node:fs";
|
|
42401
42410
|
import * as path26 from "node:path";
|
|
42402
42411
|
function isValidTaskId(taskId) {
|
|
42403
42412
|
return isStrictTaskId(taskId);
|
|
@@ -42435,7 +42444,7 @@ function expandRequiredGates(existingGates, newAgentType) {
|
|
|
42435
42444
|
function getEvidenceDir(directory) {
|
|
42436
42445
|
const swarmDir = path26.resolve(directory, ".swarm");
|
|
42437
42446
|
const evidenceDir = path26.join(swarmDir, "evidence");
|
|
42438
|
-
|
|
42447
|
+
mkdirSync10(evidenceDir, { recursive: true });
|
|
42439
42448
|
let resolvedSwarmDir;
|
|
42440
42449
|
let resolvedEvidenceDir;
|
|
42441
42450
|
try {
|
|
@@ -59361,8 +59370,8 @@ __export(exports_knowledge_store, {
|
|
|
59361
59370
|
_internals: () => _internals22,
|
|
59362
59371
|
OUTCOME_SIGNAL_SMOOTHING: () => OUTCOME_SIGNAL_SMOOTHING
|
|
59363
59372
|
});
|
|
59364
|
-
import { existsSync as
|
|
59365
|
-
import { appendFile as appendFile3, mkdir as
|
|
59373
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
59374
|
+
import { appendFile as appendFile3, mkdir as mkdir4, readFile as readFile4 } from "node:fs/promises";
|
|
59366
59375
|
import * as os9 from "node:os";
|
|
59367
59376
|
import * as path31 from "node:path";
|
|
59368
59377
|
function getPlatformConfigDir() {
|
|
@@ -59403,7 +59412,7 @@ function resolveHiveRejectedPath() {
|
|
|
59403
59412
|
return path31.join(path31.dirname(hivePath), "shared-learnings-rejected.jsonl");
|
|
59404
59413
|
}
|
|
59405
59414
|
async function readKnowledge(filePath) {
|
|
59406
|
-
if (!
|
|
59415
|
+
if (!existsSync13(filePath))
|
|
59407
59416
|
return [];
|
|
59408
59417
|
const content = await readFile4(filePath, "utf-8");
|
|
59409
59418
|
const results = [];
|
|
@@ -59498,7 +59507,7 @@ async function appendRetractionRecord(directory, record3) {
|
|
|
59498
59507
|
}
|
|
59499
59508
|
async function appendKnowledge(filePath, entry) {
|
|
59500
59509
|
const dir = path31.dirname(filePath);
|
|
59501
|
-
await
|
|
59510
|
+
await mkdir4(dir, { recursive: true });
|
|
59502
59511
|
let release = null;
|
|
59503
59512
|
try {
|
|
59504
59513
|
release = await import_proper_lockfile3.default.lock(dir, {
|
|
@@ -59517,7 +59526,7 @@ async function appendKnowledge(filePath, entry) {
|
|
|
59517
59526
|
}
|
|
59518
59527
|
async function rewriteKnowledge(filePath, entries) {
|
|
59519
59528
|
const dir = path31.dirname(filePath);
|
|
59520
|
-
await
|
|
59529
|
+
await mkdir4(dir, { recursive: true });
|
|
59521
59530
|
let release = null;
|
|
59522
59531
|
try {
|
|
59523
59532
|
release = await import_proper_lockfile3.default.lock(dir, {
|
|
@@ -59539,7 +59548,7 @@ async function rewriteKnowledge(filePath, entries) {
|
|
|
59539
59548
|
async function transactFile(filePath, read, write, mutate) {
|
|
59540
59549
|
const dir = path31.dirname(filePath);
|
|
59541
59550
|
try {
|
|
59542
|
-
await
|
|
59551
|
+
await mkdir4(dir, { recursive: true });
|
|
59543
59552
|
} catch {
|
|
59544
59553
|
return false;
|
|
59545
59554
|
}
|
|
@@ -59800,7 +59809,7 @@ async function applyConfidenceDeltas(filePath, deltas) {
|
|
|
59800
59809
|
let release = null;
|
|
59801
59810
|
try {
|
|
59802
59811
|
const dir = path31.dirname(filePath);
|
|
59803
|
-
await
|
|
59812
|
+
await mkdir4(dir, { recursive: true });
|
|
59804
59813
|
release = await import_proper_lockfile3.default.lock(dir, {
|
|
59805
59814
|
retries: { retries: 5, minTimeout: 100, maxTimeout: 500 },
|
|
59806
59815
|
stale: 5000
|
|
@@ -59890,8 +59899,8 @@ __export(exports_knowledge_events, {
|
|
|
59890
59899
|
KNOWLEDGE_EVENT_SCHEMA_VERSION: () => KNOWLEDGE_EVENT_SCHEMA_VERSION
|
|
59891
59900
|
});
|
|
59892
59901
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
59893
|
-
import { existsSync as
|
|
59894
|
-
import { appendFile as appendFile4, mkdir as
|
|
59902
|
+
import { existsSync as existsSync14 } from "node:fs";
|
|
59903
|
+
import { appendFile as appendFile4, mkdir as mkdir5, readFile as readFile5, stat as stat4 } from "node:fs/promises";
|
|
59895
59904
|
import * as path32 from "node:path";
|
|
59896
59905
|
function resolveKnowledgeEventsPath(directory) {
|
|
59897
59906
|
return path32.join(directory, ".swarm", "knowledge-events.jsonl");
|
|
@@ -59920,7 +59929,7 @@ async function appendKnowledgeEvent(directory, event) {
|
|
|
59920
59929
|
const populated = withDefaults(event);
|
|
59921
59930
|
const filePath = resolveKnowledgeEventsPath(directory);
|
|
59922
59931
|
const dirPath = path32.dirname(filePath);
|
|
59923
|
-
await
|
|
59932
|
+
await mkdir5(dirPath, { recursive: true });
|
|
59924
59933
|
let release;
|
|
59925
59934
|
try {
|
|
59926
59935
|
release = await import_proper_lockfile4.default.lock(dirPath, {
|
|
@@ -59959,7 +59968,7 @@ async function recordKnowledgeEvent(directory, event) {
|
|
|
59959
59968
|
}
|
|
59960
59969
|
async function readKnowledgeEvents(directory) {
|
|
59961
59970
|
const filePath = resolveKnowledgeEventsPath(directory);
|
|
59962
|
-
if (!
|
|
59971
|
+
if (!existsSync14(filePath))
|
|
59963
59972
|
return [];
|
|
59964
59973
|
const content = await readFile5(filePath, "utf-8");
|
|
59965
59974
|
return parseEventLines(content.split(`
|
|
@@ -59967,7 +59976,7 @@ async function readKnowledgeEvents(directory) {
|
|
|
59967
59976
|
}
|
|
59968
59977
|
async function readLegacyApplicationRecords(directory) {
|
|
59969
59978
|
const filePath = resolveLegacyApplicationLogPath(directory);
|
|
59970
|
-
if (!
|
|
59979
|
+
if (!existsSync14(filePath))
|
|
59971
59980
|
return [];
|
|
59972
59981
|
const content = await readFile5(filePath, "utf-8");
|
|
59973
59982
|
const out2 = [];
|
|
@@ -60057,7 +60066,7 @@ function maxIso(current, candidate) {
|
|
|
60057
60066
|
}
|
|
60058
60067
|
async function readCounterBaseline(directory) {
|
|
60059
60068
|
const filePath = resolveKnowledgeCounterBaselinePath(directory);
|
|
60060
|
-
if (!
|
|
60069
|
+
if (!existsSync14(filePath))
|
|
60061
60070
|
return new Map;
|
|
60062
60071
|
const raw = JSON.parse(await readFile5(filePath, "utf-8"));
|
|
60063
60072
|
const map3 = new Map;
|
|
@@ -60077,7 +60086,7 @@ async function writeCounterBaseline(directory, baseline) {
|
|
|
60077
60086
|
}
|
|
60078
60087
|
async function statCacheKey(filePath) {
|
|
60079
60088
|
try {
|
|
60080
|
-
const fileStat = await
|
|
60089
|
+
const fileStat = await stat4(filePath);
|
|
60081
60090
|
return `${fileStat.mtimeMs}:${fileStat.ctimeMs}:${fileStat.size}`;
|
|
60082
60091
|
} catch (err2) {
|
|
60083
60092
|
if (err2?.code === "ENOENT")
|
|
@@ -60372,7 +60381,7 @@ var init_knowledge_events = __esm(() => {
|
|
|
60372
60381
|
});
|
|
60373
60382
|
|
|
60374
60383
|
// src/hooks/knowledge-escalator.ts
|
|
60375
|
-
import { existsSync as
|
|
60384
|
+
import { existsSync as existsSync15 } from "node:fs";
|
|
60376
60385
|
function isFullyEscalated(e) {
|
|
60377
60386
|
return e.directive_priority === "critical" && e.enforcement_mode === "enforce";
|
|
60378
60387
|
}
|
|
@@ -60384,7 +60393,7 @@ async function maybeEscalateOnViolation(directory, entryId, now = new Date) {
|
|
|
60384
60393
|
const allEntries = [];
|
|
60385
60394
|
allEntries.push(...await readKnowledge(resolveSwarmKnowledgePath(directory)));
|
|
60386
60395
|
const hivePath = resolveHiveKnowledgePath();
|
|
60387
|
-
if (
|
|
60396
|
+
if (existsSync15(hivePath)) {
|
|
60388
60397
|
allEntries.push(...await readKnowledge(hivePath));
|
|
60389
60398
|
}
|
|
60390
60399
|
const target = allEntries.find((e) => e.id === entryId);
|
|
@@ -60439,7 +60448,7 @@ async function maybeEscalateOnViolation(directory, entryId, now = new Date) {
|
|
|
60439
60448
|
await transactKnowledge(resolveSwarmKnowledgePath(directory), mutate);
|
|
60440
60449
|
if (state.outcome.kind === "not_found") {
|
|
60441
60450
|
const hivePath = resolveHiveKnowledgePath();
|
|
60442
|
-
if (
|
|
60451
|
+
if (existsSync15(hivePath)) {
|
|
60443
60452
|
await transactKnowledge(hivePath, mutate);
|
|
60444
60453
|
}
|
|
60445
60454
|
}
|
|
@@ -60911,7 +60920,7 @@ var init_learning_metrics = __esm(() => {
|
|
|
60911
60920
|
});
|
|
60912
60921
|
|
|
60913
60922
|
// src/hooks/knowledge-validator.ts
|
|
60914
|
-
import { appendFile as appendFile5, mkdir as
|
|
60923
|
+
import { appendFile as appendFile5, mkdir as mkdir6 } from "node:fs/promises";
|
|
60915
60924
|
import * as path33 from "node:path";
|
|
60916
60925
|
function normalizeText(text) {
|
|
60917
60926
|
return text.normalize("NFKC").toLowerCase().replace(/[^\w\s]/g, " ").replace(/\s+/g, " ").trim();
|
|
@@ -61182,7 +61191,7 @@ function resolveUnactionablePath(directory) {
|
|
|
61182
61191
|
async function appendUnactionable(directory, entry, reason) {
|
|
61183
61192
|
const filePath = resolveUnactionablePath(directory);
|
|
61184
61193
|
const dirPath = path33.dirname(filePath);
|
|
61185
|
-
await
|
|
61194
|
+
await mkdir6(dirPath, { recursive: true });
|
|
61186
61195
|
await transactKnowledge(filePath, (existing) => {
|
|
61187
61196
|
const record3 = {
|
|
61188
61197
|
...entry,
|
|
@@ -61219,7 +61228,7 @@ async function quarantineEntry(directory, entryId, reason, reportedBy) {
|
|
|
61219
61228
|
const quarantinePath = path33.join(directory, ".swarm", "knowledge-quarantined.jsonl");
|
|
61220
61229
|
const rejectedPath = path33.join(directory, ".swarm", "knowledge-rejected.jsonl");
|
|
61221
61230
|
const swarmDir = path33.join(directory, ".swarm");
|
|
61222
|
-
await
|
|
61231
|
+
await mkdir6(swarmDir, { recursive: true });
|
|
61223
61232
|
let release;
|
|
61224
61233
|
try {
|
|
61225
61234
|
release = await import_proper_lockfile5.default.lock(swarmDir, {
|
|
@@ -61283,7 +61292,7 @@ async function restoreEntry(directory, entryId) {
|
|
|
61283
61292
|
const quarantinePath = path33.join(directory, ".swarm", "knowledge-quarantined.jsonl");
|
|
61284
61293
|
const rejectedPath = path33.join(directory, ".swarm", "knowledge-rejected.jsonl");
|
|
61285
61294
|
const swarmDir = path33.join(directory, ".swarm");
|
|
61286
|
-
await
|
|
61295
|
+
await mkdir6(swarmDir, { recursive: true });
|
|
61287
61296
|
let release;
|
|
61288
61297
|
try {
|
|
61289
61298
|
release = await import_proper_lockfile5.default.lock(swarmDir, {
|
|
@@ -61461,7 +61470,7 @@ var init_knowledge_validator = __esm(() => {
|
|
|
61461
61470
|
});
|
|
61462
61471
|
|
|
61463
61472
|
// src/services/skill-changelog.ts
|
|
61464
|
-
import { appendFile as appendFile6, mkdir as
|
|
61473
|
+
import { appendFile as appendFile6, mkdir as mkdir7, readFile as readFile6, writeFile as writeFile3 } from "node:fs/promises";
|
|
61465
61474
|
import * as path34 from "node:path";
|
|
61466
61475
|
function resolveSkillChangelogPath(directory, slug) {
|
|
61467
61476
|
if (slug.includes("..") || slug.includes("/") || slug.includes("\\")) {
|
|
@@ -61472,7 +61481,7 @@ function resolveSkillChangelogPath(directory, slug) {
|
|
|
61472
61481
|
async function appendSkillChangelog(directory, slug, entry) {
|
|
61473
61482
|
const filePath = resolveSkillChangelogPath(directory, slug);
|
|
61474
61483
|
const dirPath = path34.dirname(filePath);
|
|
61475
|
-
await
|
|
61484
|
+
await mkdir7(dirPath, { recursive: true });
|
|
61476
61485
|
await appendFile6(filePath, `${JSON.stringify(entry)}
|
|
61477
61486
|
`, "utf-8");
|
|
61478
61487
|
try {
|
|
@@ -61519,8 +61528,8 @@ __export(exports_skill_generator, {
|
|
|
61519
61528
|
DEFAULT_SKILL_MIN_CONFIRMATIONS: () => DEFAULT_SKILL_MIN_CONFIRMATIONS,
|
|
61520
61529
|
DEFAULT_SKILL_MIN_CONFIDENCE: () => DEFAULT_SKILL_MIN_CONFIDENCE
|
|
61521
61530
|
});
|
|
61522
|
-
import { existsSync as
|
|
61523
|
-
import { mkdir as
|
|
61531
|
+
import { existsSync as existsSync16, unlinkSync as unlinkSync5 } from "node:fs";
|
|
61532
|
+
import { mkdir as mkdir8, readFile as readFile7, rename as rename3, writeFile as writeFile4 } from "node:fs/promises";
|
|
61524
61533
|
import * as path35 from "node:path";
|
|
61525
61534
|
function sanitizeSlug(input) {
|
|
61526
61535
|
const lc = input.toLowerCase().trim();
|
|
@@ -61543,7 +61552,7 @@ function activeRepoRelativePath(slug) {
|
|
|
61543
61552
|
async function selectCandidateEntries(directory, opts) {
|
|
61544
61553
|
const swarm = await readKnowledge(resolveSwarmKnowledgePath(directory));
|
|
61545
61554
|
const hivePath = resolveHiveKnowledgePath();
|
|
61546
|
-
const hive =
|
|
61555
|
+
const hive = existsSync16(hivePath) ? await readKnowledge(hivePath) : [];
|
|
61547
61556
|
const all = [...swarm, ...hive];
|
|
61548
61557
|
const counterRollups = await readKnowledgeCounterRollups(directory);
|
|
61549
61558
|
const selected = [];
|
|
@@ -61744,7 +61753,7 @@ function escapeMarkdown(s) {
|
|
|
61744
61753
|
return s.replace(/[\r\n]+/g, " ").slice(0, 280);
|
|
61745
61754
|
}
|
|
61746
61755
|
async function atomicWrite2(p, content) {
|
|
61747
|
-
await
|
|
61756
|
+
await mkdir8(path35.dirname(p), { recursive: true });
|
|
61748
61757
|
const tmp = `${p}.tmp-${process.pid}-${Date.now()}`;
|
|
61749
61758
|
await writeFile4(tmp, content, "utf-8");
|
|
61750
61759
|
await rename3(tmp, p);
|
|
@@ -61761,7 +61770,7 @@ async function generateSkills(req) {
|
|
|
61761
61770
|
const idSet = new Set(req.sourceKnowledgeIds);
|
|
61762
61771
|
const swarm = await readKnowledge(resolveSwarmKnowledgePath(req.directory));
|
|
61763
61772
|
const hivePath = resolveHiveKnowledgePath();
|
|
61764
|
-
const hive =
|
|
61773
|
+
const hive = existsSync16(hivePath) ? await readKnowledge(hivePath) : [];
|
|
61765
61774
|
pool = [...swarm, ...hive].filter((e) => idSet.has(e.id) && e.status !== "archived");
|
|
61766
61775
|
} else {
|
|
61767
61776
|
pool = candidates;
|
|
@@ -61798,7 +61807,7 @@ async function generateSkills(req) {
|
|
|
61798
61807
|
continue;
|
|
61799
61808
|
}
|
|
61800
61809
|
let preserved = false;
|
|
61801
|
-
if (req.mode === "active" &&
|
|
61810
|
+
if (req.mode === "active" && existsSync16(targetPath) && !req.force) {
|
|
61802
61811
|
const existing = await readFile7(targetPath, "utf-8");
|
|
61803
61812
|
if (!existing.includes("generated by opencode-swarm skill-generator")) {
|
|
61804
61813
|
preserved = true;
|
|
@@ -61843,7 +61852,7 @@ async function stampSourceEntries(directory, slug, ids) {
|
|
|
61843
61852
|
if (touched)
|
|
61844
61853
|
await rewriteKnowledge(swarmPath, swarm);
|
|
61845
61854
|
const hivePath = resolveHiveKnowledgePath();
|
|
61846
|
-
if (!
|
|
61855
|
+
if (!existsSync16(hivePath))
|
|
61847
61856
|
return;
|
|
61848
61857
|
const hive = await readKnowledge(hivePath);
|
|
61849
61858
|
let touchedHive = false;
|
|
@@ -61941,7 +61950,7 @@ async function activateProposal(directory, slug, force = false) {
|
|
|
61941
61950
|
}
|
|
61942
61951
|
const from = proposalPath(directory, cleanSlug);
|
|
61943
61952
|
const to = activePath(directory, cleanSlug);
|
|
61944
|
-
if (!
|
|
61953
|
+
if (!existsSync16(from)) {
|
|
61945
61954
|
return {
|
|
61946
61955
|
activated: false,
|
|
61947
61956
|
from,
|
|
@@ -61949,7 +61958,7 @@ async function activateProposal(directory, slug, force = false) {
|
|
|
61949
61958
|
reason: `proposal not found: ${from}`
|
|
61950
61959
|
};
|
|
61951
61960
|
}
|
|
61952
|
-
if (
|
|
61961
|
+
if (existsSync16(to) && !force) {
|
|
61953
61962
|
const existing = await readFile7(to, "utf-8");
|
|
61954
61963
|
if (!existing.includes("generated by opencode-swarm skill-generator")) {
|
|
61955
61964
|
return {
|
|
@@ -62013,7 +62022,7 @@ async function listSkills(directory) {
|
|
|
62013
62022
|
const proposalsDir = path35.join(directory, ".swarm", "skills", "proposals");
|
|
62014
62023
|
const activeDir = path35.join(directory, ".opencode", "skills", "generated");
|
|
62015
62024
|
const fs19 = await import("node:fs/promises");
|
|
62016
|
-
if (
|
|
62025
|
+
if (existsSync16(proposalsDir)) {
|
|
62017
62026
|
const entries = await fs19.readdir(proposalsDir);
|
|
62018
62027
|
for (const f of entries) {
|
|
62019
62028
|
if (!f.endsWith(".md"))
|
|
@@ -62025,16 +62034,16 @@ async function listSkills(directory) {
|
|
|
62025
62034
|
});
|
|
62026
62035
|
}
|
|
62027
62036
|
}
|
|
62028
|
-
if (
|
|
62037
|
+
if (existsSync16(activeDir)) {
|
|
62029
62038
|
const entries = await fs19.readdir(activeDir, { withFileTypes: true });
|
|
62030
62039
|
for (const e of entries) {
|
|
62031
62040
|
if (!e.isDirectory())
|
|
62032
62041
|
continue;
|
|
62033
62042
|
const retiredMarker = path35.join(activeDir, e.name, "retired.marker");
|
|
62034
|
-
if (
|
|
62043
|
+
if (existsSync16(retiredMarker))
|
|
62035
62044
|
continue;
|
|
62036
62045
|
const skillPath = path35.join(activeDir, e.name, "SKILL.md");
|
|
62037
|
-
if (
|
|
62046
|
+
if (existsSync16(skillPath)) {
|
|
62038
62047
|
result.active.push({
|
|
62039
62048
|
slug: e.name,
|
|
62040
62049
|
path: skillPath
|
|
@@ -62113,7 +62122,7 @@ async function inspectSkill(directory, slug, prefer = "auto") {
|
|
|
62113
62122
|
if (prefer === "proposal" || prefer === "auto")
|
|
62114
62123
|
candidates.push({ p: proposalPath(directory, cleanSlug), m: "draft" });
|
|
62115
62124
|
for (const c of candidates) {
|
|
62116
|
-
if (
|
|
62125
|
+
if (existsSync16(c.p)) {
|
|
62117
62126
|
const content = await readFile7(c.p, "utf-8");
|
|
62118
62127
|
return { found: true, path: c.p, content, mode: c.m };
|
|
62119
62128
|
}
|
|
@@ -62131,7 +62140,7 @@ async function retireSkill(directory, slug, reason) {
|
|
|
62131
62140
|
};
|
|
62132
62141
|
}
|
|
62133
62142
|
const skillPath = activePath(directory, cleanSlug);
|
|
62134
|
-
if (!
|
|
62143
|
+
if (!existsSync16(skillPath)) {
|
|
62135
62144
|
return {
|
|
62136
62145
|
retired: false,
|
|
62137
62146
|
path: skillPath,
|
|
@@ -62145,7 +62154,7 @@ async function retireSkill(directory, slug, reason) {
|
|
|
62145
62154
|
retiredAt: new Date().toISOString(),
|
|
62146
62155
|
reason: reason ?? "manual_retire"
|
|
62147
62156
|
});
|
|
62148
|
-
await
|
|
62157
|
+
await mkdir8(markerDir, { recursive: true });
|
|
62149
62158
|
await writeFile4(markerPath, markerContent, "utf-8");
|
|
62150
62159
|
return {
|
|
62151
62160
|
retired: true,
|
|
@@ -62165,7 +62174,7 @@ async function regenerateSkill(directory, slug) {
|
|
|
62165
62174
|
};
|
|
62166
62175
|
}
|
|
62167
62176
|
const skillPath = activePath(directory, cleanSlug);
|
|
62168
|
-
if (!
|
|
62177
|
+
if (!existsSync16(skillPath)) {
|
|
62169
62178
|
return {
|
|
62170
62179
|
regenerated: false,
|
|
62171
62180
|
path: skillPath,
|
|
@@ -62190,7 +62199,7 @@ async function regenerateSkill(directory, slug) {
|
|
|
62190
62199
|
try {
|
|
62191
62200
|
const swarm = await readKnowledge(resolveSwarmKnowledgePath(directory));
|
|
62192
62201
|
const hivePath = resolveHiveKnowledgePath();
|
|
62193
|
-
const hive =
|
|
62202
|
+
const hive = existsSync16(hivePath) ? await readKnowledge(hivePath) : [];
|
|
62194
62203
|
const all = [...swarm, ...hive];
|
|
62195
62204
|
const idSet = new Set(fm.sourceKnowledgeIds);
|
|
62196
62205
|
matchedEntries = all.filter((e) => idSet.has(e.id));
|
|
@@ -62339,8 +62348,8 @@ var init_skill_generator = __esm(() => {
|
|
|
62339
62348
|
});
|
|
62340
62349
|
|
|
62341
62350
|
// src/services/skill-improver-quota.ts
|
|
62342
|
-
import { existsSync as
|
|
62343
|
-
import { mkdir as
|
|
62351
|
+
import { existsSync as existsSync17 } from "node:fs";
|
|
62352
|
+
import { mkdir as mkdir9, readFile as readFile8, rename as rename4, writeFile as writeFile5 } from "node:fs/promises";
|
|
62344
62353
|
import * as path36 from "node:path";
|
|
62345
62354
|
async function acquireLock(dir) {
|
|
62346
62355
|
const acquire = import_proper_lockfile6.default.lock(dir, LOCK_RETRY_OPTS);
|
|
@@ -62372,7 +62381,7 @@ function todayKey(window2, now = new Date) {
|
|
|
62372
62381
|
return `${yr}-${m}-${d}`;
|
|
62373
62382
|
}
|
|
62374
62383
|
async function readState(filePath) {
|
|
62375
|
-
if (!
|
|
62384
|
+
if (!existsSync17(filePath))
|
|
62376
62385
|
return null;
|
|
62377
62386
|
try {
|
|
62378
62387
|
const raw = await readFile8(filePath, "utf-8");
|
|
@@ -62386,7 +62395,7 @@ async function readState(filePath) {
|
|
|
62386
62395
|
}
|
|
62387
62396
|
}
|
|
62388
62397
|
async function writeState(filePath, state) {
|
|
62389
|
-
await
|
|
62398
|
+
await mkdir9(path36.dirname(filePath), { recursive: true });
|
|
62390
62399
|
const tmp = `${filePath}.tmp-${process.pid}`;
|
|
62391
62400
|
await writeFile5(tmp, JSON.stringify(state, null, 2), "utf-8");
|
|
62392
62401
|
await rename4(tmp, filePath);
|
|
@@ -62409,7 +62418,7 @@ async function getQuotaState(directory, opts) {
|
|
|
62409
62418
|
}
|
|
62410
62419
|
async function reserveQuota(directory, opts) {
|
|
62411
62420
|
const filePath = resolveQuotaPath(directory, opts.scope);
|
|
62412
|
-
await
|
|
62421
|
+
await mkdir9(path36.dirname(filePath), { recursive: true });
|
|
62413
62422
|
let release = null;
|
|
62414
62423
|
try {
|
|
62415
62424
|
release = await acquireLock(path36.dirname(filePath));
|
|
@@ -62439,7 +62448,7 @@ async function reserveQuota(directory, opts) {
|
|
|
62439
62448
|
}
|
|
62440
62449
|
async function releaseQuota(directory, opts) {
|
|
62441
62450
|
const filePath = resolveQuotaPath(directory, opts.scope);
|
|
62442
|
-
await
|
|
62451
|
+
await mkdir9(path36.dirname(filePath), { recursive: true });
|
|
62443
62452
|
let release = null;
|
|
62444
62453
|
try {
|
|
62445
62454
|
release = await acquireLock(path36.dirname(filePath));
|
|
@@ -62848,8 +62857,8 @@ function appendSkillUsageEntry(directory, entry) {
|
|
|
62848
62857
|
_internals26.appendFileSync(resolved, `${JSON.stringify(fullEntry)}
|
|
62849
62858
|
`, "utf-8");
|
|
62850
62859
|
try {
|
|
62851
|
-
const
|
|
62852
|
-
if (
|
|
62860
|
+
const stat5 = _internals26.statSync(resolved);
|
|
62861
|
+
if (stat5.size > SKILL_USAGE_LOG_ROTATE_BYTES) {
|
|
62853
62862
|
_internals26.pruneSkillUsageLog(directory, SKILL_USAGE_LOG_MAX_ENTRIES_PER_SKILL);
|
|
62854
62863
|
}
|
|
62855
62864
|
} catch {}
|
|
@@ -62903,11 +62912,11 @@ function readSkillUsageEntriesTail(directory, filters, maxBytes = TAIL_BYTES_DEF
|
|
|
62903
62912
|
try {
|
|
62904
62913
|
const normalizedMaxBytes = Number.isFinite(maxBytes) ? maxBytes : TAIL_BYTES_DEFAULT;
|
|
62905
62914
|
const boundedMaxBytes = Math.min(Math.max(1, normalizedMaxBytes), MAX_TAIL_BYTES);
|
|
62906
|
-
const
|
|
62907
|
-
const start2 = Math.max(0,
|
|
62915
|
+
const stat5 = _internals26.statSync(logPath);
|
|
62916
|
+
const start2 = Math.max(0, stat5.size - boundedMaxBytes);
|
|
62908
62917
|
const fd = _internals26.openSync(logPath, "r");
|
|
62909
62918
|
try {
|
|
62910
|
-
const readLen =
|
|
62919
|
+
const readLen = stat5.size - start2;
|
|
62911
62920
|
if (readLen === 0)
|
|
62912
62921
|
return [];
|
|
62913
62922
|
const buf = Buffer.alloc(readLen);
|
|
@@ -64428,10 +64437,10 @@ var init_hive_promoter = __esm(() => {
|
|
|
64428
64437
|
|
|
64429
64438
|
// src/services/synonym-map.ts
|
|
64430
64439
|
import {
|
|
64431
|
-
mkdir as
|
|
64440
|
+
mkdir as mkdir10,
|
|
64432
64441
|
readFile as readFile10,
|
|
64433
64442
|
rename as rename6,
|
|
64434
|
-
stat as
|
|
64443
|
+
stat as stat5,
|
|
64435
64444
|
unlink as unlink2,
|
|
64436
64445
|
writeFile as writeFile7
|
|
64437
64446
|
} from "node:fs/promises";
|
|
@@ -64620,7 +64629,7 @@ async function readSynonymMap(directory, maxPairs = DEFAULT_MAX_PAIRS) {
|
|
|
64620
64629
|
}
|
|
64621
64630
|
try {
|
|
64622
64631
|
const ceiling = Math.max(MIN_READ_CEILING_BYTES, Math.floor(maxPairs) * APPROX_BYTES_PER_PAIR);
|
|
64623
|
-
const st = await
|
|
64632
|
+
const st = await stat5(filePath);
|
|
64624
64633
|
if (st.size > ceiling)
|
|
64625
64634
|
return emptySynonymMap();
|
|
64626
64635
|
const raw = await readFile10(filePath, "utf-8");
|
|
@@ -64630,7 +64639,7 @@ async function readSynonymMap(directory, maxPairs = DEFAULT_MAX_PAIRS) {
|
|
|
64630
64639
|
}
|
|
64631
64640
|
}
|
|
64632
64641
|
async function writeSynonymMapAtomic(filePath, map3) {
|
|
64633
|
-
await
|
|
64642
|
+
await mkdir10(path40.dirname(filePath), { recursive: true });
|
|
64634
64643
|
const tmp = `${filePath}.tmp.${Date.now()}.${Math.floor(Math.random() * 1e9)}`;
|
|
64635
64644
|
try {
|
|
64636
64645
|
await writeFile7(tmp, JSON.stringify(map3, null, 2), "utf-8");
|
|
@@ -64644,7 +64653,7 @@ async function writeSynonymMapAtomic(filePath, map3) {
|
|
|
64644
64653
|
async function rebuildSynonymMap(directory, entries, maxPairs = DEFAULT_MAX_PAIRS) {
|
|
64645
64654
|
const filePath = resolveSynonymMapPath(directory);
|
|
64646
64655
|
const dir = path40.dirname(filePath);
|
|
64647
|
-
await
|
|
64656
|
+
await mkdir10(dir, { recursive: true });
|
|
64648
64657
|
let release = null;
|
|
64649
64658
|
try {
|
|
64650
64659
|
release = await import_proper_lockfile7.default.lock(dir, {
|
|
@@ -64933,8 +64942,8 @@ function formatSkillIndexWithContext(skills, directory) {
|
|
|
64933
64942
|
const usageLogPath = path41.join(directory, ".swarm", "skill-usage.jsonl");
|
|
64934
64943
|
let hasHistory = false;
|
|
64935
64944
|
try {
|
|
64936
|
-
const
|
|
64937
|
-
hasHistory =
|
|
64945
|
+
const stat6 = fs21.statSync(usageLogPath);
|
|
64946
|
+
hasHistory = stat6.size > 0;
|
|
64938
64947
|
} catch {}
|
|
64939
64948
|
if (!hasHistory) {
|
|
64940
64949
|
return skills.map((sp) => {
|
|
@@ -65630,7 +65639,7 @@ var init_skill_propagation_gate = __esm(() => {
|
|
|
65630
65639
|
});
|
|
65631
65640
|
|
|
65632
65641
|
// src/hooks/micro-reflector.ts
|
|
65633
|
-
import { existsSync as
|
|
65642
|
+
import { existsSync as existsSync21 } from "node:fs";
|
|
65634
65643
|
import { readFile as readFile11, writeFile as writeFile8 } from "node:fs/promises";
|
|
65635
65644
|
import * as path43 from "node:path";
|
|
65636
65645
|
function resolveInsightCandidatesPath(directory) {
|
|
@@ -65665,7 +65674,7 @@ async function readTaskTrajectory(directory, taskId) {
|
|
|
65665
65674
|
try {
|
|
65666
65675
|
const rel = path43.join("evidence", sanitizeTaskId2(taskId), "trajectory.jsonl");
|
|
65667
65676
|
const filePath = validateSwarmPath(directory, rel);
|
|
65668
|
-
if (!
|
|
65677
|
+
if (!existsSync21(filePath))
|
|
65669
65678
|
return [];
|
|
65670
65679
|
const content = await readFile11(filePath, "utf-8");
|
|
65671
65680
|
const out2 = [];
|
|
@@ -65908,8 +65917,8 @@ var init_micro_reflector = __esm(() => {
|
|
|
65908
65917
|
});
|
|
65909
65918
|
|
|
65910
65919
|
// src/hooks/knowledge-curator.ts
|
|
65911
|
-
import { existsSync as
|
|
65912
|
-
import { appendFile as appendFile7, mkdir as
|
|
65920
|
+
import { existsSync as existsSync22 } from "node:fs";
|
|
65921
|
+
import { appendFile as appendFile7, mkdir as mkdir11, readFile as readFile12, writeFile as writeFile9 } from "node:fs/promises";
|
|
65913
65922
|
import * as path44 from "node:path";
|
|
65914
65923
|
function pruneSeenRetroSections() {
|
|
65915
65924
|
const cutoff = Date.now() - 86400000;
|
|
@@ -66171,7 +66180,7 @@ RETRY: your last output was missing ${result.missing.join("; ")}; produce valid
|
|
|
66171
66180
|
async function appendCuratorSkippedEvent(directory, record3) {
|
|
66172
66181
|
try {
|
|
66173
66182
|
const filePath = path44.join(directory, ".swarm", "events.jsonl");
|
|
66174
|
-
await
|
|
66183
|
+
await mkdir11(path44.dirname(filePath), { recursive: true });
|
|
66175
66184
|
await appendFile7(filePath, `${JSON.stringify({
|
|
66176
66185
|
timestamp: new Date().toISOString(),
|
|
66177
66186
|
event: "curator_skipped",
|
|
@@ -66198,7 +66207,7 @@ function readInsightJsonl2(content) {
|
|
|
66198
66207
|
async function consumeInsightCandidates(directory, batchLimit = MESO_INSIGHT_BATCH_LIMIT) {
|
|
66199
66208
|
try {
|
|
66200
66209
|
const filePath = resolveInsightCandidatesPath(directory);
|
|
66201
|
-
if (!
|
|
66210
|
+
if (!existsSync22(filePath))
|
|
66202
66211
|
return [];
|
|
66203
66212
|
const consumed = [];
|
|
66204
66213
|
await transactFile(filePath, async (p) => readInsightJsonl2(await readFile12(p, "utf-8").catch(() => "")), async (p, data) => {
|
|
@@ -66728,7 +66737,7 @@ var init_skill_improver_llm_factory = __esm(() => {
|
|
|
66728
66737
|
});
|
|
66729
66738
|
|
|
66730
66739
|
// src/services/trajectory-cluster.ts
|
|
66731
|
-
import { mkdir as
|
|
66740
|
+
import { mkdir as mkdir12, writeFile as writeFile10 } from "node:fs/promises";
|
|
66732
66741
|
import * as path45 from "node:path";
|
|
66733
66742
|
function failureKind(e) {
|
|
66734
66743
|
const tool3 = (e.tool ?? "").toLowerCase();
|
|
@@ -66859,7 +66868,7 @@ async function writeMotifProposals(directory, opts = {}) {
|
|
|
66859
66868
|
return result;
|
|
66860
66869
|
const max = opts.maxProposals ?? 10;
|
|
66861
66870
|
const proposalsDir = validateSwarmPath(directory, path45.join("skills", "proposals"));
|
|
66862
|
-
await
|
|
66871
|
+
await mkdir12(proposalsDir, { recursive: true });
|
|
66863
66872
|
for (const motif of motifs.slice(0, max)) {
|
|
66864
66873
|
const slug = `motif-${slugify2(motif.signature)}`;
|
|
66865
66874
|
const filePath = path45.join(proposalsDir, `${slug}.md`);
|
|
@@ -67003,7 +67012,7 @@ async function writeSuccessMotifProposals(directory, opts = {}) {
|
|
|
67003
67012
|
return result;
|
|
67004
67013
|
const max = opts.maxProposals ?? 10;
|
|
67005
67014
|
const proposalsDir = validateSwarmPath(directory, path45.join("skills", "proposals"));
|
|
67006
|
-
await
|
|
67015
|
+
await mkdir12(proposalsDir, { recursive: true });
|
|
67007
67016
|
for (const motif of motifs.slice(0, max)) {
|
|
67008
67017
|
const slug = workflowSlug(motif.signature);
|
|
67009
67018
|
const filePath = path45.join(proposalsDir, `${slug}.md`);
|
|
@@ -67025,12 +67034,12 @@ var init_trajectory_cluster = __esm(() => {
|
|
|
67025
67034
|
});
|
|
67026
67035
|
|
|
67027
67036
|
// src/services/unactionable-hardening.ts
|
|
67028
|
-
import { existsSync as
|
|
67037
|
+
import { existsSync as existsSync23 } from "node:fs";
|
|
67029
67038
|
async function hardenUnactionableEntries(params) {
|
|
67030
67039
|
const result = { hardened: 0, retired: 0, remaining: 0 };
|
|
67031
67040
|
try {
|
|
67032
67041
|
const queuePath = resolveUnactionablePath(params.directory);
|
|
67033
|
-
if (!
|
|
67042
|
+
if (!existsSync23(queuePath))
|
|
67034
67043
|
return result;
|
|
67035
67044
|
const limit = params.batchLimit ?? HARDENING_BATCH_LIMIT;
|
|
67036
67045
|
const dedupThreshold = params.dedupThreshold ?? 0.6;
|
|
@@ -67137,14 +67146,14 @@ var init_unactionable_hardening = __esm(() => {
|
|
|
67137
67146
|
});
|
|
67138
67147
|
|
|
67139
67148
|
// src/services/skill-improver.ts
|
|
67140
|
-
import { existsSync as
|
|
67141
|
-
import { mkdir as
|
|
67149
|
+
import { existsSync as existsSync24 } from "node:fs";
|
|
67150
|
+
import { mkdir as mkdir13, readFile as readFile13, rename as rename7, writeFile as writeFile11 } from "node:fs/promises";
|
|
67142
67151
|
import * as path46 from "node:path";
|
|
67143
67152
|
function timestampSlug(d) {
|
|
67144
67153
|
return d.toISOString().replace(/[:.]/g, "-");
|
|
67145
67154
|
}
|
|
67146
67155
|
async function atomicWrite3(p, content) {
|
|
67147
|
-
await
|
|
67156
|
+
await mkdir13(path46.dirname(p), { recursive: true });
|
|
67148
67157
|
const tmp = `${p}.tmp-${process.pid}-${Date.now()}`;
|
|
67149
67158
|
await writeFile11(tmp, content, "utf-8");
|
|
67150
67159
|
await rename7(tmp, p);
|
|
@@ -67152,7 +67161,7 @@ async function atomicWrite3(p, content) {
|
|
|
67152
67161
|
async function gatherInventory(directory) {
|
|
67153
67162
|
const swarm = await readKnowledge(resolveSwarmKnowledgePath(directory));
|
|
67154
67163
|
const hivePath = resolveHiveKnowledgePath();
|
|
67155
|
-
const hive =
|
|
67164
|
+
const hive = existsSync24(hivePath) ? await readKnowledge(hivePath) : [];
|
|
67156
67165
|
const archived = [...swarm, ...hive].filter((e) => e.status === "archived").length;
|
|
67157
67166
|
const skills = await listSkills(directory);
|
|
67158
67167
|
const knowledgeById = new Map([...swarm, ...hive].map((entry) => [entry.id, entry]));
|
|
@@ -67918,7 +67927,7 @@ __export(exports_curator_postmortem, {
|
|
|
67918
67927
|
runCuratorPostMortem: () => runCuratorPostMortem,
|
|
67919
67928
|
_internals: () => _internals32
|
|
67920
67929
|
});
|
|
67921
|
-
import { existsSync as
|
|
67930
|
+
import { existsSync as existsSync25, readdirSync as readdirSync6, readFileSync as readFileSync12 } from "node:fs";
|
|
67922
67931
|
import * as path47 from "node:path";
|
|
67923
67932
|
async function collectKnowledgeSummary(directory) {
|
|
67924
67933
|
const entries = await readKnowledge(resolveSwarmKnowledgePath(directory));
|
|
@@ -67958,7 +67967,7 @@ async function collectKnowledgeSummary(directory) {
|
|
|
67958
67967
|
}
|
|
67959
67968
|
function readJsonlFile(filePath) {
|
|
67960
67969
|
try {
|
|
67961
|
-
if (!
|
|
67970
|
+
if (!existsSync25(filePath))
|
|
67962
67971
|
return [];
|
|
67963
67972
|
const content = readFileSync12(filePath, "utf-8");
|
|
67964
67973
|
const results = [];
|
|
@@ -67979,12 +67988,12 @@ function collectRetrospectives(directory) {
|
|
|
67979
67988
|
const results = [];
|
|
67980
67989
|
const evidenceDir = path47.join(directory, ".swarm", "evidence");
|
|
67981
67990
|
try {
|
|
67982
|
-
if (!
|
|
67991
|
+
if (!existsSync25(evidenceDir))
|
|
67983
67992
|
return results;
|
|
67984
|
-
for (const entry of
|
|
67993
|
+
for (const entry of readdirSync6(evidenceDir, { withFileTypes: true })) {
|
|
67985
67994
|
if (entry.isDirectory() && entry.name.startsWith("retro-")) {
|
|
67986
67995
|
const retroPath = path47.join(evidenceDir, entry.name, "evidence.json");
|
|
67987
|
-
if (
|
|
67996
|
+
if (existsSync25(retroPath)) {
|
|
67988
67997
|
try {
|
|
67989
67998
|
results.push(readFileSync12(retroPath, "utf-8"));
|
|
67990
67999
|
} catch {}
|
|
@@ -67998,9 +68007,9 @@ function collectDriftReports(directory) {
|
|
|
67998
68007
|
const results = [];
|
|
67999
68008
|
const swarmDir = path47.join(directory, ".swarm");
|
|
68000
68009
|
try {
|
|
68001
|
-
if (!
|
|
68010
|
+
if (!existsSync25(swarmDir))
|
|
68002
68011
|
return results;
|
|
68003
|
-
for (const entry of
|
|
68012
|
+
for (const entry of readdirSync6(swarmDir)) {
|
|
68004
68013
|
if (entry.startsWith("drift-report-phase-") && entry.endsWith(".json")) {
|
|
68005
68014
|
try {
|
|
68006
68015
|
results.push(readFileSync12(path47.join(swarmDir, entry), "utf-8"));
|
|
@@ -68013,7 +68022,7 @@ function collectDriftReports(directory) {
|
|
|
68013
68022
|
function collectPendingProposals(directory) {
|
|
68014
68023
|
const results = [];
|
|
68015
68024
|
const insightPath = path47.join(directory, ".swarm", "insight-candidates.jsonl");
|
|
68016
|
-
if (
|
|
68025
|
+
if (existsSync25(insightPath)) {
|
|
68017
68026
|
try {
|
|
68018
68027
|
results.push({
|
|
68019
68028
|
source: "insight-candidates",
|
|
@@ -68023,8 +68032,8 @@ function collectPendingProposals(directory) {
|
|
|
68023
68032
|
}
|
|
68024
68033
|
const proposalsDir = path47.join(directory, ".swarm", "skills", "proposals");
|
|
68025
68034
|
try {
|
|
68026
|
-
if (
|
|
68027
|
-
for (const entry of
|
|
68035
|
+
if (existsSync25(proposalsDir)) {
|
|
68036
|
+
for (const entry of readdirSync6(proposalsDir)) {
|
|
68028
68037
|
if (entry.endsWith(".md") || entry.endsWith(".json")) {
|
|
68029
68038
|
try {
|
|
68030
68039
|
results.push({
|
|
@@ -68178,7 +68187,7 @@ async function runCuratorPostMortem(directory, options = {}) {
|
|
|
68178
68187
|
warnings: [...warnings, "Invalid report path."]
|
|
68179
68188
|
};
|
|
68180
68189
|
}
|
|
68181
|
-
if (!options.force &&
|
|
68190
|
+
if (!options.force && existsSync25(reportPath)) {
|
|
68182
68191
|
return {
|
|
68183
68192
|
success: true,
|
|
68184
68193
|
planId,
|
|
@@ -68241,8 +68250,8 @@ ${llmOutput}`;
|
|
|
68241
68250
|
reportContent = buildDataOnlyReport(planId, planSummary, knowledgeSummary, curatorDigest, proposals, unactionable, retrospectives, driftReports);
|
|
68242
68251
|
}
|
|
68243
68252
|
try {
|
|
68244
|
-
const { mkdirSync:
|
|
68245
|
-
|
|
68253
|
+
const { mkdirSync: mkdirSync16, writeFileSync: writeFileSync10 } = await import("node:fs");
|
|
68254
|
+
mkdirSync16(path47.dirname(reportPath), { recursive: true });
|
|
68246
68255
|
writeFileSync10(reportPath, reportContent, "utf-8");
|
|
68247
68256
|
} catch (err2) {
|
|
68248
68257
|
const msg = err2 instanceof Error ? err2.message : String(err2);
|
|
@@ -68332,8 +68341,8 @@ async function copyDirRecursive(src, dest) {
|
|
|
68332
68341
|
const srcEntry = path48.join(src, entry);
|
|
68333
68342
|
const destEntry = path48.join(dest, entry);
|
|
68334
68343
|
try {
|
|
68335
|
-
const
|
|
68336
|
-
if (
|
|
68344
|
+
const stat6 = await fs23.stat(srcEntry);
|
|
68345
|
+
if (stat6.isDirectory()) {
|
|
68337
68346
|
const subCount = await copyDirRecursive(srcEntry, destEntry).catch(() => 0);
|
|
68338
68347
|
count += subCount;
|
|
68339
68348
|
} else {
|
|
@@ -68369,8 +68378,8 @@ function guaranteeAllPlansComplete(planData) {
|
|
|
68369
68378
|
async function handleCloseCommand(directory, args2, options = {}) {
|
|
68370
68379
|
const swarmDir = path48.join(directory, ".swarm");
|
|
68371
68380
|
try {
|
|
68372
|
-
const
|
|
68373
|
-
if (
|
|
68381
|
+
const stat6 = fsSync5.lstatSync(swarmDir);
|
|
68382
|
+
if (stat6.isSymbolicLink()) {
|
|
68374
68383
|
return `❌ Refused: .swarm/ is a symlink or junction. Refusing to operate on a redirected directory for safety.`;
|
|
68375
68384
|
}
|
|
68376
68385
|
} catch (err2) {
|
|
@@ -69366,7 +69375,7 @@ __export(exports_co_change_analyzer, {
|
|
|
69366
69375
|
});
|
|
69367
69376
|
import * as child_process3 from "node:child_process";
|
|
69368
69377
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
69369
|
-
import { readdir as
|
|
69378
|
+
import { readdir as readdir3, readFile as readFile14, stat as stat6 } from "node:fs/promises";
|
|
69370
69379
|
import * as path50 from "node:path";
|
|
69371
69380
|
import { promisify } from "node:util";
|
|
69372
69381
|
function getExecFileAsync() {
|
|
@@ -69469,7 +69478,7 @@ async function scanSourceFiles(dir) {
|
|
|
69469
69478
|
const results = [];
|
|
69470
69479
|
const skipDirs = new Set(["node_modules", ".swarm", "dist", "build"]);
|
|
69471
69480
|
try {
|
|
69472
|
-
const entries = await
|
|
69481
|
+
const entries = await readdir3(dir, { withFileTypes: true });
|
|
69473
69482
|
for (const entry of entries) {
|
|
69474
69483
|
const fullPath = path50.join(dir, entry.name);
|
|
69475
69484
|
if (entry.isDirectory()) {
|
|
@@ -69517,7 +69526,7 @@ async function getStaticEdges(directory) {
|
|
|
69517
69526
|
for (const ext of extensions) {
|
|
69518
69527
|
const testPath = resolvedPath + ext;
|
|
69519
69528
|
try {
|
|
69520
|
-
const testStat = await
|
|
69529
|
+
const testStat = await stat6(testPath);
|
|
69521
69530
|
if (testStat.isFile()) {
|
|
69522
69531
|
targetFile = testPath;
|
|
69523
69532
|
break;
|
|
@@ -70263,7 +70272,7 @@ var init_gate_bridge = __esm(() => {
|
|
|
70263
70272
|
});
|
|
70264
70273
|
|
|
70265
70274
|
// src/services/version-check.ts
|
|
70266
|
-
import { existsSync as
|
|
70275
|
+
import { existsSync as existsSync26, mkdirSync as mkdirSync16, readFileSync as readFileSync13, writeFileSync as writeFileSync10 } from "node:fs";
|
|
70267
70276
|
import { homedir as homedir6 } from "node:os";
|
|
70268
70277
|
import { join as join41 } from "node:path";
|
|
70269
70278
|
function cacheDir() {
|
|
@@ -70277,7 +70286,7 @@ function cacheFile() {
|
|
|
70277
70286
|
function readVersionCache() {
|
|
70278
70287
|
try {
|
|
70279
70288
|
const path53 = cacheFile();
|
|
70280
|
-
if (!
|
|
70289
|
+
if (!existsSync26(path53))
|
|
70281
70290
|
return null;
|
|
70282
70291
|
const raw = readFileSync13(path53, "utf-8");
|
|
70283
70292
|
const parsed = JSON.parse(raw);
|
|
@@ -70292,7 +70301,7 @@ function readVersionCache() {
|
|
|
70292
70301
|
function writeVersionCache(entry) {
|
|
70293
70302
|
try {
|
|
70294
70303
|
const dir = cacheDir();
|
|
70295
|
-
|
|
70304
|
+
mkdirSync16(dir, { recursive: true });
|
|
70296
70305
|
writeFileSync10(cacheFile(), JSON.stringify(entry, null, 2), "utf-8");
|
|
70297
70306
|
} catch {}
|
|
70298
70307
|
}
|
|
@@ -70375,10 +70384,10 @@ var init_version_check = __esm(() => {
|
|
|
70375
70384
|
});
|
|
70376
70385
|
|
|
70377
70386
|
// src/services/knowledge-diagnostics.ts
|
|
70378
|
-
import { existsSync as
|
|
70387
|
+
import { existsSync as existsSync27 } from "node:fs";
|
|
70379
70388
|
import { readFile as readFile15 } from "node:fs/promises";
|
|
70380
70389
|
async function readRawLines(filePath) {
|
|
70381
|
-
if (!
|
|
70390
|
+
if (!existsSync27(filePath))
|
|
70382
70391
|
return { entries: [], corrupt: 0 };
|
|
70383
70392
|
const content = await readFile15(filePath, "utf-8");
|
|
70384
70393
|
const entries = [];
|
|
@@ -70503,7 +70512,7 @@ async function computeKnowledgeDebug(directory) {
|
|
|
70503
70512
|
};
|
|
70504
70513
|
}
|
|
70505
70514
|
async function safeJsonlCount(filePath) {
|
|
70506
|
-
if (!filePath || !
|
|
70515
|
+
if (!filePath || !existsSync27(filePath))
|
|
70507
70516
|
return 0;
|
|
70508
70517
|
try {
|
|
70509
70518
|
const content = await readFile15(filePath, "utf-8");
|
|
@@ -70586,7 +70595,7 @@ var init_knowledge_diagnostics = __esm(() => {
|
|
|
70586
70595
|
|
|
70587
70596
|
// src/services/diagnose-service.ts
|
|
70588
70597
|
import * as child_process4 from "node:child_process";
|
|
70589
|
-
import { existsSync as
|
|
70598
|
+
import { existsSync as existsSync28, readdirSync as readdirSync7, readFileSync as readFileSync14, statSync as statSync10 } from "node:fs";
|
|
70590
70599
|
import path53 from "node:path";
|
|
70591
70600
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
70592
70601
|
function validateTaskDag(plan) {
|
|
@@ -70803,7 +70812,7 @@ async function checkPlanSync(directory, plan) {
|
|
|
70803
70812
|
}
|
|
70804
70813
|
async function checkConfigBackups(directory) {
|
|
70805
70814
|
try {
|
|
70806
|
-
const files =
|
|
70815
|
+
const files = readdirSync7(directory);
|
|
70807
70816
|
const backupCount = files.filter((f) => /\.opencode-swarm\.yaml\.bak/.test(f)).length;
|
|
70808
70817
|
if (backupCount <= 5) {
|
|
70809
70818
|
return {
|
|
@@ -70834,7 +70843,7 @@ async function checkConfigBackups(directory) {
|
|
|
70834
70843
|
}
|
|
70835
70844
|
async function checkGitRepository(directory) {
|
|
70836
70845
|
try {
|
|
70837
|
-
if (!
|
|
70846
|
+
if (!existsSync28(directory) || !statSync10(directory).isDirectory()) {
|
|
70838
70847
|
return {
|
|
70839
70848
|
name: "Git Repository",
|
|
70840
70849
|
status: "❌",
|
|
@@ -70899,7 +70908,7 @@ async function checkSpecStaleness(directory, plan) {
|
|
|
70899
70908
|
}
|
|
70900
70909
|
async function checkConfigParseability(directory) {
|
|
70901
70910
|
const configPath = path53.join(directory, ".opencode/opencode-swarm.json");
|
|
70902
|
-
if (!
|
|
70911
|
+
if (!existsSync28(configPath)) {
|
|
70903
70912
|
return {
|
|
70904
70913
|
name: "Config Parseability",
|
|
70905
70914
|
status: "✅",
|
|
@@ -70954,11 +70963,11 @@ async function checkGrammarWasmFiles() {
|
|
|
70954
70963
|
const thisDir = path53.dirname(fileURLToPath2(import.meta.url));
|
|
70955
70964
|
const grammarDir = resolveGrammarDir(thisDir);
|
|
70956
70965
|
const missing = [];
|
|
70957
|
-
if (!
|
|
70966
|
+
if (!existsSync28(path53.join(grammarDir, "tree-sitter.wasm"))) {
|
|
70958
70967
|
missing.push("tree-sitter.wasm (core runtime)");
|
|
70959
70968
|
}
|
|
70960
70969
|
for (const file3 of grammarFiles) {
|
|
70961
|
-
if (!
|
|
70970
|
+
if (!existsSync28(path53.join(grammarDir, file3))) {
|
|
70962
70971
|
missing.push(file3);
|
|
70963
70972
|
}
|
|
70964
70973
|
}
|
|
@@ -70977,7 +70986,7 @@ async function checkGrammarWasmFiles() {
|
|
|
70977
70986
|
}
|
|
70978
70987
|
async function checkCheckpointManifest(directory) {
|
|
70979
70988
|
const manifestPath = path53.join(directory, ".swarm/checkpoints.json");
|
|
70980
|
-
if (!
|
|
70989
|
+
if (!existsSync28(manifestPath)) {
|
|
70981
70990
|
return {
|
|
70982
70991
|
name: "Checkpoint Manifest",
|
|
70983
70992
|
status: "✅",
|
|
@@ -71029,7 +71038,7 @@ async function checkCheckpointManifest(directory) {
|
|
|
71029
71038
|
}
|
|
71030
71039
|
async function checkEventStreamIntegrity(directory) {
|
|
71031
71040
|
const eventsPath = path53.join(directory, ".swarm/events.jsonl");
|
|
71032
|
-
if (!
|
|
71041
|
+
if (!existsSync28(eventsPath)) {
|
|
71033
71042
|
return {
|
|
71034
71043
|
name: "Event Stream",
|
|
71035
71044
|
status: "✅",
|
|
@@ -71070,7 +71079,7 @@ async function checkEventStreamIntegrity(directory) {
|
|
|
71070
71079
|
}
|
|
71071
71080
|
async function checkSteeringDirectives(directory) {
|
|
71072
71081
|
const eventsPath = path53.join(directory, ".swarm/events.jsonl");
|
|
71073
|
-
if (!
|
|
71082
|
+
if (!existsSync28(eventsPath)) {
|
|
71074
71083
|
return {
|
|
71075
71084
|
name: "Steering Directives",
|
|
71076
71085
|
status: "✅",
|
|
@@ -71126,7 +71135,7 @@ async function checkCurator(directory) {
|
|
|
71126
71135
|
};
|
|
71127
71136
|
}
|
|
71128
71137
|
const summaryPath = path53.join(directory, ".swarm/curator-summary.json");
|
|
71129
|
-
if (!
|
|
71138
|
+
if (!existsSync28(summaryPath)) {
|
|
71130
71139
|
return {
|
|
71131
71140
|
name: "Curator",
|
|
71132
71141
|
status: "✅",
|
|
@@ -71293,7 +71302,7 @@ async function getDiagnoseData(directory) {
|
|
|
71293
71302
|
checks5.push(await checkKnowledgeHealth(directory));
|
|
71294
71303
|
try {
|
|
71295
71304
|
const evidenceDir = path53.join(directory, ".swarm", "evidence");
|
|
71296
|
-
const snapshotFiles =
|
|
71305
|
+
const snapshotFiles = existsSync28(evidenceDir) ? readdirSync7(evidenceDir).filter((f) => f.startsWith("agent-tools-") && f.endsWith(".json")) : [];
|
|
71297
71306
|
if (snapshotFiles.length > 0) {
|
|
71298
71307
|
const latest = snapshotFiles.sort().pop();
|
|
71299
71308
|
checks5.push({
|
|
@@ -71326,7 +71335,7 @@ async function getDiagnoseData(directory) {
|
|
|
71326
71335
|
const cacheRows = [];
|
|
71327
71336
|
for (const cachePath of cachePaths) {
|
|
71328
71337
|
try {
|
|
71329
|
-
if (!
|
|
71338
|
+
if (!existsSync28(cachePath)) {
|
|
71330
71339
|
cacheRows.push(`⬜ ${cachePath} — absent`);
|
|
71331
71340
|
continue;
|
|
71332
71341
|
}
|
|
@@ -73703,7 +73712,7 @@ var init_profiles = __esm(() => {
|
|
|
73703
73712
|
});
|
|
73704
73713
|
|
|
73705
73714
|
// src/lang/detector.ts
|
|
73706
|
-
import { access as
|
|
73715
|
+
import { access as access4, readdir as readdir4 } from "node:fs/promises";
|
|
73707
73716
|
import { extname as extname3, join as join43 } from "node:path";
|
|
73708
73717
|
function getProfileForFile(filePath) {
|
|
73709
73718
|
const ext = extname3(filePath);
|
|
@@ -73717,7 +73726,7 @@ async function detectProjectLanguages(projectDir) {
|
|
|
73717
73726
|
let dirEntries;
|
|
73718
73727
|
let entries;
|
|
73719
73728
|
try {
|
|
73720
|
-
dirEntries = await
|
|
73729
|
+
dirEntries = await readdir4(dir, { withFileTypes: true });
|
|
73721
73730
|
entries = dirEntries.map((e) => e.name);
|
|
73722
73731
|
} catch {
|
|
73723
73732
|
return;
|
|
@@ -73733,7 +73742,7 @@ async function detectProjectLanguages(projectDir) {
|
|
|
73733
73742
|
continue;
|
|
73734
73743
|
}
|
|
73735
73744
|
try {
|
|
73736
|
-
await
|
|
73745
|
+
await access4(join43(dir, detectFile));
|
|
73737
73746
|
detected.add(profile.id);
|
|
73738
73747
|
break;
|
|
73739
73748
|
} catch {}
|
|
@@ -73751,7 +73760,7 @@ async function detectProjectLanguages(projectDir) {
|
|
|
73751
73760
|
}
|
|
73752
73761
|
await scanDir(projectDir);
|
|
73753
73762
|
try {
|
|
73754
|
-
const topEntries = await
|
|
73763
|
+
const topEntries = await readdir4(projectDir, { withFileTypes: true });
|
|
73755
73764
|
for (const entry of topEntries) {
|
|
73756
73765
|
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules") {
|
|
73757
73766
|
await scanDir(join43(projectDir, entry.name));
|
|
@@ -75894,7 +75903,7 @@ var init_handoff_service = __esm(() => {
|
|
|
75894
75903
|
});
|
|
75895
75904
|
|
|
75896
75905
|
// src/session/snapshot-writer.ts
|
|
75897
|
-
import { closeSync as closeSync5, fsyncSync as fsyncSync2, mkdirSync as
|
|
75906
|
+
import { closeSync as closeSync5, fsyncSync as fsyncSync2, mkdirSync as mkdirSync19, openSync as openSync5, renameSync as renameSync12 } from "node:fs";
|
|
75898
75907
|
import * as path57 from "node:path";
|
|
75899
75908
|
function serializeAgentSession(s) {
|
|
75900
75909
|
const gateLog = {};
|
|
@@ -76002,7 +76011,7 @@ async function writeSnapshot(directory, state) {
|
|
|
76002
76011
|
const content = JSON.stringify(snapshot, null, 2);
|
|
76003
76012
|
const resolvedPath = validateSwarmPath(directory, "session/state.json");
|
|
76004
76013
|
const dir = path57.dirname(resolvedPath);
|
|
76005
|
-
|
|
76014
|
+
mkdirSync19(dir, { recursive: true });
|
|
76006
76015
|
const tempPath = `${resolvedPath}.tmp.${Date.now()}.${Math.random().toString(36).slice(2)}`;
|
|
76007
76016
|
await bunWrite(tempPath, content);
|
|
76008
76017
|
try {
|
|
@@ -76541,8 +76550,8 @@ var KNOWLEDGE_SCHEMA_VERSION = 2;
|
|
|
76541
76550
|
|
|
76542
76551
|
// src/hooks/knowledge-migrator.ts
|
|
76543
76552
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
76544
|
-
import { existsSync as
|
|
76545
|
-
import { mkdir as
|
|
76553
|
+
import { existsSync as existsSync32, readFileSync as readFileSync18 } from "node:fs";
|
|
76554
|
+
import { mkdir as mkdir14, readFile as readFile16, writeFile as writeFile12 } from "node:fs/promises";
|
|
76546
76555
|
import * as os13 from "node:os";
|
|
76547
76556
|
import * as path58 from "node:path";
|
|
76548
76557
|
async function migrateKnowledgeToExternal(_directory, _config) {
|
|
@@ -76558,7 +76567,7 @@ async function migrateContextToKnowledge(directory, config3) {
|
|
|
76558
76567
|
const sentinelPath = path58.join(directory, ".swarm", ".knowledge-migrated");
|
|
76559
76568
|
const contextPath = path58.join(directory, ".swarm", "context.md");
|
|
76560
76569
|
const knowledgePath = resolveSwarmKnowledgePath(directory);
|
|
76561
|
-
if (
|
|
76570
|
+
if (existsSync32(sentinelPath)) {
|
|
76562
76571
|
return {
|
|
76563
76572
|
migrated: false,
|
|
76564
76573
|
entriesMigrated: 0,
|
|
@@ -76567,7 +76576,7 @@ async function migrateContextToKnowledge(directory, config3) {
|
|
|
76567
76576
|
skippedReason: "sentinel-exists"
|
|
76568
76577
|
};
|
|
76569
76578
|
}
|
|
76570
|
-
if (!
|
|
76579
|
+
if (!existsSync32(contextPath)) {
|
|
76571
76580
|
return {
|
|
76572
76581
|
migrated: false,
|
|
76573
76582
|
entriesMigrated: 0,
|
|
@@ -76659,7 +76668,7 @@ async function migrateHiveKnowledgeLegacy(config3) {
|
|
|
76659
76668
|
const legacyHivePath = _internals40.resolveLegacyHiveKnowledgePath();
|
|
76660
76669
|
const canonicalHivePath = resolveHiveKnowledgePath();
|
|
76661
76670
|
const sentinelPath = path58.join(path58.dirname(canonicalHivePath), ".hive-knowledge-migrated");
|
|
76662
|
-
if (
|
|
76671
|
+
if (existsSync32(sentinelPath)) {
|
|
76663
76672
|
return {
|
|
76664
76673
|
migrated: false,
|
|
76665
76674
|
entriesMigrated: 0,
|
|
@@ -76668,7 +76677,7 @@ async function migrateHiveKnowledgeLegacy(config3) {
|
|
|
76668
76677
|
skippedReason: "sentinel-exists"
|
|
76669
76678
|
};
|
|
76670
76679
|
}
|
|
76671
|
-
if (!
|
|
76680
|
+
if (!existsSync32(legacyHivePath)) {
|
|
76672
76681
|
return {
|
|
76673
76682
|
migrated: false,
|
|
76674
76683
|
entriesMigrated: 0,
|
|
@@ -76870,7 +76879,7 @@ function truncateLesson2(text) {
|
|
|
76870
76879
|
}
|
|
76871
76880
|
function inferProjectName(directory) {
|
|
76872
76881
|
const packageJsonPath = path58.join(directory, "package.json");
|
|
76873
|
-
if (
|
|
76882
|
+
if (existsSync32(packageJsonPath)) {
|
|
76874
76883
|
try {
|
|
76875
76884
|
const pkg = JSON.parse(readFileSync18(packageJsonPath, "utf-8"));
|
|
76876
76885
|
if (pkg.name && typeof pkg.name === "string") {
|
|
@@ -76890,7 +76899,7 @@ async function writeSentinel(sentinelPath, migrated, dropped) {
|
|
|
76890
76899
|
schema_version: 1,
|
|
76891
76900
|
migration_tool: "knowledge-migrator.ts"
|
|
76892
76901
|
};
|
|
76893
|
-
await
|
|
76902
|
+
await mkdir14(path58.dirname(sentinelPath), { recursive: true });
|
|
76894
76903
|
await writeFile12(sentinelPath, JSON.stringify(sentinel, null, 2), "utf-8");
|
|
76895
76904
|
}
|
|
76896
76905
|
function resolveLegacyHiveKnowledgePath() {
|
|
@@ -78107,10 +78116,10 @@ var init_scoring = __esm(() => {
|
|
|
78107
78116
|
|
|
78108
78117
|
// src/memory/local-jsonl-provider.ts
|
|
78109
78118
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
78110
|
-
import { existsSync as
|
|
78119
|
+
import { existsSync as existsSync33 } from "node:fs";
|
|
78111
78120
|
import {
|
|
78112
78121
|
appendFile as appendFile8,
|
|
78113
|
-
mkdir as
|
|
78122
|
+
mkdir as mkdir15,
|
|
78114
78123
|
readFile as readFile17,
|
|
78115
78124
|
rename as rename8,
|
|
78116
78125
|
writeFile as writeFile13
|
|
@@ -78458,7 +78467,7 @@ function validateLoadedProposals(values, config3) {
|
|
|
78458
78467
|
return { records, invalidCount };
|
|
78459
78468
|
}
|
|
78460
78469
|
async function readJsonl(filePath) {
|
|
78461
|
-
if (!
|
|
78470
|
+
if (!existsSync33(filePath))
|
|
78462
78471
|
return [];
|
|
78463
78472
|
const content = await readFile17(filePath, "utf-8");
|
|
78464
78473
|
const records = [];
|
|
@@ -78514,12 +78523,12 @@ function parseRecallUsageEvent(event) {
|
|
|
78514
78523
|
}
|
|
78515
78524
|
}
|
|
78516
78525
|
async function appendJsonl(filePath, value) {
|
|
78517
|
-
await
|
|
78526
|
+
await mkdir15(path59.dirname(filePath), { recursive: true });
|
|
78518
78527
|
await appendFile8(filePath, `${JSON.stringify(value)}
|
|
78519
78528
|
`, "utf-8");
|
|
78520
78529
|
}
|
|
78521
78530
|
async function writeJsonlAtomic(filePath, values) {
|
|
78522
|
-
await
|
|
78531
|
+
await mkdir15(path59.dirname(filePath), { recursive: true });
|
|
78523
78532
|
const tmp = `${filePath}.tmp.${randomUUID7()}`;
|
|
78524
78533
|
const content = values.map((value) => JSON.stringify(value)).join(`
|
|
78525
78534
|
`) + (values.length > 0 ? `
|
|
@@ -78618,8 +78627,8 @@ var init_prompt_block = __esm(() => {
|
|
|
78618
78627
|
});
|
|
78619
78628
|
|
|
78620
78629
|
// src/memory/jsonl-migration.ts
|
|
78621
|
-
import { existsSync as
|
|
78622
|
-
import { copyFile, mkdir as
|
|
78630
|
+
import { existsSync as existsSync34 } from "node:fs";
|
|
78631
|
+
import { copyFile as copyFile2, mkdir as mkdir16, readFile as readFile18, stat as stat7, writeFile as writeFile14 } from "node:fs/promises";
|
|
78623
78632
|
import * as path60 from "node:path";
|
|
78624
78633
|
function resolveMemoryStorageDir(rootDirectory, config3 = {}) {
|
|
78625
78634
|
const resolved = resolveConfig(config3);
|
|
@@ -78646,25 +78655,25 @@ async function readLegacyJsonl(rootDirectory, config3 = {}) {
|
|
|
78646
78655
|
async function backupLegacyJsonl(rootDirectory, config3 = {}) {
|
|
78647
78656
|
const storageDir = resolveMemoryStorageDir(rootDirectory, config3);
|
|
78648
78657
|
const backupDir = path60.join(storageDir, "backups");
|
|
78649
|
-
await
|
|
78658
|
+
await mkdir16(backupDir, { recursive: true });
|
|
78650
78659
|
const results = [];
|
|
78651
78660
|
for (const filename of ["memories.jsonl", "proposals.jsonl"]) {
|
|
78652
78661
|
const source = path60.join(storageDir, filename);
|
|
78653
|
-
if (!
|
|
78662
|
+
if (!existsSync34(source))
|
|
78654
78663
|
continue;
|
|
78655
78664
|
const backup = path60.join(backupDir, `${filename}.pre-sqlite-migration`);
|
|
78656
|
-
if (
|
|
78665
|
+
if (existsSync34(backup)) {
|
|
78657
78666
|
results.push({ source, backup, created: false });
|
|
78658
78667
|
continue;
|
|
78659
78668
|
}
|
|
78660
|
-
await
|
|
78669
|
+
await copyFile2(source, backup);
|
|
78661
78670
|
results.push({ source, backup, created: true });
|
|
78662
78671
|
}
|
|
78663
78672
|
return results;
|
|
78664
78673
|
}
|
|
78665
78674
|
async function writeJsonlExport(rootDirectory, config3, memories, proposals) {
|
|
78666
78675
|
const exportDir = path60.join(resolveMemoryStorageDir(rootDirectory, config3), "export");
|
|
78667
|
-
await
|
|
78676
|
+
await mkdir16(exportDir, { recursive: true });
|
|
78668
78677
|
const memoriesPath = path60.join(exportDir, "memories.jsonl");
|
|
78669
78678
|
const proposalsPath = path60.join(exportDir, "proposals.jsonl");
|
|
78670
78679
|
await writeFile14(memoriesPath, toJsonl(memories), "utf-8");
|
|
@@ -78673,14 +78682,14 @@ async function writeJsonlExport(rootDirectory, config3, memories, proposals) {
|
|
|
78673
78682
|
}
|
|
78674
78683
|
async function writeMigrationReport(rootDirectory, report, config3 = {}) {
|
|
78675
78684
|
const reportPath = path60.join(resolveMemoryStorageDir(rootDirectory, config3), "migration-report.json");
|
|
78676
|
-
await
|
|
78685
|
+
await mkdir16(path60.dirname(reportPath), { recursive: true });
|
|
78677
78686
|
await writeFile14(reportPath, `${JSON.stringify(report, null, 2)}
|
|
78678
78687
|
`, "utf-8");
|
|
78679
78688
|
return reportPath;
|
|
78680
78689
|
}
|
|
78681
78690
|
async function readMigrationReport(rootDirectory, config3 = {}) {
|
|
78682
78691
|
const reportPath = path60.join(resolveMemoryStorageDir(rootDirectory, config3), "migration-report.json");
|
|
78683
|
-
if (!
|
|
78692
|
+
if (!existsSync34(reportPath))
|
|
78684
78693
|
return null;
|
|
78685
78694
|
try {
|
|
78686
78695
|
return JSON.parse(await readFile18(reportPath, "utf-8"));
|
|
@@ -78694,13 +78703,13 @@ async function getLegacyJsonlFileStatus(rootDirectory, config3 = {}) {
|
|
|
78694
78703
|
for (const file3 of ["memories.jsonl", "proposals.jsonl"]) {
|
|
78695
78704
|
const filePath = path60.join(storageDir, file3);
|
|
78696
78705
|
let sizeBytes = 0;
|
|
78697
|
-
if (
|
|
78698
|
-
sizeBytes = (await
|
|
78706
|
+
if (existsSync34(filePath)) {
|
|
78707
|
+
sizeBytes = (await stat7(filePath)).size;
|
|
78699
78708
|
}
|
|
78700
78709
|
statuses.push({
|
|
78701
78710
|
file: file3,
|
|
78702
78711
|
path: filePath,
|
|
78703
|
-
exists:
|
|
78712
|
+
exists: existsSync34(filePath),
|
|
78704
78713
|
sizeBytes
|
|
78705
78714
|
});
|
|
78706
78715
|
}
|
|
@@ -78781,7 +78790,7 @@ async function readProposalJsonl(filePath, config3) {
|
|
|
78781
78790
|
return { records, invalidRows, totalRows: rows.totalRows };
|
|
78782
78791
|
}
|
|
78783
78792
|
async function readJsonlRows(filePath) {
|
|
78784
|
-
if (!
|
|
78793
|
+
if (!existsSync34(filePath)) {
|
|
78785
78794
|
return { rows: [], invalidRows: [], totalRows: 0 };
|
|
78786
78795
|
}
|
|
78787
78796
|
const content = await readFile18(filePath, "utf-8");
|
|
@@ -78819,7 +78828,7 @@ var init_jsonl_migration = __esm(() => {
|
|
|
78819
78828
|
|
|
78820
78829
|
// src/memory/sqlite-provider.ts
|
|
78821
78830
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
78822
|
-
import { mkdirSync as
|
|
78831
|
+
import { mkdirSync as mkdirSync20 } from "node:fs";
|
|
78823
78832
|
import { createRequire as createRequire3 } from "node:module";
|
|
78824
78833
|
import * as path61 from "node:path";
|
|
78825
78834
|
function loadDatabaseCtor2() {
|
|
@@ -78879,7 +78888,7 @@ class SQLiteMemoryProvider {
|
|
|
78879
78888
|
if (this.initialized)
|
|
78880
78889
|
return;
|
|
78881
78890
|
const dbPath = this.databasePath();
|
|
78882
|
-
|
|
78891
|
+
mkdirSync20(path61.dirname(dbPath), { recursive: true });
|
|
78883
78892
|
const Db = loadDatabaseCtor2();
|
|
78884
78893
|
this.db = new Db(dbPath);
|
|
78885
78894
|
this.db.run("PRAGMA journal_mode = WAL;");
|
|
@@ -79745,7 +79754,7 @@ var init_sqlite_provider = __esm(() => {
|
|
|
79745
79754
|
|
|
79746
79755
|
// src/memory/gateway.ts
|
|
79747
79756
|
import { createHash as createHash8 } from "node:crypto";
|
|
79748
|
-
import { existsSync as
|
|
79757
|
+
import { existsSync as existsSync35, readFileSync as readFileSync19 } from "node:fs";
|
|
79749
79758
|
import * as path62 from "node:path";
|
|
79750
79759
|
|
|
79751
79760
|
class MemoryGateway {
|
|
@@ -80070,7 +80079,7 @@ function readGitRemoteUrl(directory) {
|
|
|
80070
80079
|
if (gitRemoteUrlCache.has(directory))
|
|
80071
80080
|
return gitRemoteUrlCache.get(directory);
|
|
80072
80081
|
const gitConfigPath = path62.join(directory, ".git", "config");
|
|
80073
|
-
if (!
|
|
80082
|
+
if (!existsSync35(gitConfigPath)) {
|
|
80074
80083
|
gitRemoteUrlCache.set(directory, undefined);
|
|
80075
80084
|
return;
|
|
80076
80085
|
}
|
|
@@ -80639,13 +80648,13 @@ var init_recall_planner = __esm(() => {
|
|
|
80639
80648
|
});
|
|
80640
80649
|
|
|
80641
80650
|
// src/memory/run-log.ts
|
|
80642
|
-
import { appendFile as appendFile9, mkdir as
|
|
80651
|
+
import { appendFile as appendFile9, mkdir as mkdir17 } from "node:fs/promises";
|
|
80643
80652
|
import * as path64 from "node:path";
|
|
80644
80653
|
async function appendMemoryRunLog(directory, runId, event) {
|
|
80645
80654
|
const safeRunId = sanitizeRunId(runId);
|
|
80646
80655
|
const relativePath = path64.join("runs", safeRunId, "memory.jsonl");
|
|
80647
80656
|
const filePath = validateSwarmPath(directory, relativePath);
|
|
80648
|
-
await
|
|
80657
|
+
await mkdir17(path64.dirname(filePath), { recursive: true });
|
|
80649
80658
|
await appendFile9(filePath, `${JSON.stringify({
|
|
80650
80659
|
...event,
|
|
80651
80660
|
runId: safeRunId,
|
|
@@ -81046,7 +81055,7 @@ var init_memory = __esm(() => {
|
|
|
81046
81055
|
});
|
|
81047
81056
|
|
|
81048
81057
|
// src/commands/memory.ts
|
|
81049
|
-
import { existsSync as
|
|
81058
|
+
import { existsSync as existsSync36 } from "node:fs";
|
|
81050
81059
|
import * as path65 from "node:path";
|
|
81051
81060
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
81052
81061
|
async function handleMemoryCommand(_directory, _args) {
|
|
@@ -81078,7 +81087,7 @@ async function handleMemoryStatusCommand(directory, _args) {
|
|
|
81078
81087
|
`- Provider: \`${config3.provider}\``,
|
|
81079
81088
|
`- Storage: \`${storageDir}\``,
|
|
81080
81089
|
`- SQLite path: \`${sqlitePath}\``,
|
|
81081
|
-
`- SQLite database exists: \`${
|
|
81090
|
+
`- SQLite database exists: \`${existsSync36(sqlitePath)}\``,
|
|
81082
81091
|
`- Automatic destructive cleanup: \`disabled\``,
|
|
81083
81092
|
"",
|
|
81084
81093
|
"### Legacy JSONL"
|
|
@@ -82776,11 +82785,11 @@ function createRedactedContext(line, findings) {
|
|
|
82776
82785
|
function scanFileForSecrets(filePath) {
|
|
82777
82786
|
const findings = [];
|
|
82778
82787
|
try {
|
|
82779
|
-
const
|
|
82780
|
-
if (
|
|
82788
|
+
const lstat2 = fs30.lstatSync(filePath);
|
|
82789
|
+
if (lstat2.isSymbolicLink()) {
|
|
82781
82790
|
return findings;
|
|
82782
82791
|
}
|
|
82783
|
-
if (
|
|
82792
|
+
if (lstat2.size > MAX_FILE_SIZE_BYTES) {
|
|
82784
82793
|
return findings;
|
|
82785
82794
|
}
|
|
82786
82795
|
let buffer;
|
|
@@ -82868,18 +82877,18 @@ function findScannableFiles(dir, excludeExact, excludeGlobs, scanDir, visited, s
|
|
|
82868
82877
|
stats.skippedDirs++;
|
|
82869
82878
|
continue;
|
|
82870
82879
|
}
|
|
82871
|
-
let
|
|
82880
|
+
let lstat2;
|
|
82872
82881
|
try {
|
|
82873
|
-
|
|
82882
|
+
lstat2 = fs30.lstatSync(fullPath);
|
|
82874
82883
|
} catch {
|
|
82875
82884
|
stats.fileErrors++;
|
|
82876
82885
|
continue;
|
|
82877
82886
|
}
|
|
82878
|
-
if (
|
|
82887
|
+
if (lstat2.isSymbolicLink()) {
|
|
82879
82888
|
stats.symlinkSkipped++;
|
|
82880
82889
|
continue;
|
|
82881
82890
|
}
|
|
82882
|
-
if (
|
|
82891
|
+
if (lstat2.isDirectory()) {
|
|
82883
82892
|
let realPath;
|
|
82884
82893
|
try {
|
|
82885
82894
|
realPath = fs30.realpathSync(fullPath);
|
|
@@ -82897,7 +82906,7 @@ function findScannableFiles(dir, excludeExact, excludeGlobs, scanDir, visited, s
|
|
|
82897
82906
|
}
|
|
82898
82907
|
const subFiles = findScannableFiles(fullPath, excludeExact, excludeGlobs, scanDir, visited, stats);
|
|
82899
82908
|
files.push(...subFiles);
|
|
82900
|
-
} else if (
|
|
82909
|
+
} else if (lstat2.isFile()) {
|
|
82901
82910
|
const ext = path68.extname(fullPath).toLowerCase();
|
|
82902
82911
|
if (!DEFAULT_EXCLUDE_EXTENSIONS.has(ext)) {
|
|
82903
82912
|
files.push(fullPath);
|
|
@@ -83228,8 +83237,8 @@ var init_secretscan = __esm(() => {
|
|
|
83228
83237
|
break;
|
|
83229
83238
|
const fileFindings = scanFileForSecrets(filePath);
|
|
83230
83239
|
try {
|
|
83231
|
-
const
|
|
83232
|
-
if (
|
|
83240
|
+
const stat8 = fs30.statSync(filePath);
|
|
83241
|
+
if (stat8.size > MAX_FILE_SIZE_BYTES) {
|
|
83233
83242
|
skippedFiles++;
|
|
83234
83243
|
continue;
|
|
83235
83244
|
}
|
|
@@ -84039,8 +84048,8 @@ function sharedTrailingSegments(a, b) {
|
|
|
84039
84048
|
function isCacheStale(impactMap, generatedAtMs) {
|
|
84040
84049
|
for (const sourcePath of Object.keys(impactMap)) {
|
|
84041
84050
|
try {
|
|
84042
|
-
const
|
|
84043
|
-
if (
|
|
84051
|
+
const stat8 = fs34.statSync(sourcePath);
|
|
84052
|
+
if (stat8.mtimeMs > generatedAtMs) {
|
|
84044
84053
|
return true;
|
|
84045
84054
|
}
|
|
84046
84055
|
} catch {
|
|
@@ -85386,8 +85395,8 @@ function manifestHash(dir) {
|
|
|
85386
85395
|
if (!entries.has(name2))
|
|
85387
85396
|
continue;
|
|
85388
85397
|
try {
|
|
85389
|
-
const
|
|
85390
|
-
parts2.push(`${name2}:${
|
|
85398
|
+
const stat8 = fs39.statSync(path77.join(dir, name2));
|
|
85399
|
+
parts2.push(`${name2}:${stat8.size}:${stat8.mtimeMs}:${stat8.ino}`);
|
|
85391
85400
|
} catch {}
|
|
85392
85401
|
}
|
|
85393
85402
|
return parts2.join("|");
|
|
@@ -88942,7 +88951,7 @@ var init_reset_session = __esm(() => {
|
|
|
88942
88951
|
});
|
|
88943
88952
|
|
|
88944
88953
|
// src/summaries/manager.ts
|
|
88945
|
-
import { mkdirSync as
|
|
88954
|
+
import { mkdirSync as mkdirSync22, readdirSync as readdirSync17, renameSync as renameSync14, rmSync as rmSync5, statSync as statSync18 } from "node:fs";
|
|
88946
88955
|
import * as path82 from "node:path";
|
|
88947
88956
|
function sanitizeSummaryId(id) {
|
|
88948
88957
|
if (!id || id.length === 0) {
|
|
@@ -88988,14 +88997,14 @@ async function storeSummary(directory, id, fullOutput, summaryText, maxStoredByt
|
|
|
88988
88997
|
originalBytes: Buffer.byteLength(fullOutput, "utf8")
|
|
88989
88998
|
};
|
|
88990
88999
|
const entryJson = JSON.stringify(entry);
|
|
88991
|
-
|
|
89000
|
+
mkdirSync22(summaryDir, { recursive: true });
|
|
88992
89001
|
const tempPath = path82.join(summaryDir, `${sanitizedId}.json.tmp.${Date.now()}.${process.pid}`);
|
|
88993
89002
|
try {
|
|
88994
89003
|
await bunWrite(tempPath, entryJson);
|
|
88995
89004
|
renameSync14(tempPath, summaryPath);
|
|
88996
89005
|
} catch (error93) {
|
|
88997
89006
|
try {
|
|
88998
|
-
|
|
89007
|
+
rmSync5(tempPath, { force: true });
|
|
88999
89008
|
} catch {}
|
|
89000
89009
|
throw error93;
|
|
89001
89010
|
}
|
|
@@ -90141,8 +90150,8 @@ async function countProposals(directory) {
|
|
|
90141
90150
|
const proposalsDir = validateSwarmPath(directory, "skills/proposals");
|
|
90142
90151
|
if (!fsSync6.existsSync(proposalsDir))
|
|
90143
90152
|
return 0;
|
|
90144
|
-
const { readdir:
|
|
90145
|
-
const entries = await
|
|
90153
|
+
const { readdir: readdir6 } = await import("node:fs/promises");
|
|
90154
|
+
const entries = await readdir6(proposalsDir);
|
|
90146
90155
|
return entries.filter((f) => f.endsWith(".md")).length;
|
|
90147
90156
|
} catch {
|
|
90148
90157
|
return 0;
|
|
@@ -91249,7 +91258,7 @@ Showing full help:
|
|
|
91249
91258
|
}
|
|
91250
91259
|
async function handleModeCommandWithBundledSkills(ctx, handler) {
|
|
91251
91260
|
if (ctx.packageRoot) {
|
|
91252
|
-
|
|
91261
|
+
await syncBundledProjectSkillsIfMissingAsync(ctx.directory, ctx.packageRoot);
|
|
91253
91262
|
}
|
|
91254
91263
|
return Promise.resolve(handler(ctx.directory, ctx.args));
|
|
91255
91264
|
}
|
|
@@ -91449,6 +91458,13 @@ var init_registry = __esm(() => {
|
|
|
91449
91458
|
description: "Run tool registration coherence check",
|
|
91450
91459
|
category: "diagnostics"
|
|
91451
91460
|
},
|
|
91461
|
+
"doctor-tools": {
|
|
91462
|
+
handler: (ctx) => handleDoctorToolsCommand(ctx.directory, ctx.args),
|
|
91463
|
+
description: "Run tool registration coherence check",
|
|
91464
|
+
category: "diagnostics",
|
|
91465
|
+
aliasOf: "doctor tools",
|
|
91466
|
+
deprecated: true
|
|
91467
|
+
},
|
|
91452
91468
|
diagnose: {
|
|
91453
91469
|
handler: (ctx) => handleDiagnoseCommand(ctx.directory, ctx.args),
|
|
91454
91470
|
description: "Run health check on swarm state",
|
|
@@ -95941,7 +95957,7 @@ COVERAGE REPORTING:
|
|
|
95941
95957
|
`;
|
|
95942
95958
|
|
|
95943
95959
|
// src/agents/index.ts
|
|
95944
|
-
import { mkdir as
|
|
95960
|
+
import { mkdir as mkdir18, writeFile as writeFile15 } from "node:fs/promises";
|
|
95945
95961
|
import * as path87 from "node:path";
|
|
95946
95962
|
function stripSwarmPrefix(agentName, swarmPrefix) {
|
|
95947
95963
|
if (!swarmPrefix || !agentName)
|
|
@@ -96421,7 +96437,7 @@ function getAgentConfigs(config3, directory, sessionId, projectContext) {
|
|
|
96421
96437
|
generatedAt: new Date().toISOString(),
|
|
96422
96438
|
agents: agentToolSnapshot
|
|
96423
96439
|
}, null, 2);
|
|
96424
|
-
|
|
96440
|
+
mkdir18(evidenceDir, { recursive: true }).then(() => writeFile15(path87.join(evidenceDir, filename), snapshotData)).catch(() => {});
|
|
96425
96441
|
}
|
|
96426
96442
|
return result;
|
|
96427
96443
|
}
|
|
@@ -96461,12 +96477,12 @@ __export(exports_evidence_summary_integration, {
|
|
|
96461
96477
|
createEvidenceSummaryIntegration: () => createEvidenceSummaryIntegration,
|
|
96462
96478
|
EvidenceSummaryIntegration: () => EvidenceSummaryIntegration
|
|
96463
96479
|
});
|
|
96464
|
-
import { existsSync as
|
|
96480
|
+
import { existsSync as existsSync48, mkdirSync as mkdirSync24, writeFileSync as writeFileSync14 } from "node:fs";
|
|
96465
96481
|
import * as path88 from "node:path";
|
|
96466
96482
|
function persistSummary(projectDir, artifact, filename) {
|
|
96467
96483
|
const swarmPath = path88.join(projectDir, ".swarm");
|
|
96468
|
-
if (!
|
|
96469
|
-
|
|
96484
|
+
if (!existsSync48(swarmPath)) {
|
|
96485
|
+
mkdirSync24(swarmPath, { recursive: true });
|
|
96470
96486
|
}
|
|
96471
96487
|
const artifactPath = path88.join(swarmPath, filename);
|
|
96472
96488
|
const content = JSON.stringify(artifact, null, 2);
|
|
@@ -97477,8 +97493,8 @@ var init_schema3 = __esm(() => {
|
|
|
97477
97493
|
|
|
97478
97494
|
// src/summaries/store.ts
|
|
97479
97495
|
import {
|
|
97480
|
-
existsSync as
|
|
97481
|
-
mkdirSync as
|
|
97496
|
+
existsSync as existsSync60,
|
|
97497
|
+
mkdirSync as mkdirSync31,
|
|
97482
97498
|
readFileSync as readFileSync41,
|
|
97483
97499
|
renameSync as renameSync20,
|
|
97484
97500
|
unlinkSync as unlinkSync15,
|
|
@@ -97486,13 +97502,13 @@ import {
|
|
|
97486
97502
|
} from "node:fs";
|
|
97487
97503
|
import * as path101 from "node:path";
|
|
97488
97504
|
function writeRawSidecar(absPath, bundle) {
|
|
97489
|
-
|
|
97505
|
+
mkdirSync31(path101.dirname(absPath), { recursive: true });
|
|
97490
97506
|
const tempFile = `${absPath}.tmp-${Date.now()}-${process.pid}`;
|
|
97491
97507
|
try {
|
|
97492
97508
|
writeFileSync21(tempFile, JSON.stringify(bundle, null, 2), "utf-8");
|
|
97493
97509
|
renameSync20(tempFile, absPath);
|
|
97494
97510
|
} finally {
|
|
97495
|
-
if (
|
|
97511
|
+
if (existsSync60(tempFile)) {
|
|
97496
97512
|
try {
|
|
97497
97513
|
unlinkSync15(tempFile);
|
|
97498
97514
|
} catch {}
|
|
@@ -97579,7 +97595,7 @@ function readSupervisorReportRaw(directory, phase) {
|
|
|
97579
97595
|
} catch {
|
|
97580
97596
|
return null;
|
|
97581
97597
|
}
|
|
97582
|
-
if (!
|
|
97598
|
+
if (!existsSync60(abs))
|
|
97583
97599
|
return null;
|
|
97584
97600
|
try {
|
|
97585
97601
|
const parsed = JSON.parse(readFileSync41(abs, "utf-8"));
|
|
@@ -100976,7 +100992,7 @@ __export(exports_runtime, {
|
|
|
100976
100992
|
clearParserCache: () => clearParserCache,
|
|
100977
100993
|
_internals: () => _internals68
|
|
100978
100994
|
});
|
|
100979
|
-
import { existsSync as
|
|
100995
|
+
import { existsSync as existsSync65, statSync as statSync26 } from "node:fs";
|
|
100980
100996
|
import * as path114 from "node:path";
|
|
100981
100997
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
100982
100998
|
async function initTreeSitter() {
|
|
@@ -101044,7 +101060,7 @@ async function loadGrammar(languageId) {
|
|
|
101044
101060
|
const parser = new Parser;
|
|
101045
101061
|
const wasmFileName = getWasmFileName(normalizedId);
|
|
101046
101062
|
const wasmPath = path114.join(getGrammarsDirAbsolute(), wasmFileName);
|
|
101047
|
-
if (!
|
|
101063
|
+
if (!existsSync65(wasmPath)) {
|
|
101048
101064
|
throw new Error(`Grammar file not found for ${languageId}: ${wasmPath}
|
|
101049
101065
|
` + `Make sure to run 'bun run build' to copy grammar files to dist/lang/grammars/`);
|
|
101050
101066
|
}
|
|
@@ -101085,7 +101101,7 @@ async function isGrammarAvailable(languageId) {
|
|
|
101085
101101
|
try {
|
|
101086
101102
|
const wasmFileName = getWasmFileName(normalizedId);
|
|
101087
101103
|
const wasmPath = path114.join(getGrammarsDirAbsolute(), wasmFileName);
|
|
101088
|
-
|
|
101104
|
+
statSync26(wasmPath);
|
|
101089
101105
|
return true;
|
|
101090
101106
|
} catch {
|
|
101091
101107
|
return false;
|
|
@@ -101147,11 +101163,11 @@ __export(exports_doc_scan, {
|
|
|
101147
101163
|
import * as crypto9 from "node:crypto";
|
|
101148
101164
|
import * as fs67 from "node:fs";
|
|
101149
101165
|
import {
|
|
101150
|
-
mkdir as
|
|
101151
|
-
readdir as
|
|
101166
|
+
mkdir as mkdir21,
|
|
101167
|
+
readdir as readdir7,
|
|
101152
101168
|
readFile as readFile22,
|
|
101153
101169
|
realpath as realpath3,
|
|
101154
|
-
stat as
|
|
101170
|
+
stat as stat10,
|
|
101155
101171
|
writeFile as writeFile17
|
|
101156
101172
|
} from "node:fs/promises";
|
|
101157
101173
|
import * as path116 from "node:path";
|
|
@@ -101234,8 +101250,8 @@ async function scanDocIndex(directory) {
|
|
|
101234
101250
|
for (const file3 of existingManifest.files) {
|
|
101235
101251
|
try {
|
|
101236
101252
|
const fullPath = path116.join(directory, file3.path);
|
|
101237
|
-
const
|
|
101238
|
-
if (
|
|
101253
|
+
const stat11 = fs67.statSync(fullPath);
|
|
101254
|
+
if (stat11.mtimeMs > file3.mtime) {
|
|
101239
101255
|
cacheValid = false;
|
|
101240
101256
|
break;
|
|
101241
101257
|
}
|
|
@@ -101255,7 +101271,7 @@ async function scanDocIndex(directory) {
|
|
|
101255
101271
|
const walkDir2 = async (dir) => {
|
|
101256
101272
|
let entries;
|
|
101257
101273
|
try {
|
|
101258
|
-
entries = await
|
|
101274
|
+
entries = await readdir7(dir, { withFileTypes: true });
|
|
101259
101275
|
if (dir === directory)
|
|
101260
101276
|
rootReadable = true;
|
|
101261
101277
|
} catch {
|
|
@@ -101273,7 +101289,7 @@ async function scanDocIndex(directory) {
|
|
|
101273
101289
|
const rel = path116.relative(resolvedDirectory, resolved);
|
|
101274
101290
|
if (rel.startsWith("..") || path116.isAbsolute(rel))
|
|
101275
101291
|
continue;
|
|
101276
|
-
const targetStat = await
|
|
101292
|
+
const targetStat = await stat10(symlinkPath);
|
|
101277
101293
|
isFile = targetStat.isFile();
|
|
101278
101294
|
} catch {
|
|
101279
101295
|
continue;
|
|
@@ -101302,7 +101318,7 @@ async function scanDocIndex(directory) {
|
|
|
101302
101318
|
continue;
|
|
101303
101319
|
let fileStat;
|
|
101304
101320
|
try {
|
|
101305
|
-
fileStat = await
|
|
101321
|
+
fileStat = await stat10(fullPath);
|
|
101306
101322
|
} catch {
|
|
101307
101323
|
continue;
|
|
101308
101324
|
}
|
|
@@ -101349,7 +101365,7 @@ async function scanDocIndex(directory) {
|
|
|
101349
101365
|
files: discoveredFiles
|
|
101350
101366
|
};
|
|
101351
101367
|
try {
|
|
101352
|
-
await
|
|
101368
|
+
await mkdir21(path116.dirname(manifestPath), { recursive: true });
|
|
101353
101369
|
await writeFile17(manifestPath, JSON.stringify(manifest, null, 2), "utf-8");
|
|
101354
101370
|
} catch {}
|
|
101355
101371
|
return { manifest, cached: false };
|
|
@@ -101563,7 +101579,7 @@ var init_doc_scan = __esm(() => {
|
|
|
101563
101579
|
});
|
|
101564
101580
|
|
|
101565
101581
|
// src/hooks/knowledge-reader.ts
|
|
101566
|
-
import { existsSync as
|
|
101582
|
+
import { existsSync as existsSync66 } from "node:fs";
|
|
101567
101583
|
import { readFile as readFile23 } from "node:fs/promises";
|
|
101568
101584
|
import * as path117 from "node:path";
|
|
101569
101585
|
function inferCategoriesFromPhase(phaseDescription) {
|
|
@@ -101611,7 +101627,7 @@ function inferCategoriesFromPhase(phaseDescription) {
|
|
|
101611
101627
|
}
|
|
101612
101628
|
async function transactShownFile(shownFile, mutate) {
|
|
101613
101629
|
return transactFile(shownFile, async (filePath) => {
|
|
101614
|
-
if (!
|
|
101630
|
+
if (!existsSync66(filePath))
|
|
101615
101631
|
return {};
|
|
101616
101632
|
try {
|
|
101617
101633
|
const content = await readFile23(filePath, "utf-8");
|
|
@@ -101741,7 +101757,7 @@ async function readMergedKnowledge(directory, config3, context, opts) {
|
|
|
101741
101757
|
async function updateRetrievalOutcome(directory, phaseInfo, phaseSucceeded) {
|
|
101742
101758
|
const shownFile = path117.join(directory, ".swarm", ".knowledge-shown.json");
|
|
101743
101759
|
try {
|
|
101744
|
-
if (!
|
|
101760
|
+
if (!existsSync66(shownFile)) {
|
|
101745
101761
|
return;
|
|
101746
101762
|
}
|
|
101747
101763
|
let shownIds;
|
|
@@ -102521,8 +102537,8 @@ async function runDesignDocDriftCheck(directory, phase, outDir) {
|
|
|
102521
102537
|
const traceabilityAbs = path162.join(outAbs, TRACEABILITY_REL);
|
|
102522
102538
|
let registry3 = null;
|
|
102523
102539
|
try {
|
|
102524
|
-
const
|
|
102525
|
-
if (
|
|
102540
|
+
const stat12 = await fs109.promises.stat(traceabilityAbs);
|
|
102541
|
+
if (stat12.size <= MAX_TRACEABILITY_BYTES) {
|
|
102526
102542
|
const raw = await fs109.promises.readFile(traceabilityAbs, "utf-8");
|
|
102527
102543
|
const parsed = JSON.parse(raw);
|
|
102528
102544
|
registry3 = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
@@ -103821,6 +103837,7 @@ function createBackgroundCompletionObserver(opts) {
|
|
|
103821
103837
|
init_pr_subscriptions();
|
|
103822
103838
|
init_commands();
|
|
103823
103839
|
init_config();
|
|
103840
|
+
init_bundled_skills();
|
|
103824
103841
|
init_constants();
|
|
103825
103842
|
|
|
103826
103843
|
// src/config/project-init.ts
|
|
@@ -103835,8 +103852,8 @@ function writeProjectConfigIfNew(directory, quiet = false) {
|
|
|
103835
103852
|
const dest = path91.join(opencodeDir, "opencode-swarm.json");
|
|
103836
103853
|
const normalizePathForCompare = (p) => process.platform === "win32" ? p.toLowerCase() : p;
|
|
103837
103854
|
try {
|
|
103838
|
-
const
|
|
103839
|
-
if (
|
|
103855
|
+
const stat8 = fs49.lstatSync(opencodeDir);
|
|
103856
|
+
if (stat8.isSymbolicLink())
|
|
103840
103857
|
return;
|
|
103841
103858
|
const resolvedDir = fs49.realpathSync(opencodeDir);
|
|
103842
103859
|
const canonicalOpencode = path91.join(fs49.realpathSync(directory), ".opencode");
|
|
@@ -104009,8 +104026,8 @@ function extractFileSummary(filePath, content, absolutePath, existingEntry) {
|
|
|
104009
104026
|
let mtimeMs = 0;
|
|
104010
104027
|
if (absolutePath) {
|
|
104011
104028
|
try {
|
|
104012
|
-
const
|
|
104013
|
-
mtimeMs =
|
|
104029
|
+
const stat8 = fs51.statSync(absolutePath);
|
|
104030
|
+
mtimeMs = stat8.mtimeMs;
|
|
104014
104031
|
} catch {}
|
|
104015
104032
|
}
|
|
104016
104033
|
const base = {
|
|
@@ -106962,8 +106979,8 @@ function createPhaseMonitorHook(directory, preflightManager, curatorRunner, dele
|
|
|
106962
106979
|
const initResult = await runner(directory, curatorConfig, llmDelegate);
|
|
106963
106980
|
if (initResult.briefing) {
|
|
106964
106981
|
const briefingPath = path102.join(directory, ".swarm", "curator-briefing.md");
|
|
106965
|
-
const { mkdir:
|
|
106966
|
-
await
|
|
106982
|
+
const { mkdir: mkdir19, writeFile: writeFile16 } = await import("node:fs/promises");
|
|
106983
|
+
await mkdir19(path102.dirname(briefingPath), { recursive: true });
|
|
106967
106984
|
await writeFile16(briefingPath, initResult.briefing, "utf-8");
|
|
106968
106985
|
const { buildApprovedReceipt: buildApprovedReceipt2, persistReviewReceipt: persistReviewReceipt2 } = await Promise.resolve().then(() => (init_review_receipt(), exports_review_receipt));
|
|
106969
106986
|
const initReceipt = buildApprovedReceipt2({
|
|
@@ -107105,7 +107122,7 @@ import * as path111 from "node:path";
|
|
|
107105
107122
|
init_logger();
|
|
107106
107123
|
init_path_security();
|
|
107107
107124
|
import * as fsSync7 from "node:fs";
|
|
107108
|
-
import { existsSync as
|
|
107125
|
+
import { existsSync as existsSync61, realpathSync as realpathSync13 } from "node:fs";
|
|
107109
107126
|
import * as fsPromises5 from "node:fs/promises";
|
|
107110
107127
|
import * as os15 from "node:os";
|
|
107111
107128
|
import * as path106 from "node:path";
|
|
@@ -107778,15 +107795,15 @@ function classifyDataOperation(line) {
|
|
|
107778
107795
|
const lower = trimmed.toLowerCase();
|
|
107779
107796
|
const evidence = trimmed.slice(0, 160);
|
|
107780
107797
|
let operation = null;
|
|
107781
|
-
let
|
|
107798
|
+
let access5 = "unknown";
|
|
107782
107799
|
let entity;
|
|
107783
107800
|
if (/\b(transaction|begintransaction|commit|rollback)\b/i.test(trimmed)) {
|
|
107784
107801
|
operation = "transaction";
|
|
107785
|
-
|
|
107802
|
+
access5 = "database";
|
|
107786
107803
|
}
|
|
107787
107804
|
if (/\b(migrate|migration|schema\.alter|createTable|dropTable)\b/i.test(trimmed)) {
|
|
107788
107805
|
operation = "migration";
|
|
107789
|
-
|
|
107806
|
+
access5 = "database";
|
|
107790
107807
|
}
|
|
107791
107808
|
if (/\b(findMany|findUnique|findFirst|select|query|count|aggregate)\b/.test(trimmed)) {
|
|
107792
107809
|
operation ??= "read";
|
|
@@ -107798,17 +107815,17 @@ function classifyDataOperation(line) {
|
|
|
107798
107815
|
operation = "delete";
|
|
107799
107816
|
}
|
|
107800
107817
|
if (/\b(sql`|\bselect\b|\binsert\b|\bupdate\b|\bdelete\b|\bfrom\b)/i.test(trimmed)) {
|
|
107801
|
-
|
|
107818
|
+
access5 = "sql";
|
|
107802
107819
|
}
|
|
107803
107820
|
if (/\b(prisma|drizzle|sequelize|knex|db\.|database\.|repository\.)/i.test(trimmed)) {
|
|
107804
|
-
|
|
107821
|
+
access5 = access5 === "sql" ? "sql" : "orm";
|
|
107805
107822
|
}
|
|
107806
107823
|
if (/\b(readFile|writeFile|appendFile|rmSync|unlink)\b/.test(trimmed)) {
|
|
107807
|
-
|
|
107824
|
+
access5 = "filesystem";
|
|
107808
107825
|
operation ??= lower.includes("read") ? "read" : "write";
|
|
107809
107826
|
}
|
|
107810
107827
|
if (/\b(fetch|axios|http\.|https\.)\b/.test(trimmed)) {
|
|
107811
|
-
|
|
107828
|
+
access5 = "network";
|
|
107812
107829
|
operation ??= "read";
|
|
107813
107830
|
}
|
|
107814
107831
|
const entityMatch = trimmed.match(/\b(?:prisma|db|database)\.(\w+)/i);
|
|
@@ -107816,7 +107833,7 @@ function classifyDataOperation(line) {
|
|
|
107816
107833
|
entity = entityMatch[1];
|
|
107817
107834
|
if (!operation)
|
|
107818
107835
|
return null;
|
|
107819
|
-
return { operation, access:
|
|
107836
|
+
return { operation, access: access5, entity, line: 0, evidence };
|
|
107820
107837
|
}
|
|
107821
107838
|
function extractDataOperations(content) {
|
|
107822
107839
|
const facts = [];
|
|
@@ -108355,7 +108372,7 @@ function resolveModuleSpecifier(workspaceRoot, sourceFile, specifier) {
|
|
|
108355
108372
|
if (realRoot === null) {
|
|
108356
108373
|
return null;
|
|
108357
108374
|
}
|
|
108358
|
-
if (!
|
|
108375
|
+
if (!existsSync61(resolved)) {
|
|
108359
108376
|
const EXTENSIONS = [
|
|
108360
108377
|
".ts",
|
|
108361
108378
|
".tsx",
|
|
@@ -108369,7 +108386,7 @@ function resolveModuleSpecifier(workspaceRoot, sourceFile, specifier) {
|
|
|
108369
108386
|
let found = null;
|
|
108370
108387
|
for (const ext of EXTENSIONS) {
|
|
108371
108388
|
const candidate = resolved + ext;
|
|
108372
|
-
if (
|
|
108389
|
+
if (existsSync61(candidate)) {
|
|
108373
108390
|
found = candidate;
|
|
108374
108391
|
break;
|
|
108375
108392
|
}
|
|
@@ -108754,7 +108771,7 @@ async function buildWorkspaceGraphAsync(workspaceRoot, options) {
|
|
|
108754
108771
|
const walkBudgetMs = options?.walkBudgetMs ?? DEFAULT_WALK_BUDGET_MS;
|
|
108755
108772
|
const followSymlinks = options?.followSymlinks ?? false;
|
|
108756
108773
|
const absoluteRoot = path106.resolve(workspaceRoot);
|
|
108757
|
-
if (!
|
|
108774
|
+
if (!existsSync61(absoluteRoot)) {
|
|
108758
108775
|
throw new Error(`Workspace directory does not exist: ${workspaceRoot}`);
|
|
108759
108776
|
}
|
|
108760
108777
|
if (isRefusedWorkspaceRoot(absoluteRoot)) {
|
|
@@ -108839,7 +108856,7 @@ function getCachedMtime(workspace) {
|
|
|
108839
108856
|
}
|
|
108840
108857
|
// src/tools/repo-graph/incremental.ts
|
|
108841
108858
|
init_logger();
|
|
108842
|
-
import { existsSync as
|
|
108859
|
+
import { existsSync as existsSync63 } from "node:fs";
|
|
108843
108860
|
import * as fsPromises7 from "node:fs/promises";
|
|
108844
108861
|
import * as path110 from "node:path";
|
|
108845
108862
|
|
|
@@ -109298,7 +109315,7 @@ function buildOntologyPreflightPacket(graph, filePaths = [], options = {}) {
|
|
|
109298
109315
|
init_utils2();
|
|
109299
109316
|
init_logger();
|
|
109300
109317
|
init_path_security();
|
|
109301
|
-
import { constants as constants5, existsSync as
|
|
109318
|
+
import { constants as constants5, existsSync as existsSync62, readFileSync as readFileSync44, statSync as statSync24 } from "node:fs";
|
|
109302
109319
|
import * as fsPromises6 from "node:fs/promises";
|
|
109303
109320
|
import * as path109 from "node:path";
|
|
109304
109321
|
var _internals67 = {
|
|
@@ -109358,7 +109375,7 @@ async function loadGraph(workspace) {
|
|
|
109358
109375
|
if (cached3 && !isDirty(normalized)) {
|
|
109359
109376
|
try {
|
|
109360
109377
|
const graphPath = getGraphPath(workspace);
|
|
109361
|
-
if (
|
|
109378
|
+
if (existsSync62(graphPath)) {
|
|
109362
109379
|
const stats = await fsPromises6.stat(graphPath);
|
|
109363
109380
|
const cachedMtime = getCachedMtime(normalized);
|
|
109364
109381
|
if (cachedMtime !== undefined && stats.mtimeMs !== cachedMtime) {
|
|
@@ -109375,7 +109392,7 @@ async function loadGraph(workspace) {
|
|
|
109375
109392
|
}
|
|
109376
109393
|
try {
|
|
109377
109394
|
const graphPath = getGraphPath(workspace);
|
|
109378
|
-
if (!
|
|
109395
|
+
if (!existsSync62(graphPath)) {
|
|
109379
109396
|
return null;
|
|
109380
109397
|
}
|
|
109381
109398
|
const stats = await fsPromises6.stat(graphPath);
|
|
@@ -109409,9 +109426,9 @@ function loadGraphSync(workspace) {
|
|
|
109409
109426
|
const normalized = path109.normalize(workspace);
|
|
109410
109427
|
try {
|
|
109411
109428
|
const graphPath = getGraphPath(workspace);
|
|
109412
|
-
if (!
|
|
109429
|
+
if (!existsSync62(graphPath))
|
|
109413
109430
|
return null;
|
|
109414
|
-
const stats =
|
|
109431
|
+
const stats = statSync24(graphPath);
|
|
109415
109432
|
const content = readFileSync44(graphPath, "utf-8");
|
|
109416
109433
|
if (content.includes("\x00") || content.includes("�")) {
|
|
109417
109434
|
throw Object.assign(new Error("repo-graph.json contains null bytes or invalid encoding"), { code: "CORRUPTION" });
|
|
@@ -109535,7 +109552,7 @@ async function updateGraphForFiles(workspaceRoot, filePaths, options) {
|
|
|
109535
109552
|
const updatedPaths = new Set;
|
|
109536
109553
|
for (const rawFilePath of filePaths) {
|
|
109537
109554
|
const normalizedPath = normalizeGraphPath(rawFilePath);
|
|
109538
|
-
const fileExists =
|
|
109555
|
+
const fileExists = existsSync63(rawFilePath);
|
|
109539
109556
|
if (fileExists) {
|
|
109540
109557
|
graph.edges = graph.edges.filter((e) => normalizeGraphPath(e.source) !== normalizedPath);
|
|
109541
109558
|
const result = scanFile(rawFilePath, absoluteRoot, maxFileSize);
|
|
@@ -109575,7 +109592,7 @@ async function updateGraphForFiles(workspaceRoot, filePaths, options) {
|
|
|
109575
109592
|
if (loadedMtime !== undefined) {
|
|
109576
109593
|
try {
|
|
109577
109594
|
const graphPath = getGraphPath(workspaceRoot);
|
|
109578
|
-
if (
|
|
109595
|
+
if (existsSync63(graphPath)) {
|
|
109579
109596
|
const currentStats = await fsPromises7.stat(graphPath);
|
|
109580
109597
|
if (currentStats.mtimeMs !== loadedMtime) {
|
|
109581
109598
|
warn(`[repo-graph] Concurrent modification detected — falling back to full rebuild`);
|
|
@@ -110411,15 +110428,15 @@ import * as fs65 from "node:fs";
|
|
|
110411
110428
|
var cache2 = new Map;
|
|
110412
110429
|
function getCachedGraph2(directory) {
|
|
110413
110430
|
const file3 = getGraphPath(directory);
|
|
110414
|
-
let
|
|
110431
|
+
let stat10;
|
|
110415
110432
|
try {
|
|
110416
|
-
|
|
110433
|
+
stat10 = fs65.statSync(file3);
|
|
110417
110434
|
} catch {
|
|
110418
110435
|
cache2.delete(directory);
|
|
110419
110436
|
return null;
|
|
110420
110437
|
}
|
|
110421
110438
|
const cached3 = cache2.get(directory);
|
|
110422
|
-
if (cached3 && cached3.mtimeMs ===
|
|
110439
|
+
if (cached3 && cached3.mtimeMs === stat10.mtimeMs && cached3.size === stat10.size) {
|
|
110423
110440
|
return cached3.graph;
|
|
110424
110441
|
}
|
|
110425
110442
|
let graph;
|
|
@@ -110433,7 +110450,7 @@ function getCachedGraph2(directory) {
|
|
|
110433
110450
|
cache2.delete(directory);
|
|
110434
110451
|
return null;
|
|
110435
110452
|
}
|
|
110436
|
-
cache2.set(directory, { graph, mtimeMs:
|
|
110453
|
+
cache2.set(directory, { graph, mtimeMs: stat10.mtimeMs, size: stat10.size });
|
|
110437
110454
|
return graph;
|
|
110438
110455
|
}
|
|
110439
110456
|
function buildCoderLocalizationBlock(directory, targetFile) {
|
|
@@ -112870,7 +112887,7 @@ import * as path120 from "node:path";
|
|
|
112870
112887
|
|
|
112871
112888
|
// src/turbo/lean/evidence.ts
|
|
112872
112889
|
init_bun_compat();
|
|
112873
|
-
import { rmSync as
|
|
112890
|
+
import { rmSync as rmSync6 } from "node:fs";
|
|
112874
112891
|
import * as fs69 from "node:fs/promises";
|
|
112875
112892
|
import * as path119 from "node:path";
|
|
112876
112893
|
function leanTurboEvidenceDir(directory, phase) {
|
|
@@ -112913,7 +112930,7 @@ async function atomicWriteJson(filePath, data) {
|
|
|
112913
112930
|
await fs69.rename(tempPath, filePath);
|
|
112914
112931
|
} catch (error93) {
|
|
112915
112932
|
try {
|
|
112916
|
-
|
|
112933
|
+
rmSync6(tempPath, { force: true });
|
|
112917
112934
|
} catch {}
|
|
112918
112935
|
throw error93;
|
|
112919
112936
|
}
|
|
@@ -113822,7 +113839,7 @@ function createDarkMatterDetectorHook(directory) {
|
|
|
113822
113839
|
}
|
|
113823
113840
|
|
|
113824
113841
|
// src/hooks/delegate-ack-collector.ts
|
|
113825
|
-
import { appendFile as appendFile13, mkdir as
|
|
113842
|
+
import { appendFile as appendFile13, mkdir as mkdir25 } from "node:fs/promises";
|
|
113826
113843
|
import * as path123 from "node:path";
|
|
113827
113844
|
|
|
113828
113845
|
// src/hooks/knowledge-application.ts
|
|
@@ -113830,8 +113847,8 @@ init_task_file();
|
|
|
113830
113847
|
init_logger();
|
|
113831
113848
|
init_knowledge_store();
|
|
113832
113849
|
var import_proper_lockfile9 = __toESM(require_proper_lockfile(), 1);
|
|
113833
|
-
import { existsSync as
|
|
113834
|
-
import { appendFile as appendFile11, mkdir as
|
|
113850
|
+
import { existsSync as existsSync69 } from "node:fs";
|
|
113851
|
+
import { appendFile as appendFile11, mkdir as mkdir24, readFile as readFile25 } from "node:fs/promises";
|
|
113835
113852
|
import * as path121 from "node:path";
|
|
113836
113853
|
function resolveApplicationLogPath(directory) {
|
|
113837
113854
|
return path121.join(directory, ".swarm", "knowledge-application.jsonl");
|
|
@@ -113854,7 +113871,7 @@ function parseAcknowledgments(text) {
|
|
|
113854
113871
|
async function appendAudit(directory, record3) {
|
|
113855
113872
|
const filePath = resolveApplicationLogPath(directory);
|
|
113856
113873
|
const dirPath = path121.dirname(filePath);
|
|
113857
|
-
await
|
|
113874
|
+
await mkdir24(dirPath, { recursive: true });
|
|
113858
113875
|
let release;
|
|
113859
113876
|
try {
|
|
113860
113877
|
release = await import_proper_lockfile9.default.lock(dirPath, {
|
|
@@ -113915,7 +113932,7 @@ async function bumpCountersBatch(directory, bumps) {
|
|
|
113915
113932
|
const swarmPath = resolveSwarmKnowledgePath(directory);
|
|
113916
113933
|
await transactKnowledge(swarmPath, (swarm) => applyOne(swarm) ? swarm : null);
|
|
113917
113934
|
const hivePath = resolveHiveKnowledgePath();
|
|
113918
|
-
if (
|
|
113935
|
+
if (existsSync69(hivePath)) {
|
|
113919
113936
|
await transactKnowledge(hivePath, (hive) => applyOne(hive) ? hive : null);
|
|
113920
113937
|
}
|
|
113921
113938
|
}
|
|
@@ -114714,7 +114731,7 @@ function extractTaskId2(prompt) {
|
|
|
114714
114731
|
}
|
|
114715
114732
|
async function appendUnacknowledgedCritical(directory, record3) {
|
|
114716
114733
|
const filePath = validateSwarmPath(directory, "unacknowledged-criticals.jsonl");
|
|
114717
|
-
await
|
|
114734
|
+
await mkdir25(path123.dirname(filePath), { recursive: true });
|
|
114718
114735
|
await appendFile13(filePath, `${JSON.stringify(record3)}
|
|
114719
114736
|
`, "utf-8");
|
|
114720
114737
|
}
|
|
@@ -114889,7 +114906,7 @@ init_extractors();
|
|
|
114889
114906
|
// src/hooks/phase-directives.ts
|
|
114890
114907
|
init_knowledge_events();
|
|
114891
114908
|
init_knowledge_store();
|
|
114892
|
-
import { existsSync as
|
|
114909
|
+
import { existsSync as existsSync70 } from "node:fs";
|
|
114893
114910
|
async function collectPhaseDirectiveIds(directory, phaseLabel) {
|
|
114894
114911
|
const events = await readKnowledgeEvents(directory);
|
|
114895
114912
|
const ids = new Set;
|
|
@@ -114909,7 +114926,7 @@ async function readEntriesById(directory) {
|
|
|
114909
114926
|
for (const e of swarm)
|
|
114910
114927
|
map3.set(e.id, e);
|
|
114911
114928
|
const hivePath = resolveHiveKnowledgePath();
|
|
114912
|
-
if (
|
|
114929
|
+
if (existsSync70(hivePath)) {
|
|
114913
114930
|
const hive = await readKnowledge(hivePath);
|
|
114914
114931
|
for (const e of hive)
|
|
114915
114932
|
if (!map3.has(e.id))
|
|
@@ -116670,7 +116687,7 @@ ${errorSummary}`);
|
|
|
116670
116687
|
init_schema();
|
|
116671
116688
|
init_state();
|
|
116672
116689
|
init_logger();
|
|
116673
|
-
import { appendFile as appendFile14, mkdir as
|
|
116690
|
+
import { appendFile as appendFile14, mkdir as mkdir26 } from "node:fs/promises";
|
|
116674
116691
|
import * as path126 from "node:path";
|
|
116675
116692
|
var HIGH_RISK_TOOLS = new Set([
|
|
116676
116693
|
"save_plan",
|
|
@@ -116742,7 +116759,7 @@ async function knowledgeApplicationGateBefore(directory, input, config3) {
|
|
|
116742
116759
|
}
|
|
116743
116760
|
async function writeWarnEvent2(directory, record3) {
|
|
116744
116761
|
const filePath = path126.join(directory, ".swarm", "events.jsonl");
|
|
116745
|
-
await
|
|
116762
|
+
await mkdir26(path126.dirname(filePath), { recursive: true });
|
|
116746
116763
|
await appendFile14(filePath, `${JSON.stringify(record3)}
|
|
116747
116764
|
`, "utf-8");
|
|
116748
116765
|
}
|
|
@@ -116800,7 +116817,7 @@ init_schema();
|
|
|
116800
116817
|
// src/services/directive-predicate-runner.ts
|
|
116801
116818
|
init_bun_compat();
|
|
116802
116819
|
init_logger();
|
|
116803
|
-
import { existsSync as
|
|
116820
|
+
import { existsSync as existsSync73 } from "node:fs";
|
|
116804
116821
|
import * as path127 from "node:path";
|
|
116805
116822
|
var PREDICATE_TIMEOUT_MS = 15000;
|
|
116806
116823
|
var TOOL_BINARY_ALLOWLIST = new Set([
|
|
@@ -116842,7 +116859,7 @@ function findBinaryInPath(binary2) {
|
|
|
116842
116859
|
if (!dir)
|
|
116843
116860
|
continue;
|
|
116844
116861
|
const candidate = path127.join(dir, exeName);
|
|
116845
|
-
if (
|
|
116862
|
+
if (existsSync73(candidate))
|
|
116846
116863
|
return candidate;
|
|
116847
116864
|
}
|
|
116848
116865
|
return null;
|
|
@@ -117731,8 +117748,8 @@ async function cleanupOldTrajectoryFiles(directory, maxAgeDays = 7) {
|
|
|
117731
117748
|
continue;
|
|
117732
117749
|
const filePath = path130.join(dirPath, entry.name);
|
|
117733
117750
|
try {
|
|
117734
|
-
const
|
|
117735
|
-
if (now -
|
|
117751
|
+
const stat12 = await fs80.stat(filePath);
|
|
117752
|
+
if (now - stat12.mtimeMs > cutoffMs) {
|
|
117736
117753
|
await fs80.unlink(filePath);
|
|
117737
117754
|
}
|
|
117738
117755
|
} catch {}
|
|
@@ -118918,13 +118935,13 @@ init_zod();
|
|
|
118918
118935
|
init_path_security();
|
|
118919
118936
|
init_create_tool();
|
|
118920
118937
|
import {
|
|
118921
|
-
existsSync as
|
|
118922
|
-
mkdirSync as
|
|
118938
|
+
existsSync as existsSync75,
|
|
118939
|
+
mkdirSync as mkdirSync32,
|
|
118923
118940
|
mkdtempSync as mkdtempSync2,
|
|
118924
118941
|
readFileSync as readFileSync50,
|
|
118925
118942
|
realpathSync as realpathSync16,
|
|
118926
118943
|
renameSync as renameSync24,
|
|
118927
|
-
rmdirSync
|
|
118944
|
+
rmdirSync,
|
|
118928
118945
|
unlinkSync as unlinkSync18,
|
|
118929
118946
|
writeFileSync as writeFileSync23
|
|
118930
118947
|
} from "node:fs";
|
|
@@ -119268,7 +119285,7 @@ function applyHunks(content, fileDiff) {
|
|
|
119268
119285
|
}
|
|
119269
119286
|
function atomicWriteFileSync2(targetPath, content) {
|
|
119270
119287
|
const dir = path133.dirname(targetPath);
|
|
119271
|
-
|
|
119288
|
+
mkdirSync32(dir, { recursive: true });
|
|
119272
119289
|
const tempPrefix = `.apply-patch-${Date.now()}-${process.pid}`;
|
|
119273
119290
|
let tempPath;
|
|
119274
119291
|
try {
|
|
@@ -119281,15 +119298,15 @@ function atomicWriteFileSync2(targetPath, content) {
|
|
|
119281
119298
|
writeFileSync23(tempPath, content, "utf-8");
|
|
119282
119299
|
renameSync24(tempPath, targetPath);
|
|
119283
119300
|
} finally {
|
|
119284
|
-
if (
|
|
119301
|
+
if (existsSync75(tempPath)) {
|
|
119285
119302
|
try {
|
|
119286
119303
|
unlinkSync18(tempPath);
|
|
119287
119304
|
} catch {}
|
|
119288
119305
|
}
|
|
119289
119306
|
const tempDir = path133.dirname(tempPath);
|
|
119290
|
-
if (tempDir !== dir &&
|
|
119307
|
+
if (tempDir !== dir && existsSync75(tempDir)) {
|
|
119291
119308
|
try {
|
|
119292
|
-
|
|
119309
|
+
rmdirSync(tempDir);
|
|
119293
119310
|
} catch {}
|
|
119294
119311
|
}
|
|
119295
119312
|
}
|
|
@@ -119364,7 +119381,7 @@ function processFileDiff(fileDiff, targetPath, fullPath, workspace, dryRun, allo
|
|
|
119364
119381
|
};
|
|
119365
119382
|
}
|
|
119366
119383
|
const parentDir = path133.dirname(fullPath);
|
|
119367
|
-
if (!
|
|
119384
|
+
if (!existsSync75(parentDir)) {
|
|
119368
119385
|
return {
|
|
119369
119386
|
file: targetPath,
|
|
119370
119387
|
status: "error",
|
|
@@ -119380,7 +119397,7 @@ function processFileDiff(fileDiff, targetPath, fullPath, workspace, dryRun, allo
|
|
|
119380
119397
|
]
|
|
119381
119398
|
};
|
|
119382
119399
|
}
|
|
119383
|
-
if (
|
|
119400
|
+
if (existsSync75(fullPath)) {
|
|
119384
119401
|
return {
|
|
119385
119402
|
file: targetPath,
|
|
119386
119403
|
status: "error",
|
|
@@ -119455,7 +119472,7 @@ function processFileDiff(fileDiff, targetPath, fullPath, workspace, dryRun, allo
|
|
|
119455
119472
|
]
|
|
119456
119473
|
};
|
|
119457
119474
|
}
|
|
119458
|
-
if (!
|
|
119475
|
+
if (!existsSync75(fullPath)) {
|
|
119459
119476
|
return {
|
|
119460
119477
|
file: targetPath,
|
|
119461
119478
|
status: "error",
|
|
@@ -119499,7 +119516,7 @@ function processFileDiff(fileDiff, targetPath, fullPath, workspace, dryRun, allo
|
|
|
119499
119516
|
hunksFailed: 0
|
|
119500
119517
|
};
|
|
119501
119518
|
}
|
|
119502
|
-
if (!
|
|
119519
|
+
if (!existsSync75(fullPath)) {
|
|
119503
119520
|
return {
|
|
119504
119521
|
file: targetPath,
|
|
119505
119522
|
status: "error",
|
|
@@ -119650,7 +119667,7 @@ var applyPatch = createSwarmTool({
|
|
|
119650
119667
|
const dryRun = obj.dryRun ?? false;
|
|
119651
119668
|
const allowCreates = obj.allowCreates ?? false;
|
|
119652
119669
|
const allowDeletes = obj.allowDeletes ?? false;
|
|
119653
|
-
if (!
|
|
119670
|
+
if (!existsSync75(directory)) {
|
|
119654
119671
|
return JSON.stringify(buildErrorResult("Workspace directory does not exist"), null, 2);
|
|
119655
119672
|
}
|
|
119656
119673
|
if (files.length === 0) {
|
|
@@ -120610,8 +120627,8 @@ function estimateCyclomaticComplexity(content) {
|
|
|
120610
120627
|
}
|
|
120611
120628
|
function getComplexityForFile(filePath) {
|
|
120612
120629
|
try {
|
|
120613
|
-
const
|
|
120614
|
-
if (
|
|
120630
|
+
const stat12 = fs86.statSync(filePath);
|
|
120631
|
+
if (stat12.size > MAX_FILE_SIZE_BYTES3) {
|
|
120615
120632
|
return null;
|
|
120616
120633
|
}
|
|
120617
120634
|
const content = fs86.readFileSync(filePath, "utf-8");
|
|
@@ -120812,8 +120829,8 @@ async function computeDuplicationRatio(files, workingDir) {
|
|
|
120812
120829
|
continue;
|
|
120813
120830
|
}
|
|
120814
120831
|
try {
|
|
120815
|
-
const
|
|
120816
|
-
if (
|
|
120832
|
+
const stat12 = fs86.statSync(fullPath);
|
|
120833
|
+
if (stat12.size > MAX_FILE_SIZE_BYTES3) {
|
|
120817
120834
|
continue;
|
|
120818
120835
|
}
|
|
120819
120836
|
const content = fs86.readFileSync(fullPath, "utf-8");
|
|
@@ -121273,8 +121290,8 @@ async function getGitChurn(days, directory) {
|
|
|
121273
121290
|
}
|
|
121274
121291
|
function getComplexityForFile2(filePath) {
|
|
121275
121292
|
try {
|
|
121276
|
-
const
|
|
121277
|
-
if (
|
|
121293
|
+
const stat12 = fs87.statSync(filePath);
|
|
121294
|
+
if (stat12.size > MAX_FILE_SIZE_BYTES4) {
|
|
121278
121295
|
return null;
|
|
121279
121296
|
}
|
|
121280
121297
|
const content = fs87.readFileSync(filePath, "utf-8");
|
|
@@ -121469,7 +121486,7 @@ ${body2}`);
|
|
|
121469
121486
|
// src/council/council-evidence-writer.ts
|
|
121470
121487
|
init_zod();
|
|
121471
121488
|
init_task_file();
|
|
121472
|
-
import { appendFileSync as appendFileSync15, existsSync as
|
|
121489
|
+
import { appendFileSync as appendFileSync15, existsSync as existsSync80, mkdirSync as mkdirSync34, readFileSync as readFileSync56 } from "node:fs";
|
|
121473
121490
|
import { join as join111 } from "node:path";
|
|
121474
121491
|
var EVIDENCE_DIR2 = ".swarm/evidence";
|
|
121475
121492
|
var VALID_TASK_ID = /^\d+\.\d+(\.\d+)*$/;
|
|
@@ -121509,11 +121526,11 @@ async function writeCouncilEvidence(workingDir, synthesis) {
|
|
|
121509
121526
|
throw new Error(`writeCouncilEvidence: invalid taskId "${synthesis.taskId}" — must match N.M or N.M.P format`);
|
|
121510
121527
|
}
|
|
121511
121528
|
const dir = join111(workingDir, EVIDENCE_DIR2);
|
|
121512
|
-
|
|
121529
|
+
mkdirSync34(dir, { recursive: true });
|
|
121513
121530
|
const filePath = taskEvidencePath(workingDir, synthesis.taskId);
|
|
121514
121531
|
await _internals77.withTaskEvidenceLock(workingDir, synthesis.taskId, COUNCIL_AGENT_ID, async () => {
|
|
121515
121532
|
const existingRoot = Object.create(null);
|
|
121516
|
-
if (
|
|
121533
|
+
if (existsSync80(filePath)) {
|
|
121517
121534
|
try {
|
|
121518
121535
|
const parsed = EvidenceFileSchema.parse(JSON.parse(readFileSync56(filePath, "utf-8")));
|
|
121519
121536
|
safeAssignOwnProps(existingRoot, parsed);
|
|
@@ -121545,7 +121562,7 @@ async function writeCouncilEvidence(workingDir, synthesis) {
|
|
|
121545
121562
|
});
|
|
121546
121563
|
try {
|
|
121547
121564
|
const councilDir = join111(workingDir, ".swarm", "council");
|
|
121548
|
-
|
|
121565
|
+
mkdirSync34(councilDir, { recursive: true });
|
|
121549
121566
|
const auditLine = JSON.stringify({
|
|
121550
121567
|
round: synthesis.roundNumber,
|
|
121551
121568
|
verdict: synthesis.overallVerdict,
|
|
@@ -121907,7 +121924,7 @@ function buildFinalCouncilFeedback(projectSummary, verdict, vetoedBy, requiredFi
|
|
|
121907
121924
|
|
|
121908
121925
|
// src/council/criteria-store.ts
|
|
121909
121926
|
init_zod();
|
|
121910
|
-
import { existsSync as
|
|
121927
|
+
import { existsSync as existsSync81, mkdirSync as mkdirSync35, readFileSync as readFileSync57, writeFileSync as writeFileSync25 } from "node:fs";
|
|
121911
121928
|
import { join as join112 } from "node:path";
|
|
121912
121929
|
var COUNCIL_DIR = ".swarm/council";
|
|
121913
121930
|
var CouncilCriteriaSchema = exports_external.object({
|
|
@@ -121921,7 +121938,7 @@ var CouncilCriteriaSchema = exports_external.object({
|
|
|
121921
121938
|
});
|
|
121922
121939
|
function writeCriteria(workingDir, taskId, criteria) {
|
|
121923
121940
|
const dir = join112(workingDir, COUNCIL_DIR);
|
|
121924
|
-
|
|
121941
|
+
mkdirSync35(dir, { recursive: true });
|
|
121925
121942
|
const payload = {
|
|
121926
121943
|
taskId,
|
|
121927
121944
|
criteria,
|
|
@@ -121931,7 +121948,7 @@ function writeCriteria(workingDir, taskId, criteria) {
|
|
|
121931
121948
|
}
|
|
121932
121949
|
function readCriteria(workingDir, taskId) {
|
|
121933
121950
|
const filePath = join112(workingDir, COUNCIL_DIR, `${safeId(taskId)}.json`);
|
|
121934
|
-
if (!
|
|
121951
|
+
if (!existsSync81(filePath))
|
|
121935
121952
|
return null;
|
|
121936
121953
|
try {
|
|
121937
121954
|
return CouncilCriteriaSchema.parse(JSON.parse(readFileSync57(filePath, "utf-8")));
|
|
@@ -123743,8 +123760,8 @@ function readEvidenceFiles(evidenceDir, _cwd) {
|
|
|
123743
123760
|
if (!resolvedPath.startsWith(evidenceDirResolved)) {
|
|
123744
123761
|
continue;
|
|
123745
123762
|
}
|
|
123746
|
-
const
|
|
123747
|
-
if (!
|
|
123763
|
+
const stat12 = fs92.lstatSync(filePath);
|
|
123764
|
+
if (!stat12.isFile()) {
|
|
123748
123765
|
continue;
|
|
123749
123766
|
}
|
|
123750
123767
|
} catch {
|
|
@@ -126253,8 +126270,8 @@ var git_blame = createSwarmTool({
|
|
|
126253
126270
|
lines: []
|
|
126254
126271
|
});
|
|
126255
126272
|
}
|
|
126256
|
-
const
|
|
126257
|
-
if (
|
|
126273
|
+
const stat12 = fs96.statSync(resolvedPath);
|
|
126274
|
+
if (stat12.isDirectory()) {
|
|
126258
126275
|
return JSON.stringify({
|
|
126259
126276
|
error: "path is a directory, not a file",
|
|
126260
126277
|
file: file3,
|
|
@@ -126774,9 +126791,9 @@ function findSourceFiles2(dir, files = [], stats = { skippedDirs: [], skippedFil
|
|
|
126774
126791
|
continue;
|
|
126775
126792
|
}
|
|
126776
126793
|
const fullPath = path149.join(dir, entry);
|
|
126777
|
-
let
|
|
126794
|
+
let stat12;
|
|
126778
126795
|
try {
|
|
126779
|
-
|
|
126796
|
+
stat12 = fs97.statSync(fullPath);
|
|
126780
126797
|
} catch (e) {
|
|
126781
126798
|
stats.fileErrors.push({
|
|
126782
126799
|
path: fullPath,
|
|
@@ -126784,9 +126801,9 @@ function findSourceFiles2(dir, files = [], stats = { skippedDirs: [], skippedFil
|
|
|
126784
126801
|
});
|
|
126785
126802
|
continue;
|
|
126786
126803
|
}
|
|
126787
|
-
if (
|
|
126804
|
+
if (stat12.isDirectory()) {
|
|
126788
126805
|
findSourceFiles2(fullPath, files, stats);
|
|
126789
|
-
} else if (
|
|
126806
|
+
} else if (stat12.isFile()) {
|
|
126790
126807
|
const ext = path149.extname(fullPath).toLowerCase();
|
|
126791
126808
|
if (SUPPORTED_EXTENSIONS3.includes(ext)) {
|
|
126792
126809
|
files.push(fullPath);
|
|
@@ -126881,8 +126898,8 @@ var imports = createSwarmTool({
|
|
|
126881
126898
|
if (consumers.length >= MAX_CONSUMERS)
|
|
126882
126899
|
break;
|
|
126883
126900
|
try {
|
|
126884
|
-
const
|
|
126885
|
-
if (
|
|
126901
|
+
const stat12 = fs97.statSync(filePath);
|
|
126902
|
+
if (stat12.size > MAX_FILE_SIZE_BYTES6) {
|
|
126886
126903
|
skippedFileCount++;
|
|
126887
126904
|
continue;
|
|
126888
126905
|
}
|
|
@@ -127336,7 +127353,7 @@ init_zod();
|
|
|
127336
127353
|
init_config();
|
|
127337
127354
|
init_knowledge_store();
|
|
127338
127355
|
init_create_tool();
|
|
127339
|
-
import { existsSync as
|
|
127356
|
+
import { existsSync as existsSync87 } from "node:fs";
|
|
127340
127357
|
var DEFAULT_LIMIT = 10;
|
|
127341
127358
|
var MAX_LESSON_LENGTH = 200;
|
|
127342
127359
|
var VALID_CATEGORIES3 = [
|
|
@@ -127412,14 +127429,14 @@ function validateLimit(limit) {
|
|
|
127412
127429
|
}
|
|
127413
127430
|
async function readSwarmKnowledge(directory) {
|
|
127414
127431
|
const swarmPath = resolveSwarmKnowledgePath(directory);
|
|
127415
|
-
if (!
|
|
127432
|
+
if (!existsSync87(swarmPath)) {
|
|
127416
127433
|
return [];
|
|
127417
127434
|
}
|
|
127418
127435
|
return readKnowledge(swarmPath);
|
|
127419
127436
|
}
|
|
127420
127437
|
async function readHiveKnowledge() {
|
|
127421
127438
|
const hivePath = resolveHiveKnowledgePath();
|
|
127422
|
-
if (!
|
|
127439
|
+
if (!existsSync87(hivePath)) {
|
|
127423
127440
|
return [];
|
|
127424
127441
|
}
|
|
127425
127442
|
return readKnowledge(hivePath);
|
|
@@ -134025,8 +134042,8 @@ async function placeholderScan(input, directory) {
|
|
|
134025
134042
|
}
|
|
134026
134043
|
let content;
|
|
134027
134044
|
try {
|
|
134028
|
-
const
|
|
134029
|
-
if (
|
|
134045
|
+
const stat12 = fs112.statSync(fullPath);
|
|
134046
|
+
if (stat12.size > MAX_FILE_SIZE) {
|
|
134030
134047
|
continue;
|
|
134031
134048
|
}
|
|
134032
134049
|
content = fs112.readFileSync(fullPath, "utf-8");
|
|
@@ -136365,14 +136382,14 @@ async function runSecretscanWithFiles(files, directory) {
|
|
|
136365
136382
|
skippedFiles++;
|
|
136366
136383
|
continue;
|
|
136367
136384
|
}
|
|
136368
|
-
let
|
|
136385
|
+
let stat12;
|
|
136369
136386
|
try {
|
|
136370
|
-
|
|
136387
|
+
stat12 = fs116.statSync(file3);
|
|
136371
136388
|
} catch {
|
|
136372
136389
|
skippedFiles++;
|
|
136373
136390
|
continue;
|
|
136374
136391
|
}
|
|
136375
|
-
if (
|
|
136392
|
+
if (stat12.size > MAX_FILE_SIZE_BYTES8) {
|
|
136376
136393
|
skippedFiles++;
|
|
136377
136394
|
continue;
|
|
136378
136395
|
}
|
|
@@ -137199,8 +137216,8 @@ function readTouchedFiles(evidenceDir, phase, cwd) {
|
|
|
137199
137216
|
for (const entry of entries) {
|
|
137200
137217
|
const entryPath = path171.join(evidenceDir, entry);
|
|
137201
137218
|
try {
|
|
137202
|
-
const
|
|
137203
|
-
if (!
|
|
137219
|
+
const stat12 = fs117.statSync(entryPath);
|
|
137220
|
+
if (!stat12.isDirectory()) {
|
|
137204
137221
|
continue;
|
|
137205
137222
|
}
|
|
137206
137223
|
} catch {
|
|
@@ -137220,11 +137237,11 @@ function readTouchedFiles(evidenceDir, phase, cwd) {
|
|
|
137220
137237
|
if (!resolvedPath.startsWith(evidenceDirResolved + path171.sep)) {
|
|
137221
137238
|
continue;
|
|
137222
137239
|
}
|
|
137223
|
-
const
|
|
137224
|
-
if (!
|
|
137240
|
+
const stat12 = fs117.lstatSync(evidenceFilePath);
|
|
137241
|
+
if (!stat12.isFile()) {
|
|
137225
137242
|
continue;
|
|
137226
137243
|
}
|
|
137227
|
-
if (
|
|
137244
|
+
if (stat12.size > MAX_FILE_SIZE_BYTES8) {
|
|
137228
137245
|
continue;
|
|
137229
137246
|
}
|
|
137230
137247
|
} catch {
|
|
@@ -140078,7 +140095,7 @@ init_zod();
|
|
|
140078
140095
|
init_config();
|
|
140079
140096
|
init_schema();
|
|
140080
140097
|
init_create_tool();
|
|
140081
|
-
import { mkdir as
|
|
140098
|
+
import { mkdir as mkdir31, rename as rename12, writeFile as writeFile21 } from "node:fs/promises";
|
|
140082
140099
|
import * as path176 from "node:path";
|
|
140083
140100
|
var MAX_SPEC_BYTES2 = 256 * 1024;
|
|
140084
140101
|
var spec_write = createSwarmTool({
|
|
@@ -140121,7 +140138,7 @@ var spec_write = createSwarmTool({
|
|
|
140121
140138
|
}, null, 2);
|
|
140122
140139
|
}
|
|
140123
140140
|
const target = path176.join(directory, ".swarm", "spec.md");
|
|
140124
|
-
await
|
|
140141
|
+
await mkdir31(path176.dirname(target), { recursive: true });
|
|
140125
140142
|
const tmp = `${target}.tmp-${process.pid}-${Date.now()}`;
|
|
140126
140143
|
let finalContent = content;
|
|
140127
140144
|
if (mode === "append") {
|
|
@@ -140150,8 +140167,8 @@ ${content}
|
|
|
140150
140167
|
init_zod();
|
|
140151
140168
|
init_loader();
|
|
140152
140169
|
import {
|
|
140153
|
-
existsSync as
|
|
140154
|
-
mkdirSync as
|
|
140170
|
+
existsSync as existsSync102,
|
|
140171
|
+
mkdirSync as mkdirSync41,
|
|
140155
140172
|
readFileSync as readFileSync82,
|
|
140156
140173
|
renameSync as renameSync26,
|
|
140157
140174
|
unlinkSync as unlinkSync21,
|
|
@@ -140387,7 +140404,7 @@ function getPhaseMutationGapFinding(phaseNumber, workingDir) {
|
|
|
140387
140404
|
}
|
|
140388
140405
|
function writePhaseCouncilEvidence(workingDir, synthesis, provenance) {
|
|
140389
140406
|
const evidenceDir = path177.join(workingDir, ".swarm", "evidence", String(synthesis.phaseNumber));
|
|
140390
|
-
|
|
140407
|
+
mkdirSync41(evidenceDir, { recursive: true });
|
|
140391
140408
|
const evidenceFile = path177.join(evidenceDir, "phase-council.json");
|
|
140392
140409
|
const evidenceBundle = {
|
|
140393
140410
|
entries: [
|
|
@@ -140425,7 +140442,7 @@ function writePhaseCouncilEvidence(workingDir, synthesis, provenance) {
|
|
|
140425
140442
|
writeFileSync33(tempFile, JSON.stringify(evidenceBundle, null, 2), "utf-8");
|
|
140426
140443
|
renameSync26(tempFile, evidenceFile);
|
|
140427
140444
|
} finally {
|
|
140428
|
-
if (
|
|
140445
|
+
if (existsSync102(tempFile)) {
|
|
140429
140446
|
unlinkSync21(tempFile);
|
|
140430
140447
|
}
|
|
140431
140448
|
}
|
|
@@ -141359,8 +141376,8 @@ async function syntaxCheck(input, directory, config3) {
|
|
|
141359
141376
|
return { result, counted: false, failed: false, skipped: true };
|
|
141360
141377
|
}
|
|
141361
141378
|
try {
|
|
141362
|
-
const
|
|
141363
|
-
if (
|
|
141379
|
+
const stat12 = fs123.statSync(fullPath);
|
|
141380
|
+
if (stat12.size >= MAX_FILE_SIZE2) {
|
|
141364
141381
|
result.skipped_reason = "file_too_large";
|
|
141365
141382
|
return { result, counted: false, failed: false, skipped: true };
|
|
141366
141383
|
}
|
|
@@ -141592,15 +141609,15 @@ function findSourceFiles3(dir, files = []) {
|
|
|
141592
141609
|
continue;
|
|
141593
141610
|
}
|
|
141594
141611
|
const fullPath = path180.join(dir, entry);
|
|
141595
|
-
let
|
|
141612
|
+
let stat12;
|
|
141596
141613
|
try {
|
|
141597
|
-
|
|
141614
|
+
stat12 = fs124.statSync(fullPath);
|
|
141598
141615
|
} catch {
|
|
141599
141616
|
continue;
|
|
141600
141617
|
}
|
|
141601
|
-
if (
|
|
141618
|
+
if (stat12.isDirectory()) {
|
|
141602
141619
|
findSourceFiles3(fullPath, files);
|
|
141603
|
-
} else if (
|
|
141620
|
+
} else if (stat12.isFile()) {
|
|
141604
141621
|
if (isSupportedExtension(fullPath)) {
|
|
141605
141622
|
files.push(fullPath);
|
|
141606
141623
|
}
|
|
@@ -141697,8 +141714,8 @@ var todo_extract = createSwarmTool({
|
|
|
141697
141714
|
return JSON.stringify(errorResult, null, 2);
|
|
141698
141715
|
}
|
|
141699
141716
|
const filesToScan = [];
|
|
141700
|
-
const
|
|
141701
|
-
if (
|
|
141717
|
+
const stat12 = fs124.statSync(scanPath);
|
|
141718
|
+
if (stat12.isFile()) {
|
|
141702
141719
|
if (isSupportedExtension(scanPath)) {
|
|
141703
141720
|
filesToScan.push(scanPath);
|
|
141704
141721
|
} else {
|
|
@@ -142819,7 +142836,7 @@ import * as zlib from "node:zlib";
|
|
|
142819
142836
|
init_utils2();
|
|
142820
142837
|
init_redaction();
|
|
142821
142838
|
import { createHash as createHash17 } from "node:crypto";
|
|
142822
|
-
import { appendFile as appendFile17, mkdir as
|
|
142839
|
+
import { appendFile as appendFile17, mkdir as mkdir32 } from "node:fs/promises";
|
|
142823
142840
|
import * as path185 from "node:path";
|
|
142824
142841
|
var EVIDENCE_CACHE_FILE = "evidence-cache/documents.jsonl";
|
|
142825
142842
|
var MAX_EVIDENCE_TEXT_LENGTH = 4000;
|
|
@@ -142828,7 +142845,7 @@ async function writeEvidenceDocuments(directory, inputs, now = () => new Date) {
|
|
|
142828
142845
|
const capturedAt = now().toISOString();
|
|
142829
142846
|
const records = inputs.map((input) => createEvidenceDocumentRecord(input, capturedAt)).filter((record3) => record3 !== null);
|
|
142830
142847
|
if (records.length > 0) {
|
|
142831
|
-
await
|
|
142848
|
+
await mkdir32(path185.dirname(filePath), { recursive: true });
|
|
142832
142849
|
await appendFile17(filePath, `${records.map((record3) => JSON.stringify(record3)).join(`
|
|
142833
142850
|
`)}
|
|
142834
142851
|
`, "utf-8");
|
|
@@ -144729,6 +144746,7 @@ init_warning_buffer();
|
|
|
144729
144746
|
var _heartbeatTimers = new Map;
|
|
144730
144747
|
var SWARM_COMMAND_SYSTEM_RULE_TAG = "[opencode-swarm:swarm-command-rule]";
|
|
144731
144748
|
var PACKAGE_ROOT2 = path192.resolve(path192.dirname(fileURLToPath5(import.meta.url)), "..");
|
|
144749
|
+
var SYNC_BUNDLED_SKILLS_TIMEOUT_MS = 2000;
|
|
144732
144750
|
function createSwarmCommandSystemRuleHook(agentDefinitions, registeredAgents) {
|
|
144733
144751
|
return async (input, output) => {
|
|
144734
144752
|
const { sessionID } = input;
|
|
@@ -144827,6 +144845,14 @@ async function initializeOpenCodeSwarm(ctx) {
|
|
|
144827
144845
|
});
|
|
144828
144846
|
writeSwarmConfigExampleIfNew(ctx.directory);
|
|
144829
144847
|
writeProjectConfigIfNew(ctx.directory, config3.quiet);
|
|
144848
|
+
queueMicrotask(() => {
|
|
144849
|
+
withTimeout(syncBundledProjectSkillsIfMissingAsync(ctx.directory, PACKAGE_ROOT2, config3.quiet), SYNC_BUNDLED_SKILLS_TIMEOUT_MS, new Error(`syncBundledProjectSkillsIfMissingAsync exceeded ${SYNC_BUNDLED_SKILLS_TIMEOUT_MS}ms budget; continuing without skill materialization (command-path sync remains a backstop)`)).catch((err3) => {
|
|
144850
|
+
const msg = err3 instanceof Error ? err3.message : String(err3);
|
|
144851
|
+
log("bundled skill materialization timed out or failed (non-fatal)", {
|
|
144852
|
+
error: msg
|
|
144853
|
+
});
|
|
144854
|
+
});
|
|
144855
|
+
});
|
|
144830
144856
|
if (config3.version_check !== false) {
|
|
144831
144857
|
scheduleVersionCheck(package_default.version, (msg) => {
|
|
144832
144858
|
if (config3.quiet) {
|