@fro.bot/systematic 3.27.1 → 3.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ATTRIBUTIONS.md +2 -2
- package/HARNESSES.md +24 -11
- package/agents/research/learnings-researcher.md +49 -9
- package/dist/claude-code-search.d.ts +30 -0
- package/dist/claude-code-validator-bin.d.ts +17 -0
- package/dist/cli.d.ts +18 -0
- package/dist/cli.js +335 -108
- package/dist/{index-608preny.js → index-9chxhh5j.js} +1120 -72
- package/dist/index.js +204 -8
- package/dist/lib/agent-resolver.d.ts +8 -2
- package/dist/lib/asset-plan.d.ts +23 -1
- package/dist/lib/config-protected-fields.d.ts +1 -1
- package/dist/lib/config-schema.d.ts +6 -0
- package/dist/lib/config.d.ts +13 -0
- package/dist/lib/main-module.d.ts +30 -0
- package/dist/lib/opencode-v2-commands.d.ts +4 -3
- package/dist/lib/opencode-v2-skills.d.ts +12 -2
- package/dist/lib/opencode-v2.d.ts +1 -0
- package/dist/lib/pi-delegate-session.d.ts +3 -1
- package/dist/lib/pi-delegate-tool.d.ts +12 -1
- package/dist/lib/search-cli.d.ts +52 -0
- package/dist/lib/search-core.d.ts +128 -0
- package/dist/lib/search-corpus.d.ts +105 -0
- package/dist/lib/search-lexical.d.ts +136 -0
- package/dist/lib/search-render.d.ts +69 -0
- package/dist/lib/search-tool.d.ts +53 -0
- package/dist/lib/search-user-config.d.ts +96 -0
- package/dist/pi.js +1155 -77
- package/package.json +3 -3
- package/skills/ce-review/SKILL.md +1 -1
- package/skills/ce-review/references/review-output-template.md +1 -1
- package/skills/ce-review/scripts/validate-review.mjs +1 -3
- package/skills/using-systematic/references/claude-code-profile.md +1 -0
- package/skills/using-systematic/references/opencode-profile.md +1 -0
- package/skills/using-systematic/references/opencode-v2-profile.md +1 -0
- package/skills/using-systematic/references/pi-profile.md +1 -0
package/dist/cli.js
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
discriminatedUnion,
|
|
25
25
|
_enum,
|
|
26
26
|
literal,
|
|
27
|
+
loadUserLevelSearchSettings,
|
|
27
28
|
extractString,
|
|
28
29
|
toSourcedPiSubagentsOverlays,
|
|
29
30
|
resolveRouting,
|
|
@@ -34,8 +35,16 @@ import {
|
|
|
34
35
|
findAgentsInDir,
|
|
35
36
|
findCommandsInDir,
|
|
36
37
|
findSkillsInDir,
|
|
37
|
-
discoverSkills
|
|
38
|
-
|
|
38
|
+
discoverSkills,
|
|
39
|
+
resolveSearchRoot,
|
|
40
|
+
SEARCH_TOOL_NAME,
|
|
41
|
+
SEARCH_ARGS,
|
|
42
|
+
MIN_LIMIT,
|
|
43
|
+
MAX_LIMIT,
|
|
44
|
+
SEARCH_NOTICES,
|
|
45
|
+
SEARCH_CONFIG_UNREADABLE_NOTE,
|
|
46
|
+
runSearch
|
|
47
|
+
} from "./index-9chxhh5j.js";
|
|
39
48
|
var __defProp = Object.defineProperty;
|
|
40
49
|
var __returnValue = (v) => v;
|
|
41
50
|
function __exportSetter(name, newValue) {
|
|
@@ -65,9 +74,9 @@ __export(exports_iso, {
|
|
|
65
74
|
});
|
|
66
75
|
|
|
67
76
|
// src/cli.ts
|
|
68
|
-
import
|
|
77
|
+
import fs8 from "fs";
|
|
69
78
|
import os2 from "os";
|
|
70
|
-
import
|
|
79
|
+
import path6 from "path";
|
|
71
80
|
|
|
72
81
|
// src/lib/agent-resolver.ts
|
|
73
82
|
import fs from "fs";
|
|
@@ -144,14 +153,21 @@ function extractRawToolsSource(data, sourceFile) {
|
|
|
144
153
|
}
|
|
145
154
|
return trimmed;
|
|
146
155
|
}
|
|
147
|
-
var DEFAULT_READONLY_TOOLS = [
|
|
156
|
+
var DEFAULT_READONLY_TOOLS = [
|
|
157
|
+
"read",
|
|
158
|
+
"grep",
|
|
159
|
+
"find",
|
|
160
|
+
"ls",
|
|
161
|
+
SEARCH_TOOL_NAME
|
|
162
|
+
];
|
|
148
163
|
var OPENCODE_TO_PI_TOOL = {
|
|
149
164
|
Read: "read",
|
|
150
165
|
Grep: "grep",
|
|
151
166
|
Glob: "find",
|
|
152
167
|
Bash: "bash",
|
|
153
168
|
Edit: "edit",
|
|
154
|
-
Write: "write"
|
|
169
|
+
Write: "write",
|
|
170
|
+
[SEARCH_TOOL_NAME]: SEARCH_TOOL_NAME
|
|
155
171
|
};
|
|
156
172
|
function unknownDeclaredToolError(toolName) {
|
|
157
173
|
const error = new Error(`Unknown declared tool "${toolName}" in persona frontmatter; refusing to map ` + "to a Pi built-in (fail-closed). Known tools: " + `${Object.keys(OPENCODE_TO_PI_TOOL).join(", ")}.`);
|
|
@@ -841,16 +857,41 @@ function time(params) {
|
|
|
841
857
|
function duration(params) {
|
|
842
858
|
return _isoDuration(ZodISODuration, params);
|
|
843
859
|
}
|
|
860
|
+
// src/lib/main-module.ts
|
|
861
|
+
import fs2 from "fs";
|
|
862
|
+
import { fileURLToPath } from "url";
|
|
863
|
+
function resolveRealPath(value) {
|
|
864
|
+
if (value === undefined || value === "")
|
|
865
|
+
return;
|
|
866
|
+
try {
|
|
867
|
+
return fs2.realpathSync(value);
|
|
868
|
+
} catch {
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
function moduleFilePath(moduleUrl) {
|
|
873
|
+
try {
|
|
874
|
+
return fileURLToPath(moduleUrl);
|
|
875
|
+
} catch {
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
function isMainModule(moduleUrl, argv = process.argv) {
|
|
880
|
+
const entryPath = resolveRealPath(argv[1]);
|
|
881
|
+
const modulePath = resolveRealPath(moduleFilePath(moduleUrl));
|
|
882
|
+
return entryPath !== undefined && modulePath !== undefined && entryPath === modulePath;
|
|
883
|
+
}
|
|
884
|
+
|
|
844
885
|
// src/lib/pi-subagents-export.ts
|
|
845
886
|
import * as crypto2 from "crypto";
|
|
846
|
-
import * as
|
|
887
|
+
import * as fs4 from "fs";
|
|
847
888
|
import * as os from "os";
|
|
848
889
|
import * as path2 from "path";
|
|
849
|
-
import { fileURLToPath } from "url";
|
|
890
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
850
891
|
|
|
851
892
|
// src/lib/pi-subagents-personas.ts
|
|
852
893
|
import * as crypto from "crypto";
|
|
853
|
-
import * as
|
|
894
|
+
import * as fs3 from "fs";
|
|
854
895
|
import * as path from "path";
|
|
855
896
|
var CURATED_PERSONAS = [
|
|
856
897
|
{
|
|
@@ -1120,7 +1161,7 @@ function generateAll(repoRoot) {
|
|
|
1120
1161
|
const fullPath = path.join(repoRoot, curatedEntry.relPath);
|
|
1121
1162
|
let rawContent;
|
|
1122
1163
|
try {
|
|
1123
|
-
rawContent =
|
|
1164
|
+
rawContent = fs3.readFileSync(fullPath, "utf-8");
|
|
1124
1165
|
} catch (err) {
|
|
1125
1166
|
throw new Error(`Failed to read ${curatedEntry.relPath}: ${err.message}`);
|
|
1126
1167
|
}
|
|
@@ -1201,7 +1242,7 @@ function assertAnchoredPathSafe(anchor, targetPath) {
|
|
|
1201
1242
|
current = path2.join(current, part);
|
|
1202
1243
|
let stat;
|
|
1203
1244
|
try {
|
|
1204
|
-
stat =
|
|
1245
|
+
stat = fs4.lstatSync(current);
|
|
1205
1246
|
} catch {
|
|
1206
1247
|
continue;
|
|
1207
1248
|
}
|
|
@@ -1214,11 +1255,11 @@ function assertAnchoredPathSafe(anchor, targetPath) {
|
|
|
1214
1255
|
function assertCanonicalRootWithinAnchor(anchor, root) {
|
|
1215
1256
|
let canonicalAnchor;
|
|
1216
1257
|
try {
|
|
1217
|
-
canonicalAnchor =
|
|
1258
|
+
canonicalAnchor = fs4.realpathSync(anchor);
|
|
1218
1259
|
} catch (err) {
|
|
1219
1260
|
throw new Error(`Cannot resolve safety anchor ${anchor}: ${err instanceof Error ? err.message : String(err)}`);
|
|
1220
1261
|
}
|
|
1221
|
-
const canonicalRoot =
|
|
1262
|
+
const canonicalRoot = fs4.realpathSync(root);
|
|
1222
1263
|
if (canonicalRoot !== canonicalAnchor && !canonicalRoot.startsWith(canonicalAnchor + path2.sep)) {
|
|
1223
1264
|
throw new Error(`Refusing to operate on ${canonicalRoot}: canonical path escapes safety anchor ` + `${canonicalAnchor} (raced-symlink ancestor detected after resolution)`);
|
|
1224
1265
|
}
|
|
@@ -1253,11 +1294,11 @@ function validateManifestObject(parsed) {
|
|
|
1253
1294
|
}
|
|
1254
1295
|
return null;
|
|
1255
1296
|
}
|
|
1256
|
-
var HAS_O_NOFOLLOW = typeof
|
|
1297
|
+
var HAS_O_NOFOLLOW = typeof fs4.constants.O_NOFOLLOW === "number";
|
|
1257
1298
|
function verifyManifestPathIdentity(manifestPath, openedStat) {
|
|
1258
1299
|
let linkStat;
|
|
1259
1300
|
try {
|
|
1260
|
-
linkStat =
|
|
1301
|
+
linkStat = fs4.lstatSync(manifestPath);
|
|
1261
1302
|
} catch (err) {
|
|
1262
1303
|
return `Cannot verify manifest path after open: ${err instanceof Error ? err.message : String(err)}`;
|
|
1263
1304
|
}
|
|
@@ -1268,9 +1309,9 @@ function verifyManifestPathIdentity(manifestPath, openedStat) {
|
|
|
1268
1309
|
return null;
|
|
1269
1310
|
}
|
|
1270
1311
|
function openManifestFd(manifestPath) {
|
|
1271
|
-
const openFlags =
|
|
1312
|
+
const openFlags = fs4.constants.O_RDONLY | (HAS_O_NOFOLLOW ? fs4.constants.O_NOFOLLOW : 0);
|
|
1272
1313
|
try {
|
|
1273
|
-
return { kind: "fd", fd:
|
|
1314
|
+
return { kind: "fd", fd: fs4.openSync(manifestPath, openFlags) };
|
|
1274
1315
|
} catch (err) {
|
|
1275
1316
|
if (err.code === "ENOENT")
|
|
1276
1317
|
return { kind: "result", result: { kind: "absent" } };
|
|
@@ -1313,7 +1354,7 @@ function readManifestStrict(agentsRoot) {
|
|
|
1313
1354
|
return opened.result;
|
|
1314
1355
|
const { fd } = opened;
|
|
1315
1356
|
try {
|
|
1316
|
-
const stat =
|
|
1357
|
+
const stat = fs4.fstatSync(fd);
|
|
1317
1358
|
if (!stat.isFile())
|
|
1318
1359
|
return {
|
|
1319
1360
|
kind: "malformed",
|
|
@@ -1324,14 +1365,14 @@ function readManifestStrict(agentsRoot) {
|
|
|
1324
1365
|
if (identityError !== null)
|
|
1325
1366
|
return { kind: "malformed", error: identityError };
|
|
1326
1367
|
}
|
|
1327
|
-
return parseManifestContents(
|
|
1368
|
+
return parseManifestContents(fs4.readFileSync(fd, "utf-8"));
|
|
1328
1369
|
} catch (err) {
|
|
1329
1370
|
return {
|
|
1330
1371
|
kind: "malformed",
|
|
1331
1372
|
error: `Cannot read manifest: ${err instanceof Error ? err.message : String(err)}`
|
|
1332
1373
|
};
|
|
1333
1374
|
} finally {
|
|
1334
|
-
|
|
1375
|
+
fs4.closeSync(fd);
|
|
1335
1376
|
}
|
|
1336
1377
|
}
|
|
1337
1378
|
function writeManifest(agentsRoot, manifest) {
|
|
@@ -1340,7 +1381,7 @@ function writeManifest(agentsRoot, manifest) {
|
|
|
1340
1381
|
}
|
|
1341
1382
|
function statOrNull(p) {
|
|
1342
1383
|
try {
|
|
1343
|
-
return
|
|
1384
|
+
return fs4.lstatSync(p);
|
|
1344
1385
|
} catch {
|
|
1345
1386
|
return null;
|
|
1346
1387
|
}
|
|
@@ -1348,7 +1389,7 @@ function statOrNull(p) {
|
|
|
1348
1389
|
function assertRealAgentsRoot(agentsRoot) {
|
|
1349
1390
|
let stat = null;
|
|
1350
1391
|
try {
|
|
1351
|
-
stat =
|
|
1392
|
+
stat = fs4.lstatSync(agentsRoot);
|
|
1352
1393
|
} catch {}
|
|
1353
1394
|
if (stat !== null) {
|
|
1354
1395
|
if (stat.isSymbolicLink())
|
|
@@ -1356,7 +1397,7 @@ function assertRealAgentsRoot(agentsRoot) {
|
|
|
1356
1397
|
if (!stat.isDirectory())
|
|
1357
1398
|
throw new Error(`Refusing to write under ${agentsRoot}: not a directory`);
|
|
1358
1399
|
}
|
|
1359
|
-
return
|
|
1400
|
+
return fs4.realpathSync(agentsRoot);
|
|
1360
1401
|
}
|
|
1361
1402
|
function safeFilePathOrThrow(agentsRoot, filename) {
|
|
1362
1403
|
if (path2.basename(filename) !== filename || path2.isAbsolute(filename)) {
|
|
@@ -1378,7 +1419,7 @@ function safeFilePath(agentsRoot, filename) {
|
|
|
1378
1419
|
function acquireLock(agentsRoot) {
|
|
1379
1420
|
const lockPath = path2.join(agentsRoot, LOCK_FILENAME);
|
|
1380
1421
|
try {
|
|
1381
|
-
return { ok: true, fd:
|
|
1422
|
+
return { ok: true, fd: fs4.openSync(lockPath, "wx") };
|
|
1382
1423
|
} catch (err) {
|
|
1383
1424
|
if (err.code === "EEXIST") {
|
|
1384
1425
|
return {
|
|
@@ -1396,10 +1437,10 @@ function acquireLock(agentsRoot) {
|
|
|
1396
1437
|
}
|
|
1397
1438
|
function releaseLock(agentsRoot, fd) {
|
|
1398
1439
|
try {
|
|
1399
|
-
|
|
1440
|
+
fs4.closeSync(fd);
|
|
1400
1441
|
} catch {}
|
|
1401
1442
|
try {
|
|
1402
|
-
|
|
1443
|
+
fs4.unlinkSync(path2.join(agentsRoot, LOCK_FILENAME));
|
|
1403
1444
|
} catch {}
|
|
1404
1445
|
}
|
|
1405
1446
|
function withLock(agentsRoot, fn) {
|
|
@@ -1421,11 +1462,11 @@ function atomicWriteString(destPath, content) {
|
|
|
1421
1462
|
const parentDir = path2.dirname(destPath);
|
|
1422
1463
|
const tmpPath = path2.join(parentDir, `.${path2.basename(destPath)}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
|
1423
1464
|
try {
|
|
1424
|
-
|
|
1425
|
-
|
|
1465
|
+
fs4.writeFileSync(tmpPath, content, { flag: "w", mode: 420 });
|
|
1466
|
+
fs4.renameSync(tmpPath, destPath);
|
|
1426
1467
|
} catch (err) {
|
|
1427
1468
|
try {
|
|
1428
|
-
|
|
1469
|
+
fs4.unlinkSync(tmpPath);
|
|
1429
1470
|
} catch {}
|
|
1430
1471
|
throw err;
|
|
1431
1472
|
}
|
|
@@ -1434,7 +1475,7 @@ function snapshotFiles(filePaths) {
|
|
|
1434
1475
|
const backup = new Map;
|
|
1435
1476
|
for (const p of filePaths) {
|
|
1436
1477
|
try {
|
|
1437
|
-
backup.set(p,
|
|
1478
|
+
backup.set(p, fs4.readFileSync(p, "utf-8"));
|
|
1438
1479
|
} catch (err) {
|
|
1439
1480
|
if (err.code === "ENOENT") {
|
|
1440
1481
|
backup.set(p, undefined);
|
|
@@ -1454,10 +1495,10 @@ function restoreFromBackup(backup, paths) {
|
|
|
1454
1495
|
const content = backup.get(p);
|
|
1455
1496
|
try {
|
|
1456
1497
|
if (content === undefined) {
|
|
1457
|
-
if (
|
|
1458
|
-
|
|
1498
|
+
if (fs4.existsSync(p))
|
|
1499
|
+
fs4.unlinkSync(p);
|
|
1459
1500
|
} else {
|
|
1460
|
-
|
|
1501
|
+
fs4.writeFileSync(p, content, "utf-8");
|
|
1461
1502
|
}
|
|
1462
1503
|
} catch {
|
|
1463
1504
|
failed.push(p);
|
|
@@ -1612,13 +1653,13 @@ function generateEntries(repoRoot, configOptions) {
|
|
|
1612
1653
|
};
|
|
1613
1654
|
}
|
|
1614
1655
|
function findPackageRoot() {
|
|
1615
|
-
const thisFile =
|
|
1656
|
+
const thisFile = fileURLToPath2(import.meta.url);
|
|
1616
1657
|
const dir = path2.resolve(path2.dirname(thisFile), "..", "..");
|
|
1617
|
-
if (
|
|
1658
|
+
if (fs4.existsSync(path2.join(dir, "package.json")))
|
|
1618
1659
|
return dir;
|
|
1619
1660
|
let candidate = path2.dirname(thisFile);
|
|
1620
1661
|
for (let i = 0;i < 8; i++) {
|
|
1621
|
-
if (
|
|
1662
|
+
if (fs4.existsSync(path2.join(candidate, "package.json")))
|
|
1622
1663
|
return candidate;
|
|
1623
1664
|
const parent = path2.dirname(candidate);
|
|
1624
1665
|
if (parent === candidate)
|
|
@@ -1643,7 +1684,7 @@ function planEntryActions(absRoot, entries, owned) {
|
|
|
1643
1684
|
for (const entry of entries) {
|
|
1644
1685
|
if (!isWrittenEntry(entry))
|
|
1645
1686
|
continue;
|
|
1646
|
-
const exists =
|
|
1687
|
+
const exists = fs4.existsSync(path2.join(absRoot, entry.filename));
|
|
1647
1688
|
actions.push(exists ? planExistingEntry(absRoot, entry.filename, entry.hash, owned) : { action: "create", filename: entry.filename });
|
|
1648
1689
|
}
|
|
1649
1690
|
return actions;
|
|
@@ -1709,12 +1750,12 @@ function classifyOneExportEntry(absRoot, entry, owned) {
|
|
|
1709
1750
|
const safePath = safeFilePath(absRoot, entry.filename);
|
|
1710
1751
|
if (safePath === null)
|
|
1711
1752
|
return { kind: "refuse", reason: "Filename would escape agents root" };
|
|
1712
|
-
if (
|
|
1753
|
+
if (fs4.existsSync(safePath) && !owned.has(entry.filename))
|
|
1713
1754
|
return {
|
|
1714
1755
|
kind: "refuse",
|
|
1715
1756
|
reason: "File exists but is not owned by a previous export (user file)"
|
|
1716
1757
|
};
|
|
1717
|
-
if (
|
|
1758
|
+
if (fs4.existsSync(safePath)) {
|
|
1718
1759
|
if (hashOfFile(safePath) === entry.hash)
|
|
1719
1760
|
return { kind: "skip", safePath };
|
|
1720
1761
|
}
|
|
@@ -1767,12 +1808,12 @@ function makeExportError(error) {
|
|
|
1767
1808
|
function prepareExportRoot(agentsRoot) {
|
|
1768
1809
|
let preStat = null;
|
|
1769
1810
|
try {
|
|
1770
|
-
preStat =
|
|
1811
|
+
preStat = fs4.lstatSync(agentsRoot);
|
|
1771
1812
|
} catch {}
|
|
1772
1813
|
if (preStat?.isSymbolicLink())
|
|
1773
1814
|
return makeExportError(`Refusing to write under ${agentsRoot}: not a real directory (symlink detected)`);
|
|
1774
1815
|
try {
|
|
1775
|
-
|
|
1816
|
+
fs4.mkdirSync(agentsRoot, { recursive: true });
|
|
1776
1817
|
return assertRealAgentsRoot(agentsRoot);
|
|
1777
1818
|
} catch (err) {
|
|
1778
1819
|
return makeExportError(err instanceof Error ? err.message : String(err));
|
|
@@ -1798,7 +1839,7 @@ function findStalePaths(absRoot, prevManifest, currentFilenames, disabledFilenam
|
|
|
1798
1839
|
if (currentFilenames.has(mEntry.filename))
|
|
1799
1840
|
continue;
|
|
1800
1841
|
const safe = safeFilePath(absRoot, mEntry.filename);
|
|
1801
|
-
if (safe === null || !
|
|
1842
|
+
if (safe === null || !fs4.existsSync(safe))
|
|
1802
1843
|
continue;
|
|
1803
1844
|
if (hashOfFile(safe) === mEntry.hash) {
|
|
1804
1845
|
remove.push({
|
|
@@ -1818,13 +1859,13 @@ function findStalePaths(absRoot, prevManifest, currentFilenames, disabledFilenam
|
|
|
1818
1859
|
return { remove, retained };
|
|
1819
1860
|
}
|
|
1820
1861
|
function unlinkStaleOwned({ path: p, filename, hash }) {
|
|
1821
|
-
if (!
|
|
1862
|
+
if (!fs4.existsSync(p))
|
|
1822
1863
|
return;
|
|
1823
1864
|
assertHashMatchesOrThrow(p, hash, filename, "remove stale file");
|
|
1824
|
-
|
|
1865
|
+
fs4.unlinkSync(p);
|
|
1825
1866
|
}
|
|
1826
1867
|
function hashOfFile(filePath) {
|
|
1827
|
-
return crypto2.createHash("sha256").update(
|
|
1868
|
+
return crypto2.createHash("sha256").update(fs4.readFileSync(filePath, "utf-8")).digest("hex");
|
|
1828
1869
|
}
|
|
1829
1870
|
function exportPersonas(agentsRoot, configOptions) {
|
|
1830
1871
|
let generated;
|
|
@@ -1921,7 +1962,7 @@ function classifyOneRefreshEntry(absRoot, entry, owned) {
|
|
|
1921
1962
|
const safePath = safeFilePath(absRoot, entry.filename);
|
|
1922
1963
|
if (safePath === null)
|
|
1923
1964
|
return { kind: "ignore" };
|
|
1924
|
-
const exists =
|
|
1965
|
+
const exists = fs4.existsSync(safePath);
|
|
1925
1966
|
if (exists && !owned.has(entry.filename))
|
|
1926
1967
|
return { kind: "skip-unowned", safePath };
|
|
1927
1968
|
if (!exists && !owned.has(entry.filename))
|
|
@@ -1955,10 +1996,10 @@ function classifyRefreshEntries(absRoot, entries, owned) {
|
|
|
1955
1996
|
}
|
|
1956
1997
|
function validateRefreshRoot(agentsRoot) {
|
|
1957
1998
|
const absRoot = path2.resolve(agentsRoot);
|
|
1958
|
-
if (!
|
|
1999
|
+
if (!fs4.existsSync(absRoot))
|
|
1959
2000
|
return makeRefreshError(`Agents root does not exist: ${absRoot}. Run export first.`);
|
|
1960
2001
|
try {
|
|
1961
|
-
const stat =
|
|
2002
|
+
const stat = fs4.lstatSync(absRoot);
|
|
1962
2003
|
if (stat.isSymbolicLink())
|
|
1963
2004
|
return makeRefreshError(`Refusing to write under ${absRoot}: not a real directory (symlink)`);
|
|
1964
2005
|
} catch (err) {
|
|
@@ -2049,7 +2090,7 @@ function collectCleanupPaths(absRoot, manifest) {
|
|
|
2049
2090
|
const targets = [];
|
|
2050
2091
|
for (const entry of manifest.files) {
|
|
2051
2092
|
const safe = safeFilePath(absRoot, entry.filename);
|
|
2052
|
-
if (safe === null || !
|
|
2093
|
+
if (safe === null || !fs4.existsSync(safe))
|
|
2053
2094
|
continue;
|
|
2054
2095
|
assertHashMatchesOrThrow(safe, entry.hash, entry.filename, "delete");
|
|
2055
2096
|
targets.push({ path: safe, filename: entry.filename, hash: entry.hash });
|
|
@@ -2057,7 +2098,7 @@ function collectCleanupPaths(absRoot, manifest) {
|
|
|
2057
2098
|
const manifestPath = path2.join(absRoot, MANIFEST_FILENAME);
|
|
2058
2099
|
return {
|
|
2059
2100
|
targets,
|
|
2060
|
-
manifestPath:
|
|
2101
|
+
manifestPath: fs4.existsSync(manifestPath) ? manifestPath : null
|
|
2061
2102
|
};
|
|
2062
2103
|
}
|
|
2063
2104
|
function cleanup(agentsRoot, configOptions) {
|
|
@@ -2067,7 +2108,7 @@ function cleanup(agentsRoot, configOptions) {
|
|
|
2067
2108
|
throw new Error(`Refusing to operate on ${absRootCandidate}: not a real directory (symlink detected)`);
|
|
2068
2109
|
const anchor = anchorForScope(configOptions, absRootCandidate);
|
|
2069
2110
|
assertAnchoredPathSafe(anchor, absRootCandidate);
|
|
2070
|
-
if (!
|
|
2111
|
+
if (!fs4.existsSync(absRootCandidate))
|
|
2071
2112
|
return { status: "ok" };
|
|
2072
2113
|
const absRoot = assertCanonicalRootWithinAnchor(anchor, absRootCandidate);
|
|
2073
2114
|
const lockResult = withLock(absRoot, () => {
|
|
@@ -2082,9 +2123,9 @@ function cleanup(agentsRoot, configOptions) {
|
|
|
2082
2123
|
...targets.map(({ path: p, filename, hash }) => ({
|
|
2083
2124
|
path: p,
|
|
2084
2125
|
run: () => {
|
|
2085
|
-
if (
|
|
2126
|
+
if (fs4.existsSync(p)) {
|
|
2086
2127
|
assertHashMatchesOrThrow(p, hash, filename, "delete");
|
|
2087
|
-
|
|
2128
|
+
fs4.unlinkSync(p);
|
|
2088
2129
|
}
|
|
2089
2130
|
}
|
|
2090
2131
|
})),
|
|
@@ -2092,8 +2133,8 @@ function cleanup(agentsRoot, configOptions) {
|
|
|
2092
2133
|
{
|
|
2093
2134
|
path: manifestPath,
|
|
2094
2135
|
run: () => {
|
|
2095
|
-
if (
|
|
2096
|
-
|
|
2136
|
+
if (fs4.existsSync(manifestPath))
|
|
2137
|
+
fs4.unlinkSync(manifestPath);
|
|
2097
2138
|
}
|
|
2098
2139
|
}
|
|
2099
2140
|
] : []
|
|
@@ -2114,7 +2155,7 @@ function cleanup(agentsRoot, configOptions) {
|
|
|
2114
2155
|
}
|
|
2115
2156
|
|
|
2116
2157
|
// src/lib/review-artifact-path.ts
|
|
2117
|
-
import
|
|
2158
|
+
import fs5 from "fs";
|
|
2118
2159
|
import path3 from "path";
|
|
2119
2160
|
function formatReviewArtifactIssuePath(issuePath) {
|
|
2120
2161
|
if (issuePath.length === 0)
|
|
@@ -2157,7 +2198,7 @@ function formatReviewArtifactValidationFailure(issues) {
|
|
|
2157
2198
|
function readReviewArtifact(filePath) {
|
|
2158
2199
|
let content;
|
|
2159
2200
|
try {
|
|
2160
|
-
content =
|
|
2201
|
+
content = fs5.readFileSync(filePath, "utf8");
|
|
2161
2202
|
} catch {
|
|
2162
2203
|
return { message: "Review artifact file could not be read", ok: false };
|
|
2163
2204
|
}
|
|
@@ -2201,7 +2242,7 @@ function pathContainsSymlink(candidate) {
|
|
|
2201
2242
|
continue;
|
|
2202
2243
|
current = path3.join(current, segment);
|
|
2203
2244
|
try {
|
|
2204
|
-
if (
|
|
2245
|
+
if (fs5.lstatSync(current).isSymbolicLink())
|
|
2205
2246
|
return true;
|
|
2206
2247
|
} catch {
|
|
2207
2248
|
return false;
|
|
@@ -2225,8 +2266,8 @@ function resolveReviewArtifactPath(input, cwd, options = {}) {
|
|
|
2225
2266
|
if (!allowOutsideArtifactRoot) {
|
|
2226
2267
|
const artifactRoot = path3.resolve(cwd, ".context", "systematic", "ce-review");
|
|
2227
2268
|
try {
|
|
2228
|
-
canonicalRoot =
|
|
2229
|
-
if (!
|
|
2269
|
+
canonicalRoot = fs5.realpathSync(artifactRoot);
|
|
2270
|
+
if (!fs5.statSync(canonicalRoot).isDirectory()) {
|
|
2230
2271
|
return {
|
|
2231
2272
|
message: "Review artifact directory is not a directory",
|
|
2232
2273
|
ok: false
|
|
@@ -2245,7 +2286,7 @@ function resolveReviewArtifactPath(input, cwd, options = {}) {
|
|
|
2245
2286
|
}
|
|
2246
2287
|
let canonicalTarget;
|
|
2247
2288
|
try {
|
|
2248
|
-
canonicalTarget =
|
|
2289
|
+
canonicalTarget = fs5.realpathSync(candidate);
|
|
2249
2290
|
} catch {
|
|
2250
2291
|
return { message: "Review artifact file was not found", ok: false };
|
|
2251
2292
|
}
|
|
@@ -2256,7 +2297,7 @@ function resolveReviewArtifactPath(input, cwd, options = {}) {
|
|
|
2256
2297
|
};
|
|
2257
2298
|
}
|
|
2258
2299
|
try {
|
|
2259
|
-
if (!
|
|
2300
|
+
if (!fs5.lstatSync(canonicalTarget).isFile()) {
|
|
2260
2301
|
return {
|
|
2261
2302
|
message: "Review artifact target is not a regular file",
|
|
2262
2303
|
ok: false
|
|
@@ -2758,7 +2799,7 @@ var ParentRecordSchema = object({
|
|
|
2758
2799
|
}).strict();
|
|
2759
2800
|
|
|
2760
2801
|
// src/lib/review-return-validator.ts
|
|
2761
|
-
import
|
|
2802
|
+
import fs6 from "fs";
|
|
2762
2803
|
var VALIDATE_REVIEW_RETURN_USAGE = "Usage: systematic validate-review-return";
|
|
2763
2804
|
var MAX_REVIEW_RETURN_BYTES = 1024 * 1024;
|
|
2764
2805
|
var REVIEW_RETURN_VALID_MESSAGE = "Review return is valid";
|
|
@@ -2780,7 +2821,7 @@ function formatReviewReturnValidationFailure(total) {
|
|
|
2780
2821
|
}
|
|
2781
2822
|
var READ_CHUNK_BYTES = 64 * 1024;
|
|
2782
2823
|
function defaultReadChunk(fd, buffer, offset, length, position) {
|
|
2783
|
-
return
|
|
2824
|
+
return fs6.readSync(fd, buffer, offset, length, position);
|
|
2784
2825
|
}
|
|
2785
2826
|
var TRANSIENT_READ_RETRY_MS = 1;
|
|
2786
2827
|
function isTransientReadError(error) {
|
|
@@ -2883,9 +2924,137 @@ function runReviewReturnValidator(options) {
|
|
|
2883
2924
|
return 1;
|
|
2884
2925
|
}
|
|
2885
2926
|
|
|
2886
|
-
// src/lib/
|
|
2887
|
-
import fs6 from "fs";
|
|
2927
|
+
// src/lib/search-cli.ts
|
|
2888
2928
|
import path4 from "path";
|
|
2929
|
+
function searchCliUsage(commandName) {
|
|
2930
|
+
return `Usage: ${commandName} <query...> [--dir <path>] [--kind solution] [--limit <${MIN_LIMIT}-${MAX_LIMIT}>] [--]
|
|
2931
|
+
|
|
2932
|
+
Searches the project's docs/solutions learnings by symptom, error text, module
|
|
2933
|
+
or topic, and prints ranked hits.
|
|
2934
|
+
|
|
2935
|
+
Options:
|
|
2936
|
+
--dir <path> Start the search from <path> (default: the current directory).
|
|
2937
|
+
The project root is the nearest ancestor holding .git.
|
|
2938
|
+
--kind <kind> The kind of durable output to search. Only "solution" exists.
|
|
2939
|
+
--limit <n> How many hits to return, ${MIN_LIMIT} to ${MAX_LIMIT} (default: 8).
|
|
2940
|
+
-- End of options; everything after it is part of the query.
|
|
2941
|
+
-h, --help Show this help.
|
|
2942
|
+
|
|
2943
|
+
Exit statuses: 0 results, no hits, or search disabled; 2 usage error`;
|
|
2944
|
+
}
|
|
2945
|
+
var SEARCH_CLI_DISABLED_NOTICE = "Search is disabled (search.enabled is false in your Systematic config), so there is nothing to search.";
|
|
2946
|
+
var VALUE_FLAGS = new Set([
|
|
2947
|
+
"dir",
|
|
2948
|
+
"kind",
|
|
2949
|
+
"limit"
|
|
2950
|
+
]);
|
|
2951
|
+
function isValueFlag(name) {
|
|
2952
|
+
return VALUE_FLAGS.has(name);
|
|
2953
|
+
}
|
|
2954
|
+
function usageError(message, usage) {
|
|
2955
|
+
return { kind: "error", message: `${message}
|
|
2956
|
+
${usage}` };
|
|
2957
|
+
}
|
|
2958
|
+
function readValueFlag(argv, index, seen) {
|
|
2959
|
+
const arg = argv[index] ?? "";
|
|
2960
|
+
const equals = arg.indexOf("=");
|
|
2961
|
+
const name = arg.slice(2, equals === -1 ? undefined : equals);
|
|
2962
|
+
if (!arg.startsWith("--") || !isValueFlag(name)) {
|
|
2963
|
+
return { kind: "error", message: "Error: unknown option." };
|
|
2964
|
+
}
|
|
2965
|
+
if (seen[name] !== undefined) {
|
|
2966
|
+
return {
|
|
2967
|
+
kind: "error",
|
|
2968
|
+
message: "Error: an option was given more than once."
|
|
2969
|
+
};
|
|
2970
|
+
}
|
|
2971
|
+
const value = equals === -1 ? argv[index + 1] : arg.slice(equals + 1);
|
|
2972
|
+
if (value === undefined) {
|
|
2973
|
+
return { kind: "error", message: "Error: an option is missing its value." };
|
|
2974
|
+
}
|
|
2975
|
+
return { kind: "flag", name, value, consumed: equals === -1 ? 2 : 1 };
|
|
2976
|
+
}
|
|
2977
|
+
function parseArgs(argv, usage) {
|
|
2978
|
+
const words = [];
|
|
2979
|
+
const flags = {};
|
|
2980
|
+
let endOfFlags = false;
|
|
2981
|
+
let index = 0;
|
|
2982
|
+
while (index < argv.length) {
|
|
2983
|
+
const arg = argv[index] ?? "";
|
|
2984
|
+
if (endOfFlags || !arg.startsWith("-") || arg === "-") {
|
|
2985
|
+
words.push(arg);
|
|
2986
|
+
index += 1;
|
|
2987
|
+
} else if (arg === "--") {
|
|
2988
|
+
endOfFlags = true;
|
|
2989
|
+
index += 1;
|
|
2990
|
+
} else if (arg === "-h" || arg === "--help") {
|
|
2991
|
+
return { kind: "help" };
|
|
2992
|
+
} else {
|
|
2993
|
+
const read = readValueFlag(argv, index, flags);
|
|
2994
|
+
if (read.kind === "error")
|
|
2995
|
+
return usageError(read.message, usage);
|
|
2996
|
+
flags[read.name] = read.value;
|
|
2997
|
+
index += read.consumed;
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
3000
|
+
return { kind: "search", query: words.join(" "), flags };
|
|
3001
|
+
}
|
|
3002
|
+
function limitValue(raw) {
|
|
3003
|
+
if (raw === undefined)
|
|
3004
|
+
return;
|
|
3005
|
+
return /^-?\d+$/.test(raw) ? Number(raw) : raw;
|
|
3006
|
+
}
|
|
3007
|
+
async function runSearchCli(options) {
|
|
3008
|
+
const outputSink = options.outputSink ?? ((message) => console.log(message));
|
|
3009
|
+
const errorSink = options.errorSink ?? ((message) => console.error(message));
|
|
3010
|
+
const usage = searchCliUsage(options.usageName);
|
|
3011
|
+
const parsed = parseArgs(options.argv, usage);
|
|
3012
|
+
if (parsed.kind === "help") {
|
|
3013
|
+
outputSink(usage);
|
|
3014
|
+
return 0;
|
|
3015
|
+
}
|
|
3016
|
+
if (parsed.kind === "error") {
|
|
3017
|
+
errorSink(parsed.message);
|
|
3018
|
+
return 2;
|
|
3019
|
+
}
|
|
3020
|
+
try {
|
|
3021
|
+
const startDir = path4.resolve(options.cwd ?? process.cwd(), parsed.flags.dir ?? ".");
|
|
3022
|
+
let load;
|
|
3023
|
+
try {
|
|
3024
|
+
load = options.loadSettings(startDir);
|
|
3025
|
+
} catch {
|
|
3026
|
+
load = { settings: undefined, warnings: [], unreadable: true };
|
|
3027
|
+
}
|
|
3028
|
+
for (const warning of load.warnings)
|
|
3029
|
+
errorSink(warning);
|
|
3030
|
+
if (load.settings?.enabled === false) {
|
|
3031
|
+
outputSink(SEARCH_CLI_DISABLED_NOTICE);
|
|
3032
|
+
return 0;
|
|
3033
|
+
}
|
|
3034
|
+
const response = await runSearch({
|
|
3035
|
+
[SEARCH_ARGS.query]: parsed.query,
|
|
3036
|
+
[SEARCH_ARGS.kind]: parsed.flags.kind,
|
|
3037
|
+
[SEARCH_ARGS.limit]: limitValue(parsed.flags.limit)
|
|
3038
|
+
}, {
|
|
3039
|
+
startDir,
|
|
3040
|
+
settings: load.settings,
|
|
3041
|
+
...load.unreadable && { notes: [SEARCH_CONFIG_UNREADABLE_NOTE] }
|
|
3042
|
+
});
|
|
3043
|
+
if (!response.ok) {
|
|
3044
|
+
errorSink(response.text);
|
|
3045
|
+
return 2;
|
|
3046
|
+
}
|
|
3047
|
+
outputSink(response.text);
|
|
3048
|
+
return 0;
|
|
3049
|
+
} catch {
|
|
3050
|
+
errorSink(SEARCH_NOTICES.failed);
|
|
3051
|
+
return 1;
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
|
|
3055
|
+
// src/lib/setup.ts
|
|
3056
|
+
import fs7 from "fs";
|
|
3057
|
+
import path5 from "path";
|
|
2889
3058
|
var SYSTEMATIC_PACKAGE_NAME = "@fro.bot/systematic";
|
|
2890
3059
|
var PI_PACKAGE_IDENTIFIER = `npm:${SYSTEMATIC_PACKAGE_NAME}`;
|
|
2891
3060
|
var SETUP_ERROR_NAME = "SetupError";
|
|
@@ -2895,10 +3064,10 @@ function createSetupError(message) {
|
|
|
2895
3064
|
return error;
|
|
2896
3065
|
}
|
|
2897
3066
|
var DEFAULT_OPS = {
|
|
2898
|
-
writeFileSync:
|
|
2899
|
-
renameSync:
|
|
2900
|
-
unlinkSync:
|
|
2901
|
-
chmodSync:
|
|
3067
|
+
writeFileSync: fs7.writeFileSync,
|
|
3068
|
+
renameSync: fs7.renameSync,
|
|
3069
|
+
unlinkSync: fs7.unlinkSync,
|
|
3070
|
+
chmodSync: fs7.chmodSync
|
|
2902
3071
|
};
|
|
2903
3072
|
function isRecord2(value) {
|
|
2904
3073
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -2920,7 +3089,7 @@ function isPiSystematicIdentifier(identifier) {
|
|
|
2920
3089
|
}
|
|
2921
3090
|
function lstatOrNull(targetPath) {
|
|
2922
3091
|
try {
|
|
2923
|
-
return
|
|
3092
|
+
return fs7.lstatSync(targetPath);
|
|
2924
3093
|
} catch (error) {
|
|
2925
3094
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
2926
3095
|
return null;
|
|
@@ -2929,10 +3098,10 @@ function lstatOrNull(targetPath) {
|
|
|
2929
3098
|
}
|
|
2930
3099
|
}
|
|
2931
3100
|
function assertRealpathUnderCwd(dir, cwd) {
|
|
2932
|
-
const realDir =
|
|
2933
|
-
const realCwd =
|
|
2934
|
-
const relative =
|
|
2935
|
-
if (relative.startsWith("..") ||
|
|
3101
|
+
const realDir = fs7.realpathSync(dir);
|
|
3102
|
+
const realCwd = fs7.realpathSync(cwd);
|
|
3103
|
+
const relative = path5.relative(realCwd, realDir);
|
|
3104
|
+
if (relative.startsWith("..") || path5.isAbsolute(relative)) {
|
|
2936
3105
|
throw createSetupError(`Refusing to write under ${dir}: resolved directory escapes the project root`);
|
|
2937
3106
|
}
|
|
2938
3107
|
}
|
|
@@ -2945,7 +3114,7 @@ function assertParentTrusted(parentDir, cwd) {
|
|
|
2945
3114
|
assertRealpathUnderCwd(parentDir, cwd);
|
|
2946
3115
|
return;
|
|
2947
3116
|
}
|
|
2948
|
-
|
|
3117
|
+
fs7.mkdirSync(parentDir, { recursive: true });
|
|
2949
3118
|
assertRealpathUnderCwd(parentDir, cwd);
|
|
2950
3119
|
}
|
|
2951
3120
|
var OPENCODE_TARGET_CANDIDATES = [
|
|
@@ -2955,19 +3124,19 @@ var OPENCODE_TARGET_CANDIDATES = [
|
|
|
2955
3124
|
"opencode.json"
|
|
2956
3125
|
];
|
|
2957
3126
|
function resolveOpenCodeTargetPath(cwd) {
|
|
2958
|
-
const opencodeDirStat = lstatOrNull(
|
|
3127
|
+
const opencodeDirStat = lstatOrNull(path5.join(cwd, ".opencode"));
|
|
2959
3128
|
if (opencodeDirStat?.isSymbolicLink()) {
|
|
2960
|
-
return
|
|
3129
|
+
return path5.join(cwd, OPENCODE_TARGET_CANDIDATES[0]);
|
|
2961
3130
|
}
|
|
2962
3131
|
for (const candidate of OPENCODE_TARGET_CANDIDATES) {
|
|
2963
|
-
const candidatePath =
|
|
3132
|
+
const candidatePath = path5.join(cwd, candidate);
|
|
2964
3133
|
if (lstatOrNull(candidatePath) !== null)
|
|
2965
3134
|
return candidatePath;
|
|
2966
3135
|
}
|
|
2967
|
-
return
|
|
3136
|
+
return path5.join(cwd, "opencode.jsonc");
|
|
2968
3137
|
}
|
|
2969
3138
|
var IS_WINDOWS = process.platform === "win32";
|
|
2970
|
-
var OPEN_FLAGS = IS_WINDOWS ?
|
|
3139
|
+
var OPEN_FLAGS = IS_WINDOWS ? fs7.constants.O_RDONLY : fs7.constants.O_RDONLY | fs7.constants.O_NOFOLLOW | fs7.constants.O_NONBLOCK;
|
|
2971
3140
|
function assertWindowsPreOpenTrust(targetPath) {
|
|
2972
3141
|
const preStat = lstatOrNull(targetPath);
|
|
2973
3142
|
if (preStat && (preStat.isSymbolicLink() || !preStat.isFile())) {
|
|
@@ -2979,7 +3148,7 @@ function openTrustedExisting(targetPath) {
|
|
|
2979
3148
|
assertWindowsPreOpenTrust(targetPath);
|
|
2980
3149
|
let fd;
|
|
2981
3150
|
try {
|
|
2982
|
-
fd =
|
|
3151
|
+
fd = fs7.openSync(targetPath, OPEN_FLAGS);
|
|
2983
3152
|
} catch (error) {
|
|
2984
3153
|
if (error instanceof Error && "code" in error) {
|
|
2985
3154
|
if (error.code === "ENOENT")
|
|
@@ -2991,13 +3160,13 @@ function openTrustedExisting(targetPath) {
|
|
|
2991
3160
|
throw error;
|
|
2992
3161
|
}
|
|
2993
3162
|
try {
|
|
2994
|
-
const stat =
|
|
3163
|
+
const stat = fs7.fstatSync(fd);
|
|
2995
3164
|
if (!stat.isFile()) {
|
|
2996
3165
|
throw createSetupError(`Refusing to read ${targetPath}: not a regular file`);
|
|
2997
3166
|
}
|
|
2998
|
-
return { bytes:
|
|
3167
|
+
return { bytes: fs7.readFileSync(fd), mode: stat.mode & 511 };
|
|
2999
3168
|
} finally {
|
|
3000
|
-
|
|
3169
|
+
fs7.closeSync(fd);
|
|
3001
3170
|
}
|
|
3002
3171
|
}
|
|
3003
3172
|
function atomicWrite(targetPath, content, originalBytes, mode, ops) {
|
|
@@ -3012,8 +3181,8 @@ function atomicWrite(targetPath, content, originalBytes, mode, ops) {
|
|
|
3012
3181
|
writeTempAndRename(targetPath, content, mode, preserveMode, ops);
|
|
3013
3182
|
}
|
|
3014
3183
|
function writeTempAndRename(destPath, content, mode, preserveExactMode, ops) {
|
|
3015
|
-
const parentDir =
|
|
3016
|
-
const tempPath = makeTempPath(parentDir,
|
|
3184
|
+
const parentDir = path5.dirname(destPath);
|
|
3185
|
+
const tempPath = makeTempPath(parentDir, path5.basename(destPath));
|
|
3017
3186
|
try {
|
|
3018
3187
|
ops.writeFileSync(tempPath, content, { flag: "wx", mode });
|
|
3019
3188
|
if (preserveExactMode) {
|
|
@@ -3026,10 +3195,10 @@ function writeTempAndRename(destPath, content, mode, preserveExactMode, ops) {
|
|
|
3026
3195
|
}
|
|
3027
3196
|
}
|
|
3028
3197
|
function makeTempPath(parentDir, basename) {
|
|
3029
|
-
return
|
|
3198
|
+
return path5.join(parentDir, `.${basename}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
|
3030
3199
|
}
|
|
3031
3200
|
function cleanupTemp(tempPath, ops) {
|
|
3032
|
-
if (!
|
|
3201
|
+
if (!fs7.existsSync(tempPath))
|
|
3033
3202
|
return;
|
|
3034
3203
|
try {
|
|
3035
3204
|
ops.unlinkSync(tempPath);
|
|
@@ -3063,7 +3232,7 @@ function parseOpenCodeJsonc(rawText, targetPath) {
|
|
|
3063
3232
|
}
|
|
3064
3233
|
function setupOpenCode(cwd, ops) {
|
|
3065
3234
|
const targetPath = resolveOpenCodeTargetPath(cwd);
|
|
3066
|
-
assertParentTrusted(
|
|
3235
|
+
assertParentTrusted(path5.dirname(targetPath), cwd);
|
|
3067
3236
|
const existing = openTrustedExisting(targetPath);
|
|
3068
3237
|
if (existing === null) {
|
|
3069
3238
|
const content = `${JSON.stringify({ plugin: [SYSTEMATIC_PACKAGE_NAME] }, null, 2)}
|
|
@@ -3121,8 +3290,8 @@ function assertPiTaggedEntryUsable(entry, targetPath) {
|
|
|
3121
3290
|
}
|
|
3122
3291
|
}
|
|
3123
3292
|
function setupPi(cwd, ops) {
|
|
3124
|
-
const targetPath =
|
|
3125
|
-
assertParentTrusted(
|
|
3293
|
+
const targetPath = path5.join(cwd, ".pi", "settings.json");
|
|
3294
|
+
assertParentTrusted(path5.dirname(targetPath), cwd);
|
|
3126
3295
|
const existing = openTrustedExisting(targetPath);
|
|
3127
3296
|
if (existing === null) {
|
|
3128
3297
|
const content = `${JSON.stringify({ packages: [PI_PACKAGE_IDENTIFIER] }, null, 2)}
|
|
@@ -3182,10 +3351,10 @@ function setupHarness(harness, cwd, opsOverride) {
|
|
|
3182
3351
|
// src/cli.ts
|
|
3183
3352
|
function readPackageMetadata(packageRoot) {
|
|
3184
3353
|
try {
|
|
3185
|
-
const packageJsonPath =
|
|
3186
|
-
if (!
|
|
3354
|
+
const packageJsonPath = path6.join(packageRoot, "package.json");
|
|
3355
|
+
if (!fs8.existsSync(packageJsonPath))
|
|
3187
3356
|
return {};
|
|
3188
|
-
const content =
|
|
3357
|
+
const content = fs8.readFileSync(packageJsonPath, "utf8");
|
|
3189
3358
|
const parsed = JSON.parse(content);
|
|
3190
3359
|
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
3191
3360
|
return {};
|
|
@@ -3199,7 +3368,7 @@ function readPackageMetadata(packageRoot) {
|
|
|
3199
3368
|
return {};
|
|
3200
3369
|
}
|
|
3201
3370
|
}
|
|
3202
|
-
var PACKAGE_ROOT =
|
|
3371
|
+
var PACKAGE_ROOT = path6.resolve(import.meta.dirname, "..");
|
|
3203
3372
|
var VERSION = readPackageMetadata(PACKAGE_ROOT).version ?? "unknown";
|
|
3204
3373
|
var HELP = `
|
|
3205
3374
|
systematic - OpenCode plugin for systematic engineering workflows
|
|
@@ -3218,6 +3387,13 @@ Commands:
|
|
|
3218
3387
|
CI, issues, or fixtures. Not for the ce:review parent's own run artifact.
|
|
3219
3388
|
Exit statuses: 0 valid artifact, 1 validation failure,
|
|
3220
3389
|
2 operational failure, 3 legacy artifact with no schema_version
|
|
3390
|
+
search <query...> [--dir <path>] [--kind solution] [--limit <1-20>]
|
|
3391
|
+
Search the project's docs/solutions learnings by symptom, error text,
|
|
3392
|
+
module or topic, and print ranked hits. The project root is the nearest
|
|
3393
|
+
ancestor of --dir (default: the current directory) that holds .git.
|
|
3394
|
+
Reads user-level search settings; a project config cannot change them.
|
|
3395
|
+
Exit statuses: 0 results, no hits, or search disabled; 2 usage error
|
|
3396
|
+
Use -- to end options, for a query that starts with a dash
|
|
3221
3397
|
validate-review-return Validate one raw ce:review persona return read from stdin
|
|
3222
3398
|
Reads exactly one JSON document (max 1 MiB) and checks it against the
|
|
3223
3399
|
raw reviewer return schema. No files are read or written; accepts no
|
|
@@ -3244,6 +3420,8 @@ Examples:
|
|
|
3244
3420
|
systematic validate-review-artifact .context/systematic/ce-review/review-summary.json
|
|
3245
3421
|
systematic validate-review-artifact --allow-outside-artifact-root /path/to/external-artifact.json
|
|
3246
3422
|
systematic validate-review-return < reviewer-return.json
|
|
3423
|
+
systematic search "tests fail only on retry"
|
|
3424
|
+
systematic search flaky retry --limit 5
|
|
3247
3425
|
systematic list agents
|
|
3248
3426
|
systematic config show
|
|
3249
3427
|
systematic config show --json
|
|
@@ -3277,9 +3455,9 @@ Scope:
|
|
|
3277
3455
|
global $PI_CODING_AGENT_DIR/agents or ~/.pi/agent/agents
|
|
3278
3456
|
`;
|
|
3279
3457
|
function defaultCapabilityRoots() {
|
|
3280
|
-
const configDir = process.env.XDG_CONFIG_HOME ?
|
|
3458
|
+
const configDir = process.env.XDG_CONFIG_HOME ? path6.join(process.env.XDG_CONFIG_HOME, "opencode") : path6.join(os2.homedir(), ".config/opencode");
|
|
3281
3459
|
return {
|
|
3282
|
-
agentsRoot:
|
|
3460
|
+
agentsRoot: path6.join(PACKAGE_ROOT, "agents"),
|
|
3283
3461
|
configDir,
|
|
3284
3462
|
cwd: process.cwd(),
|
|
3285
3463
|
homeDir: os2.homedir(),
|
|
@@ -3378,9 +3556,9 @@ function collectConfigMetadata(roots, injected) {
|
|
|
3378
3556
|
}
|
|
3379
3557
|
function resolveCapabilityRootPath(root) {
|
|
3380
3558
|
try {
|
|
3381
|
-
return
|
|
3559
|
+
return fs8.realpathSync(root);
|
|
3382
3560
|
} catch {
|
|
3383
|
-
return
|
|
3561
|
+
return path6.resolve(root);
|
|
3384
3562
|
}
|
|
3385
3563
|
}
|
|
3386
3564
|
function capabilityRoots(roots) {
|
|
@@ -3390,7 +3568,7 @@ function capabilityRoots(roots) {
|
|
|
3390
3568
|
{ id: "package", path: resolveCapabilityRootPath(roots.packageRoot) },
|
|
3391
3569
|
{
|
|
3392
3570
|
id: "skills",
|
|
3393
|
-
path: resolveCapabilityRootPath(
|
|
3571
|
+
path: resolveCapabilityRootPath(path6.join(roots.packageRoot, "skills"))
|
|
3394
3572
|
},
|
|
3395
3573
|
{ id: "user", path: resolveCapabilityRootPath(roots.homeDir) }
|
|
3396
3574
|
];
|
|
@@ -3485,6 +3663,42 @@ function runValidateReviewReturn(options) {
|
|
|
3485
3663
|
function runValidateReviewReturnCli(options) {
|
|
3486
3664
|
return runValidateReviewReturn(options);
|
|
3487
3665
|
}
|
|
3666
|
+
function userLevelDirOptions(options) {
|
|
3667
|
+
return {
|
|
3668
|
+
...options?.homeDir !== undefined && { homeDir: options.homeDir },
|
|
3669
|
+
...options?.userConfigDir !== undefined && {
|
|
3670
|
+
userConfigDir: options.userConfigDir
|
|
3671
|
+
},
|
|
3672
|
+
...options !== undefined && Object.hasOwn(options, "customConfigDir") && {
|
|
3673
|
+
customConfigDir: options.customConfigDir
|
|
3674
|
+
}
|
|
3675
|
+
};
|
|
3676
|
+
}
|
|
3677
|
+
function loadSearchSettingsForCli(startDir, configOptions) {
|
|
3678
|
+
const warnings = [];
|
|
3679
|
+
try {
|
|
3680
|
+
const loaded = loadConfigWithSources(resolveSearchRoot(startDir), {
|
|
3681
|
+
...configOptions,
|
|
3682
|
+
invalidSource: "report",
|
|
3683
|
+
warningSink: (message) => warnings.push(message)
|
|
3684
|
+
});
|
|
3685
|
+
const invalidSource = loaded.metadata.sources.some((source) => source.presence === "invalid" && source.kind !== "project");
|
|
3686
|
+
if (invalidSource) {
|
|
3687
|
+
warnings.push("[systematic] A Systematic config file could not be read, so search results carry a `config unreadable` note. Run `systematic config show` for details.");
|
|
3688
|
+
}
|
|
3689
|
+
return {
|
|
3690
|
+
settings: invalidSource ? loadUserLevelSearchSettings(userLevelDirOptions(configOptions)).settings : loaded.config.search,
|
|
3691
|
+
warnings,
|
|
3692
|
+
unreadable: invalidSource || loaded.config.searchUnreadable === true
|
|
3693
|
+
};
|
|
3694
|
+
} catch {
|
|
3695
|
+
return {
|
|
3696
|
+
settings: loadUserLevelSearchSettings(userLevelDirOptions(configOptions)).settings,
|
|
3697
|
+
warnings,
|
|
3698
|
+
unreadable: true
|
|
3699
|
+
};
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3488
3702
|
function isHarness(value) {
|
|
3489
3703
|
return value === "opencode" || value === "pi";
|
|
3490
3704
|
}
|
|
@@ -3512,7 +3726,7 @@ function setupCommand(rest) {
|
|
|
3512
3726
|
}
|
|
3513
3727
|
}
|
|
3514
3728
|
function listItems(type) {
|
|
3515
|
-
const packageRoot =
|
|
3729
|
+
const packageRoot = path6.resolve(import.meta.dirname, "..");
|
|
3516
3730
|
const bundledDir = packageRoot;
|
|
3517
3731
|
let finder;
|
|
3518
3732
|
let subdir;
|
|
@@ -3533,7 +3747,7 @@ function listItems(type) {
|
|
|
3533
3747
|
console.error(`Unknown type: ${type}. Use: skills, agents, commands`);
|
|
3534
3748
|
process.exit(1);
|
|
3535
3749
|
}
|
|
3536
|
-
const items = finder(
|
|
3750
|
+
const items = finder(path6.join(bundledDir, subdir));
|
|
3537
3751
|
if (items.length === 0) {
|
|
3538
3752
|
console.log(`No ${type} found.`);
|
|
3539
3753
|
return;
|
|
@@ -3681,15 +3895,15 @@ function configShow(options) {
|
|
|
3681
3895
|
`);
|
|
3682
3896
|
console.log(` User config: ${paths.userConfig}`);
|
|
3683
3897
|
console.log(` Project config: ${paths.projectConfig}`);
|
|
3684
|
-
if (
|
|
3898
|
+
if (fs8.existsSync(paths.projectConfig)) {
|
|
3685
3899
|
console.log(`
|
|
3686
3900
|
Project configuration:`);
|
|
3687
|
-
console.log(
|
|
3901
|
+
console.log(fs8.readFileSync(paths.projectConfig, "utf-8"));
|
|
3688
3902
|
}
|
|
3689
|
-
if (
|
|
3903
|
+
if (fs8.existsSync(paths.userConfig)) {
|
|
3690
3904
|
console.log(`
|
|
3691
3905
|
User configuration:`);
|
|
3692
|
-
console.log(
|
|
3906
|
+
console.log(fs8.readFileSync(paths.userConfig, "utf-8"));
|
|
3693
3907
|
}
|
|
3694
3908
|
if (!printResolvedSection())
|
|
3695
3909
|
process.exit(1);
|
|
@@ -3938,6 +4152,18 @@ function runLegacyCli(args) {
|
|
|
3938
4152
|
process.exit(status);
|
|
3939
4153
|
break;
|
|
3940
4154
|
}
|
|
4155
|
+
case "search":
|
|
4156
|
+
runSearchCli({
|
|
4157
|
+
argv: args.slice(1),
|
|
4158
|
+
cwd: process.cwd(),
|
|
4159
|
+
errorSink: console.error,
|
|
4160
|
+
usageName: "systematic search",
|
|
4161
|
+
loadSettings: loadSearchSettingsForCli,
|
|
4162
|
+
outputSink: console.log
|
|
4163
|
+
}).then((status) => {
|
|
4164
|
+
process.exitCode = status;
|
|
4165
|
+
});
|
|
4166
|
+
break;
|
|
3941
4167
|
case "validate-review-return": {
|
|
3942
4168
|
const status = runValidateReviewReturnCli({
|
|
3943
4169
|
argv: ["systematic", ...args],
|
|
@@ -3987,10 +4213,11 @@ function runLegacyCli(args) {
|
|
|
3987
4213
|
process.exit(1);
|
|
3988
4214
|
}
|
|
3989
4215
|
}
|
|
3990
|
-
if (import.meta.
|
|
4216
|
+
if (isMainModule(import.meta.url)) {
|
|
3991
4217
|
runLegacyCli(process.argv.slice(2));
|
|
3992
4218
|
}
|
|
3993
4219
|
export {
|
|
4220
|
+
loadSearchSettingsForCli,
|
|
3994
4221
|
runCapabilitiesCli,
|
|
3995
4222
|
runValidateReviewArtifactCli,
|
|
3996
4223
|
runValidateReviewReturnCli
|