@c4a/context-cli 0.7.101 → 0.7.103
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 +774 -563
- package/indexers/contracts/profile-contract.json +245 -245
- package/indexers/release-manifest.json +1 -1
- package/package.json +12 -12
- package/plugins/VERSION +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/commands/context.md +8 -2
- package/plugins/claude/resources/context/routine-update.md +2 -1
- package/plugins/claude/resources/context/version-alignment.md +9 -4
- package/plugins/claude/skills/context-plan/references/knowledge-migration.md +1 -1
- package/plugins/codex/.codex-plugin/plugin.json +2 -2
- package/plugins/codex/skills/context/SKILL.md +8 -2
- package/plugins/codex/skills/context/references/routine-update.md +2 -1
- package/plugins/codex/skills/context/references/version-alignment.md +9 -4
- package/plugins/codex/skills/context-plan/references/knowledge-migration.md +1 -1
- package/plugins/cursor/.cursor-plugin/plugin.json +1 -1
- package/plugins/cursor/commands/c4a-context.md +8 -2
- package/plugins/cursor/resources/context/routine-update.md +2 -1
- package/plugins/cursor/resources/context/version-alignment.md +9 -4
- package/plugins/cursor/skills/context-plan/references/knowledge-migration.md +1 -1
- package/plugins/skills/context/SKILL.md +8 -2
- package/plugins/skills/context/references/routine-update.md +2 -1
- package/plugins/skills/context/references/version-alignment.md +9 -4
- package/plugins/skills/context-plan/references/knowledge-migration.md +1 -1
- package/providers/context/manifest.json +11 -11
- package/providers/context/provider.yaml +1 -1
- package/providers/context/resources/manuals/guides/page-customization.md +16 -3
- package/providers/context/resources/manuals/reference/project-api.md +3 -1
- package/providers/context/resources/procedures/document-capture.md +11 -5
- package/providers/context/resources/procedures/production-stage-files.md +3 -1
package/cli.js
CHANGED
|
@@ -79260,8 +79260,8 @@ async function readGitHead(cwd) {
|
|
|
79260
79260
|
async function ensureMaterializedSymlink(input) {
|
|
79261
79261
|
const linkPath = join24(input.projectRoot, input.materializedAt);
|
|
79262
79262
|
await mkdir14(dirname18(linkPath), { recursive: true });
|
|
79263
|
-
|
|
79264
|
-
|
|
79263
|
+
const stats = await lstat6(linkPath).catch(() => null);
|
|
79264
|
+
if (stats !== null) {
|
|
79265
79265
|
if (!stats.isSymbolicLink()) {
|
|
79266
79266
|
input.diagnostics.push(`materialized path exists and is not a symlink: ${input.materializedAt}`);
|
|
79267
79267
|
return false;
|
|
@@ -87746,6 +87746,7 @@ function renderReadme(projectName, language) {
|
|
|
87746
87746
|
"- `node_modules/@c4a/context/docs/README.md`",
|
|
87747
87747
|
"- `node_modules/@c4a/context/docs/reference/project-api.md`",
|
|
87748
87748
|
"- `node_modules/@c4a/context/docs/reference/package-templates.md`",
|
|
87749
|
+
"- 这些文档随工作区 SDK 安装;`context status` 报告 `version_alignment` 时先按其说明升级 SDK,否则文档可能落后于运行中的 CLI。",
|
|
87749
87750
|
""
|
|
87750
87751
|
].join(`
|
|
87751
87752
|
`);
|
|
@@ -87787,6 +87788,7 @@ function renderReadme(projectName, language) {
|
|
|
87787
87788
|
"- `node_modules/@c4a/context/docs/README.md`",
|
|
87788
87789
|
"- `node_modules/@c4a/context/docs/reference/project-api.md`",
|
|
87789
87790
|
"- `node_modules/@c4a/context/docs/reference/package-templates.md`",
|
|
87791
|
+
"- These docs come with the workspace SDK; when `context status` reports `version_alignment`, upgrade the SDK as it says first, or they may lag the running CLI.",
|
|
87790
87792
|
""
|
|
87791
87793
|
].join(`
|
|
87792
87794
|
`);
|
|
@@ -87837,6 +87839,7 @@ function renderAgents(projectName, language) {
|
|
|
87837
87839
|
"- SDK 总入口:`node_modules/@c4a/context/docs/README.md`。",
|
|
87838
87840
|
"- 项目声明:`node_modules/@c4a/context/docs/reference/project-api.md`。",
|
|
87839
87841
|
"- 包模板:`node_modules/@c4a/context/docs/reference/package-templates.md`。",
|
|
87842
|
+
"- 这些文档随工作区 SDK 安装;`context status` 报告 `version_alignment` 时先按其说明升级 SDK,否则文档可能落后于运行中的 CLI。",
|
|
87840
87843
|
""
|
|
87841
87844
|
].join(`
|
|
87842
87845
|
`);
|
|
@@ -87885,6 +87888,7 @@ function renderAgents(projectName, language) {
|
|
|
87885
87888
|
"- General SDK index: `node_modules/@c4a/context/docs/README.md`.",
|
|
87886
87889
|
"- Project declarations: `node_modules/@c4a/context/docs/reference/project-api.md`.",
|
|
87887
87890
|
"- Package templates: `node_modules/@c4a/context/docs/reference/package-templates.md`.",
|
|
87891
|
+
"- These docs come with the workspace SDK; when `context status` reports `version_alignment`, upgrade the SDK as it says first, or they may lag the running CLI.",
|
|
87888
87892
|
""
|
|
87889
87893
|
].join(`
|
|
87890
87894
|
`);
|
|
@@ -88045,6 +88049,7 @@ var exports_workspace = {};
|
|
|
88045
88049
|
__export(exports_workspace, {
|
|
88046
88050
|
resolveContextProjectInitTarget: () => resolveContextProjectInitTarget,
|
|
88047
88051
|
resolveContextPackageTemplatesRoot: () => resolveContextPackageTemplatesRoot,
|
|
88052
|
+
readCurrentPackageVersion: () => readCurrentPackageVersion,
|
|
88048
88053
|
projectLanguage: () => projectLanguage,
|
|
88049
88054
|
loadContextProjectModule: () => loadContextProjectModule,
|
|
88050
88055
|
isContextProjectRoot: () => isContextProjectRoot,
|
|
@@ -93906,12 +93911,89 @@ var init_packageSiteLocales = __esm(() => {
|
|
|
93906
93911
|
htmlEscapes = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
93907
93912
|
});
|
|
93908
93913
|
|
|
93914
|
+
// src/project/siteCustomPageLinks.ts
|
|
93915
|
+
var exports_siteCustomPageLinks = {};
|
|
93916
|
+
__export(exports_siteCustomPageLinks, {
|
|
93917
|
+
htmlContentLinks: () => htmlContentLinks,
|
|
93918
|
+
htmlAnchorIds: () => htmlAnchorIds,
|
|
93919
|
+
customPageLinkProblems: () => customPageLinkProblems
|
|
93920
|
+
});
|
|
93921
|
+
import { existsSync as existsSync19 } from "node:fs";
|
|
93922
|
+
import { readFile as readFile71 } from "node:fs/promises";
|
|
93923
|
+
import { join as join81, posix as posix10 } from "node:path";
|
|
93924
|
+
function decode2(value) {
|
|
93925
|
+
const text8 = value.replace(/&(amp|lt|gt|quot|#39|apos);/gu, (_, name3) => ENTITIES[name3] ?? _);
|
|
93926
|
+
try {
|
|
93927
|
+
return decodeURIComponent(text8);
|
|
93928
|
+
} catch {
|
|
93929
|
+
return text8;
|
|
93930
|
+
}
|
|
93931
|
+
}
|
|
93932
|
+
function htmlAnchorIds(html) {
|
|
93933
|
+
return new Set([...html.matchAll(/\sid="([^"]+)"/gu)].map((match) => decode2(match[1])));
|
|
93934
|
+
}
|
|
93935
|
+
function htmlContentLinks(html) {
|
|
93936
|
+
const start2 = html.indexOf("<main");
|
|
93937
|
+
const end = html.indexOf("</main>", start2);
|
|
93938
|
+
const body = start2 >= 0 && end > start2 ? html.slice(start2, end) : html;
|
|
93939
|
+
return [...body.matchAll(/<a\s[^>]*href="([^"]*)"/gu)].map((match) => decode2(match[1]));
|
|
93940
|
+
}
|
|
93941
|
+
async function customPageLinkProblems(output, base, keys) {
|
|
93942
|
+
const problems = [];
|
|
93943
|
+
const anchors = new Map;
|
|
93944
|
+
const idsOf = async (file) => {
|
|
93945
|
+
let ids = anchors.get(file);
|
|
93946
|
+
if (!ids) {
|
|
93947
|
+
ids = htmlAnchorIds(await readFile71(join81(output, file), "utf8"));
|
|
93948
|
+
anchors.set(file, ids);
|
|
93949
|
+
}
|
|
93950
|
+
return ids;
|
|
93951
|
+
};
|
|
93952
|
+
const prefix = base.endsWith("/") ? base : `${base}/`;
|
|
93953
|
+
for (const key of keys) {
|
|
93954
|
+
const page = `custom/${key}.html`;
|
|
93955
|
+
if (!existsSync19(join81(output, page)))
|
|
93956
|
+
continue;
|
|
93957
|
+
for (const href of htmlContentLinks(await readFile71(join81(output, page), "utf8"))) {
|
|
93958
|
+
if (!href || /^[a-z][a-z0-9+.-]*:/iu.test(href) || href.startsWith("//"))
|
|
93959
|
+
continue;
|
|
93960
|
+
const [rawPath = "", fragment2] = href.split("#", 2);
|
|
93961
|
+
const path2 = rawPath.split("?", 1)[0];
|
|
93962
|
+
let target;
|
|
93963
|
+
if (path2 === "")
|
|
93964
|
+
target = page;
|
|
93965
|
+
else if (path2.startsWith("/")) {
|
|
93966
|
+
if (!path2.startsWith(prefix) && `${path2}/` !== prefix)
|
|
93967
|
+
continue;
|
|
93968
|
+
target = path2.slice(prefix.length);
|
|
93969
|
+
} else
|
|
93970
|
+
target = posix10.normalize(posix10.join(posix10.dirname(page), path2));
|
|
93971
|
+
if (target === "" || target.endsWith("/"))
|
|
93972
|
+
target += "index.html";
|
|
93973
|
+
else if (!posix10.extname(target))
|
|
93974
|
+
target += ".html";
|
|
93975
|
+
if (target.startsWith("..") || !existsSync19(join81(output, target))) {
|
|
93976
|
+
problems.push(`${page}: link ${href} has no target`);
|
|
93977
|
+
continue;
|
|
93978
|
+
}
|
|
93979
|
+
if (fragment2 && target.endsWith(".html") && !(await idsOf(target)).has(decode2(fragment2))) {
|
|
93980
|
+
problems.push(`${page}: link ${href} points to a missing anchor in ${target}`);
|
|
93981
|
+
}
|
|
93982
|
+
}
|
|
93983
|
+
}
|
|
93984
|
+
return problems;
|
|
93985
|
+
}
|
|
93986
|
+
var ENTITIES;
|
|
93987
|
+
var init_siteCustomPageLinks = __esm(() => {
|
|
93988
|
+
ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', "#39": "'", apos: "'" };
|
|
93989
|
+
});
|
|
93990
|
+
|
|
93909
93991
|
// src/project/packageSite.ts
|
|
93910
93992
|
import { createHash as createHash26 } from "node:crypto";
|
|
93911
93993
|
import { spawn as spawn4 } from "node:child_process";
|
|
93912
|
-
import { mkdir as mkdir30, mkdtemp as mkdtemp3, readFile as
|
|
93994
|
+
import { mkdir as mkdir30, mkdtemp as mkdtemp3, readFile as readFile72, writeFile as writeFile23, rm as rm18, symlink as symlink4, cp as cp2, access as access5, stat as stat9 } from "node:fs/promises";
|
|
93913
93995
|
import { createRequire as createRequire5 } from "node:module";
|
|
93914
|
-
import { dirname as dirname36, join as
|
|
93996
|
+
import { dirname as dirname36, join as join82, posix as posix11 } from "node:path";
|
|
93915
93997
|
function sitePagePath(identity) {
|
|
93916
93998
|
return `pages/${createHash26("sha256").update(identity).digest("hex").slice(0, 32)}.html`;
|
|
93917
93999
|
}
|
|
@@ -93937,7 +94019,7 @@ function createSiteNavigation(pkg, selected, structure) {
|
|
|
93937
94019
|
approved_path: `knowledge/${file.relPath}`,
|
|
93938
94020
|
package_path: packageKnowledgeOutputPath(pkg, file.relPath),
|
|
93939
94021
|
site_path: path2,
|
|
93940
|
-
title: typeof meta.title === "string" ? meta.title :
|
|
94022
|
+
title: typeof meta.title === "string" ? meta.title : posix11.basename(file.relPath, ".md")
|
|
93941
94023
|
};
|
|
93942
94024
|
});
|
|
93943
94025
|
for (const [key, href] of siteExtensionTargets(pkg.kind === "package.kb" ? pkg.site : undefined)) {
|
|
@@ -93991,7 +94073,7 @@ function siteMarkdown(content3, from, pages, files) {
|
|
|
93991
94073
|
const [pathPart, fragment2] = link.target.split(/#(.*)/su);
|
|
93992
94074
|
let path2;
|
|
93993
94075
|
try {
|
|
93994
|
-
path2 =
|
|
94076
|
+
path2 = posix11.normalize(posix11.join(posix11.dirname(from), decodeURIComponent(pathPart.split("?")[0])));
|
|
93995
94077
|
} catch {
|
|
93996
94078
|
continue;
|
|
93997
94079
|
}
|
|
@@ -94031,7 +94113,7 @@ function siteSections(entries2) {
|
|
|
94031
94113
|
async function compileSite(root, outDir) {
|
|
94032
94114
|
const vitepressRoot = dirname36(require2.resolve("vitepress/package.json"));
|
|
94033
94115
|
await new Promise((resolve8, reject) => {
|
|
94034
|
-
const child = spawn4(process.versions.bun ? "node" : process.execPath, [
|
|
94116
|
+
const child = spawn4(process.versions.bun ? "node" : process.execPath, [join82(vitepressRoot, "bin/vitepress.js"), "build", root, "--outDir", outDir], { stdio: ["ignore", "pipe", "pipe"] });
|
|
94035
94117
|
let tail = "";
|
|
94036
94118
|
const receive = (chunk) => {
|
|
94037
94119
|
tail = (tail + chunk.toString()).slice(-16000);
|
|
@@ -94091,15 +94173,15 @@ async function siteSourceMaps(input) {
|
|
|
94091
94173
|
file.article.sections.forEach((section) => section.references.forEach(({ source_ref: ref2, locator }) => {
|
|
94092
94174
|
const note = ref2.startsWith("note:") ? input.registry.notes.find((entry) => ref2 === `note:${entry.id}`) : undefined;
|
|
94093
94175
|
const lark = ref2.startsWith("lark:") ? input.registry.larks.find((entry) => ref2 === `lark:${entry.id}` || ref2 === `lark:${entry.name}`) : undefined;
|
|
94094
|
-
const path2 = note ? note.materializedAt : lark && !lark.title ?
|
|
94095
|
-
if (path2 && !
|
|
94176
|
+
const path2 = note ? note.materializedAt : lark && !lark.title ? posix11.join(lark.materializedAt, locator.path) : undefined;
|
|
94177
|
+
if (path2 && !posix11.normalize(path2).startsWith("../"))
|
|
94096
94178
|
documents.set(siteDocumentKey(ref2, locator.path), path2);
|
|
94097
94179
|
}));
|
|
94098
94180
|
articles.push({ article: file.article, href: `/${page.site_path}`, titles: titles2, sectionTitles });
|
|
94099
94181
|
}
|
|
94100
94182
|
const titles = new Map;
|
|
94101
94183
|
for (const [key, file] of documents) {
|
|
94102
|
-
const content3 = await
|
|
94184
|
+
const content3 = await readFile72(join82(input.projectRoot, file), "utf8").catch(() => {
|
|
94103
94185
|
return;
|
|
94104
94186
|
});
|
|
94105
94187
|
const title = content3 && (/^title:[ \t]*["']?(.+?)["']?[ \t]*$/mu.exec(/^---\r?\n([\s\S]*?)\r?\n---/u.exec(content3)?.[1] ?? "")?.[1] ?? /^#[ \t]+(.+?)[ \t#]*$/mu.exec(content3)?.[1]);
|
|
@@ -94121,8 +94203,8 @@ async function writePackageSite(input) {
|
|
|
94121
94203
|
const base = options.base ?? "/";
|
|
94122
94204
|
const history = await readWorkspaceChangelog(projectRoot);
|
|
94123
94205
|
const historyDate = history[0]?.date ?? null;
|
|
94124
|
-
const root =
|
|
94125
|
-
const output =
|
|
94206
|
+
const root = join82(projectRoot, pkg.outDir);
|
|
94207
|
+
const output = join82(projectRoot, packageSiteOutputDir(pkg));
|
|
94126
94208
|
try {
|
|
94127
94209
|
await access5(output);
|
|
94128
94210
|
throw new Error("Website output already exists; build through the staged package workflow.");
|
|
@@ -94130,9 +94212,9 @@ async function writePackageSite(input) {
|
|
|
94130
94212
|
if (error.code !== "ENOENT")
|
|
94131
94213
|
throw error;
|
|
94132
94214
|
}
|
|
94133
|
-
const temporaryRoot =
|
|
94215
|
+
const temporaryRoot = join82(projectRoot, ".tmp");
|
|
94134
94216
|
await mkdir30(temporaryRoot, { recursive: true });
|
|
94135
|
-
const temporary = await mkdtemp3(
|
|
94217
|
+
const temporary = await mkdtemp3(join82(temporaryRoot, "website-"));
|
|
94136
94218
|
try {
|
|
94137
94219
|
const registry2 = await loadSourcesRegistry({ rootDir: projectRoot });
|
|
94138
94220
|
const repositoryRemote = await optionalRepoGit(projectRoot, ["remote", "get-url", "origin"]);
|
|
@@ -94147,22 +94229,22 @@ async function writePackageSite(input) {
|
|
|
94147
94229
|
continue;
|
|
94148
94230
|
if (!/^(?:skills|wikis|guides|rules|feats)\/.*\.md$/u.test(file.relPath) || byPath.has(file.relPath))
|
|
94149
94231
|
continue;
|
|
94150
|
-
const content3 = await
|
|
94232
|
+
const content3 = await readFile72(file.absPath, "utf8");
|
|
94151
94233
|
const meta = parseKnowledgeFrontmatter(content3);
|
|
94152
94234
|
const page = {
|
|
94153
94235
|
package_path: file.relPath,
|
|
94154
94236
|
site_path: sitePagePath(`index:${file.relPath}`),
|
|
94155
|
-
title: typeof meta.title === "string" ? meta.title : typeof meta.name === "string" ? meta.name : /^#\s+(.+)$/mu.exec(content3)?.[1] ??
|
|
94237
|
+
title: typeof meta.title === "string" ? meta.title : typeof meta.name === "string" ? meta.name : /^#\s+(.+)$/mu.exec(content3)?.[1] ?? posix11.basename(file.relPath, ".md")
|
|
94156
94238
|
};
|
|
94157
94239
|
byPath.set(file.relPath, page);
|
|
94158
94240
|
}
|
|
94159
94241
|
const sections = siteSections(mapping.entries);
|
|
94160
94242
|
const resources = new Set(delivered.filter((file) => file.relPath.startsWith("others/assets/") || file.relPath.startsWith("skills/") && !file.relPath.endsWith(".md")).map((file) => file.relPath));
|
|
94161
|
-
const configRoot =
|
|
94162
|
-
await mkdir30(
|
|
94163
|
-
await mkdir30(
|
|
94243
|
+
const configRoot = join82(temporary, ".vitepress");
|
|
94244
|
+
await mkdir30(join82(configRoot, "theme"), { recursive: true });
|
|
94245
|
+
await mkdir30(join82(temporary, "node_modules"), { recursive: true });
|
|
94164
94246
|
const vitepressRoot = dirname36(require2.resolve("vitepress/package.json"));
|
|
94165
|
-
const vueRequire = createRequire5(
|
|
94247
|
+
const vueRequire = createRequire5(join82(vitepressRoot, "package.json"));
|
|
94166
94248
|
for (const [name3, path2] of [
|
|
94167
94249
|
["vitepress", vitepressRoot],
|
|
94168
94250
|
["vue", dirname36(vueRequire.resolve("vue/package.json"))],
|
|
@@ -94170,17 +94252,17 @@ async function writePackageSite(input) {
|
|
|
94170
94252
|
["mermaid", dirname36(require2.resolve("mermaid/package.json"))],
|
|
94171
94253
|
["markdown-it-cjk-friendly", dirname36(require2.resolve("markdown-it-cjk-friendly/package.json"))]
|
|
94172
94254
|
]) {
|
|
94173
|
-
await mkdir30(dirname36(
|
|
94174
|
-
await symlink4(path2,
|
|
94255
|
+
await mkdir30(dirname36(join82(temporary, "node_modules", name3)), { recursive: true });
|
|
94256
|
+
await symlink4(path2, join82(temporary, "node_modules", name3), "dir");
|
|
94175
94257
|
}
|
|
94176
94258
|
const readers = siteReaderLocales(options, pkg.name);
|
|
94177
94259
|
const marker = createLocaleMarker();
|
|
94178
94260
|
const theme = await resolveSiteTheme(projectRoot, options.theme, true);
|
|
94179
|
-
await writeFile23(
|
|
94180
|
-
await writeFile23(
|
|
94261
|
+
await writeFile23(join82(configRoot, "theme/index.js"), siteThemeScript);
|
|
94262
|
+
await writeFile23(join82(configRoot, "theme/style.css"), siteThemeCss + siteLocaleCss(readers) + siteThemeVariables(theme));
|
|
94181
94263
|
await writeSiteExtensions(projectRoot, temporary, options.extensions);
|
|
94182
94264
|
const localizer = await createSiteLocalizer({ projectRoot, readers, marker, selected, byPath, resources });
|
|
94183
|
-
await mkdir30(
|
|
94265
|
+
await mkdir30(join82(temporary, "pages"), { recursive: true });
|
|
94184
94266
|
const primaryBody = (page, packageContent) => {
|
|
94185
94267
|
let content3 = packageContent;
|
|
94186
94268
|
if (page.package_path === "wikis/index.md" && typeof pkg.repoContentPage !== "object") {
|
|
@@ -94220,9 +94302,9 @@ ${titles ? `contextTitles: ${JSON.stringify(titles)}
|
|
|
94220
94302
|
`;
|
|
94221
94303
|
};
|
|
94222
94304
|
for (const page of byPath.values()) {
|
|
94223
|
-
const content3 = await
|
|
94305
|
+
const content3 = await readFile72(join82(root, page.package_path), "utf8");
|
|
94224
94306
|
const localized = await localizer.page(page, primaryBody(page, content3));
|
|
94225
|
-
await writeFile23(
|
|
94307
|
+
await writeFile23(join82(temporary, page.site_path.replace(/\.html$/u, ".md")), `${pageFrontmatter(page, content3, localized.titles)}
|
|
94226
94308
|
${localized.body}`);
|
|
94227
94309
|
}
|
|
94228
94310
|
const themeSections = sections.map((section) => ({
|
|
@@ -94281,7 +94363,7 @@ ${localized.body}`);
|
|
|
94281
94363
|
contextLocales: { primary: readers.primary, tags: readers.tags, labels: readers.labels, titles: readers.titles, preferenceKey: readers.preferenceKey }
|
|
94282
94364
|
}
|
|
94283
94365
|
};
|
|
94284
|
-
await writeFile23(
|
|
94366
|
+
await writeFile23(join82(configRoot, "config.mjs"), `${siteMarkdownImports()}const contextLocaleMarker = ${JSON.stringify(readers.translated ? marker : null)};
|
|
94285
94367
|
` + `export default { ...${JSON.stringify(config)}, markdown: { ${siteMarkdownConfig} },
|
|
94286
94368
|
` + ` transformHtml: html => html.replace(/<script id="check-dark-mode">[\\s\\S]*?<\\/script>/u, "") };
|
|
94287
94369
|
`);
|
|
@@ -94297,9 +94379,9 @@ ${localized.body}`);
|
|
|
94297
94379
|
menu(lines, entries2, 0, tag);
|
|
94298
94380
|
lines.push("", "</div>", "");
|
|
94299
94381
|
};
|
|
94300
|
-
await mkdir30(
|
|
94382
|
+
await mkdir30(join82(temporary, "sections"), { recursive: true });
|
|
94301
94383
|
for (const section of sections) {
|
|
94302
|
-
await writeFile23(
|
|
94384
|
+
await writeFile23(join82(temporary, section.href.slice(1).replace(/\.html$/u, ".md")), localizer.variants((tag) => {
|
|
94303
94385
|
const lines = [`# ${mdLabel(localizer.entryTitle(tag, section.entry))}`, "", '<div class="context-section-grid">', ""];
|
|
94304
94386
|
const grouped = section.entries.some((entry) => entry.children.length > 0);
|
|
94305
94387
|
let articles = [];
|
|
@@ -94338,12 +94420,12 @@ ${localized.body}`);
|
|
|
94338
94420
|
` : "";
|
|
94339
94421
|
const homeHero = options.extensions?.slots?.banner === undefined ? `hero: ${JSON.stringify(hero)}
|
|
94340
94422
|
${heroActions}` : "";
|
|
94341
|
-
await writeFile23(
|
|
94423
|
+
await writeFile23(join82(temporary, "index.md"), `---
|
|
94342
94424
|
layout: home
|
|
94343
94425
|
title: ${JSON.stringify(options.home?.title ?? options.title ?? pkg.name)}
|
|
94344
94426
|
${homeHero}---
|
|
94345
94427
|
`);
|
|
94346
|
-
await writeFile23(
|
|
94428
|
+
await writeFile23(join82(temporary, "changelog.md"), `---
|
|
94347
94429
|
title: Changelog
|
|
94348
94430
|
contextHistory: ${JSON.stringify(Buffer.from(JSON.stringify(history)).toString("base64"))}
|
|
94349
94431
|
---
|
|
@@ -94356,19 +94438,19 @@ contextHistory: ${JSON.stringify(Buffer.from(JSON.stringify(history)).toString("
|
|
|
94356
94438
|
assetsPrefix: "resources/",
|
|
94357
94439
|
articles: await Promise.all(llmsArticles(pkg, selected).map(async (article) => ({
|
|
94358
94440
|
...article,
|
|
94359
|
-
content: await
|
|
94441
|
+
content: await readFile72(join82(root, article.path), "utf8")
|
|
94360
94442
|
}))),
|
|
94361
94443
|
...structure ? { map: structure } : {}
|
|
94362
94444
|
});
|
|
94363
|
-
await writeLlmsDocuments(
|
|
94364
|
-
await mkdir30(
|
|
94445
|
+
await writeLlmsDocuments(join82(temporary, "public"), llms, { utf8Bom: true });
|
|
94446
|
+
await mkdir30(join82(temporary, "llms"), { recursive: true });
|
|
94365
94447
|
let landingNavigation = llms.navigationMarkdown;
|
|
94366
94448
|
for (const link of markdownReaderLinks(landingNavigation).reverse()) {
|
|
94367
94449
|
if (!link.target.startsWith(base))
|
|
94368
94450
|
continue;
|
|
94369
94451
|
landingNavigation = landingNavigation.slice(0, link.start) + `[${link.label}](</${link.target.slice(base.length)}>)` + landingNavigation.slice(link.end);
|
|
94370
94452
|
}
|
|
94371
|
-
await writeFile23(
|
|
94453
|
+
await writeFile23(join82(temporary, "llms/index.md"), `---
|
|
94372
94454
|
title: LLM Docs
|
|
94373
94455
|
---
|
|
94374
94456
|
|
|
@@ -94378,16 +94460,26 @@ title: LLM Docs
|
|
|
94378
94460
|
|
|
94379
94461
|
` + landingNavigation);
|
|
94380
94462
|
for (const path2 of resources) {
|
|
94381
|
-
const destination =
|
|
94463
|
+
const destination = join82(temporary, "public/resources", path2);
|
|
94382
94464
|
await mkdir30(dirname36(destination), { recursive: true });
|
|
94383
|
-
await cp2(
|
|
94465
|
+
await cp2(join82(root, path2), destination);
|
|
94384
94466
|
}
|
|
94385
94467
|
await compileSite(temporary, output);
|
|
94468
|
+
const customPages = Object.keys(options.extensions?.pages ?? {});
|
|
94469
|
+
if (customPages.length) {
|
|
94470
|
+
const { customPageLinkProblems: customPageLinkProblems2 } = await Promise.resolve().then(() => (init_siteCustomPageLinks(), exports_siteCustomPageLinks));
|
|
94471
|
+
const problems = await customPageLinkProblems2(output, base, customPages);
|
|
94472
|
+
if (problems.length)
|
|
94473
|
+
throw new Error(`Custom website pages contain ${problems.length} broken link(s). Existing package was preserved. Fix the links in the custom pages (heading anchors follow the website's rule, for example "_3v架构" for "3V架构") and rerun context build.
|
|
94474
|
+
${problems.slice(0, 50).join(`
|
|
94475
|
+
`)}${problems.length > 50 ? `
|
|
94476
|
+
… and ${problems.length - 50} more` : ""}`);
|
|
94477
|
+
}
|
|
94386
94478
|
const originLinks = [...navigation.nav, ...navigation.more].filter((item) => item.origin).map((item) => item.link);
|
|
94387
94479
|
for (const file of await walkPackageFiles(output)) {
|
|
94388
|
-
const extension2 =
|
|
94480
|
+
const extension2 = posix11.extname(file.relPath).toLowerCase();
|
|
94389
94481
|
if (extension2 === ".html" && originLinks.length) {
|
|
94390
|
-
const html = await
|
|
94482
|
+
const html = await readFile72(file.absPath, "utf8");
|
|
94391
94483
|
const restored = restoreOriginNavLinks(html, base, originLinks);
|
|
94392
94484
|
if (restored !== html)
|
|
94393
94485
|
await writeFile23(file.absPath, restored);
|
|
@@ -94412,11 +94504,11 @@ title: LLM Docs
|
|
|
94412
94504
|
warnings: mapping.warnings
|
|
94413
94505
|
}, null, 2) + `
|
|
94414
94506
|
`;
|
|
94415
|
-
const packageSiteMap =
|
|
94416
|
-
const distributedSiteMap =
|
|
94507
|
+
const packageSiteMap = join82(projectRoot, pkg.outDir, "context-site-map.json");
|
|
94508
|
+
const distributedSiteMap = join82(projectRoot, pkg.outDir, packageDistributionMetadataPath("context-site-map.json"));
|
|
94417
94509
|
await mkdir30(dirname36(distributedSiteMap), { recursive: true });
|
|
94418
94510
|
await Promise.all([
|
|
94419
|
-
writeFile23(
|
|
94511
|
+
writeFile23(join82(output, "context-site-map.json"), siteMapContent),
|
|
94420
94512
|
writeFile23(packageSiteMap, siteMapContent),
|
|
94421
94513
|
writeFile23(distributedSiteMap, siteMapContent)
|
|
94422
94514
|
]);
|
|
@@ -94463,7 +94555,7 @@ var init_packageSite2 = __esm(() => {
|
|
|
94463
94555
|
});
|
|
94464
94556
|
|
|
94465
94557
|
// src/project/workspaceBuildVersion.ts
|
|
94466
|
-
import { join as
|
|
94558
|
+
import { join as join83 } from "node:path";
|
|
94467
94559
|
import { mkdir as mkdir31, writeFile as writeFile24 } from "node:fs/promises";
|
|
94468
94560
|
async function workspaceVersionFingerprint(root) {
|
|
94469
94561
|
return { version: await workspaceVersion(root), changelog: await readWorkspaceChangelog(root) };
|
|
@@ -94475,8 +94567,8 @@ async function writePackageVersion(projectRoot, output) {
|
|
|
94475
94567
|
throw new TypeError(`Package template uses reserved version output ${path2}; rename that template output.`);
|
|
94476
94568
|
}
|
|
94477
94569
|
await mkdir31(output, { recursive: true });
|
|
94478
|
-
await writeFile24(
|
|
94479
|
-
await writeFile24(
|
|
94570
|
+
await writeFile24(join83(output, "CHANGELOG.md"), renderChangelog(info2.changelog));
|
|
94571
|
+
await writeFile24(join83(output, "context-version.json"), JSON.stringify({ version: info2.version }) + `
|
|
94480
94572
|
`);
|
|
94481
94573
|
}
|
|
94482
94574
|
var init_workspaceBuildVersion = __esm(() => {
|
|
@@ -94484,23 +94576,23 @@ var init_workspaceBuildVersion = __esm(() => {
|
|
|
94484
94576
|
});
|
|
94485
94577
|
|
|
94486
94578
|
// src/project/packageBuildStage.ts
|
|
94487
|
-
import { mkdir as mkdir32, mkdtemp as mkdtemp4, readFile as
|
|
94488
|
-
import { dirname as dirname37, join as
|
|
94579
|
+
import { mkdir as mkdir32, mkdtemp as mkdtemp4, readFile as readFile73, rename as rename9, rm as rm19, rmdir } from "node:fs/promises";
|
|
94580
|
+
import { dirname as dirname37, join as join84, relative as relative27 } from "node:path";
|
|
94489
94581
|
async function withStagedPackageOutput(projectRoot, pkg, render) {
|
|
94490
|
-
const tempRoot =
|
|
94582
|
+
const tempRoot = join84(projectRoot, ".tmp");
|
|
94491
94583
|
await mkdir32(tempRoot, { recursive: true });
|
|
94492
|
-
const stage = await mkdtemp4(
|
|
94493
|
-
const stagedPackage = { ...pkg, outDir: relative27(projectRoot,
|
|
94584
|
+
const stage = await mkdtemp4(join84(tempRoot, "package-build-"));
|
|
94585
|
+
const stagedPackage = { ...pkg, outDir: relative27(projectRoot, join84(stage, pkg.name)) };
|
|
94494
94586
|
try {
|
|
94495
|
-
await mkdir32(
|
|
94587
|
+
await mkdir32(join84(projectRoot, stagedPackage.outDir), { recursive: true });
|
|
94496
94588
|
const value = await render(stagedPackage);
|
|
94497
94589
|
await validatePackageIndexLinks({ projectRoot, pkg: stagedPackage });
|
|
94498
94590
|
const destinations = packageOutputDirs(pkg);
|
|
94499
94591
|
const staged = packageOutputDirs(stagedPackage);
|
|
94500
94592
|
for (const [index3, destination] of destinations.entries()) {
|
|
94501
|
-
const target =
|
|
94593
|
+
const target = join84(projectRoot, destination);
|
|
94502
94594
|
const previous2 = await walkPackageFiles(target);
|
|
94503
|
-
const next = await walkPackageFiles(
|
|
94595
|
+
const next = await walkPackageFiles(join84(projectRoot, staged[index3]));
|
|
94504
94596
|
const desired = new Set(next.map((file) => file.relPath));
|
|
94505
94597
|
for (const file of previous2) {
|
|
94506
94598
|
if (desired.has(file.relPath))
|
|
@@ -94518,9 +94610,9 @@ async function withStagedPackageOutput(projectRoot, pkg, render) {
|
|
|
94518
94610
|
}
|
|
94519
94611
|
for (let offset2 = 0;offset2 < next.length; offset2 += 8) {
|
|
94520
94612
|
const results = await Promise.allSettled(next.slice(offset2, offset2 + 8).map(async (file) => {
|
|
94521
|
-
const output =
|
|
94522
|
-
const bytes = await
|
|
94523
|
-
const old = await
|
|
94613
|
+
const output = join84(target, file.relPath);
|
|
94614
|
+
const bytes = await readFile73(file.absPath);
|
|
94615
|
+
const old = await readFile73(output).catch((error) => {
|
|
94524
94616
|
if (error.code === "ENOENT")
|
|
94525
94617
|
return;
|
|
94526
94618
|
throw error;
|
|
@@ -94549,7 +94641,7 @@ var init_packageBuildStage = __esm(() => {
|
|
|
94549
94641
|
// src/runtimeEventOutbox.ts
|
|
94550
94642
|
import {
|
|
94551
94643
|
closeSync,
|
|
94552
|
-
existsSync as
|
|
94644
|
+
existsSync as existsSync20,
|
|
94553
94645
|
mkdirSync as mkdirSync2,
|
|
94554
94646
|
openSync,
|
|
94555
94647
|
readFileSync as readFileSync7,
|
|
@@ -94558,7 +94650,7 @@ import {
|
|
|
94558
94650
|
unlinkSync,
|
|
94559
94651
|
writeFileSync as writeFileSync2
|
|
94560
94652
|
} from "node:fs";
|
|
94561
|
-
import { dirname as dirname38, join as
|
|
94653
|
+
import { dirname as dirname38, join as join85 } from "node:path";
|
|
94562
94654
|
function isRecord12(value) {
|
|
94563
94655
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
94564
94656
|
}
|
|
@@ -94576,10 +94668,10 @@ function parseEvent(value) {
|
|
|
94576
94668
|
};
|
|
94577
94669
|
}
|
|
94578
94670
|
function runtimeEventOutboxPath(projectRoot) {
|
|
94579
|
-
return
|
|
94671
|
+
return join85(projectRoot, OUTBOX_RELATIVE_PATH);
|
|
94580
94672
|
}
|
|
94581
94673
|
function readRuntimeEventOutboxFile(path2) {
|
|
94582
|
-
if (!
|
|
94674
|
+
if (!existsSync20(path2))
|
|
94583
94675
|
return [];
|
|
94584
94676
|
const pending = new Map;
|
|
94585
94677
|
try {
|
|
@@ -94707,20 +94799,20 @@ function acknowledgeRuntimeEventOutbox(projectRoot, eventIds) {
|
|
|
94707
94799
|
}
|
|
94708
94800
|
var OUTBOX_EVENT_SCHEMA = "context.runtime-event-outbox.event.v1", OUTBOX_ACK_SCHEMA = "context.runtime-event-outbox.ack.v1", OUTBOX_RELATIVE_PATH, OUTBOX_LOCK_STALE_MS = 30000, OUTBOX_LOCK_RETRY_MS = 10, OUTBOX_LOCK_RETRIES = 100;
|
|
94709
94801
|
var init_runtimeEventOutbox = __esm(() => {
|
|
94710
|
-
OUTBOX_RELATIVE_PATH =
|
|
94802
|
+
OUTBOX_RELATIVE_PATH = join85(".tmp", "context-runtime", "logs", "outbox.jsonl");
|
|
94711
94803
|
});
|
|
94712
94804
|
|
|
94713
94805
|
// src/runtimeEvents.ts
|
|
94714
94806
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
94715
94807
|
import {
|
|
94716
|
-
existsSync as
|
|
94808
|
+
existsSync as existsSync21,
|
|
94717
94809
|
mkdirSync as mkdirSync3,
|
|
94718
94810
|
readFileSync as readFileSync8,
|
|
94719
94811
|
renameSync as renameSync2,
|
|
94720
94812
|
writeFileSync as writeFileSync3
|
|
94721
94813
|
} from "node:fs";
|
|
94722
94814
|
import { spawn as spawn5 } from "node:child_process";
|
|
94723
|
-
import { dirname as dirname39, join as
|
|
94815
|
+
import { dirname as dirname39, join as join86 } from "node:path";
|
|
94724
94816
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
94725
94817
|
function isRecord13(value) {
|
|
94726
94818
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -94823,8 +94915,8 @@ function readRuntimePackageMetadata() {
|
|
|
94823
94915
|
try {
|
|
94824
94916
|
let dir = dirname39(fileURLToPath6(import.meta.url));
|
|
94825
94917
|
for (let index3 = 0;index3 < 8; index3++) {
|
|
94826
|
-
const packagePath =
|
|
94827
|
-
if (
|
|
94918
|
+
const packagePath = join86(dir, "package.json");
|
|
94919
|
+
if (existsSync21(packagePath)) {
|
|
94828
94920
|
const parsed = JSON.parse(readFileSync8(packagePath, "utf8"));
|
|
94829
94921
|
if (isRecord13(parsed)) {
|
|
94830
94922
|
return {
|
|
@@ -94960,7 +95052,7 @@ function dispatchCommand(sink, batch, cwd) {
|
|
|
94960
95052
|
});
|
|
94961
95053
|
}
|
|
94962
95054
|
function runtimeEventStatePath(cwd) {
|
|
94963
|
-
return
|
|
95055
|
+
return join86(cwd, ".tmp", "context-runtime", RUNTIME_EVENT_STATE_FILE);
|
|
94964
95056
|
}
|
|
94965
95057
|
function readRuntimeEventState(cwd) {
|
|
94966
95058
|
try {
|
|
@@ -95422,8 +95514,8 @@ var init_packageTemplateGuard = __esm(() => {
|
|
|
95422
95514
|
});
|
|
95423
95515
|
|
|
95424
95516
|
// src/project/approvedKnowledgeSnapshots.ts
|
|
95425
|
-
import { readFile as
|
|
95426
|
-
import { join as
|
|
95517
|
+
import { readFile as readFile74 } from "node:fs/promises";
|
|
95518
|
+
import { join as join87 } from "node:path";
|
|
95427
95519
|
function approvedKnowledgeSnapshotsFromStructure(structure) {
|
|
95428
95520
|
return validateArticleStructureEntries(structure?.articles ?? []);
|
|
95429
95521
|
}
|
|
@@ -95432,7 +95524,7 @@ async function prepareApprovedKnowledgeSnapshotTarget(input) {
|
|
|
95432
95524
|
return;
|
|
95433
95525
|
let before;
|
|
95434
95526
|
try {
|
|
95435
|
-
before = await
|
|
95527
|
+
before = await readFile74(join87(input.projectRoot, STRUCTURE_PATH2), "utf8");
|
|
95436
95528
|
} catch (error) {
|
|
95437
95529
|
if (error.code !== "ENOENT")
|
|
95438
95530
|
throw error;
|
|
@@ -95610,12 +95702,12 @@ function approvedStructureInputHash(input) {
|
|
|
95610
95702
|
var init_approvedStructureInputHash = () => {};
|
|
95611
95703
|
|
|
95612
95704
|
// src/project/verifyApprovedStructure.ts
|
|
95613
|
-
import { existsSync as
|
|
95614
|
-
import { join as
|
|
95705
|
+
import { existsSync as existsSync22 } from "node:fs";
|
|
95706
|
+
import { join as join88 } from "node:path";
|
|
95615
95707
|
async function validateApprovedStructure(input) {
|
|
95616
95708
|
const issue = (code, path3, message) => input.issues.push({ severity: "error", code, path: path3, message });
|
|
95617
|
-
const path2 =
|
|
95618
|
-
if (!input.structureOverride && !
|
|
95709
|
+
const path2 = join88(input.projectRoot, STRUCTURE_PATH3);
|
|
95710
|
+
if (!input.structureOverride && !existsSync22(path2))
|
|
95619
95711
|
return;
|
|
95620
95712
|
let parsed;
|
|
95621
95713
|
let articles;
|
|
@@ -95771,8 +95863,8 @@ var init_verifyDiagnostics = __esm(() => {
|
|
|
95771
95863
|
});
|
|
95772
95864
|
|
|
95773
95865
|
// src/project/verify.ts
|
|
95774
|
-
import { existsSync as
|
|
95775
|
-
import { join as
|
|
95866
|
+
import { existsSync as existsSync23 } from "node:fs";
|
|
95867
|
+
import { join as join89 } from "node:path";
|
|
95776
95868
|
function evidenceStatusForIssues(issues) {
|
|
95777
95869
|
if (issues.some((issue) => issue.severity === "error"))
|
|
95778
95870
|
return "fail";
|
|
@@ -95846,7 +95938,7 @@ async function verifyProjectWorkspace(projectRoot, options = {}) {
|
|
|
95846
95938
|
pageRelPath: `knowledge/${file.relPath}`,
|
|
95847
95939
|
content: content3
|
|
95848
95940
|
})) {
|
|
95849
|
-
if (!
|
|
95941
|
+
if (!existsSync23(join89(projectRoot, assetPath))) {
|
|
95850
95942
|
issues.push({
|
|
95851
95943
|
severity: "error",
|
|
95852
95944
|
code: "approved-resource-missing",
|
|
@@ -95984,9 +96076,9 @@ __export(exports_packageBuilder, {
|
|
|
95984
96076
|
buildProjectPackages: () => buildProjectPackages
|
|
95985
96077
|
});
|
|
95986
96078
|
import { createHash as createHash28 } from "node:crypto";
|
|
95987
|
-
import { existsSync as
|
|
95988
|
-
import { mkdir as mkdir33, readdir as readdir21, readFile as
|
|
95989
|
-
import { dirname as dirname40, join as
|
|
96079
|
+
import { existsSync as existsSync24 } from "node:fs";
|
|
96080
|
+
import { mkdir as mkdir33, readdir as readdir21, readFile as readFile75, rm as rm20, writeFile as writeFile25 } from "node:fs/promises";
|
|
96081
|
+
import { dirname as dirname40, join as join90, resolve as resolve31 } from "node:path";
|
|
95990
96082
|
function packageAssetDeliverySummary(value) {
|
|
95991
96083
|
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
95992
96084
|
return;
|
|
@@ -96008,7 +96100,7 @@ function assertPackageOutputDir(pkg) {
|
|
|
96008
96100
|
}
|
|
96009
96101
|
function packageFingerprintPath(projectRoot, pkg) {
|
|
96010
96102
|
assertSafeRenderedPath(`${pkg.name}.json`, "package fingerprint path");
|
|
96011
|
-
return
|
|
96103
|
+
return join90(projectRoot, PACKAGE_FINGERPRINT_ROOT, `${pkg.name}.json`);
|
|
96012
96104
|
}
|
|
96013
96105
|
async function listApprovedKnowledge(projectRoot) {
|
|
96014
96106
|
const metadata = await readApprovedKnowledgeMetadataIndex(projectRoot);
|
|
@@ -96039,7 +96131,7 @@ function isDeprecatedKnowledge(content3) {
|
|
|
96039
96131
|
async function listTemplateFiles(projectRoot, templatePath) {
|
|
96040
96132
|
assertSafeRenderedPath(templatePath, "package template path");
|
|
96041
96133
|
const templateRoot = resolve31(projectRoot, templatePath);
|
|
96042
|
-
if (!
|
|
96134
|
+
if (!existsSync24(templateRoot)) {
|
|
96043
96135
|
throw new ContextError(ExitCode.WorkspaceStateError, `package template path is missing: ${templatePath}`, {
|
|
96044
96136
|
category: ErrorCategory.WorkspaceStateInvalid,
|
|
96045
96137
|
path: templatePath,
|
|
@@ -96049,7 +96141,7 @@ async function listTemplateFiles(projectRoot, templatePath) {
|
|
|
96049
96141
|
const files = await walkPackageFiles(templateRoot);
|
|
96050
96142
|
return Promise.all(files.filter((file) => file.relPath.split("/").at(-1) !== PACKAGE_TEMPLATE_REVIEW_FILE).map(async (file) => ({
|
|
96051
96143
|
...file,
|
|
96052
|
-
content: await
|
|
96144
|
+
content: await readFile75(file.absPath, "utf8")
|
|
96053
96145
|
})));
|
|
96054
96146
|
}
|
|
96055
96147
|
function stableHash2(value) {
|
|
@@ -96114,10 +96206,10 @@ async function packageInputFingerprint(input) {
|
|
|
96114
96206
|
}
|
|
96115
96207
|
async function readPackageManifest(projectRoot, pkg) {
|
|
96116
96208
|
const filePath2 = packageFingerprintPath(projectRoot, pkg);
|
|
96117
|
-
if (!
|
|
96209
|
+
if (!existsSync24(filePath2))
|
|
96118
96210
|
return null;
|
|
96119
96211
|
try {
|
|
96120
|
-
const parsed = JSON.parse(await
|
|
96212
|
+
const parsed = JSON.parse(await readFile75(filePath2, "utf8"));
|
|
96121
96213
|
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
96122
96214
|
const candidate = parsed;
|
|
96123
96215
|
if (typeof candidate.builder_protocol === "string" && typeof candidate.fingerprint === "string" && typeof candidate.output_fingerprint === "string" && typeof candidate.output_files === "number" && Array.isArray(candidate.outputs)) {
|
|
@@ -96164,12 +96256,12 @@ async function writePackageFingerprint(input) {
|
|
|
96164
96256
|
`, "utf8");
|
|
96165
96257
|
}
|
|
96166
96258
|
async function removeOrphanPackageDirs(projectRoot, packages) {
|
|
96167
|
-
const distRoot =
|
|
96168
|
-
if (!
|
|
96259
|
+
const distRoot = join90(projectRoot, "dist");
|
|
96260
|
+
if (!existsSync24(distRoot))
|
|
96169
96261
|
return;
|
|
96170
96262
|
const declaredNames = new Set(packages.flatMap((pkg) => packageOutputDirs(pkg).map((path2) => path2.slice("dist/".length))));
|
|
96171
96263
|
const entries2 = await readdir21(distRoot, { withFileTypes: true });
|
|
96172
|
-
await Promise.all(entries2.filter((entry) => entry.isDirectory() && !declaredNames.has(entry.name)).map((entry) => rm20(
|
|
96264
|
+
await Promise.all(entries2.filter((entry) => entry.isDirectory() && !declaredNames.has(entry.name)).map((entry) => rm20(join90(distRoot, entry.name), { recursive: true, force: true, maxRetries: 3, retryDelay: 100 })));
|
|
96173
96265
|
}
|
|
96174
96266
|
async function collectPackageFreshness(projectRoot, packages) {
|
|
96175
96267
|
assertDistinctPackageOutputs(packages);
|
|
@@ -96178,8 +96270,8 @@ async function collectPackageFreshness(projectRoot, packages) {
|
|
|
96178
96270
|
assertPackageOutputDir(pkg);
|
|
96179
96271
|
const selected = selectPackageKnowledge(approved, pkg);
|
|
96180
96272
|
assertSafeRenderedPath(pkg.template.path, "package template path");
|
|
96181
|
-
const templateRoot =
|
|
96182
|
-
const templateExists =
|
|
96273
|
+
const templateRoot = join90(projectRoot, pkg.template.path);
|
|
96274
|
+
const templateExists = existsSync24(templateRoot);
|
|
96183
96275
|
if (!templateExists) {
|
|
96184
96276
|
throw new ContextError(ExitCode.WorkspaceStateError, `package template path is missing: ${pkg.template.path}`, {
|
|
96185
96277
|
category: ErrorCategory.WorkspaceStateInvalid,
|
|
@@ -96429,19 +96521,19 @@ async function buildProjectPackagesInternal(projectRoot, options) {
|
|
|
96429
96521
|
if (stagedPkg.kind === "package.llms") {
|
|
96430
96522
|
const articles = await Promise.all(llmsArticles(stagedPkg, selected).map(async (article) => ({
|
|
96431
96523
|
...article,
|
|
96432
|
-
content: await
|
|
96524
|
+
content: await readFile75(join90(projectRoot, stagedPkg.outDir, article.path), "utf8")
|
|
96433
96525
|
})));
|
|
96434
|
-
await writeLlmsDocuments(
|
|
96526
|
+
await writeLlmsDocuments(join90(projectRoot, stagedPkg.outDir), buildLlmsDocuments({
|
|
96435
96527
|
title: stagedPkg.name,
|
|
96436
96528
|
articles,
|
|
96437
96529
|
...reading ? { map: reading } : {}
|
|
96438
96530
|
}), { preserveIndex: true });
|
|
96439
96531
|
}
|
|
96440
|
-
await writePackageVersion(projectRoot,
|
|
96532
|
+
await writePackageVersion(projectRoot, join90(projectRoot, stagedPkg.outDir));
|
|
96441
96533
|
await writePackageSite({ projectRoot, pkg: stagedPkg, selected, ...siteUrl ? { siteUrl } : {}, ...reading ? { structure: reading } : {} });
|
|
96442
96534
|
const linkWarnings = [
|
|
96443
96535
|
...writtenKnowledge2.linkWarnings,
|
|
96444
|
-
...await inspectPackageMarkdownDirectory(
|
|
96536
|
+
...await inspectPackageMarkdownDirectory(join90(projectRoot, stagedPkg.outDir))
|
|
96445
96537
|
];
|
|
96446
96538
|
return { ...writtenKnowledge2, linkWarnings };
|
|
96447
96539
|
});
|
|
@@ -96586,7 +96678,7 @@ var init_packageBuilder = __esm(() => {
|
|
|
96586
96678
|
init_siteTranslation();
|
|
96587
96679
|
init_approvedKnowledgeMetadata();
|
|
96588
96680
|
import_yaml44 = __toESM(require_dist(), 1);
|
|
96589
|
-
PACKAGE_FINGERPRINT_ROOT =
|
|
96681
|
+
PACKAGE_FINGERPRINT_ROOT = join90(".tmp", "context-runtime", "packages");
|
|
96590
96682
|
});
|
|
96591
96683
|
|
|
96592
96684
|
// src/project/knowledgeMaintenance.ts
|
|
@@ -96601,15 +96693,15 @@ __export(exports_knowledgeMaintenance, {
|
|
|
96601
96693
|
cancelKnowledgeMaintenance: () => cancelKnowledgeMaintenance,
|
|
96602
96694
|
advanceKnowledgeMaintenance: () => advanceKnowledgeMaintenance
|
|
96603
96695
|
});
|
|
96604
|
-
import { readFile as
|
|
96605
|
-
import { join as
|
|
96696
|
+
import { readFile as readFile76, readdir as readdir22, rm as rm21 } from "node:fs/promises";
|
|
96697
|
+
import { join as join91 } from "node:path";
|
|
96606
96698
|
async function deliveryDigest(root) {
|
|
96607
|
-
const directory =
|
|
96699
|
+
const directory = join91(root, ".tmp/context-runtime/packages");
|
|
96608
96700
|
try {
|
|
96609
96701
|
const files = (await readdir22(directory)).filter((name3) => name3.endsWith(".json")).sort();
|
|
96610
96702
|
if (!files.length)
|
|
96611
96703
|
return indexerProtocolDigest(null);
|
|
96612
|
-
return indexerProtocolDigest(await Promise.all(files.map((name3) =>
|
|
96704
|
+
return indexerProtocolDigest(await Promise.all(files.map((name3) => readFile76(join91(directory, name3), "utf8"))));
|
|
96613
96705
|
} catch (error) {
|
|
96614
96706
|
if (error.code === "ENOENT")
|
|
96615
96707
|
return indexerProtocolDigest(null);
|
|
@@ -96752,7 +96844,7 @@ async function observeKnowledgeMaintenance(root) {
|
|
|
96752
96844
|
async function maintenanceRevision(root) {
|
|
96753
96845
|
const observed = await observeKnowledgeMaintenance(root);
|
|
96754
96846
|
const localInputs = observed.state.active ? {
|
|
96755
|
-
revision: await
|
|
96847
|
+
revision: await readFile76(join91(root, MAINTENANCE_ROOT, "revision.json"), "utf8").catch((error) => {
|
|
96756
96848
|
if (error.code === "ENOENT")
|
|
96757
96849
|
return null;
|
|
96758
96850
|
throw error;
|
|
@@ -96865,7 +96957,7 @@ async function finishMaintenanceRevision(root, outcome = "completed") {
|
|
|
96865
96957
|
outcome = state.active.completion_outcome;
|
|
96866
96958
|
state.active.phase = "finishing";
|
|
96867
96959
|
await saveMaintenance(root, state);
|
|
96868
|
-
await rm21(
|
|
96960
|
+
await rm21(join91(root, MAINTENANCE_ROOT, "revision.json"), { force: true });
|
|
96869
96961
|
state.completed.push({ id: state.active.input.id, input_digest: indexerProtocolDigest(state.active.input), outcome });
|
|
96870
96962
|
delete state.active;
|
|
96871
96963
|
await saveMaintenance(root, state);
|
|
@@ -96899,8 +96991,8 @@ async function discardMaintenanceDraft(root) {
|
|
|
96899
96991
|
const owned = new Set([...request?.batch_candidates ?? [], ...request?.candidate ? [request.candidate] : []].map((item) => item.candidate_id));
|
|
96900
96992
|
if (candidates.some((item) => !owned.has(item.candidate_id)))
|
|
96901
96993
|
throw new TypeError("Unrelated Candidates are present; no draft was discarded. Inspect the current review before retrying cancellation.");
|
|
96902
|
-
await rm21(
|
|
96903
|
-
await rm21(
|
|
96994
|
+
await rm21(join91(root, CANDIDATE_LEDGER_FILE), { force: true });
|
|
96995
|
+
await rm21(join91(root, MAINTENANCE_ROOT, "revision.json"), { force: true });
|
|
96904
96996
|
const { closeProjectWorkspace } = await Promise.resolve().then(() => (init_close(), exports_close));
|
|
96905
96997
|
const { buildProjectPackages: buildProjectPackages2 } = await Promise.resolve().then(() => (init_packageBuilder(), exports_packageBuilder));
|
|
96906
96998
|
await closeProjectWorkspace(root);
|
|
@@ -96928,8 +97020,8 @@ __export(exports_taskRollback, {
|
|
|
96928
97020
|
readTaskRollback: () => readTaskRollback,
|
|
96929
97021
|
finishTaskRollback: () => finishTaskRollback
|
|
96930
97022
|
});
|
|
96931
|
-
import { readFile as
|
|
96932
|
-
import { join as
|
|
97023
|
+
import { readFile as readFile77, rm as rm22 } from "node:fs/promises";
|
|
97024
|
+
import { join as join92 } from "node:path";
|
|
96933
97025
|
async function productionScope(projectRoot) {
|
|
96934
97026
|
const { readProductionStage: readProductionStage2 } = await Promise.resolve().then(() => (init_productionStageStore(), exports_productionStageStore));
|
|
96935
97027
|
const stage = await readProductionStage2(projectRoot);
|
|
@@ -96970,7 +97062,7 @@ async function readTaskRollback(projectRoot) {
|
|
|
96970
97062
|
}
|
|
96971
97063
|
async function contents(projectRoot, path2) {
|
|
96972
97064
|
try {
|
|
96973
|
-
return await
|
|
97065
|
+
return await readFile77(join92(projectRoot, path2), "utf8");
|
|
96974
97066
|
} catch (error) {
|
|
96975
97067
|
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT")
|
|
96976
97068
|
return;
|
|
@@ -97118,7 +97210,7 @@ async function finishTaskRollback(projectRoot) {
|
|
|
97118
97210
|
const production = await readProductionStage2(projectRoot);
|
|
97119
97211
|
const recorded = rollback.production;
|
|
97120
97212
|
if (production && recorded !== undefined && (recorded === null || !recorded.discard || recorded.stage !== production.id)) {
|
|
97121
|
-
await rm22(
|
|
97213
|
+
await rm22(join92(projectRoot, await revisionStoragePath(projectRoot)), { force: true });
|
|
97122
97214
|
return {
|
|
97123
97215
|
action: "finished",
|
|
97124
97216
|
production: recorded?.stage === production.id ? "resumed" : "kept",
|
|
@@ -97251,9 +97343,9 @@ __export(exports_close, {
|
|
|
97251
97343
|
approvedStructureInputHashFor: () => approvedStructureInputHashFor,
|
|
97252
97344
|
approvedKnowledgeInputHash: () => approvedKnowledgeInputHash
|
|
97253
97345
|
});
|
|
97254
|
-
import { existsSync as
|
|
97346
|
+
import { existsSync as existsSync25 } from "node:fs";
|
|
97255
97347
|
import { mkdir as mkdir34, writeFile as writeFile26 } from "node:fs/promises";
|
|
97256
|
-
import { dirname as dirname41, join as
|
|
97348
|
+
import { dirname as dirname41, join as join93 } from "node:path";
|
|
97257
97349
|
function parseFrontmatter4(content3) {
|
|
97258
97350
|
const match = /^---\r?\n([\s\S]*?)\r?\n---/u.exec(content3);
|
|
97259
97351
|
if (match?.[1] === undefined)
|
|
@@ -97325,7 +97417,7 @@ async function deriveApprovedStructure(projectRoot) {
|
|
|
97325
97417
|
}
|
|
97326
97418
|
async function writeApprovedStructureProjection(projectRoot) {
|
|
97327
97419
|
const { inputHash, structure, compactFiles } = await deriveApprovedStructure(projectRoot);
|
|
97328
|
-
const outputPath =
|
|
97420
|
+
const outputPath = join93(projectRoot, STRUCTURE_PATH4);
|
|
97329
97421
|
await mkdir34(dirname41(outputPath), { recursive: true });
|
|
97330
97422
|
await writeFile26(outputPath, import_yaml45.default.stringify(structure), "utf8");
|
|
97331
97423
|
await Promise.all(compactFiles.map((file) => writeFile26(file.absPath, file.content, "utf8")));
|
|
@@ -97336,11 +97428,11 @@ function referencesReceipt() {
|
|
|
97336
97428
|
}
|
|
97337
97429
|
async function readProjectCloseStatus(projectRoot) {
|
|
97338
97430
|
const approved = await approvedKnowledgeFiles(projectRoot);
|
|
97339
|
-
const structurePath =
|
|
97340
|
-
if (approved.length === 0 && !
|
|
97431
|
+
const structurePath = join93(projectRoot, STRUCTURE_PATH4);
|
|
97432
|
+
if (approved.length === 0 && !existsSync25(structurePath))
|
|
97341
97433
|
return { state: "missing", diagnostics: [] };
|
|
97342
97434
|
const inputHash = await approvedKnowledgeInputHash(projectRoot);
|
|
97343
|
-
if (!
|
|
97435
|
+
if (!existsSync25(structurePath))
|
|
97344
97436
|
return { state: "missing", inputHash, diagnostics: [`close structure is missing: ${STRUCTURE_PATH4}`] };
|
|
97345
97437
|
try {
|
|
97346
97438
|
const parsed = await readApprovedStructureValue(projectRoot);
|
|
@@ -97400,7 +97492,7 @@ async function closeProjectWorkspace(projectRoot) {
|
|
|
97400
97492
|
next: "Fix context verify errors, then rerun context close --format json."
|
|
97401
97493
|
});
|
|
97402
97494
|
}
|
|
97403
|
-
const outputPath =
|
|
97495
|
+
const outputPath = join93(projectRoot, STRUCTURE_PATH4);
|
|
97404
97496
|
await mkdir34(dirname41(outputPath), { recursive: true });
|
|
97405
97497
|
await writeFile26(outputPath, `${import_yaml45.default.stringify(structure)}`, "utf8");
|
|
97406
97498
|
await Promise.all(compactFiles.map((file) => writeFile26(file.absPath, file.content, "utf8")));
|
|
@@ -97477,7 +97569,7 @@ var init_close = __esm(() => {
|
|
|
97477
97569
|
init_knowledgeAssetRepair();
|
|
97478
97570
|
init_approvedKnowledgeMetadata();
|
|
97479
97571
|
import_yaml45 = __toESM(require_dist(), 1);
|
|
97480
|
-
STRUCTURE_PATH4 =
|
|
97572
|
+
STRUCTURE_PATH4 = join93(KNOWLEDGE_ROOT, "structure.yaml");
|
|
97481
97573
|
});
|
|
97482
97574
|
|
|
97483
97575
|
// src/project/processedScopeStorage.ts
|
|
@@ -97490,8 +97582,8 @@ __export(exports_processedScopeStorage, {
|
|
|
97490
97582
|
commitProcessedScopes: () => commitProcessedScopes,
|
|
97491
97583
|
captureProcessedScopes: () => captureProcessedScopes
|
|
97492
97584
|
});
|
|
97493
|
-
import { access as access6, readFile as
|
|
97494
|
-
import { dirname as dirname42, join as
|
|
97585
|
+
import { access as access6, readFile as readFile78 } from "node:fs/promises";
|
|
97586
|
+
import { dirname as dirname42, join as join94 } from "node:path";
|
|
97495
97587
|
async function currentScopeSourceVersion(projectRoot, sourceRef) {
|
|
97496
97588
|
if (sourceRef.startsWith("repo-content:"))
|
|
97497
97589
|
return repoContentWorkingVersion(projectRoot, sourceRef);
|
|
@@ -97517,7 +97609,7 @@ async function currentScopeSourceVersion(projectRoot, sourceRef) {
|
|
|
97517
97609
|
throw new TypeError(`Source must identify one registered document: ${sourceRef}`);
|
|
97518
97610
|
const entry = entries2[0];
|
|
97519
97611
|
const manifest = entry.snapshot?.manifest ?? `${entry.materializedAt}/manifest.json`;
|
|
97520
|
-
return parseDocumentSnapshotForSource(JSON.parse(await
|
|
97612
|
+
return parseDocumentSnapshotForSource(JSON.parse(await readFile78(join94(projectRoot, manifest), "utf8")), entry.name).snapshot_hash;
|
|
97521
97613
|
}
|
|
97522
97614
|
async function sourceMaterialAvailable(projectRoot, sourceRef) {
|
|
97523
97615
|
try {
|
|
@@ -97540,10 +97632,10 @@ async function sourceMaterialAvailable(projectRoot, sourceRef) {
|
|
|
97540
97632
|
if (entries2.length !== 1)
|
|
97541
97633
|
return false;
|
|
97542
97634
|
const manifestPath = entries2[0].snapshot?.manifest ?? `${entries2[0].materializedAt}/manifest.json`;
|
|
97543
|
-
const snapshot = parseDocumentSnapshotForSource(JSON.parse(await
|
|
97544
|
-
const base =
|
|
97635
|
+
const snapshot = parseDocumentSnapshotForSource(JSON.parse(await readFile78(join94(projectRoot, manifestPath), "utf8")), entries2[0].name);
|
|
97636
|
+
const base = join94(projectRoot, dirname42(manifestPath));
|
|
97545
97637
|
for (const file of snapshot.files)
|
|
97546
|
-
await access6(
|
|
97638
|
+
await access6(join94(base, file.path));
|
|
97547
97639
|
return true;
|
|
97548
97640
|
} catch {
|
|
97549
97641
|
return false;
|
|
@@ -97581,7 +97673,7 @@ async function commitProcessedScopes(projectRoot, scopes) {
|
|
|
97581
97673
|
const { articles } = await inspectSettledReferences(projectRoot, repoContent, scopes.map((scope2) => scope2.source_ref), settled);
|
|
97582
97674
|
const { approvedStructureInputHashFor: approvedStructureInputHashFor2 } = await Promise.resolve().then(() => (init_close(), exports_close));
|
|
97583
97675
|
const input_hash = structure.parsed.input_hash === await approvedStructureInputHashFor2(projectRoot, previous2) ? await approvedStructureInputHashFor2(projectRoot, articles) : structure.parsed.input_hash;
|
|
97584
|
-
await atomicWriteFile(
|
|
97676
|
+
await atomicWriteFile(join94(projectRoot, structure.path), import_yaml46.default.stringify({ ...structure.parsed, input_hash, articles, processed_scopes: processed }));
|
|
97585
97677
|
}
|
|
97586
97678
|
async function invalidateChangedProcessedRequirements(projectRoot, previous2, current3) {
|
|
97587
97679
|
const targets = new Map(current3.map((requirement2) => [requirement2.id, indexerProtocolDigest(requirement2)]));
|
|
@@ -97595,7 +97687,7 @@ async function invalidateChangedProcessedRequirements(projectRoot, previous2, cu
|
|
|
97595
97687
|
const retained = scopes.filter((scope2) => !changed.has(scope2.requirement_ref));
|
|
97596
97688
|
if (retained.length === scopes.length)
|
|
97597
97689
|
return;
|
|
97598
|
-
await atomicWriteFile(
|
|
97690
|
+
await atomicWriteFile(join94(projectRoot, structure.path), import_yaml46.default.stringify({ ...structure.parsed, processed_scopes: retained }));
|
|
97599
97691
|
}
|
|
97600
97692
|
async function migrateUnchangedScopeReferences(projectRoot, scopes) {
|
|
97601
97693
|
const structure = await readKnowledgeStructure(projectRoot);
|
|
@@ -97614,7 +97706,7 @@ async function migrateUnchangedScopeReferences(projectRoot, scopes) {
|
|
|
97614
97706
|
}
|
|
97615
97707
|
const { approvedStructureInputHashFor: approvedStructureInputHashFor2 } = await Promise.resolve().then(() => (init_close(), exports_close));
|
|
97616
97708
|
const input_hash = structure.parsed.input_hash === await approvedStructureInputHashFor2(projectRoot, previous2) ? await approvedStructureInputHashFor2(projectRoot, second.articles) : structure.parsed.input_hash;
|
|
97617
|
-
await atomicWriteFile(
|
|
97709
|
+
await atomicWriteFile(join94(projectRoot, structure.path), import_yaml46.default.stringify({ ...structure.parsed, input_hash, articles: second.articles }));
|
|
97618
97710
|
return previous2.flatMap((article) => article.sections.flatMap((section) => section.references.flatMap((before, index3) => {
|
|
97619
97711
|
const after = second.articles.find((item) => item.path === article.path).sections.find((item) => item.id === section.id).references[index3];
|
|
97620
97712
|
return indexerProtocolDigest(before) === indexerProtocolDigest(after) ? [] : [{ article: article.path, section: section.id, before, after }];
|
|
@@ -97633,7 +97725,7 @@ var init_processedScopeStorage = __esm(() => {
|
|
|
97633
97725
|
});
|
|
97634
97726
|
|
|
97635
97727
|
// src/project/codeAnalysisInput.ts
|
|
97636
|
-
import { readFile as
|
|
97728
|
+
import { readFile as readFile79 } from "node:fs/promises";
|
|
97637
97729
|
import { relative as relative28, resolve as resolve32 } from "node:path";
|
|
97638
97730
|
function safeCodeSourcePath(root, normalizedPath) {
|
|
97639
97731
|
const absolute = resolve32(root, normalizedPath);
|
|
@@ -97676,7 +97768,7 @@ function sourceFileSystem(root, tracked, texts, readSource) {
|
|
|
97676
97768
|
return {
|
|
97677
97769
|
readFile: async (path2) => {
|
|
97678
97770
|
const normalized = assertTrackedFile(path2);
|
|
97679
|
-
return contents2.has(normalized) ? contents2.get(normalized) : readSource ? readSource(normalized) :
|
|
97771
|
+
return contents2.has(normalized) ? contents2.get(normalized) : readSource ? readSource(normalized) : readFile79(safeCodeSourcePath(root, normalized), "utf8");
|
|
97680
97772
|
},
|
|
97681
97773
|
async readdir(path2) {
|
|
97682
97774
|
const normalized = normalizedVirtualPath(path2);
|
|
@@ -97738,7 +97830,7 @@ async function prepareCodeAnalysisInput(input) {
|
|
|
97738
97830
|
var init_codeAnalysisInput = () => {};
|
|
97739
97831
|
|
|
97740
97832
|
// src/project/revisionProtocolDeclarations.ts
|
|
97741
|
-
import { posix as
|
|
97833
|
+
import { posix as posix12 } from "node:path";
|
|
97742
97834
|
async function loadRevisionProtocolDependencies(capability, loadedModule, initial, trackedPaths, readSource) {
|
|
97743
97835
|
const isProto = capability === "parser.proto";
|
|
97744
97836
|
const exportName = isProto ? "lexProto" : "lexThrift";
|
|
@@ -97770,7 +97862,7 @@ async function loadRevisionProtocolDependencies(capability, loadedModule, initia
|
|
|
97770
97862
|
if (!name3 || name3.startsWith("/") || name3.includes("\\") || name3.split("/").some((part) => !part || part === "." || part === "..")) {
|
|
97771
97863
|
throw new TypeError(`Protocol import ${name3} in ${path2} escapes the captured source scope`);
|
|
97772
97864
|
}
|
|
97773
|
-
const candidates = isProto ? [name3] : [
|
|
97865
|
+
const candidates = isProto ? [name3] : [posix12.join(posix12.dirname(path2), name3), name3];
|
|
97774
97866
|
const dependency = candidates.find((candidate) => tracked.has(candidate));
|
|
97775
97867
|
if (!dependency)
|
|
97776
97868
|
throw new TypeError(`Protocol import ${name3} in ${path2} is missing from the captured source scope`);
|
|
@@ -97863,7 +97955,7 @@ __export(exports_approvedRevisionPrograms, {
|
|
|
97863
97955
|
});
|
|
97864
97956
|
import { execFile as execFile16 } from "node:child_process";
|
|
97865
97957
|
import { promisify as promisify13 } from "node:util";
|
|
97866
|
-
import { extname as extname11, join as
|
|
97958
|
+
import { extname as extname11, join as join95 } from "node:path";
|
|
97867
97959
|
import { createRequire as createRequire6 } from "node:module";
|
|
97868
97960
|
import { pathToFileURL } from "node:url";
|
|
97869
97961
|
async function prepareRevisionProgramBlocks(root, sourceRefs, scopes, references) {
|
|
@@ -97879,7 +97971,7 @@ async function prepareRevisionProgramBlocks(root, sourceRefs, scopes, references
|
|
|
97879
97971
|
if (entries2.length !== 1)
|
|
97880
97972
|
throw new TypeError(`Regeneration requires one registered source: ${source2}`);
|
|
97881
97973
|
const entry = entries2[0];
|
|
97882
|
-
const directory =
|
|
97974
|
+
const directory = join95(root, entry.materializedAt);
|
|
97883
97975
|
const paths = [...new Set(references.filter((reference2) => reference2.source_ref === source2).map((reference2) => reference2.locator.path))];
|
|
97884
97976
|
if (!paths.length)
|
|
97885
97977
|
continue;
|
|
@@ -98011,7 +98103,7 @@ var exports_approvedPageMove = {};
|
|
|
98011
98103
|
__export(exports_approvedPageMove, {
|
|
98012
98104
|
moveKnowledgeLinkTargets: () => moveKnowledgeLinkTargets
|
|
98013
98105
|
});
|
|
98014
|
-
import { posix as
|
|
98106
|
+
import { posix as posix13 } from "node:path";
|
|
98015
98107
|
function moveKnowledgeLinkTargets(content3, pagePath, previousPath, moves) {
|
|
98016
98108
|
return replaceMarkdownInlineLinkTargets(content3, (link) => {
|
|
98017
98109
|
const target = link.target;
|
|
@@ -98035,11 +98127,11 @@ function moveKnowledgeLinkTargets(content3, pagePath, previousPath, moves) {
|
|
|
98035
98127
|
if (!path2 || path2.startsWith("/") && !path2.startsWith("/knowledge/"))
|
|
98036
98128
|
return;
|
|
98037
98129
|
const rooted = path2.startsWith("knowledge/") || path2.startsWith("/knowledge/");
|
|
98038
|
-
const resolved = rooted ? path2.replace(/^\/?knowledge\//u, "") :
|
|
98130
|
+
const resolved = rooted ? path2.replace(/^\/?knowledge\//u, "") : posix13.normalize(posix13.join(posix13.dirname(previousPath), path2));
|
|
98039
98131
|
const destination = moves.get(resolved) ?? resolved;
|
|
98040
|
-
if (destination === resolved && (rooted ||
|
|
98132
|
+
if (destination === resolved && (rooted || posix13.dirname(pagePath) === posix13.dirname(previousPath)))
|
|
98041
98133
|
return;
|
|
98042
|
-
const rewritten = rooted ? `${path2.startsWith("/") ? "/" : ""}knowledge/${destination}` :
|
|
98134
|
+
const rewritten = rooted ? `${path2.startsWith("/") ? "/" : ""}knowledge/${destination}` : posix13.relative(posix13.dirname(pagePath), destination);
|
|
98043
98135
|
return `${encodeURI(rewritten)}${match[2]}`;
|
|
98044
98136
|
});
|
|
98045
98137
|
}
|
|
@@ -98065,8 +98157,8 @@ __export(exports_approvedRevision, {
|
|
|
98065
98157
|
assertApprovedRevisionBase: () => assertApprovedRevisionBase,
|
|
98066
98158
|
APPROVED_REVISION_PATH: () => APPROVED_REVISION_PATH
|
|
98067
98159
|
});
|
|
98068
|
-
import { readFile as
|
|
98069
|
-
import { join as
|
|
98160
|
+
import { readFile as readFile80, realpath as realpath14, rm as rm23 } from "node:fs/promises";
|
|
98161
|
+
import { join as join96, relative as relative29, isAbsolute as isAbsolute16 } from "node:path";
|
|
98070
98162
|
function requestDigest(input) {
|
|
98071
98163
|
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}/`)));
|
|
98072
98164
|
const ids = new Set(scopes?.map((scope2) => scope2.requirement_ref));
|
|
@@ -98104,7 +98196,7 @@ function revisionCandidateFingerprint(revision, markdown, sections) {
|
|
|
98104
98196
|
}
|
|
98105
98197
|
async function readApprovedRevision(projectRoot) {
|
|
98106
98198
|
try {
|
|
98107
|
-
return parseApprovedRevision(JSON.parse(await
|
|
98199
|
+
return parseApprovedRevision(JSON.parse(await readFile80(join96(projectRoot, await revisionStoragePath(projectRoot)), "utf8")));
|
|
98108
98200
|
} catch (error) {
|
|
98109
98201
|
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT")
|
|
98110
98202
|
return;
|
|
@@ -98163,16 +98255,16 @@ async function resolveApprovedRevisionAuthor(projectRoot, request) {
|
|
|
98163
98255
|
}
|
|
98164
98256
|
async function targetBytes(projectRoot, path2) {
|
|
98165
98257
|
const project = await realpath14(projectRoot);
|
|
98166
|
-
const root = await realpath14(
|
|
98258
|
+
const root = await realpath14(join96(projectRoot, "knowledge"));
|
|
98167
98259
|
const rootRelative = relative29(project, root);
|
|
98168
98260
|
if (isAbsolute16(rootRelative) || rootRelative === ".." || rootRelative.startsWith("../")) {
|
|
98169
98261
|
throw new TypeError("Approved knowledge directory leaves the Context workspace");
|
|
98170
98262
|
}
|
|
98171
|
-
const target = await realpath14(
|
|
98263
|
+
const target = await realpath14(join96(root, path2));
|
|
98172
98264
|
const rel = relative29(root, target);
|
|
98173
98265
|
if (isAbsolute16(rel) || rel === ".." || rel.startsWith("../"))
|
|
98174
98266
|
throw new TypeError("Approved revision target leaves knowledge/");
|
|
98175
|
-
return
|
|
98267
|
+
return readFile80(target, "utf8");
|
|
98176
98268
|
}
|
|
98177
98269
|
async function assertApprovedRevisionBase(projectRoot, request) {
|
|
98178
98270
|
let current3;
|
|
@@ -98325,7 +98417,7 @@ ${import_yaml47.default.stringify({ ...import_yaml47.default.parse(fields), type
|
|
|
98325
98417
|
revision: requestDigest(payload)
|
|
98326
98418
|
});
|
|
98327
98419
|
if (input.persist !== false) {
|
|
98328
|
-
await atomicWriteFile(
|
|
98420
|
+
await atomicWriteFile(join96(input.projectRoot, await revisionStoragePath(input.projectRoot)), `${JSON.stringify(request)}
|
|
98329
98421
|
`);
|
|
98330
98422
|
markSubmissionState("committed");
|
|
98331
98423
|
}
|
|
@@ -98453,7 +98545,7 @@ async function completeApprovedRevision(input) {
|
|
|
98453
98545
|
const { prepareRevisionBatchContinuation: prepareRevisionBatchContinuation3 } = await Promise.resolve().then(() => (init_approvedRevisionBatch(), exports_approvedRevisionBatch));
|
|
98454
98546
|
const next2 = await prepareRevisionBatchContinuation3(input.projectRoot, request, request.batch_candidates ?? []);
|
|
98455
98547
|
if (next2 || request.batch_candidates?.length || request.build_pending) {
|
|
98456
|
-
await atomicWriteFile(
|
|
98548
|
+
await atomicWriteFile(join96(input.projectRoot, await revisionStoragePath(input.projectRoot)), `${JSON.stringify(next2 ?? { ...request, review_ready: true })}
|
|
98457
98549
|
`);
|
|
98458
98550
|
markSubmissionState("committed");
|
|
98459
98551
|
} else {
|
|
@@ -98461,10 +98553,10 @@ async function completeApprovedRevision(input) {
|
|
|
98461
98553
|
}
|
|
98462
98554
|
return;
|
|
98463
98555
|
}
|
|
98464
|
-
const current3 = await
|
|
98556
|
+
const current3 = await readFile80(join96(input.projectRoot, await revisionStoragePath(input.projectRoot)), "utf8");
|
|
98465
98557
|
let previous2;
|
|
98466
98558
|
try {
|
|
98467
|
-
previous2 = await
|
|
98559
|
+
previous2 = await readFile80(join96(input.projectRoot, CANDIDATE_LEDGER_FILE), "utf8");
|
|
98468
98560
|
} catch (error) {
|
|
98469
98561
|
if (!(error && typeof error === "object" && ("code" in error) && error.code === "ENOENT"))
|
|
98470
98562
|
throw error;
|
|
@@ -98559,7 +98651,7 @@ async function advanceApprovedRevision(projectRoot, request, buildPending = fals
|
|
|
98559
98651
|
return;
|
|
98560
98652
|
const { readProductionStage: readProductionStage2 } = await Promise.resolve().then(() => (init_productionStageStore(), exports_productionStageStore));
|
|
98561
98653
|
if (await readProductionStage2(projectRoot)) {
|
|
98562
|
-
await rm23(
|
|
98654
|
+
await rm23(join96(projectRoot, await revisionStoragePath(projectRoot)), { force: true });
|
|
98563
98655
|
return;
|
|
98564
98656
|
}
|
|
98565
98657
|
const { clearCompletedLifecycle: clearCompletedLifecycle2 } = await Promise.resolve().then(() => (init_lifecycleCleanup(), exports_lifecycleCleanup));
|
|
@@ -98663,12 +98755,12 @@ Additional request: ${input.instruction.trim()}` : input.instruction.trim();
|
|
|
98663
98755
|
}))
|
|
98664
98756
|
} : {}
|
|
98665
98757
|
} };
|
|
98666
|
-
const current3 = await
|
|
98758
|
+
const current3 = await readFile80(join96(input.projectRoot, await revisionStoragePath(input.projectRoot)), "utf8");
|
|
98667
98759
|
const content3 = `${JSON.stringify({ ...payload, revision: requestDigest(payload) })}
|
|
98668
98760
|
`;
|
|
98669
98761
|
let ledger;
|
|
98670
98762
|
try {
|
|
98671
|
-
ledger = await
|
|
98763
|
+
ledger = await readFile80(join96(input.projectRoot, CANDIDATE_LEDGER_FILE), "utf8");
|
|
98672
98764
|
} catch (error) {
|
|
98673
98765
|
if (!(error && typeof error === "object" && ("code" in error) && error.code === "ENOENT"))
|
|
98674
98766
|
throw error;
|
|
@@ -98788,8 +98880,8 @@ var init_sourceInputMutation = __esm(() => {
|
|
|
98788
98880
|
|
|
98789
98881
|
// src/project/documentCapture.ts
|
|
98790
98882
|
import { createHash as createHash29 } from "node:crypto";
|
|
98791
|
-
import { lstat as lstat15, mkdir as mkdir35, readdir as readdir23, readFile as
|
|
98792
|
-
import { basename as basename7, dirname as dirname43, extname as extname12, join as
|
|
98883
|
+
import { lstat as lstat15, mkdir as mkdir35, readdir as readdir23, readFile as readFile81, rm as rm24, stat as stat10, writeFile as writeFile27 } from "node:fs/promises";
|
|
98884
|
+
import { basename as basename7, dirname as dirname43, extname as extname12, join as join97, relative as relative30, resolve as resolve33 } from "node:path";
|
|
98793
98885
|
function toPosixPath7(path2) {
|
|
98794
98886
|
return path2.split(/[\\/]+/u).filter((part) => part.length > 0).join("/");
|
|
98795
98887
|
}
|
|
@@ -98927,7 +99019,7 @@ async function walkMarkdownFiles(input) {
|
|
|
98927
99019
|
const visit3 = async (dir) => {
|
|
98928
99020
|
const entries2 = await readdir23(dir, { withFileTypes: true });
|
|
98929
99021
|
for (const entry of entries2) {
|
|
98930
|
-
const absolutePath =
|
|
99022
|
+
const absolutePath = join97(dir, entry.name);
|
|
98931
99023
|
if (entry.isSymbolicLink() && input.rejectSymlinks === true) {
|
|
98932
99024
|
throw new ContextError(ExitCode.UserError, `file source contains a symbolic link: ${toPosixPath7(relative30(input.localRoot, absolutePath))}`, {
|
|
98933
99025
|
category: ErrorCategory.UserInputInvalid,
|
|
@@ -98957,14 +99049,14 @@ async function walkMarkdownFiles(input) {
|
|
|
98957
99049
|
}
|
|
98958
99050
|
async function writeTextIfChanged(path2, content3) {
|
|
98959
99051
|
try {
|
|
98960
|
-
if (await
|
|
99052
|
+
if (await readFile81(path2, "utf8") === content3)
|
|
98961
99053
|
return;
|
|
98962
99054
|
} catch {}
|
|
98963
99055
|
await mkdir35(dirname43(path2), { recursive: true });
|
|
98964
99056
|
await writeFile27(path2, content3, "utf8");
|
|
98965
99057
|
}
|
|
98966
99058
|
function sourceManifestPath(entry) {
|
|
98967
|
-
return entry.snapshot?.manifest ??
|
|
99059
|
+
return entry.snapshot?.manifest ?? join97(entry.materializedAt, "manifest.json");
|
|
98968
99060
|
}
|
|
98969
99061
|
function runtimeError2(message, detail) {
|
|
98970
99062
|
return new ContextError(ExitCode.UserError, message, {
|
|
@@ -99069,7 +99161,7 @@ async function removeEmptySnapshotDirs(root, dir = root) {
|
|
|
99069
99161
|
for (const entry of entries2) {
|
|
99070
99162
|
if (!entry.isDirectory() || entry.name === ".tmp" || entry.name === ".cache")
|
|
99071
99163
|
continue;
|
|
99072
|
-
await removeEmptySnapshotDirs(root,
|
|
99164
|
+
await removeEmptySnapshotDirs(root, join97(dir, entry.name));
|
|
99073
99165
|
}
|
|
99074
99166
|
if (dir === root)
|
|
99075
99167
|
return;
|
|
@@ -99081,7 +99173,7 @@ async function removeEmptySnapshotDirs(root, dir = root) {
|
|
|
99081
99173
|
async function cleanupStaleSnapshotFiles(input) {
|
|
99082
99174
|
for (const path2 of input.previousPaths) {
|
|
99083
99175
|
if (!input.currentPaths.has(path2)) {
|
|
99084
|
-
await rm24(
|
|
99176
|
+
await rm24(join97(input.materializedAtAbsPath, path2), { force: true });
|
|
99085
99177
|
}
|
|
99086
99178
|
}
|
|
99087
99179
|
await removeEmptySnapshotDirs(input.materializedAtAbsPath);
|
|
@@ -99093,7 +99185,7 @@ async function readDocumentFiles(input) {
|
|
|
99093
99185
|
for (const file of input.files) {
|
|
99094
99186
|
let raw;
|
|
99095
99187
|
try {
|
|
99096
|
-
raw = await
|
|
99188
|
+
raw = await readFile81(file.absolutePath, "utf8");
|
|
99097
99189
|
} catch (error) {
|
|
99098
99190
|
const message = error instanceof Error ? error.message : String(error);
|
|
99099
99191
|
throw runtimeError2(`file source ${input.sourceName} document read failed: ${file.snapshotPath}: ${message}`, {
|
|
@@ -99294,9 +99386,9 @@ async function runCaptureFilePhaseUnlocked(input) {
|
|
|
99294
99386
|
routeMetadata,
|
|
99295
99387
|
documentSnapshot
|
|
99296
99388
|
});
|
|
99297
|
-
const manifestAbsPath =
|
|
99389
|
+
const manifestAbsPath = join97(input.projectRoot, manifestPath);
|
|
99298
99390
|
const materializedAt = entry.materializedAt;
|
|
99299
|
-
const materializedAtAbsPath =
|
|
99391
|
+
const materializedAtAbsPath = join97(input.projectRoot, materializedAt);
|
|
99300
99392
|
const manifestInput = {
|
|
99301
99393
|
sourceType: "file",
|
|
99302
99394
|
sourceName: resolved.sourceName,
|
|
@@ -99348,13 +99440,13 @@ async function runCaptureFilePhaseUnlocked(input) {
|
|
|
99348
99440
|
}));
|
|
99349
99441
|
try {
|
|
99350
99442
|
for (const file of snapshotFiles) {
|
|
99351
|
-
await writeTextIfChanged(
|
|
99443
|
+
await writeTextIfChanged(join97(materializedAtAbsPath, file.path), String(file.bytes));
|
|
99352
99444
|
}
|
|
99353
99445
|
for (const file of files.metadata) {
|
|
99354
|
-
await writeTextIfChanged(
|
|
99446
|
+
await writeTextIfChanged(join97(materializedAtAbsPath, file.snapshotPath), routeMetadata.rawByPath.get(file.snapshotPath) ?? "");
|
|
99355
99447
|
}
|
|
99356
99448
|
for (const asset of linkedAssets) {
|
|
99357
|
-
await writeCaptureAssetIfChanged(
|
|
99449
|
+
await writeCaptureAssetIfChanged(join97(materializedAtAbsPath, asset.snapshotPath), asset.bytes);
|
|
99358
99450
|
}
|
|
99359
99451
|
await writeTextIfChanged(manifestAbsPath, manifestContent);
|
|
99360
99452
|
await cleanupStaleSnapshotFiles({
|
|
@@ -99556,7 +99648,7 @@ var init_entityId = __esm(() => {
|
|
|
99556
99648
|
// src/project/reviewShared.ts
|
|
99557
99649
|
import { createHash as createHash30 } from "node:crypto";
|
|
99558
99650
|
import { mkdir as mkdir36, writeFile as writeFile28 } from "node:fs/promises";
|
|
99559
|
-
import { dirname as dirname44, join as
|
|
99651
|
+
import { dirname as dirname44, join as join98 } from "node:path";
|
|
99560
99652
|
function isRecord14(value) {
|
|
99561
99653
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
99562
99654
|
}
|
|
@@ -99599,7 +99691,7 @@ async function buildApprovedArticleIndex(projectRoot) {
|
|
|
99599
99691
|
if (!isApprovedKnowledgeMarkdownPath(rel))
|
|
99600
99692
|
continue;
|
|
99601
99693
|
const { absPath, content: content3 } = file;
|
|
99602
|
-
const relPath =
|
|
99694
|
+
const relPath = join98("knowledge", collection, rel);
|
|
99603
99695
|
assetReferencesByRelPath.set(relPath, knowledgeAssetReferences({
|
|
99604
99696
|
pageRelPath: relPath,
|
|
99605
99697
|
content: content3
|
|
@@ -99612,7 +99704,7 @@ async function buildApprovedArticleIndex(projectRoot) {
|
|
|
99612
99704
|
continue;
|
|
99613
99705
|
const frontmatter2 = hydrateApprovedFrontmatter({
|
|
99614
99706
|
frontmatter: parsed,
|
|
99615
|
-
relPath:
|
|
99707
|
+
relPath: join98(collection, rel),
|
|
99616
99708
|
metadata
|
|
99617
99709
|
});
|
|
99618
99710
|
const article = articlesByPath.get(`${collection}/${rel}`);
|
|
@@ -99667,8 +99759,8 @@ ${yaml3}
|
|
|
99667
99759
|
}
|
|
99668
99760
|
async function writeReviewActionLog(input) {
|
|
99669
99761
|
const stamp = new Date().toISOString().replace(/[-:.TZ]/gu, "");
|
|
99670
|
-
const relPath =
|
|
99671
|
-
const path2 =
|
|
99762
|
+
const relPath = join98(REVIEW_ACTION_ROOT2, `${stamp}-${input.action}-${input.id.replace(/[\\/]+/gu, "_")}.json`);
|
|
99763
|
+
const path2 = join98(input.projectRoot, relPath);
|
|
99672
99764
|
await mkdir36(dirname44(path2), { recursive: true });
|
|
99673
99765
|
await writeFile28(path2, `${JSON.stringify({
|
|
99674
99766
|
action: input.action,
|
|
@@ -99701,7 +99793,7 @@ var init_reviewShared = __esm(() => {
|
|
|
99701
99793
|
init_knowledgeAssets();
|
|
99702
99794
|
init_entityId();
|
|
99703
99795
|
import_yaml48 = __toESM(require_dist(), 1);
|
|
99704
|
-
REVIEW_ACTION_ROOT2 =
|
|
99796
|
+
REVIEW_ACTION_ROOT2 = join98(".tmp", "context-runtime", "review-actions");
|
|
99705
99797
|
});
|
|
99706
99798
|
|
|
99707
99799
|
// src/project/managedDocumentStatus.ts
|
|
@@ -99776,17 +99868,17 @@ __export(exports_statusReaders, {
|
|
|
99776
99868
|
loadStatusPhases: () => loadStatusPhases,
|
|
99777
99869
|
countFiles: () => countFiles
|
|
99778
99870
|
});
|
|
99779
|
-
import { existsSync as
|
|
99780
|
-
import { join as
|
|
99871
|
+
import { existsSync as existsSync26, readFileSync as readFileSync9 } from "node:fs";
|
|
99872
|
+
import { join as join99 } from "node:path";
|
|
99781
99873
|
async function countFiles(root, predicate) {
|
|
99782
|
-
if (!
|
|
99874
|
+
if (!existsSync26(root))
|
|
99783
99875
|
return 0;
|
|
99784
99876
|
let count = 0;
|
|
99785
99877
|
const visit3 = async (dir, prefix = "") => {
|
|
99786
99878
|
const entries2 = await readCommandDirectory(dir);
|
|
99787
99879
|
for (const entry of entries2) {
|
|
99788
99880
|
const rel = prefix.length === 0 ? entry.name : `${prefix}/${entry.name}`;
|
|
99789
|
-
const abs =
|
|
99881
|
+
const abs = join99(dir, entry.name);
|
|
99790
99882
|
if (entry.isDirectory())
|
|
99791
99883
|
await visit3(abs, rel);
|
|
99792
99884
|
else if (entry.isFile() && predicate(rel))
|
|
@@ -99988,8 +100080,8 @@ async function documentSourceSiteHint(input) {
|
|
|
99988
100080
|
});
|
|
99989
100081
|
}
|
|
99990
100082
|
function documentSnapshotReadiness(input) {
|
|
99991
|
-
const manifestPath =
|
|
99992
|
-
if (!
|
|
100083
|
+
const manifestPath = join99(input.projectRoot, input.manifest);
|
|
100084
|
+
if (!existsSync26(manifestPath)) {
|
|
99993
100085
|
return {
|
|
99994
100086
|
ready: false,
|
|
99995
100087
|
diagnostics: [`snapshot is missing: ${input.manifest}`],
|
|
@@ -100069,7 +100161,7 @@ function documentSnapshotReadiness(input) {
|
|
|
100069
100161
|
const missingFiles = [
|
|
100070
100162
|
...manifest.files.map((file) => file.path),
|
|
100071
100163
|
...(manifest.assets ?? []).filter((asset) => asset.content_hash !== undefined).map((asset) => asset.path)
|
|
100072
|
-
].filter((path2) => !
|
|
100164
|
+
].filter((path2) => !existsSync26(join99(input.projectRoot, input.materializedAt, path2)));
|
|
100073
100165
|
if (missingFiles.length > 0) {
|
|
100074
100166
|
return {
|
|
100075
100167
|
ready: false,
|
|
@@ -100116,12 +100208,12 @@ var init_statusReaders = __esm(() => {
|
|
|
100116
100208
|
|
|
100117
100209
|
// src/project/documentCaptureAvailability.ts
|
|
100118
100210
|
import { createHash as createHash31 } from "node:crypto";
|
|
100119
|
-
import { readFile as
|
|
100120
|
-
import { join as
|
|
100211
|
+
import { readFile as readFile82, rm as rm25 } from "node:fs/promises";
|
|
100212
|
+
import { join as join100 } from "node:path";
|
|
100121
100213
|
import { isDeepStrictEqual } from "node:util";
|
|
100122
100214
|
function receiptPath(root, phaseId) {
|
|
100123
100215
|
const key = createHash31("sha256").update(phaseId).digest("hex");
|
|
100124
|
-
return
|
|
100216
|
+
return join100(root, ".tmp/context-runtime/document-acquisition", `${key}.json`);
|
|
100125
100217
|
}
|
|
100126
100218
|
async function identity(root, phase) {
|
|
100127
100219
|
const resolved = await resolveDocumentPhaseSource({ projectRoot: root, phase });
|
|
@@ -100156,7 +100248,7 @@ async function runDocumentCaptureWithAvailability(root, phase, capture2) {
|
|
|
100156
100248
|
...Array.isArray(error.detail.access_events) ? { access_events: error.detail.access_events } : {},
|
|
100157
100249
|
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."
|
|
100158
100250
|
};
|
|
100159
|
-
await applyAtomicFileBatch({ transactionRoot:
|
|
100251
|
+
await applyAtomicFileBatch({ transactionRoot: join100(root, ".tmp/context-runtime/transactions"), writes: [{ path: path2, bytes: `${JSON.stringify({ configuration, warning }, null, 2)}
|
|
100160
100252
|
` }] });
|
|
100161
100253
|
return {
|
|
100162
100254
|
kind: "document.capture.warning",
|
|
@@ -100173,7 +100265,7 @@ async function attachDocumentAcquisitionWarnings(root, phases, sources) {
|
|
|
100173
100265
|
continue;
|
|
100174
100266
|
let receipt2;
|
|
100175
100267
|
try {
|
|
100176
|
-
receipt2 = JSON.parse(await
|
|
100268
|
+
receipt2 = JSON.parse(await readFile82(receiptPath(root, phase.id), "utf8"));
|
|
100177
100269
|
} catch {
|
|
100178
100270
|
continue;
|
|
100179
100271
|
}
|
|
@@ -100590,7 +100682,7 @@ var init_workflowHostPlans = __esm(() => {
|
|
|
100590
100682
|
});
|
|
100591
100683
|
|
|
100592
100684
|
// src/project/workflow/workflowProvider.ts
|
|
100593
|
-
import { existsSync as
|
|
100685
|
+
import { existsSync as existsSync27 } from "node:fs";
|
|
100594
100686
|
import { dirname as dirname45, resolve as resolve34 } from "node:path";
|
|
100595
100687
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
100596
100688
|
function providerCandidates() {
|
|
@@ -100602,7 +100694,7 @@ function providerCandidates() {
|
|
|
100602
100694
|
];
|
|
100603
100695
|
}
|
|
100604
100696
|
function contextWorkflowProviderPath() {
|
|
100605
|
-
const candidate = providerCandidates().find((path2) =>
|
|
100697
|
+
const candidate = providerCandidates().find((path2) => existsSync27(path2));
|
|
100606
100698
|
if (candidate === undefined) {
|
|
100607
100699
|
throw new Error("Context workflow Provider is missing. Rebuild @c4a/context-cli or reinstall the published package.");
|
|
100608
100700
|
}
|
|
@@ -101315,8 +101407,8 @@ function pendingDocumentCaptureCommands(input) {
|
|
|
101315
101407
|
}
|
|
101316
101408
|
|
|
101317
101409
|
// src/project/productionStageRefresh.ts
|
|
101318
|
-
import { readFile as
|
|
101319
|
-
import { join as
|
|
101410
|
+
import { readFile as readFile83 } from "node:fs/promises";
|
|
101411
|
+
import { join as join101 } from "node:path";
|
|
101320
101412
|
async function refreshProductionStageSources(projectRoot, stage) {
|
|
101321
101413
|
const active = activeProductionSources(stage);
|
|
101322
101414
|
const affected = new Set(stage.gaps.filter((gap) => active.has(gap.scope)).map((gap) => gap.scope));
|
|
@@ -101361,14 +101453,14 @@ Restore the authorized source and retry preparation.
|
|
|
101361
101453
|
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)
|
|
101362
101454
|
});
|
|
101363
101455
|
const directory = productionStageDirectory(stage.id);
|
|
101364
|
-
const contents2 = new Map([...sourceMaterials].map(([scope2, content3]) => [
|
|
101365
|
-
contents2.set(
|
|
101456
|
+
const contents2 = new Map([...sourceMaterials].map(([scope2, content3]) => [join101(directory, productionSourceFile(scope2)), content3]));
|
|
101457
|
+
contents2.set(join101(directory, "manifest.json"), `${JSON.stringify(updated)}
|
|
101366
101458
|
`);
|
|
101367
101459
|
const targets = [];
|
|
101368
101460
|
for (const [path2, content3] of contents2) {
|
|
101369
101461
|
let previous2;
|
|
101370
101462
|
try {
|
|
101371
|
-
previous2 = await
|
|
101463
|
+
previous2 = await readFile83(await safeProjectTarget(projectRoot, path2), "utf8");
|
|
101372
101464
|
} catch (error) {
|
|
101373
101465
|
if (error.code !== "ENOENT")
|
|
101374
101466
|
throw error;
|
|
@@ -101493,7 +101585,7 @@ var init_productionReport = __esm(() => {
|
|
|
101493
101585
|
});
|
|
101494
101586
|
|
|
101495
101587
|
// src/project/productionPlanningRoute.ts
|
|
101496
|
-
import { join as
|
|
101588
|
+
import { join as join102 } from "node:path";
|
|
101497
101589
|
async function productionPlanningRoute(input, stage) {
|
|
101498
101590
|
const request = stage ? undefined : await productionPlanningRequest(input.projectRoot);
|
|
101499
101591
|
const present = !!stage || !!request;
|
|
@@ -101531,7 +101623,7 @@ async function productionPlanningRoute(input, stage) {
|
|
|
101531
101623
|
id: `production/${stage.id}/planning`,
|
|
101532
101624
|
kind: "context-view",
|
|
101533
101625
|
media_type: "text/markdown",
|
|
101534
|
-
path:
|
|
101626
|
+
path: join102(input.projectRoot, productionStageDirectory(stage.id), "planning.md"),
|
|
101535
101627
|
read_state: "read-required"
|
|
101536
101628
|
}] : []
|
|
101537
101629
|
],
|
|
@@ -101558,8 +101650,8 @@ var init_productionPlanningRoute = __esm(() => {
|
|
|
101558
101650
|
});
|
|
101559
101651
|
|
|
101560
101652
|
// src/project/productionWorkflowRoute.ts
|
|
101561
|
-
import { existsSync as
|
|
101562
|
-
import { join as
|
|
101653
|
+
import { existsSync as existsSync28 } from "node:fs";
|
|
101654
|
+
import { join as join103 } from "node:path";
|
|
101563
101655
|
async function productionWorkflowRoute(input) {
|
|
101564
101656
|
const stage = await readProductionStage(input.projectRoot);
|
|
101565
101657
|
if (!stage || !stage.planning_complete)
|
|
@@ -101577,7 +101669,7 @@ async function productionWorkflowRoute(input) {
|
|
|
101577
101669
|
const selected = new Set(dispatch2.batches.flatMap((batch) => batch.tasks));
|
|
101578
101670
|
const context = { workspace: input.projectRoot, authorities: [...input.authorities], facts: { production: {
|
|
101579
101671
|
report_approved: stage.report_approved,
|
|
101580
|
-
prepared: !dispatch2.batches.length ||
|
|
101672
|
+
prepared: !dispatch2.batches.length || existsSync28(join103(input.projectRoot, directory, "stage.md")) && stage.tasks.filter((task) => selected.has(task.id)).every((task) => task.status === "issued"),
|
|
101581
101673
|
writing_complete: dispatch2.batches.length === 0,
|
|
101582
101674
|
complete: dispatch2.state === "ended",
|
|
101583
101675
|
review_clear: rejected.length === 0,
|
|
@@ -101594,7 +101686,7 @@ async function productionWorkflowRoute(input) {
|
|
|
101594
101686
|
const resolved = await resolveRoute(provider, "indexer", "production", primary.routeId, context, evaluated.evaluation.revision);
|
|
101595
101687
|
const report = resolved.node === "confirm-production-report";
|
|
101596
101688
|
if (report)
|
|
101597
|
-
await writeProductionProjection(input.projectRoot,
|
|
101689
|
+
await writeProductionProjection(input.projectRoot, join103(directory, "plan.md"), productionPlanMarkdown(stage));
|
|
101598
101690
|
const prepare = resolved.node === "prepare-production-stage";
|
|
101599
101691
|
const writing = resolved.node === "work-production-stage";
|
|
101600
101692
|
const repair = resolved.node === "repair-production-articles";
|
|
@@ -101609,7 +101701,7 @@ async function productionWorkflowRoute(input) {
|
|
|
101609
101701
|
id: `production/${stage.id}/${report ? "plan" : "stage"}`,
|
|
101610
101702
|
kind: "context-view",
|
|
101611
101703
|
media_type: "text/markdown",
|
|
101612
|
-
path:
|
|
101704
|
+
path: join103(input.projectRoot, directory, path3),
|
|
101613
101705
|
read_state: "read-required"
|
|
101614
101706
|
});
|
|
101615
101707
|
if (report || writing)
|
|
@@ -101620,18 +101712,18 @@ async function productionWorkflowRoute(input) {
|
|
|
101620
101712
|
id: `production/${stage.id}/planning`,
|
|
101621
101713
|
kind: "context-view",
|
|
101622
101714
|
media_type: "text/markdown",
|
|
101623
|
-
path:
|
|
101715
|
+
path: join103(input.projectRoot, directory, "planning.md"),
|
|
101624
101716
|
read_state: "read-required"
|
|
101625
101717
|
});
|
|
101626
101718
|
}
|
|
101627
101719
|
if (repair) {
|
|
101628
|
-
await writeProductionProjection(input.projectRoot,
|
|
101720
|
+
await writeProductionProjection(input.projectRoot, join103(directory, "repair.md"), [
|
|
101629
101721
|
"# Revise rejected articles",
|
|
101630
101722
|
"",
|
|
101631
101723
|
...rejected.map((candidate) => `- ${candidate.path}: ${candidate.review.title}`),
|
|
101632
101724
|
"",
|
|
101633
101725
|
"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.",
|
|
101634
|
-
`Submit the plan amendment to ${path2} using ${
|
|
101726
|
+
`Submit the plan amendment to ${path2} using ${join103(directory, "planning.schema.json")}. Keep accepted task identities unchanged; the CLI assigns the revision tasks and preserves article identities.`,
|
|
101635
101727
|
"Once issued, repair the affected sections through the existing edits submission. Unchanged sections and references do not need resubmission.",
|
|
101636
101728
|
""
|
|
101637
101729
|
].join(`
|
|
@@ -101640,7 +101732,7 @@ async function productionWorkflowRoute(input) {
|
|
|
101640
101732
|
id: `production/${stage.id}/repair`,
|
|
101641
101733
|
kind: "context-view",
|
|
101642
101734
|
media_type: "text/markdown",
|
|
101643
|
-
path:
|
|
101735
|
+
path: join103(input.projectRoot, directory, "repair.md"),
|
|
101644
101736
|
read_state: "read-required"
|
|
101645
101737
|
});
|
|
101646
101738
|
}
|
|
@@ -101739,7 +101831,7 @@ var init_knowledgeMaintenanceRoute = __esm(() => {
|
|
|
101739
101831
|
});
|
|
101740
101832
|
|
|
101741
101833
|
// src/project/approvedRevisionContext.ts
|
|
101742
|
-
import { readFile as
|
|
101834
|
+
import { readFile as readFile84 } from "node:fs/promises";
|
|
101743
101835
|
async function approvedRevisionContext(root, target) {
|
|
101744
101836
|
const registry2 = await readProductionRequirements(root);
|
|
101745
101837
|
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}/`))));
|
|
@@ -101750,7 +101842,7 @@ async function approvedRevisionContext(root, target) {
|
|
|
101750
101842
|
const type = source_ref.slice(0, separator);
|
|
101751
101843
|
const name3 = source_ref.slice(separator + 1);
|
|
101752
101844
|
const path2 = await assertManagedDocumentPath(root, type, name3);
|
|
101753
|
-
const markdown = await
|
|
101845
|
+
const markdown = await readFile84(path2, "utf8");
|
|
101754
101846
|
const changes = type === "sessions" ? readSessionChanges(markdown) : undefined;
|
|
101755
101847
|
return {
|
|
101756
101848
|
source_ref,
|
|
@@ -101781,15 +101873,15 @@ var exports_approvedRevisionRoute = {};
|
|
|
101781
101873
|
__export(exports_approvedRevisionRoute, {
|
|
101782
101874
|
buildApprovedRevisionRoute: () => buildApprovedRevisionRoute
|
|
101783
101875
|
});
|
|
101784
|
-
import { existsSync as
|
|
101785
|
-
import { join as
|
|
101876
|
+
import { existsSync as existsSync29 } from "node:fs";
|
|
101877
|
+
import { join as join104 } from "node:path";
|
|
101786
101878
|
async function sourceUpdateRouteInput(projectRoot, update) {
|
|
101787
101879
|
const { reference_evidence: evidence, ...rest } = update;
|
|
101788
101880
|
if (!evidence?.length)
|
|
101789
101881
|
return rest;
|
|
101790
101882
|
const file = `.tmp/context-runtime/source-update/evidence-${update.revision.replace(/^sha256:/u, "")}.json`;
|
|
101791
|
-
if (!
|
|
101792
|
-
await atomicWriteFile(
|
|
101883
|
+
if (!existsSync29(join104(projectRoot, file)))
|
|
101884
|
+
await atomicWriteFile(join104(projectRoot, file), `${JSON.stringify(evidence, null, 2)}
|
|
101793
101885
|
`);
|
|
101794
101886
|
return { ...rest, reference_evidence_file: file, reference_evidence_count: evidence.length };
|
|
101795
101887
|
}
|
|
@@ -101954,6 +102046,34 @@ var init_indexerCurrentWorkflowRoute = __esm(() => {
|
|
|
101954
102046
|
init_productionWorkflowRoute();
|
|
101955
102047
|
});
|
|
101956
102048
|
|
|
102049
|
+
// src/project/productionCaptureScope.ts
|
|
102050
|
+
function documentSourceMatches(source2, ref2) {
|
|
102051
|
+
return [source2.name, source2.id].filter(Boolean).some((name3) => ref2 === `${source2.type}:${name3}` || ref2 === `docs:${name3}` || ref2.startsWith(`${source2.type}:${name3}#`) || ref2.startsWith(`${source2.type}:${name3}/`));
|
|
102052
|
+
}
|
|
102053
|
+
function documentSourceSettled(source2) {
|
|
102054
|
+
return source2.snapshotReady || source2.acquisitionWarning !== undefined;
|
|
102055
|
+
}
|
|
102056
|
+
function productionCaptureDocuments(stage, documents) {
|
|
102057
|
+
const requested = productionRequestedSources(stage);
|
|
102058
|
+
const own5 = documents.filter((source2) => requested.some((ref2) => documentSourceMatches(source2, ref2)));
|
|
102059
|
+
const deferred = documents.filter((source2) => !own5.includes(source2) && !documentSourceSettled(source2)).map(documentRef);
|
|
102060
|
+
return { documents: own5, deferred };
|
|
102061
|
+
}
|
|
102062
|
+
function capturedRequirementTargets(requirements, documents) {
|
|
102063
|
+
const ready = requirements.requirements.filter((item) => {
|
|
102064
|
+
const refs = [...item.target_scope.targets, ...item.evidence_source_scope?.targets ?? []].map((target) => target.source_ref);
|
|
102065
|
+
return documents.filter((source2) => refs.some((ref2) => documentSourceMatches(source2, ref2))).every(documentSourceSettled);
|
|
102066
|
+
});
|
|
102067
|
+
const targets = [...new Set(ready.flatMap((item) => item.target_scope.targets.map((target) => target.source_ref)))];
|
|
102068
|
+
const readyRefs = ready.flatMap((item) => [...item.target_scope.targets, ...item.evidence_source_scope?.targets ?? []].map((target) => target.source_ref));
|
|
102069
|
+
const deferred = documents.filter((source2) => !documentSourceSettled(source2) && !readyRefs.some((ref2) => documentSourceMatches(source2, ref2))).map(documentRef);
|
|
102070
|
+
return { targets, deferred };
|
|
102071
|
+
}
|
|
102072
|
+
var documentRef = (source2) => `${source2.type}:${source2.name}`;
|
|
102073
|
+
var init_productionCaptureScope = __esm(() => {
|
|
102074
|
+
init_productionScope();
|
|
102075
|
+
});
|
|
102076
|
+
|
|
101957
102077
|
// src/project/status.ts
|
|
101958
102078
|
var exports_status = {};
|
|
101959
102079
|
__export(exports_status, {
|
|
@@ -101962,7 +102082,7 @@ __export(exports_status, {
|
|
|
101962
102082
|
collectProjectStatusSnapshot: () => collectProjectStatusSnapshot,
|
|
101963
102083
|
collectProjectStatus: () => collectProjectStatus
|
|
101964
102084
|
});
|
|
101965
|
-
import { join as
|
|
102085
|
+
import { join as join105 } from "node:path";
|
|
101966
102086
|
async function recordWorkflowEvaluation(projectRoot, workflow) {
|
|
101967
102087
|
const current3 = workflow.current;
|
|
101968
102088
|
await recordAgentGraphEvaluation({
|
|
@@ -102014,7 +102134,7 @@ async function collectProjectStatusSnapshotInternal(projectRoot, options = {}) {
|
|
|
102014
102134
|
const navigationOnly = !maintenance && !localRevision && !localUpdate && !localRollback && taskPreparation === "cleared" && !production && phaseStatus.projectEntryValid && await navigationOnlyChange(projectRoot, phaseStatus.packages);
|
|
102015
102135
|
const deferDeliveryChecks = !maintenance && !localRevision && !localUpdate && !localRollback && !navigationOnly && (taskPreparation === "cleared" && !production || !!authoring);
|
|
102016
102136
|
const collectionsWithPages = new Set;
|
|
102017
|
-
const approvedPages = await countFiles(
|
|
102137
|
+
const approvedPages = await countFiles(join105(projectRoot, "knowledge"), (rel) => {
|
|
102018
102138
|
if (!isApprovedKnowledgeMarkdownPath(rel) || rel.startsWith("assets/"))
|
|
102019
102139
|
return false;
|
|
102020
102140
|
collectionsWithPages.add(rel.split("/")[0]);
|
|
@@ -102022,9 +102142,10 @@ async function collectProjectStatusSnapshotInternal(projectRoot, options = {}) {
|
|
|
102022
102142
|
});
|
|
102023
102143
|
const approvedCollections = KNOWLEDGE_COLLECTIONS.filter((collection) => collectionsWithPages.has(collection));
|
|
102024
102144
|
const closeStatus = deferDeliveryChecks ? { state: "not-checked", diagnostics: [] } : await readCloseStatus(projectRoot);
|
|
102025
|
-
const distFiles = await countFiles(
|
|
102145
|
+
const distFiles = await countFiles(join105(projectRoot, "dist"), () => true);
|
|
102026
102146
|
const verifyStatus = !deferDeliveryChecks && draftStatus.diagnostics.length === 0 ? await readVerifyStatus(projectRoot) : { issues: [], diagnostics: [] };
|
|
102027
|
-
const
|
|
102147
|
+
const productionCapture = !localRevision && production ? productionCaptureDocuments(production, documentSources) : undefined;
|
|
102148
|
+
const revisionDocuments = localRevision ? documentSources.filter((source2) => localRevision.target.source_refs.some((ref2) => documentSourceMatches(source2, ref2))) : productionCapture?.documents ?? documentSources;
|
|
102028
102149
|
const pendingCapture = pendingDocumentCaptureCommands({
|
|
102029
102150
|
phases,
|
|
102030
102151
|
documentSources: revisionDocuments
|
|
@@ -102110,12 +102231,15 @@ async function collectProjectStatusSnapshotInternal(projectRoot, options = {}) {
|
|
|
102110
102231
|
});
|
|
102111
102232
|
const statusProjectionStarted = performance.now();
|
|
102112
102233
|
const baseWorkflow = projectContextWorkflowStatus(workflowSnapshot);
|
|
102113
|
-
const
|
|
102234
|
+
const indexerRoute = await projectCurrentIndexerWorkflowRoute({
|
|
102114
102235
|
projectRoot,
|
|
102115
102236
|
route: baseWorkflow.current,
|
|
102116
102237
|
authorities,
|
|
102117
102238
|
managed: options.managed === true
|
|
102118
102239
|
});
|
|
102240
|
+
const capturePlanning = !production && !localRevision && !localUpdate ? await productionStartForCapturedSources(projectRoot, indexerRoute, documentSources) : undefined;
|
|
102241
|
+
const currentRoute2 = capturePlanning?.route ?? indexerRoute;
|
|
102242
|
+
const deferredCaptureSources = productionCapture?.deferred ?? capturePlanning?.deferred ?? [];
|
|
102119
102243
|
const workflow = {
|
|
102120
102244
|
...baseWorkflow,
|
|
102121
102245
|
...currentRoute2 === undefined ? {} : { current: currentRoute2 },
|
|
@@ -102153,6 +102277,7 @@ async function collectProjectStatusSnapshotInternal(projectRoot, options = {}) {
|
|
|
102153
102277
|
packages: packageFreshness,
|
|
102154
102278
|
packageTemplateReviews,
|
|
102155
102279
|
pendingCapturePhases: pendingCapture.phaseIds,
|
|
102280
|
+
...deferredCaptureSources.length ? { deferredCaptureSources } : {},
|
|
102156
102281
|
evidenceStatus,
|
|
102157
102282
|
evidenceWarnings,
|
|
102158
102283
|
close: closeStatus,
|
|
@@ -102268,6 +102393,29 @@ async function navigationOnlyChange(projectRoot, packages) {
|
|
|
102268
102393
|
const freshness = await readPackageFreshnessStatus(projectRoot, packages);
|
|
102269
102394
|
return freshness.diagnostics.length > 0 || freshness.packages.length < packages.length || freshness.packages.some((item) => item.state !== "ready");
|
|
102270
102395
|
}
|
|
102396
|
+
async function productionStartForCapturedSources(projectRoot, route, documents) {
|
|
102397
|
+
if (!route || !["authorize-document-capture", "capture-next"].includes(route.node))
|
|
102398
|
+
return;
|
|
102399
|
+
const inspected = await inspectProductionRequirements(projectRoot).catch(() => {
|
|
102400
|
+
return;
|
|
102401
|
+
});
|
|
102402
|
+
if (!inspected)
|
|
102403
|
+
return;
|
|
102404
|
+
const { targets, deferred } = capturedRequirementTargets(inspected.requirements, documents);
|
|
102405
|
+
if (targets.length === 0 || deferred.length === 0)
|
|
102406
|
+
return;
|
|
102407
|
+
const request = await productionPlanningRequest(projectRoot).catch(() => {
|
|
102408
|
+
return;
|
|
102409
|
+
});
|
|
102410
|
+
if (!request)
|
|
102411
|
+
return;
|
|
102412
|
+
const command2 = `context action prepare-current --revision ${request.revision} ${targets.map((target) => `--source ${target}`).join(" ")} --format json`;
|
|
102413
|
+
return { deferred, route: {
|
|
102414
|
+
...route,
|
|
102415
|
+
summary: [route.summary, `To start production now for requirements whose documents are already captured, run ${command2}. These documents stay registered and are captured when their read permission is given: ${deferred.join(", ")}.`].filter(Boolean).join(" "),
|
|
102416
|
+
commands: [...route.commands, { command: command2, effect: "write", availability: "immediate", managed_execution: "agent-required" }]
|
|
102417
|
+
} };
|
|
102418
|
+
}
|
|
102271
102419
|
var init_status = __esm(() => {
|
|
102272
102420
|
init_documentCaptureAvailability();
|
|
102273
102421
|
init_productionPlanning();
|
|
@@ -102292,6 +102440,9 @@ var init_status = __esm(() => {
|
|
|
102292
102440
|
init_workspaceChangelog();
|
|
102293
102441
|
init_indexerCurrentWorkflowRoute();
|
|
102294
102442
|
init_productionStageStore();
|
|
102443
|
+
init_productionCaptureScope();
|
|
102444
|
+
init_productionRequirements();
|
|
102445
|
+
init_productionPlanning();
|
|
102295
102446
|
init_productionStage();
|
|
102296
102447
|
init_candidateLedger();
|
|
102297
102448
|
init_commandReadCache();
|
|
@@ -102337,6 +102488,7 @@ function formatProjectStatus(status, options = {}) {
|
|
|
102337
102488
|
`- dist files: ${status.distFiles}`,
|
|
102338
102489
|
`- phases: ${options.full ? status.phases.join(", ") || "none" : status.phases.length}`,
|
|
102339
102490
|
`- pending capture phases: ${status.pendingCapturePhases.length}`,
|
|
102491
|
+
...status.deferredCaptureSources?.length ? [`- deferred capture: ${status.deferredCaptureSources.join(", ")}`] : [],
|
|
102340
102492
|
`- indexer registry: ${status.indexerRegistry.state}`,
|
|
102341
102493
|
`- indexer candidate compile: ${status.indexerCandidateCompile.state}`,
|
|
102342
102494
|
`- close: ${status.close.state}`,
|
|
@@ -102473,14 +102625,14 @@ __export(exports_workflowRouteOutput, {
|
|
|
102473
102625
|
});
|
|
102474
102626
|
import { Buffer as Buffer4 } from "node:buffer";
|
|
102475
102627
|
import { createHash as createHash32 } from "node:crypto";
|
|
102476
|
-
import { join as
|
|
102628
|
+
import { join as join106 } from "node:path";
|
|
102477
102629
|
async function workflowRouteOutput(projectRoot, route, options = {}) {
|
|
102478
102630
|
if (!route)
|
|
102479
102631
|
return null;
|
|
102480
102632
|
const body = `${JSON.stringify(route, null, 2)}
|
|
102481
102633
|
`;
|
|
102482
102634
|
const digest7 = createHash32("sha256").update(body).digest("hex");
|
|
102483
|
-
const file =
|
|
102635
|
+
const file = join106(projectRoot, ".tmp/context-runtime/routes", `${digest7}.json`);
|
|
102484
102636
|
await atomicWriteFile(file, body);
|
|
102485
102637
|
const routeBytes = Buffer4.byteLength(body);
|
|
102486
102638
|
const inlineByteLimit = Math.max(0, Math.min(WORKFLOW_ROUTE_INLINE_BYTE_LIMIT, options.inlineByteLimit ?? WORKFLOW_ROUTE_INLINE_BYTE_LIMIT));
|
|
@@ -102502,7 +102654,7 @@ async function workflowRunResultFile(projectRoot, result) {
|
|
|
102502
102654
|
const body = `${JSON.stringify(result, null, 2)}
|
|
102503
102655
|
`;
|
|
102504
102656
|
const digest7 = createHash32("sha256").update(body).digest("hex");
|
|
102505
|
-
const file =
|
|
102657
|
+
const file = join106(projectRoot, ".tmp/context-runtime/action-results", `${digest7}.run.json`);
|
|
102506
102658
|
await atomicWriteFile(file, body);
|
|
102507
102659
|
return file;
|
|
102508
102660
|
}
|
|
@@ -102521,15 +102673,15 @@ __export(exports_originalRevisions, {
|
|
|
102521
102673
|
originalRevisionReviewHtml: () => originalRevisionReviewHtml,
|
|
102522
102674
|
ORIGINAL_REVISION_PROPOSALS_PATH: () => ORIGINAL_REVISION_PROPOSALS_PATH
|
|
102523
102675
|
});
|
|
102524
|
-
import { readFile as
|
|
102525
|
-
import { join as
|
|
102676
|
+
import { readFile as readFile85, rm as rm26 } from "node:fs/promises";
|
|
102677
|
+
import { join as join107 } from "node:path";
|
|
102526
102678
|
function inputError(message, reasonCode) {
|
|
102527
102679
|
return new ContextError(ExitCode.UserError, message, { category: ErrorCategory.UserInputInvalid, reason_code: reasonCode });
|
|
102528
102680
|
}
|
|
102529
102681
|
async function readOriginalRevisionProposals(projectRoot) {
|
|
102530
102682
|
let content3;
|
|
102531
102683
|
try {
|
|
102532
|
-
content3 = await
|
|
102684
|
+
content3 = await readFile85(join107(projectRoot, ORIGINAL_REVISION_PROPOSALS_PATH), "utf8");
|
|
102533
102685
|
} catch (error) {
|
|
102534
102686
|
if (error.code === "ENOENT")
|
|
102535
102687
|
return [];
|
|
@@ -102542,7 +102694,7 @@ async function readOriginalRevisionProposals(projectRoot) {
|
|
|
102542
102694
|
return parsed.data.revisions;
|
|
102543
102695
|
}
|
|
102544
102696
|
async function writeProposals(projectRoot, proposals) {
|
|
102545
|
-
const path2 =
|
|
102697
|
+
const path2 = join107(projectRoot, ORIGINAL_REVISION_PROPOSALS_PATH);
|
|
102546
102698
|
if (proposals.length === 0) {
|
|
102547
102699
|
await rm26(path2, { force: true });
|
|
102548
102700
|
return;
|
|
@@ -102640,6 +102792,54 @@ var init_originalRevisions = __esm(() => {
|
|
|
102640
102792
|
storedProposalsSchema = exports_external.object({ revisions: exports_external.array(storedProposalSchema).default([]) }).strict();
|
|
102641
102793
|
});
|
|
102642
102794
|
|
|
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
|
+
|
|
102643
102843
|
// src/project/statusCommand.ts
|
|
102644
102844
|
async function projectStatusSummary(status, projectRoot) {
|
|
102645
102845
|
const { observeKnowledgeMaintenance: observeKnowledgeMaintenance2 } = await Promise.resolve().then(() => (init_knowledgeMaintenance(), exports_knowledgeMaintenance));
|
|
@@ -102657,6 +102857,8 @@ async function projectStatusSummary(status, projectRoot) {
|
|
|
102657
102857
|
const completedCollections = [...status.approvedCollections].sort();
|
|
102658
102858
|
const { readOriginalRevisionProposals: readOriginalRevisionProposals2 } = await Promise.resolve().then(() => (init_originalRevisions(), exports_originalRevisions));
|
|
102659
102859
|
const originalRevisions = await readOriginalRevisionProposals2(projectRoot).then((revisions) => ({ proposed: revisions.length }), (error) => ({ problem: error instanceof Error ? error.message : String(error) }));
|
|
102860
|
+
const { inspectSdkAlignment: inspectSdkAlignment2 } = await Promise.resolve().then(() => (init_sdkAlignment(), exports_sdkAlignment));
|
|
102861
|
+
const sdkAlignment = await inspectSdkAlignment2(projectRoot);
|
|
102660
102862
|
return {
|
|
102661
102863
|
...status.sourceUpdate ? { source_update: {
|
|
102662
102864
|
...status.sourceUpdate,
|
|
@@ -102677,6 +102879,7 @@ async function projectStatusSummary(status, projectRoot) {
|
|
|
102677
102879
|
message: "Revisions proposed for pages kept as written await a decision; apply it to the article, record it in the changelog, then resolve the proposal. Fully managed and routine runs keep the revisions locally."
|
|
102678
102880
|
}
|
|
102679
102881
|
} } : {},
|
|
102882
|
+
...sdkAlignment ? { version_alignment: sdkAlignment } : {},
|
|
102680
102883
|
...status.executionMode !== undefined ? { executionMode: status.executionMode } : {},
|
|
102681
102884
|
...complete ? {
|
|
102682
102885
|
completedScope: {
|
|
@@ -102694,6 +102897,7 @@ async function projectStatusSummary(status, projectRoot) {
|
|
|
102694
102897
|
},
|
|
102695
102898
|
progress: {
|
|
102696
102899
|
pendingCapturePhases: status.pendingCapturePhases.length,
|
|
102900
|
+
...status.deferredCaptureSources?.length ? { deferredCaptureSources: status.deferredCaptureSources } : {},
|
|
102697
102901
|
indexerRegistry: status.indexerRegistry.state,
|
|
102698
102902
|
indexerCandidateCompile: status.indexerCandidateCompile.state
|
|
102699
102903
|
},
|
|
@@ -102808,8 +103012,8 @@ __export(exports_articleRetirement, {
|
|
|
102808
103012
|
batchDraftReader: () => batchDraftReader,
|
|
102809
103013
|
articleRetirementSchema: () => articleRetirementSchema
|
|
102810
103014
|
});
|
|
102811
|
-
import { readFile as
|
|
102812
|
-
import { posix as
|
|
103015
|
+
import { readFile as readFile88, readdir as readdir25 } from "node:fs/promises";
|
|
103016
|
+
import { posix as posix14 } from "node:path";
|
|
102813
103017
|
function rebuildInput(revision) {
|
|
102814
103018
|
return JSON.stringify({ id: `retirement-${revision.slice(7)}`, operation: "rebuild", timing: "priority", targets: [] });
|
|
102815
103019
|
}
|
|
@@ -102829,7 +103033,7 @@ function invalid2(reason, message, details = {}) {
|
|
|
102829
103033
|
}
|
|
102830
103034
|
async function text11(root2, path3) {
|
|
102831
103035
|
try {
|
|
102832
|
-
return await
|
|
103036
|
+
return await readFile88(await safeProjectTarget(root2, path3), "utf8");
|
|
102833
103037
|
} catch (error) {
|
|
102834
103038
|
if (error.code === "ENOENT")
|
|
102835
103039
|
return;
|
|
@@ -102993,7 +103197,7 @@ async function planArticleRetirement(root2, value, read, options = {}) {
|
|
|
102993
103197
|
const rooted = /^\/?knowledge\//u.test(target);
|
|
102994
103198
|
if (target.startsWith("/") && !rooted)
|
|
102995
103199
|
return;
|
|
102996
|
-
let resolved = knowledge ? target : rooted ? target.replace(/^\/?knowledge\//u, "") :
|
|
103200
|
+
let resolved = knowledge ? target : rooted ? target.replace(/^\/?knowledge\//u, "") : posix14.normalize(posix14.join(posix14.dirname(article.path), target));
|
|
102997
103201
|
if (knowledge && !resolved.endsWith(".md"))
|
|
102998
103202
|
resolved += ".md";
|
|
102999
103203
|
if (!selected.has(resolved))
|
|
@@ -103007,7 +103211,7 @@ async function planArticleRetirement(root2, value, read, options = {}) {
|
|
|
103007
103211
|
blockers.push({ path: path3, target: link2.target, reason: replacement ? "Repair fragment links explicitly before retirement." : "Repair this incoming link or supply an approved replacement." });
|
|
103008
103212
|
return;
|
|
103009
103213
|
}
|
|
103010
|
-
return knowledge ? `knowledge:${target.endsWith(".md") ? replacement : replacement.replace(/\.md$/u, "")}${match[2]}` : `${encodeURI(rooted ? `${target.startsWith("/") ? "/" : ""}knowledge/${replacement}` :
|
|
103214
|
+
return knowledge ? `knowledge:${target.endsWith(".md") ? replacement : replacement.replace(/\.md$/u, "")}${match[2]}` : `${encodeURI(rooted ? `${target.startsWith("/") ? "/" : ""}knowledge/${replacement}` : posix14.relative(posix14.dirname(article.path), replacement))}${match[2]}`;
|
|
103011
103215
|
});
|
|
103012
103216
|
change(path3, bytes, content3);
|
|
103013
103217
|
}
|
|
@@ -107888,7 +108092,7 @@ var init_larkResourceCommand = __esm(() => {
|
|
|
107888
108092
|
|
|
107889
108093
|
// src/lib/larkMediaDownload.ts
|
|
107890
108094
|
import { readdir as readdir26, rm as rm27 } from "node:fs/promises";
|
|
107891
|
-
import { join as
|
|
108095
|
+
import { join as join116 } from "node:path";
|
|
107892
108096
|
async function downloadLarkMedia(input) {
|
|
107893
108097
|
const shared = ["--as", input.identity, "--token", input.token, "--output", "./resource", "--format", "json"];
|
|
107894
108098
|
try {
|
|
@@ -107898,7 +108102,7 @@ async function downloadLarkMedia(input) {
|
|
|
107898
108102
|
if (!input.allowPreview || !isLarkResourcePermissionDenied(error))
|
|
107899
108103
|
throw error;
|
|
107900
108104
|
for (const entry of await readdir26(input.cwd))
|
|
107901
|
-
await rm27(
|
|
108105
|
+
await rm27(join116(input.cwd, entry), { recursive: true, force: true });
|
|
107902
108106
|
await runLarkResourceCommand(input.runner, ["docs", "+media-preview", ...shared], { cwd: input.cwd });
|
|
107903
108107
|
return "preview";
|
|
107904
108108
|
}
|
|
@@ -107908,9 +108112,9 @@ var init_larkMediaDownload = __esm(() => {
|
|
|
107908
108112
|
});
|
|
107909
108113
|
|
|
107910
108114
|
// src/lib/larkWhiteboardExport.ts
|
|
107911
|
-
import { mkdtemp as mkdtemp5, readFile as
|
|
108115
|
+
import { mkdtemp as mkdtemp5, readFile as readFile94, rm as rm28 } from "node:fs/promises";
|
|
107912
108116
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
107913
|
-
import { join as
|
|
108117
|
+
import { join as join117 } from "node:path";
|
|
107914
108118
|
function stableJson2(value) {
|
|
107915
108119
|
if (value === undefined)
|
|
107916
108120
|
return "null";
|
|
@@ -107940,7 +108144,7 @@ function canonicalWhiteboardPayload(value) {
|
|
|
107940
108144
|
};
|
|
107941
108145
|
}
|
|
107942
108146
|
async function exportLarkWhiteboardRaw(runner2, identity2, token) {
|
|
107943
|
-
const tempRoot = await mkdtemp5(
|
|
108147
|
+
const tempRoot = await mkdtemp5(join117(tmpdir2(), "context-lark-whiteboard-"));
|
|
107944
108148
|
try {
|
|
107945
108149
|
await runLarkResourceCommand(runner2, [
|
|
107946
108150
|
"whiteboard",
|
|
@@ -107957,7 +108161,7 @@ async function exportLarkWhiteboardRaw(runner2, identity2, token) {
|
|
|
107957
108161
|
"--format",
|
|
107958
108162
|
"json"
|
|
107959
108163
|
], { cwd: tempRoot });
|
|
107960
|
-
const rawPayload = JSON.parse(await
|
|
108164
|
+
const rawPayload = JSON.parse(await readFile94(join117(tempRoot, "raw.json"), "utf8"));
|
|
107961
108165
|
return Buffer.from(`${stableJson2(canonicalWhiteboardPayload(rawPayload))}
|
|
107962
108166
|
`, "utf8");
|
|
107963
108167
|
} finally {
|
|
@@ -107996,8 +108200,8 @@ var init_larkImagePolicy = __esm(() => {
|
|
|
107996
108200
|
|
|
107997
108201
|
// src/lib/larkResourceMaterialization.ts
|
|
107998
108202
|
import { createHash as createHash36 } from "node:crypto";
|
|
107999
|
-
import { mkdtemp as mkdtemp6, readFile as
|
|
108000
|
-
import { extname as extname13, join as
|
|
108203
|
+
import { mkdtemp as mkdtemp6, readFile as readFile95, readdir as readdir27, rm as rm29 } from "node:fs/promises";
|
|
108204
|
+
import { extname as extname13, join as join118 } from "node:path";
|
|
108001
108205
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
108002
108206
|
function countByKind(items, status) {
|
|
108003
108207
|
const counts2 = new Map;
|
|
@@ -108102,17 +108306,17 @@ function findBooleanField(value, name3) {
|
|
|
108102
108306
|
}
|
|
108103
108307
|
async function downloadedFile(input) {
|
|
108104
108308
|
if (input.localPath !== undefined) {
|
|
108105
|
-
const bytes = await
|
|
108309
|
+
const bytes = await readFile95(input.localPath);
|
|
108106
108310
|
return { path: input.localPath, bytes, mediaType: mediaTypeFor(input.localPath, bytes), representation: "original" };
|
|
108107
108311
|
}
|
|
108108
|
-
const tempRoot = await mkdtemp6(
|
|
108312
|
+
const tempRoot = await mkdtemp6(join118(tmpdir3(), "context-lark-resource-"));
|
|
108109
108313
|
try {
|
|
108110
108314
|
const representation = await downloadLarkMedia({ ...input, cwd: tempRoot });
|
|
108111
108315
|
const entries2 = (await readdir27(tempRoot, { withFileTypes: true })).filter((entry) => entry.isFile());
|
|
108112
108316
|
if (entries2.length !== 1)
|
|
108113
108317
|
throw new Error(`media download produced ${entries2.length} files, expected exactly one`);
|
|
108114
108318
|
const path3 = entries2[0]?.name ?? "resource.bin";
|
|
108115
|
-
const bytes = await
|
|
108319
|
+
const bytes = await readFile95(join118(tempRoot, path3));
|
|
108116
108320
|
return { path: path3, bytes, mediaType: mediaTypeFor(path3, bytes), representation };
|
|
108117
108321
|
} finally {
|
|
108118
108322
|
await rm29(tempRoot, { recursive: true, force: true });
|
|
@@ -108184,9 +108388,9 @@ async function sheetMaterialization(resource, runner2, identity2) {
|
|
|
108184
108388
|
const sheetId = resource.attributes["sheet-id"];
|
|
108185
108389
|
if (token === undefined || sheetId === undefined)
|
|
108186
108390
|
throw new Error("embedded Sheet requires token and sheet-id");
|
|
108187
|
-
const tempRoot = await mkdtemp6(
|
|
108391
|
+
const tempRoot = await mkdtemp6(join118(tmpdir3(), "context-lark-sheet-"));
|
|
108188
108392
|
try {
|
|
108189
|
-
const outputPath =
|
|
108393
|
+
const outputPath = join118(tempRoot, "sheet.json");
|
|
108190
108394
|
const stdout = await runLarkResourceCommand(runner2, [
|
|
108191
108395
|
"sheets",
|
|
108192
108396
|
"+csv-get",
|
|
@@ -108206,7 +108410,7 @@ async function sheetMaterialization(resource, runner2, identity2) {
|
|
|
108206
108410
|
if (findBooleanField(receipt2, "truncated") === true || findBooleanField(receipt2, "complete") === false) {
|
|
108207
108411
|
throw new Error("embedded Sheet read was truncated");
|
|
108208
108412
|
}
|
|
108209
|
-
const payload = JSON.parse(await
|
|
108413
|
+
const payload = JSON.parse(await readFile95(outputPath, "utf8"));
|
|
108210
108414
|
const csv = findStringField(payload, new Set(["annotated_csv", "csv", "content", "text"]));
|
|
108211
108415
|
if (csv === undefined)
|
|
108212
108416
|
throw new Error("embedded Sheet response has no CSV payload");
|
|
@@ -109377,8 +109581,8 @@ var init_sensitiveSourceLiteral = __esm(() => {
|
|
|
109377
109581
|
|
|
109378
109582
|
// src/project/larkSnapshotBundle.ts
|
|
109379
109583
|
import { createHash as createHash37 } from "node:crypto";
|
|
109380
|
-
import { lstat as lstat16, mkdir as mkdir39, readFile as
|
|
109381
|
-
import { basename as basename9, dirname as dirname47, isAbsolute as isAbsolute19, join as
|
|
109584
|
+
import { lstat as lstat16, mkdir as mkdir39, readFile as readFile96, realpath as realpath15, rename as rename10, writeFile as writeFile30 } from "node:fs/promises";
|
|
109585
|
+
import { basename as basename9, dirname as dirname47, isAbsolute as isAbsolute19, join as join119, relative as relative31, resolve as resolve37, sep as sep10 } from "node:path";
|
|
109382
109586
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
109383
109587
|
function normalizedSnapshotResourcePolicy(policy) {
|
|
109384
109588
|
return { ...policy, images: policy.images ?? "bundle", gifs: policy.gifs ?? "bundle" };
|
|
@@ -109419,13 +109623,13 @@ async function readFileEntry(root2, entry) {
|
|
|
109419
109623
|
const parts = safePath(entry.path).split("/");
|
|
109420
109624
|
let current3 = root2;
|
|
109421
109625
|
for (const [index3, part] of parts.entries()) {
|
|
109422
|
-
current3 =
|
|
109626
|
+
current3 = join119(current3, part);
|
|
109423
109627
|
const stat11 = await lstat16(current3);
|
|
109424
109628
|
if (stat11.isSymbolicLink() || (index3 === parts.length - 1 ? !stat11.isFile() : !stat11.isDirectory())) {
|
|
109425
109629
|
throw larkSnapshotError(`Snapshot entry is not a regular file: ${entry.path}`, "path-invalid");
|
|
109426
109630
|
}
|
|
109427
109631
|
}
|
|
109428
|
-
const bytes = await
|
|
109632
|
+
const bytes = await readFile96(current3);
|
|
109429
109633
|
if (digest7(bytes) !== entry.sha256)
|
|
109430
109634
|
throw larkSnapshotError(`Snapshot content changed: ${entry.path}`, "digest-mismatch");
|
|
109431
109635
|
return bytes;
|
|
@@ -109488,13 +109692,13 @@ async function writeLarkSnapshotBundle(input) {
|
|
|
109488
109692
|
};
|
|
109489
109693
|
schema2.parse(manifest);
|
|
109490
109694
|
for (const [path3, bytes] of files) {
|
|
109491
|
-
await mkdir39(dirname47(
|
|
109492
|
-
await writeFile30(
|
|
109695
|
+
await mkdir39(dirname47(join119(root2, path3)), { recursive: true });
|
|
109696
|
+
await writeFile30(join119(root2, path3), bytes, { flag: "wx", mode: 384 });
|
|
109493
109697
|
}
|
|
109494
109698
|
await validateBundle(root2, manifest);
|
|
109495
|
-
await writeFile30(
|
|
109699
|
+
await writeFile30(join119(root2, `${FILE2}.pending`), `${JSON.stringify(manifest, null, 2)}
|
|
109496
109700
|
`, { flag: "wx", mode: 384 });
|
|
109497
|
-
await rename10(
|
|
109701
|
+
await rename10(join119(root2, `${FILE2}.pending`), join119(root2, FILE2));
|
|
109498
109702
|
return manifest;
|
|
109499
109703
|
}
|
|
109500
109704
|
async function validateBundle(root2, manifest) {
|
|
@@ -109568,11 +109772,11 @@ async function validateBundle(root2, manifest) {
|
|
|
109568
109772
|
async function readLarkSnapshotBundle(directory, target) {
|
|
109569
109773
|
try {
|
|
109570
109774
|
const root2 = await assertSnapshotDirectory(directory);
|
|
109571
|
-
const path3 =
|
|
109775
|
+
const path3 = join119(root2, FILE2);
|
|
109572
109776
|
const stat11 = await lstat16(path3);
|
|
109573
109777
|
if (stat11.isSymbolicLink() || !stat11.isFile())
|
|
109574
109778
|
throw larkSnapshotError("Snapshot receipt must be a regular file", "path-invalid");
|
|
109575
|
-
const manifest = schema2.parse(JSON.parse(await
|
|
109779
|
+
const manifest = schema2.parse(JSON.parse(await readFile96(path3, "utf8")));
|
|
109576
109780
|
assertTarget(manifest.url, target);
|
|
109577
109781
|
return await validateBundle(root2, manifest);
|
|
109578
109782
|
} catch (error) {
|
|
@@ -109596,8 +109800,8 @@ async function reserveSnapshotDirectory(directory, workspaceRoot) {
|
|
|
109596
109800
|
ancestor = dirname47(ancestor);
|
|
109597
109801
|
}
|
|
109598
109802
|
}
|
|
109599
|
-
const parent2 =
|
|
109600
|
-
const output =
|
|
109803
|
+
const parent2 = join119(ancestor, ...missing2);
|
|
109804
|
+
const output = join119(parent2, basename9(requested));
|
|
109601
109805
|
const { findContextProjectRoot: findContextProjectRoot2 } = await Promise.resolve().then(() => (init_workspace(), exports_workspace));
|
|
109602
109806
|
const owner = findContextProjectRoot2(parent2)?.projectRoot ?? workspaceRoot;
|
|
109603
109807
|
if (owner !== undefined) {
|
|
@@ -109671,8 +109875,8 @@ var init_larkSnapshotBundle = __esm(() => {
|
|
|
109671
109875
|
|
|
109672
109876
|
// src/project/documentCaptureLark.ts
|
|
109673
109877
|
import { createHash as createHash38 } from "node:crypto";
|
|
109674
|
-
import { readdir as readdir28, readFile as
|
|
109675
|
-
import { basename as basename10, extname as extname14, join as
|
|
109878
|
+
import { readdir as readdir28, readFile as readFile97 } from "node:fs/promises";
|
|
109879
|
+
import { basename as basename10, extname as extname14, join as join120 } from "node:path";
|
|
109676
109880
|
function titleFromMarkdown2(markdown, fallbackPath) {
|
|
109677
109881
|
const heading2 = markdown.split(`
|
|
109678
109882
|
`).find((line) => /^#\s+\S/u.test(line));
|
|
@@ -109691,7 +109895,7 @@ function countLines3(markdown) {
|
|
|
109691
109895
|
}
|
|
109692
109896
|
async function fileContentMatches(path3, content3) {
|
|
109693
109897
|
try {
|
|
109694
|
-
const current3 = await
|
|
109898
|
+
const current3 = await readFile97(path3);
|
|
109695
109899
|
const expected = typeof content3 === "string" ? Buffer.from(content3, "utf8") : Buffer.from(content3);
|
|
109696
109900
|
return current3.equals(expected);
|
|
109697
109901
|
} catch {
|
|
@@ -109699,7 +109903,7 @@ async function fileContentMatches(path3, content3) {
|
|
|
109699
109903
|
}
|
|
109700
109904
|
}
|
|
109701
109905
|
function sourceManifestPath2(entry) {
|
|
109702
|
-
return entry.snapshot?.manifest ??
|
|
109906
|
+
return entry.snapshot?.manifest ?? join120(entry.materializedAt, "manifest.json");
|
|
109703
109907
|
}
|
|
109704
109908
|
function larkRuntimeError(message, detail) {
|
|
109705
109909
|
return new ContextError(ExitCode.ExternalToolError, message, {
|
|
@@ -109832,7 +110036,7 @@ function assetManifestEntry(asset, assetRoot) {
|
|
|
109832
110036
|
};
|
|
109833
110037
|
}
|
|
109834
110038
|
async function listSnapshotAssetFiles(root2, assetRoot) {
|
|
109835
|
-
const assetsRoot =
|
|
110039
|
+
const assetsRoot = join120(root2, assetRoot);
|
|
109836
110040
|
const files = [];
|
|
109837
110041
|
const visit4 = async (dir, prefix = assetRoot) => {
|
|
109838
110042
|
let entries2;
|
|
@@ -109845,7 +110049,7 @@ async function listSnapshotAssetFiles(root2, assetRoot) {
|
|
|
109845
110049
|
}
|
|
109846
110050
|
for (const entry of entries2) {
|
|
109847
110051
|
const relPath = `${prefix}/${entry.name}`;
|
|
109848
|
-
const absolutePath =
|
|
110052
|
+
const absolutePath = join120(dir, entry.name);
|
|
109849
110053
|
if (entry.isDirectory()) {
|
|
109850
110054
|
await visit4(absolutePath, relPath);
|
|
109851
110055
|
continue;
|
|
@@ -109860,7 +110064,7 @@ async function listSnapshotAssetFiles(root2, assetRoot) {
|
|
|
109860
110064
|
}
|
|
109861
110065
|
async function staleSnapshotAssetPaths(input) {
|
|
109862
110066
|
const existingPaths = await listSnapshotAssetFiles(input.materializedAtAbsPath, input.assetRoot);
|
|
109863
|
-
return existingPaths.filter((path3) => !input.currentPaths.has(path3)).map((path3) =>
|
|
110067
|
+
return existingPaths.filter((path3) => !input.currentPaths.has(path3)).map((path3) => join120(input.materializedAtAbsPath, path3));
|
|
109864
110068
|
}
|
|
109865
110069
|
function normalizeLarkError(error, sourceName) {
|
|
109866
110070
|
if (error instanceof ContextError)
|
|
@@ -109924,7 +110128,7 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
109924
110128
|
const target = larkTarget(entry);
|
|
109925
110129
|
const manifestPath = sourceManifestPath2(entry);
|
|
109926
110130
|
const materializedAt = entry.materializedAt;
|
|
109927
|
-
const materializedAtAbsPath =
|
|
110131
|
+
const materializedAtAbsPath = join120(input.projectRoot, materializedAt);
|
|
109928
110132
|
const { current: currentManifestFile, previous: previousManifest, recovery } = await readDocumentManifestForCapture({
|
|
109929
110133
|
projectRoot: input.projectRoot,
|
|
109930
110134
|
manifestPath,
|
|
@@ -110071,7 +110275,7 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
110071
110275
|
title: title2,
|
|
110072
110276
|
locator
|
|
110073
110277
|
}];
|
|
110074
|
-
const manifestAbsPath =
|
|
110278
|
+
const manifestAbsPath = join120(input.projectRoot, manifestPath);
|
|
110075
110279
|
const manifest = createDocumentSnapshotManifest({
|
|
110076
110280
|
sourceType: "lark",
|
|
110077
110281
|
sourceName: resolved.sourceName,
|
|
@@ -110101,13 +110305,13 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
110101
110305
|
const cacheDiagnostics = [];
|
|
110102
110306
|
try {
|
|
110103
110307
|
const requestedWrites = [{
|
|
110104
|
-
path:
|
|
110308
|
+
path: join120(materializedAtAbsPath, documentPath),
|
|
110105
110309
|
bytes: normalized
|
|
110106
110310
|
}];
|
|
110107
110311
|
for (const asset of assets) {
|
|
110108
110312
|
if (asset.bytes !== undefined) {
|
|
110109
110313
|
requestedWrites.push({
|
|
110110
|
-
path:
|
|
110314
|
+
path: join120(materializedAtAbsPath, asset.entry.path),
|
|
110111
110315
|
bytes: asset.bytes
|
|
110112
110316
|
});
|
|
110113
110317
|
}
|
|
@@ -110141,7 +110345,7 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
110141
110345
|
if (relativePath in capturedFiles)
|
|
110142
110346
|
continue;
|
|
110143
110347
|
try {
|
|
110144
|
-
capturedFiles[relativePath] = `sha256:${createHash38("sha256").update(await
|
|
110348
|
+
capturedFiles[relativePath] = `sha256:${createHash38("sha256").update(await readFile97(join120(input.projectRoot, relativePath))).digest("hex")}`;
|
|
110145
110349
|
} catch (error) {
|
|
110146
110350
|
if (error.code === "ENOENT")
|
|
110147
110351
|
capturedFiles[relativePath] = null;
|
|
@@ -110150,7 +110354,7 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
110150
110354
|
}
|
|
110151
110355
|
}
|
|
110152
110356
|
await applyAtomicFileBatch({
|
|
110153
|
-
transactionRoot:
|
|
110357
|
+
transactionRoot: join120(input.projectRoot, ".tmp", "context-runtime", "capture-transactions"),
|
|
110154
110358
|
writes,
|
|
110155
110359
|
removals
|
|
110156
110360
|
});
|
|
@@ -110335,8 +110539,8 @@ __export(exports_writeLockRecovery, {
|
|
|
110335
110539
|
recoverWriterLock: () => recoverWriterLock,
|
|
110336
110540
|
inspectWriterLock: () => inspectWriterLock
|
|
110337
110541
|
});
|
|
110338
|
-
import { lstat as lstat17, mkdir as mkdir41, readFile as
|
|
110339
|
-
import { join as
|
|
110542
|
+
import { lstat as lstat17, mkdir as mkdir41, readFile as readFile103, readdir as readdir29, rename as rename11, rmdir as rmdir2 } from "node:fs/promises";
|
|
110543
|
+
import { join as join125 } from "node:path";
|
|
110340
110544
|
import { createHash as createHash40, randomUUID as randomUUID8 } from "node:crypto";
|
|
110341
110545
|
async function inspectWriterLock(root2) {
|
|
110342
110546
|
const path3 = await safeProjectTarget(root2, lockRelative);
|
|
@@ -110351,7 +110555,7 @@ async function inspectWriterLock(root2) {
|
|
|
110351
110555
|
if (!stat11.isDirectory() || stat11.isSymbolicLink())
|
|
110352
110556
|
throw new Error("Writer lock must be a real directory.");
|
|
110353
110557
|
const ownerPath = await safeProjectTarget(root2, `${lockRelative}/owner.json`);
|
|
110354
|
-
const bytes = await
|
|
110558
|
+
const bytes = await readFile103(ownerPath, "utf8");
|
|
110355
110559
|
const owner = JSON.parse(bytes);
|
|
110356
110560
|
if (owner.protocol !== "context.project-write-lock.v1" || !Number.isSafeInteger(owner.pid) || owner.pid <= 0) {
|
|
110357
110561
|
throw new Error("Writer lock owner is invalid; preserve the lock for diagnosis.");
|
|
@@ -110387,8 +110591,8 @@ async function recoverWriterLock(input) {
|
|
|
110387
110591
|
};
|
|
110388
110592
|
if (input.plan_digest !== revision)
|
|
110389
110593
|
throw new Error("Writer lock or transactions changed; preview recovery again.");
|
|
110390
|
-
const path3 =
|
|
110391
|
-
const guard =
|
|
110594
|
+
const path3 = join125(input.projectRoot, lockRelative);
|
|
110595
|
+
const guard = join125(path3, ".recovery");
|
|
110392
110596
|
await mkdir41(guard);
|
|
110393
110597
|
let archived = false;
|
|
110394
110598
|
try {
|
|
@@ -110399,7 +110603,7 @@ async function recoverWriterLock(input) {
|
|
|
110399
110603
|
if (names.some((name3) => name3 !== "owner.json" && name3 !== ".recovery"))
|
|
110400
110604
|
throw new Error("Unexpected lock contents; preserve for diagnosis.");
|
|
110401
110605
|
const archive = `.tmp/context-runtime/locks/recovered-write-${randomUUID8()}.lock`;
|
|
110402
|
-
await rename11(path3,
|
|
110606
|
+
await rename11(path3, join125(input.projectRoot, archive));
|
|
110403
110607
|
archived = true;
|
|
110404
110608
|
const receipts = await withProjectWriteLock(input.projectRoot, "recover-writer-transactions", async () => {
|
|
110405
110609
|
if (JSON.stringify(await recoveryJournals(input.projectRoot)) !== JSON.stringify(journals)) {
|
|
@@ -110431,13 +110635,13 @@ __export(exports_taskRecovery, {
|
|
|
110431
110635
|
TRANSACTIONS_PATH: () => TRANSACTIONS_PATH,
|
|
110432
110636
|
RECOVERY_COMMAND: () => RECOVERY_COMMAND
|
|
110433
110637
|
});
|
|
110434
|
-
import { existsSync as
|
|
110435
|
-
import { basename as basename11, dirname as dirname50, join as
|
|
110436
|
-
import { lstat as lstat18, readdir as readdir30, readFile as
|
|
110638
|
+
import { existsSync as existsSync32 } from "node:fs";
|
|
110639
|
+
import { basename as basename11, dirname as dirname50, join as join126 } from "node:path";
|
|
110640
|
+
import { lstat as lstat18, readdir as readdir30, readFile as readFile104 } from "node:fs/promises";
|
|
110437
110641
|
async function recoveryText(root2, path3) {
|
|
110438
110642
|
const target = await safeProjectTarget(root2, path3);
|
|
110439
110643
|
try {
|
|
110440
|
-
return await
|
|
110644
|
+
return await readFile104(target, "utf8");
|
|
110441
110645
|
} catch (error) {
|
|
110442
110646
|
if (error.code === "ENOENT")
|
|
110443
110647
|
return;
|
|
@@ -110450,7 +110654,7 @@ async function recoveryJournals(root2) {
|
|
|
110450
110654
|
await safeProjectTarget(root2, path3);
|
|
110451
110655
|
let stat11;
|
|
110452
110656
|
try {
|
|
110453
|
-
stat11 = await lstat18(
|
|
110657
|
+
stat11 = await lstat18(join126(root2, path3));
|
|
110454
110658
|
} catch (error) {
|
|
110455
110659
|
if (error.code === "ENOENT")
|
|
110456
110660
|
return;
|
|
@@ -110461,7 +110665,7 @@ async function recoveryJournals(root2) {
|
|
|
110461
110665
|
if (stat11.isDirectory()) {
|
|
110462
110666
|
if (depth > 3)
|
|
110463
110667
|
throw new TypeError("Unexpected transaction directory depth; preserve it for diagnosis.");
|
|
110464
|
-
for (const name3 of (await readdir30(
|
|
110668
|
+
for (const name3 of (await readdir30(join126(root2, path3))).sort())
|
|
110465
110669
|
await visit4(`${path3}/${name3}`, depth + 1);
|
|
110466
110670
|
} else if (stat11.isFile())
|
|
110467
110671
|
entries2.push({ path: path3, digest: indexerProtocolDigest(await recoveryText(root2, path3)) });
|
|
@@ -110473,10 +110677,10 @@ function recoveryResources() {
|
|
|
110473
110677
|
try {
|
|
110474
110678
|
const root2 = dirname50(contextWorkflowProviderPath());
|
|
110475
110679
|
const resources = {
|
|
110476
|
-
skill:
|
|
110477
|
-
issue_template:
|
|
110680
|
+
skill: join126(root2, "skills/recover-workspace/SKILL.md"),
|
|
110681
|
+
issue_template: join126(root2, "resources/templates/recovery-issue.md")
|
|
110478
110682
|
};
|
|
110479
|
-
if (!Object.values(resources).every((path3) =>
|
|
110683
|
+
if (!Object.values(resources).every((path3) => existsSync32(path3)))
|
|
110480
110684
|
throw new Error("Recovery resources are absent from this Provider.");
|
|
110481
110685
|
return resources;
|
|
110482
110686
|
} catch {
|
|
@@ -110589,8 +110793,8 @@ var exports_taskLocalSourceAdjustment = {};
|
|
|
110589
110793
|
__export(exports_taskLocalSourceAdjustment, {
|
|
110590
110794
|
adjustLocalRevisionSources: () => adjustLocalRevisionSources
|
|
110591
110795
|
});
|
|
110592
|
-
import { readFile as
|
|
110593
|
-
import { join as
|
|
110796
|
+
import { readFile as readFile105 } from "node:fs/promises";
|
|
110797
|
+
import { join as join127 } from "node:path";
|
|
110594
110798
|
async function adjustLocalRevisionSources(root2, input) {
|
|
110595
110799
|
const { readMaintenance: readMaintenance2 } = await Promise.resolve().then(() => (init_maintenanceStorage(), exports_maintenanceStorage));
|
|
110596
110800
|
if ((await readMaintenance2(root2)).active && await readProductionStage(root2))
|
|
@@ -110636,7 +110840,7 @@ async function adjustLocalRevisionSources(root2, input) {
|
|
|
110636
110840
|
if (input.refresh && (!current3.refresh_sources || indexerProtocolDigest([...current3.refresh_sources].sort()) !== indexerProtocolDigest([...selected].sort()))) {
|
|
110637
110841
|
throw new TypeError("No matching acquisition adjustment exists. Run task adjust without refresh first.");
|
|
110638
110842
|
}
|
|
110639
|
-
const raw = await
|
|
110843
|
+
const raw = await readFile105(join127(root2, await revisionStoragePath(root2)), "utf8");
|
|
110640
110844
|
let next2;
|
|
110641
110845
|
const discardIds = new Set;
|
|
110642
110846
|
if (!refresh) {
|
|
@@ -110751,7 +110955,7 @@ ${input.instruction}` : revision.instruction
|
|
|
110751
110955
|
content: content3
|
|
110752
110956
|
}];
|
|
110753
110957
|
if (discardIds.size > 0) {
|
|
110754
|
-
const ledger = await
|
|
110958
|
+
const ledger = await readFile105(join127(root2, CANDIDATE_LEDGER_FILE), "utf8").catch((error) => {
|
|
110755
110959
|
if (error.code === "ENOENT")
|
|
110756
110960
|
return;
|
|
110757
110961
|
throw error;
|
|
@@ -110975,6 +111179,9 @@ async function completeCurrentIndexerActionInternal(input) {
|
|
|
110975
111179
|
...await readApprovedRevision(found.projectRoot) ? {
|
|
110976
111180
|
expected_stage: "approved-revision",
|
|
110977
111181
|
hint: "Submit the active revision with stage: approved-revision and its current revision token. Do not clear the task or remove sources to repair a payload."
|
|
111182
|
+
} : await readKnowledgeUpdate(found.projectRoot) ? {
|
|
111183
|
+
expected_stage: "source-update",
|
|
111184
|
+
hint: "Submit the source update decision with stage: source-update, decisions, scope_summary and new_topics, as in the Route's output schema."
|
|
110978
111185
|
} : {},
|
|
110979
111186
|
next_action: { command: "context status --format json" }
|
|
110980
111187
|
});
|
|
@@ -111096,7 +111303,7 @@ __export(exports_approvedRevisionSubmission, {
|
|
|
111096
111303
|
prepareApprovedRevisionSubmission: () => prepareApprovedRevisionSubmission,
|
|
111097
111304
|
completeApprovedRevisionSubmission: () => completeApprovedRevisionSubmission
|
|
111098
111305
|
});
|
|
111099
|
-
import { join as
|
|
111306
|
+
import { join as join129 } from "node:path";
|
|
111100
111307
|
function paused(message, managed, authorities = []) {
|
|
111101
111308
|
return new ContextError(ExitCode.WorkspaceStateError, message, {
|
|
111102
111309
|
category: ErrorCategory.WorkspaceStateInvalid,
|
|
@@ -111151,9 +111358,9 @@ async function prepareApprovedRevisionSubmission(input) {
|
|
|
111151
111358
|
const { route, requests, contexts, issued } = await issueRevisionBatch(input);
|
|
111152
111359
|
const stage = stageId(issued);
|
|
111153
111360
|
const directory = productionAgentDirectory(stage);
|
|
111154
|
-
await atomicWriteFile(await safeProjectTarget(input.projectRoot,
|
|
111361
|
+
await atomicWriteFile(await safeProjectTarget(input.projectRoot, join129(directory, "issued.json")), JSON.stringify(issued));
|
|
111155
111362
|
for (const [index3, request] of requests.entries()) {
|
|
111156
|
-
await atomicWriteFile(await safeProjectTarget(input.projectRoot,
|
|
111363
|
+
await atomicWriteFile(await safeProjectTarget(input.projectRoot, join129(directory, `${issued.tasks[index3].task}.input.json`)), JSON.stringify({
|
|
111157
111364
|
stage: "approved-revision",
|
|
111158
111365
|
revision: request.revision,
|
|
111159
111366
|
instruction: request.instruction,
|
|
@@ -111168,7 +111375,7 @@ async function prepareApprovedRevisionSubmission(input) {
|
|
|
111168
111375
|
tasks: issued.tasks.map((task, index3) => ({
|
|
111169
111376
|
...task,
|
|
111170
111377
|
path: requests[index3].target.path,
|
|
111171
|
-
task_input:
|
|
111378
|
+
task_input: join129(directory, `${task.task}.input.json`)
|
|
111172
111379
|
})),
|
|
111173
111380
|
submission: { stage, tasks: issued.tasks.map((task) => ({ task: task.task, input: task.input, edits: `${task.task}.edits.json` })) },
|
|
111174
111381
|
next_action: {
|
|
@@ -111396,7 +111603,7 @@ var init_approvedRevisionSubmission = __esm(() => {
|
|
|
111396
111603
|
});
|
|
111397
111604
|
|
|
111398
111605
|
// src/project/managedDocumentImport.ts
|
|
111399
|
-
import { readFile as
|
|
111606
|
+
import { readFile as readFile114 } from "node:fs/promises";
|
|
111400
111607
|
async function importManagedDocument(projectRoot2, value) {
|
|
111401
111608
|
const input = inputSchema.parse(value);
|
|
111402
111609
|
if (input.type !== "sessions" && input.changes !== undefined)
|
|
@@ -111405,7 +111612,7 @@ async function importManagedDocument(projectRoot2, value) {
|
|
|
111405
111612
|
const path3 = await assertManagedDocumentPath(projectRoot2, input.type, input.name);
|
|
111406
111613
|
let previous3;
|
|
111407
111614
|
try {
|
|
111408
|
-
previous3 = await
|
|
111615
|
+
previous3 = await readFile114(path3, "utf8");
|
|
111409
111616
|
} catch (error) {
|
|
111410
111617
|
if (!(error && typeof error === "object" && ("code" in error) && error.code === "ENOENT"))
|
|
111411
111618
|
throw error;
|
|
@@ -111452,7 +111659,7 @@ var init_managedDocumentImport = __esm(() => {
|
|
|
111452
111659
|
});
|
|
111453
111660
|
|
|
111454
111661
|
// src/project/larkDocumentImport.ts
|
|
111455
|
-
import { readFile as
|
|
111662
|
+
import { readFile as readFile115 } from "node:fs/promises";
|
|
111456
111663
|
import { resolve as resolve48 } from "node:path";
|
|
111457
111664
|
async function importLarkDocument(projectRoot2, value) {
|
|
111458
111665
|
const input = schema4.parse(value);
|
|
@@ -111469,7 +111676,7 @@ async function importLarkDocument(projectRoot2, value) {
|
|
|
111469
111676
|
const responsePages = [];
|
|
111470
111677
|
for (const path3 of input.response_files) {
|
|
111471
111678
|
assertActionInputWorkspace(projectRoot2, path3);
|
|
111472
|
-
responsePages.push(await
|
|
111679
|
+
responsePages.push(await readFile115(resolve48(projectRoot2, path3), "utf8"));
|
|
111473
111680
|
}
|
|
111474
111681
|
const mediaFiles = {};
|
|
111475
111682
|
for (const [token, path3] of Object.entries(input.media_files ?? {})) {
|
|
@@ -111536,11 +111743,11 @@ var exports_managedDocumentRename = {};
|
|
|
111536
111743
|
__export(exports_managedDocumentRename, {
|
|
111537
111744
|
renameManagedDocument: () => renameManagedDocument
|
|
111538
111745
|
});
|
|
111539
|
-
import { readFile as
|
|
111540
|
-
import { join as
|
|
111746
|
+
import { readFile as readFile116 } from "node:fs/promises";
|
|
111747
|
+
import { join as join141, posix as posix15 } from "node:path";
|
|
111541
111748
|
async function optionalText3(path3) {
|
|
111542
111749
|
try {
|
|
111543
|
-
return await
|
|
111750
|
+
return await readFile116(path3, "utf8");
|
|
111544
111751
|
} catch (error) {
|
|
111545
111752
|
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT")
|
|
111546
111753
|
return;
|
|
@@ -111624,7 +111831,7 @@ async function renameManagedDocument(input) {
|
|
|
111624
111831
|
if (path3.split("/").includes("..") || path3.startsWith("/"))
|
|
111625
111832
|
throw new TypeError("Source references contain an unsafe knowledge path; repair it before renaming.");
|
|
111626
111833
|
await safeProjectTarget(input.projectRoot, path3);
|
|
111627
|
-
const before = await optionalText3(
|
|
111834
|
+
const before = await optionalText3(join141(input.projectRoot, path3));
|
|
111628
111835
|
if (before === undefined)
|
|
111629
111836
|
continue;
|
|
111630
111837
|
let after;
|
|
@@ -111637,7 +111844,7 @@ async function renameManagedDocument(input) {
|
|
|
111637
111844
|
references: section.references.map((citation) => citation.source_ref !== input.source_ref ? citation : {
|
|
111638
111845
|
...citation,
|
|
111639
111846
|
source_ref: nextRef,
|
|
111640
|
-
locator: { ...citation.locator, path:
|
|
111847
|
+
locator: { ...citation.locator, path: posix15.basename(input.name) }
|
|
111641
111848
|
})
|
|
111642
111849
|
})) }));
|
|
111643
111850
|
updated.articles = rewritten;
|
|
@@ -111663,11 +111870,11 @@ async function renameManagedDocument(input) {
|
|
|
111663
111870
|
return;
|
|
111664
111871
|
}
|
|
111665
111872
|
const rooted = destination.startsWith("sources/") || destination.startsWith("/sources/");
|
|
111666
|
-
const resolved = rooted ? destination.replace(/^\//u, "") :
|
|
111873
|
+
const resolved = rooted ? destination.replace(/^\//u, "") : posix15.normalize(posix15.join(posix15.dirname(path3), destination));
|
|
111667
111874
|
if (resolved !== `sources/${type}/${oldName}`)
|
|
111668
111875
|
return;
|
|
111669
111876
|
const renamed = `sources/${type}/${input.name}`;
|
|
111670
|
-
return encodeURI(rooted ? `${destination.startsWith("/") ? "/" : ""}${renamed}` :
|
|
111877
|
+
return encodeURI(rooted ? `${destination.startsWith("/") ? "/" : ""}${renamed}` : posix15.relative(posix15.dirname(path3), renamed)) + match2[2];
|
|
111671
111878
|
});
|
|
111672
111879
|
if (before === after)
|
|
111673
111880
|
continue;
|
|
@@ -111716,7 +111923,7 @@ var exports_originalRevisionsCommand = {};
|
|
|
111716
111923
|
__export(exports_originalRevisionsCommand, {
|
|
111717
111924
|
runOriginalRevisionsCommand: () => runOriginalRevisionsCommand
|
|
111718
111925
|
});
|
|
111719
|
-
import { readFile as
|
|
111926
|
+
import { readFile as readFile120 } from "node:fs/promises";
|
|
111720
111927
|
import { resolve as resolve56 } from "node:path";
|
|
111721
111928
|
async function readInput(cwd, source2) {
|
|
111722
111929
|
const raw = source2 === "-" ? await new Promise((resolveInput, reject) => {
|
|
@@ -111727,7 +111934,7 @@ async function readInput(cwd, source2) {
|
|
|
111727
111934
|
});
|
|
111728
111935
|
process.stdin.on("end", () => resolveInput(data2));
|
|
111729
111936
|
process.stdin.on("error", reject);
|
|
111730
|
-
}) : await
|
|
111937
|
+
}) : await readFile120(resolve56(cwd, source2), "utf8");
|
|
111731
111938
|
return import_yaml68.default.parse(raw);
|
|
111732
111939
|
}
|
|
111733
111940
|
async function runOriginalRevisionsCommand(input) {
|
|
@@ -111781,8 +111988,8 @@ var init_originalRevisionsCommand = __esm(() => {
|
|
|
111781
111988
|
});
|
|
111782
111989
|
|
|
111783
111990
|
// src/cli.ts
|
|
111784
|
-
import { existsSync as
|
|
111785
|
-
import { dirname as dirname57, join as
|
|
111991
|
+
import { existsSync as existsSync41, realpathSync as realpathSync3 } from "node:fs";
|
|
111992
|
+
import { dirname as dirname57, join as join147 } from "node:path";
|
|
111786
111993
|
import { fileURLToPath as fileURLToPath12, pathToFileURL as pathToFileURL3 } from "node:url";
|
|
111787
111994
|
|
|
111788
111995
|
// ../../node_modules/.bun/commander@11.1.0/node_modules/commander/esm.mjs
|
|
@@ -111821,15 +112028,15 @@ init_workflowFacts();
|
|
|
111821
112028
|
init_workflowProvider();
|
|
111822
112029
|
init_workflowResourceRender();
|
|
111823
112030
|
init_workflowTypes();
|
|
111824
|
-
import { join as
|
|
112031
|
+
import { join as join114 } from "node:path";
|
|
111825
112032
|
|
|
111826
112033
|
// src/project/reviewHtml.ts
|
|
111827
112034
|
init_originalRevisions();
|
|
111828
112035
|
init_candidateLedger();
|
|
111829
112036
|
init_reviewShared();
|
|
111830
|
-
import { copyFile, mkdir as mkdir37, readFile as
|
|
112037
|
+
import { copyFile, mkdir as mkdir37, readFile as readFile91, writeFile as writeFile29 } from "node:fs/promises";
|
|
111831
112038
|
import { fileURLToPath as fileURLToPath8 } from "node:url";
|
|
111832
|
-
import { dirname as dirname46, isAbsolute as isAbsolute17, join as
|
|
112039
|
+
import { dirname as dirname46, isAbsolute as isAbsolute17, join as join112, resolve as resolve35 } from "node:path";
|
|
111833
112040
|
|
|
111834
112041
|
// src/project/reviewSiteModel.ts
|
|
111835
112042
|
init_siteTheme2();
|
|
@@ -111837,8 +112044,8 @@ init_src2();
|
|
|
111837
112044
|
init_unified();
|
|
111838
112045
|
init_remark_parse();
|
|
111839
112046
|
var import_yaml52 = __toESM(require_dist(), 1);
|
|
111840
|
-
import { readFile as
|
|
111841
|
-
import { join as
|
|
112047
|
+
import { readFile as readFile89 } from "node:fs/promises";
|
|
112048
|
+
import { join as join110 } from "node:path";
|
|
111842
112049
|
import { execFile as execFile17 } from "node:child_process";
|
|
111843
112050
|
import { promisify as promisify14 } from "node:util";
|
|
111844
112051
|
import { createHash as createHash33 } from "node:crypto";
|
|
@@ -114803,10 +115010,10 @@ function remarkGfm(options) {
|
|
|
114803
115010
|
init_workspace();
|
|
114804
115011
|
|
|
114805
115012
|
// src/project/reviewFeedback.ts
|
|
114806
|
-
import { readdir as readdir24, readFile as
|
|
114807
|
-
import { join as
|
|
115013
|
+
import { readdir as readdir24, readFile as readFile87 } from "node:fs/promises";
|
|
115014
|
+
import { join as join109 } from "node:path";
|
|
114808
115015
|
async function readPendingReviewFeedback(root2, candidates) {
|
|
114809
|
-
const directory =
|
|
115016
|
+
const directory = join109(root2, ".tmp/context-runtime/review-feedback");
|
|
114810
115017
|
let files;
|
|
114811
115018
|
try {
|
|
114812
115019
|
files = await readdir24(directory);
|
|
@@ -114819,7 +115026,7 @@ async function readPendingReviewFeedback(root2, candidates) {
|
|
|
114819
115026
|
const results = new Map;
|
|
114820
115027
|
const receipts = [];
|
|
114821
115028
|
for (const file of files.filter((f) => /^[a-f0-9]+\.json$/u.test(f)).sort()) {
|
|
114822
|
-
const receipt2 = JSON.parse(await
|
|
115029
|
+
const receipt2 = JSON.parse(await readFile87(join109(directory, file), "utf8"));
|
|
114823
115030
|
receipts.push(receipt2);
|
|
114824
115031
|
}
|
|
114825
115032
|
for (const receipt2 of receipts.sort((a2, b) => a2.created_at.localeCompare(b.created_at))) {
|
|
@@ -114929,7 +115136,7 @@ var title = (s, fallback) => {
|
|
|
114929
115136
|
};
|
|
114930
115137
|
async function optional2(path3) {
|
|
114931
115138
|
try {
|
|
114932
|
-
return await
|
|
115139
|
+
return await readFile89(path3, "utf8");
|
|
114933
115140
|
} catch (e) {
|
|
114934
115141
|
if (e.code === "ENOENT")
|
|
114935
115142
|
return;
|
|
@@ -114966,7 +115173,7 @@ async function reviewSiteBaselineHash(root2, reviewedPaths) {
|
|
|
114966
115173
|
const displayed = new Set([...reviewedPaths, ...(metadata.structure?.articles ?? []).filter((a2) => navigation.changedArticles.has(a2.article_id)).map((a2) => a2.path)]);
|
|
114967
115174
|
return hash4(JSON.stringify([
|
|
114968
115175
|
navigation.baseline,
|
|
114969
|
-
await optional2(
|
|
115176
|
+
await optional2(join110(root2, "src/knowledge-map.yaml")) ?? null,
|
|
114970
115177
|
navigation.planned ? [navigation.planned.retired, navigation.planned.knowledge_map ?? null] : null,
|
|
114971
115178
|
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]))
|
|
114972
115179
|
]));
|
|
@@ -115079,9 +115286,9 @@ async function collectReviewSiteModel(root2, candidates) {
|
|
|
115079
115286
|
nodes.push({ key: `review-page-${p.id}`, parent: "review-unplaced", title: p.title, order: i2, page: p.id, change: p.change });
|
|
115080
115287
|
}
|
|
115081
115288
|
const navigationChanges = navigationBaseline === "empty" ? [] : reviewNavigationChanges(baseline?.entries ?? [], current3?.entries ?? [], pages);
|
|
115082
|
-
const pkgText = await optional2(
|
|
115289
|
+
const pkgText = await optional2(join110(root2, "package.json"));
|
|
115083
115290
|
const pkg = pkgText ? JSON.parse(pkgText) : {};
|
|
115084
|
-
const project = await optional2(
|
|
115291
|
+
const project = await optional2(join110(root2, "src/index.ts")) === undefined ? undefined : await loadContextProjectModule(root2);
|
|
115085
115292
|
const siteTitle = project?.project.packages.flatMap((p) => p.kind === "package.kb" && p.site?.title ? [p.site.title] : [])[0];
|
|
115086
115293
|
const sitePackages = project?.project.packages.flatMap((p) => p.kind === "package.kb" && p.site ? [p.site] : []) ?? [];
|
|
115087
115294
|
const themeCss = siteThemeVariables(await resolveSiteTheme(root2, sitePackages.length === 1 ? sitePackages[0]?.theme : undefined));
|
|
@@ -115148,9 +115355,9 @@ init_errors3();
|
|
|
115148
115355
|
init_cliFeedback();
|
|
115149
115356
|
init_exitCode();
|
|
115150
115357
|
init_reviewShared();
|
|
115151
|
-
import { readFile as
|
|
115152
|
-
import { join as
|
|
115153
|
-
var scopePath = (root2, scope2) =>
|
|
115358
|
+
import { readFile as readFile90 } from "node:fs/promises";
|
|
115359
|
+
import { join as join111 } from "node:path";
|
|
115360
|
+
var scopePath = (root2, scope2) => join111(root2, ".tmp/context-runtime/review", `${scope2}.scope.json`);
|
|
115154
115361
|
async function saveReviewReportScope(root2, scope2, candidates, baselineHash, reportPath) {
|
|
115155
115362
|
const ids = candidates.map((candidate) => candidate.record.candidate_id).sort();
|
|
115156
115363
|
const value = {
|
|
@@ -115170,7 +115377,7 @@ async function saveReviewReportScope(root2, scope2, candidates, baselineHash, re
|
|
|
115170
115377
|
}
|
|
115171
115378
|
async function readConfirmedReviewScope(root2, scope2) {
|
|
115172
115379
|
try {
|
|
115173
|
-
const value = JSON.parse(await
|
|
115380
|
+
const value = JSON.parse(await readFile90(scopePath(root2, scope2), "utf8"));
|
|
115174
115381
|
if (!value || typeof value !== "object" || !("scope" in value) || !("baseline_hash" in value))
|
|
115175
115382
|
throw new Error("Missing report scope");
|
|
115176
115383
|
const parsed = value;
|
|
@@ -115712,7 +115919,7 @@ button:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
|
|
|
115712
115919
|
|
|
115713
115920
|
// src/project/reviewHtml.ts
|
|
115714
115921
|
init_knowledgeMap2();
|
|
115715
|
-
var REVIEW_HTML_ROOT =
|
|
115922
|
+
var REVIEW_HTML_ROOT = join112(".tmp", "context-runtime", "review");
|
|
115716
115923
|
async function collectReviewCandidates(projectRoot, collection) {
|
|
115717
115924
|
const rows = await readCandidateRecords(projectRoot);
|
|
115718
115925
|
const draftRows = rows.filter((row) => row.collection === collection && row.status === "draft");
|
|
@@ -115762,13 +115969,13 @@ ${diagramScript ? `<script>${diagramScript}</script>` : ""}<script>const DATA=${
|
|
|
115762
115969
|
}
|
|
115763
115970
|
function resolveOutputPath(projectRoot, outPath, reviewScope) {
|
|
115764
115971
|
if (outPath === undefined)
|
|
115765
|
-
return
|
|
115972
|
+
return join112(projectRoot, REVIEW_HTML_ROOT, `${reviewScope}.html`);
|
|
115766
115973
|
return isAbsolute17(outPath) ? outPath : resolve35(projectRoot, outPath);
|
|
115767
115974
|
}
|
|
115768
|
-
var APPLIED_REVIEW_REPORT_ROOT =
|
|
115975
|
+
var APPLIED_REVIEW_REPORT_ROOT = join112(".tmp", "review-reports");
|
|
115769
115976
|
async function archiveAppliedReviewReport(projectRoot, reportPath, scope2) {
|
|
115770
115977
|
const stamp = new Date().toISOString().replace(/[:.]/gu, "-");
|
|
115771
|
-
const target =
|
|
115978
|
+
const target = join112(projectRoot, APPLIED_REVIEW_REPORT_ROOT, `${stamp}-${scope2}.html`);
|
|
115772
115979
|
await mkdir37(dirname46(target), { recursive: true });
|
|
115773
115980
|
await copyFile(reportPath, target);
|
|
115774
115981
|
return target;
|
|
@@ -115814,11 +116021,11 @@ async function writeReviewHtml(input) {
|
|
|
115814
116021
|
if (model.pages.some((page) => page.html.includes('class="language-mermaid"'))) {
|
|
115815
116022
|
const here = dirname46(fileURLToPath8(import.meta.url));
|
|
115816
116023
|
try {
|
|
115817
|
-
diagramScript = await
|
|
116024
|
+
diagramScript = await readFile91(join112(here, "browser/diagrams.js"), "utf8");
|
|
115818
116025
|
} catch (error) {
|
|
115819
116026
|
if (error.code !== "ENOENT")
|
|
115820
116027
|
throw error;
|
|
115821
|
-
diagramScript = await
|
|
116028
|
+
diagramScript = await readFile91(resolve35(here, "../../dist/browser/diagrams.js"), "utf8");
|
|
115822
116029
|
}
|
|
115823
116030
|
}
|
|
115824
116031
|
await writeFile29(outPath, renderReviewHtml(model, diagramScript), "utf8");
|
|
@@ -115862,8 +116069,8 @@ init_productionRequirements();
|
|
|
115862
116069
|
init_dist();
|
|
115863
116070
|
init_atomicWrite();
|
|
115864
116071
|
init_reviewShared();
|
|
115865
|
-
import { mkdir as mkdir38, readFile as
|
|
115866
|
-
import { join as
|
|
116072
|
+
import { mkdir as mkdir38, readFile as readFile92 } from "node:fs/promises";
|
|
116073
|
+
import { join as join113 } from "node:path";
|
|
115867
116074
|
var REVIEW_BATCH_MAX_CANDIDATES = 6;
|
|
115868
116075
|
var REVIEW_BATCH_MAX_BYTES = 512 * 1024;
|
|
115869
116076
|
async function readerPurposes(projectRoot, sources) {
|
|
@@ -115943,12 +116150,12 @@ async function materializeCurrentReviewBatchSet(input) {
|
|
|
115943
116150
|
const batches = buildCurrentReviewBatchDocuments(input.candidates);
|
|
115944
116151
|
const setDigest = digestText(batches.map((batch) => `${batch.task_key}:${batch.digest}`).join(`
|
|
115945
116152
|
`));
|
|
115946
|
-
const root2 =
|
|
116153
|
+
const root2 = join113(input.projectRoot, ".tmp", "context-runtime", "review", `current-${setDigest.slice("sha256:".length)}`);
|
|
115947
116154
|
await mkdir38(root2, { recursive: true });
|
|
115948
116155
|
const entries2 = [];
|
|
115949
116156
|
for (const batch of batches) {
|
|
115950
|
-
const path4 =
|
|
115951
|
-
const existing = await
|
|
116157
|
+
const path4 = join113(input.projectRoot, ".tmp", "context-runtime", "review", `${batch.task_key}-${batch.digest.slice("sha256:".length)}.md`);
|
|
116158
|
+
const existing = await readFile92(path4, "utf8").catch((error) => {
|
|
115952
116159
|
if (error.code === "ENOENT")
|
|
115953
116160
|
return;
|
|
115954
116161
|
throw error;
|
|
@@ -116001,7 +116208,7 @@ async function materializeCurrentReviewBatchSet(input) {
|
|
|
116001
116208
|
].join(`
|
|
116002
116209
|
`);
|
|
116003
116210
|
const digest7 = digestText(content3);
|
|
116004
|
-
const path3 =
|
|
116211
|
+
const path3 = join113(root2, "index.md");
|
|
116005
116212
|
await atomicWriteFile(path3, `${content3}
|
|
116006
116213
|
`);
|
|
116007
116214
|
return {
|
|
@@ -116035,11 +116242,11 @@ function shellQuote6(value) {
|
|
|
116035
116242
|
}
|
|
116036
116243
|
function receiptSetPath(receipts) {
|
|
116037
116244
|
const token = digestText(JSON.stringify(receipts)).slice("sha256:".length);
|
|
116038
|
-
return
|
|
116245
|
+
return join114(".tmp", "context-runtime", "workflow", "read-receipts", `${token}.json`);
|
|
116039
116246
|
}
|
|
116040
116247
|
async function writeReceiptContinuation(input) {
|
|
116041
116248
|
const path3 = receiptSetPath(input.receipts);
|
|
116042
|
-
const absolutePath =
|
|
116249
|
+
const absolutePath = join114(input.projectRoot, path3);
|
|
116043
116250
|
await writeJsonAtomic(absolutePath, input.receipts);
|
|
116044
116251
|
const contextCommand = input.managed ? [
|
|
116045
116252
|
"context",
|
|
@@ -116134,7 +116341,7 @@ async function materializeContextWorkflowResource(input) {
|
|
|
116134
116341
|
const resourceId = workflowResourceId(input.resourceId);
|
|
116135
116342
|
const content3 = renderContextWorkflowResource(resourceId, status);
|
|
116136
116343
|
const location = await materializeResource(await loadContextWorkflowProvider(), resourceId, {
|
|
116137
|
-
cache:
|
|
116344
|
+
cache: join114(found.projectRoot, ".tmp", "context-runtime", "workflow", "resources"),
|
|
116138
116345
|
workspace: found.projectRoot,
|
|
116139
116346
|
revision: input.revision,
|
|
116140
116347
|
input: {
|
|
@@ -116166,7 +116373,7 @@ async function materializeContextWorkflowResource(input) {
|
|
|
116166
116373
|
receipts: afterReadReceipts
|
|
116167
116374
|
});
|
|
116168
116375
|
const directResources = (status.workflow.current?.resources.required ?? []).filter((resource) => resource.read_state === "read-required" && resource.path !== undefined && resource.digest !== undefined);
|
|
116169
|
-
const afterReadCommand = directResources.length === 0 ? continuation.command : `context resource acknowledge-current --revision ${shellQuote6(input.revision)}${authorityCommandOptions(authorities, "resource")} --resource-receipts ${shellQuote6(`@${
|
|
116376
|
+
const afterReadCommand = directResources.length === 0 ? continuation.command : `context resource acknowledge-current --revision ${shellQuote6(input.revision)}${authorityCommandOptions(authorities, "resource")} --resource-receipts ${shellQuote6(`@${join114(found.projectRoot, continuation.path)}`)} --format json`;
|
|
116170
116377
|
return {
|
|
116171
116378
|
protocol: "context.workflow.resource.v1",
|
|
116172
116379
|
id: resourceId,
|
|
@@ -116227,14 +116434,14 @@ async function acknowledgeCurrentWorkflowResources(input) {
|
|
|
116227
116434
|
const reevaluated = await reevaluateProjectStatusWorkflow({
|
|
116228
116435
|
snapshot,
|
|
116229
116436
|
resourceReceipts: normalizedReceipts,
|
|
116230
|
-
resourceReceiptsReference: `@${
|
|
116437
|
+
resourceReceiptsReference: `@${join114(found.projectRoot, continuation.path)}`
|
|
116231
116438
|
});
|
|
116232
116439
|
return {
|
|
116233
116440
|
...reevaluated,
|
|
116234
116441
|
resourceAcknowledgement: {
|
|
116235
116442
|
protocol: "context.workflow.resource-receipts.v1",
|
|
116236
116443
|
acknowledged: directResources.length,
|
|
116237
|
-
receiptReference: `@${
|
|
116444
|
+
receiptReference: `@${join114(found.projectRoot, continuation.path)}`,
|
|
116238
116445
|
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."
|
|
116239
116446
|
}
|
|
116240
116447
|
};
|
|
@@ -116281,9 +116488,9 @@ init_cliFeedback();
|
|
|
116281
116488
|
init_errors3();
|
|
116282
116489
|
init_exitCode();
|
|
116283
116490
|
init_workspace();
|
|
116284
|
-
import { readFile as
|
|
116285
|
-
import { isAbsolute as isAbsolute18, join as
|
|
116286
|
-
var RECEIPT_DIRECTORY =
|
|
116491
|
+
import { readFile as readFile93 } from "node:fs/promises";
|
|
116492
|
+
import { isAbsolute as isAbsolute18, join as join115, sep as sep8, resolve as resolve36 } from "node:path";
|
|
116493
|
+
var RECEIPT_DIRECTORY = join115(".tmp", "context-runtime", "workflow", "read-receipts");
|
|
116287
116494
|
function workflowResourceReceiptCwd(value, cwd) {
|
|
116288
116495
|
if (value === undefined || !value.startsWith("@"))
|
|
116289
116496
|
return cwd;
|
|
@@ -116301,7 +116508,7 @@ async function receiptDocument(value, cwd) {
|
|
|
116301
116508
|
let source2 = value;
|
|
116302
116509
|
if (value.startsWith("@")) {
|
|
116303
116510
|
try {
|
|
116304
|
-
source2 = await
|
|
116511
|
+
source2 = await readFile93(resolve36(cwd, value.slice(1)), "utf8");
|
|
116305
116512
|
} catch (error) {
|
|
116306
116513
|
const ioCode = error !== null && typeof error === "object" && "code" in error && typeof error.code === "string" ? error.code : undefined;
|
|
116307
116514
|
throw new ContextError(ExitCode.UserError, "resource read receipt file is unavailable", {
|
|
@@ -116563,14 +116770,14 @@ function compactJsonResult(result, verbose) {
|
|
|
116563
116770
|
// src/project/runLog.ts
|
|
116564
116771
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
116565
116772
|
import { mkdir as mkdir40, writeFile as writeFile31 } from "node:fs/promises";
|
|
116566
|
-
import { dirname as dirname48, join as
|
|
116773
|
+
import { dirname as dirname48, join as join121 } from "node:path";
|
|
116567
116774
|
var createPhaseRunId = () => {
|
|
116568
116775
|
const timestamp = new Date().toISOString().replace(/[-:.TZ]/gu, "");
|
|
116569
116776
|
return `run_${timestamp}_${randomUUID6().slice(0, 8)}`;
|
|
116570
116777
|
};
|
|
116571
116778
|
async function writePhaseRunLog(input) {
|
|
116572
|
-
const relPath =
|
|
116573
|
-
const absPath =
|
|
116779
|
+
const relPath = join121(".tmp", "context-runtime", "runs", `${input.runId}.json`);
|
|
116780
|
+
const absPath = join121(input.projectRoot, relPath);
|
|
116574
116781
|
await mkdir40(dirname48(absPath), { recursive: true });
|
|
116575
116782
|
await writeFile31(absPath, `${JSON.stringify({
|
|
116576
116783
|
run_id: input.runId,
|
|
@@ -117609,7 +117816,7 @@ function createReviewCodeCodec() {
|
|
|
117609
117816
|
const identity2 = checksum(code3);
|
|
117610
117817
|
return Array.from({ length: total }, (_, i2) => `CRP1.${identity2}.${i2 + 1}.${total}.${code3.slice(i2 * 900, (i2 + 1) * 900)}`);
|
|
117611
117818
|
}
|
|
117612
|
-
function
|
|
117819
|
+
function decode3(input) {
|
|
117613
117820
|
if (input.length > 250000)
|
|
117614
117821
|
throw new Error("Review code exceeds the supported size");
|
|
117615
117822
|
const lines = input.trim().split(/\s+/);
|
|
@@ -117664,7 +117871,7 @@ function createReviewCodeCodec() {
|
|
|
117664
117871
|
throw new Error("Review contains no decisions");
|
|
117665
117872
|
return { scope: scope2, count, idsHash: unhash(ids), contentHash: unhash(content3), statuses };
|
|
117666
117873
|
}
|
|
117667
|
-
return { encode, decode:
|
|
117874
|
+
return { encode, decode: decode3 };
|
|
117668
117875
|
}
|
|
117669
117876
|
|
|
117670
117877
|
// src/project/reviewFeedbackCode.ts
|
|
@@ -117716,7 +117923,7 @@ ${repairs}` : "";
|
|
|
117716
117923
|
throw new Error("Review feedback is too large; shorten instructions or review a smaller scope");
|
|
117717
117924
|
return code3;
|
|
117718
117925
|
}
|
|
117719
|
-
function
|
|
117926
|
+
function decode3(raw) {
|
|
117720
117927
|
const code3 = raw.trim();
|
|
117721
117928
|
if (code3.length > 250000)
|
|
117722
117929
|
throw new Error("Review feedback exceeds supported size");
|
|
@@ -117749,7 +117956,7 @@ ${lines.join(`
|
|
|
117749
117956
|
throw new Error("Noncanonical review feedback encoding");
|
|
117750
117957
|
return value;
|
|
117751
117958
|
}
|
|
117752
|
-
return { encode, decode:
|
|
117959
|
+
return { encode, decode: decode3 };
|
|
117753
117960
|
}
|
|
117754
117961
|
|
|
117755
117962
|
// src/project/reviewLegacy.ts
|
|
@@ -117800,8 +118007,8 @@ async function readLegacyReviewPayload(raw, projectRoot) {
|
|
|
117800
118007
|
init_cliFeedback();
|
|
117801
118008
|
init_errors3();
|
|
117802
118009
|
init_exitCode();
|
|
117803
|
-
import { existsSync as
|
|
117804
|
-
import { readFile as
|
|
118010
|
+
import { existsSync as existsSync31 } from "node:fs";
|
|
118011
|
+
import { readFile as readFile100 } from "node:fs/promises";
|
|
117805
118012
|
import { isAbsolute as isAbsolute21, resolve as resolve38 } from "node:path";
|
|
117806
118013
|
|
|
117807
118014
|
// src/project/reviewApply.ts
|
|
@@ -117817,9 +118024,9 @@ init_reviewCandidateAuthority();
|
|
|
117817
118024
|
init_durableMultiFileTransaction();
|
|
117818
118025
|
init_durableSingleFileTransaction();
|
|
117819
118026
|
init_reviewShared();
|
|
117820
|
-
import { existsSync as
|
|
117821
|
-
import { readFile as
|
|
117822
|
-
import { join as
|
|
118027
|
+
import { existsSync as existsSync30 } from "node:fs";
|
|
118028
|
+
import { readFile as readFile98 } from "node:fs/promises";
|
|
118029
|
+
import { join as join122 } from "node:path";
|
|
117823
118030
|
function existingTimestamp(markdown) {
|
|
117824
118031
|
if (markdown === undefined)
|
|
117825
118032
|
return;
|
|
@@ -117846,7 +118053,7 @@ async function prepareApprovedPage(input) {
|
|
|
117846
118053
|
next: "Refresh the current production or article revision, then reopen Review before approval."
|
|
117847
118054
|
});
|
|
117848
118055
|
}
|
|
117849
|
-
const relPath =
|
|
118056
|
+
const relPath = join122("knowledge", input.record.path);
|
|
117850
118057
|
const existingView = findApprovedPageForArticleId(input.record.indexer_candidate.artifact_ref, input.approvedPageIndex);
|
|
117851
118058
|
const previousPath = input.record.approved_revision?.previous_path;
|
|
117852
118059
|
if (previousPath !== undefined && (!isSafeKnowledgeTargetPath(previousPath.split("/")[0], previousPath) || previousPath.includes("\\")))
|
|
@@ -117861,13 +118068,13 @@ async function prepareApprovedPage(input) {
|
|
|
117861
118068
|
next: "Resolve the approved page path migration explicitly before approving this candidate."
|
|
117862
118069
|
});
|
|
117863
118070
|
}
|
|
117864
|
-
const absPath =
|
|
117865
|
-
const existing =
|
|
118071
|
+
const absPath = join122(input.projectRoot, relPath);
|
|
118072
|
+
const existing = existsSync30(absPath) ? await readFile98(absPath, "utf8") : undefined;
|
|
117866
118073
|
let previous3;
|
|
117867
118074
|
if (previousPath !== undefined) {
|
|
117868
118075
|
if (existing !== undefined || existingView?.relPath !== `knowledge/${previousPath}`)
|
|
117869
118076
|
throw new TypeError("Page move destination or original identity changed; refresh its revision.");
|
|
117870
|
-
previous3 = { path: `knowledge/${previousPath}`, content: await
|
|
118077
|
+
previous3 = { path: `knowledge/${previousPath}`, content: await readFile98(join122(input.projectRoot, "knowledge", previousPath), "utf8") };
|
|
117871
118078
|
}
|
|
117872
118079
|
if (input.record.approved_revision !== undefined) {
|
|
117873
118080
|
const base = previous3?.content ?? existing;
|
|
@@ -117914,7 +118121,7 @@ async function prepareApprovedPage(input) {
|
|
|
117914
118121
|
}
|
|
117915
118122
|
async function readProjectFileMaybe(projectRoot, relPath) {
|
|
117916
118123
|
try {
|
|
117917
|
-
return await
|
|
118124
|
+
return await readFile98(join122(projectRoot, relPath), "utf8");
|
|
117918
118125
|
} catch (error) {
|
|
117919
118126
|
if (error !== null && typeof error === "object" && "code" in error && error.code === "ENOENT") {
|
|
117920
118127
|
return;
|
|
@@ -118135,7 +118342,7 @@ async function applyReviewDecisions(input) {
|
|
|
118135
118342
|
});
|
|
118136
118343
|
}
|
|
118137
118344
|
seenApprovedIds.set(approvedRef, row.candidate_id);
|
|
118138
|
-
const approvedPath =
|
|
118345
|
+
const approvedPath = join122("knowledge", row.path);
|
|
118139
118346
|
const previousPathCandidate = seenApprovedPaths.get(knowledgeTargetPathKey(approvedPath));
|
|
118140
118347
|
if (previousPathCandidate !== undefined) {
|
|
118141
118348
|
throw new ContextError(ExitCode.UserError, `multiple approved review decisions target the same knowledge path: ${approvedPath}`, {
|
|
@@ -118185,7 +118392,7 @@ async function applyReviewDecisions(input) {
|
|
|
118185
118392
|
for (const path3 of approvedPageIndex.byRelPath.keys()) {
|
|
118186
118393
|
if (pagesToWrite.some((page) => page.relPath === path3 || page.previous?.path === path3))
|
|
118187
118394
|
continue;
|
|
118188
|
-
const before = await
|
|
118395
|
+
const before = await readFile98(join122(input.projectRoot, path3), "utf8");
|
|
118189
118396
|
const local = path3.replace(/^knowledge\//u, "");
|
|
118190
118397
|
const after = moveKnowledgeLinkTargets2(before, local, local, moved);
|
|
118191
118398
|
navigationTargets.push(reviewFileTarget({ path: path3, baseContent: before, targetContent: after }));
|
|
@@ -118251,11 +118458,11 @@ async function applyReviewDecisions(input) {
|
|
|
118251
118458
|
init_reviewShared();
|
|
118252
118459
|
init_writeLock();
|
|
118253
118460
|
init_verifyFrontmatter();
|
|
118254
|
-
import { readFile as
|
|
118461
|
+
import { readFile as readFile99, writeFile as writeFile32 } from "node:fs/promises";
|
|
118255
118462
|
function deprecateApprovedPage(input) {
|
|
118256
118463
|
return withProjectWriteLock(input.projectRoot, "deprecate-article", async () => {
|
|
118257
118464
|
const page = await approvedPageForArticleId(input.projectRoot, input.viewRef);
|
|
118258
|
-
const original = await
|
|
118465
|
+
const original = await readFile99(page.path, "utf8");
|
|
118259
118466
|
const content3 = parseFrontmatterLoose(original).deprecated === true ? original : updateFrontmatter(original, (metadata) => ({ ...metadata, deprecated: true, timestamp: new Date().toISOString() }));
|
|
118260
118467
|
const changed = content3 !== original;
|
|
118261
118468
|
if (changed)
|
|
@@ -118276,12 +118483,12 @@ init_candidateLedger();
|
|
|
118276
118483
|
|
|
118277
118484
|
// src/project/localHtmlReport.ts
|
|
118278
118485
|
import { execFile as execFile18 } from "node:child_process";
|
|
118279
|
-
import { isAbsolute as isAbsolute20, join as
|
|
118486
|
+
import { isAbsolute as isAbsolute20, join as join123 } from "node:path";
|
|
118280
118487
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
118281
118488
|
import { promisify as promisify15 } from "node:util";
|
|
118282
118489
|
var execFileAsync4 = promisify15(execFile18);
|
|
118283
118490
|
function htmlReportReference(input) {
|
|
118284
|
-
const absolutePath = isAbsolute20(input.path) ? input.path :
|
|
118491
|
+
const absolutePath = isAbsolute20(input.path) ? input.path : join123(input.projectRoot, input.path);
|
|
118285
118492
|
return {
|
|
118286
118493
|
format: "html",
|
|
118287
118494
|
path: input.path,
|
|
@@ -118467,7 +118674,7 @@ function parseReviewPayloadText(raw) {
|
|
|
118467
118674
|
async function readReviewPayloadFile(filePath2, projectRoot) {
|
|
118468
118675
|
let raw;
|
|
118469
118676
|
try {
|
|
118470
|
-
raw = await
|
|
118677
|
+
raw = await readFile100(filePath2, "utf8");
|
|
118471
118678
|
} catch (error) {
|
|
118472
118679
|
const message = error instanceof Error ? error.message : String(error);
|
|
118473
118680
|
throw new ContextError(ExitCode.UserError, `review payload file cannot be read: ${filePath2}`, {
|
|
@@ -118726,7 +118933,7 @@ async function runReviewApproveAllCommand(input) {
|
|
|
118726
118933
|
}
|
|
118727
118934
|
});
|
|
118728
118935
|
const scope2 = scoped2.collection ?? "all";
|
|
118729
|
-
const confirmedReport = typeof confirmedScope?.report_path === "string" &&
|
|
118936
|
+
const confirmedReport = typeof confirmedScope?.report_path === "string" && existsSync31(confirmedScope.report_path) ? confirmedScope.report_path : undefined;
|
|
118730
118937
|
const shown = report?.path ?? confirmedReport;
|
|
118731
118938
|
const reportPath2 = shown ? await archiveAppliedReviewReport(projectRoot, shown, scope2) : undefined;
|
|
118732
118939
|
return { scoped: scoped2, reportPath: reportPath2, result: result2 };
|
|
@@ -119070,7 +119277,7 @@ init_cliFeedback();
|
|
|
119070
119277
|
init_errors3();
|
|
119071
119278
|
init_exitCode();
|
|
119072
119279
|
var import_yaml53 = __toESM(require_dist(), 1);
|
|
119073
|
-
import { readFile as
|
|
119280
|
+
import { readFile as readFile101 } from "node:fs/promises";
|
|
119074
119281
|
function userInputError2(message, detail = {}) {
|
|
119075
119282
|
return new ContextError(ExitCode.UserError, message, {
|
|
119076
119283
|
category: ErrorCategory.UserInputInvalid,
|
|
@@ -119139,7 +119346,7 @@ async function readPayloadTextFromStdin(stdin) {
|
|
|
119139
119346
|
}
|
|
119140
119347
|
async function readPayloadText(path3) {
|
|
119141
119348
|
if (path3 !== "-")
|
|
119142
|
-
return
|
|
119349
|
+
return readFile101(path3, "utf8");
|
|
119143
119350
|
return readPayloadTextFromStdin(process.stdin);
|
|
119144
119351
|
}
|
|
119145
119352
|
function unquotedColonText(message) {
|
|
@@ -119469,8 +119676,8 @@ init_exitCode();
|
|
|
119469
119676
|
init_maintenanceStorage();
|
|
119470
119677
|
init_productionFeedback();
|
|
119471
119678
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
119472
|
-
import { readFile as
|
|
119473
|
-
import { join as
|
|
119679
|
+
import { readFile as readFile102 } from "node:fs/promises";
|
|
119680
|
+
import { join as join124 } from "node:path";
|
|
119474
119681
|
async function beginProductionRevision(input) {
|
|
119475
119682
|
return withProductionFeedback({ operation: "revision" }, () => withProjectWriteLock(input.projectRoot, "production-revision", async () => {
|
|
119476
119683
|
await recoverDurableMultiFileTransactions(input.projectRoot);
|
|
@@ -119509,7 +119716,7 @@ async function beginProductionRevision(input) {
|
|
|
119509
119716
|
const formal = approved.byPath.get(path3);
|
|
119510
119717
|
if (!prior && !formal)
|
|
119511
119718
|
throw invalid3("Write the current task first; there is no article draft to revise yet.");
|
|
119512
|
-
const markdown = prior?.body ?? await
|
|
119719
|
+
const markdown = prior?.body ?? await readFile102(await safeProjectTarget(input.projectRoot, join124("knowledge", path3)), "utf8");
|
|
119513
119720
|
const sections = prior?.indexer_candidate.sections.map((section) => ({ id: section.section_key, references: section.references })) ?? formal?.sections;
|
|
119514
119721
|
const sources = [];
|
|
119515
119722
|
for (const source2 of owner.sources) {
|
|
@@ -119966,6 +120173,7 @@ init_workspaceChangelog();
|
|
|
119966
120173
|
init_status();
|
|
119967
120174
|
init_workflowCommandOptions();
|
|
119968
120175
|
init_workflowExecutionContext();
|
|
120176
|
+
init_sdkAlignment();
|
|
119969
120177
|
function registerVersionCommands(program2) {
|
|
119970
120178
|
const command3 = program2.command("version").description("Inspect formal changes and record a knowledge workspace SemVer and changelog");
|
|
119971
120179
|
command3.command("inspect").option("--base <ref>", "Git commit or tag to compare; defaults to the current version tag or HEAD").option("--format <format>", "json", "json").action(async (options) => {
|
|
@@ -119976,8 +120184,10 @@ function registerVersionCommands(program2) {
|
|
|
119976
120184
|
const first = status.version === "0.0.0";
|
|
119977
120185
|
const [major, minor, patch] = status.version.split(".").map(Number);
|
|
119978
120186
|
const suggested = status.reusable_version ?? (first ? "0.1.0" : `${major}.${minor}.${patch + 1}`);
|
|
120187
|
+
const sdkAlignment = await inspectSdkAlignment(root2);
|
|
119979
120188
|
process.stdout.write(JSON.stringify({
|
|
119980
120189
|
...status,
|
|
120190
|
+
...sdkAlignment ? { version_alignment: sdkAlignment } : {},
|
|
119981
120191
|
next_action: { command: "context version record --input <file> --format json" },
|
|
119982
120192
|
input_example: {
|
|
119983
120193
|
expected_digest: status.expected_digest,
|
|
@@ -120029,7 +120239,8 @@ function registerVersionCommands(program2) {
|
|
|
120029
120239
|
...execution,
|
|
120030
120240
|
...resourceReceipts === undefined ? {} : { resourceReceipts }
|
|
120031
120241
|
});
|
|
120032
|
-
|
|
120242
|
+
const sdkAlignment = await inspectSdkAlignment(root2);
|
|
120243
|
+
result = { version: recorded.version, outcome: recorded.outcome ?? "recorded", ...sdkAlignment ? { version_alignment: sdkAlignment } : {}, workflow: status.workflow };
|
|
120033
120244
|
} catch (error) {
|
|
120034
120245
|
result = { ...recorded, next_action: { command: workflowStatusCommand(execution) }, outcome: recorded.outcome ?? "recorded", next_preparation: {
|
|
120035
120246
|
message: error instanceof Error ? error.message : String(error),
|
|
@@ -120043,7 +120254,7 @@ function registerVersionCommands(program2) {
|
|
|
120043
120254
|
|
|
120044
120255
|
// src/commands/translateCommands.ts
|
|
120045
120256
|
init_workspace();
|
|
120046
|
-
import { isAbsolute as isAbsolute22, join as
|
|
120257
|
+
import { isAbsolute as isAbsolute22, join as join128 } from "node:path";
|
|
120047
120258
|
init_status();
|
|
120048
120259
|
init_workflowCommandOptions();
|
|
120049
120260
|
init_workflowExecutionContext();
|
|
@@ -120137,7 +120348,7 @@ function registerTranslateCommands(program2) {
|
|
|
120137
120348
|
readFailureNext: "Check the input path",
|
|
120138
120349
|
parseFailureNext: "Use valid YAML or JSON"
|
|
120139
120350
|
}));
|
|
120140
|
-
const saved = await submitSiteTranslation(root2, await projectPackages(root2), value, (file) => isAbsolute22(file) ? file :
|
|
120351
|
+
const saved = await submitSiteTranslation(root2, await projectPackages(root2), value, (file) => isAbsolute22(file) ? file : join128(root2, file));
|
|
120141
120352
|
write(await withWorkflow(root2, { outcome: "submitted", ...saved }));
|
|
120142
120353
|
});
|
|
120143
120354
|
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) => {
|
|
@@ -120235,7 +120446,7 @@ init_workflowRouteOutput();
|
|
|
120235
120446
|
var import_yaml57 = __toESM(require_dist(), 1);
|
|
120236
120447
|
import { Buffer as Buffer5 } from "node:buffer";
|
|
120237
120448
|
import { createHash as createHash41 } from "node:crypto";
|
|
120238
|
-
import { join as
|
|
120449
|
+
import { join as join130 } from "node:path";
|
|
120239
120450
|
var INLINE_LIMIT = 16 * 1024;
|
|
120240
120451
|
function record4(value) {
|
|
120241
120452
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
@@ -120261,8 +120472,8 @@ async function prepareActionCompletionOutput(input) {
|
|
|
120261
120472
|
if (production && Buffer5.byteLength(full) <= INLINE_LIMIT)
|
|
120262
120473
|
return input.result;
|
|
120263
120474
|
const digest8 = createHash41("sha256").update(full).digest("hex");
|
|
120264
|
-
const root2 =
|
|
120265
|
-
const resultFile =
|
|
120475
|
+
const root2 = join130(input.projectRoot, ".tmp/context-runtime/action-results");
|
|
120476
|
+
const resultFile = join130(root2, `${digest8}.json`);
|
|
120266
120477
|
await atomicWriteFile(resultFile, full);
|
|
120267
120478
|
if (production)
|
|
120268
120479
|
return {
|
|
@@ -120543,10 +120754,10 @@ function registerProjectActionCommands(program2) {
|
|
|
120543
120754
|
|
|
120544
120755
|
// src/commands/cleanClaudePluginCache.ts
|
|
120545
120756
|
init_cliFeedback();
|
|
120546
|
-
import { existsSync as
|
|
120757
|
+
import { existsSync as existsSync33 } from "node:fs";
|
|
120547
120758
|
import { readdir as readdir31, rm as rm30 } from "node:fs/promises";
|
|
120548
120759
|
import { homedir } from "node:os";
|
|
120549
|
-
import { join as
|
|
120760
|
+
import { join as join131 } from "node:path";
|
|
120550
120761
|
var ORPHAN_MARKER = ".orphaned_at";
|
|
120551
120762
|
var CLAUDE_PLUGIN_CACHE_ROOT_ENV = "C4A_CLAUDE_PLUGIN_CACHE_ROOT";
|
|
120552
120763
|
var CLAUDE_PLUGIN_CACHE_HOME_ENV = "C4A_CLAUDE_PLUGIN_CACHE_HOME";
|
|
@@ -120555,7 +120766,7 @@ async function cleanClaudePluginCache(opts = {}) {
|
|
|
120555
120766
|
const lines = [];
|
|
120556
120767
|
let removed = 0;
|
|
120557
120768
|
let scanned = 0;
|
|
120558
|
-
if (!
|
|
120769
|
+
if (!existsSync33(cacheRoot)) {
|
|
120559
120770
|
lines.push("· claude plugin cache: missing — nothing to clean");
|
|
120560
120771
|
return { lines, removed, scanned };
|
|
120561
120772
|
}
|
|
@@ -120563,20 +120774,20 @@ async function cleanClaudePluginCache(opts = {}) {
|
|
|
120563
120774
|
for (const mp of marketplaces) {
|
|
120564
120775
|
if (!mp.isDirectory())
|
|
120565
120776
|
continue;
|
|
120566
|
-
const mpDir =
|
|
120777
|
+
const mpDir = join131(cacheRoot, mp.name);
|
|
120567
120778
|
const plugins = await readdir31(mpDir, { withFileTypes: true });
|
|
120568
120779
|
for (const pl of plugins) {
|
|
120569
120780
|
if (!pl.isDirectory())
|
|
120570
120781
|
continue;
|
|
120571
|
-
const plDir =
|
|
120782
|
+
const plDir = join131(mpDir, pl.name);
|
|
120572
120783
|
const versions = await readdir31(plDir, { withFileTypes: true });
|
|
120573
120784
|
for (const ver of versions) {
|
|
120574
120785
|
if (!ver.isDirectory())
|
|
120575
120786
|
continue;
|
|
120576
120787
|
scanned += 1;
|
|
120577
|
-
const verDir =
|
|
120578
|
-
const markerPath =
|
|
120579
|
-
if (!
|
|
120788
|
+
const verDir = join131(plDir, ver.name);
|
|
120789
|
+
const markerPath = join131(verDir, ORPHAN_MARKER);
|
|
120790
|
+
if (!existsSync33(markerPath))
|
|
120580
120791
|
continue;
|
|
120581
120792
|
const label2 = `${mp.name}/${pl.name}/${ver.name}`;
|
|
120582
120793
|
if (opts.dryRun) {
|
|
@@ -120607,7 +120818,7 @@ function resolveClaudePluginCacheRoot(opts) {
|
|
|
120607
120818
|
if (explicitRoot)
|
|
120608
120819
|
return explicitRoot;
|
|
120609
120820
|
const home = opts.home ?? process.env[CLAUDE_PLUGIN_CACHE_HOME_ENV] ?? homedir();
|
|
120610
|
-
return
|
|
120821
|
+
return join131(home, ".claude", "plugins", "cache");
|
|
120611
120822
|
}
|
|
120612
120823
|
async function isEmptyDir(dir) {
|
|
120613
120824
|
try {
|
|
@@ -120643,7 +120854,7 @@ init_statusCommand();
|
|
|
120643
120854
|
// src/project/sourceCommands.ts
|
|
120644
120855
|
init_repoContentLinks();
|
|
120645
120856
|
init_src2();
|
|
120646
|
-
import { readFile as
|
|
120857
|
+
import { readFile as readFile117 } from "node:fs/promises";
|
|
120647
120858
|
import { isAbsolute as isAbsolute26, resolve as resolve49 } from "node:path";
|
|
120648
120859
|
init_cliFeedback();
|
|
120649
120860
|
init_errors3();
|
|
@@ -120660,7 +120871,7 @@ init_repoSources();
|
|
|
120660
120871
|
init_repoSourceRegistry();
|
|
120661
120872
|
init_writeLock();
|
|
120662
120873
|
import { execFile as execFile19 } from "node:child_process";
|
|
120663
|
-
import { existsSync as
|
|
120874
|
+
import { existsSync as existsSync34 } from "node:fs";
|
|
120664
120875
|
import { lstat as lstat19, mkdir as mkdir42, readlink as readlink3, realpath as realpath16, rm as rm31, symlink as symlink5 } from "node:fs/promises";
|
|
120665
120876
|
import { basename as basename12, dirname as dirname51, isAbsolute as isAbsolute23, relative as relative34, resolve as resolve43 } from "node:path";
|
|
120666
120877
|
import { promisify as promisify16 } from "node:util";
|
|
@@ -120817,7 +121028,7 @@ async function git4(cwd, args) {
|
|
|
120817
121028
|
}
|
|
120818
121029
|
async function resolveGitRoot2(path3) {
|
|
120819
121030
|
const root2 = await git4(path3, ["rev-parse", "--show-toplevel"]);
|
|
120820
|
-
if (root2.length === 0 || !
|
|
121031
|
+
if (root2.length === 0 || !existsSync34(root2)) {
|
|
120821
121032
|
throw userInputError3(`local repository path is not a Git checkout: ${path3}`, { path: path3 });
|
|
120822
121033
|
}
|
|
120823
121034
|
return realpath16(root2);
|
|
@@ -120842,7 +121053,7 @@ async function verifyCheckout(input) {
|
|
|
120842
121053
|
}
|
|
120843
121054
|
async function cloneCheckout(input) {
|
|
120844
121055
|
const target = resolve43(input.projectRoot, input.target ?? `.tmp/repo/${repositorySlug(input.remote)}-${input.ref.slice(0, 12)}`);
|
|
120845
|
-
if (
|
|
121056
|
+
if (existsSync34(target)) {
|
|
120846
121057
|
throw userInputError3(`clone target already exists: ${target}`, {
|
|
120847
121058
|
target,
|
|
120848
121059
|
next: `Use local mode with path ${JSON.stringify(target)} after inspecting the existing checkout.`
|
|
@@ -121010,17 +121221,17 @@ async function restoreRepositorySources(input) {
|
|
|
121010
121221
|
// src/project/sourceDocumentStatus.ts
|
|
121011
121222
|
init_src2();
|
|
121012
121223
|
init_documentCapture();
|
|
121013
|
-
import { existsSync as
|
|
121014
|
-
import { readFile as
|
|
121015
|
-
import { join as
|
|
121224
|
+
import { existsSync as existsSync35 } from "node:fs";
|
|
121225
|
+
import { readFile as readFile107 } from "node:fs/promises";
|
|
121226
|
+
import { join as join133 } from "node:path";
|
|
121016
121227
|
|
|
121017
121228
|
// src/project/sourceCommandViews.ts
|
|
121018
121229
|
init_fileSourceOrigins();
|
|
121019
121230
|
init_documentSiteDetection();
|
|
121020
121231
|
init_workspace();
|
|
121021
121232
|
init_documentBatchManifest();
|
|
121022
|
-
import { readFile as
|
|
121023
|
-
import { join as
|
|
121233
|
+
import { readFile as readFile106 } from "node:fs/promises";
|
|
121234
|
+
import { join as join132 } from "node:path";
|
|
121024
121235
|
function repoSourceAgentView(source2) {
|
|
121025
121236
|
return {
|
|
121026
121237
|
id: source2.id ?? source2.name,
|
|
@@ -121085,7 +121296,7 @@ async function fileSourceAgentViewWithNextAction(input) {
|
|
|
121085
121296
|
};
|
|
121086
121297
|
}
|
|
121087
121298
|
function documentSourceManifestPath(source2) {
|
|
121088
|
-
return source2.snapshot?.manifest ??
|
|
121299
|
+
return source2.snapshot?.manifest ?? join132(source2.materializedAt, "manifest.json");
|
|
121089
121300
|
}
|
|
121090
121301
|
async function fileSourceDocumentSiteHint(input) {
|
|
121091
121302
|
const detection = await detectDocumentSiteFiles({
|
|
@@ -121095,7 +121306,7 @@ async function fileSourceDocumentSiteHint(input) {
|
|
|
121095
121306
|
let snapshotConfigured = false;
|
|
121096
121307
|
const manifest = documentSourceManifestPath(input.source);
|
|
121097
121308
|
try {
|
|
121098
|
-
const parsed = parseDocumentSnapshotForSource(JSON.parse(await
|
|
121309
|
+
const parsed = parseDocumentSnapshotForSource(JSON.parse(await readFile106(join132(input.projectRoot, manifest), "utf8")), input.source.name);
|
|
121099
121310
|
snapshotConfigured = manifestUsesMdxJsonDocs(parsed);
|
|
121100
121311
|
} catch {
|
|
121101
121312
|
snapshotConfigured = false;
|
|
@@ -121128,12 +121339,12 @@ async function larkSourceAgentViewWithNextAction(input) {
|
|
|
121128
121339
|
init_documentBatchManifest();
|
|
121129
121340
|
init_documentSnapshotFidelity();
|
|
121130
121341
|
function documentSourceManifestPath2(source2) {
|
|
121131
|
-
return source2.snapshot?.manifest ??
|
|
121342
|
+
return source2.snapshot?.manifest ?? join133(source2.materializedAt, "manifest.json");
|
|
121132
121343
|
}
|
|
121133
121344
|
async function documentSnapshotState(input) {
|
|
121134
121345
|
const manifest = documentSourceManifestPath2(input.source);
|
|
121135
|
-
const manifestPath =
|
|
121136
|
-
if (!
|
|
121346
|
+
const manifestPath = join133(input.projectRoot, manifest);
|
|
121347
|
+
if (!existsSync35(manifestPath)) {
|
|
121137
121348
|
return {
|
|
121138
121349
|
snapshotReady: false,
|
|
121139
121350
|
state: "needs-capture",
|
|
@@ -121143,7 +121354,7 @@ async function documentSnapshotState(input) {
|
|
|
121143
121354
|
};
|
|
121144
121355
|
}
|
|
121145
121356
|
try {
|
|
121146
|
-
const parsed = findDocumentSnapshotForSource(JSON.parse(await
|
|
121357
|
+
const parsed = findDocumentSnapshotForSource(JSON.parse(await readFile107(manifestPath, "utf8")), input.source.name);
|
|
121147
121358
|
if (parsed === null) {
|
|
121148
121359
|
return {
|
|
121149
121360
|
snapshotReady: false,
|
|
@@ -121211,7 +121422,7 @@ async function documentSnapshotState(input) {
|
|
|
121211
121422
|
const missing2 = [
|
|
121212
121423
|
...parsed.files.map((file) => file.path),
|
|
121213
121424
|
...(parsed.assets ?? []).filter((asset) => asset.content_hash !== undefined).map((asset) => asset.path)
|
|
121214
|
-
].find((path3) => !
|
|
121425
|
+
].find((path3) => !existsSync35(join133(input.projectRoot, input.source.materializedAt, path3)));
|
|
121215
121426
|
if (missing2 !== undefined) {
|
|
121216
121427
|
return {
|
|
121217
121428
|
snapshotReady: false,
|
|
@@ -121312,8 +121523,8 @@ init_errors3();
|
|
|
121312
121523
|
init_exitCode();
|
|
121313
121524
|
var import_yaml59 = __toESM(require_dist(), 1);
|
|
121314
121525
|
import { createHash as createHash42 } from "node:crypto";
|
|
121315
|
-
import { readFile as
|
|
121316
|
-
import { basename as basename13, extname as extname15, isAbsolute as isAbsolute24, join as
|
|
121526
|
+
import { readFile as readFile108, realpath as realpath17 } from "node:fs/promises";
|
|
121527
|
+
import { basename as basename13, extname as extname15, isAbsolute as isAbsolute24, join as join134, relative as relative35, resolve as resolve44 } from "node:path";
|
|
121317
121528
|
init_writeLock();
|
|
121318
121529
|
var SOURCE_NAME_PATTERN3 = /^[a-z0-9][a-z0-9._-]*$/u;
|
|
121319
121530
|
function isDateSourceNamespace(value) {
|
|
@@ -121409,7 +121620,7 @@ function assertSafeFileInclude(value) {
|
|
|
121409
121620
|
}
|
|
121410
121621
|
async function readRegistryDocument(projectRoot2, registryPath2) {
|
|
121411
121622
|
try {
|
|
121412
|
-
const content3 = await
|
|
121623
|
+
const content3 = await readFile108(join134(projectRoot2, registryPath2), "utf8");
|
|
121413
121624
|
return content3.trim().length === 0 ? { sources: [] } : import_yaml59.default.parse(content3);
|
|
121414
121625
|
} catch (error) {
|
|
121415
121626
|
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
@@ -121499,10 +121710,10 @@ function flatRawSource(sources, name3) {
|
|
|
121499
121710
|
}
|
|
121500
121711
|
async function ensureOriginInstallRootIgnored(projectRoot2, kind) {
|
|
121501
121712
|
const line = `${fileSourceOriginInstallRoot(kind)}/`;
|
|
121502
|
-
const path3 =
|
|
121713
|
+
const path3 = join134(projectRoot2, ".gitignore");
|
|
121503
121714
|
let current3 = "";
|
|
121504
121715
|
try {
|
|
121505
|
-
current3 = await
|
|
121716
|
+
current3 = await readFile108(path3, "utf8");
|
|
121506
121717
|
} catch {
|
|
121507
121718
|
current3 = "";
|
|
121508
121719
|
}
|
|
@@ -121600,7 +121811,7 @@ async function addFileSourceUnlocked(input) {
|
|
|
121600
121811
|
sourceName: input.name
|
|
121601
121812
|
});
|
|
121602
121813
|
}
|
|
121603
|
-
await atomicWriteFile(
|
|
121814
|
+
await atomicWriteFile(join134(input.projectRoot, DEFAULT_FILE_SOURCES_REGISTRY_PATH), import_yaml59.default.stringify({ sources: nextSources }));
|
|
121604
121815
|
const gitignoreUpdated = origin !== undefined && await ensureOriginInstallRootIgnored(input.projectRoot, origin.kind);
|
|
121605
121816
|
const updated = await loadSourcesRegistry({ rootDir: input.projectRoot });
|
|
121606
121817
|
const entry = updated.files.find((source2) => source2.name === input.name || source2.id === input.name);
|
|
@@ -121661,7 +121872,7 @@ async function addLarkSourceUnlocked(input) {
|
|
|
121661
121872
|
const record6 = entry2;
|
|
121662
121873
|
return record6.name !== input.name && record6.id !== input.name;
|
|
121663
121874
|
}), nextEntry];
|
|
121664
|
-
await atomicWriteFile(
|
|
121875
|
+
await atomicWriteFile(join134(input.projectRoot, DEFAULT_LARK_SOURCES_REGISTRY_PATH), import_yaml59.default.stringify({ sources: nextSources }));
|
|
121665
121876
|
const updated = await loadSourcesRegistry({ rootDir: input.projectRoot });
|
|
121666
121877
|
const entry = updated.larks.find((source2) => source2.name === input.name || source2.id === input.name);
|
|
121667
121878
|
if (entry === undefined) {
|
|
@@ -121693,18 +121904,18 @@ init_cliFeedback();
|
|
|
121693
121904
|
init_errors3();
|
|
121694
121905
|
init_exitCode();
|
|
121695
121906
|
var import_yaml60 = __toESM(require_dist(), 1);
|
|
121696
|
-
import { readFile as
|
|
121697
|
-
import { join as
|
|
121907
|
+
import { readFile as readFile109 } from "node:fs/promises";
|
|
121908
|
+
import { join as join135 } from "node:path";
|
|
121698
121909
|
import { isDeepStrictEqual as isDeepStrictEqual3 } from "node:util";
|
|
121699
121910
|
function identityKeys(entry) {
|
|
121700
121911
|
return new Set([entry.name, entry.id]);
|
|
121701
121912
|
}
|
|
121702
121913
|
async function createLarkBatchRegistration(projectRoot2, namespace) {
|
|
121703
121914
|
const registry2 = await loadSourcesRegistry({ rootDir: projectRoot2 });
|
|
121704
|
-
const registryPath2 =
|
|
121915
|
+
const registryPath2 = join135(projectRoot2, DEFAULT_LARK_SOURCES_REGISTRY_PATH);
|
|
121705
121916
|
let committedSources;
|
|
121706
121917
|
try {
|
|
121707
|
-
const text12 = await
|
|
121918
|
+
const text12 = await readFile109(registryPath2, "utf8");
|
|
121708
121919
|
committedSources = text12.trim().length === 0 ? [] : import_yaml60.default.parse(text12).sources ?? [];
|
|
121709
121920
|
} catch (error) {
|
|
121710
121921
|
if (!(error instanceof Error && ("code" in error) && error.code === "ENOENT"))
|
|
@@ -121822,8 +122033,8 @@ init_cliFeedback();
|
|
|
121822
122033
|
init_errors3();
|
|
121823
122034
|
init_exitCode();
|
|
121824
122035
|
import { createHash as createHash43 } from "node:crypto";
|
|
121825
|
-
import { lstat as lstat20, readFile as
|
|
121826
|
-
import { join as
|
|
122036
|
+
import { lstat as lstat20, readFile as readFile110 } from "node:fs/promises";
|
|
122037
|
+
import { join as join136, resolve as resolve45 } from "node:path";
|
|
121827
122038
|
var INPUT_SCHEMA = "context.source-batch.input.v1";
|
|
121828
122039
|
var STATE_SCHEMA = "context.source-batch.state.v1";
|
|
121829
122040
|
var RUNTIME_PARTS = [".tmp", "context-runtime", "source-batches"];
|
|
@@ -121874,14 +122085,14 @@ function paths(projectRoot2, jobId) {
|
|
|
121874
122085
|
throw journalError("source-batch-id-invalid", "Source batch checkpoint ID must contain exactly 32 lowercase hexadecimal characters.");
|
|
121875
122086
|
}
|
|
121876
122087
|
const directory = resolve45(projectRoot2, ...RUNTIME_PARTS, jobId);
|
|
121877
|
-
return { inputPath:
|
|
122088
|
+
return { inputPath: join136(directory, "input.json"), statePath: join136(directory, "state.json") };
|
|
121878
122089
|
}
|
|
121879
122090
|
async function assertJournalPath(projectRoot2, jobId, filename) {
|
|
121880
122091
|
paths(projectRoot2, jobId);
|
|
121881
122092
|
let current3 = resolve45(projectRoot2);
|
|
121882
122093
|
const parts = [...RUNTIME_PARTS, jobId, filename];
|
|
121883
122094
|
for (const [index3, part] of parts.entries()) {
|
|
121884
|
-
current3 =
|
|
122095
|
+
current3 = join136(current3, part);
|
|
121885
122096
|
let stat11;
|
|
121886
122097
|
try {
|
|
121887
122098
|
stat11 = await lstat20(current3);
|
|
@@ -121912,7 +122123,7 @@ async function loadSourceBatchJournal(input) {
|
|
|
121912
122123
|
const { inputPath } = paths(input.projectRoot, input.jobId);
|
|
121913
122124
|
try {
|
|
121914
122125
|
await assertJournalPath(input.projectRoot, input.jobId, "input.json");
|
|
121915
|
-
const stored = JSON.parse(await
|
|
122126
|
+
const stored = JSON.parse(await readFile110(inputPath, "utf8"));
|
|
121916
122127
|
if (stored === null || typeof stored !== "object" || Array.isArray(stored)) {
|
|
121917
122128
|
throw journalError("source-batch-input-invalid", "Source batch checkpoint input must be an object.");
|
|
121918
122129
|
}
|
|
@@ -122015,7 +122226,7 @@ async function readSourceBatchJournalStatus(input) {
|
|
|
122015
122226
|
let warning;
|
|
122016
122227
|
try {
|
|
122017
122228
|
await assertJournalPath(journal.projectRoot, journal.jobId, "state.json");
|
|
122018
|
-
const parsed = JSON.parse(await
|
|
122229
|
+
const parsed = JSON.parse(await readFile110(journal.statePath, "utf8"));
|
|
122019
122230
|
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))) {
|
|
122020
122231
|
throw journalError("source-batch-state-invalid", "Source batch checkpoint progress is invalid.");
|
|
122021
122232
|
}
|
|
@@ -122613,13 +122824,13 @@ init_exitCode();
|
|
|
122613
122824
|
|
|
122614
122825
|
// src/project/wikiDiscovery.ts
|
|
122615
122826
|
import { mkdir as mkdir44 } from "node:fs/promises";
|
|
122616
|
-
import { join as
|
|
122827
|
+
import { join as join138, relative as relative37 } from "node:path";
|
|
122617
122828
|
|
|
122618
122829
|
// src/project/wikiDiscoveryStore.ts
|
|
122619
122830
|
init_atomicWrite();
|
|
122620
122831
|
import { createHash as createHash44, randomUUID as randomUUID9 } from "node:crypto";
|
|
122621
|
-
import { link as link2, lstat as lstat21, mkdir as mkdir43, readFile as
|
|
122622
|
-
import { join as
|
|
122832
|
+
import { link as link2, lstat as lstat21, mkdir as mkdir43, readFile as readFile111, readdir as readdir32, rm as rm32, writeFile as writeFile33 } from "node:fs/promises";
|
|
122833
|
+
import { join as join137, relative as relative36, resolve as resolve46, sep as sep11 } from "node:path";
|
|
122623
122834
|
function wikiDiscoveryDigest(value) {
|
|
122624
122835
|
return createHash44("sha256").update(value).digest("hex");
|
|
122625
122836
|
}
|
|
@@ -122633,7 +122844,7 @@ async function assertWikiDiscoveryPath(root2, path3) {
|
|
|
122633
122844
|
throw new WikiDiscoveryError("unsafe-checkpoint-path", false, "Discovery checkpoint must stay inside its workspace");
|
|
122634
122845
|
let current3 = base;
|
|
122635
122846
|
for (const part of parts) {
|
|
122636
|
-
current3 =
|
|
122847
|
+
current3 = join137(current3, part);
|
|
122637
122848
|
try {
|
|
122638
122849
|
if ((await lstat21(current3)).isSymbolicLink()) {
|
|
122639
122850
|
throw new WikiDiscoveryError("unsafe-checkpoint-path", false, "Discovery checkpoint paths must not contain symbolic links");
|
|
@@ -122649,7 +122860,7 @@ async function readWikiDiscoveryJson(path3) {
|
|
|
122649
122860
|
try {
|
|
122650
122861
|
if ((await lstat21(path3)).isSymbolicLink())
|
|
122651
122862
|
throw new WikiDiscoveryError("unsafe-checkpoint-path", false, "Discovery checkpoint must not be a symbolic link");
|
|
122652
|
-
return JSON.parse(await
|
|
122863
|
+
return JSON.parse(await readFile111(path3, "utf8"));
|
|
122653
122864
|
} catch (error) {
|
|
122654
122865
|
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT")
|
|
122655
122866
|
return;
|
|
@@ -122662,12 +122873,12 @@ async function saveWikiDiscoveryJson(path3, value) {
|
|
|
122662
122873
|
}
|
|
122663
122874
|
async function loadWikiDiscoveryReceipts(directory) {
|
|
122664
122875
|
const result = new Map;
|
|
122665
|
-
await assertWikiDiscoveryPath(directory,
|
|
122666
|
-
await mkdir43(
|
|
122667
|
-
for (const file of await readdir32(
|
|
122876
|
+
await assertWikiDiscoveryPath(directory, join137(directory, "pages"));
|
|
122877
|
+
await mkdir43(join137(directory, "pages"), { recursive: true });
|
|
122878
|
+
for (const file of await readdir32(join137(directory, "pages"))) {
|
|
122668
122879
|
if (!/^[a-f0-9]{64}\.json$/u.test(file))
|
|
122669
122880
|
continue;
|
|
122670
|
-
const value = await readWikiDiscoveryJson(
|
|
122881
|
+
const value = await readWikiDiscoveryJson(join137(directory, "pages", file));
|
|
122671
122882
|
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) {
|
|
122672
122883
|
throw new WikiDiscoveryError("checkpoint-invalid", false, "Discovery page checkpoint is invalid; preserve it for inspection");
|
|
122673
122884
|
}
|
|
@@ -122686,14 +122897,14 @@ function ownerRunning(pid) {
|
|
|
122686
122897
|
}
|
|
122687
122898
|
}
|
|
122688
122899
|
async function acquireWikiDiscoveryLease(directory) {
|
|
122689
|
-
const leases =
|
|
122900
|
+
const leases = join137(directory, "leases");
|
|
122690
122901
|
await assertWikiDiscoveryPath(directory, leases);
|
|
122691
122902
|
await mkdir43(leases, { recursive: true });
|
|
122692
122903
|
for (let attempt = 0;attempt < 8; attempt++) {
|
|
122693
122904
|
const files = (await readdir32(leases)).filter((file) => /^\d{12}\.json$/u.test(file)).sort();
|
|
122694
122905
|
const latest = files.at(-1);
|
|
122695
122906
|
if (latest) {
|
|
122696
|
-
const current3 = await readWikiDiscoveryJson(
|
|
122907
|
+
const current3 = await readWikiDiscoveryJson(join137(leases, latest));
|
|
122697
122908
|
if (!current3 || !Number.isSafeInteger(current3.pid) || current3.pid <= 0 || typeof current3.token !== "string" || typeof current3.released !== "boolean") {
|
|
122698
122909
|
throw new WikiDiscoveryError("checkpoint-invalid", false, "Discovery lease is invalid; preserve it for inspection");
|
|
122699
122910
|
}
|
|
@@ -122702,9 +122913,9 @@ async function acquireWikiDiscoveryLease(directory) {
|
|
|
122702
122913
|
}
|
|
122703
122914
|
}
|
|
122704
122915
|
const sequence = latest ? Number(latest.slice(0, 12)) + 1 : 1;
|
|
122705
|
-
const path3 =
|
|
122916
|
+
const path3 = join137(leases, `${String(sequence).padStart(12, "0")}.json`);
|
|
122706
122917
|
const owner = { pid: process.pid, token: randomUUID9(), released: false };
|
|
122707
|
-
const temporary =
|
|
122918
|
+
const temporary = join137(leases, `.lease-${owner.token}`);
|
|
122708
122919
|
await writeFile33(temporary, JSON.stringify(owner), { flag: "wx", mode: 384 });
|
|
122709
122920
|
try {
|
|
122710
122921
|
await link2(temporary, path3);
|
|
@@ -122829,7 +123040,7 @@ async function discoverLarkWiki(input) {
|
|
|
122829
123040
|
throw new WikiDiscoveryError("invalid-concurrency", false, "Wiki concurrency must be an integer from 1 to 4");
|
|
122830
123041
|
}
|
|
122831
123042
|
const jobId = wikiDiscoveryDigest(url);
|
|
122832
|
-
const directory =
|
|
123043
|
+
const directory = join138(input.projectRoot, ".tmp", "context-runtime", "wiki-discovery", jobId);
|
|
122833
123044
|
await assertWikiDiscoveryPath(input.projectRoot, directory);
|
|
122834
123045
|
await mkdir44(directory, { recursive: true });
|
|
122835
123046
|
const release = await acquireWikiDiscoveryLease(directory);
|
|
@@ -122841,7 +123052,7 @@ async function discoverLarkWiki(input) {
|
|
|
122841
123052
|
}
|
|
122842
123053
|
async function runDiscovery(input, job) {
|
|
122843
123054
|
const { directory, url, identity: identity2 } = job;
|
|
122844
|
-
const metadataPath =
|
|
123055
|
+
const metadataPath = join138(directory, "job.json");
|
|
122845
123056
|
let metadata = await readWikiDiscoveryJson(metadataPath);
|
|
122846
123057
|
if (metadata && (metadata.protocol !== "context.wiki-discovery.v1" || metadata.url !== url || metadata.identity !== identity2)) {
|
|
122847
123058
|
throw new WikiDiscoveryError("job-identity-mismatch", false, "Resume must preserve the discovery's original URL and identity");
|
|
@@ -122890,7 +123101,7 @@ async function runDiscovery(input, job) {
|
|
|
122890
123101
|
}
|
|
122891
123102
|
const key = wikiDiscoveryPageKey(cursor);
|
|
122892
123103
|
try {
|
|
122893
|
-
await saveWikiDiscoveryJson(
|
|
123104
|
+
await saveWikiDiscoveryJson(join138(directory, "pages", `${key}.json`), receipt2);
|
|
122894
123105
|
receipts.set(key, receipt2);
|
|
122895
123106
|
} catch {
|
|
122896
123107
|
checkpointError = "A discovery page could not be checkpointed; saved pages remain reusable and unsaved pages must be requested again";
|
|
@@ -122908,7 +123119,7 @@ async function finishDiscovery(input, state) {
|
|
|
122908
123119
|
const { directory, url, identity: identity2, jobId, metadata, view } = state;
|
|
122909
123120
|
let checkpointError = state.checkpointError;
|
|
122910
123121
|
let status = input.signal?.aborted ? "paused" : checkpointError || view.pending.length || view.failed.length || !metadata.root ? "partial" : "completed";
|
|
122911
|
-
const manifestPath =
|
|
123122
|
+
const manifestPath = join138(directory, "manifest.json");
|
|
122912
123123
|
try {
|
|
122913
123124
|
await saveWikiDiscoveryJson(manifestPath, {
|
|
122914
123125
|
protocol: "context.wiki-discovery.manifest.v1",
|
|
@@ -123086,10 +123297,10 @@ init_documentBatchManifest();
|
|
|
123086
123297
|
init_workspace();
|
|
123087
123298
|
init_writeLock();
|
|
123088
123299
|
var import_yaml63 = __toESM(require_dist(), 1);
|
|
123089
|
-
import { existsSync as
|
|
123300
|
+
import { existsSync as existsSync36 } from "node:fs";
|
|
123090
123301
|
import { createHash as createHash45 } from "node:crypto";
|
|
123091
|
-
import { readFile as
|
|
123092
|
-
import { isAbsolute as isAbsolute25, join as
|
|
123302
|
+
import { readFile as readFile112, readdir as readdir33, rm as rm33 } from "node:fs/promises";
|
|
123303
|
+
import { isAbsolute as isAbsolute25, join as join139, relative as relative38, resolve as resolve47, sep as sep12 } from "node:path";
|
|
123093
123304
|
function sourceIdentity(source2) {
|
|
123094
123305
|
if (source2.kind === "source.collection")
|
|
123095
123306
|
return;
|
|
@@ -123121,10 +123332,10 @@ function collectStrings(value, output) {
|
|
|
123121
123332
|
}
|
|
123122
123333
|
}
|
|
123123
123334
|
async function yamlReferences(input) {
|
|
123124
|
-
const absolutePath =
|
|
123125
|
-
if (!
|
|
123335
|
+
const absolutePath = join139(input.projectRoot, input.path);
|
|
123336
|
+
if (!existsSync36(absolutePath))
|
|
123126
123337
|
return false;
|
|
123127
|
-
const parsed = import_yaml63.default.parse(await
|
|
123338
|
+
const parsed = import_yaml63.default.parse(await readFile112(absolutePath, "utf8"));
|
|
123128
123339
|
const strings = [];
|
|
123129
123340
|
collectStrings(parsed, strings);
|
|
123130
123341
|
return strings.some((value) => stringReferencesSource(value, input.source));
|
|
@@ -123270,8 +123481,8 @@ async function registryRemovalWrite(projectRoot2, source2) {
|
|
|
123270
123481
|
const path3 = registryPath2(source2.type);
|
|
123271
123482
|
if (path3 === null)
|
|
123272
123483
|
return;
|
|
123273
|
-
const absolutePath =
|
|
123274
|
-
const document4 =
|
|
123484
|
+
const absolutePath = join139(projectRoot2, path3);
|
|
123485
|
+
const document4 = existsSync36(absolutePath) ? import_yaml63.default.parse(await readFile112(absolutePath, "utf8")) : { sources: [] };
|
|
123275
123486
|
return {
|
|
123276
123487
|
path: absolutePath,
|
|
123277
123488
|
bytes: import_yaml63.default.stringify(removeDocumentEntry(document4, source2))
|
|
@@ -123289,7 +123500,7 @@ function safeManagedMaterializedPath(projectRoot2, source2) {
|
|
|
123289
123500
|
return absolute;
|
|
123290
123501
|
}
|
|
123291
123502
|
function safeManagedManifestPath(projectRoot2, source2) {
|
|
123292
|
-
const manifest = source2.manifest ??
|
|
123503
|
+
const manifest = source2.manifest ?? join139(source2.materializedAt, "manifest.json");
|
|
123293
123504
|
if (isAbsolute25(manifest))
|
|
123294
123505
|
throw unsafeOwnership(source2, manifest);
|
|
123295
123506
|
const absolute = resolve47(projectRoot2, manifest);
|
|
@@ -123404,7 +123615,7 @@ async function createRemovalPlan(projectRoot2, selector) {
|
|
|
123404
123615
|
}
|
|
123405
123616
|
} else {
|
|
123406
123617
|
const materializedPath = safeManagedMaterializedPath(projectRoot2, source2);
|
|
123407
|
-
if (materializedPath !== undefined && sharedMaterializedBy.length === 0 &&
|
|
123618
|
+
if (materializedPath !== undefined && sharedMaterializedBy.length === 0 && existsSync36(materializedPath)) {
|
|
123408
123619
|
absoluteRemovals.push(materializedPath);
|
|
123409
123620
|
cleanup = {
|
|
123410
123621
|
mode: "exclusive-materialization",
|
|
@@ -123418,7 +123629,7 @@ async function createRemovalPlan(projectRoot2, selector) {
|
|
|
123418
123629
|
source: source2,
|
|
123419
123630
|
registry: registryPath2(source2.type),
|
|
123420
123631
|
registryBytes: registryWrite?.bytes ?? null,
|
|
123421
|
-
managedBytes: source2.type === "note" || source2.type === "sessions" ? await
|
|
123632
|
+
managedBytes: source2.type === "note" || source2.type === "sessions" ? await readFile112(absoluteRemovals[0], "utf8") : null,
|
|
123422
123633
|
references,
|
|
123423
123634
|
cleanup,
|
|
123424
123635
|
manifestBytes: manifestWrite?.bytes ?? null
|
|
@@ -123451,10 +123662,10 @@ function publicRemovalResult(plan, action) {
|
|
|
123451
123662
|
};
|
|
123452
123663
|
}
|
|
123453
123664
|
async function pruneExtractRuntime(projectRoot2, source2) {
|
|
123454
|
-
const fingerprintPath =
|
|
123665
|
+
const fingerprintPath = join139(projectRoot2, ".tmp/context-runtime/extract/source-fingerprints.json");
|
|
123455
123666
|
const removedPhaseIds = new Set;
|
|
123456
|
-
if (
|
|
123457
|
-
const parsed = JSON.parse(await
|
|
123667
|
+
if (existsSync36(fingerprintPath)) {
|
|
123668
|
+
const parsed = JSON.parse(await readFile112(fingerprintPath, "utf8"));
|
|
123458
123669
|
const phases = parsed.phases ?? {};
|
|
123459
123670
|
const next2 = Object.fromEntries(Object.entries(phases).filter(([phaseId, raw]) => {
|
|
123460
123671
|
if (raw === null || typeof raw !== "object" || Array.isArray(raw))
|
|
@@ -123468,27 +123679,27 @@ async function pruneExtractRuntime(projectRoot2, source2) {
|
|
|
123468
123679
|
await atomicWriteFile(fingerprintPath, `${JSON.stringify({ ...parsed, phases: next2 }, null, 2)}
|
|
123469
123680
|
`);
|
|
123470
123681
|
}
|
|
123471
|
-
const phaseOwnershipPath =
|
|
123472
|
-
if (
|
|
123473
|
-
const parsed = JSON.parse(await
|
|
123682
|
+
const phaseOwnershipPath = join139(projectRoot2, ".tmp/context-runtime/extract/custom-phase-candidates.json");
|
|
123683
|
+
if (existsSync36(phaseOwnershipPath) && removedPhaseIds.size > 0) {
|
|
123684
|
+
const parsed = JSON.parse(await readFile112(phaseOwnershipPath, "utf8"));
|
|
123474
123685
|
const phases = Object.fromEntries(Object.entries(parsed.phases ?? {}).filter(([phaseId]) => !removedPhaseIds.has(phaseId)));
|
|
123475
123686
|
await atomicWriteFile(phaseOwnershipPath, `${JSON.stringify({ ...parsed, phases }, null, 2)}
|
|
123476
123687
|
`);
|
|
123477
123688
|
}
|
|
123478
|
-
const symbolPath =
|
|
123479
|
-
if (
|
|
123480
|
-
const parsed = JSON.parse(await
|
|
123689
|
+
const symbolPath = join139(projectRoot2, ".tmp/context-runtime/extract/source-symbols.json");
|
|
123690
|
+
if (existsSync36(symbolPath)) {
|
|
123691
|
+
const parsed = JSON.parse(await readFile112(symbolPath, "utf8"));
|
|
123481
123692
|
const symbols = Array.isArray(parsed.symbols) ? parsed.symbols.filter((entry) => entry === null || typeof entry !== "object" || Array.isArray(entry) || entry.source !== source2.name) : [];
|
|
123482
123693
|
const phaseFingerprints = Object.fromEntries(Object.entries(parsed.phaseFingerprints ?? {}).filter(([phaseId]) => !removedPhaseIds.has(phaseId)));
|
|
123483
123694
|
await atomicWriteFile(symbolPath, `${JSON.stringify({ ...parsed, phaseFingerprints, symbols }, null, 2)}
|
|
123484
123695
|
`);
|
|
123485
123696
|
}
|
|
123486
|
-
const snapshotRoot =
|
|
123697
|
+
const snapshotRoot = join139(projectRoot2, ".tmp/context-runtime/extract/candidates");
|
|
123487
123698
|
const visit4 = async (directory) => {
|
|
123488
|
-
if (!
|
|
123699
|
+
if (!existsSync36(directory))
|
|
123489
123700
|
return;
|
|
123490
123701
|
for (const entry of await readdir33(directory, { withFileTypes: true })) {
|
|
123491
|
-
const path3 =
|
|
123702
|
+
const path3 = join139(directory, entry.name);
|
|
123492
123703
|
if (entry.isDirectory()) {
|
|
123493
123704
|
await visit4(path3);
|
|
123494
123705
|
continue;
|
|
@@ -123496,7 +123707,7 @@ async function pruneExtractRuntime(projectRoot2, source2) {
|
|
|
123496
123707
|
if (!entry.isFile() || !entry.name.endsWith(".json"))
|
|
123497
123708
|
continue;
|
|
123498
123709
|
try {
|
|
123499
|
-
const parsed = JSON.parse(await
|
|
123710
|
+
const parsed = JSON.parse(await readFile112(path3, "utf8"));
|
|
123500
123711
|
const refs = Array.isArray(parsed.source_refs) ? parsed.source_refs : [];
|
|
123501
123712
|
if (parsed.source === source2.name || refs.some((ref2) => typeof ref2 === "string" && stringReferencesSource(ref2, source2))) {
|
|
123502
123713
|
await rm33(path3, { force: true });
|
|
@@ -123538,7 +123749,7 @@ async function removeProjectSource(input) {
|
|
|
123538
123749
|
});
|
|
123539
123750
|
}
|
|
123540
123751
|
await applyAtomicFileBatch({
|
|
123541
|
-
transactionRoot:
|
|
123752
|
+
transactionRoot: join139(input.projectRoot, ".tmp", "context-runtime", "source-remove-transactions"),
|
|
123542
123753
|
writes: [...plan.registryWrite === undefined ? [] : [plan.registryWrite], ...plan.manifestWrite !== undefined ? [plan.manifestWrite] : []],
|
|
123543
123754
|
removals: plan.absoluteRemovals
|
|
123544
123755
|
});
|
|
@@ -123554,7 +123765,7 @@ init_workspace();
|
|
|
123554
123765
|
init_writeLock();
|
|
123555
123766
|
init_durableMultiFileTransaction();
|
|
123556
123767
|
init_durableSingleFileTransaction();
|
|
123557
|
-
import { readFile as
|
|
123768
|
+
import { readFile as readFile113 } from "node:fs/promises";
|
|
123558
123769
|
import ts from "typescript";
|
|
123559
123770
|
function generateSourceConfiguration(text12, selected) {
|
|
123560
123771
|
const file = ts.createSourceFile("index.ts", text12, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
@@ -123694,7 +123905,7 @@ function generateSourceConfiguration(text12, selected) {
|
|
|
123694
123905
|
async function configureRegisteredSources(projectRoot2, selected) {
|
|
123695
123906
|
return withProjectWriteLock(projectRoot2, "source-project-configuration", async () => {
|
|
123696
123907
|
const path3 = "src/index.ts";
|
|
123697
|
-
const config = JSON.parse(await
|
|
123908
|
+
const config = JSON.parse(await readFile113(await safeProjectTarget(projectRoot2, "package.json"), "utf8"));
|
|
123698
123909
|
if (config.context?.entry !== path3)
|
|
123699
123910
|
return {
|
|
123700
123911
|
status: "manual",
|
|
@@ -123703,7 +123914,7 @@ async function configureRegisteredSources(projectRoot2, selected) {
|
|
|
123703
123914
|
sources: selected
|
|
123704
123915
|
};
|
|
123705
123916
|
const target = await safeProjectTarget(projectRoot2, path3);
|
|
123706
|
-
const text12 = await
|
|
123917
|
+
const text12 = await readFile113(target, "utf8");
|
|
123707
123918
|
const updated = generateSourceConfiguration(text12, selected);
|
|
123708
123919
|
if (updated === undefined)
|
|
123709
123920
|
return {
|
|
@@ -123739,7 +123950,7 @@ init_sourceInputMutation();
|
|
|
123739
123950
|
init_writeLock();
|
|
123740
123951
|
import { execFile as execFile20 } from "node:child_process";
|
|
123741
123952
|
import { promisify as promisify17 } from "node:util";
|
|
123742
|
-
import { join as
|
|
123953
|
+
import { join as join140 } from "node:path";
|
|
123743
123954
|
var exec6 = promisify17(execFile20);
|
|
123744
123955
|
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();
|
|
123745
123956
|
async function restoreDocumentSnapshot(projectRoot2, value) {
|
|
@@ -123831,8 +124042,8 @@ async function restoreDocumentSnapshot(projectRoot2, value) {
|
|
|
123831
124042
|
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)));
|
|
123832
124043
|
const removalTargets = await Promise.all(removals.map((path3) => safeProjectTarget(projectRoot2, path3)));
|
|
123833
124044
|
await applyAtomicFileBatch({
|
|
123834
|
-
transactionRoot:
|
|
123835
|
-
writes: [...selected.files].map(([path3, bytes]) => ({ path:
|
|
124045
|
+
transactionRoot: join140(projectRoot2, ".tmp/context-runtime/capture-transactions"),
|
|
124046
|
+
writes: [...selected.files].map(([path3, bytes]) => ({ path: join140(projectRoot2, path3), bytes })).concat([
|
|
123836
124047
|
{ path: manifestTarget, bytes: Buffer.from(renderDocumentManifestFile(next2)) }
|
|
123837
124048
|
]),
|
|
123838
124049
|
removals: removalTargets
|
|
@@ -123905,7 +124116,7 @@ async function readIncludeList(projectRoot2, path3) {
|
|
|
123905
124116
|
}
|
|
123906
124117
|
let content3;
|
|
123907
124118
|
try {
|
|
123908
|
-
content3 = await
|
|
124119
|
+
content3 = await readFile117(isAbsolute26(trimmed) ? resolve49(trimmed) : resolve49(projectRoot2, trimmed), "utf8");
|
|
123909
124120
|
} catch (error) {
|
|
123910
124121
|
throw new ContextError(ExitCode.UserError, `cannot read include list: ${trimmed}`, {
|
|
123911
124122
|
category: ErrorCategory.UserInputInvalid,
|
|
@@ -124365,13 +124576,13 @@ init_errors3();
|
|
|
124365
124576
|
init_cliFeedback();
|
|
124366
124577
|
init_exitCode();
|
|
124367
124578
|
var import_yaml66 = __toESM(require_dist(), 1);
|
|
124368
|
-
import { constants as constants6, existsSync as
|
|
124579
|
+
import { constants as constants6, existsSync as existsSync37 } from "node:fs";
|
|
124369
124580
|
import { lstat as lstat22, open as open5, readdir as readdir34 } from "node:fs/promises";
|
|
124370
|
-
import { dirname as dirname52, join as
|
|
124581
|
+
import { dirname as dirname52, join as join142, resolve as resolve50 } from "node:path";
|
|
124371
124582
|
import { fileURLToPath as fileURLToPath10 } from "node:url";
|
|
124372
124583
|
function bundledSkillRoot() {
|
|
124373
124584
|
const directory = dirname52(fileURLToPath10(import.meta.url));
|
|
124374
|
-
const root2 = [resolve50(directory, "indexers/bundles"), resolve50(directory, "../../dist/indexers/bundles")].find((path3) =>
|
|
124585
|
+
const root2 = [resolve50(directory, "indexers/bundles"), resolve50(directory, "../../dist/indexers/bundles")].find((path3) => existsSync37(path3));
|
|
124375
124586
|
if (!root2)
|
|
124376
124587
|
throw new TypeError("Bundled skill files are unavailable; build or reinstall the Context CLI.");
|
|
124377
124588
|
return root2;
|
|
@@ -124397,7 +124608,7 @@ async function readProductionSkills(root2) {
|
|
|
124397
124608
|
const entries2 = (await readdir34(root2, { withFileTypes: true })).filter((entry) => entry.isDirectory()).sort((a2, b) => a2.name < b.name ? -1 : a2.name > b.name ? 1 : 0);
|
|
124398
124609
|
const skills = [];
|
|
124399
124610
|
for (const directory of entries2) {
|
|
124400
|
-
const entry =
|
|
124611
|
+
const entry = join142(root2, directory.name, "SKILL.md");
|
|
124401
124612
|
if (!(await lstat22(entry)).isFile())
|
|
124402
124613
|
throw new TypeError(`Skill entry must be a regular file: ${entry}`);
|
|
124403
124614
|
const handle3 = await open5(entry, constants6.O_RDONLY | constants6.O_NOFOLLOW | constants6.O_NONBLOCK);
|
|
@@ -124534,7 +124745,7 @@ init_exitCode();
|
|
|
124534
124745
|
// src/project/entryCommand.ts
|
|
124535
124746
|
init_workflowProvider();
|
|
124536
124747
|
init_workspace();
|
|
124537
|
-
import { existsSync as
|
|
124748
|
+
import { existsSync as existsSync38 } from "node:fs";
|
|
124538
124749
|
import { dirname as dirname53, resolve as resolve51 } from "node:path";
|
|
124539
124750
|
function shellQuote7(value) {
|
|
124540
124751
|
return /^[A-Za-z0-9._/=-]+$/u.test(value) ? value : `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
@@ -124591,7 +124802,7 @@ function resolveContextEntry(input) {
|
|
|
124591
124802
|
const cwd = resolve51(input.cwd);
|
|
124592
124803
|
if (input.projectDir !== undefined) {
|
|
124593
124804
|
const target2 = resolveContextProjectInitTarget(cwd, input.projectDir);
|
|
124594
|
-
if (
|
|
124805
|
+
if (existsSync38(target2) && isContextProjectRoot(target2)) {
|
|
124595
124806
|
return readyResult(input, target2, target2 !== cwd);
|
|
124596
124807
|
}
|
|
124597
124808
|
return {
|
|
@@ -124600,7 +124811,7 @@ function resolveContextEntry(input) {
|
|
|
124600
124811
|
cwd,
|
|
124601
124812
|
workspace: {
|
|
124602
124813
|
root: target2,
|
|
124603
|
-
exists:
|
|
124814
|
+
exists: existsSync38(target2)
|
|
124604
124815
|
},
|
|
124605
124816
|
next_action: {
|
|
124606
124817
|
kind: "initialize-workspace",
|
|
@@ -124644,7 +124855,7 @@ function resolveContextEntry(input) {
|
|
|
124644
124855
|
cwd,
|
|
124645
124856
|
workspace: {
|
|
124646
124857
|
root: target,
|
|
124647
|
-
exists:
|
|
124858
|
+
exists: existsSync38(target)
|
|
124648
124859
|
},
|
|
124649
124860
|
next_action: {
|
|
124650
124861
|
kind: "initialize-workspace",
|
|
@@ -124811,8 +125022,8 @@ init_cliFeedback();
|
|
|
124811
125022
|
init_errors3();
|
|
124812
125023
|
init_exitCode();
|
|
124813
125024
|
import { createHash as createHash46 } from "node:crypto";
|
|
124814
|
-
import { cp as cp3, lstat as lstat23, mkdir as mkdir45, mkdtemp as mkdtemp7, readFile as
|
|
124815
|
-
import { dirname as dirname54, join as
|
|
125025
|
+
import { cp as cp3, lstat as lstat23, mkdir as mkdir45, mkdtemp as mkdtemp7, readFile as readFile118, readdir as readdir35, rename as rename12, rm as rm34, writeFile as writeFile34 } from "node:fs/promises";
|
|
125026
|
+
import { dirname as dirname54, join as join143, resolve as resolve52 } from "node:path";
|
|
124816
125027
|
var MARKER = ".context-skill-install.json";
|
|
124817
125028
|
function conflict(path3) {
|
|
124818
125029
|
throw new ContextError(ExitCode.UserError, `Local skill install conflict: ${path3}`, {
|
|
@@ -124843,7 +125054,7 @@ async function digest9(root2) {
|
|
|
124843
125054
|
for (const name3 of (await readdir35(dir)).sort()) {
|
|
124844
125055
|
if (!prefix && name3 === MARKER)
|
|
124845
125056
|
continue;
|
|
124846
|
-
const path3 =
|
|
125057
|
+
const path3 = join143(dir, name3);
|
|
124847
125058
|
const entry = await lstat23(path3);
|
|
124848
125059
|
if (entry.isSymbolicLink())
|
|
124849
125060
|
conflict(path3);
|
|
@@ -124851,7 +125062,7 @@ async function digest9(root2) {
|
|
|
124851
125062
|
if (entry.isDirectory())
|
|
124852
125063
|
await visit4(path3, `${prefix}${name3}/`);
|
|
124853
125064
|
else if (entry.isFile())
|
|
124854
|
-
hash5.update(await
|
|
125065
|
+
hash5.update(await readFile118(path3));
|
|
124855
125066
|
else
|
|
124856
125067
|
conflict(path3);
|
|
124857
125068
|
}
|
|
@@ -124862,12 +125073,12 @@ async function digest9(root2) {
|
|
|
124862
125073
|
async function assertOwnedDirectory(target, existing) {
|
|
124863
125074
|
if (!existing.isDirectory() || existing.isSymbolicLink())
|
|
124864
125075
|
conflict(target);
|
|
124865
|
-
const markerPath =
|
|
125076
|
+
const markerPath = join143(target, MARKER);
|
|
124866
125077
|
if (!(await stat11(markerPath))?.isFile())
|
|
124867
125078
|
conflict(target);
|
|
124868
125079
|
let marker;
|
|
124869
125080
|
try {
|
|
124870
|
-
marker = JSON.parse(await
|
|
125081
|
+
marker = JSON.parse(await readFile118(markerPath, "utf8"));
|
|
124871
125082
|
} catch {
|
|
124872
125083
|
conflict(target);
|
|
124873
125084
|
}
|
|
@@ -124878,24 +125089,24 @@ async function installLocalSkills(root2, path3, dryRun, agent) {
|
|
|
124878
125089
|
if (!path3.trim())
|
|
124879
125090
|
conflict("--local requires a non-empty path");
|
|
124880
125091
|
const targetRoot = resolve52(path3);
|
|
124881
|
-
const skillsRoot =
|
|
125092
|
+
const skillsRoot = join143(targetRoot, "skills");
|
|
124882
125093
|
await checkParents(skillsRoot);
|
|
124883
|
-
const sourceRoot =
|
|
125094
|
+
const sourceRoot = join143(root2, "skills");
|
|
124884
125095
|
const commandPlans = [];
|
|
124885
125096
|
const commandEntries = new Set;
|
|
124886
125097
|
if (agent === "claude" || agent === "cursor") {
|
|
124887
|
-
for (const name3 of await readdir35(
|
|
125098
|
+
for (const name3 of await readdir35(join143(root2, "claude", "commands"))) {
|
|
124888
125099
|
if (name3.endsWith(".md"))
|
|
124889
125100
|
commandEntries.add(name3.slice(0, -3));
|
|
124890
125101
|
}
|
|
124891
|
-
const commandsRoot =
|
|
125102
|
+
const commandsRoot = join143(targetRoot, "commands");
|
|
124892
125103
|
await checkParents(commandsRoot);
|
|
124893
|
-
for (const entry of await readdir35(
|
|
125104
|
+
for (const entry of await readdir35(join143(root2, agent, "commands"), { withFileTypes: true })) {
|
|
124894
125105
|
if (!entry.isFile() || !entry.name.endsWith(".md"))
|
|
124895
125106
|
continue;
|
|
124896
|
-
const content3 = await
|
|
124897
|
-
const target =
|
|
124898
|
-
const marker =
|
|
125107
|
+
const content3 = await readFile118(join143(root2, agent, "commands", entry.name), "utf8");
|
|
125108
|
+
const target = join143(commandsRoot, entry.name);
|
|
125109
|
+
const marker = join143(commandsRoot, `.context-${entry.name}.json`);
|
|
124899
125110
|
for (const file of [target, marker]) {
|
|
124900
125111
|
const existing = await stat11(file);
|
|
124901
125112
|
if (existing && (!existing.isFile() || existing.isSymbolicLink()))
|
|
@@ -124904,11 +125115,11 @@ async function installLocalSkills(root2, path3, dryRun, agent) {
|
|
|
124904
125115
|
if (await stat11(target)) {
|
|
124905
125116
|
let previous3;
|
|
124906
125117
|
try {
|
|
124907
|
-
previous3 = JSON.parse(await
|
|
125118
|
+
previous3 = JSON.parse(await readFile118(marker, "utf8"));
|
|
124908
125119
|
} catch {
|
|
124909
125120
|
conflict(target);
|
|
124910
125121
|
}
|
|
124911
|
-
const current3 = createHash46("sha256").update(await
|
|
125122
|
+
const current3 = createHash46("sha256").update(await readFile118(target)).digest("hex");
|
|
124912
125123
|
if (previous3?.owner !== "context-plugin-local" || previous3.digest !== current3)
|
|
124913
125124
|
conflict(target);
|
|
124914
125125
|
} else if (await stat11(marker))
|
|
@@ -124916,14 +125127,14 @@ async function installLocalSkills(root2, path3, dryRun, agent) {
|
|
|
124916
125127
|
commandPlans.push({ name: entry.name, target, marker, content: content3, hash: createHash46("sha256").update(content3).digest("hex") });
|
|
124917
125128
|
}
|
|
124918
125129
|
if (!commandPlans.length)
|
|
124919
|
-
conflict(
|
|
125130
|
+
conflict(join143(root2, agent, "commands"));
|
|
124920
125131
|
}
|
|
124921
125132
|
const plans = [];
|
|
124922
125133
|
for (const entry of (await readdir35(sourceRoot, { withFileTypes: true })).sort((a2, b) => a2.name.localeCompare(b.name))) {
|
|
124923
|
-
if (!entry.isDirectory() || !await stat11(
|
|
125134
|
+
if (!entry.isDirectory() || !await stat11(join143(sourceRoot, entry.name, "SKILL.md")))
|
|
124924
125135
|
continue;
|
|
124925
|
-
const source2 =
|
|
124926
|
-
const target =
|
|
125136
|
+
const source2 = join143(sourceRoot, entry.name);
|
|
125137
|
+
const target = join143(skillsRoot, entry.name);
|
|
124927
125138
|
if (commandEntries.has(entry.name) && !["context-plan", "context-repo-content"].includes(entry.name)) {
|
|
124928
125139
|
if (await stat11(target))
|
|
124929
125140
|
conflict(`${target} (use a fresh host directory to avoid duplicate command/skill entries)`);
|
|
@@ -124937,16 +125148,16 @@ async function installLocalSkills(root2, path3, dryRun, agent) {
|
|
|
124937
125148
|
if (!plans.length)
|
|
124938
125149
|
conflict(sourceRoot);
|
|
124939
125150
|
const resourcePlans = [];
|
|
124940
|
-
const resourcesRoot =
|
|
125151
|
+
const resourcesRoot = join143(targetRoot, "resources");
|
|
124941
125152
|
if (agent === "claude" || agent === "cursor") {
|
|
124942
|
-
const resourceSource =
|
|
125153
|
+
const resourceSource = join143(root2, agent, "resources");
|
|
124943
125154
|
if (await stat11(resourceSource)) {
|
|
124944
125155
|
await checkParents(resourcesRoot);
|
|
124945
125156
|
for (const entry of (await readdir35(resourceSource, { withFileTypes: true })).sort((a2, b) => a2.name.localeCompare(b.name))) {
|
|
124946
125157
|
if (!entry.isDirectory())
|
|
124947
125158
|
continue;
|
|
124948
|
-
const source2 =
|
|
124949
|
-
const target =
|
|
125159
|
+
const source2 = join143(resourceSource, entry.name);
|
|
125160
|
+
const target = join143(resourcesRoot, entry.name);
|
|
124950
125161
|
const existing = await stat11(target);
|
|
124951
125162
|
if (existing)
|
|
124952
125163
|
await assertOwnedDirectory(target, existing);
|
|
@@ -124960,15 +125171,15 @@ async function installLocalSkills(root2, path3, dryRun, agent) {
|
|
|
124960
125171
|
await mkdir45(resourcesRoot, { recursive: true });
|
|
124961
125172
|
for (const plan of [...plans, ...resourcePlans]) {
|
|
124962
125173
|
const resource = resourcePlans.includes(plan);
|
|
124963
|
-
const staging = await mkdtemp7(
|
|
124964
|
-
const candidate =
|
|
124965
|
-
const previous3 =
|
|
125174
|
+
const staging = await mkdtemp7(join143(dirname54(plan.target), ".context-install-"));
|
|
125175
|
+
const candidate = join143(staging, "candidate");
|
|
125176
|
+
const previous3 = join143(staging, "previous");
|
|
124966
125177
|
let moved = false;
|
|
124967
125178
|
try {
|
|
124968
125179
|
await cp3(plan.source, candidate, { recursive: true });
|
|
124969
125180
|
if (!resource && (agent === "claude" || agent === "cursor" && ["context-plan", "context-repo-content"].includes(plan.name))) {
|
|
124970
|
-
const skillFile =
|
|
124971
|
-
const content3 = await
|
|
125181
|
+
const skillFile = join143(candidate, "SKILL.md");
|
|
125182
|
+
const content3 = await readFile118(skillFile, "utf8");
|
|
124972
125183
|
const parts = /^(---\r?\n)([\s\S]*?)(\r?\n---(?:\r?\n|$))/.exec(content3);
|
|
124973
125184
|
if (parts && (["context-plan", "context-repo-content"].includes(plan.name) || /^\s*context-public-entry:\s*["']?false["']?\s*$/mu.test(parts[2]))) {
|
|
124974
125185
|
const frontmatter2 = parts[2].replace(/^user-invocable:.*\r?\n?/mu, "");
|
|
@@ -124976,7 +125187,7 @@ async function installLocalSkills(root2, path3, dryRun, agent) {
|
|
|
124976
125187
|
${frontmatter2}${parts[3]}${content3.slice(parts[0].length)}`);
|
|
124977
125188
|
}
|
|
124978
125189
|
}
|
|
124979
|
-
await writeFile34(
|
|
125190
|
+
await writeFile34(join143(candidate, MARKER), JSON.stringify({ owner: "context-plugin-local", digest: await digest9(candidate) }) + `
|
|
124980
125191
|
`);
|
|
124981
125192
|
if (plan.exists) {
|
|
124982
125193
|
await rename12(plan.target, previous3);
|
|
@@ -125000,12 +125211,12 @@ ${frontmatter2}${parts[3]}${content3.slice(parts[0].length)}`);
|
|
|
125000
125211
|
}
|
|
125001
125212
|
for (const command3 of commandPlans) {
|
|
125002
125213
|
await mkdir45(dirname54(command3.target), { recursive: true });
|
|
125003
|
-
const staging = await mkdtemp7(
|
|
125004
|
-
await writeFile34(
|
|
125005
|
-
await writeFile34(
|
|
125214
|
+
const staging = await mkdtemp7(join143(dirname54(command3.target), ".context-install-"));
|
|
125215
|
+
await writeFile34(join143(staging, "command"), command3.content);
|
|
125216
|
+
await writeFile34(join143(staging, "marker"), JSON.stringify({ owner: "context-plugin-local", digest: command3.hash }) + `
|
|
125006
125217
|
`);
|
|
125007
|
-
await rename12(
|
|
125008
|
-
await rename12(
|
|
125218
|
+
await rename12(join143(staging, "command"), command3.target);
|
|
125219
|
+
await rename12(join143(staging, "marker"), command3.marker);
|
|
125009
125220
|
await rm34(staging, { recursive: true, force: true });
|
|
125010
125221
|
}
|
|
125011
125222
|
}
|
|
@@ -125030,10 +125241,10 @@ init_cliFeedback();
|
|
|
125030
125241
|
init_errors3();
|
|
125031
125242
|
init_exitCode();
|
|
125032
125243
|
import { lstat as lstat24 } from "node:fs/promises";
|
|
125033
|
-
import { join as
|
|
125244
|
+
import { join as join144, resolve as resolve53 } from "node:path";
|
|
125034
125245
|
var HOST_DIRS = { claude: ".claude", cursor: ".cursor", codex: ".agents" };
|
|
125035
125246
|
async function detectLocalAgent(agent, repo) {
|
|
125036
|
-
const path3 =
|
|
125247
|
+
const path3 = join144(repo, HOST_DIRS[agent]);
|
|
125037
125248
|
try {
|
|
125038
125249
|
const entry = await lstat24(path3);
|
|
125039
125250
|
if (!entry.isDirectory() || entry.isSymbolicLink()) {
|
|
@@ -125058,7 +125269,7 @@ async function installAutoLocalSkills(root2, path3, dryRun, detect = detectLocal
|
|
|
125058
125269
|
if (selectedAgent ? selectedAgent === "all" || agent === selectedAgent : await detect(agent, repo))
|
|
125059
125270
|
agents.push(agent);
|
|
125060
125271
|
}
|
|
125061
|
-
const targets = agents.length ? agents.map((agent) => ({ agent, path:
|
|
125272
|
+
const targets = agents.length ? agents.map((agent) => ({ agent, path: join144(repo, HOST_DIRS[agent]) })) : [{ path: join144(repo, ".agents") }];
|
|
125062
125273
|
const previews = [];
|
|
125063
125274
|
for (const target of targets)
|
|
125064
125275
|
previews.push(await installLocalSkills(root2, target.path, true, target.agent));
|
|
@@ -125090,8 +125301,8 @@ init_exitCode();
|
|
|
125090
125301
|
init_cliFeedback();
|
|
125091
125302
|
init_errors3();
|
|
125092
125303
|
init_exitCode();
|
|
125093
|
-
import { existsSync as
|
|
125094
|
-
import { dirname as dirname56, join as
|
|
125304
|
+
import { existsSync as existsSync40 } from "node:fs";
|
|
125305
|
+
import { dirname as dirname56, join as join146, resolve as resolve54 } from "node:path";
|
|
125095
125306
|
import { fileURLToPath as fileURLToPath11 } from "node:url";
|
|
125096
125307
|
|
|
125097
125308
|
// src/project/pluginInstallTargets.ts
|
|
@@ -125099,10 +125310,10 @@ init_cliFeedback();
|
|
|
125099
125310
|
init_errors3();
|
|
125100
125311
|
init_exitCode();
|
|
125101
125312
|
import { execFile as execFile21 } from "node:child_process";
|
|
125102
|
-
import { existsSync as
|
|
125103
|
-
import { cp as cp4, mkdir as mkdir46, readdir as readdir36, readFile as
|
|
125313
|
+
import { existsSync as existsSync39 } from "node:fs";
|
|
125314
|
+
import { cp as cp4, mkdir as mkdir46, readdir as readdir36, readFile as readFile119, rename as rename13, rm as rm35, writeFile as writeFile35 } from "node:fs/promises";
|
|
125104
125315
|
import { homedir as homedir2 } from "node:os";
|
|
125105
|
-
import { dirname as dirname55, join as
|
|
125316
|
+
import { dirname as dirname55, join as join145 } from "node:path";
|
|
125106
125317
|
import { promisify as promisify18 } from "node:util";
|
|
125107
125318
|
var execFileAsync6 = promisify18(execFile21);
|
|
125108
125319
|
var MARKETPLACE_NAME = "c4a";
|
|
@@ -125156,23 +125367,23 @@ async function claudePluginInstalled(pluginId) {
|
|
|
125156
125367
|
}
|
|
125157
125368
|
}
|
|
125158
125369
|
function codexHome() {
|
|
125159
|
-
return process.env.CODEX_HOME?.trim() ||
|
|
125370
|
+
return process.env.CODEX_HOME?.trim() || join145(homedir2(), ".codex");
|
|
125160
125371
|
}
|
|
125161
125372
|
function claudePluginCacheRoot() {
|
|
125162
125373
|
const explicitRoot = process.env[CLAUDE_PLUGIN_CACHE_ROOT_ENV2]?.trim();
|
|
125163
125374
|
if (explicitRoot)
|
|
125164
125375
|
return explicitRoot;
|
|
125165
125376
|
const home = process.env[CLAUDE_PLUGIN_CACHE_HOME_ENV2]?.trim() || homedir2();
|
|
125166
|
-
return
|
|
125377
|
+
return join145(home, ".claude", "plugins", "cache");
|
|
125167
125378
|
}
|
|
125168
125379
|
function sharedSkillsRoot() {
|
|
125169
|
-
return process.env[SHARED_SKILLS_ROOT_ENV]?.trim() ||
|
|
125380
|
+
return process.env[SHARED_SKILLS_ROOT_ENV]?.trim() || join145(homedir2(), ".agents", "skills");
|
|
125170
125381
|
}
|
|
125171
125382
|
function claudeSkillsRoot() {
|
|
125172
|
-
return process.env[CLAUDE_SKILLS_ROOT_ENV]?.trim() ||
|
|
125383
|
+
return process.env[CLAUDE_SKILLS_ROOT_ENV]?.trim() || join145(homedir2(), ".claude", "skills");
|
|
125173
125384
|
}
|
|
125174
125385
|
function cursorPluginRoot() {
|
|
125175
|
-
return process.env[CURSOR_PLUGIN_ROOT_ENV]?.trim() ||
|
|
125386
|
+
return process.env[CURSOR_PLUGIN_ROOT_ENV]?.trim() || join145(homedir2(), ".cursor", "plugins", "local", PLUGIN_NAME);
|
|
125176
125387
|
}
|
|
125177
125388
|
function blockHeader(line) {
|
|
125178
125389
|
const match = line.match(/^\s*\[([^\]]+)\]\s*$/u);
|
|
@@ -125223,8 +125434,8 @@ function pruneLegacyCodexConfigContent(content3) {
|
|
|
125223
125434
|
`), removed };
|
|
125224
125435
|
}
|
|
125225
125436
|
async function pruneLegacyCodexConfig(dryRun, steps) {
|
|
125226
|
-
const configPath =
|
|
125227
|
-
const current3 = await
|
|
125437
|
+
const configPath = join145(codexHome(), "config.toml");
|
|
125438
|
+
const current3 = await readFile119(configPath, "utf8").catch(() => "");
|
|
125228
125439
|
if (!current3)
|
|
125229
125440
|
return;
|
|
125230
125441
|
const next2 = pruneLegacyCodexConfigContent(current3);
|
|
@@ -125240,8 +125451,8 @@ async function pruneLegacyCodexConfig(dryRun, steps) {
|
|
|
125240
125451
|
}
|
|
125241
125452
|
}
|
|
125242
125453
|
async function pruneCodexPluginCacheForName(pluginName, keepVersion, dryRun, steps) {
|
|
125243
|
-
const cacheRoot =
|
|
125244
|
-
if (!
|
|
125454
|
+
const cacheRoot = join145(codexHome(), "plugins", "cache", MARKETPLACE_NAME, pluginName);
|
|
125455
|
+
if (!existsSync39(cacheRoot))
|
|
125245
125456
|
return;
|
|
125246
125457
|
const versions = (await readdir36(cacheRoot, { withFileTypes: true }).catch(() => [])).filter((entry) => entry.isDirectory() && entry.name !== keepVersion).map((entry) => entry.name).sort();
|
|
125247
125458
|
if (versions.length === 0)
|
|
@@ -125252,7 +125463,7 @@ async function pruneCodexPluginCacheForName(pluginName, keepVersion, dryRun, ste
|
|
|
125252
125463
|
status: dryRun ? "planned" : "ran"
|
|
125253
125464
|
});
|
|
125254
125465
|
if (!dryRun)
|
|
125255
|
-
await Promise.all(versions.map((version3) => rm35(
|
|
125466
|
+
await Promise.all(versions.map((version3) => rm35(join145(cacheRoot, version3), { recursive: true, force: true })));
|
|
125256
125467
|
}
|
|
125257
125468
|
async function pruneCodexPluginCache(currentVersion, dryRun, steps) {
|
|
125258
125469
|
await pruneCodexPluginCacheForName(PLUGIN_NAME, currentVersion, dryRun, steps);
|
|
@@ -125269,22 +125480,22 @@ async function isEmptyDir2(dir) {
|
|
|
125269
125480
|
}
|
|
125270
125481
|
async function pruneClaudeOrphanContextCache(dryRun, steps) {
|
|
125271
125482
|
const cacheRoot = claudePluginCacheRoot();
|
|
125272
|
-
if (!
|
|
125483
|
+
if (!existsSync39(cacheRoot))
|
|
125273
125484
|
return;
|
|
125274
125485
|
const removed = [];
|
|
125275
125486
|
const marketplaces = await readdir36(cacheRoot, { withFileTypes: true }).catch(() => []);
|
|
125276
125487
|
for (const marketplace of marketplaces) {
|
|
125277
125488
|
if (!marketplace.isDirectory())
|
|
125278
125489
|
continue;
|
|
125279
|
-
const pluginDir =
|
|
125280
|
-
if (!
|
|
125490
|
+
const pluginDir = join145(cacheRoot, marketplace.name, PLUGIN_NAME);
|
|
125491
|
+
if (!existsSync39(pluginDir))
|
|
125281
125492
|
continue;
|
|
125282
125493
|
const versions = await readdir36(pluginDir, { withFileTypes: true }).catch(() => []);
|
|
125283
125494
|
for (const version3 of versions) {
|
|
125284
125495
|
if (!version3.isDirectory())
|
|
125285
125496
|
continue;
|
|
125286
|
-
const versionDir =
|
|
125287
|
-
if (!
|
|
125497
|
+
const versionDir = join145(pluginDir, version3.name);
|
|
125498
|
+
if (!existsSync39(join145(versionDir, ORPHAN_MARKER2)))
|
|
125288
125499
|
continue;
|
|
125289
125500
|
removed.push(`${marketplace.name}/${PLUGIN_NAME}/${version3.name}`);
|
|
125290
125501
|
if (!dryRun) {
|
|
@@ -125294,7 +125505,7 @@ async function pruneClaudeOrphanContextCache(dryRun, steps) {
|
|
|
125294
125505
|
if (!dryRun && await isEmptyDir2(pluginDir)) {
|
|
125295
125506
|
await rm35(pluginDir, { recursive: true, force: true });
|
|
125296
125507
|
}
|
|
125297
|
-
const marketplaceDir =
|
|
125508
|
+
const marketplaceDir = join145(cacheRoot, marketplace.name);
|
|
125298
125509
|
if (!dryRun && await isEmptyDir2(marketplaceDir)) {
|
|
125299
125510
|
await rm35(marketplaceDir, { recursive: true, force: true });
|
|
125300
125511
|
}
|
|
@@ -125311,12 +125522,12 @@ async function pruneClaudeLegacyPluginCache(dryRun, steps) {
|
|
|
125311
125522
|
if (LEGACY_PLUGIN_NAMES.length === 0)
|
|
125312
125523
|
return;
|
|
125313
125524
|
const cacheRoot = claudePluginCacheRoot();
|
|
125314
|
-
if (!
|
|
125525
|
+
if (!existsSync39(cacheRoot))
|
|
125315
125526
|
return;
|
|
125316
125527
|
const removed = [];
|
|
125317
125528
|
for (const pluginName of LEGACY_PLUGIN_NAMES) {
|
|
125318
|
-
const pluginDir =
|
|
125319
|
-
if (!
|
|
125529
|
+
const pluginDir = join145(cacheRoot, MARKETPLACE_NAME, pluginName);
|
|
125530
|
+
if (!existsSync39(pluginDir))
|
|
125320
125531
|
continue;
|
|
125321
125532
|
removed.push(`${MARKETPLACE_NAME}/${pluginName}`);
|
|
125322
125533
|
if (!dryRun) {
|
|
@@ -125332,11 +125543,11 @@ async function pruneClaudeLegacyPluginCache(dryRun, steps) {
|
|
|
125332
125543
|
}
|
|
125333
125544
|
}
|
|
125334
125545
|
async function pruneClaudeSupersededContextCache(root2, dryRun, steps) {
|
|
125335
|
-
const manifest = await
|
|
125546
|
+
const manifest = await readFile119(join145(root2, "claude", ".claude-plugin", "plugin.json"), "utf8").then((content3) => JSON.parse(content3)).catch(() => null);
|
|
125336
125547
|
const currentVersion = typeof manifest?.version === "string" ? manifest.version : null;
|
|
125337
125548
|
if (!currentVersion)
|
|
125338
125549
|
return;
|
|
125339
|
-
const pluginDir =
|
|
125550
|
+
const pluginDir = join145(claudePluginCacheRoot(), MARKETPLACE_NAME, PLUGIN_NAME);
|
|
125340
125551
|
const staleVersions = (await readdir36(pluginDir, { withFileTypes: true }).catch(() => [])).filter((entry) => entry.isDirectory() && entry.name !== currentVersion).map((entry) => entry.name);
|
|
125341
125552
|
if (staleVersions.length === 0)
|
|
125342
125553
|
return;
|
|
@@ -125346,7 +125557,7 @@ async function pruneClaudeSupersededContextCache(root2, dryRun, steps) {
|
|
|
125346
125557
|
status: dryRun ? "planned" : "ran"
|
|
125347
125558
|
});
|
|
125348
125559
|
if (!dryRun) {
|
|
125349
|
-
await Promise.all(staleVersions.map((version3) => rm35(
|
|
125560
|
+
await Promise.all(staleVersions.map((version3) => rm35(join145(pluginDir, version3), { recursive: true, force: true })));
|
|
125350
125561
|
}
|
|
125351
125562
|
}
|
|
125352
125563
|
function enableCodexPluginConfig(content3) {
|
|
@@ -125410,33 +125621,33 @@ source = ${JSON.stringify(root2)}
|
|
|
125410
125621
|
`;
|
|
125411
125622
|
}
|
|
125412
125623
|
async function ensureCodexPluginEnabled() {
|
|
125413
|
-
const configPath =
|
|
125624
|
+
const configPath = join145(codexHome(), "config.toml");
|
|
125414
125625
|
await mkdir46(dirname55(configPath), { recursive: true });
|
|
125415
|
-
const current3 = await
|
|
125626
|
+
const current3 = await readFile119(configPath, "utf8").catch(() => "");
|
|
125416
125627
|
const next2 = enableCodexPluginConfig(current3);
|
|
125417
125628
|
if (next2 !== current3) {
|
|
125418
125629
|
await writeFile35(configPath, next2, "utf8");
|
|
125419
125630
|
}
|
|
125420
125631
|
}
|
|
125421
125632
|
async function ensureCodexLocalMarketplace(root2) {
|
|
125422
|
-
const configPath =
|
|
125633
|
+
const configPath = join145(codexHome(), "config.toml");
|
|
125423
125634
|
await mkdir46(dirname55(configPath), { recursive: true });
|
|
125424
|
-
const current3 = await
|
|
125635
|
+
const current3 = await readFile119(configPath, "utf8").catch(() => "");
|
|
125425
125636
|
const next2 = upsertCodexLocalMarketplaceConfig(current3, root2);
|
|
125426
125637
|
if (next2 !== current3) {
|
|
125427
125638
|
await writeFile35(configPath, next2, "utf8");
|
|
125428
125639
|
}
|
|
125429
125640
|
}
|
|
125430
125641
|
async function codexPluginVersion(root2) {
|
|
125431
|
-
const manifestPath =
|
|
125432
|
-
const manifest = JSON.parse(await
|
|
125642
|
+
const manifestPath = join145(root2, "codex", ".codex-plugin", "plugin.json");
|
|
125643
|
+
const manifest = JSON.parse(await readFile119(manifestPath, "utf8"));
|
|
125433
125644
|
if (typeof manifest.version !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/u.test(manifest.version)) {
|
|
125434
125645
|
throw new Error(`Codex plugin manifest has an invalid version: ${manifestPath}`);
|
|
125435
125646
|
}
|
|
125436
125647
|
return manifest.version;
|
|
125437
125648
|
}
|
|
125438
125649
|
function codexPluginCacheDir(version3) {
|
|
125439
|
-
return
|
|
125650
|
+
return join145(codexHome(), "plugins", "cache", MARKETPLACE_NAME, PLUGIN_NAME, version3);
|
|
125440
125651
|
}
|
|
125441
125652
|
async function replaceDirectoryFromSource(source2, target) {
|
|
125442
125653
|
await mkdir46(dirname55(target), { recursive: true });
|
|
@@ -125444,7 +125655,7 @@ async function replaceDirectoryFromSource(source2, target) {
|
|
|
125444
125655
|
const previous3 = `${target}.previous-${process.pid}-${Date.now()}`;
|
|
125445
125656
|
await rm35(temporary, { recursive: true, force: true });
|
|
125446
125657
|
await cp4(source2, temporary, { recursive: true, force: true });
|
|
125447
|
-
const hadPrevious =
|
|
125658
|
+
const hadPrevious = existsSync39(target);
|
|
125448
125659
|
try {
|
|
125449
125660
|
if (hadPrevious)
|
|
125450
125661
|
await rename13(target, previous3);
|
|
@@ -125453,13 +125664,13 @@ async function replaceDirectoryFromSource(source2, target) {
|
|
|
125453
125664
|
await rm35(previous3, { recursive: true, force: true });
|
|
125454
125665
|
} catch (error) {
|
|
125455
125666
|
await rm35(temporary, { recursive: true, force: true });
|
|
125456
|
-
if (hadPrevious && !
|
|
125667
|
+
if (hadPrevious && !existsSync39(target) && existsSync39(previous3))
|
|
125457
125668
|
await rename13(previous3, target);
|
|
125458
125669
|
throw error;
|
|
125459
125670
|
}
|
|
125460
125671
|
}
|
|
125461
125672
|
async function materializeCodexPluginCache(root2, version3, dryRun, steps) {
|
|
125462
|
-
const source2 =
|
|
125673
|
+
const source2 = join145(root2, "codex");
|
|
125463
125674
|
const target = codexPluginCacheDir(version3);
|
|
125464
125675
|
steps.push({
|
|
125465
125676
|
agent: "codex",
|
|
@@ -125471,16 +125682,16 @@ async function materializeCodexPluginCache(root2, version3, dryRun, steps) {
|
|
|
125471
125682
|
await replaceDirectoryFromSource(source2, target);
|
|
125472
125683
|
}
|
|
125473
125684
|
async function bundledProviderSkillNames(root2) {
|
|
125474
|
-
const skillsRoot =
|
|
125685
|
+
const skillsRoot = join145(root2, "skills");
|
|
125475
125686
|
const entries2 = await readdir36(skillsRoot, { withFileTypes: true });
|
|
125476
125687
|
const names = [];
|
|
125477
125688
|
for (const entry of entries2) {
|
|
125478
125689
|
if (!entry.isDirectory() || entry.name === "context")
|
|
125479
125690
|
continue;
|
|
125480
|
-
const skillPath =
|
|
125481
|
-
if (!
|
|
125691
|
+
const skillPath = join145(skillsRoot, entry.name, "SKILL.md");
|
|
125692
|
+
if (!existsSync39(skillPath))
|
|
125482
125693
|
continue;
|
|
125483
|
-
const skill = await
|
|
125694
|
+
const skill = await readFile119(skillPath, "utf8");
|
|
125484
125695
|
if (!/^\s*context-role:\s*["']?indexer-provider["']?\s*$/mu.test(skill))
|
|
125485
125696
|
continue;
|
|
125486
125697
|
names.push(entry.name);
|
|
@@ -125492,10 +125703,10 @@ async function bundledProviderSkillNames(root2) {
|
|
|
125492
125703
|
return names;
|
|
125493
125704
|
}
|
|
125494
125705
|
async function materializeProviderSkills(root2, targetRoot, agent, dryRun, steps) {
|
|
125495
|
-
const sourceRoot =
|
|
125706
|
+
const sourceRoot = join145(root2, "skills");
|
|
125496
125707
|
for (const name3 of await bundledProviderSkillNames(root2)) {
|
|
125497
|
-
const source2 =
|
|
125498
|
-
const target =
|
|
125708
|
+
const source2 = join145(sourceRoot, name3);
|
|
125709
|
+
const target = join145(targetRoot, name3);
|
|
125499
125710
|
steps.push({
|
|
125500
125711
|
agent,
|
|
125501
125712
|
command: `materialize lifecycle Provider skill: ${shellQuote8(source2)} -> ${shellQuote8(target)}`,
|
|
@@ -125506,7 +125717,7 @@ async function materializeProviderSkills(root2, targetRoot, agent, dryRun, steps
|
|
|
125506
125717
|
}
|
|
125507
125718
|
}
|
|
125508
125719
|
async function installCursor(root2, dryRun, steps) {
|
|
125509
|
-
const source2 =
|
|
125720
|
+
const source2 = join145(root2, "cursor");
|
|
125510
125721
|
const target = cursorPluginRoot();
|
|
125511
125722
|
steps.push({
|
|
125512
125723
|
agent: "cursor",
|
|
@@ -125561,12 +125772,12 @@ async function installCodex(root2, dryRun, steps) {
|
|
|
125561
125772
|
steps.push({ agent: "codex", command: commandLine("codex", addArgs), status: dryRun ? "planned" : "ran" });
|
|
125562
125773
|
steps.push({
|
|
125563
125774
|
agent: "codex",
|
|
125564
|
-
command: `ensure ${shellQuote8(
|
|
125775
|
+
command: `ensure ${shellQuote8(join145(codexHome(), "config.toml"))} registers local marketplace ${shellQuote8(MARKETPLACE_NAME)}`,
|
|
125565
125776
|
status: dryRun ? "planned" : "ran"
|
|
125566
125777
|
});
|
|
125567
125778
|
steps.push({
|
|
125568
125779
|
agent: "codex",
|
|
125569
|
-
command: `ensure ${shellQuote8(
|
|
125780
|
+
command: `ensure ${shellQuote8(join145(codexHome(), "config.toml"))} enables ${shellQuote8(PLUGIN_ID)}`,
|
|
125570
125781
|
status: dryRun ? "planned" : "ran"
|
|
125571
125782
|
});
|
|
125572
125783
|
if (dryRun) {
|
|
@@ -125621,13 +125832,13 @@ function pluginRootCandidates() {
|
|
|
125621
125832
|
return [resolve54(envRoot)];
|
|
125622
125833
|
const candidates = [];
|
|
125623
125834
|
for (const dir of packageCandidateDirs()) {
|
|
125624
|
-
candidates.push(
|
|
125625
|
-
candidates.push(
|
|
125835
|
+
candidates.push(join146(dir, "plugins"));
|
|
125836
|
+
candidates.push(join146(dir, "dist", "plugins"));
|
|
125626
125837
|
}
|
|
125627
125838
|
return [...new Set(candidates)];
|
|
125628
125839
|
}
|
|
125629
125840
|
function isInstallablePluginRoot(root2) {
|
|
125630
|
-
return
|
|
125841
|
+
return existsSync40(join146(root2, ".claude-plugin", "marketplace.json")) && existsSync40(join146(root2, ".agents", "plugins", "marketplace.json")) && existsSync40(join146(root2, "claude", ".claude-plugin", "plugin.json")) && existsSync40(join146(root2, "codex", ".codex-plugin", "plugin.json")) && existsSync40(join146(root2, "cursor", ".cursor-plugin", "plugin.json")) && existsSync40(join146(root2, "skills"));
|
|
125631
125842
|
}
|
|
125632
125843
|
function resolveBundledPluginsRoot() {
|
|
125633
125844
|
const candidates = pluginRootCandidates();
|
|
@@ -125893,11 +126104,11 @@ function readQuickstartPath() {
|
|
|
125893
126104
|
try {
|
|
125894
126105
|
let dir = dirname57(fileURLToPath12(import.meta.url));
|
|
125895
126106
|
for (let i2 = 0;i2 < 8; i2++) {
|
|
125896
|
-
const candidate =
|
|
125897
|
-
if (
|
|
126107
|
+
const candidate = join147(dir, "docs", "quickstart.md");
|
|
126108
|
+
if (existsSync41(candidate))
|
|
125898
126109
|
return candidate;
|
|
125899
|
-
const pkg =
|
|
125900
|
-
if (
|
|
126110
|
+
const pkg = join147(dir, "package.json");
|
|
126111
|
+
if (existsSync41(pkg))
|
|
125901
126112
|
return candidate;
|
|
125902
126113
|
const parent2 = dirname57(dir);
|
|
125903
126114
|
if (parent2 === dir)
|
|
@@ -125905,7 +126116,7 @@ function readQuickstartPath() {
|
|
|
125905
126116
|
dir = parent2;
|
|
125906
126117
|
}
|
|
125907
126118
|
} catch {}
|
|
125908
|
-
return
|
|
126119
|
+
return join147(dirname57(fileURLToPath12(import.meta.url)), "docs", "quickstart.md");
|
|
125909
126120
|
}
|
|
125910
126121
|
var GREEN = "\x1B[32m";
|
|
125911
126122
|
var RESET = "\x1B[0m";
|