@c4a/context-cli 0.7.103 → 0.7.105
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/cli.js +939 -599
- package/indexers/contracts/profile-contract.json +245 -245
- package/indexers/release-manifest.json +1 -1
- package/package.json +12 -12
- package/parserEntryWorker.js +5 -1
- package/plugins/VERSION +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/commands/context.md +2 -2
- package/plugins/codex/.codex-plugin/plugin.json +2 -2
- package/plugins/codex/skills/context/SKILL.md +2 -2
- package/plugins/cursor/.cursor-plugin/plugin.json +1 -1
- package/plugins/cursor/commands/c4a-context.md +2 -2
- package/plugins/skills/context/SKILL.md +2 -2
- package/providers/context/manifest.json +13 -13
- package/providers/context/provider.yaml +1 -1
- package/providers/context/resources/manuals/guides/lark-resources.md +21 -1
- package/providers/context/resources/manuals/guides/package-outputs.md +36 -0
- package/providers/context/resources/manuals/reference/project-api.md +8 -0
- package/providers/context/resources/procedures/document-capture.md +8 -0
- package/providers/context/resources/procedures/production-stage-files.md +4 -0
package/cli.js
CHANGED
|
@@ -40810,7 +40810,7 @@ var getSourceType = (sourceDefinition) => {
|
|
|
40810
40810
|
}), captureLark = (definition) => {
|
|
40811
40811
|
const sourceDefinition = bindSourceType(definition.source, "lark", "captureLark source");
|
|
40812
40812
|
const sourceId = getSourceName(sourceDefinition);
|
|
40813
|
-
for (const key of ["images", "gifs"]) {
|
|
40813
|
+
for (const key of ["images", "gifs", "files", "whiteboards"]) {
|
|
40814
40814
|
const value = definition.resources?.[key];
|
|
40815
40815
|
if (value !== undefined && value !== "bundle" && value !== "reference-only") {
|
|
40816
40816
|
throw new TypeError(`captureLark resources.${key} must be bundle or reference-only`);
|
|
@@ -40836,6 +40836,8 @@ var getSourceType = (sourceDefinition) => {
|
|
|
40836
40836
|
resources: {
|
|
40837
40837
|
...definition.resources?.images === undefined ? {} : { images: definition.resources.images },
|
|
40838
40838
|
...definition.resources?.gifs === undefined ? {} : { gifs: definition.resources.gifs },
|
|
40839
|
+
...definition.resources?.files === undefined ? {} : { files: definition.resources.files },
|
|
40840
|
+
...definition.resources?.whiteboards === undefined ? {} : { whiteboards: definition.resources.whiteboards },
|
|
40839
40841
|
videos: definition.resources?.videos ?? "reference-only",
|
|
40840
40842
|
maxBytesPerResource,
|
|
40841
40843
|
maxTotalBytes
|
|
@@ -41463,6 +41465,7 @@ var init_indexerApprovedKnowledge = __esm(() => {
|
|
|
41463
41465
|
});
|
|
41464
41466
|
|
|
41465
41467
|
// ../context/src/index.ts
|
|
41468
|
+
var DEFAULT_PACKAGE_RULE_LIMITS;
|
|
41466
41469
|
var init_src2 = __esm(() => {
|
|
41467
41470
|
init_siteTheme();
|
|
41468
41471
|
init_packageSite();
|
|
@@ -41516,6 +41519,7 @@ var init_src2 = __esm(() => {
|
|
|
41516
41519
|
init_indexerApprovedKnowledge();
|
|
41517
41520
|
init_articleStructure();
|
|
41518
41521
|
init_articleSourceLocatorInput();
|
|
41522
|
+
DEFAULT_PACKAGE_RULE_LIMITS = { fileKb: 16, totalKb: 64 };
|
|
41519
41523
|
});
|
|
41520
41524
|
|
|
41521
41525
|
// src/project/documentRun.ts
|
|
@@ -71250,6 +71254,37 @@ var init_approvedFileRead = __esm(() => {
|
|
|
71250
71254
|
import_yaml13 = __toESM(require_dist(), 1);
|
|
71251
71255
|
});
|
|
71252
71256
|
|
|
71257
|
+
// src/project/knowledgePathPatterns.ts
|
|
71258
|
+
function globToRegExp(pattern) {
|
|
71259
|
+
const normalized = pattern.split("\\").join("/");
|
|
71260
|
+
if (normalized.endsWith("/**")) {
|
|
71261
|
+
const prefix = normalized.slice(0, -3).replace(/[.+^${}()|[\]\\]/gu, "\\$&");
|
|
71262
|
+
return new RegExp(`^${prefix}(?:/.*)?$`, "u");
|
|
71263
|
+
}
|
|
71264
|
+
let out = "^";
|
|
71265
|
+
for (let index2 = 0;index2 < normalized.length; index2++) {
|
|
71266
|
+
const char = normalized[index2];
|
|
71267
|
+
const next = normalized[index2 + 1];
|
|
71268
|
+
if (char === "*" && next === "*") {
|
|
71269
|
+
out += ".*";
|
|
71270
|
+
index2++;
|
|
71271
|
+
} else if (char === "*") {
|
|
71272
|
+
out += "[^/]*";
|
|
71273
|
+
} else if (char === "?") {
|
|
71274
|
+
out += "[^/]";
|
|
71275
|
+
} else {
|
|
71276
|
+
out += char?.replace(/[.+^${}()|[\]\\]/gu, "\\$&") ?? "";
|
|
71277
|
+
}
|
|
71278
|
+
}
|
|
71279
|
+
return new RegExp(`${out}$`, "u");
|
|
71280
|
+
}
|
|
71281
|
+
function matchingKnowledgePatterns(path2, patterns) {
|
|
71282
|
+
return patterns?.filter((pattern) => pattern === path2 || globToRegExp(pattern).test(path2)) ?? [];
|
|
71283
|
+
}
|
|
71284
|
+
function matchesKnowledgePattern(path2, patterns) {
|
|
71285
|
+
return matchingKnowledgePatterns(path2, patterns).length > 0;
|
|
71286
|
+
}
|
|
71287
|
+
|
|
71253
71288
|
// src/project/okfTypes.ts
|
|
71254
71289
|
function isKnowledgeCollection(value) {
|
|
71255
71290
|
return value !== undefined && KNOWLEDGE_COLLECTIONS.includes(value);
|
|
@@ -71260,14 +71295,16 @@ function okfTypeForCollection(collection) {
|
|
|
71260
71295
|
function okfRootForCollection(collection) {
|
|
71261
71296
|
return OKF_ROOT_BY_COLLECTION[collection];
|
|
71262
71297
|
}
|
|
71263
|
-
function okfPackagePathForKnowledgePath(relPath) {
|
|
71298
|
+
function okfPackagePathForKnowledgePath(relPath, rules) {
|
|
71264
71299
|
const parts = relPath.split(/[\\/]+/u).filter(Boolean);
|
|
71265
71300
|
const hasKnowledgeRoot = parts[0] === "knowledge";
|
|
71266
71301
|
const collection = hasKnowledgeRoot ? parts[1] : parts[0];
|
|
71267
71302
|
if (!isKnowledgeCollection(collection))
|
|
71268
71303
|
return relPath;
|
|
71269
71304
|
const rest = hasKnowledgeRoot ? parts.slice(2) : parts.slice(1);
|
|
71270
|
-
|
|
71305
|
+
let root = okfRootForCollection(collection);
|
|
71306
|
+
if (root === "rules" && matchesKnowledgePattern([collection, ...rest].join("/"), rules?.exclude))
|
|
71307
|
+
root = "guides";
|
|
71271
71308
|
return root === collection ? [root, ...rest].join("/") : [root, collection, ...rest].join("/");
|
|
71272
71309
|
}
|
|
71273
71310
|
function okfTypeForKnowledgePath(relPath) {
|
|
@@ -71349,7 +71386,7 @@ function namespaceOkfPath(pkg, relPath) {
|
|
|
71349
71386
|
return relPath;
|
|
71350
71387
|
}
|
|
71351
71388
|
function packageKnowledgeOutputPath(pkg, approvedRelPath) {
|
|
71352
|
-
return namespaceOkfPath(pkg, okfPackagePathForKnowledgePath(approvedRelPath));
|
|
71389
|
+
return namespaceOkfPath(pkg, okfPackagePathForKnowledgePath(approvedRelPath, pkg.kind === "package.kb" ? pkg.rules : undefined));
|
|
71353
71390
|
}
|
|
71354
71391
|
function packageTemplateOutputPath(pkg, logicalRelPath) {
|
|
71355
71392
|
return namespaceOkfPath(pkg, logicalRelPath);
|
|
@@ -77347,6 +77384,13 @@ function formatPackageBuildSummary(pkg) {
|
|
|
77347
77384
|
const explanation = warning.code === "package-article-not-selected" ? "is not included; its source coordinate is retained for inspection" : warning.code === "package-link-anchor-unresolved" ? "has an unresolved section anchor; check the target heading or explicit anchor" : "has no matching Markdown page in this package; check the selected navigation";
|
|
77348
77385
|
lines.push(` warning: ${warning.path} references ${warning.target}, which ${explanation}.`);
|
|
77349
77386
|
}
|
|
77387
|
+
if (pkg.rules) {
|
|
77388
|
+
lines.push(` warning: ${pkg.rules.message}`);
|
|
77389
|
+
for (const path2 of pkg.rules.oversized) {
|
|
77390
|
+
lines.push(` ${path2}: ${pkg.rules.files.find((file) => file.path === path2)?.kb ?? "?"} KB`);
|
|
77391
|
+
}
|
|
77392
|
+
lines.push(` next: ${pkg.rules.next_action.instruction}`);
|
|
77393
|
+
}
|
|
77350
77394
|
const optimization = pkg.resources.delivery.optimization;
|
|
77351
77395
|
for (const warning of optimization?.warnings ?? []) {
|
|
77352
77396
|
lines.push(` image replaced with placeholder: ${warning.path}: ${warning.reason}`);
|
|
@@ -77858,7 +77902,7 @@ function knowledgeInventory(files, templateRelPath, navigation = DEFAULT_PACKAGE
|
|
|
77858
77902
|
const productionFrontmatter = parseKnowledgeFrontmatter(file.content);
|
|
77859
77903
|
const frontmatter = packageKnowledgeFrontmatter(productionFrontmatter);
|
|
77860
77904
|
const productionMetadata = packageKnowledgeMetadata(productionFrontmatter);
|
|
77861
|
-
const logicalOutputRelPath = okfPackagePathForKnowledgePath(file.relPath);
|
|
77905
|
+
const logicalOutputRelPath = okfPackagePathForKnowledgePath(file.relPath, pkg?.kind === "package.kb" ? pkg.rules : undefined);
|
|
77862
77906
|
const outputRelPath = pkg === undefined ? logicalOutputRelPath : packageKnowledgeOutputPath(pkg, file.relPath);
|
|
77863
77907
|
const sourcePath = file.relPath;
|
|
77864
77908
|
const sourceCollection = splitKnowledgePath(file.relPath).collection;
|
|
@@ -86106,6 +86150,7 @@ function materializationItem(resource) {
|
|
|
86106
86150
|
};
|
|
86107
86151
|
}
|
|
86108
86152
|
function createLarkCaptureReport(input) {
|
|
86153
|
+
const budgetExceeded = input.resourceMaterialization.items.some((item) => item.reason_code === "image-budget-exceeded");
|
|
86109
86154
|
const descriptors = new Map(input.resources.map((resource) => [resourceKey2(resource), resource]));
|
|
86110
86155
|
return {
|
|
86111
86156
|
schema_version: LARK_CAPTURE_REPORT_SCHEMA_VERSION,
|
|
@@ -86119,9 +86164,22 @@ function createLarkCaptureReport(input) {
|
|
|
86119
86164
|
attributes: descriptor?.attributes ?? {}
|
|
86120
86165
|
};
|
|
86121
86166
|
}),
|
|
86122
|
-
...input.access === undefined ? {} : { access: input.access }
|
|
86167
|
+
...input.access === undefined ? {} : { access: input.access },
|
|
86168
|
+
...budgetExceeded && input.resourceBudget !== undefined ? { resource_budget: {
|
|
86169
|
+
maxBytesPerResource: input.resourceBudget.maxBytesPerResource,
|
|
86170
|
+
maxTotalBytes: input.resourceBudget.maxTotalBytes
|
|
86171
|
+
} } : {}
|
|
86123
86172
|
};
|
|
86124
86173
|
}
|
|
86174
|
+
function parseResourceBudget(value) {
|
|
86175
|
+
if (value === undefined)
|
|
86176
|
+
return;
|
|
86177
|
+
const positive = (field) => typeof field === "number" && Number.isSafeInteger(field) && field > 0;
|
|
86178
|
+
if (!isRecord10(value) || !positive(value.maxBytesPerResource) || !positive(value.maxTotalBytes)) {
|
|
86179
|
+
throw new TypeError("Lark capture report resource_budget must hold positive maxBytesPerResource and maxTotalBytes");
|
|
86180
|
+
}
|
|
86181
|
+
return { maxBytesPerResource: value.maxBytesPerResource, maxTotalBytes: value.maxTotalBytes };
|
|
86182
|
+
}
|
|
86125
86183
|
function parseAccess(value) {
|
|
86126
86184
|
if (value === undefined)
|
|
86127
86185
|
return;
|
|
@@ -86185,6 +86243,7 @@ function parseLarkCaptureReport(value) {
|
|
|
86185
86243
|
throw new TypeError("Lark capture report resource_materialization is required");
|
|
86186
86244
|
}
|
|
86187
86245
|
const access4 = parseAccess(value.access);
|
|
86246
|
+
const resourceBudget = parseResourceBudget(value.resource_budget);
|
|
86188
86247
|
return {
|
|
86189
86248
|
schema_version: LARK_CAPTURE_REPORT_SCHEMA_VERSION,
|
|
86190
86249
|
fidelity,
|
|
@@ -86194,7 +86253,8 @@ function parseLarkCaptureReport(value) {
|
|
|
86194
86253
|
...enriched[index2]?.title === undefined ? {} : { title: enriched[index2].title },
|
|
86195
86254
|
attributes: enriched[index2]?.attributes ?? {}
|
|
86196
86255
|
})),
|
|
86197
|
-
...access4 === undefined ? {} : { access: access4 }
|
|
86256
|
+
...access4 === undefined ? {} : { access: access4 },
|
|
86257
|
+
...resourceBudget === undefined ? {} : { resource_budget: resourceBudget }
|
|
86198
86258
|
};
|
|
86199
86259
|
}
|
|
86200
86260
|
function captureReportMaterialization(report) {
|
|
@@ -91323,34 +91383,23 @@ var init_packageAssetDelivery = __esm(() => {
|
|
|
91323
91383
|
import { existsSync as existsSync17 } from "node:fs";
|
|
91324
91384
|
import { mkdir as mkdir27, readFile as readFile68, writeFile as writeFile20 } from "node:fs/promises";
|
|
91325
91385
|
import { dirname as dirname33, join as join78 } from "node:path";
|
|
91326
|
-
function
|
|
91327
|
-
const
|
|
91328
|
-
|
|
91329
|
-
|
|
91330
|
-
|
|
91331
|
-
|
|
91332
|
-
|
|
91333
|
-
|
|
91334
|
-
|
|
91335
|
-
|
|
91336
|
-
|
|
91337
|
-
out += ".*";
|
|
91338
|
-
index3++;
|
|
91339
|
-
} else if (char === "*") {
|
|
91340
|
-
out += "[^/]*";
|
|
91341
|
-
} else if (char === "?") {
|
|
91342
|
-
out += "[^/]";
|
|
91343
|
-
} else {
|
|
91344
|
-
out += char?.replace(/[.+^${}()|[\]\\]/gu, "\\$&") ?? "";
|
|
91345
|
-
}
|
|
91346
|
-
}
|
|
91347
|
-
return new RegExp(`${out}$`, "u");
|
|
91386
|
+
function withAlwaysApply(markdown) {
|
|
91387
|
+
const end = markdown.startsWith(`---
|
|
91388
|
+
`) ? markdown.indexOf(`
|
|
91389
|
+
---`, 3) : -1;
|
|
91390
|
+
if (end < 0)
|
|
91391
|
+
return markdown;
|
|
91392
|
+
const frontmatter = markdown.slice(4, end);
|
|
91393
|
+
const updated = /^alwaysApply:.*$/mu.test(frontmatter) ? frontmatter.replace(/^alwaysApply:.*$/mu, "alwaysApply: true") : `alwaysApply: true
|
|
91394
|
+
${frontmatter}`;
|
|
91395
|
+
return `---
|
|
91396
|
+
${updated}${markdown.slice(end)}`;
|
|
91348
91397
|
}
|
|
91349
91398
|
function matchesAny(path2, patterns) {
|
|
91350
|
-
return
|
|
91399
|
+
return matchesKnowledgePattern(path2, patterns);
|
|
91351
91400
|
}
|
|
91352
91401
|
function matchingPatterns(path2, patterns) {
|
|
91353
|
-
return
|
|
91402
|
+
return matchingKnowledgePatterns(path2, patterns);
|
|
91354
91403
|
}
|
|
91355
91404
|
function selectionReasonsForFile(file, pkg) {
|
|
91356
91405
|
const internalCollection = file.relPath.split("/")[0];
|
|
@@ -91361,7 +91410,7 @@ function selectionReasonsForFile(file, pkg) {
|
|
|
91361
91410
|
return null;
|
|
91362
91411
|
if (pkg.select?.collections?.length)
|
|
91363
91412
|
reasons.push({ kind: "collection", value: internalCollection });
|
|
91364
|
-
const okfRoot = okfRootForCollection(internalCollection);
|
|
91413
|
+
const okfRoot = okfPackagePathForKnowledgePath(file.relPath, pkg.kind === "package.kb" ? pkg.rules : undefined).startsWith("guides/") ? "guides" : okfRootForCollection(internalCollection);
|
|
91365
91414
|
if (pkg.select?.okfRoots?.length && !pkg.select.okfRoots.includes(okfRoot))
|
|
91366
91415
|
return null;
|
|
91367
91416
|
if (pkg.select?.okfRoots?.length)
|
|
@@ -91529,7 +91578,9 @@ async function writeSelectedPackageKnowledge(input) {
|
|
|
91529
91578
|
content: links.markdown
|
|
91530
91579
|
});
|
|
91531
91580
|
const file = byPath.get(approvedByOutput.get(projected.pageOutputPath));
|
|
91532
|
-
|
|
91581
|
+
const alwaysOn = input.pkg.kind === "package.kb" && projected.pageOutputPath.startsWith("rules/") && matchesKnowledgePattern(approvedByOutput.get(projected.pageOutputPath).replace(/^knowledge\//u, ""), input.pkg.rules?.alwaysApply);
|
|
91582
|
+
const ruleMarkdown = alwaysOn ? withAlwaysApply(markdown) : markdown;
|
|
91583
|
+
await writeFile20(outputPath, ruleMarkdown + articleProvenanceMarkdown(file?.article, registry2, repositoryRemote), "utf8");
|
|
91533
91584
|
return links.warnings;
|
|
91534
91585
|
}));
|
|
91535
91586
|
for (const result of results) {
|
|
@@ -95330,6 +95381,101 @@ var init_runtimeEvents = __esm(() => {
|
|
|
95330
95381
|
RUNTIME_EVENT_SINK_DESCRIPTION_MAX_BYTES = 16 * 1024;
|
|
95331
95382
|
});
|
|
95332
95383
|
|
|
95384
|
+
// src/project/sdkAlignment.ts
|
|
95385
|
+
var exports_sdkAlignment = {};
|
|
95386
|
+
__export(exports_sdkAlignment, {
|
|
95387
|
+
inspectSdkAlignment: () => inspectSdkAlignment
|
|
95388
|
+
});
|
|
95389
|
+
import { readFile as readFile74 } from "node:fs/promises";
|
|
95390
|
+
import { join as join87 } from "node:path";
|
|
95391
|
+
function core3(version3) {
|
|
95392
|
+
const match = /^(\d+)\.(\d+)\.(\d+)$/u.exec(version3?.trim() ?? "");
|
|
95393
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
|
|
95394
|
+
}
|
|
95395
|
+
function older(left, right) {
|
|
95396
|
+
for (let index3 = 0;index3 < 3; index3++)
|
|
95397
|
+
if (left[index3] !== right[index3])
|
|
95398
|
+
return left[index3] < right[index3];
|
|
95399
|
+
return false;
|
|
95400
|
+
}
|
|
95401
|
+
async function readJson(path2) {
|
|
95402
|
+
try {
|
|
95403
|
+
return JSON.parse(await readFile74(path2, "utf8"));
|
|
95404
|
+
} catch {
|
|
95405
|
+
return null;
|
|
95406
|
+
}
|
|
95407
|
+
}
|
|
95408
|
+
async function inspectSdkAlignment(projectRoot, cliVersion = readCurrentPackageVersion()) {
|
|
95409
|
+
const manifest = await readJson(join87(projectRoot, "package.json"));
|
|
95410
|
+
const dependencies = { ...manifest?.devDependencies, ...manifest?.dependencies };
|
|
95411
|
+
const pinned = dependencies[SDK_PACKAGE];
|
|
95412
|
+
const installed = (await readJson(join87(projectRoot, "node_modules", ...SDK_PACKAGE.split("/"), "package.json")))?.version;
|
|
95413
|
+
const cli = core3(cliVersion);
|
|
95414
|
+
const target = core3(pinned);
|
|
95415
|
+
if (pinned === undefined || cli === null || target === null || target[0] !== cli[0])
|
|
95416
|
+
return;
|
|
95417
|
+
const installedCore = core3(typeof installed === "string" ? installed : null);
|
|
95418
|
+
if (!older(target, cli) && (installedCore === null || !older(installedCore, cli)))
|
|
95419
|
+
return;
|
|
95420
|
+
return {
|
|
95421
|
+
workspace_sdk: { pinned, installed: typeof installed === "string" ? installed : null },
|
|
95422
|
+
cli: cliVersion,
|
|
95423
|
+
message: `The workspace pins ${SDK_PACKAGE} ${pinned}, older than the running CLI ${cliVersion}; its documentation and registry parsing lag behind the CLI.`,
|
|
95424
|
+
instruction: `Set ${SDK_PACKAGE} in package.json to ${cliVersion}, install with the workspace package manager (bun install for bun.lock) and commit package.json together with the lock file in the next delivery. A routine update without content changes may deliver this upgrade alone.`
|
|
95425
|
+
};
|
|
95426
|
+
}
|
|
95427
|
+
var SDK_PACKAGE = "@c4a/context";
|
|
95428
|
+
var init_sdkAlignment = __esm(() => {
|
|
95429
|
+
init_workspace();
|
|
95430
|
+
});
|
|
95431
|
+
|
|
95432
|
+
// src/project/packageRulesSize.ts
|
|
95433
|
+
import { readFile as readFile75 } from "node:fs/promises";
|
|
95434
|
+
import { join as join88 } from "node:path";
|
|
95435
|
+
async function inspectPackageRules(projectRoot, pkg) {
|
|
95436
|
+
if (pkg.kind !== "package.kb")
|
|
95437
|
+
return;
|
|
95438
|
+
const limits = { ...DEFAULT_PACKAGE_RULE_LIMITS, ...pkg.rules?.limits };
|
|
95439
|
+
const files = [];
|
|
95440
|
+
let total = 0;
|
|
95441
|
+
for (const file of await walkPackageFiles(join88(projectRoot, pkg.outDir, "rules"))) {
|
|
95442
|
+
if (!/\.mdx?$/iu.test(file.relPath))
|
|
95443
|
+
continue;
|
|
95444
|
+
const content3 = await readFile75(file.absPath, "utf8");
|
|
95445
|
+
const frontmatter = /^---\r?\n([\s\S]*?)\r?\n---/u.exec(content3)?.[1] ?? "";
|
|
95446
|
+
if (/^type:\s*["']?Knowledge Directory["']?\s*$/mu.test(frontmatter))
|
|
95447
|
+
continue;
|
|
95448
|
+
const bytes = Buffer.byteLength(content3);
|
|
95449
|
+
total += bytes;
|
|
95450
|
+
files.push({ path: `rules/${file.relPath}`, kb: kb(bytes), always_apply: /^alwaysApply:\s*true\s*$/mu.test(frontmatter) });
|
|
95451
|
+
}
|
|
95452
|
+
const oversized = files.filter((file) => file.kb > limits.fileKb).map((file) => file.path);
|
|
95453
|
+
const totalKb = kb(total);
|
|
95454
|
+
if (oversized.length === 0 && totalKb <= limits.totalKb)
|
|
95455
|
+
return;
|
|
95456
|
+
const alignment = await inspectSdkAlignment(projectRoot);
|
|
95457
|
+
const instruction = "Read the listed rule articles and decide with the user which are binding rules: keep those short and list the ones every session needs in the package's rules.alwaysApply; move reference material (dictionaries, tables, methodology) to guides/ with rules.exclude. Adjust rules.limits if larger rules are intended. Then rebuild.";
|
|
95458
|
+
return {
|
|
95459
|
+
total_kb: totalKb,
|
|
95460
|
+
limits,
|
|
95461
|
+
files: files.sort((left, right) => right.kb - left.kb),
|
|
95462
|
+
oversized,
|
|
95463
|
+
total_exceeded: totalKb > limits.totalKb,
|
|
95464
|
+
message: `Package rules total ${totalKb} KB${oversized.length ? `; ${oversized.length} file(s) exceed ${limits.fileKb} KB` : ""}. AI tools may load package rules into every session.`,
|
|
95465
|
+
next_action: {
|
|
95466
|
+
file: "src/index.ts",
|
|
95467
|
+
instruction: alignment ? `First upgrade the workspace SDK as version_alignment describes: an older SDK ignores the rules option. ${instruction}` : instruction
|
|
95468
|
+
},
|
|
95469
|
+
...alignment ? { version_alignment: alignment } : {}
|
|
95470
|
+
};
|
|
95471
|
+
}
|
|
95472
|
+
var kb = (bytes) => Math.round(bytes / 102.4) / 10;
|
|
95473
|
+
var init_packageRulesSize = __esm(() => {
|
|
95474
|
+
init_src2();
|
|
95475
|
+
init_packageBuildReceipt();
|
|
95476
|
+
init_sdkAlignment();
|
|
95477
|
+
});
|
|
95478
|
+
|
|
95333
95479
|
// src/project/packageTemplateGuard.ts
|
|
95334
95480
|
function validatePackageTemplateContract(pkg, templateFiles2) {
|
|
95335
95481
|
if (pkg.kind === "package.kb") {
|
|
@@ -95514,8 +95660,8 @@ var init_packageTemplateGuard = __esm(() => {
|
|
|
95514
95660
|
});
|
|
95515
95661
|
|
|
95516
95662
|
// src/project/approvedKnowledgeSnapshots.ts
|
|
95517
|
-
import { readFile as
|
|
95518
|
-
import { join as
|
|
95663
|
+
import { readFile as readFile76 } from "node:fs/promises";
|
|
95664
|
+
import { join as join89 } from "node:path";
|
|
95519
95665
|
function approvedKnowledgeSnapshotsFromStructure(structure) {
|
|
95520
95666
|
return validateArticleStructureEntries(structure?.articles ?? []);
|
|
95521
95667
|
}
|
|
@@ -95524,7 +95670,7 @@ async function prepareApprovedKnowledgeSnapshotTarget(input) {
|
|
|
95524
95670
|
return;
|
|
95525
95671
|
let before;
|
|
95526
95672
|
try {
|
|
95527
|
-
before = await
|
|
95673
|
+
before = await readFile76(join89(input.projectRoot, STRUCTURE_PATH2), "utf8");
|
|
95528
95674
|
} catch (error) {
|
|
95529
95675
|
if (error.code !== "ENOENT")
|
|
95530
95676
|
throw error;
|
|
@@ -95703,10 +95849,10 @@ var init_approvedStructureInputHash = () => {};
|
|
|
95703
95849
|
|
|
95704
95850
|
// src/project/verifyApprovedStructure.ts
|
|
95705
95851
|
import { existsSync as existsSync22 } from "node:fs";
|
|
95706
|
-
import { join as
|
|
95852
|
+
import { join as join90 } from "node:path";
|
|
95707
95853
|
async function validateApprovedStructure(input) {
|
|
95708
95854
|
const issue = (code, path3, message) => input.issues.push({ severity: "error", code, path: path3, message });
|
|
95709
|
-
const path2 =
|
|
95855
|
+
const path2 = join90(input.projectRoot, STRUCTURE_PATH3);
|
|
95710
95856
|
if (!input.structureOverride && !existsSync22(path2))
|
|
95711
95857
|
return;
|
|
95712
95858
|
let parsed;
|
|
@@ -95864,7 +96010,7 @@ var init_verifyDiagnostics = __esm(() => {
|
|
|
95864
96010
|
|
|
95865
96011
|
// src/project/verify.ts
|
|
95866
96012
|
import { existsSync as existsSync23 } from "node:fs";
|
|
95867
|
-
import { join as
|
|
96013
|
+
import { join as join91 } from "node:path";
|
|
95868
96014
|
function evidenceStatusForIssues(issues) {
|
|
95869
96015
|
if (issues.some((issue) => issue.severity === "error"))
|
|
95870
96016
|
return "fail";
|
|
@@ -95938,7 +96084,7 @@ async function verifyProjectWorkspace(projectRoot, options = {}) {
|
|
|
95938
96084
|
pageRelPath: `knowledge/${file.relPath}`,
|
|
95939
96085
|
content: content3
|
|
95940
96086
|
})) {
|
|
95941
|
-
if (!existsSync23(
|
|
96087
|
+
if (!existsSync23(join91(projectRoot, assetPath))) {
|
|
95942
96088
|
issues.push({
|
|
95943
96089
|
severity: "error",
|
|
95944
96090
|
code: "approved-resource-missing",
|
|
@@ -96077,8 +96223,8 @@ __export(exports_packageBuilder, {
|
|
|
96077
96223
|
});
|
|
96078
96224
|
import { createHash as createHash28 } from "node:crypto";
|
|
96079
96225
|
import { existsSync as existsSync24 } from "node:fs";
|
|
96080
|
-
import { mkdir as mkdir33, readdir as readdir21, readFile as
|
|
96081
|
-
import { dirname as dirname40, join as
|
|
96226
|
+
import { mkdir as mkdir33, readdir as readdir21, readFile as readFile77, rm as rm20, writeFile as writeFile25 } from "node:fs/promises";
|
|
96227
|
+
import { dirname as dirname40, join as join92, resolve as resolve31 } from "node:path";
|
|
96082
96228
|
function packageAssetDeliverySummary(value) {
|
|
96083
96229
|
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
96084
96230
|
return;
|
|
@@ -96100,7 +96246,7 @@ function assertPackageOutputDir(pkg) {
|
|
|
96100
96246
|
}
|
|
96101
96247
|
function packageFingerprintPath(projectRoot, pkg) {
|
|
96102
96248
|
assertSafeRenderedPath(`${pkg.name}.json`, "package fingerprint path");
|
|
96103
|
-
return
|
|
96249
|
+
return join92(projectRoot, PACKAGE_FINGERPRINT_ROOT, `${pkg.name}.json`);
|
|
96104
96250
|
}
|
|
96105
96251
|
async function listApprovedKnowledge(projectRoot) {
|
|
96106
96252
|
const metadata = await readApprovedKnowledgeMetadataIndex(projectRoot);
|
|
@@ -96141,7 +96287,7 @@ async function listTemplateFiles(projectRoot, templatePath) {
|
|
|
96141
96287
|
const files = await walkPackageFiles(templateRoot);
|
|
96142
96288
|
return Promise.all(files.filter((file) => file.relPath.split("/").at(-1) !== PACKAGE_TEMPLATE_REVIEW_FILE).map(async (file) => ({
|
|
96143
96289
|
...file,
|
|
96144
|
-
content: await
|
|
96290
|
+
content: await readFile77(file.absPath, "utf8")
|
|
96145
96291
|
})));
|
|
96146
96292
|
}
|
|
96147
96293
|
function stableHash2(value) {
|
|
@@ -96183,6 +96329,7 @@ async function packageInputFingerprint(input) {
|
|
|
96183
96329
|
name: input.pkg.name,
|
|
96184
96330
|
select: input.pkg.select ?? null,
|
|
96185
96331
|
navigation: input.pkg.kind === "package.kb" ? packageNavigation(input.pkg) : null,
|
|
96332
|
+
...input.pkg.kind === "package.kb" && input.pkg.rules !== undefined ? { rules: input.pkg.rules } : {},
|
|
96186
96333
|
assets: input.pkg.kind === "package.kb" ? input.pkg.assets ?? null : null,
|
|
96187
96334
|
...input.pkg.kind === "package.kb" && input.pkg.site ? { site: { ...input.pkg.site, renderer: PACKAGE_SITE_VERSION } } : {},
|
|
96188
96335
|
template: input.pkg.template,
|
|
@@ -96209,7 +96356,7 @@ async function readPackageManifest(projectRoot, pkg) {
|
|
|
96209
96356
|
if (!existsSync24(filePath2))
|
|
96210
96357
|
return null;
|
|
96211
96358
|
try {
|
|
96212
|
-
const parsed = JSON.parse(await
|
|
96359
|
+
const parsed = JSON.parse(await readFile77(filePath2, "utf8"));
|
|
96213
96360
|
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
96214
96361
|
const candidate = parsed;
|
|
96215
96362
|
if (typeof candidate.builder_protocol === "string" && typeof candidate.fingerprint === "string" && typeof candidate.output_fingerprint === "string" && typeof candidate.output_files === "number" && Array.isArray(candidate.outputs)) {
|
|
@@ -96256,12 +96403,12 @@ async function writePackageFingerprint(input) {
|
|
|
96256
96403
|
`, "utf8");
|
|
96257
96404
|
}
|
|
96258
96405
|
async function removeOrphanPackageDirs(projectRoot, packages) {
|
|
96259
|
-
const distRoot =
|
|
96406
|
+
const distRoot = join92(projectRoot, "dist");
|
|
96260
96407
|
if (!existsSync24(distRoot))
|
|
96261
96408
|
return;
|
|
96262
96409
|
const declaredNames = new Set(packages.flatMap((pkg) => packageOutputDirs(pkg).map((path2) => path2.slice("dist/".length))));
|
|
96263
96410
|
const entries2 = await readdir21(distRoot, { withFileTypes: true });
|
|
96264
|
-
await Promise.all(entries2.filter((entry) => entry.isDirectory() && !declaredNames.has(entry.name)).map((entry) => rm20(
|
|
96411
|
+
await Promise.all(entries2.filter((entry) => entry.isDirectory() && !declaredNames.has(entry.name)).map((entry) => rm20(join92(distRoot, entry.name), { recursive: true, force: true, maxRetries: 3, retryDelay: 100 })));
|
|
96265
96412
|
}
|
|
96266
96413
|
async function collectPackageFreshness(projectRoot, packages) {
|
|
96267
96414
|
assertDistinctPackageOutputs(packages);
|
|
@@ -96270,7 +96417,7 @@ async function collectPackageFreshness(projectRoot, packages) {
|
|
|
96270
96417
|
assertPackageOutputDir(pkg);
|
|
96271
96418
|
const selected = selectPackageKnowledge(approved, pkg);
|
|
96272
96419
|
assertSafeRenderedPath(pkg.template.path, "package template path");
|
|
96273
|
-
const templateRoot =
|
|
96420
|
+
const templateRoot = join92(projectRoot, pkg.template.path);
|
|
96274
96421
|
const templateExists = existsSync24(templateRoot);
|
|
96275
96422
|
if (!templateExists) {
|
|
96276
96423
|
throw new ContextError(ExitCode.WorkspaceStateError, `package template path is missing: ${pkg.template.path}`, {
|
|
@@ -96437,11 +96584,13 @@ async function buildProjectPackagesInternal(projectRoot, options) {
|
|
|
96437
96584
|
if (previousManifest?.builderProtocol === PACKAGE_BUILDER_PROTOCOL_VERSION && previousManifest.fingerprint === fingerprint && previousManifest.assetDelivery !== undefined) {
|
|
96438
96585
|
const existingOutput = await packageOutputFingerprint(projectRoot, pkg);
|
|
96439
96586
|
if (existingOutput.fingerprint === previousManifest.outputFingerprint) {
|
|
96587
|
+
const unchangedRules = await inspectPackageRules(projectRoot, pkg);
|
|
96440
96588
|
summaries.push({
|
|
96441
96589
|
name: pkg.name,
|
|
96442
96590
|
kind: packageKind(pkg),
|
|
96443
96591
|
outDir: pkg.outDir,
|
|
96444
96592
|
...pkg.kind === "package.kb" && pkg.site ? { siteOutDir: packageSiteOutputDir(pkg) } : {},
|
|
96593
|
+
...unchangedRules ? { rules: unchangedRules } : {},
|
|
96445
96594
|
inputs: selected.length,
|
|
96446
96595
|
files: existingOutput.files,
|
|
96447
96596
|
state: "unchanged",
|
|
@@ -96521,19 +96670,19 @@ async function buildProjectPackagesInternal(projectRoot, options) {
|
|
|
96521
96670
|
if (stagedPkg.kind === "package.llms") {
|
|
96522
96671
|
const articles = await Promise.all(llmsArticles(stagedPkg, selected).map(async (article) => ({
|
|
96523
96672
|
...article,
|
|
96524
|
-
content: await
|
|
96673
|
+
content: await readFile77(join92(projectRoot, stagedPkg.outDir, article.path), "utf8")
|
|
96525
96674
|
})));
|
|
96526
|
-
await writeLlmsDocuments(
|
|
96675
|
+
await writeLlmsDocuments(join92(projectRoot, stagedPkg.outDir), buildLlmsDocuments({
|
|
96527
96676
|
title: stagedPkg.name,
|
|
96528
96677
|
articles,
|
|
96529
96678
|
...reading ? { map: reading } : {}
|
|
96530
96679
|
}), { preserveIndex: true });
|
|
96531
96680
|
}
|
|
96532
|
-
await writePackageVersion(projectRoot,
|
|
96681
|
+
await writePackageVersion(projectRoot, join92(projectRoot, stagedPkg.outDir));
|
|
96533
96682
|
await writePackageSite({ projectRoot, pkg: stagedPkg, selected, ...siteUrl ? { siteUrl } : {}, ...reading ? { structure: reading } : {} });
|
|
96534
96683
|
const linkWarnings = [
|
|
96535
96684
|
...writtenKnowledge2.linkWarnings,
|
|
96536
|
-
...await inspectPackageMarkdownDirectory(
|
|
96685
|
+
...await inspectPackageMarkdownDirectory(join92(projectRoot, stagedPkg.outDir))
|
|
96537
96686
|
];
|
|
96538
96687
|
return { ...writtenKnowledge2, linkWarnings };
|
|
96539
96688
|
});
|
|
@@ -96551,9 +96700,11 @@ async function buildProjectPackagesInternal(projectRoot, options) {
|
|
|
96551
96700
|
assetDelivery: writtenKnowledge.assetDelivery,
|
|
96552
96701
|
linkWarnings: writtenKnowledge.linkWarnings
|
|
96553
96702
|
});
|
|
96703
|
+
const rulesReport = await inspectPackageRules(projectRoot, pkg);
|
|
96554
96704
|
summaries.push({
|
|
96555
96705
|
name: pkg.name,
|
|
96556
96706
|
...pkg.kind === "package.kb" && pkg.site ? { siteOutDir: packageSiteOutputDir(pkg) } : {},
|
|
96707
|
+
...rulesReport ? { rules: rulesReport } : {},
|
|
96557
96708
|
kind: packageKind(pkg),
|
|
96558
96709
|
outDir: pkg.outDir,
|
|
96559
96710
|
inputs: selected.length,
|
|
@@ -96665,6 +96816,7 @@ var init_packageBuilder = __esm(() => {
|
|
|
96665
96816
|
init_packageIndexes();
|
|
96666
96817
|
init_packageNavigation();
|
|
96667
96818
|
init_packageBuildReceipt();
|
|
96819
|
+
init_packageRulesSize();
|
|
96668
96820
|
init_packageBuildContent();
|
|
96669
96821
|
init_packageTemplateGuard();
|
|
96670
96822
|
init_packageAssets();
|
|
@@ -96678,7 +96830,7 @@ var init_packageBuilder = __esm(() => {
|
|
|
96678
96830
|
init_siteTranslation();
|
|
96679
96831
|
init_approvedKnowledgeMetadata();
|
|
96680
96832
|
import_yaml44 = __toESM(require_dist(), 1);
|
|
96681
|
-
PACKAGE_FINGERPRINT_ROOT =
|
|
96833
|
+
PACKAGE_FINGERPRINT_ROOT = join92(".tmp", "context-runtime", "packages");
|
|
96682
96834
|
});
|
|
96683
96835
|
|
|
96684
96836
|
// src/project/knowledgeMaintenance.ts
|
|
@@ -96693,15 +96845,15 @@ __export(exports_knowledgeMaintenance, {
|
|
|
96693
96845
|
cancelKnowledgeMaintenance: () => cancelKnowledgeMaintenance,
|
|
96694
96846
|
advanceKnowledgeMaintenance: () => advanceKnowledgeMaintenance
|
|
96695
96847
|
});
|
|
96696
|
-
import { readFile as
|
|
96697
|
-
import { join as
|
|
96848
|
+
import { readFile as readFile78, readdir as readdir22, rm as rm21 } from "node:fs/promises";
|
|
96849
|
+
import { join as join93 } from "node:path";
|
|
96698
96850
|
async function deliveryDigest(root) {
|
|
96699
|
-
const directory =
|
|
96851
|
+
const directory = join93(root, ".tmp/context-runtime/packages");
|
|
96700
96852
|
try {
|
|
96701
96853
|
const files = (await readdir22(directory)).filter((name3) => name3.endsWith(".json")).sort();
|
|
96702
96854
|
if (!files.length)
|
|
96703
96855
|
return indexerProtocolDigest(null);
|
|
96704
|
-
return indexerProtocolDigest(await Promise.all(files.map((name3) =>
|
|
96856
|
+
return indexerProtocolDigest(await Promise.all(files.map((name3) => readFile78(join93(directory, name3), "utf8"))));
|
|
96705
96857
|
} catch (error) {
|
|
96706
96858
|
if (error.code === "ENOENT")
|
|
96707
96859
|
return indexerProtocolDigest(null);
|
|
@@ -96844,7 +96996,7 @@ async function observeKnowledgeMaintenance(root) {
|
|
|
96844
96996
|
async function maintenanceRevision(root) {
|
|
96845
96997
|
const observed = await observeKnowledgeMaintenance(root);
|
|
96846
96998
|
const localInputs = observed.state.active ? {
|
|
96847
|
-
revision: await
|
|
96999
|
+
revision: await readFile78(join93(root, MAINTENANCE_ROOT, "revision.json"), "utf8").catch((error) => {
|
|
96848
97000
|
if (error.code === "ENOENT")
|
|
96849
97001
|
return null;
|
|
96850
97002
|
throw error;
|
|
@@ -96957,7 +97109,7 @@ async function finishMaintenanceRevision(root, outcome = "completed") {
|
|
|
96957
97109
|
outcome = state.active.completion_outcome;
|
|
96958
97110
|
state.active.phase = "finishing";
|
|
96959
97111
|
await saveMaintenance(root, state);
|
|
96960
|
-
await rm21(
|
|
97112
|
+
await rm21(join93(root, MAINTENANCE_ROOT, "revision.json"), { force: true });
|
|
96961
97113
|
state.completed.push({ id: state.active.input.id, input_digest: indexerProtocolDigest(state.active.input), outcome });
|
|
96962
97114
|
delete state.active;
|
|
96963
97115
|
await saveMaintenance(root, state);
|
|
@@ -96991,8 +97143,8 @@ async function discardMaintenanceDraft(root) {
|
|
|
96991
97143
|
const owned = new Set([...request?.batch_candidates ?? [], ...request?.candidate ? [request.candidate] : []].map((item) => item.candidate_id));
|
|
96992
97144
|
if (candidates.some((item) => !owned.has(item.candidate_id)))
|
|
96993
97145
|
throw new TypeError("Unrelated Candidates are present; no draft was discarded. Inspect the current review before retrying cancellation.");
|
|
96994
|
-
await rm21(
|
|
96995
|
-
await rm21(
|
|
97146
|
+
await rm21(join93(root, CANDIDATE_LEDGER_FILE), { force: true });
|
|
97147
|
+
await rm21(join93(root, MAINTENANCE_ROOT, "revision.json"), { force: true });
|
|
96996
97148
|
const { closeProjectWorkspace } = await Promise.resolve().then(() => (init_close(), exports_close));
|
|
96997
97149
|
const { buildProjectPackages: buildProjectPackages2 } = await Promise.resolve().then(() => (init_packageBuilder(), exports_packageBuilder));
|
|
96998
97150
|
await closeProjectWorkspace(root);
|
|
@@ -97020,8 +97172,8 @@ __export(exports_taskRollback, {
|
|
|
97020
97172
|
readTaskRollback: () => readTaskRollback,
|
|
97021
97173
|
finishTaskRollback: () => finishTaskRollback
|
|
97022
97174
|
});
|
|
97023
|
-
import { readFile as
|
|
97024
|
-
import { join as
|
|
97175
|
+
import { readFile as readFile79, rm as rm22 } from "node:fs/promises";
|
|
97176
|
+
import { join as join94 } from "node:path";
|
|
97025
97177
|
async function productionScope(projectRoot) {
|
|
97026
97178
|
const { readProductionStage: readProductionStage2 } = await Promise.resolve().then(() => (init_productionStageStore(), exports_productionStageStore));
|
|
97027
97179
|
const stage = await readProductionStage2(projectRoot);
|
|
@@ -97062,7 +97214,7 @@ async function readTaskRollback(projectRoot) {
|
|
|
97062
97214
|
}
|
|
97063
97215
|
async function contents(projectRoot, path2) {
|
|
97064
97216
|
try {
|
|
97065
|
-
return await
|
|
97217
|
+
return await readFile79(join94(projectRoot, path2), "utf8");
|
|
97066
97218
|
} catch (error) {
|
|
97067
97219
|
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT")
|
|
97068
97220
|
return;
|
|
@@ -97210,7 +97362,7 @@ async function finishTaskRollback(projectRoot) {
|
|
|
97210
97362
|
const production = await readProductionStage2(projectRoot);
|
|
97211
97363
|
const recorded = rollback.production;
|
|
97212
97364
|
if (production && recorded !== undefined && (recorded === null || !recorded.discard || recorded.stage !== production.id)) {
|
|
97213
|
-
await rm22(
|
|
97365
|
+
await rm22(join94(projectRoot, await revisionStoragePath(projectRoot)), { force: true });
|
|
97214
97366
|
return {
|
|
97215
97367
|
action: "finished",
|
|
97216
97368
|
production: recorded?.stage === production.id ? "resumed" : "kept",
|
|
@@ -97345,7 +97497,7 @@ __export(exports_close, {
|
|
|
97345
97497
|
});
|
|
97346
97498
|
import { existsSync as existsSync25 } from "node:fs";
|
|
97347
97499
|
import { mkdir as mkdir34, writeFile as writeFile26 } from "node:fs/promises";
|
|
97348
|
-
import { dirname as dirname41, join as
|
|
97500
|
+
import { dirname as dirname41, join as join95 } from "node:path";
|
|
97349
97501
|
function parseFrontmatter4(content3) {
|
|
97350
97502
|
const match = /^---\r?\n([\s\S]*?)\r?\n---/u.exec(content3);
|
|
97351
97503
|
if (match?.[1] === undefined)
|
|
@@ -97417,7 +97569,7 @@ async function deriveApprovedStructure(projectRoot) {
|
|
|
97417
97569
|
}
|
|
97418
97570
|
async function writeApprovedStructureProjection(projectRoot) {
|
|
97419
97571
|
const { inputHash, structure, compactFiles } = await deriveApprovedStructure(projectRoot);
|
|
97420
|
-
const outputPath =
|
|
97572
|
+
const outputPath = join95(projectRoot, STRUCTURE_PATH4);
|
|
97421
97573
|
await mkdir34(dirname41(outputPath), { recursive: true });
|
|
97422
97574
|
await writeFile26(outputPath, import_yaml45.default.stringify(structure), "utf8");
|
|
97423
97575
|
await Promise.all(compactFiles.map((file) => writeFile26(file.absPath, file.content, "utf8")));
|
|
@@ -97428,7 +97580,7 @@ function referencesReceipt() {
|
|
|
97428
97580
|
}
|
|
97429
97581
|
async function readProjectCloseStatus(projectRoot) {
|
|
97430
97582
|
const approved = await approvedKnowledgeFiles(projectRoot);
|
|
97431
|
-
const structurePath =
|
|
97583
|
+
const structurePath = join95(projectRoot, STRUCTURE_PATH4);
|
|
97432
97584
|
if (approved.length === 0 && !existsSync25(structurePath))
|
|
97433
97585
|
return { state: "missing", diagnostics: [] };
|
|
97434
97586
|
const inputHash = await approvedKnowledgeInputHash(projectRoot);
|
|
@@ -97492,7 +97644,7 @@ async function closeProjectWorkspace(projectRoot) {
|
|
|
97492
97644
|
next: "Fix context verify errors, then rerun context close --format json."
|
|
97493
97645
|
});
|
|
97494
97646
|
}
|
|
97495
|
-
const outputPath =
|
|
97647
|
+
const outputPath = join95(projectRoot, STRUCTURE_PATH4);
|
|
97496
97648
|
await mkdir34(dirname41(outputPath), { recursive: true });
|
|
97497
97649
|
await writeFile26(outputPath, `${import_yaml45.default.stringify(structure)}`, "utf8");
|
|
97498
97650
|
await Promise.all(compactFiles.map((file) => writeFile26(file.absPath, file.content, "utf8")));
|
|
@@ -97569,7 +97721,7 @@ var init_close = __esm(() => {
|
|
|
97569
97721
|
init_knowledgeAssetRepair();
|
|
97570
97722
|
init_approvedKnowledgeMetadata();
|
|
97571
97723
|
import_yaml45 = __toESM(require_dist(), 1);
|
|
97572
|
-
STRUCTURE_PATH4 =
|
|
97724
|
+
STRUCTURE_PATH4 = join95(KNOWLEDGE_ROOT, "structure.yaml");
|
|
97573
97725
|
});
|
|
97574
97726
|
|
|
97575
97727
|
// src/project/processedScopeStorage.ts
|
|
@@ -97582,8 +97734,8 @@ __export(exports_processedScopeStorage, {
|
|
|
97582
97734
|
commitProcessedScopes: () => commitProcessedScopes,
|
|
97583
97735
|
captureProcessedScopes: () => captureProcessedScopes
|
|
97584
97736
|
});
|
|
97585
|
-
import { access as access6, readFile as
|
|
97586
|
-
import { dirname as dirname42, join as
|
|
97737
|
+
import { access as access6, readFile as readFile80 } from "node:fs/promises";
|
|
97738
|
+
import { dirname as dirname42, join as join96 } from "node:path";
|
|
97587
97739
|
async function currentScopeSourceVersion(projectRoot, sourceRef) {
|
|
97588
97740
|
if (sourceRef.startsWith("repo-content:"))
|
|
97589
97741
|
return repoContentWorkingVersion(projectRoot, sourceRef);
|
|
@@ -97609,7 +97761,7 @@ async function currentScopeSourceVersion(projectRoot, sourceRef) {
|
|
|
97609
97761
|
throw new TypeError(`Source must identify one registered document: ${sourceRef}`);
|
|
97610
97762
|
const entry = entries2[0];
|
|
97611
97763
|
const manifest = entry.snapshot?.manifest ?? `${entry.materializedAt}/manifest.json`;
|
|
97612
|
-
return parseDocumentSnapshotForSource(JSON.parse(await
|
|
97764
|
+
return parseDocumentSnapshotForSource(JSON.parse(await readFile80(join96(projectRoot, manifest), "utf8")), entry.name).snapshot_hash;
|
|
97613
97765
|
}
|
|
97614
97766
|
async function sourceMaterialAvailable(projectRoot, sourceRef) {
|
|
97615
97767
|
try {
|
|
@@ -97632,10 +97784,10 @@ async function sourceMaterialAvailable(projectRoot, sourceRef) {
|
|
|
97632
97784
|
if (entries2.length !== 1)
|
|
97633
97785
|
return false;
|
|
97634
97786
|
const manifestPath = entries2[0].snapshot?.manifest ?? `${entries2[0].materializedAt}/manifest.json`;
|
|
97635
|
-
const snapshot = parseDocumentSnapshotForSource(JSON.parse(await
|
|
97636
|
-
const base =
|
|
97787
|
+
const snapshot = parseDocumentSnapshotForSource(JSON.parse(await readFile80(join96(projectRoot, manifestPath), "utf8")), entries2[0].name);
|
|
97788
|
+
const base = join96(projectRoot, dirname42(manifestPath));
|
|
97637
97789
|
for (const file of snapshot.files)
|
|
97638
|
-
await access6(
|
|
97790
|
+
await access6(join96(base, file.path));
|
|
97639
97791
|
return true;
|
|
97640
97792
|
} catch {
|
|
97641
97793
|
return false;
|
|
@@ -97673,7 +97825,7 @@ async function commitProcessedScopes(projectRoot, scopes) {
|
|
|
97673
97825
|
const { articles } = await inspectSettledReferences(projectRoot, repoContent, scopes.map((scope2) => scope2.source_ref), settled);
|
|
97674
97826
|
const { approvedStructureInputHashFor: approvedStructureInputHashFor2 } = await Promise.resolve().then(() => (init_close(), exports_close));
|
|
97675
97827
|
const input_hash = structure.parsed.input_hash === await approvedStructureInputHashFor2(projectRoot, previous2) ? await approvedStructureInputHashFor2(projectRoot, articles) : structure.parsed.input_hash;
|
|
97676
|
-
await atomicWriteFile(
|
|
97828
|
+
await atomicWriteFile(join96(projectRoot, structure.path), import_yaml46.default.stringify({ ...structure.parsed, input_hash, articles, processed_scopes: processed }));
|
|
97677
97829
|
}
|
|
97678
97830
|
async function invalidateChangedProcessedRequirements(projectRoot, previous2, current3) {
|
|
97679
97831
|
const targets = new Map(current3.map((requirement2) => [requirement2.id, indexerProtocolDigest(requirement2)]));
|
|
@@ -97687,7 +97839,7 @@ async function invalidateChangedProcessedRequirements(projectRoot, previous2, cu
|
|
|
97687
97839
|
const retained = scopes.filter((scope2) => !changed.has(scope2.requirement_ref));
|
|
97688
97840
|
if (retained.length === scopes.length)
|
|
97689
97841
|
return;
|
|
97690
|
-
await atomicWriteFile(
|
|
97842
|
+
await atomicWriteFile(join96(projectRoot, structure.path), import_yaml46.default.stringify({ ...structure.parsed, processed_scopes: retained }));
|
|
97691
97843
|
}
|
|
97692
97844
|
async function migrateUnchangedScopeReferences(projectRoot, scopes) {
|
|
97693
97845
|
const structure = await readKnowledgeStructure(projectRoot);
|
|
@@ -97706,7 +97858,7 @@ async function migrateUnchangedScopeReferences(projectRoot, scopes) {
|
|
|
97706
97858
|
}
|
|
97707
97859
|
const { approvedStructureInputHashFor: approvedStructureInputHashFor2 } = await Promise.resolve().then(() => (init_close(), exports_close));
|
|
97708
97860
|
const input_hash = structure.parsed.input_hash === await approvedStructureInputHashFor2(projectRoot, previous2) ? await approvedStructureInputHashFor2(projectRoot, second.articles) : structure.parsed.input_hash;
|
|
97709
|
-
await atomicWriteFile(
|
|
97861
|
+
await atomicWriteFile(join96(projectRoot, structure.path), import_yaml46.default.stringify({ ...structure.parsed, input_hash, articles: second.articles }));
|
|
97710
97862
|
return previous2.flatMap((article) => article.sections.flatMap((section) => section.references.flatMap((before, index3) => {
|
|
97711
97863
|
const after = second.articles.find((item) => item.path === article.path).sections.find((item) => item.id === section.id).references[index3];
|
|
97712
97864
|
return indexerProtocolDigest(before) === indexerProtocolDigest(after) ? [] : [{ article: article.path, section: section.id, before, after }];
|
|
@@ -97725,7 +97877,7 @@ var init_processedScopeStorage = __esm(() => {
|
|
|
97725
97877
|
});
|
|
97726
97878
|
|
|
97727
97879
|
// src/project/codeAnalysisInput.ts
|
|
97728
|
-
import { readFile as
|
|
97880
|
+
import { readFile as readFile81 } from "node:fs/promises";
|
|
97729
97881
|
import { relative as relative28, resolve as resolve32 } from "node:path";
|
|
97730
97882
|
function safeCodeSourcePath(root, normalizedPath) {
|
|
97731
97883
|
const absolute = resolve32(root, normalizedPath);
|
|
@@ -97768,7 +97920,7 @@ function sourceFileSystem(root, tracked, texts, readSource) {
|
|
|
97768
97920
|
return {
|
|
97769
97921
|
readFile: async (path2) => {
|
|
97770
97922
|
const normalized = assertTrackedFile(path2);
|
|
97771
|
-
return contents2.has(normalized) ? contents2.get(normalized) : readSource ? readSource(normalized) :
|
|
97923
|
+
return contents2.has(normalized) ? contents2.get(normalized) : readSource ? readSource(normalized) : readFile81(safeCodeSourcePath(root, normalized), "utf8");
|
|
97772
97924
|
},
|
|
97773
97925
|
async readdir(path2) {
|
|
97774
97926
|
const normalized = normalizedVirtualPath(path2);
|
|
@@ -97955,7 +98107,7 @@ __export(exports_approvedRevisionPrograms, {
|
|
|
97955
98107
|
});
|
|
97956
98108
|
import { execFile as execFile16 } from "node:child_process";
|
|
97957
98109
|
import { promisify as promisify13 } from "node:util";
|
|
97958
|
-
import { extname as extname11, join as
|
|
98110
|
+
import { extname as extname11, join as join97 } from "node:path";
|
|
97959
98111
|
import { createRequire as createRequire6 } from "node:module";
|
|
97960
98112
|
import { pathToFileURL } from "node:url";
|
|
97961
98113
|
async function prepareRevisionProgramBlocks(root, sourceRefs, scopes, references) {
|
|
@@ -97971,7 +98123,7 @@ async function prepareRevisionProgramBlocks(root, sourceRefs, scopes, references
|
|
|
97971
98123
|
if (entries2.length !== 1)
|
|
97972
98124
|
throw new TypeError(`Regeneration requires one registered source: ${source2}`);
|
|
97973
98125
|
const entry = entries2[0];
|
|
97974
|
-
const directory =
|
|
98126
|
+
const directory = join97(root, entry.materializedAt);
|
|
97975
98127
|
const paths = [...new Set(references.filter((reference2) => reference2.source_ref === source2).map((reference2) => reference2.locator.path))];
|
|
97976
98128
|
if (!paths.length)
|
|
97977
98129
|
continue;
|
|
@@ -98157,8 +98309,8 @@ __export(exports_approvedRevision, {
|
|
|
98157
98309
|
assertApprovedRevisionBase: () => assertApprovedRevisionBase,
|
|
98158
98310
|
APPROVED_REVISION_PATH: () => APPROVED_REVISION_PATH
|
|
98159
98311
|
});
|
|
98160
|
-
import { readFile as
|
|
98161
|
-
import { join as
|
|
98312
|
+
import { readFile as readFile82, realpath as realpath14, rm as rm23 } from "node:fs/promises";
|
|
98313
|
+
import { join as join98, relative as relative29, isAbsolute as isAbsolute16 } from "node:path";
|
|
98162
98314
|
function requestDigest(input) {
|
|
98163
98315
|
const scopes = input.processed_scopes?.filter((scope2) => input.target.source_refs.some((ref2) => repoContentScopeMatches(scope2.source_ref, ref2) || ref2.startsWith(`${scope2.source_ref}#`) || ref2.startsWith(`${scope2.source_ref}/`)));
|
|
98164
98316
|
const ids = new Set(scopes?.map((scope2) => scope2.requirement_ref));
|
|
@@ -98196,7 +98348,7 @@ function revisionCandidateFingerprint(revision, markdown, sections) {
|
|
|
98196
98348
|
}
|
|
98197
98349
|
async function readApprovedRevision(projectRoot) {
|
|
98198
98350
|
try {
|
|
98199
|
-
return parseApprovedRevision(JSON.parse(await
|
|
98351
|
+
return parseApprovedRevision(JSON.parse(await readFile82(join98(projectRoot, await revisionStoragePath(projectRoot)), "utf8")));
|
|
98200
98352
|
} catch (error) {
|
|
98201
98353
|
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT")
|
|
98202
98354
|
return;
|
|
@@ -98255,16 +98407,16 @@ async function resolveApprovedRevisionAuthor(projectRoot, request) {
|
|
|
98255
98407
|
}
|
|
98256
98408
|
async function targetBytes(projectRoot, path2) {
|
|
98257
98409
|
const project = await realpath14(projectRoot);
|
|
98258
|
-
const root = await realpath14(
|
|
98410
|
+
const root = await realpath14(join98(projectRoot, "knowledge"));
|
|
98259
98411
|
const rootRelative = relative29(project, root);
|
|
98260
98412
|
if (isAbsolute16(rootRelative) || rootRelative === ".." || rootRelative.startsWith("../")) {
|
|
98261
98413
|
throw new TypeError("Approved knowledge directory leaves the Context workspace");
|
|
98262
98414
|
}
|
|
98263
|
-
const target = await realpath14(
|
|
98415
|
+
const target = await realpath14(join98(root, path2));
|
|
98264
98416
|
const rel = relative29(root, target);
|
|
98265
98417
|
if (isAbsolute16(rel) || rel === ".." || rel.startsWith("../"))
|
|
98266
98418
|
throw new TypeError("Approved revision target leaves knowledge/");
|
|
98267
|
-
return
|
|
98419
|
+
return readFile82(target, "utf8");
|
|
98268
98420
|
}
|
|
98269
98421
|
async function assertApprovedRevisionBase(projectRoot, request) {
|
|
98270
98422
|
let current3;
|
|
@@ -98417,7 +98569,7 @@ ${import_yaml47.default.stringify({ ...import_yaml47.default.parse(fields), type
|
|
|
98417
98569
|
revision: requestDigest(payload)
|
|
98418
98570
|
});
|
|
98419
98571
|
if (input.persist !== false) {
|
|
98420
|
-
await atomicWriteFile(
|
|
98572
|
+
await atomicWriteFile(join98(input.projectRoot, await revisionStoragePath(input.projectRoot)), `${JSON.stringify(request)}
|
|
98421
98573
|
`);
|
|
98422
98574
|
markSubmissionState("committed");
|
|
98423
98575
|
}
|
|
@@ -98545,7 +98697,7 @@ async function completeApprovedRevision(input) {
|
|
|
98545
98697
|
const { prepareRevisionBatchContinuation: prepareRevisionBatchContinuation3 } = await Promise.resolve().then(() => (init_approvedRevisionBatch(), exports_approvedRevisionBatch));
|
|
98546
98698
|
const next2 = await prepareRevisionBatchContinuation3(input.projectRoot, request, request.batch_candidates ?? []);
|
|
98547
98699
|
if (next2 || request.batch_candidates?.length || request.build_pending) {
|
|
98548
|
-
await atomicWriteFile(
|
|
98700
|
+
await atomicWriteFile(join98(input.projectRoot, await revisionStoragePath(input.projectRoot)), `${JSON.stringify(next2 ?? { ...request, review_ready: true })}
|
|
98549
98701
|
`);
|
|
98550
98702
|
markSubmissionState("committed");
|
|
98551
98703
|
} else {
|
|
@@ -98553,10 +98705,10 @@ async function completeApprovedRevision(input) {
|
|
|
98553
98705
|
}
|
|
98554
98706
|
return;
|
|
98555
98707
|
}
|
|
98556
|
-
const current3 = await
|
|
98708
|
+
const current3 = await readFile82(join98(input.projectRoot, await revisionStoragePath(input.projectRoot)), "utf8");
|
|
98557
98709
|
let previous2;
|
|
98558
98710
|
try {
|
|
98559
|
-
previous2 = await
|
|
98711
|
+
previous2 = await readFile82(join98(input.projectRoot, CANDIDATE_LEDGER_FILE), "utf8");
|
|
98560
98712
|
} catch (error) {
|
|
98561
98713
|
if (!(error && typeof error === "object" && ("code" in error) && error.code === "ENOENT"))
|
|
98562
98714
|
throw error;
|
|
@@ -98651,7 +98803,7 @@ async function advanceApprovedRevision(projectRoot, request, buildPending = fals
|
|
|
98651
98803
|
return;
|
|
98652
98804
|
const { readProductionStage: readProductionStage2 } = await Promise.resolve().then(() => (init_productionStageStore(), exports_productionStageStore));
|
|
98653
98805
|
if (await readProductionStage2(projectRoot)) {
|
|
98654
|
-
await rm23(
|
|
98806
|
+
await rm23(join98(projectRoot, await revisionStoragePath(projectRoot)), { force: true });
|
|
98655
98807
|
return;
|
|
98656
98808
|
}
|
|
98657
98809
|
const { clearCompletedLifecycle: clearCompletedLifecycle2 } = await Promise.resolve().then(() => (init_lifecycleCleanup(), exports_lifecycleCleanup));
|
|
@@ -98755,12 +98907,12 @@ Additional request: ${input.instruction.trim()}` : input.instruction.trim();
|
|
|
98755
98907
|
}))
|
|
98756
98908
|
} : {}
|
|
98757
98909
|
} };
|
|
98758
|
-
const current3 = await
|
|
98910
|
+
const current3 = await readFile82(join98(input.projectRoot, await revisionStoragePath(input.projectRoot)), "utf8");
|
|
98759
98911
|
const content3 = `${JSON.stringify({ ...payload, revision: requestDigest(payload) })}
|
|
98760
98912
|
`;
|
|
98761
98913
|
let ledger;
|
|
98762
98914
|
try {
|
|
98763
|
-
ledger = await
|
|
98915
|
+
ledger = await readFile82(join98(input.projectRoot, CANDIDATE_LEDGER_FILE), "utf8");
|
|
98764
98916
|
} catch (error) {
|
|
98765
98917
|
if (!(error && typeof error === "object" && ("code" in error) && error.code === "ENOENT"))
|
|
98766
98918
|
throw error;
|
|
@@ -98880,8 +99032,8 @@ var init_sourceInputMutation = __esm(() => {
|
|
|
98880
99032
|
|
|
98881
99033
|
// src/project/documentCapture.ts
|
|
98882
99034
|
import { createHash as createHash29 } from "node:crypto";
|
|
98883
|
-
import { lstat as lstat15, mkdir as mkdir35, readdir as readdir23, readFile as
|
|
98884
|
-
import { basename as basename7, dirname as dirname43, extname as extname12, join as
|
|
99035
|
+
import { lstat as lstat15, mkdir as mkdir35, readdir as readdir23, readFile as readFile83, rm as rm24, stat as stat10, writeFile as writeFile27 } from "node:fs/promises";
|
|
99036
|
+
import { basename as basename7, dirname as dirname43, extname as extname12, join as join99, relative as relative30, resolve as resolve33 } from "node:path";
|
|
98885
99037
|
function toPosixPath7(path2) {
|
|
98886
99038
|
return path2.split(/[\\/]+/u).filter((part) => part.length > 0).join("/");
|
|
98887
99039
|
}
|
|
@@ -99019,7 +99171,7 @@ async function walkMarkdownFiles(input) {
|
|
|
99019
99171
|
const visit3 = async (dir) => {
|
|
99020
99172
|
const entries2 = await readdir23(dir, { withFileTypes: true });
|
|
99021
99173
|
for (const entry of entries2) {
|
|
99022
|
-
const absolutePath =
|
|
99174
|
+
const absolutePath = join99(dir, entry.name);
|
|
99023
99175
|
if (entry.isSymbolicLink() && input.rejectSymlinks === true) {
|
|
99024
99176
|
throw new ContextError(ExitCode.UserError, `file source contains a symbolic link: ${toPosixPath7(relative30(input.localRoot, absolutePath))}`, {
|
|
99025
99177
|
category: ErrorCategory.UserInputInvalid,
|
|
@@ -99049,14 +99201,14 @@ async function walkMarkdownFiles(input) {
|
|
|
99049
99201
|
}
|
|
99050
99202
|
async function writeTextIfChanged(path2, content3) {
|
|
99051
99203
|
try {
|
|
99052
|
-
if (await
|
|
99204
|
+
if (await readFile83(path2, "utf8") === content3)
|
|
99053
99205
|
return;
|
|
99054
99206
|
} catch {}
|
|
99055
99207
|
await mkdir35(dirname43(path2), { recursive: true });
|
|
99056
99208
|
await writeFile27(path2, content3, "utf8");
|
|
99057
99209
|
}
|
|
99058
99210
|
function sourceManifestPath(entry) {
|
|
99059
|
-
return entry.snapshot?.manifest ??
|
|
99211
|
+
return entry.snapshot?.manifest ?? join99(entry.materializedAt, "manifest.json");
|
|
99060
99212
|
}
|
|
99061
99213
|
function runtimeError2(message, detail) {
|
|
99062
99214
|
return new ContextError(ExitCode.UserError, message, {
|
|
@@ -99161,7 +99313,7 @@ async function removeEmptySnapshotDirs(root, dir = root) {
|
|
|
99161
99313
|
for (const entry of entries2) {
|
|
99162
99314
|
if (!entry.isDirectory() || entry.name === ".tmp" || entry.name === ".cache")
|
|
99163
99315
|
continue;
|
|
99164
|
-
await removeEmptySnapshotDirs(root,
|
|
99316
|
+
await removeEmptySnapshotDirs(root, join99(dir, entry.name));
|
|
99165
99317
|
}
|
|
99166
99318
|
if (dir === root)
|
|
99167
99319
|
return;
|
|
@@ -99173,7 +99325,7 @@ async function removeEmptySnapshotDirs(root, dir = root) {
|
|
|
99173
99325
|
async function cleanupStaleSnapshotFiles(input) {
|
|
99174
99326
|
for (const path2 of input.previousPaths) {
|
|
99175
99327
|
if (!input.currentPaths.has(path2)) {
|
|
99176
|
-
await rm24(
|
|
99328
|
+
await rm24(join99(input.materializedAtAbsPath, path2), { force: true });
|
|
99177
99329
|
}
|
|
99178
99330
|
}
|
|
99179
99331
|
await removeEmptySnapshotDirs(input.materializedAtAbsPath);
|
|
@@ -99185,7 +99337,7 @@ async function readDocumentFiles(input) {
|
|
|
99185
99337
|
for (const file of input.files) {
|
|
99186
99338
|
let raw;
|
|
99187
99339
|
try {
|
|
99188
|
-
raw = await
|
|
99340
|
+
raw = await readFile83(file.absolutePath, "utf8");
|
|
99189
99341
|
} catch (error) {
|
|
99190
99342
|
const message = error instanceof Error ? error.message : String(error);
|
|
99191
99343
|
throw runtimeError2(`file source ${input.sourceName} document read failed: ${file.snapshotPath}: ${message}`, {
|
|
@@ -99386,9 +99538,9 @@ async function runCaptureFilePhaseUnlocked(input) {
|
|
|
99386
99538
|
routeMetadata,
|
|
99387
99539
|
documentSnapshot
|
|
99388
99540
|
});
|
|
99389
|
-
const manifestAbsPath =
|
|
99541
|
+
const manifestAbsPath = join99(input.projectRoot, manifestPath);
|
|
99390
99542
|
const materializedAt = entry.materializedAt;
|
|
99391
|
-
const materializedAtAbsPath =
|
|
99543
|
+
const materializedAtAbsPath = join99(input.projectRoot, materializedAt);
|
|
99392
99544
|
const manifestInput = {
|
|
99393
99545
|
sourceType: "file",
|
|
99394
99546
|
sourceName: resolved.sourceName,
|
|
@@ -99440,13 +99592,13 @@ async function runCaptureFilePhaseUnlocked(input) {
|
|
|
99440
99592
|
}));
|
|
99441
99593
|
try {
|
|
99442
99594
|
for (const file of snapshotFiles) {
|
|
99443
|
-
await writeTextIfChanged(
|
|
99595
|
+
await writeTextIfChanged(join99(materializedAtAbsPath, file.path), String(file.bytes));
|
|
99444
99596
|
}
|
|
99445
99597
|
for (const file of files.metadata) {
|
|
99446
|
-
await writeTextIfChanged(
|
|
99598
|
+
await writeTextIfChanged(join99(materializedAtAbsPath, file.snapshotPath), routeMetadata.rawByPath.get(file.snapshotPath) ?? "");
|
|
99447
99599
|
}
|
|
99448
99600
|
for (const asset of linkedAssets) {
|
|
99449
|
-
await writeCaptureAssetIfChanged(
|
|
99601
|
+
await writeCaptureAssetIfChanged(join99(materializedAtAbsPath, asset.snapshotPath), asset.bytes);
|
|
99450
99602
|
}
|
|
99451
99603
|
await writeTextIfChanged(manifestAbsPath, manifestContent);
|
|
99452
99604
|
await cleanupStaleSnapshotFiles({
|
|
@@ -99648,7 +99800,7 @@ var init_entityId = __esm(() => {
|
|
|
99648
99800
|
// src/project/reviewShared.ts
|
|
99649
99801
|
import { createHash as createHash30 } from "node:crypto";
|
|
99650
99802
|
import { mkdir as mkdir36, writeFile as writeFile28 } from "node:fs/promises";
|
|
99651
|
-
import { dirname as dirname44, join as
|
|
99803
|
+
import { dirname as dirname44, join as join100 } from "node:path";
|
|
99652
99804
|
function isRecord14(value) {
|
|
99653
99805
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
99654
99806
|
}
|
|
@@ -99691,7 +99843,7 @@ async function buildApprovedArticleIndex(projectRoot) {
|
|
|
99691
99843
|
if (!isApprovedKnowledgeMarkdownPath(rel))
|
|
99692
99844
|
continue;
|
|
99693
99845
|
const { absPath, content: content3 } = file;
|
|
99694
|
-
const relPath =
|
|
99846
|
+
const relPath = join100("knowledge", collection, rel);
|
|
99695
99847
|
assetReferencesByRelPath.set(relPath, knowledgeAssetReferences({
|
|
99696
99848
|
pageRelPath: relPath,
|
|
99697
99849
|
content: content3
|
|
@@ -99704,7 +99856,7 @@ async function buildApprovedArticleIndex(projectRoot) {
|
|
|
99704
99856
|
continue;
|
|
99705
99857
|
const frontmatter2 = hydrateApprovedFrontmatter({
|
|
99706
99858
|
frontmatter: parsed,
|
|
99707
|
-
relPath:
|
|
99859
|
+
relPath: join100(collection, rel),
|
|
99708
99860
|
metadata
|
|
99709
99861
|
});
|
|
99710
99862
|
const article = articlesByPath.get(`${collection}/${rel}`);
|
|
@@ -99759,8 +99911,8 @@ ${yaml3}
|
|
|
99759
99911
|
}
|
|
99760
99912
|
async function writeReviewActionLog(input) {
|
|
99761
99913
|
const stamp = new Date().toISOString().replace(/[-:.TZ]/gu, "");
|
|
99762
|
-
const relPath =
|
|
99763
|
-
const path2 =
|
|
99914
|
+
const relPath = join100(REVIEW_ACTION_ROOT2, `${stamp}-${input.action}-${input.id.replace(/[\\/]+/gu, "_")}.json`);
|
|
99915
|
+
const path2 = join100(input.projectRoot, relPath);
|
|
99764
99916
|
await mkdir36(dirname44(path2), { recursive: true });
|
|
99765
99917
|
await writeFile28(path2, `${JSON.stringify({
|
|
99766
99918
|
action: input.action,
|
|
@@ -99793,7 +99945,7 @@ var init_reviewShared = __esm(() => {
|
|
|
99793
99945
|
init_knowledgeAssets();
|
|
99794
99946
|
init_entityId();
|
|
99795
99947
|
import_yaml48 = __toESM(require_dist(), 1);
|
|
99796
|
-
REVIEW_ACTION_ROOT2 =
|
|
99948
|
+
REVIEW_ACTION_ROOT2 = join100(".tmp", "context-runtime", "review-actions");
|
|
99797
99949
|
});
|
|
99798
99950
|
|
|
99799
99951
|
// src/project/managedDocumentStatus.ts
|
|
@@ -99869,7 +100021,7 @@ __export(exports_statusReaders, {
|
|
|
99869
100021
|
countFiles: () => countFiles
|
|
99870
100022
|
});
|
|
99871
100023
|
import { existsSync as existsSync26, readFileSync as readFileSync9 } from "node:fs";
|
|
99872
|
-
import { join as
|
|
100024
|
+
import { join as join101 } from "node:path";
|
|
99873
100025
|
async function countFiles(root, predicate) {
|
|
99874
100026
|
if (!existsSync26(root))
|
|
99875
100027
|
return 0;
|
|
@@ -99878,7 +100030,7 @@ async function countFiles(root, predicate) {
|
|
|
99878
100030
|
const entries2 = await readCommandDirectory(dir);
|
|
99879
100031
|
for (const entry of entries2) {
|
|
99880
100032
|
const rel = prefix.length === 0 ? entry.name : `${prefix}/${entry.name}`;
|
|
99881
|
-
const abs =
|
|
100033
|
+
const abs = join101(dir, entry.name);
|
|
99882
100034
|
if (entry.isDirectory())
|
|
99883
100035
|
await visit3(abs, rel);
|
|
99884
100036
|
else if (entry.isFile() && predicate(rel))
|
|
@@ -100080,7 +100232,7 @@ async function documentSourceSiteHint(input) {
|
|
|
100080
100232
|
});
|
|
100081
100233
|
}
|
|
100082
100234
|
function documentSnapshotReadiness(input) {
|
|
100083
|
-
const manifestPath =
|
|
100235
|
+
const manifestPath = join101(input.projectRoot, input.manifest);
|
|
100084
100236
|
if (!existsSync26(manifestPath)) {
|
|
100085
100237
|
return {
|
|
100086
100238
|
ready: false,
|
|
@@ -100161,7 +100313,7 @@ function documentSnapshotReadiness(input) {
|
|
|
100161
100313
|
const missingFiles = [
|
|
100162
100314
|
...manifest.files.map((file) => file.path),
|
|
100163
100315
|
...(manifest.assets ?? []).filter((asset) => asset.content_hash !== undefined).map((asset) => asset.path)
|
|
100164
|
-
].filter((path2) => !existsSync26(
|
|
100316
|
+
].filter((path2) => !existsSync26(join101(input.projectRoot, input.materializedAt, path2)));
|
|
100165
100317
|
if (missingFiles.length > 0) {
|
|
100166
100318
|
return {
|
|
100167
100319
|
ready: false,
|
|
@@ -100208,12 +100360,12 @@ var init_statusReaders = __esm(() => {
|
|
|
100208
100360
|
|
|
100209
100361
|
// src/project/documentCaptureAvailability.ts
|
|
100210
100362
|
import { createHash as createHash31 } from "node:crypto";
|
|
100211
|
-
import { readFile as
|
|
100212
|
-
import { join as
|
|
100363
|
+
import { readFile as readFile84, rm as rm25 } from "node:fs/promises";
|
|
100364
|
+
import { join as join102 } from "node:path";
|
|
100213
100365
|
import { isDeepStrictEqual } from "node:util";
|
|
100214
100366
|
function receiptPath(root, phaseId) {
|
|
100215
100367
|
const key = createHash31("sha256").update(phaseId).digest("hex");
|
|
100216
|
-
return
|
|
100368
|
+
return join102(root, ".tmp/context-runtime/document-acquisition", `${key}.json`);
|
|
100217
100369
|
}
|
|
100218
100370
|
async function identity(root, phase) {
|
|
100219
100371
|
const resolved = await resolveDocumentPhaseSource({ projectRoot: root, phase });
|
|
@@ -100248,7 +100400,7 @@ async function runDocumentCaptureWithAvailability(root, phase, capture2) {
|
|
|
100248
100400
|
...Array.isArray(error.detail.access_events) ? { access_events: error.detail.access_events } : {},
|
|
100249
100401
|
message: source2.snapshotReady ? "Document refresh unavailable. Retain the validated registered snapshot; it is not confirmed current upstream." : "Document acquisition unavailable. Keep this source registered as a pending evidence gap; do not cite it or invent content. Unrelated work may continue."
|
|
100250
100402
|
};
|
|
100251
|
-
await applyAtomicFileBatch({ transactionRoot:
|
|
100403
|
+
await applyAtomicFileBatch({ transactionRoot: join102(root, ".tmp/context-runtime/transactions"), writes: [{ path: path2, bytes: `${JSON.stringify({ configuration, warning }, null, 2)}
|
|
100252
100404
|
` }] });
|
|
100253
100405
|
return {
|
|
100254
100406
|
kind: "document.capture.warning",
|
|
@@ -100265,7 +100417,7 @@ async function attachDocumentAcquisitionWarnings(root, phases, sources) {
|
|
|
100265
100417
|
continue;
|
|
100266
100418
|
let receipt2;
|
|
100267
100419
|
try {
|
|
100268
|
-
receipt2 = JSON.parse(await
|
|
100420
|
+
receipt2 = JSON.parse(await readFile84(receiptPath(root, phase.id), "utf8"));
|
|
100269
100421
|
} catch {
|
|
100270
100422
|
continue;
|
|
100271
100423
|
}
|
|
@@ -101407,8 +101559,8 @@ function pendingDocumentCaptureCommands(input) {
|
|
|
101407
101559
|
}
|
|
101408
101560
|
|
|
101409
101561
|
// src/project/productionStageRefresh.ts
|
|
101410
|
-
import { readFile as
|
|
101411
|
-
import { join as
|
|
101562
|
+
import { readFile as readFile85 } from "node:fs/promises";
|
|
101563
|
+
import { join as join103 } from "node:path";
|
|
101412
101564
|
async function refreshProductionStageSources(projectRoot, stage) {
|
|
101413
101565
|
const active = activeProductionSources(stage);
|
|
101414
101566
|
const affected = new Set(stage.gaps.filter((gap) => active.has(gap.scope)).map((gap) => gap.scope));
|
|
@@ -101453,14 +101605,14 @@ Restore the authorized source and retry preparation.
|
|
|
101453
101605
|
tasks: stage.tasks.map((task) => !["accepted", "excluded", "replaced"].includes(task.status) && task.sources.some((source2) => affected.has(source2.scope)) ? { ...task, status: "blocked", reason: "Source material refreshed; investigate and explicitly replace this unfinished task." } : task)
|
|
101454
101606
|
});
|
|
101455
101607
|
const directory = productionStageDirectory(stage.id);
|
|
101456
|
-
const contents2 = new Map([...sourceMaterials].map(([scope2, content3]) => [
|
|
101457
|
-
contents2.set(
|
|
101608
|
+
const contents2 = new Map([...sourceMaterials].map(([scope2, content3]) => [join103(directory, productionSourceFile(scope2)), content3]));
|
|
101609
|
+
contents2.set(join103(directory, "manifest.json"), `${JSON.stringify(updated)}
|
|
101458
101610
|
`);
|
|
101459
101611
|
const targets = [];
|
|
101460
101612
|
for (const [path2, content3] of contents2) {
|
|
101461
101613
|
let previous2;
|
|
101462
101614
|
try {
|
|
101463
|
-
previous2 = await
|
|
101615
|
+
previous2 = await readFile85(await safeProjectTarget(projectRoot, path2), "utf8");
|
|
101464
101616
|
} catch (error) {
|
|
101465
101617
|
if (error.code !== "ENOENT")
|
|
101466
101618
|
throw error;
|
|
@@ -101585,7 +101737,7 @@ var init_productionReport = __esm(() => {
|
|
|
101585
101737
|
});
|
|
101586
101738
|
|
|
101587
101739
|
// src/project/productionPlanningRoute.ts
|
|
101588
|
-
import { join as
|
|
101740
|
+
import { join as join104 } from "node:path";
|
|
101589
101741
|
async function productionPlanningRoute(input, stage) {
|
|
101590
101742
|
const request = stage ? undefined : await productionPlanningRequest(input.projectRoot);
|
|
101591
101743
|
const present = !!stage || !!request;
|
|
@@ -101623,7 +101775,7 @@ async function productionPlanningRoute(input, stage) {
|
|
|
101623
101775
|
id: `production/${stage.id}/planning`,
|
|
101624
101776
|
kind: "context-view",
|
|
101625
101777
|
media_type: "text/markdown",
|
|
101626
|
-
path:
|
|
101778
|
+
path: join104(input.projectRoot, productionStageDirectory(stage.id), "planning.md"),
|
|
101627
101779
|
read_state: "read-required"
|
|
101628
101780
|
}] : []
|
|
101629
101781
|
],
|
|
@@ -101651,7 +101803,7 @@ var init_productionPlanningRoute = __esm(() => {
|
|
|
101651
101803
|
|
|
101652
101804
|
// src/project/productionWorkflowRoute.ts
|
|
101653
101805
|
import { existsSync as existsSync28 } from "node:fs";
|
|
101654
|
-
import { join as
|
|
101806
|
+
import { join as join105 } from "node:path";
|
|
101655
101807
|
async function productionWorkflowRoute(input) {
|
|
101656
101808
|
const stage = await readProductionStage(input.projectRoot);
|
|
101657
101809
|
if (!stage || !stage.planning_complete)
|
|
@@ -101669,7 +101821,7 @@ async function productionWorkflowRoute(input) {
|
|
|
101669
101821
|
const selected = new Set(dispatch2.batches.flatMap((batch) => batch.tasks));
|
|
101670
101822
|
const context = { workspace: input.projectRoot, authorities: [...input.authorities], facts: { production: {
|
|
101671
101823
|
report_approved: stage.report_approved,
|
|
101672
|
-
prepared: !dispatch2.batches.length || existsSync28(
|
|
101824
|
+
prepared: !dispatch2.batches.length || existsSync28(join105(input.projectRoot, directory, "stage.md")) && stage.tasks.filter((task) => selected.has(task.id)).every((task) => task.status === "issued"),
|
|
101673
101825
|
writing_complete: dispatch2.batches.length === 0,
|
|
101674
101826
|
complete: dispatch2.state === "ended",
|
|
101675
101827
|
review_clear: rejected.length === 0,
|
|
@@ -101686,7 +101838,7 @@ async function productionWorkflowRoute(input) {
|
|
|
101686
101838
|
const resolved = await resolveRoute(provider, "indexer", "production", primary.routeId, context, evaluated.evaluation.revision);
|
|
101687
101839
|
const report = resolved.node === "confirm-production-report";
|
|
101688
101840
|
if (report)
|
|
101689
|
-
await writeProductionProjection(input.projectRoot,
|
|
101841
|
+
await writeProductionProjection(input.projectRoot, join105(directory, "plan.md"), productionPlanMarkdown(stage));
|
|
101690
101842
|
const prepare = resolved.node === "prepare-production-stage";
|
|
101691
101843
|
const writing = resolved.node === "work-production-stage";
|
|
101692
101844
|
const repair = resolved.node === "repair-production-articles";
|
|
@@ -101701,7 +101853,7 @@ async function productionWorkflowRoute(input) {
|
|
|
101701
101853
|
id: `production/${stage.id}/${report ? "plan" : "stage"}`,
|
|
101702
101854
|
kind: "context-view",
|
|
101703
101855
|
media_type: "text/markdown",
|
|
101704
|
-
path:
|
|
101856
|
+
path: join105(input.projectRoot, directory, path3),
|
|
101705
101857
|
read_state: "read-required"
|
|
101706
101858
|
});
|
|
101707
101859
|
if (report || writing)
|
|
@@ -101712,18 +101864,18 @@ async function productionWorkflowRoute(input) {
|
|
|
101712
101864
|
id: `production/${stage.id}/planning`,
|
|
101713
101865
|
kind: "context-view",
|
|
101714
101866
|
media_type: "text/markdown",
|
|
101715
|
-
path:
|
|
101867
|
+
path: join105(input.projectRoot, directory, "planning.md"),
|
|
101716
101868
|
read_state: "read-required"
|
|
101717
101869
|
});
|
|
101718
101870
|
}
|
|
101719
101871
|
if (repair) {
|
|
101720
|
-
await writeProductionProjection(input.projectRoot,
|
|
101872
|
+
await writeProductionProjection(input.projectRoot, join105(directory, "repair.md"), [
|
|
101721
101873
|
"# Revise rejected articles",
|
|
101722
101874
|
"",
|
|
101723
101875
|
...rejected.map((candidate) => `- ${candidate.path}: ${candidate.review.title}`),
|
|
101724
101876
|
"",
|
|
101725
101877
|
"Use the user's Review feedback to add revision tasks for these article paths. Rejection does not cancel their planned responsibilities. Ask for missing feedback instead of guessing the reason.",
|
|
101726
|
-
`Submit the plan amendment to ${path2} using ${
|
|
101878
|
+
`Submit the plan amendment to ${path2} using ${join105(directory, "planning.schema.json")}. Keep accepted task identities unchanged; the CLI assigns the revision tasks and preserves article identities.`,
|
|
101727
101879
|
"Once issued, repair the affected sections through the existing edits submission. Unchanged sections and references do not need resubmission.",
|
|
101728
101880
|
""
|
|
101729
101881
|
].join(`
|
|
@@ -101732,7 +101884,7 @@ async function productionWorkflowRoute(input) {
|
|
|
101732
101884
|
id: `production/${stage.id}/repair`,
|
|
101733
101885
|
kind: "context-view",
|
|
101734
101886
|
media_type: "text/markdown",
|
|
101735
|
-
path:
|
|
101887
|
+
path: join105(input.projectRoot, directory, "repair.md"),
|
|
101736
101888
|
read_state: "read-required"
|
|
101737
101889
|
});
|
|
101738
101890
|
}
|
|
@@ -101831,7 +101983,7 @@ var init_knowledgeMaintenanceRoute = __esm(() => {
|
|
|
101831
101983
|
});
|
|
101832
101984
|
|
|
101833
101985
|
// src/project/approvedRevisionContext.ts
|
|
101834
|
-
import { readFile as
|
|
101986
|
+
import { readFile as readFile86 } from "node:fs/promises";
|
|
101835
101987
|
async function approvedRevisionContext(root, target) {
|
|
101836
101988
|
const registry2 = await readProductionRequirements(root);
|
|
101837
101989
|
const requirements = registry2.requirements.filter((requirement2) => requirement2.target_scope.targets.some((source2) => target.source_refs.some((ref2) => repoContentScopeMatches(source2.source_ref, ref2) || ref2.startsWith(`${source2.source_ref}#`) || ref2.startsWith(`${source2.source_ref}/`))));
|
|
@@ -101842,7 +101994,7 @@ async function approvedRevisionContext(root, target) {
|
|
|
101842
101994
|
const type = source_ref.slice(0, separator);
|
|
101843
101995
|
const name3 = source_ref.slice(separator + 1);
|
|
101844
101996
|
const path2 = await assertManagedDocumentPath(root, type, name3);
|
|
101845
|
-
const markdown = await
|
|
101997
|
+
const markdown = await readFile86(path2, "utf8");
|
|
101846
101998
|
const changes = type === "sessions" ? readSessionChanges(markdown) : undefined;
|
|
101847
101999
|
return {
|
|
101848
102000
|
source_ref,
|
|
@@ -101874,14 +102026,14 @@ __export(exports_approvedRevisionRoute, {
|
|
|
101874
102026
|
buildApprovedRevisionRoute: () => buildApprovedRevisionRoute
|
|
101875
102027
|
});
|
|
101876
102028
|
import { existsSync as existsSync29 } from "node:fs";
|
|
101877
|
-
import { join as
|
|
102029
|
+
import { join as join106 } from "node:path";
|
|
101878
102030
|
async function sourceUpdateRouteInput(projectRoot, update) {
|
|
101879
102031
|
const { reference_evidence: evidence, ...rest } = update;
|
|
101880
102032
|
if (!evidence?.length)
|
|
101881
102033
|
return rest;
|
|
101882
102034
|
const file = `.tmp/context-runtime/source-update/evidence-${update.revision.replace(/^sha256:/u, "")}.json`;
|
|
101883
|
-
if (!existsSync29(
|
|
101884
|
-
await atomicWriteFile(
|
|
102035
|
+
if (!existsSync29(join106(projectRoot, file)))
|
|
102036
|
+
await atomicWriteFile(join106(projectRoot, file), `${JSON.stringify(evidence, null, 2)}
|
|
101885
102037
|
`);
|
|
101886
102038
|
return { ...rest, reference_evidence_file: file, reference_evidence_count: evidence.length };
|
|
101887
102039
|
}
|
|
@@ -102082,7 +102234,7 @@ __export(exports_status, {
|
|
|
102082
102234
|
collectProjectStatusSnapshot: () => collectProjectStatusSnapshot,
|
|
102083
102235
|
collectProjectStatus: () => collectProjectStatus
|
|
102084
102236
|
});
|
|
102085
|
-
import { join as
|
|
102237
|
+
import { join as join107 } from "node:path";
|
|
102086
102238
|
async function recordWorkflowEvaluation(projectRoot, workflow) {
|
|
102087
102239
|
const current3 = workflow.current;
|
|
102088
102240
|
await recordAgentGraphEvaluation({
|
|
@@ -102134,7 +102286,7 @@ async function collectProjectStatusSnapshotInternal(projectRoot, options = {}) {
|
|
|
102134
102286
|
const navigationOnly = !maintenance && !localRevision && !localUpdate && !localRollback && taskPreparation === "cleared" && !production && phaseStatus.projectEntryValid && await navigationOnlyChange(projectRoot, phaseStatus.packages);
|
|
102135
102287
|
const deferDeliveryChecks = !maintenance && !localRevision && !localUpdate && !localRollback && !navigationOnly && (taskPreparation === "cleared" && !production || !!authoring);
|
|
102136
102288
|
const collectionsWithPages = new Set;
|
|
102137
|
-
const approvedPages = await countFiles(
|
|
102289
|
+
const approvedPages = await countFiles(join107(projectRoot, "knowledge"), (rel) => {
|
|
102138
102290
|
if (!isApprovedKnowledgeMarkdownPath(rel) || rel.startsWith("assets/"))
|
|
102139
102291
|
return false;
|
|
102140
102292
|
collectionsWithPages.add(rel.split("/")[0]);
|
|
@@ -102142,7 +102294,7 @@ async function collectProjectStatusSnapshotInternal(projectRoot, options = {}) {
|
|
|
102142
102294
|
});
|
|
102143
102295
|
const approvedCollections = KNOWLEDGE_COLLECTIONS.filter((collection) => collectionsWithPages.has(collection));
|
|
102144
102296
|
const closeStatus = deferDeliveryChecks ? { state: "not-checked", diagnostics: [] } : await readCloseStatus(projectRoot);
|
|
102145
|
-
const distFiles = await countFiles(
|
|
102297
|
+
const distFiles = await countFiles(join107(projectRoot, "dist"), () => true);
|
|
102146
102298
|
const verifyStatus = !deferDeliveryChecks && draftStatus.diagnostics.length === 0 ? await readVerifyStatus(projectRoot) : { issues: [], diagnostics: [] };
|
|
102147
102299
|
const productionCapture = !localRevision && production ? productionCaptureDocuments(production, documentSources) : undefined;
|
|
102148
102300
|
const revisionDocuments = localRevision ? documentSources.filter((source2) => localRevision.target.source_refs.some((ref2) => documentSourceMatches(source2, ref2))) : productionCapture?.documents ?? documentSources;
|
|
@@ -102625,14 +102777,14 @@ __export(exports_workflowRouteOutput, {
|
|
|
102625
102777
|
});
|
|
102626
102778
|
import { Buffer as Buffer4 } from "node:buffer";
|
|
102627
102779
|
import { createHash as createHash32 } from "node:crypto";
|
|
102628
|
-
import { join as
|
|
102780
|
+
import { join as join108 } from "node:path";
|
|
102629
102781
|
async function workflowRouteOutput(projectRoot, route, options = {}) {
|
|
102630
102782
|
if (!route)
|
|
102631
102783
|
return null;
|
|
102632
102784
|
const body = `${JSON.stringify(route, null, 2)}
|
|
102633
102785
|
`;
|
|
102634
102786
|
const digest7 = createHash32("sha256").update(body).digest("hex");
|
|
102635
|
-
const file =
|
|
102787
|
+
const file = join108(projectRoot, ".tmp/context-runtime/routes", `${digest7}.json`);
|
|
102636
102788
|
await atomicWriteFile(file, body);
|
|
102637
102789
|
const routeBytes = Buffer4.byteLength(body);
|
|
102638
102790
|
const inlineByteLimit = Math.max(0, Math.min(WORKFLOW_ROUTE_INLINE_BYTE_LIMIT, options.inlineByteLimit ?? WORKFLOW_ROUTE_INLINE_BYTE_LIMIT));
|
|
@@ -102654,7 +102806,7 @@ async function workflowRunResultFile(projectRoot, result) {
|
|
|
102654
102806
|
const body = `${JSON.stringify(result, null, 2)}
|
|
102655
102807
|
`;
|
|
102656
102808
|
const digest7 = createHash32("sha256").update(body).digest("hex");
|
|
102657
|
-
const file =
|
|
102809
|
+
const file = join108(projectRoot, ".tmp/context-runtime/action-results", `${digest7}.run.json`);
|
|
102658
102810
|
await atomicWriteFile(file, body);
|
|
102659
102811
|
return file;
|
|
102660
102812
|
}
|
|
@@ -102673,15 +102825,15 @@ __export(exports_originalRevisions, {
|
|
|
102673
102825
|
originalRevisionReviewHtml: () => originalRevisionReviewHtml,
|
|
102674
102826
|
ORIGINAL_REVISION_PROPOSALS_PATH: () => ORIGINAL_REVISION_PROPOSALS_PATH
|
|
102675
102827
|
});
|
|
102676
|
-
import { readFile as
|
|
102677
|
-
import { join as
|
|
102828
|
+
import { readFile as readFile87, rm as rm26 } from "node:fs/promises";
|
|
102829
|
+
import { join as join109 } from "node:path";
|
|
102678
102830
|
function inputError(message, reasonCode) {
|
|
102679
102831
|
return new ContextError(ExitCode.UserError, message, { category: ErrorCategory.UserInputInvalid, reason_code: reasonCode });
|
|
102680
102832
|
}
|
|
102681
102833
|
async function readOriginalRevisionProposals(projectRoot) {
|
|
102682
102834
|
let content3;
|
|
102683
102835
|
try {
|
|
102684
|
-
content3 = await
|
|
102836
|
+
content3 = await readFile87(join109(projectRoot, ORIGINAL_REVISION_PROPOSALS_PATH), "utf8");
|
|
102685
102837
|
} catch (error) {
|
|
102686
102838
|
if (error.code === "ENOENT")
|
|
102687
102839
|
return [];
|
|
@@ -102694,7 +102846,7 @@ async function readOriginalRevisionProposals(projectRoot) {
|
|
|
102694
102846
|
return parsed.data.revisions;
|
|
102695
102847
|
}
|
|
102696
102848
|
async function writeProposals(projectRoot, proposals) {
|
|
102697
|
-
const path2 =
|
|
102849
|
+
const path2 = join109(projectRoot, ORIGINAL_REVISION_PROPOSALS_PATH);
|
|
102698
102850
|
if (proposals.length === 0) {
|
|
102699
102851
|
await rm26(path2, { force: true });
|
|
102700
102852
|
return;
|
|
@@ -102792,54 +102944,6 @@ var init_originalRevisions = __esm(() => {
|
|
|
102792
102944
|
storedProposalsSchema = exports_external.object({ revisions: exports_external.array(storedProposalSchema).default([]) }).strict();
|
|
102793
102945
|
});
|
|
102794
102946
|
|
|
102795
|
-
// src/project/sdkAlignment.ts
|
|
102796
|
-
var exports_sdkAlignment = {};
|
|
102797
|
-
__export(exports_sdkAlignment, {
|
|
102798
|
-
inspectSdkAlignment: () => inspectSdkAlignment
|
|
102799
|
-
});
|
|
102800
|
-
import { readFile as readFile86 } from "node:fs/promises";
|
|
102801
|
-
import { join as join108 } from "node:path";
|
|
102802
|
-
function core3(version3) {
|
|
102803
|
-
const match = /^(\d+)\.(\d+)\.(\d+)$/u.exec(version3?.trim() ?? "");
|
|
102804
|
-
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
|
|
102805
|
-
}
|
|
102806
|
-
function older(left, right) {
|
|
102807
|
-
for (let index3 = 0;index3 < 3; index3++)
|
|
102808
|
-
if (left[index3] !== right[index3])
|
|
102809
|
-
return left[index3] < right[index3];
|
|
102810
|
-
return false;
|
|
102811
|
-
}
|
|
102812
|
-
async function readJson(path2) {
|
|
102813
|
-
try {
|
|
102814
|
-
return JSON.parse(await readFile86(path2, "utf8"));
|
|
102815
|
-
} catch {
|
|
102816
|
-
return null;
|
|
102817
|
-
}
|
|
102818
|
-
}
|
|
102819
|
-
async function inspectSdkAlignment(projectRoot, cliVersion = readCurrentPackageVersion()) {
|
|
102820
|
-
const manifest = await readJson(join108(projectRoot, "package.json"));
|
|
102821
|
-
const dependencies = { ...manifest?.devDependencies, ...manifest?.dependencies };
|
|
102822
|
-
const pinned = dependencies[SDK_PACKAGE];
|
|
102823
|
-
const installed = (await readJson(join108(projectRoot, "node_modules", ...SDK_PACKAGE.split("/"), "package.json")))?.version;
|
|
102824
|
-
const cli = core3(cliVersion);
|
|
102825
|
-
const target = core3(pinned);
|
|
102826
|
-
if (pinned === undefined || cli === null || target === null || target[0] !== cli[0])
|
|
102827
|
-
return;
|
|
102828
|
-
const installedCore = core3(typeof installed === "string" ? installed : null);
|
|
102829
|
-
if (!older(target, cli) && (installedCore === null || !older(installedCore, cli)))
|
|
102830
|
-
return;
|
|
102831
|
-
return {
|
|
102832
|
-
workspace_sdk: { pinned, installed: typeof installed === "string" ? installed : null },
|
|
102833
|
-
cli: cliVersion,
|
|
102834
|
-
message: `The workspace pins ${SDK_PACKAGE} ${pinned}, older than the running CLI ${cliVersion}; its documentation and registry parsing lag behind the CLI.`,
|
|
102835
|
-
instruction: `Set ${SDK_PACKAGE} in package.json to ${cliVersion}, install with the workspace package manager (bun install for bun.lock) and commit package.json together with the lock file in the next delivery. A routine update without content changes may deliver this upgrade alone.`
|
|
102836
|
-
};
|
|
102837
|
-
}
|
|
102838
|
-
var SDK_PACKAGE = "@c4a/context";
|
|
102839
|
-
var init_sdkAlignment = __esm(() => {
|
|
102840
|
-
init_workspace();
|
|
102841
|
-
});
|
|
102842
|
-
|
|
102843
102947
|
// src/project/statusCommand.ts
|
|
102844
102948
|
async function projectStatusSummary(status, projectRoot) {
|
|
102845
102949
|
const { observeKnowledgeMaintenance: observeKnowledgeMaintenance2 } = await Promise.resolve().then(() => (init_knowledgeMaintenance(), exports_knowledgeMaintenance));
|
|
@@ -103012,7 +103116,7 @@ __export(exports_articleRetirement, {
|
|
|
103012
103116
|
batchDraftReader: () => batchDraftReader,
|
|
103013
103117
|
articleRetirementSchema: () => articleRetirementSchema
|
|
103014
103118
|
});
|
|
103015
|
-
import { readFile as
|
|
103119
|
+
import { readFile as readFile89, readdir as readdir25 } from "node:fs/promises";
|
|
103016
103120
|
import { posix as posix14 } from "node:path";
|
|
103017
103121
|
function rebuildInput(revision) {
|
|
103018
103122
|
return JSON.stringify({ id: `retirement-${revision.slice(7)}`, operation: "rebuild", timing: "priority", targets: [] });
|
|
@@ -103033,7 +103137,7 @@ function invalid2(reason, message, details = {}) {
|
|
|
103033
103137
|
}
|
|
103034
103138
|
async function text11(root2, path3) {
|
|
103035
103139
|
try {
|
|
103036
|
-
return await
|
|
103140
|
+
return await readFile89(await safeProjectTarget(root2, path3), "utf8");
|
|
103037
103141
|
} catch (error) {
|
|
103038
103142
|
if (error.code === "ENOENT")
|
|
103039
103143
|
return;
|
|
@@ -107863,8 +107967,10 @@ var init_larkDocxXml = __esm(() => {
|
|
|
107863
107967
|
});
|
|
107864
107968
|
|
|
107865
107969
|
// src/lib/larkResourceScheduler.ts
|
|
107970
|
+
import { readdir as readdir26, rm as rm27 } from "node:fs/promises";
|
|
107971
|
+
import { join as join117 } from "node:path";
|
|
107866
107972
|
import { setTimeout as delay } from "node:timers/promises";
|
|
107867
|
-
function
|
|
107973
|
+
function structured(value, match, depth = 0) {
|
|
107868
107974
|
if (depth > 6 || value === null)
|
|
107869
107975
|
return false;
|
|
107870
107976
|
if (typeof value === "string") {
|
|
@@ -107872,7 +107978,7 @@ function throttle(value, depth = 0) {
|
|
|
107872
107978
|
if (start2 < 0)
|
|
107873
107979
|
return false;
|
|
107874
107980
|
try {
|
|
107875
|
-
return
|
|
107981
|
+
return structured(JSON.parse(value.slice(start2)), match, depth + 1);
|
|
107876
107982
|
} catch {
|
|
107877
107983
|
return false;
|
|
107878
107984
|
}
|
|
@@ -107880,9 +107986,35 @@ function throttle(value, depth = 0) {
|
|
|
107880
107986
|
if (typeof value !== "object")
|
|
107881
107987
|
return false;
|
|
107882
107988
|
const record4 = value;
|
|
107883
|
-
if (
|
|
107989
|
+
if (match(record4))
|
|
107990
|
+
return true;
|
|
107991
|
+
return [record4.error, record4.message, record4.cause].some((entry) => structured(entry, match, depth + 1));
|
|
107992
|
+
}
|
|
107993
|
+
function failureText(result) {
|
|
107994
|
+
if (result.exitCode !== 0)
|
|
107995
|
+
return `${result.stderr}
|
|
107996
|
+
${result.stdout}`;
|
|
107997
|
+
const trimmed = result.stdout.trim();
|
|
107998
|
+
if (!trimmed.startsWith("{"))
|
|
107999
|
+
return;
|
|
108000
|
+
try {
|
|
108001
|
+
const envelope = JSON.parse(trimmed);
|
|
108002
|
+
return envelope?.ok === false ? JSON.stringify(envelope.error ?? envelope) : undefined;
|
|
108003
|
+
} catch {
|
|
108004
|
+
return;
|
|
108005
|
+
}
|
|
108006
|
+
}
|
|
108007
|
+
function isLarkResourceTransient(result) {
|
|
108008
|
+
if (result.exitCode === null)
|
|
108009
|
+
return true;
|
|
108010
|
+
const text12 = failureText(result);
|
|
108011
|
+
if (text12 === undefined || isLarkResourceThrottled(result))
|
|
108012
|
+
return false;
|
|
108013
|
+
if (structured(text12, (record4) => codes2(record4).some((code3) => TRANSIENT_STATUS.has(code3))))
|
|
107884
108014
|
return true;
|
|
107885
|
-
|
|
108015
|
+
if (structured(text12, (record4) => codes2(record4).some((code3) => PERMANENT_STATUS.has(code3)) || PERMANENT_TYPES.has(String(record4.type))))
|
|
108016
|
+
return false;
|
|
108017
|
+
return TRANSIENT_TEXT.test(text12);
|
|
107886
108018
|
}
|
|
107887
108019
|
function isLarkResourceThrottled(result) {
|
|
107888
108020
|
return throttle(result.stderr) || throttle(result.stdout);
|
|
@@ -107910,13 +108042,19 @@ function retryAfter(value, now2, depth = 0) {
|
|
|
107910
108042
|
const own5 = Number.isFinite(milliseconds) && milliseconds > 0 ? milliseconds : Number.isFinite(seconds) && seconds > 0 ? seconds * 1000 : typeof raw === "string" ? Math.max(0, Date.parse(raw) - now2) || 0 : 0;
|
|
107911
108043
|
return Math.max(own5, ...[record4.error, record4.cause, record4.message].map((entry) => retryAfter(entry, now2, depth + 1)));
|
|
107912
108044
|
}
|
|
108045
|
+
async function emptyDirectory(path3) {
|
|
108046
|
+
for (const entry of await readdir26(path3))
|
|
108047
|
+
await rm27(join117(path3, entry), { recursive: true, force: true });
|
|
108048
|
+
}
|
|
107913
108049
|
function createLarkResourceScheduler(runner2, options = {}) {
|
|
107914
108050
|
const now2 = options.now ?? Date.now;
|
|
107915
108051
|
const sleep2 = options.sleep ?? delay;
|
|
108052
|
+
const random = options.random ?? Math.random;
|
|
107916
108053
|
let concurrency = 4;
|
|
107917
108054
|
let active = 0;
|
|
107918
108055
|
let blockedUntil = 0;
|
|
107919
108056
|
let successes = 0;
|
|
108057
|
+
let lastTransientCut = Number.NEGATIVE_INFINITY;
|
|
107920
108058
|
let exhausted;
|
|
107921
108059
|
const waiters = [];
|
|
107922
108060
|
const wake2 = () => {
|
|
@@ -107942,33 +108080,54 @@ function createLarkResourceScheduler(runner2, options = {}) {
|
|
|
107942
108080
|
}
|
|
107943
108081
|
};
|
|
107944
108082
|
return async (args, commandOptions) => {
|
|
107945
|
-
|
|
108083
|
+
let throttled = 0;
|
|
108084
|
+
let transient = 0;
|
|
108085
|
+
for (;; ) {
|
|
107946
108086
|
if (exhausted)
|
|
107947
108087
|
return exhausted;
|
|
107948
108088
|
await acquire();
|
|
108089
|
+
let result;
|
|
107949
108090
|
try {
|
|
107950
108091
|
if (exhausted)
|
|
107951
108092
|
return exhausted;
|
|
107952
|
-
|
|
107953
|
-
|
|
107954
|
-
if (result.exitCode === 0 && ++successes >= 8) {
|
|
107955
|
-
concurrency = Math.min(4, concurrency + 1);
|
|
107956
|
-
successes = 0;
|
|
107957
|
-
}
|
|
107958
|
-
return result;
|
|
108093
|
+
if (throttled + transient > 0 && commandOptions?.scratchDirectory && commandOptions.cwd !== undefined) {
|
|
108094
|
+
await emptyDirectory(commandOptions.cwd);
|
|
107959
108095
|
}
|
|
108096
|
+
result = await runner2(args, commandOptions);
|
|
108097
|
+
} finally {
|
|
108098
|
+
active--;
|
|
108099
|
+
wake2();
|
|
108100
|
+
}
|
|
108101
|
+
if (isLarkResourceThrottled(result)) {
|
|
107960
108102
|
successes = 0;
|
|
107961
108103
|
concurrency = Math.max(1, Math.floor(concurrency / 2));
|
|
107962
|
-
const wait = Math.max(1000 * 2 **
|
|
108104
|
+
const wait = Math.max(1000 * 2 ** throttled, retryAfter(result.stderr, now2()), retryAfter(result.stdout, now2()));
|
|
107963
108105
|
blockedUntil = Math.max(blockedUntil, now2() + Math.min(wait, 30000));
|
|
107964
|
-
if (
|
|
108106
|
+
if (throttled >= 3 || wait > 30000) {
|
|
107965
108107
|
exhausted = result;
|
|
107966
108108
|
return result;
|
|
107967
108109
|
}
|
|
107968
|
-
|
|
107969
|
-
|
|
107970
|
-
wake2();
|
|
108110
|
+
throttled++;
|
|
108111
|
+
continue;
|
|
107971
108112
|
}
|
|
108113
|
+
if (isLarkResourceTransient(result)) {
|
|
108114
|
+
successes = 0;
|
|
108115
|
+
if (transient >= TRANSIENT_RETRIES)
|
|
108116
|
+
return result;
|
|
108117
|
+
if (now2() - lastTransientCut >= TRANSIENT_CUT_WINDOW_MS) {
|
|
108118
|
+
concurrency = Math.max(1, Math.floor(concurrency / 2));
|
|
108119
|
+
lastTransientCut = now2();
|
|
108120
|
+
}
|
|
108121
|
+
const base = 1000 * 3 ** transient;
|
|
108122
|
+
transient++;
|
|
108123
|
+
await sleep2(Math.round(base * (0.75 + random() * 0.5)));
|
|
108124
|
+
continue;
|
|
108125
|
+
}
|
|
108126
|
+
if (failureText(result) === undefined && ++successes >= 8) {
|
|
108127
|
+
concurrency = Math.min(4, concurrency + 1);
|
|
108128
|
+
successes = 0;
|
|
108129
|
+
}
|
|
108130
|
+
return result;
|
|
107972
108131
|
}
|
|
107973
108132
|
};
|
|
107974
108133
|
}
|
|
@@ -107979,7 +108138,35 @@ async function forEachLarkResource(items, visit4) {
|
|
|
107979
108138
|
await visit4(items[next2++]);
|
|
107980
108139
|
}));
|
|
107981
108140
|
}
|
|
107982
|
-
var
|
|
108141
|
+
var throttle = (value) => structured(value, (record4) => [record4.code, record4.status, record4.status_code].some((code3) => ["429", "99991400"].includes(String(code3))) || record4.type === "rate_limit" || record4.subtype === "rate_limited"), codes2 = (record4) => [record4.code, record4.status, record4.status_code].filter((code3) => code3 !== undefined && code3 !== null).map(String), TRANSIENT_STATUS, PERMANENT_STATUS, PERMANENT_TYPES, TRANSIENT_TEXT, TRANSIENT_RETRIES = 3, TRANSIENT_CUT_WINDOW_MS = 5000;
|
|
108142
|
+
var init_larkResourceScheduler = __esm(() => {
|
|
108143
|
+
TRANSIENT_STATUS = new Set(["502", "503", "504"]);
|
|
108144
|
+
PERMANENT_STATUS = new Set(["400", "401", "403", "404", "500", "2890003", "3380004", "99991672"]);
|
|
108145
|
+
PERMANENT_TYPES = new Set(["authorization", "authentication", "validation"]);
|
|
108146
|
+
TRANSIENT_TEXT = new RegExp([
|
|
108147
|
+
String.raw`(?:HTTP[/\s\d.]*\s|status(?:[ _]code)?[:=\s]+|code[:=\s]+)(?:502|503|504)\b`,
|
|
108148
|
+
String.raw`\b(?:502|503|504)\s+(?:bad gateway|service unavailable|gateway time-?out)`,
|
|
108149
|
+
"bad gateway",
|
|
108150
|
+
"service unavailable",
|
|
108151
|
+
"gateway time-?out",
|
|
108152
|
+
"request time-?out",
|
|
108153
|
+
"timed out",
|
|
108154
|
+
"deadline exceeded",
|
|
108155
|
+
"i/o timeout",
|
|
108156
|
+
String.raw`client\.timeout`,
|
|
108157
|
+
"timeout exceeded",
|
|
108158
|
+
"ETIMEDOUT",
|
|
108159
|
+
"ECONNRESET",
|
|
108160
|
+
"ECONNABORTED",
|
|
108161
|
+
"EPIPE",
|
|
108162
|
+
"EAI_AGAIN",
|
|
108163
|
+
"connection (?:reset|refused|closed)",
|
|
108164
|
+
"socket hang up",
|
|
108165
|
+
"unexpected EOF",
|
|
108166
|
+
"network is unreachable",
|
|
108167
|
+
"TLS handshake timeout"
|
|
108168
|
+
].join("|"), "iu");
|
|
108169
|
+
});
|
|
107983
108170
|
|
|
107984
108171
|
// src/lib/larkResourceCommand.ts
|
|
107985
108172
|
function hasMissingScope(value, depth = 0) {
|
|
@@ -108091,19 +108278,20 @@ var init_larkResourceCommand = __esm(() => {
|
|
|
108091
108278
|
});
|
|
108092
108279
|
|
|
108093
108280
|
// src/lib/larkMediaDownload.ts
|
|
108094
|
-
import { readdir as
|
|
108095
|
-
import { join as
|
|
108281
|
+
import { readdir as readdir27, rm as rm28 } from "node:fs/promises";
|
|
108282
|
+
import { join as join118 } from "node:path";
|
|
108096
108283
|
async function downloadLarkMedia(input) {
|
|
108284
|
+
const options = { cwd: input.cwd, scratchDirectory: true, ...input.timeoutMs === undefined ? {} : { timeoutMs: input.timeoutMs } };
|
|
108097
108285
|
const shared = ["--as", input.identity, "--token", input.token, "--output", "./resource", "--format", "json"];
|
|
108098
108286
|
try {
|
|
108099
|
-
await runLarkResourceCommand(input.runner, ["docs", "+media-download", ...shared, "--type", input.type, "--overwrite"],
|
|
108287
|
+
await runLarkResourceCommand(input.runner, ["docs", "+media-download", ...shared, "--type", input.type, "--overwrite"], options);
|
|
108100
108288
|
return "original";
|
|
108101
108289
|
} catch (error) {
|
|
108102
108290
|
if (!input.allowPreview || !isLarkResourcePermissionDenied(error))
|
|
108103
108291
|
throw error;
|
|
108104
|
-
for (const entry of await
|
|
108105
|
-
await
|
|
108106
|
-
await runLarkResourceCommand(input.runner, ["docs", "+media-preview", ...shared],
|
|
108292
|
+
for (const entry of await readdir27(input.cwd))
|
|
108293
|
+
await rm28(join118(input.cwd, entry), { recursive: true, force: true });
|
|
108294
|
+
await runLarkResourceCommand(input.runner, ["docs", "+media-preview", ...shared], options);
|
|
108107
108295
|
return "preview";
|
|
108108
108296
|
}
|
|
108109
108297
|
}
|
|
@@ -108112,9 +108300,9 @@ var init_larkMediaDownload = __esm(() => {
|
|
|
108112
108300
|
});
|
|
108113
108301
|
|
|
108114
108302
|
// src/lib/larkWhiteboardExport.ts
|
|
108115
|
-
import { mkdtemp as mkdtemp5, readFile as
|
|
108303
|
+
import { mkdtemp as mkdtemp5, readFile as readFile95, rm as rm29 } from "node:fs/promises";
|
|
108116
108304
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
108117
|
-
import { join as
|
|
108305
|
+
import { join as join119 } from "node:path";
|
|
108118
108306
|
function stableJson2(value) {
|
|
108119
108307
|
if (value === undefined)
|
|
108120
108308
|
return "null";
|
|
@@ -108144,7 +108332,7 @@ function canonicalWhiteboardPayload(value) {
|
|
|
108144
108332
|
};
|
|
108145
108333
|
}
|
|
108146
108334
|
async function exportLarkWhiteboardRaw(runner2, identity2, token) {
|
|
108147
|
-
const tempRoot = await mkdtemp5(
|
|
108335
|
+
const tempRoot = await mkdtemp5(join119(tmpdir2(), "context-lark-whiteboard-"));
|
|
108148
108336
|
try {
|
|
108149
108337
|
await runLarkResourceCommand(runner2, [
|
|
108150
108338
|
"whiteboard",
|
|
@@ -108160,12 +108348,12 @@ async function exportLarkWhiteboardRaw(runner2, identity2, token) {
|
|
|
108160
108348
|
"--overwrite",
|
|
108161
108349
|
"--format",
|
|
108162
108350
|
"json"
|
|
108163
|
-
], { cwd: tempRoot });
|
|
108164
|
-
const rawPayload = JSON.parse(await
|
|
108351
|
+
], { cwd: tempRoot, scratchDirectory: true });
|
|
108352
|
+
const rawPayload = JSON.parse(await readFile95(join119(tempRoot, "raw.json"), "utf8"));
|
|
108165
108353
|
return Buffer.from(`${stableJson2(canonicalWhiteboardPayload(rawPayload))}
|
|
108166
108354
|
`, "utf8");
|
|
108167
108355
|
} finally {
|
|
108168
|
-
await
|
|
108356
|
+
await rm29(tempRoot, { recursive: true, force: true });
|
|
108169
108357
|
}
|
|
108170
108358
|
}
|
|
108171
108359
|
var init_larkWhiteboardExport = __esm(() => {
|
|
@@ -108192,16 +108380,39 @@ function omitLarkImage(resource, policy, items, replacements, mediaType, failure
|
|
|
108192
108380
|
});
|
|
108193
108381
|
return true;
|
|
108194
108382
|
}
|
|
108195
|
-
|
|
108383
|
+
function omitLarkResourceByPolicy(resource, policy, items, replacements) {
|
|
108384
|
+
const excluded = resource.kind === "file" ? policy.files === "reference-only" : (resource.kind === "whiteboard" || resource.kind === "diagram" && resource.inline_content !== true) && policy.whiteboards === "reference-only";
|
|
108385
|
+
if (!excluded)
|
|
108386
|
+
return false;
|
|
108387
|
+
const label2 = resource.kind === "file" ? "File" : resource.kind === "diagram" ? "Diagram" : "Whiteboard";
|
|
108388
|
+
const title2 = (resource.title ?? label2.toLowerCase()).replace(/[\r\n<>]/gu, " ");
|
|
108389
|
+
replacements.set(resource.locator, `> ${label2} omitted: ${title2}. Excluded by selected policy. See the source document. <!-- ${resource.locator} -->`);
|
|
108390
|
+
items.push({
|
|
108391
|
+
kind: resource.kind,
|
|
108392
|
+
locator: resource.locator,
|
|
108393
|
+
status: "reference-only",
|
|
108394
|
+
required: false,
|
|
108395
|
+
asset_paths: [],
|
|
108396
|
+
reason_code: resource.kind === "file" ? "file-excluded-by-policy" : "whiteboard-excluded-by-policy",
|
|
108397
|
+
reason: `${label2} bytes were not retained; the selected resource policy preserves a placeholder and source reference`
|
|
108398
|
+
});
|
|
108399
|
+
return true;
|
|
108400
|
+
}
|
|
108401
|
+
var LarkResourceBudgetError, LARK_POLICY_EXCLUSION_REASON_CODES;
|
|
108196
108402
|
var init_larkImagePolicy = __esm(() => {
|
|
108197
108403
|
LarkResourceBudgetError = class LarkResourceBudgetError extends Error {
|
|
108198
108404
|
};
|
|
108405
|
+
LARK_POLICY_EXCLUSION_REASON_CODES = new Set([
|
|
108406
|
+
"image-excluded-by-policy",
|
|
108407
|
+
"file-excluded-by-policy",
|
|
108408
|
+
"whiteboard-excluded-by-policy"
|
|
108409
|
+
]);
|
|
108199
108410
|
});
|
|
108200
108411
|
|
|
108201
108412
|
// src/lib/larkResourceMaterialization.ts
|
|
108202
108413
|
import { createHash as createHash36 } from "node:crypto";
|
|
108203
|
-
import { mkdtemp as mkdtemp6, readFile as
|
|
108204
|
-
import { extname as extname13, join as
|
|
108414
|
+
import { mkdtemp as mkdtemp6, readFile as readFile96, readdir as readdir28, rm as rm30 } from "node:fs/promises";
|
|
108415
|
+
import { extname as extname13, join as join120 } from "node:path";
|
|
108205
108416
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
108206
108417
|
function countByKind(items, status) {
|
|
108207
108418
|
const counts2 = new Map;
|
|
@@ -108306,20 +108517,20 @@ function findBooleanField(value, name3) {
|
|
|
108306
108517
|
}
|
|
108307
108518
|
async function downloadedFile(input) {
|
|
108308
108519
|
if (input.localPath !== undefined) {
|
|
108309
|
-
const bytes = await
|
|
108520
|
+
const bytes = await readFile96(input.localPath);
|
|
108310
108521
|
return { path: input.localPath, bytes, mediaType: mediaTypeFor(input.localPath, bytes), representation: "original" };
|
|
108311
108522
|
}
|
|
108312
|
-
const tempRoot = await mkdtemp6(
|
|
108523
|
+
const tempRoot = await mkdtemp6(join120(tmpdir3(), "context-lark-resource-"));
|
|
108313
108524
|
try {
|
|
108314
108525
|
const representation = await downloadLarkMedia({ ...input, cwd: tempRoot });
|
|
108315
|
-
const entries2 = (await
|
|
108526
|
+
const entries2 = (await readdir28(tempRoot, { withFileTypes: true })).filter((entry) => entry.isFile());
|
|
108316
108527
|
if (entries2.length !== 1)
|
|
108317
108528
|
throw new Error(`media download produced ${entries2.length} files, expected exactly one`);
|
|
108318
108529
|
const path3 = entries2[0]?.name ?? "resource.bin";
|
|
108319
|
-
const bytes = await
|
|
108530
|
+
const bytes = await readFile96(join120(tempRoot, path3));
|
|
108320
108531
|
return { path: path3, bytes, mediaType: mediaTypeFor(path3, bytes), representation };
|
|
108321
108532
|
} finally {
|
|
108322
|
-
await
|
|
108533
|
+
await rm30(tempRoot, { recursive: true, force: true });
|
|
108323
108534
|
}
|
|
108324
108535
|
}
|
|
108325
108536
|
function parseCsv(value) {
|
|
@@ -108388,9 +108599,9 @@ async function sheetMaterialization(resource, runner2, identity2) {
|
|
|
108388
108599
|
const sheetId = resource.attributes["sheet-id"];
|
|
108389
108600
|
if (token === undefined || sheetId === undefined)
|
|
108390
108601
|
throw new Error("embedded Sheet requires token and sheet-id");
|
|
108391
|
-
const tempRoot = await mkdtemp6(
|
|
108602
|
+
const tempRoot = await mkdtemp6(join120(tmpdir3(), "context-lark-sheet-"));
|
|
108392
108603
|
try {
|
|
108393
|
-
const outputPath =
|
|
108604
|
+
const outputPath = join120(tempRoot, "sheet.json");
|
|
108394
108605
|
const stdout = await runLarkResourceCommand(runner2, [
|
|
108395
108606
|
"sheets",
|
|
108396
108607
|
"+csv-get",
|
|
@@ -108405,12 +108616,12 @@ async function sheetMaterialization(resource, runner2, identity2) {
|
|
|
108405
108616
|
"./sheet.json",
|
|
108406
108617
|
"--format",
|
|
108407
108618
|
"json"
|
|
108408
|
-
], { cwd: tempRoot });
|
|
108619
|
+
], { cwd: tempRoot, scratchDirectory: true });
|
|
108409
108620
|
const receipt2 = jsonPayload(stdout);
|
|
108410
108621
|
if (findBooleanField(receipt2, "truncated") === true || findBooleanField(receipt2, "complete") === false) {
|
|
108411
108622
|
throw new Error("embedded Sheet read was truncated");
|
|
108412
108623
|
}
|
|
108413
|
-
const payload = JSON.parse(await
|
|
108624
|
+
const payload = JSON.parse(await readFile96(outputPath, "utf8"));
|
|
108414
108625
|
const csv = findStringField(payload, new Set(["annotated_csv", "csv", "content", "text"]));
|
|
108415
108626
|
if (csv === undefined)
|
|
108416
108627
|
throw new Error("embedded Sheet response has no CSV payload");
|
|
@@ -108432,7 +108643,7 @@ ${markdownTable2(parseCsv(csv))}
|
|
|
108432
108643
|
[CSV snapshot](${sourceAssetTarget(path3)}) <!-- ${resource.locator} -->`
|
|
108433
108644
|
};
|
|
108434
108645
|
} finally {
|
|
108435
|
-
await
|
|
108646
|
+
await rm30(tempRoot, { recursive: true, force: true });
|
|
108436
108647
|
}
|
|
108437
108648
|
}
|
|
108438
108649
|
function basePageRecords(value) {
|
|
@@ -108652,7 +108863,9 @@ function assertBudget(asset, policy, total) {
|
|
|
108652
108863
|
}
|
|
108653
108864
|
}
|
|
108654
108865
|
async function materializeLarkResources(input) {
|
|
108655
|
-
|
|
108866
|
+
const raw = input.runner;
|
|
108867
|
+
const timed = (args, options) => raw(args, { ...options, timeoutMs: options?.timeoutMs ?? RESOURCE_TIMEOUT_MS });
|
|
108868
|
+
input = { ...input, runner: createLarkResourceScheduler(timed) };
|
|
108656
108869
|
const assets = [];
|
|
108657
108870
|
const replacements = new Map;
|
|
108658
108871
|
const items = [];
|
|
@@ -108667,6 +108880,10 @@ async function materializeLarkResources(input) {
|
|
|
108667
108880
|
const required = REQUIRED_KINDS.has(resource.kind);
|
|
108668
108881
|
if (omitLarkImage(resource, input.policy, items, replacements))
|
|
108669
108882
|
return;
|
|
108883
|
+
if (omitLarkResourceByPolicy(resource, input.policy, items, replacements))
|
|
108884
|
+
return;
|
|
108885
|
+
if (resource.kind === "image" && input.budgetExcluded?.has(resource.locator) && omitLarkImage(resource, input.policy, items, replacements, undefined, "The earlier capture of this revision skipped it for exceeding the resource budget; it was not downloaded again"))
|
|
108886
|
+
return;
|
|
108670
108887
|
try {
|
|
108671
108888
|
if (resource.kind === "diagram" && resource.inline_content === true) {
|
|
108672
108889
|
replacements.set(resource.locator, "");
|
|
@@ -108723,7 +108940,7 @@ async function materializeLarkResources(input) {
|
|
|
108723
108940
|
throw new Error("synced reference nesting exceeds 4 levels");
|
|
108724
108941
|
if (input.resolveSyncedReference === undefined)
|
|
108725
108942
|
throw new Error("synced reference resolver is unavailable");
|
|
108726
|
-
const projected = await input.resolveSyncedReference(resource);
|
|
108943
|
+
const projected = await input.resolveSyncedReference(resource, input.runner);
|
|
108727
108944
|
const digest8 = resourceDigest(resource);
|
|
108728
108945
|
const asset2 = {
|
|
108729
108946
|
path: `materialized/synced-reference/${digest8}.md`,
|
|
@@ -108747,12 +108964,16 @@ async function materializeLarkResources(input) {
|
|
|
108747
108964
|
const token = resourceToken(resource);
|
|
108748
108965
|
if (token === undefined)
|
|
108749
108966
|
throw new Error(`${resource.kind} has no downloadable token`);
|
|
108750
|
-
const
|
|
108967
|
+
const preloaded = reusable.get(key);
|
|
108968
|
+
reusable.delete(key);
|
|
108969
|
+
const reused = preloaded ?? (depth > 0 && (resource.kind === "image" || resource.kind === "file") ? await input.reuse?.(resource, identity2) : undefined);
|
|
108970
|
+
const downloaded = reused ?? await downloadedFile({
|
|
108751
108971
|
runner: input.runner,
|
|
108752
108972
|
identity: identity2,
|
|
108753
108973
|
token,
|
|
108754
108974
|
type: "media",
|
|
108755
108975
|
allowPreview: resource.kind === "image",
|
|
108976
|
+
timeoutMs: resource.kind === "image" ? RESOURCE_TIMEOUT_MS : LARGE_RESOURCE_TIMEOUT_MS,
|
|
108756
108977
|
...input.mediaFiles?.[token] === undefined ? {} : { localPath: input.mediaFiles[token] }
|
|
108757
108978
|
});
|
|
108758
108979
|
if (omitLarkImage(resource, input.policy, items, replacements, downloaded.mediaType))
|
|
@@ -108801,7 +109022,20 @@ async function materializeLarkResources(input) {
|
|
|
108801
109022
|
});
|
|
108802
109023
|
}
|
|
108803
109024
|
};
|
|
108804
|
-
|
|
109025
|
+
const reusable = new Map;
|
|
109026
|
+
if (input.reuse !== undefined) {
|
|
109027
|
+
for (const resource of input.resources) {
|
|
109028
|
+
if (resource.kind === "image" ? input.policy.images === "reference-only" || input.budgetExcluded?.has(resource.locator) : resource.kind !== "file" || input.policy.files === "reference-only")
|
|
109029
|
+
continue;
|
|
109030
|
+
const found = await input.reuse(resource, identity2);
|
|
109031
|
+
if (found !== undefined)
|
|
109032
|
+
reusable.set(`${resource.kind}\x00${resource.locator}`, found);
|
|
109033
|
+
}
|
|
109034
|
+
}
|
|
109035
|
+
const leaves = input.resources.filter((resource) => resource.kind !== "synced-reference");
|
|
109036
|
+
for (const resource of leaves.filter((resource2) => reusable.has(`${resource2.kind}\x00${resource2.locator}`)))
|
|
109037
|
+
await materialize(resource, 0);
|
|
109038
|
+
await forEachLarkResource(leaves.filter((resource) => !reusable.has(`${resource.kind}\x00${resource.locator}`)), (resource) => materialize(resource, 0));
|
|
108805
109039
|
for (const resource of input.resources.filter((resource2) => resource2.kind === "synced-reference"))
|
|
108806
109040
|
await materialize(resource, 0);
|
|
108807
109041
|
items.sort((a2, b) => a2.locator.localeCompare(b.locator) || a2.kind.localeCompare(b.kind));
|
|
@@ -108831,7 +109065,7 @@ function applyLarkResourceReplacements(markdown, resources, replacements) {
|
|
|
108831
109065
|
}
|
|
108832
109066
|
return output;
|
|
108833
109067
|
}
|
|
108834
|
-
var REQUIRED_KINDS, MEDIA_TYPES_BY_EXTENSION;
|
|
109068
|
+
var RESOURCE_TIMEOUT_MS = 120000, LARGE_RESOURCE_TIMEOUT_MS = 300000, REQUIRED_KINDS, MEDIA_TYPES_BY_EXTENSION;
|
|
108835
109069
|
var init_larkResourceMaterialization = __esm(() => {
|
|
108836
109070
|
init_larkResourceScheduler();
|
|
108837
109071
|
init_larkMediaDownload();
|
|
@@ -109028,6 +109262,13 @@ var init_larkReadIdentity = __esm(() => {
|
|
|
109028
109262
|
|
|
109029
109263
|
// src/lib/feishu.ts
|
|
109030
109264
|
import { spawn as spawn6 } from "node:child_process";
|
|
109265
|
+
function sameLarkRevision(earlier, revisionId, rawContentHash) {
|
|
109266
|
+
if (earlier === undefined)
|
|
109267
|
+
return false;
|
|
109268
|
+
if (revisionId !== undefined || earlier.revisionId !== undefined)
|
|
109269
|
+
return revisionId === earlier.revisionId;
|
|
109270
|
+
return rawContentHash !== undefined && rawContentHash === earlier.rawContentHash;
|
|
109271
|
+
}
|
|
109031
109272
|
async function detectDocsFetchCapabilities(runner2) {
|
|
109032
109273
|
const result = await runner2(["docs", "+fetch", "--help"]).catch(() => ({
|
|
109033
109274
|
stdout: "",
|
|
@@ -109421,24 +109662,27 @@ async function fetchFeishuDocSnapshot(input, runner2 = defaultRunner) {
|
|
|
109421
109662
|
};
|
|
109422
109663
|
}
|
|
109423
109664
|
const resources = [...new Map([...projection?.resources ?? [], ...larkMarkdownImageResources(body2)].map((resource) => [resource.locator, resource])).values()];
|
|
109665
|
+
const policy = {
|
|
109666
|
+
...DEFAULT_RESOURCE_POLICY,
|
|
109667
|
+
...input.resourcePolicy
|
|
109668
|
+
};
|
|
109424
109669
|
if (resources.length) {
|
|
109425
|
-
const
|
|
109426
|
-
...DEFAULT_RESOURCE_POLICY,
|
|
109427
|
-
...input.resourcePolicy
|
|
109428
|
-
};
|
|
109670
|
+
const earlier = sameLarkRevision(input.reuseResources, revisionId, projection?.rawContentHash) ? input.reuseResources : undefined;
|
|
109429
109671
|
const materialized = await materializeLarkResources({
|
|
109430
109672
|
resources,
|
|
109431
109673
|
runner: runner2,
|
|
109432
109674
|
...input.prefetched?.mediaFiles === undefined ? {} : { mediaFiles: input.prefetched.mediaFiles },
|
|
109675
|
+
...earlier === undefined ? {} : { reuse: earlier.load },
|
|
109676
|
+
...earlier?.budgetExcluded?.identity === accessIdentity ? { budgetExcluded: earlier.budgetExcluded.locators } : {},
|
|
109433
109677
|
policy,
|
|
109434
109678
|
identity: accessIdentity,
|
|
109435
|
-
resolveSyncedReference: async (resource) => {
|
|
109679
|
+
resolveSyncedReference: async (resource, scheduled) => {
|
|
109436
109680
|
const sourceToken = resource.attributes["src-token"];
|
|
109437
109681
|
const blockId = resource.attributes["src-block-id"];
|
|
109438
109682
|
if (sourceToken === undefined || blockId === undefined) {
|
|
109439
109683
|
throw new LarkCliError("synced reference requires src-token and src-block-id", 0, "");
|
|
109440
109684
|
}
|
|
109441
|
-
const synced = await fetchDocsResponse({ url: sourceToken }, docsFetchPlan,
|
|
109685
|
+
const synced = await fetchDocsResponse({ url: sourceToken }, docsFetchPlan, scheduled, accessIdentity);
|
|
109442
109686
|
if (synced.contentFormat !== "xml") {
|
|
109443
109687
|
throw new LarkCliError("synced reference source did not return XML", 0, "");
|
|
109444
109688
|
}
|
|
@@ -109464,7 +109708,8 @@ async function fetchFeishuDocSnapshot(input, runner2 = defaultRunner) {
|
|
|
109464
109708
|
fidelity,
|
|
109465
109709
|
resourceMaterialization,
|
|
109466
109710
|
resources,
|
|
109467
|
-
access: access7
|
|
109711
|
+
access: access7,
|
|
109712
|
+
resourceBudget: { maxBytesPerResource: policy.maxBytesPerResource, maxTotalBytes: policy.maxTotalBytes }
|
|
109468
109713
|
}));
|
|
109469
109714
|
if (title2 !== undefined && title2.length > 0 && !/^#\s/.test(body2)) {
|
|
109470
109715
|
return {
|
|
@@ -109499,12 +109744,28 @@ async function readPrefetchedLarkDocument(url, prefetched) {
|
|
|
109499
109744
|
}, prefetched.identity);
|
|
109500
109745
|
}
|
|
109501
109746
|
var LARK_BIN = "lark-cli", MAX_FETCH_PAGES = 50, MAX_STRUCTURAL_FETCH_ATTEMPTS = 2, LarkCliNotInstalledError, LarkCliError, defaultRunner = (args, options) => new Promise((resolve8, reject) => {
|
|
109747
|
+
const timeoutMs = options?.timeoutMs;
|
|
109748
|
+
const group = timeoutMs !== undefined && process.platform !== "win32";
|
|
109502
109749
|
const child = spawn6(process.env.CONTEXT_LARK_CLI_BIN?.trim() || LARK_BIN, args, {
|
|
109503
109750
|
...options?.cwd === undefined ? {} : { cwd: options.cwd },
|
|
109751
|
+
...group ? { detached: true } : {},
|
|
109504
109752
|
stdio: ["ignore", "pipe", "pipe"]
|
|
109505
109753
|
});
|
|
109506
109754
|
let stdout = "";
|
|
109507
109755
|
let stderr = "";
|
|
109756
|
+
let timedOut = false;
|
|
109757
|
+
const timer2 = timeoutMs === undefined ? undefined : setTimeout(() => {
|
|
109758
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
109759
|
+
return;
|
|
109760
|
+
timedOut = true;
|
|
109761
|
+
try {
|
|
109762
|
+
if (group && child.pid)
|
|
109763
|
+
process.kill(-child.pid, "SIGKILL");
|
|
109764
|
+
else
|
|
109765
|
+
child.kill("SIGKILL");
|
|
109766
|
+
} catch {}
|
|
109767
|
+
}, timeoutMs);
|
|
109768
|
+
timer2?.unref();
|
|
109508
109769
|
child.stdout.on("data", (chunk) => {
|
|
109509
109770
|
stdout += chunk.toString("utf8");
|
|
109510
109771
|
});
|
|
@@ -109512,14 +109773,23 @@ var LARK_BIN = "lark-cli", MAX_FETCH_PAGES = 50, MAX_STRUCTURAL_FETCH_ATTEMPTS =
|
|
|
109512
109773
|
stderr += chunk.toString("utf8");
|
|
109513
109774
|
});
|
|
109514
109775
|
child.on("error", (err) => {
|
|
109776
|
+
if (timer2 !== undefined)
|
|
109777
|
+
clearTimeout(timer2);
|
|
109515
109778
|
if (err.code === "ENOENT") {
|
|
109516
109779
|
reject(new LarkCliNotInstalledError);
|
|
109517
109780
|
return;
|
|
109518
109781
|
}
|
|
109519
109782
|
reject(err);
|
|
109520
109783
|
});
|
|
109784
|
+
child.on("exit", () => {
|
|
109785
|
+
if (timer2 !== undefined)
|
|
109786
|
+
clearTimeout(timer2);
|
|
109787
|
+
});
|
|
109521
109788
|
child.on("close", (code3) => {
|
|
109522
|
-
|
|
109789
|
+
if (timer2 !== undefined)
|
|
109790
|
+
clearTimeout(timer2);
|
|
109791
|
+
resolve8(timedOut ? { stdout, stderr: `${stderr}${stderr.length ? `
|
|
109792
|
+
` : ""}${LARK_BIN} ${args.slice(0, 2).join(" ")} timed out after ${Math.round(timeoutMs / 1000)} s`, exitCode: null } : { stdout, stderr, exitCode: code3 });
|
|
109523
109793
|
});
|
|
109524
109794
|
}), DEFAULT_RESOURCE_POLICY, docsFetchCapabilitiesCache;
|
|
109525
109795
|
var init_feishu = __esm(() => {
|
|
@@ -109581,14 +109851,21 @@ var init_sensitiveSourceLiteral = __esm(() => {
|
|
|
109581
109851
|
|
|
109582
109852
|
// src/project/larkSnapshotBundle.ts
|
|
109583
109853
|
import { createHash as createHash37 } from "node:crypto";
|
|
109584
|
-
import { lstat as lstat16, mkdir as mkdir39, readFile as
|
|
109585
|
-
import { basename as basename9, dirname as dirname47, isAbsolute as isAbsolute19, join as
|
|
109854
|
+
import { lstat as lstat16, mkdir as mkdir39, readFile as readFile97, realpath as realpath15, rename as rename10, writeFile as writeFile30 } from "node:fs/promises";
|
|
109855
|
+
import { basename as basename9, dirname as dirname47, isAbsolute as isAbsolute19, join as join121, relative as relative31, resolve as resolve37, sep as sep10 } from "node:path";
|
|
109586
109856
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
109587
109857
|
function normalizedSnapshotResourcePolicy(policy) {
|
|
109588
|
-
|
|
109858
|
+
const { files, whiteboards, ...rest } = policy;
|
|
109859
|
+
return {
|
|
109860
|
+
...rest,
|
|
109861
|
+
images: policy.images ?? "bundle",
|
|
109862
|
+
gifs: policy.gifs ?? "bundle",
|
|
109863
|
+
...files === "reference-only" ? { files } : {},
|
|
109864
|
+
...whiteboards === "reference-only" ? { whiteboards } : {}
|
|
109865
|
+
};
|
|
109589
109866
|
}
|
|
109590
109867
|
function assertSnapshotResourcePolicy(snapshot, expected) {
|
|
109591
|
-
if (!isDeepStrictEqual2(snapshot.resourcePolicy, normalizedSnapshotResourcePolicy(expected))) {
|
|
109868
|
+
if (!isDeepStrictEqual2(normalizedSnapshotResourcePolicy(snapshot.resourcePolicy), normalizedSnapshotResourcePolicy(expected))) {
|
|
109592
109869
|
throw new ContextError(ExitCode.UserError, "Saved Lark snapshot was captured with a different resource policy; import did not reinterpret or refetch its resources", {
|
|
109593
109870
|
reason_code: "lark.snapshot-policy-mismatch",
|
|
109594
109871
|
captured_policy: snapshot.resourcePolicy,
|
|
@@ -109623,13 +109900,13 @@ async function readFileEntry(root2, entry) {
|
|
|
109623
109900
|
const parts = safePath(entry.path).split("/");
|
|
109624
109901
|
let current3 = root2;
|
|
109625
109902
|
for (const [index3, part] of parts.entries()) {
|
|
109626
|
-
current3 =
|
|
109903
|
+
current3 = join121(current3, part);
|
|
109627
109904
|
const stat11 = await lstat16(current3);
|
|
109628
109905
|
if (stat11.isSymbolicLink() || (index3 === parts.length - 1 ? !stat11.isFile() : !stat11.isDirectory())) {
|
|
109629
109906
|
throw larkSnapshotError(`Snapshot entry is not a regular file: ${entry.path}`, "path-invalid");
|
|
109630
109907
|
}
|
|
109631
109908
|
}
|
|
109632
|
-
const bytes = await
|
|
109909
|
+
const bytes = await readFile97(current3);
|
|
109633
109910
|
if (digest7(bytes) !== entry.sha256)
|
|
109634
109911
|
throw larkSnapshotError(`Snapshot content changed: ${entry.path}`, "digest-mismatch");
|
|
109635
109912
|
return bytes;
|
|
@@ -109692,13 +109969,13 @@ async function writeLarkSnapshotBundle(input) {
|
|
|
109692
109969
|
};
|
|
109693
109970
|
schema2.parse(manifest);
|
|
109694
109971
|
for (const [path3, bytes] of files) {
|
|
109695
|
-
await mkdir39(dirname47(
|
|
109696
|
-
await writeFile30(
|
|
109972
|
+
await mkdir39(dirname47(join121(root2, path3)), { recursive: true });
|
|
109973
|
+
await writeFile30(join121(root2, path3), bytes, { flag: "wx", mode: 384 });
|
|
109697
109974
|
}
|
|
109698
109975
|
await validateBundle(root2, manifest);
|
|
109699
|
-
await writeFile30(
|
|
109976
|
+
await writeFile30(join121(root2, `${FILE2}.pending`), `${JSON.stringify(manifest, null, 2)}
|
|
109700
109977
|
`, { flag: "wx", mode: 384 });
|
|
109701
|
-
await rename10(
|
|
109978
|
+
await rename10(join121(root2, `${FILE2}.pending`), join121(root2, FILE2));
|
|
109702
109979
|
return manifest;
|
|
109703
109980
|
}
|
|
109704
109981
|
async function validateBundle(root2, manifest) {
|
|
@@ -109757,26 +110034,31 @@ async function validateBundle(root2, manifest) {
|
|
|
109757
110034
|
throw larkSnapshotError(`Resource report references a missing asset: ${path3}`);
|
|
109758
110035
|
}
|
|
109759
110036
|
}
|
|
109760
|
-
return {
|
|
109761
|
-
|
|
109762
|
-
|
|
109763
|
-
|
|
109764
|
-
|
|
109765
|
-
|
|
109766
|
-
|
|
109767
|
-
|
|
109768
|
-
|
|
109769
|
-
|
|
109770
|
-
|
|
110037
|
+
return {
|
|
110038
|
+
url: manifest.url,
|
|
110039
|
+
capturedAt: manifest.captured_at,
|
|
110040
|
+
resourcePolicy: normalizedSnapshotResourcePolicy(manifest.resource_policy),
|
|
110041
|
+
fetched: {
|
|
110042
|
+
markdown,
|
|
110043
|
+
assets,
|
|
110044
|
+
accessIdentity: manifest.access_identity,
|
|
110045
|
+
identityFallback: false,
|
|
110046
|
+
access: report.access ?? { identity: manifest.access_identity },
|
|
110047
|
+
...manifest.title === undefined ? {} : { title: manifest.title },
|
|
110048
|
+
...manifest.revision_id === undefined ? {} : { revisionId: manifest.revision_id },
|
|
110049
|
+
fidelity: report.fidelity,
|
|
110050
|
+
resourceMaterialization: { ...materialization, items: materialization.items.map((item) => ({ ...item, kind: item.kind })) }
|
|
110051
|
+
}
|
|
110052
|
+
};
|
|
109771
110053
|
}
|
|
109772
110054
|
async function readLarkSnapshotBundle(directory, target) {
|
|
109773
110055
|
try {
|
|
109774
110056
|
const root2 = await assertSnapshotDirectory(directory);
|
|
109775
|
-
const path3 =
|
|
110057
|
+
const path3 = join121(root2, FILE2);
|
|
109776
110058
|
const stat11 = await lstat16(path3);
|
|
109777
110059
|
if (stat11.isSymbolicLink() || !stat11.isFile())
|
|
109778
110060
|
throw larkSnapshotError("Snapshot receipt must be a regular file", "path-invalid");
|
|
109779
|
-
const manifest = schema2.parse(JSON.parse(await
|
|
110061
|
+
const manifest = schema2.parse(JSON.parse(await readFile97(path3, "utf8")));
|
|
109780
110062
|
assertTarget(manifest.url, target);
|
|
109781
110063
|
return await validateBundle(root2, manifest);
|
|
109782
110064
|
} catch (error) {
|
|
@@ -109800,8 +110082,8 @@ async function reserveSnapshotDirectory(directory, workspaceRoot) {
|
|
|
109800
110082
|
ancestor = dirname47(ancestor);
|
|
109801
110083
|
}
|
|
109802
110084
|
}
|
|
109803
|
-
const parent2 =
|
|
109804
|
-
const output =
|
|
110085
|
+
const parent2 = join121(ancestor, ...missing2);
|
|
110086
|
+
const output = join121(parent2, basename9(requested));
|
|
109805
110087
|
const { findContextProjectRoot: findContextProjectRoot2 } = await Promise.resolve().then(() => (init_workspace(), exports_workspace));
|
|
109806
110088
|
const owner = findContextProjectRoot2(parent2)?.projectRoot ?? workspaceRoot;
|
|
109807
110089
|
if (owner !== undefined) {
|
|
@@ -109838,6 +110120,8 @@ var init_larkSnapshotBundle = __esm(() => {
|
|
|
109838
110120
|
policySchema = exports_external.object({
|
|
109839
110121
|
images: exports_external.enum(["bundle", "reference-only"]),
|
|
109840
110122
|
gifs: exports_external.enum(["bundle", "reference-only"]),
|
|
110123
|
+
files: exports_external.enum(["bundle", "reference-only"]).optional(),
|
|
110124
|
+
whiteboards: exports_external.enum(["bundle", "reference-only"]).optional(),
|
|
109841
110125
|
videos: exports_external.enum(["bundle", "reference-only"]),
|
|
109842
110126
|
maxBytesPerResource: exports_external.number().int().positive(),
|
|
109843
110127
|
maxTotalBytes: exports_external.number().int().positive()
|
|
@@ -109875,8 +110159,9 @@ var init_larkSnapshotBundle = __esm(() => {
|
|
|
109875
110159
|
|
|
109876
110160
|
// src/project/documentCaptureLark.ts
|
|
109877
110161
|
import { createHash as createHash38 } from "node:crypto";
|
|
109878
|
-
import { readdir as
|
|
109879
|
-
import { basename as basename10, extname as extname14, join as
|
|
110162
|
+
import { readdir as readdir29, readFile as readFile98 } from "node:fs/promises";
|
|
110163
|
+
import { basename as basename10, extname as extname14, join as join122 } from "node:path";
|
|
110164
|
+
import { isDeepStrictEqual as isDeepStrictEqual3 } from "node:util";
|
|
109880
110165
|
function titleFromMarkdown2(markdown, fallbackPath) {
|
|
109881
110166
|
const heading2 = markdown.split(`
|
|
109882
110167
|
`).find((line) => /^#\s+\S/u.test(line));
|
|
@@ -109895,7 +110180,7 @@ function countLines3(markdown) {
|
|
|
109895
110180
|
}
|
|
109896
110181
|
async function fileContentMatches(path3, content3) {
|
|
109897
110182
|
try {
|
|
109898
|
-
const current3 = await
|
|
110183
|
+
const current3 = await readFile98(path3);
|
|
109899
110184
|
const expected = typeof content3 === "string" ? Buffer.from(content3, "utf8") : Buffer.from(content3);
|
|
109900
110185
|
return current3.equals(expected);
|
|
109901
110186
|
} catch {
|
|
@@ -109903,7 +110188,7 @@ async function fileContentMatches(path3, content3) {
|
|
|
109903
110188
|
}
|
|
109904
110189
|
}
|
|
109905
110190
|
function sourceManifestPath2(entry) {
|
|
109906
|
-
return entry.snapshot?.manifest ??
|
|
110191
|
+
return entry.snapshot?.manifest ?? join122(entry.materializedAt, "manifest.json");
|
|
109907
110192
|
}
|
|
109908
110193
|
function larkRuntimeError(message, detail) {
|
|
109909
110194
|
return new ContextError(ExitCode.ExternalToolError, message, {
|
|
@@ -110035,13 +110320,57 @@ function assetManifestEntry(asset, assetRoot) {
|
|
|
110035
110320
|
...asset.bytes !== undefined ? { bytes: asset.bytes } : {}
|
|
110036
110321
|
};
|
|
110037
110322
|
}
|
|
110323
|
+
function earlierLarkResources(projectRoot, materializedAt, manifest, budgetExcluded) {
|
|
110324
|
+
const byResource = new Map;
|
|
110325
|
+
for (const asset of manifest.assets ?? []) {
|
|
110326
|
+
const source2 = asset.source;
|
|
110327
|
+
if (asset.role !== "evidence" || source2?.kind !== "image" && source2?.kind !== "file" || !source2.locator || !source2.identity || !asset.content_hash || !asset.media_type)
|
|
110328
|
+
continue;
|
|
110329
|
+
byResource.set(`${source2.kind}\x00${source2.locator}`, asset);
|
|
110330
|
+
}
|
|
110331
|
+
if (byResource.size === 0 && budgetExcluded === undefined)
|
|
110332
|
+
return;
|
|
110333
|
+
const revisionId = manifest.metadata?.source?.revisionId;
|
|
110334
|
+
const rawContentHash = manifest.assets?.find((asset) => asset.source?.kind === "lark-docx-xml")?.source?.raw_content_hash;
|
|
110335
|
+
return {
|
|
110336
|
+
...revisionId === undefined ? {} : { revisionId },
|
|
110337
|
+
...rawContentHash === undefined ? {} : { rawContentHash },
|
|
110338
|
+
...budgetExcluded === undefined ? {} : { budgetExcluded },
|
|
110339
|
+
load: async (resource, identity2) => {
|
|
110340
|
+
const asset = byResource.get(`${resource.kind}\x00${resource.locator}`);
|
|
110341
|
+
if (asset === undefined || asset.source?.identity !== identity2)
|
|
110342
|
+
return;
|
|
110343
|
+
let bytes;
|
|
110344
|
+
try {
|
|
110345
|
+
bytes = await readFile98(join122(projectRoot, materializedAt, asset.path));
|
|
110346
|
+
} catch {
|
|
110347
|
+
return;
|
|
110348
|
+
}
|
|
110349
|
+
if (computeDocumentContentHash(bytes) !== asset.content_hash)
|
|
110350
|
+
return;
|
|
110351
|
+
return {
|
|
110352
|
+
path: asset.path,
|
|
110353
|
+
bytes,
|
|
110354
|
+
mediaType: asset.media_type,
|
|
110355
|
+
representation: asset.source.representation === "preview" ? "preview" : "original"
|
|
110356
|
+
};
|
|
110357
|
+
}
|
|
110358
|
+
};
|
|
110359
|
+
}
|
|
110360
|
+
function budgetExcludedImages(report, policy) {
|
|
110361
|
+
const budget = report?.resource_budget;
|
|
110362
|
+
if (budget === undefined || report?.access === undefined || policy.maxBytesPerResource > budget.maxBytesPerResource || policy.maxTotalBytes > budget.maxTotalBytes)
|
|
110363
|
+
return;
|
|
110364
|
+
const locators = new Set(report.resources.filter((item) => item.kind === "image" && item.reason_code === "image-budget-exceeded").map((item) => item.locator));
|
|
110365
|
+
return locators.size === 0 ? undefined : { identity: report.access.identity, locators };
|
|
110366
|
+
}
|
|
110038
110367
|
async function listSnapshotAssetFiles(root2, assetRoot) {
|
|
110039
|
-
const assetsRoot =
|
|
110368
|
+
const assetsRoot = join122(root2, assetRoot);
|
|
110040
110369
|
const files = [];
|
|
110041
110370
|
const visit4 = async (dir, prefix = assetRoot) => {
|
|
110042
110371
|
let entries2;
|
|
110043
110372
|
try {
|
|
110044
|
-
entries2 = await
|
|
110373
|
+
entries2 = await readdir29(dir, { withFileTypes: true });
|
|
110045
110374
|
} catch (error) {
|
|
110046
110375
|
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
110047
110376
|
return;
|
|
@@ -110049,7 +110378,7 @@ async function listSnapshotAssetFiles(root2, assetRoot) {
|
|
|
110049
110378
|
}
|
|
110050
110379
|
for (const entry of entries2) {
|
|
110051
110380
|
const relPath = `${prefix}/${entry.name}`;
|
|
110052
|
-
const absolutePath =
|
|
110381
|
+
const absolutePath = join122(dir, entry.name);
|
|
110053
110382
|
if (entry.isDirectory()) {
|
|
110054
110383
|
await visit4(absolutePath, relPath);
|
|
110055
110384
|
continue;
|
|
@@ -110064,7 +110393,7 @@ async function listSnapshotAssetFiles(root2, assetRoot) {
|
|
|
110064
110393
|
}
|
|
110065
110394
|
async function staleSnapshotAssetPaths(input) {
|
|
110066
110395
|
const existingPaths = await listSnapshotAssetFiles(input.materializedAtAbsPath, input.assetRoot);
|
|
110067
|
-
return existingPaths.filter((path3) => !input.currentPaths.has(path3)).map((path3) =>
|
|
110396
|
+
return existingPaths.filter((path3) => !input.currentPaths.has(path3)).map((path3) => join122(input.materializedAtAbsPath, path3));
|
|
110068
110397
|
}
|
|
110069
110398
|
function normalizeLarkError(error, sourceName) {
|
|
110070
110399
|
if (error instanceof ContextError)
|
|
@@ -110128,7 +110457,7 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
110128
110457
|
const target = larkTarget(entry);
|
|
110129
110458
|
const manifestPath = sourceManifestPath2(entry);
|
|
110130
110459
|
const materializedAt = entry.materializedAt;
|
|
110131
|
-
const materializedAtAbsPath =
|
|
110460
|
+
const materializedAtAbsPath = join122(input.projectRoot, materializedAt);
|
|
110132
110461
|
const { current: currentManifestFile, previous: previousManifest, recovery } = await readDocumentManifestForCapture({
|
|
110133
110462
|
projectRoot: input.projectRoot,
|
|
110134
110463
|
manifestPath,
|
|
@@ -110138,7 +110467,16 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
110138
110467
|
const fingerprint = previousManifest === null || larkSnapshotIdentityDiagnostic(entry, previousManifest) !== null ? undefined : await larkSnapshotFingerprint(input.projectRoot, materializedAt, previousManifest);
|
|
110139
110468
|
const refresh = input.refreshSources?.includes(`lark:${resolved.sourceName}`) === true;
|
|
110140
110469
|
const previousRevision = (fingerprint === undefined ? undefined : await checkedLarkRevision(input.projectRoot, resolved.sourceName, fingerprint)) ?? previousManifest?.metadata?.source?.revisionId;
|
|
110141
|
-
const unchangedRevisionId = !refresh && !input.prefetched && !recovery &&
|
|
110470
|
+
const unchangedRevisionId = !refresh && !input.prefetched && !recovery && isDeepStrictEqual3(normalizedSnapshotResourcePolicy({ ...DEFAULT_RESOURCE_POLICY, ...input.phase.resources }), normalizedSnapshotResourcePolicy(DEFAULT_RESOURCE_POLICY)) && previousManifest?.normalizer_version === LARK_DOCUMENT_NORMALIZER_VERSION && fingerprint !== undefined ? previousRevision : undefined;
|
|
110471
|
+
let reuseResources;
|
|
110472
|
+
if (previousManifest !== null && !recovery && !input.prefetched && larkSnapshotIdentityDiagnostic(entry, previousManifest) === null) {
|
|
110473
|
+
try {
|
|
110474
|
+
const report = readDocumentSnapshotCaptureReport({ projectRoot: input.projectRoot, materializedAt, manifest: previousManifest });
|
|
110475
|
+
if (documentSnapshotFidelityState(previousManifest, report).resourceMaterialization?.status === "error") {
|
|
110476
|
+
reuseResources = earlierLarkResources(input.projectRoot, materializedAt, previousManifest, budgetExcludedImages(report, { ...DEFAULT_RESOURCE_POLICY, ...input.phase.resources }));
|
|
110477
|
+
}
|
|
110478
|
+
} catch {}
|
|
110479
|
+
}
|
|
110142
110480
|
await beginFormatOnlyUpdate(input.projectRoot);
|
|
110143
110481
|
let unchangedAccess;
|
|
110144
110482
|
if (typeof unchangedRevisionId === "string" && previousManifest !== null) {
|
|
@@ -110160,6 +110498,7 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
110160
110498
|
url: target.value,
|
|
110161
110499
|
resourcePolicy: input.phase.resources,
|
|
110162
110500
|
requireCompleteBody: true,
|
|
110501
|
+
...reuseResources === undefined ? {} : { reuseResources },
|
|
110163
110502
|
...typeof unchangedRevisionId === "string" ? { unchangedRevisionId } : {},
|
|
110164
110503
|
...unchangedAccess === undefined ? {} : { unchangedAccess },
|
|
110165
110504
|
accessEvents,
|
|
@@ -110226,7 +110565,7 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
110226
110565
|
manifest: previousManifest
|
|
110227
110566
|
}));
|
|
110228
110567
|
let lost = fetched.resourceMaterialization.items.filter((item) => previous3.resourceMaterialization?.items.some((old) => old.kind === item.kind && old.locator === item.locator && old.status === "materialized" && (item.status !== "materialized" || item.reason_code === "document.resource.preview" && old.reason_code !== "document.resource.preview")));
|
|
110229
|
-
degraded = lost.filter((item) => item.status === "materialized" || isNonBlockingDocumentResourceFailureReasonCode(item.reason_code));
|
|
110568
|
+
degraded = lost.filter((item) => item.status === "materialized" || isNonBlockingDocumentResourceFailureReasonCode(item.reason_code) || LARK_POLICY_EXCLUSION_REASON_CODES.has(item.reason_code ?? ""));
|
|
110230
110569
|
lost = lost.filter((item) => !degraded.includes(item));
|
|
110231
110570
|
if (lost.length)
|
|
110232
110571
|
throw new ContextError(ExitCode.WorkspaceStateError, "Previously captured resources were degraded; the existing snapshot was preserved. Check resource policy and access before retrying the explicit refresh.", {
|
|
@@ -110275,7 +110614,7 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
110275
110614
|
title: title2,
|
|
110276
110615
|
locator
|
|
110277
110616
|
}];
|
|
110278
|
-
const manifestAbsPath =
|
|
110617
|
+
const manifestAbsPath = join122(input.projectRoot, manifestPath);
|
|
110279
110618
|
const manifest = createDocumentSnapshotManifest({
|
|
110280
110619
|
sourceType: "lark",
|
|
110281
110620
|
sourceName: resolved.sourceName,
|
|
@@ -110305,13 +110644,13 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
110305
110644
|
const cacheDiagnostics = [];
|
|
110306
110645
|
try {
|
|
110307
110646
|
const requestedWrites = [{
|
|
110308
|
-
path:
|
|
110647
|
+
path: join122(materializedAtAbsPath, documentPath),
|
|
110309
110648
|
bytes: normalized
|
|
110310
110649
|
}];
|
|
110311
110650
|
for (const asset of assets) {
|
|
110312
110651
|
if (asset.bytes !== undefined) {
|
|
110313
110652
|
requestedWrites.push({
|
|
110314
|
-
path:
|
|
110653
|
+
path: join122(materializedAtAbsPath, asset.entry.path),
|
|
110315
110654
|
bytes: asset.bytes
|
|
110316
110655
|
});
|
|
110317
110656
|
}
|
|
@@ -110345,7 +110684,7 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
110345
110684
|
if (relativePath in capturedFiles)
|
|
110346
110685
|
continue;
|
|
110347
110686
|
try {
|
|
110348
|
-
capturedFiles[relativePath] = `sha256:${createHash38("sha256").update(await
|
|
110687
|
+
capturedFiles[relativePath] = `sha256:${createHash38("sha256").update(await readFile98(join122(input.projectRoot, relativePath))).digest("hex")}`;
|
|
110349
110688
|
} catch (error) {
|
|
110350
110689
|
if (error.code === "ENOENT")
|
|
110351
110690
|
capturedFiles[relativePath] = null;
|
|
@@ -110354,7 +110693,7 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
110354
110693
|
}
|
|
110355
110694
|
}
|
|
110356
110695
|
await applyAtomicFileBatch({
|
|
110357
|
-
transactionRoot:
|
|
110696
|
+
transactionRoot: join122(input.projectRoot, ".tmp", "context-runtime", "capture-transactions"),
|
|
110358
110697
|
writes,
|
|
110359
110698
|
removals
|
|
110360
110699
|
});
|
|
@@ -110462,6 +110801,7 @@ var init_documentCaptureLark = __esm(() => {
|
|
|
110462
110801
|
init_writeLock();
|
|
110463
110802
|
init_sensitiveSourceLiteral();
|
|
110464
110803
|
init_larkSnapshotBundle();
|
|
110804
|
+
init_larkImagePolicy();
|
|
110465
110805
|
init_larkCaptureFreshness();
|
|
110466
110806
|
init_documentSnapshotFidelity();
|
|
110467
110807
|
init_formatOnlyUpdate();
|
|
@@ -110539,8 +110879,8 @@ __export(exports_writeLockRecovery, {
|
|
|
110539
110879
|
recoverWriterLock: () => recoverWriterLock,
|
|
110540
110880
|
inspectWriterLock: () => inspectWriterLock
|
|
110541
110881
|
});
|
|
110542
|
-
import { lstat as lstat17, mkdir as mkdir41, readFile as
|
|
110543
|
-
import { join as
|
|
110882
|
+
import { lstat as lstat17, mkdir as mkdir41, readFile as readFile104, readdir as readdir30, rename as rename11, rmdir as rmdir2 } from "node:fs/promises";
|
|
110883
|
+
import { join as join127 } from "node:path";
|
|
110544
110884
|
import { createHash as createHash40, randomUUID as randomUUID8 } from "node:crypto";
|
|
110545
110885
|
async function inspectWriterLock(root2) {
|
|
110546
110886
|
const path3 = await safeProjectTarget(root2, lockRelative);
|
|
@@ -110555,7 +110895,7 @@ async function inspectWriterLock(root2) {
|
|
|
110555
110895
|
if (!stat11.isDirectory() || stat11.isSymbolicLink())
|
|
110556
110896
|
throw new Error("Writer lock must be a real directory.");
|
|
110557
110897
|
const ownerPath = await safeProjectTarget(root2, `${lockRelative}/owner.json`);
|
|
110558
|
-
const bytes = await
|
|
110898
|
+
const bytes = await readFile104(ownerPath, "utf8");
|
|
110559
110899
|
const owner = JSON.parse(bytes);
|
|
110560
110900
|
if (owner.protocol !== "context.project-write-lock.v1" || !Number.isSafeInteger(owner.pid) || owner.pid <= 0) {
|
|
110561
110901
|
throw new Error("Writer lock owner is invalid; preserve the lock for diagnosis.");
|
|
@@ -110591,19 +110931,19 @@ async function recoverWriterLock(input) {
|
|
|
110591
110931
|
};
|
|
110592
110932
|
if (input.plan_digest !== revision)
|
|
110593
110933
|
throw new Error("Writer lock or transactions changed; preview recovery again.");
|
|
110594
|
-
const path3 =
|
|
110595
|
-
const guard =
|
|
110934
|
+
const path3 = join127(input.projectRoot, lockRelative);
|
|
110935
|
+
const guard = join127(path3, ".recovery");
|
|
110596
110936
|
await mkdir41(guard);
|
|
110597
110937
|
let archived = false;
|
|
110598
110938
|
try {
|
|
110599
110939
|
const current3 = await inspectWriterLock(input.projectRoot);
|
|
110600
110940
|
if (current3?.digest !== before.digest || current3.process_state !== "not-running")
|
|
110601
110941
|
throw new Error("Writer lock changed or owner resumed; keep the lock.");
|
|
110602
|
-
const names = await
|
|
110942
|
+
const names = await readdir30(path3);
|
|
110603
110943
|
if (names.some((name3) => name3 !== "owner.json" && name3 !== ".recovery"))
|
|
110604
110944
|
throw new Error("Unexpected lock contents; preserve for diagnosis.");
|
|
110605
110945
|
const archive = `.tmp/context-runtime/locks/recovered-write-${randomUUID8()}.lock`;
|
|
110606
|
-
await rename11(path3,
|
|
110946
|
+
await rename11(path3, join127(input.projectRoot, archive));
|
|
110607
110947
|
archived = true;
|
|
110608
110948
|
const receipts = await withProjectWriteLock(input.projectRoot, "recover-writer-transactions", async () => {
|
|
110609
110949
|
if (JSON.stringify(await recoveryJournals(input.projectRoot)) !== JSON.stringify(journals)) {
|
|
@@ -110636,12 +110976,12 @@ __export(exports_taskRecovery, {
|
|
|
110636
110976
|
RECOVERY_COMMAND: () => RECOVERY_COMMAND
|
|
110637
110977
|
});
|
|
110638
110978
|
import { existsSync as existsSync32 } from "node:fs";
|
|
110639
|
-
import { basename as basename11, dirname as dirname50, join as
|
|
110640
|
-
import { lstat as lstat18, readdir as
|
|
110979
|
+
import { basename as basename11, dirname as dirname50, join as join128 } from "node:path";
|
|
110980
|
+
import { lstat as lstat18, readdir as readdir31, readFile as readFile105 } from "node:fs/promises";
|
|
110641
110981
|
async function recoveryText(root2, path3) {
|
|
110642
110982
|
const target = await safeProjectTarget(root2, path3);
|
|
110643
110983
|
try {
|
|
110644
|
-
return await
|
|
110984
|
+
return await readFile105(target, "utf8");
|
|
110645
110985
|
} catch (error) {
|
|
110646
110986
|
if (error.code === "ENOENT")
|
|
110647
110987
|
return;
|
|
@@ -110654,7 +110994,7 @@ async function recoveryJournals(root2) {
|
|
|
110654
110994
|
await safeProjectTarget(root2, path3);
|
|
110655
110995
|
let stat11;
|
|
110656
110996
|
try {
|
|
110657
|
-
stat11 = await lstat18(
|
|
110997
|
+
stat11 = await lstat18(join128(root2, path3));
|
|
110658
110998
|
} catch (error) {
|
|
110659
110999
|
if (error.code === "ENOENT")
|
|
110660
111000
|
return;
|
|
@@ -110665,7 +111005,7 @@ async function recoveryJournals(root2) {
|
|
|
110665
111005
|
if (stat11.isDirectory()) {
|
|
110666
111006
|
if (depth > 3)
|
|
110667
111007
|
throw new TypeError("Unexpected transaction directory depth; preserve it for diagnosis.");
|
|
110668
|
-
for (const name3 of (await
|
|
111008
|
+
for (const name3 of (await readdir31(join128(root2, path3))).sort())
|
|
110669
111009
|
await visit4(`${path3}/${name3}`, depth + 1);
|
|
110670
111010
|
} else if (stat11.isFile())
|
|
110671
111011
|
entries2.push({ path: path3, digest: indexerProtocolDigest(await recoveryText(root2, path3)) });
|
|
@@ -110677,8 +111017,8 @@ function recoveryResources() {
|
|
|
110677
111017
|
try {
|
|
110678
111018
|
const root2 = dirname50(contextWorkflowProviderPath());
|
|
110679
111019
|
const resources = {
|
|
110680
|
-
skill:
|
|
110681
|
-
issue_template:
|
|
111020
|
+
skill: join128(root2, "skills/recover-workspace/SKILL.md"),
|
|
111021
|
+
issue_template: join128(root2, "resources/templates/recovery-issue.md")
|
|
110682
111022
|
};
|
|
110683
111023
|
if (!Object.values(resources).every((path3) => existsSync32(path3)))
|
|
110684
111024
|
throw new Error("Recovery resources are absent from this Provider.");
|
|
@@ -110793,8 +111133,8 @@ var exports_taskLocalSourceAdjustment = {};
|
|
|
110793
111133
|
__export(exports_taskLocalSourceAdjustment, {
|
|
110794
111134
|
adjustLocalRevisionSources: () => adjustLocalRevisionSources
|
|
110795
111135
|
});
|
|
110796
|
-
import { readFile as
|
|
110797
|
-
import { join as
|
|
111136
|
+
import { readFile as readFile106 } from "node:fs/promises";
|
|
111137
|
+
import { join as join129 } from "node:path";
|
|
110798
111138
|
async function adjustLocalRevisionSources(root2, input) {
|
|
110799
111139
|
const { readMaintenance: readMaintenance2 } = await Promise.resolve().then(() => (init_maintenanceStorage(), exports_maintenanceStorage));
|
|
110800
111140
|
if ((await readMaintenance2(root2)).active && await readProductionStage(root2))
|
|
@@ -110840,7 +111180,7 @@ async function adjustLocalRevisionSources(root2, input) {
|
|
|
110840
111180
|
if (input.refresh && (!current3.refresh_sources || indexerProtocolDigest([...current3.refresh_sources].sort()) !== indexerProtocolDigest([...selected].sort()))) {
|
|
110841
111181
|
throw new TypeError("No matching acquisition adjustment exists. Run task adjust without refresh first.");
|
|
110842
111182
|
}
|
|
110843
|
-
const raw = await
|
|
111183
|
+
const raw = await readFile106(join129(root2, await revisionStoragePath(root2)), "utf8");
|
|
110844
111184
|
let next2;
|
|
110845
111185
|
const discardIds = new Set;
|
|
110846
111186
|
if (!refresh) {
|
|
@@ -110955,7 +111295,7 @@ ${input.instruction}` : revision.instruction
|
|
|
110955
111295
|
content: content3
|
|
110956
111296
|
}];
|
|
110957
111297
|
if (discardIds.size > 0) {
|
|
110958
|
-
const ledger = await
|
|
111298
|
+
const ledger = await readFile106(join129(root2, CANDIDATE_LEDGER_FILE), "utf8").catch((error) => {
|
|
110959
111299
|
if (error.code === "ENOENT")
|
|
110960
111300
|
return;
|
|
110961
111301
|
throw error;
|
|
@@ -111303,7 +111643,7 @@ __export(exports_approvedRevisionSubmission, {
|
|
|
111303
111643
|
prepareApprovedRevisionSubmission: () => prepareApprovedRevisionSubmission,
|
|
111304
111644
|
completeApprovedRevisionSubmission: () => completeApprovedRevisionSubmission
|
|
111305
111645
|
});
|
|
111306
|
-
import { join as
|
|
111646
|
+
import { join as join131 } from "node:path";
|
|
111307
111647
|
function paused(message, managed, authorities = []) {
|
|
111308
111648
|
return new ContextError(ExitCode.WorkspaceStateError, message, {
|
|
111309
111649
|
category: ErrorCategory.WorkspaceStateInvalid,
|
|
@@ -111358,9 +111698,9 @@ async function prepareApprovedRevisionSubmission(input) {
|
|
|
111358
111698
|
const { route, requests, contexts, issued } = await issueRevisionBatch(input);
|
|
111359
111699
|
const stage = stageId(issued);
|
|
111360
111700
|
const directory = productionAgentDirectory(stage);
|
|
111361
|
-
await atomicWriteFile(await safeProjectTarget(input.projectRoot,
|
|
111701
|
+
await atomicWriteFile(await safeProjectTarget(input.projectRoot, join131(directory, "issued.json")), JSON.stringify(issued));
|
|
111362
111702
|
for (const [index3, request] of requests.entries()) {
|
|
111363
|
-
await atomicWriteFile(await safeProjectTarget(input.projectRoot,
|
|
111703
|
+
await atomicWriteFile(await safeProjectTarget(input.projectRoot, join131(directory, `${issued.tasks[index3].task}.input.json`)), JSON.stringify({
|
|
111364
111704
|
stage: "approved-revision",
|
|
111365
111705
|
revision: request.revision,
|
|
111366
111706
|
instruction: request.instruction,
|
|
@@ -111375,7 +111715,7 @@ async function prepareApprovedRevisionSubmission(input) {
|
|
|
111375
111715
|
tasks: issued.tasks.map((task, index3) => ({
|
|
111376
111716
|
...task,
|
|
111377
111717
|
path: requests[index3].target.path,
|
|
111378
|
-
task_input:
|
|
111718
|
+
task_input: join131(directory, `${task.task}.input.json`)
|
|
111379
111719
|
})),
|
|
111380
111720
|
submission: { stage, tasks: issued.tasks.map((task) => ({ task: task.task, input: task.input, edits: `${task.task}.edits.json` })) },
|
|
111381
111721
|
next_action: {
|
|
@@ -111603,7 +111943,7 @@ var init_approvedRevisionSubmission = __esm(() => {
|
|
|
111603
111943
|
});
|
|
111604
111944
|
|
|
111605
111945
|
// src/project/managedDocumentImport.ts
|
|
111606
|
-
import { readFile as
|
|
111946
|
+
import { readFile as readFile115 } from "node:fs/promises";
|
|
111607
111947
|
async function importManagedDocument(projectRoot2, value) {
|
|
111608
111948
|
const input = inputSchema.parse(value);
|
|
111609
111949
|
if (input.type !== "sessions" && input.changes !== undefined)
|
|
@@ -111612,7 +111952,7 @@ async function importManagedDocument(projectRoot2, value) {
|
|
|
111612
111952
|
const path3 = await assertManagedDocumentPath(projectRoot2, input.type, input.name);
|
|
111613
111953
|
let previous3;
|
|
111614
111954
|
try {
|
|
111615
|
-
previous3 = await
|
|
111955
|
+
previous3 = await readFile115(path3, "utf8");
|
|
111616
111956
|
} catch (error) {
|
|
111617
111957
|
if (!(error && typeof error === "object" && ("code" in error) && error.code === "ENOENT"))
|
|
111618
111958
|
throw error;
|
|
@@ -111659,7 +111999,7 @@ var init_managedDocumentImport = __esm(() => {
|
|
|
111659
111999
|
});
|
|
111660
112000
|
|
|
111661
112001
|
// src/project/larkDocumentImport.ts
|
|
111662
|
-
import { readFile as
|
|
112002
|
+
import { readFile as readFile116 } from "node:fs/promises";
|
|
111663
112003
|
import { resolve as resolve48 } from "node:path";
|
|
111664
112004
|
async function importLarkDocument(projectRoot2, value) {
|
|
111665
112005
|
const input = schema4.parse(value);
|
|
@@ -111676,7 +112016,7 @@ async function importLarkDocument(projectRoot2, value) {
|
|
|
111676
112016
|
const responsePages = [];
|
|
111677
112017
|
for (const path3 of input.response_files) {
|
|
111678
112018
|
assertActionInputWorkspace(projectRoot2, path3);
|
|
111679
|
-
responsePages.push(await
|
|
112019
|
+
responsePages.push(await readFile116(resolve48(projectRoot2, path3), "utf8"));
|
|
111680
112020
|
}
|
|
111681
112021
|
const mediaFiles = {};
|
|
111682
112022
|
for (const [token, path3] of Object.entries(input.media_files ?? {})) {
|
|
@@ -111743,11 +112083,11 @@ var exports_managedDocumentRename = {};
|
|
|
111743
112083
|
__export(exports_managedDocumentRename, {
|
|
111744
112084
|
renameManagedDocument: () => renameManagedDocument
|
|
111745
112085
|
});
|
|
111746
|
-
import { readFile as
|
|
111747
|
-
import { join as
|
|
112086
|
+
import { readFile as readFile117 } from "node:fs/promises";
|
|
112087
|
+
import { join as join143, posix as posix15 } from "node:path";
|
|
111748
112088
|
async function optionalText3(path3) {
|
|
111749
112089
|
try {
|
|
111750
|
-
return await
|
|
112090
|
+
return await readFile117(path3, "utf8");
|
|
111751
112091
|
} catch (error) {
|
|
111752
112092
|
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT")
|
|
111753
112093
|
return;
|
|
@@ -111831,7 +112171,7 @@ async function renameManagedDocument(input) {
|
|
|
111831
112171
|
if (path3.split("/").includes("..") || path3.startsWith("/"))
|
|
111832
112172
|
throw new TypeError("Source references contain an unsafe knowledge path; repair it before renaming.");
|
|
111833
112173
|
await safeProjectTarget(input.projectRoot, path3);
|
|
111834
|
-
const before = await optionalText3(
|
|
112174
|
+
const before = await optionalText3(join143(input.projectRoot, path3));
|
|
111835
112175
|
if (before === undefined)
|
|
111836
112176
|
continue;
|
|
111837
112177
|
let after;
|
|
@@ -111923,7 +112263,7 @@ var exports_originalRevisionsCommand = {};
|
|
|
111923
112263
|
__export(exports_originalRevisionsCommand, {
|
|
111924
112264
|
runOriginalRevisionsCommand: () => runOriginalRevisionsCommand
|
|
111925
112265
|
});
|
|
111926
|
-
import { readFile as
|
|
112266
|
+
import { readFile as readFile121 } from "node:fs/promises";
|
|
111927
112267
|
import { resolve as resolve56 } from "node:path";
|
|
111928
112268
|
async function readInput(cwd, source2) {
|
|
111929
112269
|
const raw = source2 === "-" ? await new Promise((resolveInput, reject) => {
|
|
@@ -111934,7 +112274,7 @@ async function readInput(cwd, source2) {
|
|
|
111934
112274
|
});
|
|
111935
112275
|
process.stdin.on("end", () => resolveInput(data2));
|
|
111936
112276
|
process.stdin.on("error", reject);
|
|
111937
|
-
}) : await
|
|
112277
|
+
}) : await readFile121(resolve56(cwd, source2), "utf8");
|
|
111938
112278
|
return import_yaml68.default.parse(raw);
|
|
111939
112279
|
}
|
|
111940
112280
|
async function runOriginalRevisionsCommand(input) {
|
|
@@ -111989,7 +112329,7 @@ var init_originalRevisionsCommand = __esm(() => {
|
|
|
111989
112329
|
|
|
111990
112330
|
// src/cli.ts
|
|
111991
112331
|
import { existsSync as existsSync41, realpathSync as realpathSync3 } from "node:fs";
|
|
111992
|
-
import { dirname as dirname57, join as
|
|
112332
|
+
import { dirname as dirname57, join as join149 } from "node:path";
|
|
111993
112333
|
import { fileURLToPath as fileURLToPath12, pathToFileURL as pathToFileURL3 } from "node:url";
|
|
111994
112334
|
|
|
111995
112335
|
// ../../node_modules/.bun/commander@11.1.0/node_modules/commander/esm.mjs
|
|
@@ -112028,15 +112368,15 @@ init_workflowFacts();
|
|
|
112028
112368
|
init_workflowProvider();
|
|
112029
112369
|
init_workflowResourceRender();
|
|
112030
112370
|
init_workflowTypes();
|
|
112031
|
-
import { join as
|
|
112371
|
+
import { join as join115 } from "node:path";
|
|
112032
112372
|
|
|
112033
112373
|
// src/project/reviewHtml.ts
|
|
112034
112374
|
init_originalRevisions();
|
|
112035
112375
|
init_candidateLedger();
|
|
112036
112376
|
init_reviewShared();
|
|
112037
|
-
import { copyFile, mkdir as mkdir37, readFile as
|
|
112377
|
+
import { copyFile, mkdir as mkdir37, readFile as readFile92, writeFile as writeFile29 } from "node:fs/promises";
|
|
112038
112378
|
import { fileURLToPath as fileURLToPath8 } from "node:url";
|
|
112039
|
-
import { dirname as dirname46, isAbsolute as isAbsolute17, join as
|
|
112379
|
+
import { dirname as dirname46, isAbsolute as isAbsolute17, join as join113, resolve as resolve35 } from "node:path";
|
|
112040
112380
|
|
|
112041
112381
|
// src/project/reviewSiteModel.ts
|
|
112042
112382
|
init_siteTheme2();
|
|
@@ -112044,8 +112384,8 @@ init_src2();
|
|
|
112044
112384
|
init_unified();
|
|
112045
112385
|
init_remark_parse();
|
|
112046
112386
|
var import_yaml52 = __toESM(require_dist(), 1);
|
|
112047
|
-
import { readFile as
|
|
112048
|
-
import { join as
|
|
112387
|
+
import { readFile as readFile90 } from "node:fs/promises";
|
|
112388
|
+
import { join as join111 } from "node:path";
|
|
112049
112389
|
import { execFile as execFile17 } from "node:child_process";
|
|
112050
112390
|
import { promisify as promisify14 } from "node:util";
|
|
112051
112391
|
import { createHash as createHash33 } from "node:crypto";
|
|
@@ -115010,10 +115350,10 @@ function remarkGfm(options) {
|
|
|
115010
115350
|
init_workspace();
|
|
115011
115351
|
|
|
115012
115352
|
// src/project/reviewFeedback.ts
|
|
115013
|
-
import { readdir as readdir24, readFile as
|
|
115014
|
-
import { join as
|
|
115353
|
+
import { readdir as readdir24, readFile as readFile88 } from "node:fs/promises";
|
|
115354
|
+
import { join as join110 } from "node:path";
|
|
115015
115355
|
async function readPendingReviewFeedback(root2, candidates) {
|
|
115016
|
-
const directory =
|
|
115356
|
+
const directory = join110(root2, ".tmp/context-runtime/review-feedback");
|
|
115017
115357
|
let files;
|
|
115018
115358
|
try {
|
|
115019
115359
|
files = await readdir24(directory);
|
|
@@ -115026,7 +115366,7 @@ async function readPendingReviewFeedback(root2, candidates) {
|
|
|
115026
115366
|
const results = new Map;
|
|
115027
115367
|
const receipts = [];
|
|
115028
115368
|
for (const file of files.filter((f) => /^[a-f0-9]+\.json$/u.test(f)).sort()) {
|
|
115029
|
-
const receipt2 = JSON.parse(await
|
|
115369
|
+
const receipt2 = JSON.parse(await readFile88(join110(directory, file), "utf8"));
|
|
115030
115370
|
receipts.push(receipt2);
|
|
115031
115371
|
}
|
|
115032
115372
|
for (const receipt2 of receipts.sort((a2, b) => a2.created_at.localeCompare(b.created_at))) {
|
|
@@ -115136,7 +115476,7 @@ var title = (s, fallback) => {
|
|
|
115136
115476
|
};
|
|
115137
115477
|
async function optional2(path3) {
|
|
115138
115478
|
try {
|
|
115139
|
-
return await
|
|
115479
|
+
return await readFile90(path3, "utf8");
|
|
115140
115480
|
} catch (e) {
|
|
115141
115481
|
if (e.code === "ENOENT")
|
|
115142
115482
|
return;
|
|
@@ -115173,7 +115513,7 @@ async function reviewSiteBaselineHash(root2, reviewedPaths) {
|
|
|
115173
115513
|
const displayed = new Set([...reviewedPaths, ...(metadata.structure?.articles ?? []).filter((a2) => navigation.changedArticles.has(a2.article_id)).map((a2) => a2.path)]);
|
|
115174
115514
|
return hash4(JSON.stringify([
|
|
115175
115515
|
navigation.baseline,
|
|
115176
|
-
await optional2(
|
|
115516
|
+
await optional2(join111(root2, "src/knowledge-map.yaml")) ?? null,
|
|
115177
115517
|
navigation.planned ? [navigation.planned.retired, navigation.planned.knowledge_map ?? null] : null,
|
|
115178
115518
|
files.map((f) => [f.relPath, displayed.has(f.relPath) ? hash4(f.content) : title(f.content, f.relPath)]).sort((a2, b) => a2[0].localeCompare(b[0]))
|
|
115179
115519
|
]));
|
|
@@ -115286,9 +115626,9 @@ async function collectReviewSiteModel(root2, candidates) {
|
|
|
115286
115626
|
nodes.push({ key: `review-page-${p.id}`, parent: "review-unplaced", title: p.title, order: i2, page: p.id, change: p.change });
|
|
115287
115627
|
}
|
|
115288
115628
|
const navigationChanges = navigationBaseline === "empty" ? [] : reviewNavigationChanges(baseline?.entries ?? [], current3?.entries ?? [], pages);
|
|
115289
|
-
const pkgText = await optional2(
|
|
115629
|
+
const pkgText = await optional2(join111(root2, "package.json"));
|
|
115290
115630
|
const pkg = pkgText ? JSON.parse(pkgText) : {};
|
|
115291
|
-
const project = await optional2(
|
|
115631
|
+
const project = await optional2(join111(root2, "src/index.ts")) === undefined ? undefined : await loadContextProjectModule(root2);
|
|
115292
115632
|
const siteTitle = project?.project.packages.flatMap((p) => p.kind === "package.kb" && p.site?.title ? [p.site.title] : [])[0];
|
|
115293
115633
|
const sitePackages = project?.project.packages.flatMap((p) => p.kind === "package.kb" && p.site ? [p.site] : []) ?? [];
|
|
115294
115634
|
const themeCss = siteThemeVariables(await resolveSiteTheme(root2, sitePackages.length === 1 ? sitePackages[0]?.theme : undefined));
|
|
@@ -115355,9 +115695,9 @@ init_errors3();
|
|
|
115355
115695
|
init_cliFeedback();
|
|
115356
115696
|
init_exitCode();
|
|
115357
115697
|
init_reviewShared();
|
|
115358
|
-
import { readFile as
|
|
115359
|
-
import { join as
|
|
115360
|
-
var scopePath = (root2, scope2) =>
|
|
115698
|
+
import { readFile as readFile91 } from "node:fs/promises";
|
|
115699
|
+
import { join as join112 } from "node:path";
|
|
115700
|
+
var scopePath = (root2, scope2) => join112(root2, ".tmp/context-runtime/review", `${scope2}.scope.json`);
|
|
115361
115701
|
async function saveReviewReportScope(root2, scope2, candidates, baselineHash, reportPath) {
|
|
115362
115702
|
const ids = candidates.map((candidate) => candidate.record.candidate_id).sort();
|
|
115363
115703
|
const value = {
|
|
@@ -115377,7 +115717,7 @@ async function saveReviewReportScope(root2, scope2, candidates, baselineHash, re
|
|
|
115377
115717
|
}
|
|
115378
115718
|
async function readConfirmedReviewScope(root2, scope2) {
|
|
115379
115719
|
try {
|
|
115380
|
-
const value = JSON.parse(await
|
|
115720
|
+
const value = JSON.parse(await readFile91(scopePath(root2, scope2), "utf8"));
|
|
115381
115721
|
if (!value || typeof value !== "object" || !("scope" in value) || !("baseline_hash" in value))
|
|
115382
115722
|
throw new Error("Missing report scope");
|
|
115383
115723
|
const parsed = value;
|
|
@@ -115919,7 +116259,7 @@ button:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
|
|
|
115919
116259
|
|
|
115920
116260
|
// src/project/reviewHtml.ts
|
|
115921
116261
|
init_knowledgeMap2();
|
|
115922
|
-
var REVIEW_HTML_ROOT =
|
|
116262
|
+
var REVIEW_HTML_ROOT = join113(".tmp", "context-runtime", "review");
|
|
115923
116263
|
async function collectReviewCandidates(projectRoot, collection) {
|
|
115924
116264
|
const rows = await readCandidateRecords(projectRoot);
|
|
115925
116265
|
const draftRows = rows.filter((row) => row.collection === collection && row.status === "draft");
|
|
@@ -115969,13 +116309,13 @@ ${diagramScript ? `<script>${diagramScript}</script>` : ""}<script>const DATA=${
|
|
|
115969
116309
|
}
|
|
115970
116310
|
function resolveOutputPath(projectRoot, outPath, reviewScope) {
|
|
115971
116311
|
if (outPath === undefined)
|
|
115972
|
-
return
|
|
116312
|
+
return join113(projectRoot, REVIEW_HTML_ROOT, `${reviewScope}.html`);
|
|
115973
116313
|
return isAbsolute17(outPath) ? outPath : resolve35(projectRoot, outPath);
|
|
115974
116314
|
}
|
|
115975
|
-
var APPLIED_REVIEW_REPORT_ROOT =
|
|
116315
|
+
var APPLIED_REVIEW_REPORT_ROOT = join113(".tmp", "review-reports");
|
|
115976
116316
|
async function archiveAppliedReviewReport(projectRoot, reportPath, scope2) {
|
|
115977
116317
|
const stamp = new Date().toISOString().replace(/[:.]/gu, "-");
|
|
115978
|
-
const target =
|
|
116318
|
+
const target = join113(projectRoot, APPLIED_REVIEW_REPORT_ROOT, `${stamp}-${scope2}.html`);
|
|
115979
116319
|
await mkdir37(dirname46(target), { recursive: true });
|
|
115980
116320
|
await copyFile(reportPath, target);
|
|
115981
116321
|
return target;
|
|
@@ -116021,11 +116361,11 @@ async function writeReviewHtml(input) {
|
|
|
116021
116361
|
if (model.pages.some((page) => page.html.includes('class="language-mermaid"'))) {
|
|
116022
116362
|
const here = dirname46(fileURLToPath8(import.meta.url));
|
|
116023
116363
|
try {
|
|
116024
|
-
diagramScript = await
|
|
116364
|
+
diagramScript = await readFile92(join113(here, "browser/diagrams.js"), "utf8");
|
|
116025
116365
|
} catch (error) {
|
|
116026
116366
|
if (error.code !== "ENOENT")
|
|
116027
116367
|
throw error;
|
|
116028
|
-
diagramScript = await
|
|
116368
|
+
diagramScript = await readFile92(resolve35(here, "../../dist/browser/diagrams.js"), "utf8");
|
|
116029
116369
|
}
|
|
116030
116370
|
}
|
|
116031
116371
|
await writeFile29(outPath, renderReviewHtml(model, diagramScript), "utf8");
|
|
@@ -116069,8 +116409,8 @@ init_productionRequirements();
|
|
|
116069
116409
|
init_dist();
|
|
116070
116410
|
init_atomicWrite();
|
|
116071
116411
|
init_reviewShared();
|
|
116072
|
-
import { mkdir as mkdir38, readFile as
|
|
116073
|
-
import { join as
|
|
116412
|
+
import { mkdir as mkdir38, readFile as readFile93 } from "node:fs/promises";
|
|
116413
|
+
import { join as join114 } from "node:path";
|
|
116074
116414
|
var REVIEW_BATCH_MAX_CANDIDATES = 6;
|
|
116075
116415
|
var REVIEW_BATCH_MAX_BYTES = 512 * 1024;
|
|
116076
116416
|
async function readerPurposes(projectRoot, sources) {
|
|
@@ -116150,12 +116490,12 @@ async function materializeCurrentReviewBatchSet(input) {
|
|
|
116150
116490
|
const batches = buildCurrentReviewBatchDocuments(input.candidates);
|
|
116151
116491
|
const setDigest = digestText(batches.map((batch) => `${batch.task_key}:${batch.digest}`).join(`
|
|
116152
116492
|
`));
|
|
116153
|
-
const root2 =
|
|
116493
|
+
const root2 = join114(input.projectRoot, ".tmp", "context-runtime", "review", `current-${setDigest.slice("sha256:".length)}`);
|
|
116154
116494
|
await mkdir38(root2, { recursive: true });
|
|
116155
116495
|
const entries2 = [];
|
|
116156
116496
|
for (const batch of batches) {
|
|
116157
|
-
const path4 =
|
|
116158
|
-
const existing = await
|
|
116497
|
+
const path4 = join114(input.projectRoot, ".tmp", "context-runtime", "review", `${batch.task_key}-${batch.digest.slice("sha256:".length)}.md`);
|
|
116498
|
+
const existing = await readFile93(path4, "utf8").catch((error) => {
|
|
116159
116499
|
if (error.code === "ENOENT")
|
|
116160
116500
|
return;
|
|
116161
116501
|
throw error;
|
|
@@ -116208,7 +116548,7 @@ async function materializeCurrentReviewBatchSet(input) {
|
|
|
116208
116548
|
].join(`
|
|
116209
116549
|
`);
|
|
116210
116550
|
const digest7 = digestText(content3);
|
|
116211
|
-
const path3 =
|
|
116551
|
+
const path3 = join114(root2, "index.md");
|
|
116212
116552
|
await atomicWriteFile(path3, `${content3}
|
|
116213
116553
|
`);
|
|
116214
116554
|
return {
|
|
@@ -116242,11 +116582,11 @@ function shellQuote6(value) {
|
|
|
116242
116582
|
}
|
|
116243
116583
|
function receiptSetPath(receipts) {
|
|
116244
116584
|
const token = digestText(JSON.stringify(receipts)).slice("sha256:".length);
|
|
116245
|
-
return
|
|
116585
|
+
return join115(".tmp", "context-runtime", "workflow", "read-receipts", `${token}.json`);
|
|
116246
116586
|
}
|
|
116247
116587
|
async function writeReceiptContinuation(input) {
|
|
116248
116588
|
const path3 = receiptSetPath(input.receipts);
|
|
116249
|
-
const absolutePath =
|
|
116589
|
+
const absolutePath = join115(input.projectRoot, path3);
|
|
116250
116590
|
await writeJsonAtomic(absolutePath, input.receipts);
|
|
116251
116591
|
const contextCommand = input.managed ? [
|
|
116252
116592
|
"context",
|
|
@@ -116341,7 +116681,7 @@ async function materializeContextWorkflowResource(input) {
|
|
|
116341
116681
|
const resourceId = workflowResourceId(input.resourceId);
|
|
116342
116682
|
const content3 = renderContextWorkflowResource(resourceId, status);
|
|
116343
116683
|
const location = await materializeResource(await loadContextWorkflowProvider(), resourceId, {
|
|
116344
|
-
cache:
|
|
116684
|
+
cache: join115(found.projectRoot, ".tmp", "context-runtime", "workflow", "resources"),
|
|
116345
116685
|
workspace: found.projectRoot,
|
|
116346
116686
|
revision: input.revision,
|
|
116347
116687
|
input: {
|
|
@@ -116373,7 +116713,7 @@ async function materializeContextWorkflowResource(input) {
|
|
|
116373
116713
|
receipts: afterReadReceipts
|
|
116374
116714
|
});
|
|
116375
116715
|
const directResources = (status.workflow.current?.resources.required ?? []).filter((resource) => resource.read_state === "read-required" && resource.path !== undefined && resource.digest !== undefined);
|
|
116376
|
-
const afterReadCommand = directResources.length === 0 ? continuation.command : `context resource acknowledge-current --revision ${shellQuote6(input.revision)}${authorityCommandOptions(authorities, "resource")} --resource-receipts ${shellQuote6(`@${
|
|
116716
|
+
const afterReadCommand = directResources.length === 0 ? continuation.command : `context resource acknowledge-current --revision ${shellQuote6(input.revision)}${authorityCommandOptions(authorities, "resource")} --resource-receipts ${shellQuote6(`@${join115(found.projectRoot, continuation.path)}`)} --format json`;
|
|
116377
116717
|
return {
|
|
116378
116718
|
protocol: "context.workflow.resource.v1",
|
|
116379
116719
|
id: resourceId,
|
|
@@ -116434,14 +116774,14 @@ async function acknowledgeCurrentWorkflowResources(input) {
|
|
|
116434
116774
|
const reevaluated = await reevaluateProjectStatusWorkflow({
|
|
116435
116775
|
snapshot,
|
|
116436
116776
|
resourceReceipts: normalizedReceipts,
|
|
116437
|
-
resourceReceiptsReference: `@${
|
|
116777
|
+
resourceReceiptsReference: `@${join115(found.projectRoot, continuation.path)}`
|
|
116438
116778
|
});
|
|
116439
116779
|
return {
|
|
116440
116780
|
...reevaluated,
|
|
116441
116781
|
resourceAcknowledgement: {
|
|
116442
116782
|
protocol: "context.workflow.resource-receipts.v1",
|
|
116443
116783
|
acknowledged: directResources.length,
|
|
116444
|
-
receiptReference: `@${
|
|
116784
|
+
receiptReference: `@${join115(found.projectRoot, continuation.path)}`,
|
|
116445
116785
|
message: "For workflow continuation, use the returned selected command with its revision and resource-receipt arguments. Receipts retain required-reading state for Route evaluation; they are not approval credentials or universal prerequisites for direct CLI primitives. Direct commands still enforce their own state, scope and confirmation checks. Do not pre-chain an earlier write command or replace this result with status without receipts. Acknowledgement does not necessarily change the revision; reread only changed or unavailable required content."
|
|
116446
116786
|
}
|
|
116447
116787
|
};
|
|
@@ -116488,9 +116828,9 @@ init_cliFeedback();
|
|
|
116488
116828
|
init_errors3();
|
|
116489
116829
|
init_exitCode();
|
|
116490
116830
|
init_workspace();
|
|
116491
|
-
import { readFile as
|
|
116492
|
-
import { isAbsolute as isAbsolute18, join as
|
|
116493
|
-
var RECEIPT_DIRECTORY =
|
|
116831
|
+
import { readFile as readFile94 } from "node:fs/promises";
|
|
116832
|
+
import { isAbsolute as isAbsolute18, join as join116, sep as sep8, resolve as resolve36 } from "node:path";
|
|
116833
|
+
var RECEIPT_DIRECTORY = join116(".tmp", "context-runtime", "workflow", "read-receipts");
|
|
116494
116834
|
function workflowResourceReceiptCwd(value, cwd) {
|
|
116495
116835
|
if (value === undefined || !value.startsWith("@"))
|
|
116496
116836
|
return cwd;
|
|
@@ -116508,7 +116848,7 @@ async function receiptDocument(value, cwd) {
|
|
|
116508
116848
|
let source2 = value;
|
|
116509
116849
|
if (value.startsWith("@")) {
|
|
116510
116850
|
try {
|
|
116511
|
-
source2 = await
|
|
116851
|
+
source2 = await readFile94(resolve36(cwd, value.slice(1)), "utf8");
|
|
116512
116852
|
} catch (error) {
|
|
116513
116853
|
const ioCode = error !== null && typeof error === "object" && "code" in error && typeof error.code === "string" ? error.code : undefined;
|
|
116514
116854
|
throw new ContextError(ExitCode.UserError, "resource read receipt file is unavailable", {
|
|
@@ -116770,14 +117110,14 @@ function compactJsonResult(result, verbose) {
|
|
|
116770
117110
|
// src/project/runLog.ts
|
|
116771
117111
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
116772
117112
|
import { mkdir as mkdir40, writeFile as writeFile31 } from "node:fs/promises";
|
|
116773
|
-
import { dirname as dirname48, join as
|
|
117113
|
+
import { dirname as dirname48, join as join123 } from "node:path";
|
|
116774
117114
|
var createPhaseRunId = () => {
|
|
116775
117115
|
const timestamp = new Date().toISOString().replace(/[-:.TZ]/gu, "");
|
|
116776
117116
|
return `run_${timestamp}_${randomUUID6().slice(0, 8)}`;
|
|
116777
117117
|
};
|
|
116778
117118
|
async function writePhaseRunLog(input) {
|
|
116779
|
-
const relPath =
|
|
116780
|
-
const absPath =
|
|
117119
|
+
const relPath = join123(".tmp", "context-runtime", "runs", `${input.runId}.json`);
|
|
117120
|
+
const absPath = join123(input.projectRoot, relPath);
|
|
116781
117121
|
await mkdir40(dirname48(absPath), { recursive: true });
|
|
116782
117122
|
await writeFile31(absPath, `${JSON.stringify({
|
|
116783
117123
|
run_id: input.runId,
|
|
@@ -118008,7 +118348,7 @@ init_cliFeedback();
|
|
|
118008
118348
|
init_errors3();
|
|
118009
118349
|
init_exitCode();
|
|
118010
118350
|
import { existsSync as existsSync31 } from "node:fs";
|
|
118011
|
-
import { readFile as
|
|
118351
|
+
import { readFile as readFile101 } from "node:fs/promises";
|
|
118012
118352
|
import { isAbsolute as isAbsolute21, resolve as resolve38 } from "node:path";
|
|
118013
118353
|
|
|
118014
118354
|
// src/project/reviewApply.ts
|
|
@@ -118025,8 +118365,8 @@ init_durableMultiFileTransaction();
|
|
|
118025
118365
|
init_durableSingleFileTransaction();
|
|
118026
118366
|
init_reviewShared();
|
|
118027
118367
|
import { existsSync as existsSync30 } from "node:fs";
|
|
118028
|
-
import { readFile as
|
|
118029
|
-
import { join as
|
|
118368
|
+
import { readFile as readFile99 } from "node:fs/promises";
|
|
118369
|
+
import { join as join124 } from "node:path";
|
|
118030
118370
|
function existingTimestamp(markdown) {
|
|
118031
118371
|
if (markdown === undefined)
|
|
118032
118372
|
return;
|
|
@@ -118053,7 +118393,7 @@ async function prepareApprovedPage(input) {
|
|
|
118053
118393
|
next: "Refresh the current production or article revision, then reopen Review before approval."
|
|
118054
118394
|
});
|
|
118055
118395
|
}
|
|
118056
|
-
const relPath =
|
|
118396
|
+
const relPath = join124("knowledge", input.record.path);
|
|
118057
118397
|
const existingView = findApprovedPageForArticleId(input.record.indexer_candidate.artifact_ref, input.approvedPageIndex);
|
|
118058
118398
|
const previousPath = input.record.approved_revision?.previous_path;
|
|
118059
118399
|
if (previousPath !== undefined && (!isSafeKnowledgeTargetPath(previousPath.split("/")[0], previousPath) || previousPath.includes("\\")))
|
|
@@ -118068,13 +118408,13 @@ async function prepareApprovedPage(input) {
|
|
|
118068
118408
|
next: "Resolve the approved page path migration explicitly before approving this candidate."
|
|
118069
118409
|
});
|
|
118070
118410
|
}
|
|
118071
|
-
const absPath =
|
|
118072
|
-
const existing = existsSync30(absPath) ? await
|
|
118411
|
+
const absPath = join124(input.projectRoot, relPath);
|
|
118412
|
+
const existing = existsSync30(absPath) ? await readFile99(absPath, "utf8") : undefined;
|
|
118073
118413
|
let previous3;
|
|
118074
118414
|
if (previousPath !== undefined) {
|
|
118075
118415
|
if (existing !== undefined || existingView?.relPath !== `knowledge/${previousPath}`)
|
|
118076
118416
|
throw new TypeError("Page move destination or original identity changed; refresh its revision.");
|
|
118077
|
-
previous3 = { path: `knowledge/${previousPath}`, content: await
|
|
118417
|
+
previous3 = { path: `knowledge/${previousPath}`, content: await readFile99(join124(input.projectRoot, "knowledge", previousPath), "utf8") };
|
|
118078
118418
|
}
|
|
118079
118419
|
if (input.record.approved_revision !== undefined) {
|
|
118080
118420
|
const base = previous3?.content ?? existing;
|
|
@@ -118121,7 +118461,7 @@ async function prepareApprovedPage(input) {
|
|
|
118121
118461
|
}
|
|
118122
118462
|
async function readProjectFileMaybe(projectRoot, relPath) {
|
|
118123
118463
|
try {
|
|
118124
|
-
return await
|
|
118464
|
+
return await readFile99(join124(projectRoot, relPath), "utf8");
|
|
118125
118465
|
} catch (error) {
|
|
118126
118466
|
if (error !== null && typeof error === "object" && "code" in error && error.code === "ENOENT") {
|
|
118127
118467
|
return;
|
|
@@ -118342,7 +118682,7 @@ async function applyReviewDecisions(input) {
|
|
|
118342
118682
|
});
|
|
118343
118683
|
}
|
|
118344
118684
|
seenApprovedIds.set(approvedRef, row.candidate_id);
|
|
118345
|
-
const approvedPath =
|
|
118685
|
+
const approvedPath = join124("knowledge", row.path);
|
|
118346
118686
|
const previousPathCandidate = seenApprovedPaths.get(knowledgeTargetPathKey(approvedPath));
|
|
118347
118687
|
if (previousPathCandidate !== undefined) {
|
|
118348
118688
|
throw new ContextError(ExitCode.UserError, `multiple approved review decisions target the same knowledge path: ${approvedPath}`, {
|
|
@@ -118392,7 +118732,7 @@ async function applyReviewDecisions(input) {
|
|
|
118392
118732
|
for (const path3 of approvedPageIndex.byRelPath.keys()) {
|
|
118393
118733
|
if (pagesToWrite.some((page) => page.relPath === path3 || page.previous?.path === path3))
|
|
118394
118734
|
continue;
|
|
118395
|
-
const before = await
|
|
118735
|
+
const before = await readFile99(join124(input.projectRoot, path3), "utf8");
|
|
118396
118736
|
const local = path3.replace(/^knowledge\//u, "");
|
|
118397
118737
|
const after = moveKnowledgeLinkTargets2(before, local, local, moved);
|
|
118398
118738
|
navigationTargets.push(reviewFileTarget({ path: path3, baseContent: before, targetContent: after }));
|
|
@@ -118458,11 +118798,11 @@ async function applyReviewDecisions(input) {
|
|
|
118458
118798
|
init_reviewShared();
|
|
118459
118799
|
init_writeLock();
|
|
118460
118800
|
init_verifyFrontmatter();
|
|
118461
|
-
import { readFile as
|
|
118801
|
+
import { readFile as readFile100, writeFile as writeFile32 } from "node:fs/promises";
|
|
118462
118802
|
function deprecateApprovedPage(input) {
|
|
118463
118803
|
return withProjectWriteLock(input.projectRoot, "deprecate-article", async () => {
|
|
118464
118804
|
const page = await approvedPageForArticleId(input.projectRoot, input.viewRef);
|
|
118465
|
-
const original = await
|
|
118805
|
+
const original = await readFile100(page.path, "utf8");
|
|
118466
118806
|
const content3 = parseFrontmatterLoose(original).deprecated === true ? original : updateFrontmatter(original, (metadata) => ({ ...metadata, deprecated: true, timestamp: new Date().toISOString() }));
|
|
118467
118807
|
const changed = content3 !== original;
|
|
118468
118808
|
if (changed)
|
|
@@ -118483,12 +118823,12 @@ init_candidateLedger();
|
|
|
118483
118823
|
|
|
118484
118824
|
// src/project/localHtmlReport.ts
|
|
118485
118825
|
import { execFile as execFile18 } from "node:child_process";
|
|
118486
|
-
import { isAbsolute as isAbsolute20, join as
|
|
118826
|
+
import { isAbsolute as isAbsolute20, join as join125 } from "node:path";
|
|
118487
118827
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
118488
118828
|
import { promisify as promisify15 } from "node:util";
|
|
118489
118829
|
var execFileAsync4 = promisify15(execFile18);
|
|
118490
118830
|
function htmlReportReference(input) {
|
|
118491
|
-
const absolutePath = isAbsolute20(input.path) ? input.path :
|
|
118831
|
+
const absolutePath = isAbsolute20(input.path) ? input.path : join125(input.projectRoot, input.path);
|
|
118492
118832
|
return {
|
|
118493
118833
|
format: "html",
|
|
118494
118834
|
path: input.path,
|
|
@@ -118674,7 +119014,7 @@ function parseReviewPayloadText(raw) {
|
|
|
118674
119014
|
async function readReviewPayloadFile(filePath2, projectRoot) {
|
|
118675
119015
|
let raw;
|
|
118676
119016
|
try {
|
|
118677
|
-
raw = await
|
|
119017
|
+
raw = await readFile101(filePath2, "utf8");
|
|
118678
119018
|
} catch (error) {
|
|
118679
119019
|
const message = error instanceof Error ? error.message : String(error);
|
|
118680
119020
|
throw new ContextError(ExitCode.UserError, `review payload file cannot be read: ${filePath2}`, {
|
|
@@ -119277,7 +119617,7 @@ init_cliFeedback();
|
|
|
119277
119617
|
init_errors3();
|
|
119278
119618
|
init_exitCode();
|
|
119279
119619
|
var import_yaml53 = __toESM(require_dist(), 1);
|
|
119280
|
-
import { readFile as
|
|
119620
|
+
import { readFile as readFile102 } from "node:fs/promises";
|
|
119281
119621
|
function userInputError2(message, detail = {}) {
|
|
119282
119622
|
return new ContextError(ExitCode.UserError, message, {
|
|
119283
119623
|
category: ErrorCategory.UserInputInvalid,
|
|
@@ -119346,7 +119686,7 @@ async function readPayloadTextFromStdin(stdin) {
|
|
|
119346
119686
|
}
|
|
119347
119687
|
async function readPayloadText(path3) {
|
|
119348
119688
|
if (path3 !== "-")
|
|
119349
|
-
return
|
|
119689
|
+
return readFile102(path3, "utf8");
|
|
119350
119690
|
return readPayloadTextFromStdin(process.stdin);
|
|
119351
119691
|
}
|
|
119352
119692
|
function unquotedColonText(message) {
|
|
@@ -119676,8 +120016,8 @@ init_exitCode();
|
|
|
119676
120016
|
init_maintenanceStorage();
|
|
119677
120017
|
init_productionFeedback();
|
|
119678
120018
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
119679
|
-
import { readFile as
|
|
119680
|
-
import { join as
|
|
120019
|
+
import { readFile as readFile103 } from "node:fs/promises";
|
|
120020
|
+
import { join as join126 } from "node:path";
|
|
119681
120021
|
async function beginProductionRevision(input) {
|
|
119682
120022
|
return withProductionFeedback({ operation: "revision" }, () => withProjectWriteLock(input.projectRoot, "production-revision", async () => {
|
|
119683
120023
|
await recoverDurableMultiFileTransactions(input.projectRoot);
|
|
@@ -119716,7 +120056,7 @@ async function beginProductionRevision(input) {
|
|
|
119716
120056
|
const formal = approved.byPath.get(path3);
|
|
119717
120057
|
if (!prior && !formal)
|
|
119718
120058
|
throw invalid3("Write the current task first; there is no article draft to revise yet.");
|
|
119719
|
-
const markdown = prior?.body ?? await
|
|
120059
|
+
const markdown = prior?.body ?? await readFile103(await safeProjectTarget(input.projectRoot, join126("knowledge", path3)), "utf8");
|
|
119720
120060
|
const sections = prior?.indexer_candidate.sections.map((section) => ({ id: section.section_key, references: section.references })) ?? formal?.sections;
|
|
119721
120061
|
const sources = [];
|
|
119722
120062
|
for (const source2 of owner.sources) {
|
|
@@ -120254,7 +120594,7 @@ function registerVersionCommands(program2) {
|
|
|
120254
120594
|
|
|
120255
120595
|
// src/commands/translateCommands.ts
|
|
120256
120596
|
init_workspace();
|
|
120257
|
-
import { isAbsolute as isAbsolute22, join as
|
|
120597
|
+
import { isAbsolute as isAbsolute22, join as join130 } from "node:path";
|
|
120258
120598
|
init_status();
|
|
120259
120599
|
init_workflowCommandOptions();
|
|
120260
120600
|
init_workflowExecutionContext();
|
|
@@ -120348,7 +120688,7 @@ function registerTranslateCommands(program2) {
|
|
|
120348
120688
|
readFailureNext: "Check the input path",
|
|
120349
120689
|
parseFailureNext: "Use valid YAML or JSON"
|
|
120350
120690
|
}));
|
|
120351
|
-
const saved = await submitSiteTranslation(root2, await projectPackages(root2), value, (file) => isAbsolute22(file) ? file :
|
|
120691
|
+
const saved = await submitSiteTranslation(root2, await projectPackages(root2), value, (file) => isAbsolute22(file) ? file : join130(root2, file));
|
|
120352
120692
|
write(await withWorkflow(root2, { outcome: "submitted", ...saved }));
|
|
120353
120693
|
});
|
|
120354
120694
|
command3.command("skip").description("Publish the current pending translations in the primary language").requiredOption("--digest <digest>", "expected_digest from context translate prepare").option("--format <format>", "json", "json").action(async (options) => {
|
|
@@ -120446,7 +120786,7 @@ init_workflowRouteOutput();
|
|
|
120446
120786
|
var import_yaml57 = __toESM(require_dist(), 1);
|
|
120447
120787
|
import { Buffer as Buffer5 } from "node:buffer";
|
|
120448
120788
|
import { createHash as createHash41 } from "node:crypto";
|
|
120449
|
-
import { join as
|
|
120789
|
+
import { join as join132 } from "node:path";
|
|
120450
120790
|
var INLINE_LIMIT = 16 * 1024;
|
|
120451
120791
|
function record4(value) {
|
|
120452
120792
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
@@ -120472,8 +120812,8 @@ async function prepareActionCompletionOutput(input) {
|
|
|
120472
120812
|
if (production && Buffer5.byteLength(full) <= INLINE_LIMIT)
|
|
120473
120813
|
return input.result;
|
|
120474
120814
|
const digest8 = createHash41("sha256").update(full).digest("hex");
|
|
120475
|
-
const root2 =
|
|
120476
|
-
const resultFile =
|
|
120815
|
+
const root2 = join132(input.projectRoot, ".tmp/context-runtime/action-results");
|
|
120816
|
+
const resultFile = join132(root2, `${digest8}.json`);
|
|
120477
120817
|
await atomicWriteFile(resultFile, full);
|
|
120478
120818
|
if (production)
|
|
120479
120819
|
return {
|
|
@@ -120755,9 +121095,9 @@ function registerProjectActionCommands(program2) {
|
|
|
120755
121095
|
// src/commands/cleanClaudePluginCache.ts
|
|
120756
121096
|
init_cliFeedback();
|
|
120757
121097
|
import { existsSync as existsSync33 } from "node:fs";
|
|
120758
|
-
import { readdir as
|
|
121098
|
+
import { readdir as readdir32, rm as rm31 } from "node:fs/promises";
|
|
120759
121099
|
import { homedir } from "node:os";
|
|
120760
|
-
import { join as
|
|
121100
|
+
import { join as join133 } from "node:path";
|
|
120761
121101
|
var ORPHAN_MARKER = ".orphaned_at";
|
|
120762
121102
|
var CLAUDE_PLUGIN_CACHE_ROOT_ENV = "C4A_CLAUDE_PLUGIN_CACHE_ROOT";
|
|
120763
121103
|
var CLAUDE_PLUGIN_CACHE_HOME_ENV = "C4A_CLAUDE_PLUGIN_CACHE_HOME";
|
|
@@ -120770,40 +121110,40 @@ async function cleanClaudePluginCache(opts = {}) {
|
|
|
120770
121110
|
lines.push("· claude plugin cache: missing — nothing to clean");
|
|
120771
121111
|
return { lines, removed, scanned };
|
|
120772
121112
|
}
|
|
120773
|
-
const marketplaces = await
|
|
121113
|
+
const marketplaces = await readdir32(cacheRoot, { withFileTypes: true });
|
|
120774
121114
|
for (const mp of marketplaces) {
|
|
120775
121115
|
if (!mp.isDirectory())
|
|
120776
121116
|
continue;
|
|
120777
|
-
const mpDir =
|
|
120778
|
-
const plugins = await
|
|
121117
|
+
const mpDir = join133(cacheRoot, mp.name);
|
|
121118
|
+
const plugins = await readdir32(mpDir, { withFileTypes: true });
|
|
120779
121119
|
for (const pl of plugins) {
|
|
120780
121120
|
if (!pl.isDirectory())
|
|
120781
121121
|
continue;
|
|
120782
|
-
const plDir =
|
|
120783
|
-
const versions = await
|
|
121122
|
+
const plDir = join133(mpDir, pl.name);
|
|
121123
|
+
const versions = await readdir32(plDir, { withFileTypes: true });
|
|
120784
121124
|
for (const ver of versions) {
|
|
120785
121125
|
if (!ver.isDirectory())
|
|
120786
121126
|
continue;
|
|
120787
121127
|
scanned += 1;
|
|
120788
|
-
const verDir =
|
|
120789
|
-
const markerPath =
|
|
121128
|
+
const verDir = join133(plDir, ver.name);
|
|
121129
|
+
const markerPath = join133(verDir, ORPHAN_MARKER);
|
|
120790
121130
|
if (!existsSync33(markerPath))
|
|
120791
121131
|
continue;
|
|
120792
121132
|
const label2 = `${mp.name}/${pl.name}/${ver.name}`;
|
|
120793
121133
|
if (opts.dryRun) {
|
|
120794
121134
|
lines.push(` - would remove: ${label2}`);
|
|
120795
121135
|
} else {
|
|
120796
|
-
await
|
|
121136
|
+
await rm31(verDir, { recursive: true, force: true });
|
|
120797
121137
|
removed += 1;
|
|
120798
121138
|
lines.push(` ✓ removed: ${label2}`);
|
|
120799
121139
|
}
|
|
120800
121140
|
}
|
|
120801
121141
|
if (!opts.dryRun && await isEmptyDir(plDir)) {
|
|
120802
|
-
await
|
|
121142
|
+
await rm31(plDir, { recursive: true, force: true });
|
|
120803
121143
|
}
|
|
120804
121144
|
}
|
|
120805
121145
|
if (!opts.dryRun && await isEmptyDir(mpDir)) {
|
|
120806
|
-
await
|
|
121146
|
+
await rm31(mpDir, { recursive: true, force: true });
|
|
120807
121147
|
}
|
|
120808
121148
|
}
|
|
120809
121149
|
if (scanned === 0) {
|
|
@@ -120818,11 +121158,11 @@ function resolveClaudePluginCacheRoot(opts) {
|
|
|
120818
121158
|
if (explicitRoot)
|
|
120819
121159
|
return explicitRoot;
|
|
120820
121160
|
const home = opts.home ?? process.env[CLAUDE_PLUGIN_CACHE_HOME_ENV] ?? homedir();
|
|
120821
|
-
return
|
|
121161
|
+
return join133(home, ".claude", "plugins", "cache");
|
|
120822
121162
|
}
|
|
120823
121163
|
async function isEmptyDir(dir) {
|
|
120824
121164
|
try {
|
|
120825
|
-
const entries2 = await
|
|
121165
|
+
const entries2 = await readdir32(dir);
|
|
120826
121166
|
return entries2.length === 0;
|
|
120827
121167
|
} catch {
|
|
120828
121168
|
return false;
|
|
@@ -120854,7 +121194,7 @@ init_statusCommand();
|
|
|
120854
121194
|
// src/project/sourceCommands.ts
|
|
120855
121195
|
init_repoContentLinks();
|
|
120856
121196
|
init_src2();
|
|
120857
|
-
import { readFile as
|
|
121197
|
+
import { readFile as readFile118 } from "node:fs/promises";
|
|
120858
121198
|
import { isAbsolute as isAbsolute26, resolve as resolve49 } from "node:path";
|
|
120859
121199
|
init_cliFeedback();
|
|
120860
121200
|
init_errors3();
|
|
@@ -120872,7 +121212,7 @@ init_repoSourceRegistry();
|
|
|
120872
121212
|
init_writeLock();
|
|
120873
121213
|
import { execFile as execFile19 } from "node:child_process";
|
|
120874
121214
|
import { existsSync as existsSync34 } from "node:fs";
|
|
120875
|
-
import { lstat as lstat19, mkdir as mkdir42, readlink as readlink3, realpath as realpath16, rm as
|
|
121215
|
+
import { lstat as lstat19, mkdir as mkdir42, readlink as readlink3, realpath as realpath16, rm as rm32, symlink as symlink5 } from "node:fs/promises";
|
|
120876
121216
|
import { basename as basename12, dirname as dirname51, isAbsolute as isAbsolute23, relative as relative34, resolve as resolve43 } from "node:path";
|
|
120877
121217
|
import { promisify as promisify16 } from "node:util";
|
|
120878
121218
|
var execFileAsync5 = promisify16(execFile19);
|
|
@@ -121065,13 +121405,13 @@ async function cloneCheckout(input) {
|
|
|
121065
121405
|
try {
|
|
121066
121406
|
await clone(cloneArgs);
|
|
121067
121407
|
} catch (first) {
|
|
121068
|
-
await
|
|
121408
|
+
await rm32(target, { recursive: true, force: true });
|
|
121069
121409
|
try {
|
|
121070
121410
|
if (first instanceof GitProgressError && first.kind !== "failed")
|
|
121071
121411
|
throw first;
|
|
121072
121412
|
await clone(["clone", "--no-checkout", "--depth=1", input.remote, target]);
|
|
121073
121413
|
} catch (error) {
|
|
121074
|
-
await
|
|
121414
|
+
await rm32(target, { recursive: true, force: true });
|
|
121075
121415
|
const detail = error instanceof Error ? error.message : String(error);
|
|
121076
121416
|
throw new ContextError(ExitCode.ExternalToolError, `cannot clone registered repository: ${input.remote}`, {
|
|
121077
121417
|
category: ErrorCategory.ExternalToolFailed,
|
|
@@ -121098,7 +121438,7 @@ async function cloneCheckout(input) {
|
|
|
121098
121438
|
await verifyCheckout({ checkout: target, remote: input.remote, ref: input.ref, subpaths: input.subpaths });
|
|
121099
121439
|
return target;
|
|
121100
121440
|
} catch (error) {
|
|
121101
|
-
await
|
|
121441
|
+
await rm32(target, { recursive: true, force: true });
|
|
121102
121442
|
throw error;
|
|
121103
121443
|
}
|
|
121104
121444
|
}
|
|
@@ -121114,7 +121454,7 @@ async function bindLocalAlias(input) {
|
|
|
121114
121454
|
const actualReal = await realpath16(actual).catch(() => null);
|
|
121115
121455
|
if (actualReal !== null && actualReal === await realpath16(input.checkout))
|
|
121116
121456
|
return;
|
|
121117
|
-
await
|
|
121457
|
+
await rm32(alias);
|
|
121118
121458
|
} else {
|
|
121119
121459
|
const actual = await realpath16(alias);
|
|
121120
121460
|
if (actual === await realpath16(input.checkout))
|
|
@@ -121222,16 +121562,16 @@ async function restoreRepositorySources(input) {
|
|
|
121222
121562
|
init_src2();
|
|
121223
121563
|
init_documentCapture();
|
|
121224
121564
|
import { existsSync as existsSync35 } from "node:fs";
|
|
121225
|
-
import { readFile as
|
|
121226
|
-
import { join as
|
|
121565
|
+
import { readFile as readFile108 } from "node:fs/promises";
|
|
121566
|
+
import { join as join135 } from "node:path";
|
|
121227
121567
|
|
|
121228
121568
|
// src/project/sourceCommandViews.ts
|
|
121229
121569
|
init_fileSourceOrigins();
|
|
121230
121570
|
init_documentSiteDetection();
|
|
121231
121571
|
init_workspace();
|
|
121232
121572
|
init_documentBatchManifest();
|
|
121233
|
-
import { readFile as
|
|
121234
|
-
import { join as
|
|
121573
|
+
import { readFile as readFile107 } from "node:fs/promises";
|
|
121574
|
+
import { join as join134 } from "node:path";
|
|
121235
121575
|
function repoSourceAgentView(source2) {
|
|
121236
121576
|
return {
|
|
121237
121577
|
id: source2.id ?? source2.name,
|
|
@@ -121296,7 +121636,7 @@ async function fileSourceAgentViewWithNextAction(input) {
|
|
|
121296
121636
|
};
|
|
121297
121637
|
}
|
|
121298
121638
|
function documentSourceManifestPath(source2) {
|
|
121299
|
-
return source2.snapshot?.manifest ??
|
|
121639
|
+
return source2.snapshot?.manifest ?? join134(source2.materializedAt, "manifest.json");
|
|
121300
121640
|
}
|
|
121301
121641
|
async function fileSourceDocumentSiteHint(input) {
|
|
121302
121642
|
const detection = await detectDocumentSiteFiles({
|
|
@@ -121306,7 +121646,7 @@ async function fileSourceDocumentSiteHint(input) {
|
|
|
121306
121646
|
let snapshotConfigured = false;
|
|
121307
121647
|
const manifest = documentSourceManifestPath(input.source);
|
|
121308
121648
|
try {
|
|
121309
|
-
const parsed = parseDocumentSnapshotForSource(JSON.parse(await
|
|
121649
|
+
const parsed = parseDocumentSnapshotForSource(JSON.parse(await readFile107(join134(input.projectRoot, manifest), "utf8")), input.source.name);
|
|
121310
121650
|
snapshotConfigured = manifestUsesMdxJsonDocs(parsed);
|
|
121311
121651
|
} catch {
|
|
121312
121652
|
snapshotConfigured = false;
|
|
@@ -121339,11 +121679,11 @@ async function larkSourceAgentViewWithNextAction(input) {
|
|
|
121339
121679
|
init_documentBatchManifest();
|
|
121340
121680
|
init_documentSnapshotFidelity();
|
|
121341
121681
|
function documentSourceManifestPath2(source2) {
|
|
121342
|
-
return source2.snapshot?.manifest ??
|
|
121682
|
+
return source2.snapshot?.manifest ?? join135(source2.materializedAt, "manifest.json");
|
|
121343
121683
|
}
|
|
121344
121684
|
async function documentSnapshotState(input) {
|
|
121345
121685
|
const manifest = documentSourceManifestPath2(input.source);
|
|
121346
|
-
const manifestPath =
|
|
121686
|
+
const manifestPath = join135(input.projectRoot, manifest);
|
|
121347
121687
|
if (!existsSync35(manifestPath)) {
|
|
121348
121688
|
return {
|
|
121349
121689
|
snapshotReady: false,
|
|
@@ -121354,7 +121694,7 @@ async function documentSnapshotState(input) {
|
|
|
121354
121694
|
};
|
|
121355
121695
|
}
|
|
121356
121696
|
try {
|
|
121357
|
-
const parsed = findDocumentSnapshotForSource(JSON.parse(await
|
|
121697
|
+
const parsed = findDocumentSnapshotForSource(JSON.parse(await readFile108(manifestPath, "utf8")), input.source.name);
|
|
121358
121698
|
if (parsed === null) {
|
|
121359
121699
|
return {
|
|
121360
121700
|
snapshotReady: false,
|
|
@@ -121422,7 +121762,7 @@ async function documentSnapshotState(input) {
|
|
|
121422
121762
|
const missing2 = [
|
|
121423
121763
|
...parsed.files.map((file) => file.path),
|
|
121424
121764
|
...(parsed.assets ?? []).filter((asset) => asset.content_hash !== undefined).map((asset) => asset.path)
|
|
121425
|
-
].find((path3) => !existsSync35(
|
|
121765
|
+
].find((path3) => !existsSync35(join135(input.projectRoot, input.source.materializedAt, path3)));
|
|
121426
121766
|
if (missing2 !== undefined) {
|
|
121427
121767
|
return {
|
|
121428
121768
|
snapshotReady: false,
|
|
@@ -121523,8 +121863,8 @@ init_errors3();
|
|
|
121523
121863
|
init_exitCode();
|
|
121524
121864
|
var import_yaml59 = __toESM(require_dist(), 1);
|
|
121525
121865
|
import { createHash as createHash42 } from "node:crypto";
|
|
121526
|
-
import { readFile as
|
|
121527
|
-
import { basename as basename13, extname as extname15, isAbsolute as isAbsolute24, join as
|
|
121866
|
+
import { readFile as readFile109, realpath as realpath17 } from "node:fs/promises";
|
|
121867
|
+
import { basename as basename13, extname as extname15, isAbsolute as isAbsolute24, join as join136, relative as relative35, resolve as resolve44 } from "node:path";
|
|
121528
121868
|
init_writeLock();
|
|
121529
121869
|
var SOURCE_NAME_PATTERN3 = /^[a-z0-9][a-z0-9._-]*$/u;
|
|
121530
121870
|
function isDateSourceNamespace(value) {
|
|
@@ -121620,7 +121960,7 @@ function assertSafeFileInclude(value) {
|
|
|
121620
121960
|
}
|
|
121621
121961
|
async function readRegistryDocument(projectRoot2, registryPath2) {
|
|
121622
121962
|
try {
|
|
121623
|
-
const content3 = await
|
|
121963
|
+
const content3 = await readFile109(join136(projectRoot2, registryPath2), "utf8");
|
|
121624
121964
|
return content3.trim().length === 0 ? { sources: [] } : import_yaml59.default.parse(content3);
|
|
121625
121965
|
} catch (error) {
|
|
121626
121966
|
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
@@ -121710,10 +122050,10 @@ function flatRawSource(sources, name3) {
|
|
|
121710
122050
|
}
|
|
121711
122051
|
async function ensureOriginInstallRootIgnored(projectRoot2, kind) {
|
|
121712
122052
|
const line = `${fileSourceOriginInstallRoot(kind)}/`;
|
|
121713
|
-
const path3 =
|
|
122053
|
+
const path3 = join136(projectRoot2, ".gitignore");
|
|
121714
122054
|
let current3 = "";
|
|
121715
122055
|
try {
|
|
121716
|
-
current3 = await
|
|
122056
|
+
current3 = await readFile109(path3, "utf8");
|
|
121717
122057
|
} catch {
|
|
121718
122058
|
current3 = "";
|
|
121719
122059
|
}
|
|
@@ -121811,7 +122151,7 @@ async function addFileSourceUnlocked(input) {
|
|
|
121811
122151
|
sourceName: input.name
|
|
121812
122152
|
});
|
|
121813
122153
|
}
|
|
121814
|
-
await atomicWriteFile(
|
|
122154
|
+
await atomicWriteFile(join136(input.projectRoot, DEFAULT_FILE_SOURCES_REGISTRY_PATH), import_yaml59.default.stringify({ sources: nextSources }));
|
|
121815
122155
|
const gitignoreUpdated = origin !== undefined && await ensureOriginInstallRootIgnored(input.projectRoot, origin.kind);
|
|
121816
122156
|
const updated = await loadSourcesRegistry({ rootDir: input.projectRoot });
|
|
121817
122157
|
const entry = updated.files.find((source2) => source2.name === input.name || source2.id === input.name);
|
|
@@ -121872,7 +122212,7 @@ async function addLarkSourceUnlocked(input) {
|
|
|
121872
122212
|
const record6 = entry2;
|
|
121873
122213
|
return record6.name !== input.name && record6.id !== input.name;
|
|
121874
122214
|
}), nextEntry];
|
|
121875
|
-
await atomicWriteFile(
|
|
122215
|
+
await atomicWriteFile(join136(input.projectRoot, DEFAULT_LARK_SOURCES_REGISTRY_PATH), import_yaml59.default.stringify({ sources: nextSources }));
|
|
121876
122216
|
const updated = await loadSourcesRegistry({ rootDir: input.projectRoot });
|
|
121877
122217
|
const entry = updated.larks.find((source2) => source2.name === input.name || source2.id === input.name);
|
|
121878
122218
|
if (entry === undefined) {
|
|
@@ -121904,18 +122244,18 @@ init_cliFeedback();
|
|
|
121904
122244
|
init_errors3();
|
|
121905
122245
|
init_exitCode();
|
|
121906
122246
|
var import_yaml60 = __toESM(require_dist(), 1);
|
|
121907
|
-
import { readFile as
|
|
121908
|
-
import { join as
|
|
121909
|
-
import { isDeepStrictEqual as
|
|
122247
|
+
import { readFile as readFile110 } from "node:fs/promises";
|
|
122248
|
+
import { join as join137 } from "node:path";
|
|
122249
|
+
import { isDeepStrictEqual as isDeepStrictEqual4 } from "node:util";
|
|
121910
122250
|
function identityKeys(entry) {
|
|
121911
122251
|
return new Set([entry.name, entry.id]);
|
|
121912
122252
|
}
|
|
121913
122253
|
async function createLarkBatchRegistration(projectRoot2, namespace) {
|
|
121914
122254
|
const registry2 = await loadSourcesRegistry({ rootDir: projectRoot2 });
|
|
121915
|
-
const registryPath2 =
|
|
122255
|
+
const registryPath2 = join137(projectRoot2, DEFAULT_LARK_SOURCES_REGISTRY_PATH);
|
|
121916
122256
|
let committedSources;
|
|
121917
122257
|
try {
|
|
121918
|
-
const text12 = await
|
|
122258
|
+
const text12 = await readFile110(registryPath2, "utf8");
|
|
121919
122259
|
committedSources = text12.trim().length === 0 ? [] : import_yaml60.default.parse(text12).sources ?? [];
|
|
121920
122260
|
} catch (error) {
|
|
121921
122261
|
if (!(error instanceof Error && ("code" in error) && error.code === "ENOENT"))
|
|
@@ -122016,7 +122356,7 @@ async function createLarkBatchRegistration(projectRoot2, namespace) {
|
|
|
122016
122356
|
modules: [...modules.values()]
|
|
122017
122357
|
};
|
|
122018
122358
|
const nextSources = batchIndex < 0 ? [...committedSources, batch] : committedSources.map((source2, index3) => index3 === batchIndex ? batch : source2);
|
|
122019
|
-
if (!
|
|
122359
|
+
if (!isDeepStrictEqual4(nextSources, committedSources)) {
|
|
122020
122360
|
await atomicWriteFile(registryPath2, import_yaml60.default.stringify({ sources: nextSources }));
|
|
122021
122361
|
committedSources = nextSources;
|
|
122022
122362
|
if (batchIndex < 0)
|
|
@@ -122033,8 +122373,8 @@ init_cliFeedback();
|
|
|
122033
122373
|
init_errors3();
|
|
122034
122374
|
init_exitCode();
|
|
122035
122375
|
import { createHash as createHash43 } from "node:crypto";
|
|
122036
|
-
import { lstat as lstat20, readFile as
|
|
122037
|
-
import { join as
|
|
122376
|
+
import { lstat as lstat20, readFile as readFile111 } from "node:fs/promises";
|
|
122377
|
+
import { join as join138, resolve as resolve45 } from "node:path";
|
|
122038
122378
|
var INPUT_SCHEMA = "context.source-batch.input.v1";
|
|
122039
122379
|
var STATE_SCHEMA = "context.source-batch.state.v1";
|
|
122040
122380
|
var RUNTIME_PARTS = [".tmp", "context-runtime", "source-batches"];
|
|
@@ -122085,14 +122425,14 @@ function paths(projectRoot2, jobId) {
|
|
|
122085
122425
|
throw journalError("source-batch-id-invalid", "Source batch checkpoint ID must contain exactly 32 lowercase hexadecimal characters.");
|
|
122086
122426
|
}
|
|
122087
122427
|
const directory = resolve45(projectRoot2, ...RUNTIME_PARTS, jobId);
|
|
122088
|
-
return { inputPath:
|
|
122428
|
+
return { inputPath: join138(directory, "input.json"), statePath: join138(directory, "state.json") };
|
|
122089
122429
|
}
|
|
122090
122430
|
async function assertJournalPath(projectRoot2, jobId, filename) {
|
|
122091
122431
|
paths(projectRoot2, jobId);
|
|
122092
122432
|
let current3 = resolve45(projectRoot2);
|
|
122093
122433
|
const parts = [...RUNTIME_PARTS, jobId, filename];
|
|
122094
122434
|
for (const [index3, part] of parts.entries()) {
|
|
122095
|
-
current3 =
|
|
122435
|
+
current3 = join138(current3, part);
|
|
122096
122436
|
let stat11;
|
|
122097
122437
|
try {
|
|
122098
122438
|
stat11 = await lstat20(current3);
|
|
@@ -122123,7 +122463,7 @@ async function loadSourceBatchJournal(input) {
|
|
|
122123
122463
|
const { inputPath } = paths(input.projectRoot, input.jobId);
|
|
122124
122464
|
try {
|
|
122125
122465
|
await assertJournalPath(input.projectRoot, input.jobId, "input.json");
|
|
122126
|
-
const stored = JSON.parse(await
|
|
122466
|
+
const stored = JSON.parse(await readFile111(inputPath, "utf8"));
|
|
122127
122467
|
if (stored === null || typeof stored !== "object" || Array.isArray(stored)) {
|
|
122128
122468
|
throw journalError("source-batch-input-invalid", "Source batch checkpoint input must be an object.");
|
|
122129
122469
|
}
|
|
@@ -122226,7 +122566,7 @@ async function readSourceBatchJournalStatus(input) {
|
|
|
122226
122566
|
let warning;
|
|
122227
122567
|
try {
|
|
122228
122568
|
await assertJournalPath(journal.projectRoot, journal.jobId, "state.json");
|
|
122229
|
-
const parsed = JSON.parse(await
|
|
122569
|
+
const parsed = JSON.parse(await readFile111(journal.statePath, "utf8"));
|
|
122230
122570
|
if (parsed.schema !== STATE_SCHEMA || parsed.job_id !== journal.jobId || parsed.input_digest !== journal.inputDigest || parsed.total !== journal.items.length || !Number.isSafeInteger(parsed.pid) || parsed.pid <= 0 || typeof parsed.updated_at !== "string" || !Number.isFinite(Date.parse(parsed.updated_at))) {
|
|
122231
122571
|
throw journalError("source-batch-state-invalid", "Source batch checkpoint progress is invalid.");
|
|
122232
122572
|
}
|
|
@@ -122824,13 +123164,13 @@ init_exitCode();
|
|
|
122824
123164
|
|
|
122825
123165
|
// src/project/wikiDiscovery.ts
|
|
122826
123166
|
import { mkdir as mkdir44 } from "node:fs/promises";
|
|
122827
|
-
import { join as
|
|
123167
|
+
import { join as join140, relative as relative37 } from "node:path";
|
|
122828
123168
|
|
|
122829
123169
|
// src/project/wikiDiscoveryStore.ts
|
|
122830
123170
|
init_atomicWrite();
|
|
122831
123171
|
import { createHash as createHash44, randomUUID as randomUUID9 } from "node:crypto";
|
|
122832
|
-
import { link as link2, lstat as lstat21, mkdir as mkdir43, readFile as
|
|
122833
|
-
import { join as
|
|
123172
|
+
import { link as link2, lstat as lstat21, mkdir as mkdir43, readFile as readFile112, readdir as readdir33, rm as rm33, writeFile as writeFile33 } from "node:fs/promises";
|
|
123173
|
+
import { join as join139, relative as relative36, resolve as resolve46, sep as sep11 } from "node:path";
|
|
122834
123174
|
function wikiDiscoveryDigest(value) {
|
|
122835
123175
|
return createHash44("sha256").update(value).digest("hex");
|
|
122836
123176
|
}
|
|
@@ -122844,7 +123184,7 @@ async function assertWikiDiscoveryPath(root2, path3) {
|
|
|
122844
123184
|
throw new WikiDiscoveryError("unsafe-checkpoint-path", false, "Discovery checkpoint must stay inside its workspace");
|
|
122845
123185
|
let current3 = base;
|
|
122846
123186
|
for (const part of parts) {
|
|
122847
|
-
current3 =
|
|
123187
|
+
current3 = join139(current3, part);
|
|
122848
123188
|
try {
|
|
122849
123189
|
if ((await lstat21(current3)).isSymbolicLink()) {
|
|
122850
123190
|
throw new WikiDiscoveryError("unsafe-checkpoint-path", false, "Discovery checkpoint paths must not contain symbolic links");
|
|
@@ -122860,7 +123200,7 @@ async function readWikiDiscoveryJson(path3) {
|
|
|
122860
123200
|
try {
|
|
122861
123201
|
if ((await lstat21(path3)).isSymbolicLink())
|
|
122862
123202
|
throw new WikiDiscoveryError("unsafe-checkpoint-path", false, "Discovery checkpoint must not be a symbolic link");
|
|
122863
|
-
return JSON.parse(await
|
|
123203
|
+
return JSON.parse(await readFile112(path3, "utf8"));
|
|
122864
123204
|
} catch (error) {
|
|
122865
123205
|
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT")
|
|
122866
123206
|
return;
|
|
@@ -122873,12 +123213,12 @@ async function saveWikiDiscoveryJson(path3, value) {
|
|
|
122873
123213
|
}
|
|
122874
123214
|
async function loadWikiDiscoveryReceipts(directory) {
|
|
122875
123215
|
const result = new Map;
|
|
122876
|
-
await assertWikiDiscoveryPath(directory,
|
|
122877
|
-
await mkdir43(
|
|
122878
|
-
for (const file of await
|
|
123216
|
+
await assertWikiDiscoveryPath(directory, join139(directory, "pages"));
|
|
123217
|
+
await mkdir43(join139(directory, "pages"), { recursive: true });
|
|
123218
|
+
for (const file of await readdir33(join139(directory, "pages"))) {
|
|
122879
123219
|
if (!/^[a-f0-9]{64}\.json$/u.test(file))
|
|
122880
123220
|
continue;
|
|
122881
|
-
const value = await readWikiDiscoveryJson(
|
|
123221
|
+
const value = await readWikiDiscoveryJson(join139(directory, "pages", file));
|
|
122882
123222
|
if (!value || typeof value.parent_node_token !== "string" || value.page_token !== undefined && typeof value.page_token !== "string" || !["completed", "failed"].includes(value.status) || value.status === "completed" && (!value.page || !Array.isArray(value.page.nodes) || value.page.next_page_token !== undefined && typeof value.page.next_page_token !== "string") || value.status === "failed" && (!value.failure || typeof value.failure.retryable !== "boolean" || typeof value.failure.reason !== "string" || typeof value.failure.message !== "string") || `${wikiDiscoveryPageKey(value)}.json` !== file) {
|
|
122883
123223
|
throw new WikiDiscoveryError("checkpoint-invalid", false, "Discovery page checkpoint is invalid; preserve it for inspection");
|
|
122884
123224
|
}
|
|
@@ -122897,14 +123237,14 @@ function ownerRunning(pid) {
|
|
|
122897
123237
|
}
|
|
122898
123238
|
}
|
|
122899
123239
|
async function acquireWikiDiscoveryLease(directory) {
|
|
122900
|
-
const leases =
|
|
123240
|
+
const leases = join139(directory, "leases");
|
|
122901
123241
|
await assertWikiDiscoveryPath(directory, leases);
|
|
122902
123242
|
await mkdir43(leases, { recursive: true });
|
|
122903
123243
|
for (let attempt = 0;attempt < 8; attempt++) {
|
|
122904
|
-
const files = (await
|
|
123244
|
+
const files = (await readdir33(leases)).filter((file) => /^\d{12}\.json$/u.test(file)).sort();
|
|
122905
123245
|
const latest = files.at(-1);
|
|
122906
123246
|
if (latest) {
|
|
122907
|
-
const current3 = await readWikiDiscoveryJson(
|
|
123247
|
+
const current3 = await readWikiDiscoveryJson(join139(leases, latest));
|
|
122908
123248
|
if (!current3 || !Number.isSafeInteger(current3.pid) || current3.pid <= 0 || typeof current3.token !== "string" || typeof current3.released !== "boolean") {
|
|
122909
123249
|
throw new WikiDiscoveryError("checkpoint-invalid", false, "Discovery lease is invalid; preserve it for inspection");
|
|
122910
123250
|
}
|
|
@@ -122913,9 +123253,9 @@ async function acquireWikiDiscoveryLease(directory) {
|
|
|
122913
123253
|
}
|
|
122914
123254
|
}
|
|
122915
123255
|
const sequence = latest ? Number(latest.slice(0, 12)) + 1 : 1;
|
|
122916
|
-
const path3 =
|
|
123256
|
+
const path3 = join139(leases, `${String(sequence).padStart(12, "0")}.json`);
|
|
122917
123257
|
const owner = { pid: process.pid, token: randomUUID9(), released: false };
|
|
122918
|
-
const temporary =
|
|
123258
|
+
const temporary = join139(leases, `.lease-${owner.token}`);
|
|
122919
123259
|
await writeFile33(temporary, JSON.stringify(owner), { flag: "wx", mode: 384 });
|
|
122920
123260
|
try {
|
|
122921
123261
|
await link2(temporary, path3);
|
|
@@ -122924,7 +123264,7 @@ async function acquireWikiDiscoveryLease(directory) {
|
|
|
122924
123264
|
continue;
|
|
122925
123265
|
throw error;
|
|
122926
123266
|
} finally {
|
|
122927
|
-
await
|
|
123267
|
+
await rm33(temporary, { force: true });
|
|
122928
123268
|
}
|
|
122929
123269
|
return async () => {
|
|
122930
123270
|
await saveWikiDiscoveryJson(path3, { ...owner, released: true });
|
|
@@ -123040,7 +123380,7 @@ async function discoverLarkWiki(input) {
|
|
|
123040
123380
|
throw new WikiDiscoveryError("invalid-concurrency", false, "Wiki concurrency must be an integer from 1 to 4");
|
|
123041
123381
|
}
|
|
123042
123382
|
const jobId = wikiDiscoveryDigest(url);
|
|
123043
|
-
const directory =
|
|
123383
|
+
const directory = join140(input.projectRoot, ".tmp", "context-runtime", "wiki-discovery", jobId);
|
|
123044
123384
|
await assertWikiDiscoveryPath(input.projectRoot, directory);
|
|
123045
123385
|
await mkdir44(directory, { recursive: true });
|
|
123046
123386
|
const release = await acquireWikiDiscoveryLease(directory);
|
|
@@ -123052,7 +123392,7 @@ async function discoverLarkWiki(input) {
|
|
|
123052
123392
|
}
|
|
123053
123393
|
async function runDiscovery(input, job) {
|
|
123054
123394
|
const { directory, url, identity: identity2 } = job;
|
|
123055
|
-
const metadataPath =
|
|
123395
|
+
const metadataPath = join140(directory, "job.json");
|
|
123056
123396
|
let metadata = await readWikiDiscoveryJson(metadataPath);
|
|
123057
123397
|
if (metadata && (metadata.protocol !== "context.wiki-discovery.v1" || metadata.url !== url || metadata.identity !== identity2)) {
|
|
123058
123398
|
throw new WikiDiscoveryError("job-identity-mismatch", false, "Resume must preserve the discovery's original URL and identity");
|
|
@@ -123101,7 +123441,7 @@ async function runDiscovery(input, job) {
|
|
|
123101
123441
|
}
|
|
123102
123442
|
const key = wikiDiscoveryPageKey(cursor);
|
|
123103
123443
|
try {
|
|
123104
|
-
await saveWikiDiscoveryJson(
|
|
123444
|
+
await saveWikiDiscoveryJson(join140(directory, "pages", `${key}.json`), receipt2);
|
|
123105
123445
|
receipts.set(key, receipt2);
|
|
123106
123446
|
} catch {
|
|
123107
123447
|
checkpointError = "A discovery page could not be checkpointed; saved pages remain reusable and unsaved pages must be requested again";
|
|
@@ -123119,7 +123459,7 @@ async function finishDiscovery(input, state) {
|
|
|
123119
123459
|
const { directory, url, identity: identity2, jobId, metadata, view } = state;
|
|
123120
123460
|
let checkpointError = state.checkpointError;
|
|
123121
123461
|
let status = input.signal?.aborted ? "paused" : checkpointError || view.pending.length || view.failed.length || !metadata.root ? "partial" : "completed";
|
|
123122
|
-
const manifestPath =
|
|
123462
|
+
const manifestPath = join140(directory, "manifest.json");
|
|
123123
123463
|
try {
|
|
123124
123464
|
await saveWikiDiscoveryJson(manifestPath, {
|
|
123125
123465
|
protocol: "context.wiki-discovery.manifest.v1",
|
|
@@ -123299,8 +123639,8 @@ init_writeLock();
|
|
|
123299
123639
|
var import_yaml63 = __toESM(require_dist(), 1);
|
|
123300
123640
|
import { existsSync as existsSync36 } from "node:fs";
|
|
123301
123641
|
import { createHash as createHash45 } from "node:crypto";
|
|
123302
|
-
import { readFile as
|
|
123303
|
-
import { isAbsolute as isAbsolute25, join as
|
|
123642
|
+
import { readFile as readFile113, readdir as readdir34, rm as rm34 } from "node:fs/promises";
|
|
123643
|
+
import { isAbsolute as isAbsolute25, join as join141, relative as relative38, resolve as resolve47, sep as sep12 } from "node:path";
|
|
123304
123644
|
function sourceIdentity(source2) {
|
|
123305
123645
|
if (source2.kind === "source.collection")
|
|
123306
123646
|
return;
|
|
@@ -123332,10 +123672,10 @@ function collectStrings(value, output) {
|
|
|
123332
123672
|
}
|
|
123333
123673
|
}
|
|
123334
123674
|
async function yamlReferences(input) {
|
|
123335
|
-
const absolutePath =
|
|
123675
|
+
const absolutePath = join141(input.projectRoot, input.path);
|
|
123336
123676
|
if (!existsSync36(absolutePath))
|
|
123337
123677
|
return false;
|
|
123338
|
-
const parsed = import_yaml63.default.parse(await
|
|
123678
|
+
const parsed = import_yaml63.default.parse(await readFile113(absolutePath, "utf8"));
|
|
123339
123679
|
const strings = [];
|
|
123340
123680
|
collectStrings(parsed, strings);
|
|
123341
123681
|
return strings.some((value) => stringReferencesSource(value, input.source));
|
|
@@ -123481,8 +123821,8 @@ async function registryRemovalWrite(projectRoot2, source2) {
|
|
|
123481
123821
|
const path3 = registryPath2(source2.type);
|
|
123482
123822
|
if (path3 === null)
|
|
123483
123823
|
return;
|
|
123484
|
-
const absolutePath =
|
|
123485
|
-
const document4 = existsSync36(absolutePath) ? import_yaml63.default.parse(await
|
|
123824
|
+
const absolutePath = join141(projectRoot2, path3);
|
|
123825
|
+
const document4 = existsSync36(absolutePath) ? import_yaml63.default.parse(await readFile113(absolutePath, "utf8")) : { sources: [] };
|
|
123486
123826
|
return {
|
|
123487
123827
|
path: absolutePath,
|
|
123488
123828
|
bytes: import_yaml63.default.stringify(removeDocumentEntry(document4, source2))
|
|
@@ -123500,7 +123840,7 @@ function safeManagedMaterializedPath(projectRoot2, source2) {
|
|
|
123500
123840
|
return absolute;
|
|
123501
123841
|
}
|
|
123502
123842
|
function safeManagedManifestPath(projectRoot2, source2) {
|
|
123503
|
-
const manifest = source2.manifest ??
|
|
123843
|
+
const manifest = source2.manifest ?? join141(source2.materializedAt, "manifest.json");
|
|
123504
123844
|
if (isAbsolute25(manifest))
|
|
123505
123845
|
throw unsafeOwnership(source2, manifest);
|
|
123506
123846
|
const absolute = resolve47(projectRoot2, manifest);
|
|
@@ -123629,7 +123969,7 @@ async function createRemovalPlan(projectRoot2, selector) {
|
|
|
123629
123969
|
source: source2,
|
|
123630
123970
|
registry: registryPath2(source2.type),
|
|
123631
123971
|
registryBytes: registryWrite?.bytes ?? null,
|
|
123632
|
-
managedBytes: source2.type === "note" || source2.type === "sessions" ? await
|
|
123972
|
+
managedBytes: source2.type === "note" || source2.type === "sessions" ? await readFile113(absoluteRemovals[0], "utf8") : null,
|
|
123633
123973
|
references,
|
|
123634
123974
|
cleanup,
|
|
123635
123975
|
manifestBytes: manifestWrite?.bytes ?? null
|
|
@@ -123662,10 +124002,10 @@ function publicRemovalResult(plan, action) {
|
|
|
123662
124002
|
};
|
|
123663
124003
|
}
|
|
123664
124004
|
async function pruneExtractRuntime(projectRoot2, source2) {
|
|
123665
|
-
const fingerprintPath =
|
|
124005
|
+
const fingerprintPath = join141(projectRoot2, ".tmp/context-runtime/extract/source-fingerprints.json");
|
|
123666
124006
|
const removedPhaseIds = new Set;
|
|
123667
124007
|
if (existsSync36(fingerprintPath)) {
|
|
123668
|
-
const parsed = JSON.parse(await
|
|
124008
|
+
const parsed = JSON.parse(await readFile113(fingerprintPath, "utf8"));
|
|
123669
124009
|
const phases = parsed.phases ?? {};
|
|
123670
124010
|
const next2 = Object.fromEntries(Object.entries(phases).filter(([phaseId, raw]) => {
|
|
123671
124011
|
if (raw === null || typeof raw !== "object" || Array.isArray(raw))
|
|
@@ -123679,27 +124019,27 @@ async function pruneExtractRuntime(projectRoot2, source2) {
|
|
|
123679
124019
|
await atomicWriteFile(fingerprintPath, `${JSON.stringify({ ...parsed, phases: next2 }, null, 2)}
|
|
123680
124020
|
`);
|
|
123681
124021
|
}
|
|
123682
|
-
const phaseOwnershipPath =
|
|
124022
|
+
const phaseOwnershipPath = join141(projectRoot2, ".tmp/context-runtime/extract/custom-phase-candidates.json");
|
|
123683
124023
|
if (existsSync36(phaseOwnershipPath) && removedPhaseIds.size > 0) {
|
|
123684
|
-
const parsed = JSON.parse(await
|
|
124024
|
+
const parsed = JSON.parse(await readFile113(phaseOwnershipPath, "utf8"));
|
|
123685
124025
|
const phases = Object.fromEntries(Object.entries(parsed.phases ?? {}).filter(([phaseId]) => !removedPhaseIds.has(phaseId)));
|
|
123686
124026
|
await atomicWriteFile(phaseOwnershipPath, `${JSON.stringify({ ...parsed, phases }, null, 2)}
|
|
123687
124027
|
`);
|
|
123688
124028
|
}
|
|
123689
|
-
const symbolPath =
|
|
124029
|
+
const symbolPath = join141(projectRoot2, ".tmp/context-runtime/extract/source-symbols.json");
|
|
123690
124030
|
if (existsSync36(symbolPath)) {
|
|
123691
|
-
const parsed = JSON.parse(await
|
|
124031
|
+
const parsed = JSON.parse(await readFile113(symbolPath, "utf8"));
|
|
123692
124032
|
const symbols = Array.isArray(parsed.symbols) ? parsed.symbols.filter((entry) => entry === null || typeof entry !== "object" || Array.isArray(entry) || entry.source !== source2.name) : [];
|
|
123693
124033
|
const phaseFingerprints = Object.fromEntries(Object.entries(parsed.phaseFingerprints ?? {}).filter(([phaseId]) => !removedPhaseIds.has(phaseId)));
|
|
123694
124034
|
await atomicWriteFile(symbolPath, `${JSON.stringify({ ...parsed, phaseFingerprints, symbols }, null, 2)}
|
|
123695
124035
|
`);
|
|
123696
124036
|
}
|
|
123697
|
-
const snapshotRoot =
|
|
124037
|
+
const snapshotRoot = join141(projectRoot2, ".tmp/context-runtime/extract/candidates");
|
|
123698
124038
|
const visit4 = async (directory) => {
|
|
123699
124039
|
if (!existsSync36(directory))
|
|
123700
124040
|
return;
|
|
123701
|
-
for (const entry of await
|
|
123702
|
-
const path3 =
|
|
124041
|
+
for (const entry of await readdir34(directory, { withFileTypes: true })) {
|
|
124042
|
+
const path3 = join141(directory, entry.name);
|
|
123703
124043
|
if (entry.isDirectory()) {
|
|
123704
124044
|
await visit4(path3);
|
|
123705
124045
|
continue;
|
|
@@ -123707,10 +124047,10 @@ async function pruneExtractRuntime(projectRoot2, source2) {
|
|
|
123707
124047
|
if (!entry.isFile() || !entry.name.endsWith(".json"))
|
|
123708
124048
|
continue;
|
|
123709
124049
|
try {
|
|
123710
|
-
const parsed = JSON.parse(await
|
|
124050
|
+
const parsed = JSON.parse(await readFile113(path3, "utf8"));
|
|
123711
124051
|
const refs = Array.isArray(parsed.source_refs) ? parsed.source_refs : [];
|
|
123712
124052
|
if (parsed.source === source2.name || refs.some((ref2) => typeof ref2 === "string" && stringReferencesSource(ref2, source2))) {
|
|
123713
|
-
await
|
|
124053
|
+
await rm34(path3, { force: true });
|
|
123714
124054
|
}
|
|
123715
124055
|
} catch {}
|
|
123716
124056
|
}
|
|
@@ -123749,7 +124089,7 @@ async function removeProjectSource(input) {
|
|
|
123749
124089
|
});
|
|
123750
124090
|
}
|
|
123751
124091
|
await applyAtomicFileBatch({
|
|
123752
|
-
transactionRoot:
|
|
124092
|
+
transactionRoot: join141(input.projectRoot, ".tmp", "context-runtime", "source-remove-transactions"),
|
|
123753
124093
|
writes: [...plan.registryWrite === undefined ? [] : [plan.registryWrite], ...plan.manifestWrite !== undefined ? [plan.manifestWrite] : []],
|
|
123754
124094
|
removals: plan.absoluteRemovals
|
|
123755
124095
|
});
|
|
@@ -123765,7 +124105,7 @@ init_workspace();
|
|
|
123765
124105
|
init_writeLock();
|
|
123766
124106
|
init_durableMultiFileTransaction();
|
|
123767
124107
|
init_durableSingleFileTransaction();
|
|
123768
|
-
import { readFile as
|
|
124108
|
+
import { readFile as readFile114 } from "node:fs/promises";
|
|
123769
124109
|
import ts from "typescript";
|
|
123770
124110
|
function generateSourceConfiguration(text12, selected) {
|
|
123771
124111
|
const file = ts.createSourceFile("index.ts", text12, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
@@ -123905,7 +124245,7 @@ function generateSourceConfiguration(text12, selected) {
|
|
|
123905
124245
|
async function configureRegisteredSources(projectRoot2, selected) {
|
|
123906
124246
|
return withProjectWriteLock(projectRoot2, "source-project-configuration", async () => {
|
|
123907
124247
|
const path3 = "src/index.ts";
|
|
123908
|
-
const config = JSON.parse(await
|
|
124248
|
+
const config = JSON.parse(await readFile114(await safeProjectTarget(projectRoot2, "package.json"), "utf8"));
|
|
123909
124249
|
if (config.context?.entry !== path3)
|
|
123910
124250
|
return {
|
|
123911
124251
|
status: "manual",
|
|
@@ -123914,7 +124254,7 @@ async function configureRegisteredSources(projectRoot2, selected) {
|
|
|
123914
124254
|
sources: selected
|
|
123915
124255
|
};
|
|
123916
124256
|
const target = await safeProjectTarget(projectRoot2, path3);
|
|
123917
|
-
const text12 = await
|
|
124257
|
+
const text12 = await readFile114(target, "utf8");
|
|
123918
124258
|
const updated = generateSourceConfiguration(text12, selected);
|
|
123919
124259
|
if (updated === undefined)
|
|
123920
124260
|
return {
|
|
@@ -123950,7 +124290,7 @@ init_sourceInputMutation();
|
|
|
123950
124290
|
init_writeLock();
|
|
123951
124291
|
import { execFile as execFile20 } from "node:child_process";
|
|
123952
124292
|
import { promisify as promisify17 } from "node:util";
|
|
123953
|
-
import { join as
|
|
124293
|
+
import { join as join142 } from "node:path";
|
|
123954
124294
|
var exec6 = promisify17(execFile20);
|
|
123955
124295
|
var requestSchema3 = exports_external.object({ type: exports_external.enum(["file", "lark"]), name: exports_external.string().min(1), commit: exports_external.string().min(1).optional() }).strict();
|
|
123956
124296
|
async function restoreDocumentSnapshot(projectRoot2, value) {
|
|
@@ -124042,8 +124382,8 @@ async function restoreDocumentSnapshot(projectRoot2, value) {
|
|
|
124042
124382
|
const removals = [...previous3?.files ?? [], ...previous3?.assets ?? []].map((file) => `${source2.materializedAt}/${file.path}`).filter((path3) => !selected.files.has(path3) && !renderDocumentManifestFile(next2).includes(path3.slice(source2.materializedAt.length + 1)));
|
|
124043
124383
|
const removalTargets = await Promise.all(removals.map((path3) => safeProjectTarget(projectRoot2, path3)));
|
|
124044
124384
|
await applyAtomicFileBatch({
|
|
124045
|
-
transactionRoot:
|
|
124046
|
-
writes: [...selected.files].map(([path3, bytes]) => ({ path:
|
|
124385
|
+
transactionRoot: join142(projectRoot2, ".tmp/context-runtime/capture-transactions"),
|
|
124386
|
+
writes: [...selected.files].map(([path3, bytes]) => ({ path: join142(projectRoot2, path3), bytes })).concat([
|
|
124047
124387
|
{ path: manifestTarget, bytes: Buffer.from(renderDocumentManifestFile(next2)) }
|
|
124048
124388
|
]),
|
|
124049
124389
|
removals: removalTargets
|
|
@@ -124116,7 +124456,7 @@ async function readIncludeList(projectRoot2, path3) {
|
|
|
124116
124456
|
}
|
|
124117
124457
|
let content3;
|
|
124118
124458
|
try {
|
|
124119
|
-
content3 = await
|
|
124459
|
+
content3 = await readFile118(isAbsolute26(trimmed) ? resolve49(trimmed) : resolve49(projectRoot2, trimmed), "utf8");
|
|
124120
124460
|
} catch (error) {
|
|
124121
124461
|
throw new ContextError(ExitCode.UserError, `cannot read include list: ${trimmed}`, {
|
|
124122
124462
|
category: ErrorCategory.UserInputInvalid,
|
|
@@ -124577,8 +124917,8 @@ init_cliFeedback();
|
|
|
124577
124917
|
init_exitCode();
|
|
124578
124918
|
var import_yaml66 = __toESM(require_dist(), 1);
|
|
124579
124919
|
import { constants as constants6, existsSync as existsSync37 } from "node:fs";
|
|
124580
|
-
import { lstat as lstat22, open as open5, readdir as
|
|
124581
|
-
import { dirname as dirname52, join as
|
|
124920
|
+
import { lstat as lstat22, open as open5, readdir as readdir35 } from "node:fs/promises";
|
|
124921
|
+
import { dirname as dirname52, join as join144, resolve as resolve50 } from "node:path";
|
|
124582
124922
|
import { fileURLToPath as fileURLToPath10 } from "node:url";
|
|
124583
124923
|
function bundledSkillRoot() {
|
|
124584
124924
|
const directory = dirname52(fileURLToPath10(import.meta.url));
|
|
@@ -124605,10 +124945,10 @@ async function listProductionSkills(root2) {
|
|
|
124605
124945
|
}
|
|
124606
124946
|
}
|
|
124607
124947
|
async function readProductionSkills(root2) {
|
|
124608
|
-
const entries2 = (await
|
|
124948
|
+
const entries2 = (await readdir35(root2, { withFileTypes: true })).filter((entry) => entry.isDirectory()).sort((a2, b) => a2.name < b.name ? -1 : a2.name > b.name ? 1 : 0);
|
|
124609
124949
|
const skills = [];
|
|
124610
124950
|
for (const directory of entries2) {
|
|
124611
|
-
const entry =
|
|
124951
|
+
const entry = join144(root2, directory.name, "SKILL.md");
|
|
124612
124952
|
if (!(await lstat22(entry)).isFile())
|
|
124613
124953
|
throw new TypeError(`Skill entry must be a regular file: ${entry}`);
|
|
124614
124954
|
const handle3 = await open5(entry, constants6.O_RDONLY | constants6.O_NOFOLLOW | constants6.O_NONBLOCK);
|
|
@@ -125022,8 +125362,8 @@ init_cliFeedback();
|
|
|
125022
125362
|
init_errors3();
|
|
125023
125363
|
init_exitCode();
|
|
125024
125364
|
import { createHash as createHash46 } from "node:crypto";
|
|
125025
|
-
import { cp as cp3, lstat as lstat23, mkdir as mkdir45, mkdtemp as mkdtemp7, readFile as
|
|
125026
|
-
import { dirname as dirname54, join as
|
|
125365
|
+
import { cp as cp3, lstat as lstat23, mkdir as mkdir45, mkdtemp as mkdtemp7, readFile as readFile119, readdir as readdir36, rename as rename12, rm as rm35, writeFile as writeFile34 } from "node:fs/promises";
|
|
125366
|
+
import { dirname as dirname54, join as join145, resolve as resolve52 } from "node:path";
|
|
125027
125367
|
var MARKER = ".context-skill-install.json";
|
|
125028
125368
|
function conflict(path3) {
|
|
125029
125369
|
throw new ContextError(ExitCode.UserError, `Local skill install conflict: ${path3}`, {
|
|
@@ -125051,10 +125391,10 @@ async function checkParents(path3) {
|
|
|
125051
125391
|
async function digest9(root2) {
|
|
125052
125392
|
const hash5 = createHash46("sha256");
|
|
125053
125393
|
async function visit4(dir, prefix) {
|
|
125054
|
-
for (const name3 of (await
|
|
125394
|
+
for (const name3 of (await readdir36(dir)).sort()) {
|
|
125055
125395
|
if (!prefix && name3 === MARKER)
|
|
125056
125396
|
continue;
|
|
125057
|
-
const path3 =
|
|
125397
|
+
const path3 = join145(dir, name3);
|
|
125058
125398
|
const entry = await lstat23(path3);
|
|
125059
125399
|
if (entry.isSymbolicLink())
|
|
125060
125400
|
conflict(path3);
|
|
@@ -125062,7 +125402,7 @@ async function digest9(root2) {
|
|
|
125062
125402
|
if (entry.isDirectory())
|
|
125063
125403
|
await visit4(path3, `${prefix}${name3}/`);
|
|
125064
125404
|
else if (entry.isFile())
|
|
125065
|
-
hash5.update(await
|
|
125405
|
+
hash5.update(await readFile119(path3));
|
|
125066
125406
|
else
|
|
125067
125407
|
conflict(path3);
|
|
125068
125408
|
}
|
|
@@ -125073,12 +125413,12 @@ async function digest9(root2) {
|
|
|
125073
125413
|
async function assertOwnedDirectory(target, existing) {
|
|
125074
125414
|
if (!existing.isDirectory() || existing.isSymbolicLink())
|
|
125075
125415
|
conflict(target);
|
|
125076
|
-
const markerPath =
|
|
125416
|
+
const markerPath = join145(target, MARKER);
|
|
125077
125417
|
if (!(await stat11(markerPath))?.isFile())
|
|
125078
125418
|
conflict(target);
|
|
125079
125419
|
let marker;
|
|
125080
125420
|
try {
|
|
125081
|
-
marker = JSON.parse(await
|
|
125421
|
+
marker = JSON.parse(await readFile119(markerPath, "utf8"));
|
|
125082
125422
|
} catch {
|
|
125083
125423
|
conflict(target);
|
|
125084
125424
|
}
|
|
@@ -125089,24 +125429,24 @@ async function installLocalSkills(root2, path3, dryRun, agent) {
|
|
|
125089
125429
|
if (!path3.trim())
|
|
125090
125430
|
conflict("--local requires a non-empty path");
|
|
125091
125431
|
const targetRoot = resolve52(path3);
|
|
125092
|
-
const skillsRoot =
|
|
125432
|
+
const skillsRoot = join145(targetRoot, "skills");
|
|
125093
125433
|
await checkParents(skillsRoot);
|
|
125094
|
-
const sourceRoot =
|
|
125434
|
+
const sourceRoot = join145(root2, "skills");
|
|
125095
125435
|
const commandPlans = [];
|
|
125096
125436
|
const commandEntries = new Set;
|
|
125097
125437
|
if (agent === "claude" || agent === "cursor") {
|
|
125098
|
-
for (const name3 of await
|
|
125438
|
+
for (const name3 of await readdir36(join145(root2, "claude", "commands"))) {
|
|
125099
125439
|
if (name3.endsWith(".md"))
|
|
125100
125440
|
commandEntries.add(name3.slice(0, -3));
|
|
125101
125441
|
}
|
|
125102
|
-
const commandsRoot =
|
|
125442
|
+
const commandsRoot = join145(targetRoot, "commands");
|
|
125103
125443
|
await checkParents(commandsRoot);
|
|
125104
|
-
for (const entry of await
|
|
125444
|
+
for (const entry of await readdir36(join145(root2, agent, "commands"), { withFileTypes: true })) {
|
|
125105
125445
|
if (!entry.isFile() || !entry.name.endsWith(".md"))
|
|
125106
125446
|
continue;
|
|
125107
|
-
const content3 = await
|
|
125108
|
-
const target =
|
|
125109
|
-
const marker =
|
|
125447
|
+
const content3 = await readFile119(join145(root2, agent, "commands", entry.name), "utf8");
|
|
125448
|
+
const target = join145(commandsRoot, entry.name);
|
|
125449
|
+
const marker = join145(commandsRoot, `.context-${entry.name}.json`);
|
|
125110
125450
|
for (const file of [target, marker]) {
|
|
125111
125451
|
const existing = await stat11(file);
|
|
125112
125452
|
if (existing && (!existing.isFile() || existing.isSymbolicLink()))
|
|
@@ -125115,11 +125455,11 @@ async function installLocalSkills(root2, path3, dryRun, agent) {
|
|
|
125115
125455
|
if (await stat11(target)) {
|
|
125116
125456
|
let previous3;
|
|
125117
125457
|
try {
|
|
125118
|
-
previous3 = JSON.parse(await
|
|
125458
|
+
previous3 = JSON.parse(await readFile119(marker, "utf8"));
|
|
125119
125459
|
} catch {
|
|
125120
125460
|
conflict(target);
|
|
125121
125461
|
}
|
|
125122
|
-
const current3 = createHash46("sha256").update(await
|
|
125462
|
+
const current3 = createHash46("sha256").update(await readFile119(target)).digest("hex");
|
|
125123
125463
|
if (previous3?.owner !== "context-plugin-local" || previous3.digest !== current3)
|
|
125124
125464
|
conflict(target);
|
|
125125
125465
|
} else if (await stat11(marker))
|
|
@@ -125127,14 +125467,14 @@ async function installLocalSkills(root2, path3, dryRun, agent) {
|
|
|
125127
125467
|
commandPlans.push({ name: entry.name, target, marker, content: content3, hash: createHash46("sha256").update(content3).digest("hex") });
|
|
125128
125468
|
}
|
|
125129
125469
|
if (!commandPlans.length)
|
|
125130
|
-
conflict(
|
|
125470
|
+
conflict(join145(root2, agent, "commands"));
|
|
125131
125471
|
}
|
|
125132
125472
|
const plans = [];
|
|
125133
|
-
for (const entry of (await
|
|
125134
|
-
if (!entry.isDirectory() || !await stat11(
|
|
125473
|
+
for (const entry of (await readdir36(sourceRoot, { withFileTypes: true })).sort((a2, b) => a2.name.localeCompare(b.name))) {
|
|
125474
|
+
if (!entry.isDirectory() || !await stat11(join145(sourceRoot, entry.name, "SKILL.md")))
|
|
125135
125475
|
continue;
|
|
125136
|
-
const source2 =
|
|
125137
|
-
const target =
|
|
125476
|
+
const source2 = join145(sourceRoot, entry.name);
|
|
125477
|
+
const target = join145(skillsRoot, entry.name);
|
|
125138
125478
|
if (commandEntries.has(entry.name) && !["context-plan", "context-repo-content"].includes(entry.name)) {
|
|
125139
125479
|
if (await stat11(target))
|
|
125140
125480
|
conflict(`${target} (use a fresh host directory to avoid duplicate command/skill entries)`);
|
|
@@ -125148,16 +125488,16 @@ async function installLocalSkills(root2, path3, dryRun, agent) {
|
|
|
125148
125488
|
if (!plans.length)
|
|
125149
125489
|
conflict(sourceRoot);
|
|
125150
125490
|
const resourcePlans = [];
|
|
125151
|
-
const resourcesRoot =
|
|
125491
|
+
const resourcesRoot = join145(targetRoot, "resources");
|
|
125152
125492
|
if (agent === "claude" || agent === "cursor") {
|
|
125153
|
-
const resourceSource =
|
|
125493
|
+
const resourceSource = join145(root2, agent, "resources");
|
|
125154
125494
|
if (await stat11(resourceSource)) {
|
|
125155
125495
|
await checkParents(resourcesRoot);
|
|
125156
|
-
for (const entry of (await
|
|
125496
|
+
for (const entry of (await readdir36(resourceSource, { withFileTypes: true })).sort((a2, b) => a2.name.localeCompare(b.name))) {
|
|
125157
125497
|
if (!entry.isDirectory())
|
|
125158
125498
|
continue;
|
|
125159
|
-
const source2 =
|
|
125160
|
-
const target =
|
|
125499
|
+
const source2 = join145(resourceSource, entry.name);
|
|
125500
|
+
const target = join145(resourcesRoot, entry.name);
|
|
125161
125501
|
const existing = await stat11(target);
|
|
125162
125502
|
if (existing)
|
|
125163
125503
|
await assertOwnedDirectory(target, existing);
|
|
@@ -125171,15 +125511,15 @@ async function installLocalSkills(root2, path3, dryRun, agent) {
|
|
|
125171
125511
|
await mkdir45(resourcesRoot, { recursive: true });
|
|
125172
125512
|
for (const plan of [...plans, ...resourcePlans]) {
|
|
125173
125513
|
const resource = resourcePlans.includes(plan);
|
|
125174
|
-
const staging = await mkdtemp7(
|
|
125175
|
-
const candidate =
|
|
125176
|
-
const previous3 =
|
|
125514
|
+
const staging = await mkdtemp7(join145(dirname54(plan.target), ".context-install-"));
|
|
125515
|
+
const candidate = join145(staging, "candidate");
|
|
125516
|
+
const previous3 = join145(staging, "previous");
|
|
125177
125517
|
let moved = false;
|
|
125178
125518
|
try {
|
|
125179
125519
|
await cp3(plan.source, candidate, { recursive: true });
|
|
125180
125520
|
if (!resource && (agent === "claude" || agent === "cursor" && ["context-plan", "context-repo-content"].includes(plan.name))) {
|
|
125181
|
-
const skillFile =
|
|
125182
|
-
const content3 = await
|
|
125521
|
+
const skillFile = join145(candidate, "SKILL.md");
|
|
125522
|
+
const content3 = await readFile119(skillFile, "utf8");
|
|
125183
125523
|
const parts = /^(---\r?\n)([\s\S]*?)(\r?\n---(?:\r?\n|$))/.exec(content3);
|
|
125184
125524
|
if (parts && (["context-plan", "context-repo-content"].includes(plan.name) || /^\s*context-public-entry:\s*["']?false["']?\s*$/mu.test(parts[2]))) {
|
|
125185
125525
|
const frontmatter2 = parts[2].replace(/^user-invocable:.*\r?\n?/mu, "");
|
|
@@ -125187,7 +125527,7 @@ async function installLocalSkills(root2, path3, dryRun, agent) {
|
|
|
125187
125527
|
${frontmatter2}${parts[3]}${content3.slice(parts[0].length)}`);
|
|
125188
125528
|
}
|
|
125189
125529
|
}
|
|
125190
|
-
await writeFile34(
|
|
125530
|
+
await writeFile34(join145(candidate, MARKER), JSON.stringify({ owner: "context-plugin-local", digest: await digest9(candidate) }) + `
|
|
125191
125531
|
`);
|
|
125192
125532
|
if (plan.exists) {
|
|
125193
125533
|
await rename12(plan.target, previous3);
|
|
@@ -125200,7 +125540,7 @@ ${frontmatter2}${parts[3]}${content3.slice(parts[0].length)}`);
|
|
|
125200
125540
|
await rename12(previous3, plan.target);
|
|
125201
125541
|
throw error;
|
|
125202
125542
|
}
|
|
125203
|
-
await
|
|
125543
|
+
await rm35(staging, { recursive: true, force: true });
|
|
125204
125544
|
} catch (error) {
|
|
125205
125545
|
throw new ContextError(ExitCode.WorkspaceStateError, `Local skill installation failed: ${plan.target}`, {
|
|
125206
125546
|
category: ErrorCategory.WorkspaceStateInvalid,
|
|
@@ -125211,13 +125551,13 @@ ${frontmatter2}${parts[3]}${content3.slice(parts[0].length)}`);
|
|
|
125211
125551
|
}
|
|
125212
125552
|
for (const command3 of commandPlans) {
|
|
125213
125553
|
await mkdir45(dirname54(command3.target), { recursive: true });
|
|
125214
|
-
const staging = await mkdtemp7(
|
|
125215
|
-
await writeFile34(
|
|
125216
|
-
await writeFile34(
|
|
125554
|
+
const staging = await mkdtemp7(join145(dirname54(command3.target), ".context-install-"));
|
|
125555
|
+
await writeFile34(join145(staging, "command"), command3.content);
|
|
125556
|
+
await writeFile34(join145(staging, "marker"), JSON.stringify({ owner: "context-plugin-local", digest: command3.hash }) + `
|
|
125217
125557
|
`);
|
|
125218
|
-
await rename12(
|
|
125219
|
-
await rename12(
|
|
125220
|
-
await
|
|
125558
|
+
await rename12(join145(staging, "command"), command3.target);
|
|
125559
|
+
await rename12(join145(staging, "marker"), command3.marker);
|
|
125560
|
+
await rm35(staging, { recursive: true, force: true });
|
|
125221
125561
|
}
|
|
125222
125562
|
}
|
|
125223
125563
|
return formatFeedback({
|
|
@@ -125241,10 +125581,10 @@ init_cliFeedback();
|
|
|
125241
125581
|
init_errors3();
|
|
125242
125582
|
init_exitCode();
|
|
125243
125583
|
import { lstat as lstat24 } from "node:fs/promises";
|
|
125244
|
-
import { join as
|
|
125584
|
+
import { join as join146, resolve as resolve53 } from "node:path";
|
|
125245
125585
|
var HOST_DIRS = { claude: ".claude", cursor: ".cursor", codex: ".agents" };
|
|
125246
125586
|
async function detectLocalAgent(agent, repo) {
|
|
125247
|
-
const path3 =
|
|
125587
|
+
const path3 = join146(repo, HOST_DIRS[agent]);
|
|
125248
125588
|
try {
|
|
125249
125589
|
const entry = await lstat24(path3);
|
|
125250
125590
|
if (!entry.isDirectory() || entry.isSymbolicLink()) {
|
|
@@ -125269,7 +125609,7 @@ async function installAutoLocalSkills(root2, path3, dryRun, detect = detectLocal
|
|
|
125269
125609
|
if (selectedAgent ? selectedAgent === "all" || agent === selectedAgent : await detect(agent, repo))
|
|
125270
125610
|
agents.push(agent);
|
|
125271
125611
|
}
|
|
125272
|
-
const targets = agents.length ? agents.map((agent) => ({ agent, path:
|
|
125612
|
+
const targets = agents.length ? agents.map((agent) => ({ agent, path: join146(repo, HOST_DIRS[agent]) })) : [{ path: join146(repo, ".agents") }];
|
|
125273
125613
|
const previews = [];
|
|
125274
125614
|
for (const target of targets)
|
|
125275
125615
|
previews.push(await installLocalSkills(root2, target.path, true, target.agent));
|
|
@@ -125302,7 +125642,7 @@ init_cliFeedback();
|
|
|
125302
125642
|
init_errors3();
|
|
125303
125643
|
init_exitCode();
|
|
125304
125644
|
import { existsSync as existsSync40 } from "node:fs";
|
|
125305
|
-
import { dirname as dirname56, join as
|
|
125645
|
+
import { dirname as dirname56, join as join148, resolve as resolve54 } from "node:path";
|
|
125306
125646
|
import { fileURLToPath as fileURLToPath11 } from "node:url";
|
|
125307
125647
|
|
|
125308
125648
|
// src/project/pluginInstallTargets.ts
|
|
@@ -125311,9 +125651,9 @@ init_errors3();
|
|
|
125311
125651
|
init_exitCode();
|
|
125312
125652
|
import { execFile as execFile21 } from "node:child_process";
|
|
125313
125653
|
import { existsSync as existsSync39 } from "node:fs";
|
|
125314
|
-
import { cp as cp4, mkdir as mkdir46, readdir as
|
|
125654
|
+
import { cp as cp4, mkdir as mkdir46, readdir as readdir37, readFile as readFile120, rename as rename13, rm as rm36, writeFile as writeFile35 } from "node:fs/promises";
|
|
125315
125655
|
import { homedir as homedir2 } from "node:os";
|
|
125316
|
-
import { dirname as dirname55, join as
|
|
125656
|
+
import { dirname as dirname55, join as join147 } from "node:path";
|
|
125317
125657
|
import { promisify as promisify18 } from "node:util";
|
|
125318
125658
|
var execFileAsync6 = promisify18(execFile21);
|
|
125319
125659
|
var MARKETPLACE_NAME = "c4a";
|
|
@@ -125367,23 +125707,23 @@ async function claudePluginInstalled(pluginId) {
|
|
|
125367
125707
|
}
|
|
125368
125708
|
}
|
|
125369
125709
|
function codexHome() {
|
|
125370
|
-
return process.env.CODEX_HOME?.trim() ||
|
|
125710
|
+
return process.env.CODEX_HOME?.trim() || join147(homedir2(), ".codex");
|
|
125371
125711
|
}
|
|
125372
125712
|
function claudePluginCacheRoot() {
|
|
125373
125713
|
const explicitRoot = process.env[CLAUDE_PLUGIN_CACHE_ROOT_ENV2]?.trim();
|
|
125374
125714
|
if (explicitRoot)
|
|
125375
125715
|
return explicitRoot;
|
|
125376
125716
|
const home = process.env[CLAUDE_PLUGIN_CACHE_HOME_ENV2]?.trim() || homedir2();
|
|
125377
|
-
return
|
|
125717
|
+
return join147(home, ".claude", "plugins", "cache");
|
|
125378
125718
|
}
|
|
125379
125719
|
function sharedSkillsRoot() {
|
|
125380
|
-
return process.env[SHARED_SKILLS_ROOT_ENV]?.trim() ||
|
|
125720
|
+
return process.env[SHARED_SKILLS_ROOT_ENV]?.trim() || join147(homedir2(), ".agents", "skills");
|
|
125381
125721
|
}
|
|
125382
125722
|
function claudeSkillsRoot() {
|
|
125383
|
-
return process.env[CLAUDE_SKILLS_ROOT_ENV]?.trim() ||
|
|
125723
|
+
return process.env[CLAUDE_SKILLS_ROOT_ENV]?.trim() || join147(homedir2(), ".claude", "skills");
|
|
125384
125724
|
}
|
|
125385
125725
|
function cursorPluginRoot() {
|
|
125386
|
-
return process.env[CURSOR_PLUGIN_ROOT_ENV]?.trim() ||
|
|
125726
|
+
return process.env[CURSOR_PLUGIN_ROOT_ENV]?.trim() || join147(homedir2(), ".cursor", "plugins", "local", PLUGIN_NAME);
|
|
125387
125727
|
}
|
|
125388
125728
|
function blockHeader(line) {
|
|
125389
125729
|
const match = line.match(/^\s*\[([^\]]+)\]\s*$/u);
|
|
@@ -125434,8 +125774,8 @@ function pruneLegacyCodexConfigContent(content3) {
|
|
|
125434
125774
|
`), removed };
|
|
125435
125775
|
}
|
|
125436
125776
|
async function pruneLegacyCodexConfig(dryRun, steps) {
|
|
125437
|
-
const configPath =
|
|
125438
|
-
const current3 = await
|
|
125777
|
+
const configPath = join147(codexHome(), "config.toml");
|
|
125778
|
+
const current3 = await readFile120(configPath, "utf8").catch(() => "");
|
|
125439
125779
|
if (!current3)
|
|
125440
125780
|
return;
|
|
125441
125781
|
const next2 = pruneLegacyCodexConfigContent(current3);
|
|
@@ -125451,10 +125791,10 @@ async function pruneLegacyCodexConfig(dryRun, steps) {
|
|
|
125451
125791
|
}
|
|
125452
125792
|
}
|
|
125453
125793
|
async function pruneCodexPluginCacheForName(pluginName, keepVersion, dryRun, steps) {
|
|
125454
|
-
const cacheRoot =
|
|
125794
|
+
const cacheRoot = join147(codexHome(), "plugins", "cache", MARKETPLACE_NAME, pluginName);
|
|
125455
125795
|
if (!existsSync39(cacheRoot))
|
|
125456
125796
|
return;
|
|
125457
|
-
const versions = (await
|
|
125797
|
+
const versions = (await readdir37(cacheRoot, { withFileTypes: true }).catch(() => [])).filter((entry) => entry.isDirectory() && entry.name !== keepVersion).map((entry) => entry.name).sort();
|
|
125458
125798
|
if (versions.length === 0)
|
|
125459
125799
|
return;
|
|
125460
125800
|
steps.push({
|
|
@@ -125463,7 +125803,7 @@ async function pruneCodexPluginCacheForName(pluginName, keepVersion, dryRun, ste
|
|
|
125463
125803
|
status: dryRun ? "planned" : "ran"
|
|
125464
125804
|
});
|
|
125465
125805
|
if (!dryRun)
|
|
125466
|
-
await Promise.all(versions.map((version3) =>
|
|
125806
|
+
await Promise.all(versions.map((version3) => rm36(join147(cacheRoot, version3), { recursive: true, force: true })));
|
|
125467
125807
|
}
|
|
125468
125808
|
async function pruneCodexPluginCache(currentVersion, dryRun, steps) {
|
|
125469
125809
|
await pruneCodexPluginCacheForName(PLUGIN_NAME, currentVersion, dryRun, steps);
|
|
@@ -125473,7 +125813,7 @@ async function pruneCodexPluginCache(currentVersion, dryRun, steps) {
|
|
|
125473
125813
|
}
|
|
125474
125814
|
async function isEmptyDir2(dir) {
|
|
125475
125815
|
try {
|
|
125476
|
-
return (await
|
|
125816
|
+
return (await readdir37(dir)).length === 0;
|
|
125477
125817
|
} catch {
|
|
125478
125818
|
return false;
|
|
125479
125819
|
}
|
|
@@ -125483,31 +125823,31 @@ async function pruneClaudeOrphanContextCache(dryRun, steps) {
|
|
|
125483
125823
|
if (!existsSync39(cacheRoot))
|
|
125484
125824
|
return;
|
|
125485
125825
|
const removed = [];
|
|
125486
|
-
const marketplaces = await
|
|
125826
|
+
const marketplaces = await readdir37(cacheRoot, { withFileTypes: true }).catch(() => []);
|
|
125487
125827
|
for (const marketplace of marketplaces) {
|
|
125488
125828
|
if (!marketplace.isDirectory())
|
|
125489
125829
|
continue;
|
|
125490
|
-
const pluginDir =
|
|
125830
|
+
const pluginDir = join147(cacheRoot, marketplace.name, PLUGIN_NAME);
|
|
125491
125831
|
if (!existsSync39(pluginDir))
|
|
125492
125832
|
continue;
|
|
125493
|
-
const versions = await
|
|
125833
|
+
const versions = await readdir37(pluginDir, { withFileTypes: true }).catch(() => []);
|
|
125494
125834
|
for (const version3 of versions) {
|
|
125495
125835
|
if (!version3.isDirectory())
|
|
125496
125836
|
continue;
|
|
125497
|
-
const versionDir =
|
|
125498
|
-
if (!existsSync39(
|
|
125837
|
+
const versionDir = join147(pluginDir, version3.name);
|
|
125838
|
+
if (!existsSync39(join147(versionDir, ORPHAN_MARKER2)))
|
|
125499
125839
|
continue;
|
|
125500
125840
|
removed.push(`${marketplace.name}/${PLUGIN_NAME}/${version3.name}`);
|
|
125501
125841
|
if (!dryRun) {
|
|
125502
|
-
await
|
|
125842
|
+
await rm36(versionDir, { recursive: true, force: true });
|
|
125503
125843
|
}
|
|
125504
125844
|
}
|
|
125505
125845
|
if (!dryRun && await isEmptyDir2(pluginDir)) {
|
|
125506
|
-
await
|
|
125846
|
+
await rm36(pluginDir, { recursive: true, force: true });
|
|
125507
125847
|
}
|
|
125508
|
-
const marketplaceDir =
|
|
125848
|
+
const marketplaceDir = join147(cacheRoot, marketplace.name);
|
|
125509
125849
|
if (!dryRun && await isEmptyDir2(marketplaceDir)) {
|
|
125510
|
-
await
|
|
125850
|
+
await rm36(marketplaceDir, { recursive: true, force: true });
|
|
125511
125851
|
}
|
|
125512
125852
|
}
|
|
125513
125853
|
if (removed.length > 0) {
|
|
@@ -125526,12 +125866,12 @@ async function pruneClaudeLegacyPluginCache(dryRun, steps) {
|
|
|
125526
125866
|
return;
|
|
125527
125867
|
const removed = [];
|
|
125528
125868
|
for (const pluginName of LEGACY_PLUGIN_NAMES) {
|
|
125529
|
-
const pluginDir =
|
|
125869
|
+
const pluginDir = join147(cacheRoot, MARKETPLACE_NAME, pluginName);
|
|
125530
125870
|
if (!existsSync39(pluginDir))
|
|
125531
125871
|
continue;
|
|
125532
125872
|
removed.push(`${MARKETPLACE_NAME}/${pluginName}`);
|
|
125533
125873
|
if (!dryRun) {
|
|
125534
|
-
await
|
|
125874
|
+
await rm36(pluginDir, { recursive: true, force: true });
|
|
125535
125875
|
}
|
|
125536
125876
|
}
|
|
125537
125877
|
if (removed.length > 0) {
|
|
@@ -125543,12 +125883,12 @@ async function pruneClaudeLegacyPluginCache(dryRun, steps) {
|
|
|
125543
125883
|
}
|
|
125544
125884
|
}
|
|
125545
125885
|
async function pruneClaudeSupersededContextCache(root2, dryRun, steps) {
|
|
125546
|
-
const manifest = await
|
|
125886
|
+
const manifest = await readFile120(join147(root2, "claude", ".claude-plugin", "plugin.json"), "utf8").then((content3) => JSON.parse(content3)).catch(() => null);
|
|
125547
125887
|
const currentVersion = typeof manifest?.version === "string" ? manifest.version : null;
|
|
125548
125888
|
if (!currentVersion)
|
|
125549
125889
|
return;
|
|
125550
|
-
const pluginDir =
|
|
125551
|
-
const staleVersions = (await
|
|
125890
|
+
const pluginDir = join147(claudePluginCacheRoot(), MARKETPLACE_NAME, PLUGIN_NAME);
|
|
125891
|
+
const staleVersions = (await readdir37(pluginDir, { withFileTypes: true }).catch(() => [])).filter((entry) => entry.isDirectory() && entry.name !== currentVersion).map((entry) => entry.name);
|
|
125552
125892
|
if (staleVersions.length === 0)
|
|
125553
125893
|
return;
|
|
125554
125894
|
steps.push({
|
|
@@ -125557,7 +125897,7 @@ async function pruneClaudeSupersededContextCache(root2, dryRun, steps) {
|
|
|
125557
125897
|
status: dryRun ? "planned" : "ran"
|
|
125558
125898
|
});
|
|
125559
125899
|
if (!dryRun) {
|
|
125560
|
-
await Promise.all(staleVersions.map((version3) =>
|
|
125900
|
+
await Promise.all(staleVersions.map((version3) => rm36(join147(pluginDir, version3), { recursive: true, force: true })));
|
|
125561
125901
|
}
|
|
125562
125902
|
}
|
|
125563
125903
|
function enableCodexPluginConfig(content3) {
|
|
@@ -125621,39 +125961,39 @@ source = ${JSON.stringify(root2)}
|
|
|
125621
125961
|
`;
|
|
125622
125962
|
}
|
|
125623
125963
|
async function ensureCodexPluginEnabled() {
|
|
125624
|
-
const configPath =
|
|
125964
|
+
const configPath = join147(codexHome(), "config.toml");
|
|
125625
125965
|
await mkdir46(dirname55(configPath), { recursive: true });
|
|
125626
|
-
const current3 = await
|
|
125966
|
+
const current3 = await readFile120(configPath, "utf8").catch(() => "");
|
|
125627
125967
|
const next2 = enableCodexPluginConfig(current3);
|
|
125628
125968
|
if (next2 !== current3) {
|
|
125629
125969
|
await writeFile35(configPath, next2, "utf8");
|
|
125630
125970
|
}
|
|
125631
125971
|
}
|
|
125632
125972
|
async function ensureCodexLocalMarketplace(root2) {
|
|
125633
|
-
const configPath =
|
|
125973
|
+
const configPath = join147(codexHome(), "config.toml");
|
|
125634
125974
|
await mkdir46(dirname55(configPath), { recursive: true });
|
|
125635
|
-
const current3 = await
|
|
125975
|
+
const current3 = await readFile120(configPath, "utf8").catch(() => "");
|
|
125636
125976
|
const next2 = upsertCodexLocalMarketplaceConfig(current3, root2);
|
|
125637
125977
|
if (next2 !== current3) {
|
|
125638
125978
|
await writeFile35(configPath, next2, "utf8");
|
|
125639
125979
|
}
|
|
125640
125980
|
}
|
|
125641
125981
|
async function codexPluginVersion(root2) {
|
|
125642
|
-
const manifestPath =
|
|
125643
|
-
const manifest = JSON.parse(await
|
|
125982
|
+
const manifestPath = join147(root2, "codex", ".codex-plugin", "plugin.json");
|
|
125983
|
+
const manifest = JSON.parse(await readFile120(manifestPath, "utf8"));
|
|
125644
125984
|
if (typeof manifest.version !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/u.test(manifest.version)) {
|
|
125645
125985
|
throw new Error(`Codex plugin manifest has an invalid version: ${manifestPath}`);
|
|
125646
125986
|
}
|
|
125647
125987
|
return manifest.version;
|
|
125648
125988
|
}
|
|
125649
125989
|
function codexPluginCacheDir(version3) {
|
|
125650
|
-
return
|
|
125990
|
+
return join147(codexHome(), "plugins", "cache", MARKETPLACE_NAME, PLUGIN_NAME, version3);
|
|
125651
125991
|
}
|
|
125652
125992
|
async function replaceDirectoryFromSource(source2, target) {
|
|
125653
125993
|
await mkdir46(dirname55(target), { recursive: true });
|
|
125654
125994
|
const temporary = `${target}.tmp-${process.pid}-${Date.now()}`;
|
|
125655
125995
|
const previous3 = `${target}.previous-${process.pid}-${Date.now()}`;
|
|
125656
|
-
await
|
|
125996
|
+
await rm36(temporary, { recursive: true, force: true });
|
|
125657
125997
|
await cp4(source2, temporary, { recursive: true, force: true });
|
|
125658
125998
|
const hadPrevious = existsSync39(target);
|
|
125659
125999
|
try {
|
|
@@ -125661,16 +126001,16 @@ async function replaceDirectoryFromSource(source2, target) {
|
|
|
125661
126001
|
await rename13(target, previous3);
|
|
125662
126002
|
await rename13(temporary, target);
|
|
125663
126003
|
if (hadPrevious)
|
|
125664
|
-
await
|
|
126004
|
+
await rm36(previous3, { recursive: true, force: true });
|
|
125665
126005
|
} catch (error) {
|
|
125666
|
-
await
|
|
126006
|
+
await rm36(temporary, { recursive: true, force: true });
|
|
125667
126007
|
if (hadPrevious && !existsSync39(target) && existsSync39(previous3))
|
|
125668
126008
|
await rename13(previous3, target);
|
|
125669
126009
|
throw error;
|
|
125670
126010
|
}
|
|
125671
126011
|
}
|
|
125672
126012
|
async function materializeCodexPluginCache(root2, version3, dryRun, steps) {
|
|
125673
|
-
const source2 =
|
|
126013
|
+
const source2 = join147(root2, "codex");
|
|
125674
126014
|
const target = codexPluginCacheDir(version3);
|
|
125675
126015
|
steps.push({
|
|
125676
126016
|
agent: "codex",
|
|
@@ -125682,16 +126022,16 @@ async function materializeCodexPluginCache(root2, version3, dryRun, steps) {
|
|
|
125682
126022
|
await replaceDirectoryFromSource(source2, target);
|
|
125683
126023
|
}
|
|
125684
126024
|
async function bundledProviderSkillNames(root2) {
|
|
125685
|
-
const skillsRoot =
|
|
125686
|
-
const entries2 = await
|
|
126025
|
+
const skillsRoot = join147(root2, "skills");
|
|
126026
|
+
const entries2 = await readdir37(skillsRoot, { withFileTypes: true });
|
|
125687
126027
|
const names = [];
|
|
125688
126028
|
for (const entry of entries2) {
|
|
125689
126029
|
if (!entry.isDirectory() || entry.name === "context")
|
|
125690
126030
|
continue;
|
|
125691
|
-
const skillPath =
|
|
126031
|
+
const skillPath = join147(skillsRoot, entry.name, "SKILL.md");
|
|
125692
126032
|
if (!existsSync39(skillPath))
|
|
125693
126033
|
continue;
|
|
125694
|
-
const skill = await
|
|
126034
|
+
const skill = await readFile120(skillPath, "utf8");
|
|
125695
126035
|
if (!/^\s*context-role:\s*["']?indexer-provider["']?\s*$/mu.test(skill))
|
|
125696
126036
|
continue;
|
|
125697
126037
|
names.push(entry.name);
|
|
@@ -125703,10 +126043,10 @@ async function bundledProviderSkillNames(root2) {
|
|
|
125703
126043
|
return names;
|
|
125704
126044
|
}
|
|
125705
126045
|
async function materializeProviderSkills(root2, targetRoot, agent, dryRun, steps) {
|
|
125706
|
-
const sourceRoot =
|
|
126046
|
+
const sourceRoot = join147(root2, "skills");
|
|
125707
126047
|
for (const name3 of await bundledProviderSkillNames(root2)) {
|
|
125708
|
-
const source2 =
|
|
125709
|
-
const target =
|
|
126048
|
+
const source2 = join147(sourceRoot, name3);
|
|
126049
|
+
const target = join147(targetRoot, name3);
|
|
125710
126050
|
steps.push({
|
|
125711
126051
|
agent,
|
|
125712
126052
|
command: `materialize lifecycle Provider skill: ${shellQuote8(source2)} -> ${shellQuote8(target)}`,
|
|
@@ -125717,7 +126057,7 @@ async function materializeProviderSkills(root2, targetRoot, agent, dryRun, steps
|
|
|
125717
126057
|
}
|
|
125718
126058
|
}
|
|
125719
126059
|
async function installCursor(root2, dryRun, steps) {
|
|
125720
|
-
const source2 =
|
|
126060
|
+
const source2 = join147(root2, "cursor");
|
|
125721
126061
|
const target = cursorPluginRoot();
|
|
125722
126062
|
steps.push({
|
|
125723
126063
|
agent: "cursor",
|
|
@@ -125772,12 +126112,12 @@ async function installCodex(root2, dryRun, steps) {
|
|
|
125772
126112
|
steps.push({ agent: "codex", command: commandLine("codex", addArgs), status: dryRun ? "planned" : "ran" });
|
|
125773
126113
|
steps.push({
|
|
125774
126114
|
agent: "codex",
|
|
125775
|
-
command: `ensure ${shellQuote8(
|
|
126115
|
+
command: `ensure ${shellQuote8(join147(codexHome(), "config.toml"))} registers local marketplace ${shellQuote8(MARKETPLACE_NAME)}`,
|
|
125776
126116
|
status: dryRun ? "planned" : "ran"
|
|
125777
126117
|
});
|
|
125778
126118
|
steps.push({
|
|
125779
126119
|
agent: "codex",
|
|
125780
|
-
command: `ensure ${shellQuote8(
|
|
126120
|
+
command: `ensure ${shellQuote8(join147(codexHome(), "config.toml"))} enables ${shellQuote8(PLUGIN_ID)}`,
|
|
125781
126121
|
status: dryRun ? "planned" : "ran"
|
|
125782
126122
|
});
|
|
125783
126123
|
if (dryRun) {
|
|
@@ -125832,13 +126172,13 @@ function pluginRootCandidates() {
|
|
|
125832
126172
|
return [resolve54(envRoot)];
|
|
125833
126173
|
const candidates = [];
|
|
125834
126174
|
for (const dir of packageCandidateDirs()) {
|
|
125835
|
-
candidates.push(
|
|
125836
|
-
candidates.push(
|
|
126175
|
+
candidates.push(join148(dir, "plugins"));
|
|
126176
|
+
candidates.push(join148(dir, "dist", "plugins"));
|
|
125837
126177
|
}
|
|
125838
126178
|
return [...new Set(candidates)];
|
|
125839
126179
|
}
|
|
125840
126180
|
function isInstallablePluginRoot(root2) {
|
|
125841
|
-
return existsSync40(
|
|
126181
|
+
return existsSync40(join148(root2, ".claude-plugin", "marketplace.json")) && existsSync40(join148(root2, ".agents", "plugins", "marketplace.json")) && existsSync40(join148(root2, "claude", ".claude-plugin", "plugin.json")) && existsSync40(join148(root2, "codex", ".codex-plugin", "plugin.json")) && existsSync40(join148(root2, "cursor", ".cursor-plugin", "plugin.json")) && existsSync40(join148(root2, "skills"));
|
|
125842
126182
|
}
|
|
125843
126183
|
function resolveBundledPluginsRoot() {
|
|
125844
126184
|
const candidates = pluginRootCandidates();
|
|
@@ -126104,10 +126444,10 @@ function readQuickstartPath() {
|
|
|
126104
126444
|
try {
|
|
126105
126445
|
let dir = dirname57(fileURLToPath12(import.meta.url));
|
|
126106
126446
|
for (let i2 = 0;i2 < 8; i2++) {
|
|
126107
|
-
const candidate =
|
|
126447
|
+
const candidate = join149(dir, "docs", "quickstart.md");
|
|
126108
126448
|
if (existsSync41(candidate))
|
|
126109
126449
|
return candidate;
|
|
126110
|
-
const pkg =
|
|
126450
|
+
const pkg = join149(dir, "package.json");
|
|
126111
126451
|
if (existsSync41(pkg))
|
|
126112
126452
|
return candidate;
|
|
126113
126453
|
const parent2 = dirname57(dir);
|
|
@@ -126116,7 +126456,7 @@ function readQuickstartPath() {
|
|
|
126116
126456
|
dir = parent2;
|
|
126117
126457
|
}
|
|
126118
126458
|
} catch {}
|
|
126119
|
-
return
|
|
126459
|
+
return join149(dirname57(fileURLToPath12(import.meta.url)), "docs", "quickstart.md");
|
|
126120
126460
|
}
|
|
126121
126461
|
var GREEN = "\x1B[32m";
|
|
126122
126462
|
var RESET = "\x1B[0m";
|