@c4a/context-cli 0.7.95 → 0.7.97
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 +851 -316
- package/indexers/contracts/profile-contract.json +245 -245
- package/indexers/release-manifest.json +1 -1
- package/package.json +12 -12
- package/parserEntryWorker.js +7 -4
- package/plugins/VERSION +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/commands/context.md +9 -3
- package/plugins/claude/resources/context/version-alignment.md +3 -0
- package/plugins/codex/.codex-plugin/plugin.json +2 -2
- package/plugins/codex/skills/context/SKILL.md +9 -3
- package/plugins/codex/skills/context/references/version-alignment.md +3 -0
- package/plugins/cursor/.cursor-plugin/plugin.json +1 -1
- package/plugins/cursor/commands/c4a-context.md +9 -3
- package/plugins/cursor/resources/context/version-alignment.md +3 -0
- package/plugins/skills/context/SKILL.md +9 -3
- package/plugins/skills/context/references/version-alignment.md +3 -0
- package/providers/context/manifest.json +15 -15
- package/providers/context/provider.yaml +1 -1
- package/providers/context/resources/manuals/guides/knowledge-updates.md +10 -1
- package/providers/context/resources/manuals/guides/lark-resources.md +9 -2
- package/providers/context/resources/procedures/approved-revision.md +7 -0
- package/providers/context/resources/procedures/knowledge-updates.md +10 -1
- package/providers/context/resources/procedures/production-stage-files.md +6 -2
- package/providers/context/resources/procedures/source-update.md +3 -1
- package/providers/context/skills/translate-site-locales/SKILL.md +1 -0
package/cli.js
CHANGED
|
@@ -41212,7 +41212,7 @@ var import_yaml8, DEFAULT_REPO_SOURCES_REGISTRY_PATH = "sources/repo/index.yaml"
|
|
|
41212
41212
|
}
|
|
41213
41213
|
}
|
|
41214
41214
|
}
|
|
41215
|
-
}, loadSourcesRegistry = async (options = {}) => {
|
|
41215
|
+
}, SOURCES_REGISTRY_EXCLUSION, loadSourcesRegistry = async (options = {}) => {
|
|
41216
41216
|
const rootDir = options.rootDir ?? process.cwd();
|
|
41217
41217
|
const repoRegistryPath = options.repoRegistryPath ?? options.registryPath ?? DEFAULT_REPO_SOURCES_REGISTRY_PATH;
|
|
41218
41218
|
const fileRegistryPath = options.fileRegistryPath ?? DEFAULT_FILE_SOURCES_REGISTRY_PATH;
|
|
@@ -41220,6 +41220,8 @@ var import_yaml8, DEFAULT_REPO_SOURCES_REGISTRY_PATH = "sources/repo/index.yaml"
|
|
|
41220
41220
|
const repoAbsolutePath = resolve7(rootDir, repoRegistryPath);
|
|
41221
41221
|
const fileAbsolutePath = resolve7(rootDir, fileRegistryPath);
|
|
41222
41222
|
const larkAbsolutePath = resolve7(rootDir, larkRegistryPath);
|
|
41223
|
+
const excluded = globalThis[SOURCES_REGISTRY_EXCLUSION];
|
|
41224
|
+
const included = (entry) => !(excluded instanceof Set && (excluded.has(entry.name) || excluded.has(entry.id)));
|
|
41223
41225
|
const repoRegistry = parseRepoSourcesRegistry(await readYamlIfPresent(repoAbsolutePath, { sources: [] }), repoRegistryPath, repoAbsolutePath);
|
|
41224
41226
|
const files = parseFileSourcesRegistry(await readYamlIfPresent(fileAbsolutePath, { sources: [] }), fileRegistryPath);
|
|
41225
41227
|
const larks = parseLarkSourcesRegistry(await readYamlIfPresent(larkAbsolutePath, { sources: [] }), larkRegistryPath);
|
|
@@ -41235,9 +41237,9 @@ var import_yaml8, DEFAULT_REPO_SOURCES_REGISTRY_PATH = "sources/repo/index.yaml"
|
|
|
41235
41237
|
file: fileAbsolutePath,
|
|
41236
41238
|
lark: larkAbsolutePath
|
|
41237
41239
|
},
|
|
41238
|
-
repos: repoRegistry.repos,
|
|
41239
|
-
files,
|
|
41240
|
-
larks,
|
|
41240
|
+
repos: repoRegistry.repos.filter(included),
|
|
41241
|
+
files: files.filter(included),
|
|
41242
|
+
larks: larks.filter(included),
|
|
41241
41243
|
notes: await discoverManagedDocuments(rootDir, "note"),
|
|
41242
41244
|
sessions: await discoverManagedDocuments(rootDir, "sessions")
|
|
41243
41245
|
};
|
|
@@ -41304,6 +41306,7 @@ var init_sources = __esm(() => {
|
|
|
41304
41306
|
larkSourcesRegistrySchema = exports_external.object({
|
|
41305
41307
|
sources: exports_external.array(exports_external.union([larkSourceRegistryEntrySchema, larkSourceBatchSchema])).default([])
|
|
41306
41308
|
}).strict();
|
|
41309
|
+
SOURCES_REGISTRY_EXCLUSION = Symbol.for("c4a.context.sources-registry-exclusion");
|
|
41307
41310
|
});
|
|
41308
41311
|
|
|
41309
41312
|
// ../context/src/processedScopes.ts
|
|
@@ -69867,6 +69870,15 @@ var init_durableMultiFileTransaction = __esm(() => {
|
|
|
69867
69870
|
});
|
|
69868
69871
|
|
|
69869
69872
|
// src/project/productionRequirements.ts
|
|
69873
|
+
var exports_productionRequirements = {};
|
|
69874
|
+
__export(exports_productionRequirements, {
|
|
69875
|
+
validateProductionRequirements: () => validateProductionRequirements,
|
|
69876
|
+
readProductionRequirements: () => readProductionRequirements,
|
|
69877
|
+
productionSourceIsExcluded: () => productionSourceIsExcluded,
|
|
69878
|
+
productionRequirementsSchema: () => productionRequirementsSchema,
|
|
69879
|
+
inspectProductionRequirements: () => inspectProductionRequirements,
|
|
69880
|
+
PRODUCTION_REQUIREMENTS_PATH: () => PRODUCTION_REQUIREMENTS_PATH
|
|
69881
|
+
});
|
|
69870
69882
|
import { readFile as readFile13 } from "node:fs/promises";
|
|
69871
69883
|
async function readProductionRequirements(projectRoot) {
|
|
69872
69884
|
const inspected = await inspectProductionRequirements(projectRoot);
|
|
@@ -70012,6 +70024,85 @@ function approvedContextSectionsInMarkdown(content3) {
|
|
|
70012
70024
|
return result;
|
|
70013
70025
|
}
|
|
70014
70026
|
|
|
70027
|
+
// src/lib/gitProgress.ts
|
|
70028
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
70029
|
+
function redactRemoteCredentials(text5) {
|
|
70030
|
+
return text5.replace(/\/\/[^/@\s]+@/gu, "//");
|
|
70031
|
+
}
|
|
70032
|
+
function progressCount(line) {
|
|
70033
|
+
const match = /^(?:remote:\s*)?([A-Za-z][A-Za-z ]*?):\s+(?:\d+%\s+\((\d+)\/\d+\)|(\d+))/u.exec(line);
|
|
70034
|
+
if (!match)
|
|
70035
|
+
return;
|
|
70036
|
+
const size = /,\s*(\d+(?:\.\d+)?)\s*(bytes|[KMGT]iB)(?!\/s)/u.exec(line.slice(match[0].length));
|
|
70037
|
+
return { phase: match[1], count: Number(match[2] ?? match[3]), bytes: size ? Number(size[1]) * UNITS[size[2]] : 0 };
|
|
70038
|
+
}
|
|
70039
|
+
async function runGitWithProgress(args, options) {
|
|
70040
|
+
const idleMs = options.idleMs ?? 5 * 60000, limitMs = options.limitMs ?? 30 * 60000, reportMs = options.reportMs ?? 30000;
|
|
70041
|
+
const command = args.findIndex((arg) => arg === "fetch" || arg === "clone");
|
|
70042
|
+
const argv = command < 0 ? [...args] : [...args.slice(0, command + 1), "--progress", ...args.slice(command + 1)];
|
|
70043
|
+
const child = spawn2(options.bin ?? "git", argv, { cwd: options.cwd, env: options.env ?? process.env, stdio: ["ignore", "pipe", "pipe"] });
|
|
70044
|
+
const started = Date.now();
|
|
70045
|
+
let lastProgress = started, lastReport = started, lastLine = "", stdout = "", tail = "";
|
|
70046
|
+
const counts2 = new Map;
|
|
70047
|
+
child.stdout.on("data", (chunk) => {
|
|
70048
|
+
stdout += String(chunk);
|
|
70049
|
+
});
|
|
70050
|
+
child.stderr.on("data", (chunk) => {
|
|
70051
|
+
const text5 = String(chunk);
|
|
70052
|
+
tail = (tail + text5).slice(-4000);
|
|
70053
|
+
for (const line of text5.split(/[\r\n]+/u).map((part) => part.trim()).filter(Boolean)) {
|
|
70054
|
+
const progress = progressCount(line);
|
|
70055
|
+
if (!progress)
|
|
70056
|
+
continue;
|
|
70057
|
+
lastLine = line;
|
|
70058
|
+
const previous2 = counts2.get(progress.phase);
|
|
70059
|
+
if (!previous2 || progress.count > previous2.count || progress.bytes > previous2.bytes) {
|
|
70060
|
+
counts2.set(progress.phase, { count: Math.max(progress.count, previous2?.count ?? 0), bytes: Math.max(progress.bytes, previous2?.bytes ?? 0) });
|
|
70061
|
+
lastProgress = Date.now();
|
|
70062
|
+
}
|
|
70063
|
+
}
|
|
70064
|
+
});
|
|
70065
|
+
let stopped;
|
|
70066
|
+
const timer = setInterval(() => {
|
|
70067
|
+
const now = Date.now();
|
|
70068
|
+
if (now - started > limitMs)
|
|
70069
|
+
stopped = new GitProgressError(`${options.label} stopped after ${Math.round(limitMs / 60000)} minutes ` + `(still running; last progress: ${redactRemoteCredentials(lastLine) || "none"}). Report this to the user before retrying.`, "too-long");
|
|
70070
|
+
else if (now - lastProgress > idleMs)
|
|
70071
|
+
stopped = new GitProgressError(`${options.label} made no progress for ${Math.round(idleMs / 60000)} minutes ` + `(last progress: ${redactRemoteCredentials(lastLine) || "none"}).`, "no-progress");
|
|
70072
|
+
if (stopped) {
|
|
70073
|
+
child.kill("SIGKILL");
|
|
70074
|
+
return;
|
|
70075
|
+
}
|
|
70076
|
+
if (now - lastReport >= reportMs && lastLine) {
|
|
70077
|
+
lastReport = now;
|
|
70078
|
+
process.stderr.write(`[context] ${options.label}: ${redactRemoteCredentials(lastLine)}
|
|
70079
|
+
`);
|
|
70080
|
+
}
|
|
70081
|
+
}, Math.min(1000, idleMs, limitMs));
|
|
70082
|
+
const code = await new Promise((resolve8, reject) => {
|
|
70083
|
+
child.once("error", reject);
|
|
70084
|
+
child.once("close", resolve8);
|
|
70085
|
+
}).finally(() => clearInterval(timer));
|
|
70086
|
+
if (stopped)
|
|
70087
|
+
throw stopped;
|
|
70088
|
+
if (code !== 0) {
|
|
70089
|
+
const line = tail.split(/[\r\n]+/u).map((part) => part.trim()).find((part) => /^(fatal|error):/iu.test(part)) ?? tail.trim().split(/[\r\n]+/u).pop() ?? "";
|
|
70090
|
+
throw new GitProgressError(`${options.label} failed: ${redactRemoteCredentials(line).slice(0, 300) || `exit ${code}`}`, "failed");
|
|
70091
|
+
}
|
|
70092
|
+
return stdout;
|
|
70093
|
+
}
|
|
70094
|
+
var GitProgressError, UNITS;
|
|
70095
|
+
var init_gitProgress = __esm(() => {
|
|
70096
|
+
GitProgressError = class GitProgressError extends Error {
|
|
70097
|
+
kind;
|
|
70098
|
+
constructor(message, kind) {
|
|
70099
|
+
super(message);
|
|
70100
|
+
this.kind = kind;
|
|
70101
|
+
}
|
|
70102
|
+
};
|
|
70103
|
+
UNITS = { bytes: 1, KiB: 1024, MiB: 1024 ** 2, GiB: 1024 ** 3, TiB: 1024 ** 4 };
|
|
70104
|
+
});
|
|
70105
|
+
|
|
70015
70106
|
// src/project/repoContentGit.ts
|
|
70016
70107
|
import { execFile as execFile2 } from "node:child_process";
|
|
70017
70108
|
import { promisify as promisify2 } from "node:util";
|
|
@@ -70437,7 +70528,7 @@ var init_repoContentEvidence = __esm(() => {
|
|
|
70437
70528
|
});
|
|
70438
70529
|
|
|
70439
70530
|
// src/project/gitObjectReader.ts
|
|
70440
|
-
import { execFile as execFile3, spawn as
|
|
70531
|
+
import { execFile as execFile3, spawn as spawn3 } from "node:child_process";
|
|
70441
70532
|
async function missingReason(root, expression) {
|
|
70442
70533
|
const separator = expression.indexOf(":./");
|
|
70443
70534
|
const commit = expression.slice(0, separator), path2 = expression.slice(separator + 3);
|
|
@@ -70549,7 +70640,7 @@ function createGitObjectReader(options = {}) {
|
|
|
70549
70640
|
progress();
|
|
70550
70641
|
}
|
|
70551
70642
|
function start2() {
|
|
70552
|
-
const process2 =
|
|
70643
|
+
const process2 = spawn3("git", ["-C", root, "cat-file", "--batch", "-z"], { env: { ...globalThis.process.env, GIT_NO_LAZY_FETCH: "1" } });
|
|
70553
70644
|
child = process2;
|
|
70554
70645
|
process2.stdout.on("data", (chunk) => {
|
|
70555
70646
|
if (child === process2)
|
|
@@ -70653,12 +70744,15 @@ function inside(root, path2) {
|
|
|
70653
70744
|
throw new SourceUnavailableError("Article source path escapes its captured scope", "source-path-outside-scope");
|
|
70654
70745
|
}
|
|
70655
70746
|
}
|
|
70656
|
-
function commitAvailability(fetched, fetch = true) {
|
|
70747
|
+
function commitAvailability(fetched, fetch = true, failures) {
|
|
70657
70748
|
return (directory, commit) => {
|
|
70658
70749
|
const key = `${directory}\x00${commit}`;
|
|
70659
70750
|
let result = fetched.get(key);
|
|
70660
70751
|
if (!result) {
|
|
70661
|
-
result = execute("git", ["-C", directory, "cat-file", "-e", `${commit}^{commit}`], { timeout: 5000, env: { ...process.env, GIT_NO_LAZY_FETCH: "1" } }).then(() => true, () => !fetch ? false :
|
|
70752
|
+
result = execute("git", ["-C", directory, "cat-file", "-e", `${commit}^{commit}`], { timeout: 5000, env: { ...process.env, GIT_NO_LAZY_FETCH: "1" } }).then(() => true, () => !fetch ? false : runGitWithProgress(["-C", directory, "fetch", "--depth=1", "origin", commit], { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, label: `git fetch of commit ${commit.slice(0, 12)}` }).then(() => true, (error) => {
|
|
70753
|
+
failures?.set(commit, error instanceof Error ? error.message : String(error));
|
|
70754
|
+
return false;
|
|
70755
|
+
}));
|
|
70662
70756
|
fetched.set(key, result);
|
|
70663
70757
|
}
|
|
70664
70758
|
return result;
|
|
@@ -70670,7 +70764,8 @@ function missingCommit(commit) {
|
|
|
70670
70764
|
async function fetchSourceCommits(projectRoot, requests) {
|
|
70671
70765
|
const workspace = await realpath5(projectRoot);
|
|
70672
70766
|
const registry2 = await loadSourcesRegistry({ rootDir: projectRoot });
|
|
70673
|
-
const
|
|
70767
|
+
const failed = new Map;
|
|
70768
|
+
const available = commitAvailability(new Map, true, failed);
|
|
70674
70769
|
for (const request of requests) {
|
|
70675
70770
|
if (!request.source_ref.startsWith("repo:"))
|
|
70676
70771
|
continue;
|
|
@@ -70685,6 +70780,7 @@ async function fetchSourceCommits(projectRoot, requests) {
|
|
|
70685
70780
|
if (root)
|
|
70686
70781
|
await available(root, commit);
|
|
70687
70782
|
}
|
|
70783
|
+
return failed;
|
|
70688
70784
|
}
|
|
70689
70785
|
async function registeredRepoHistoryReader(projectRoot) {
|
|
70690
70786
|
const workspace = await realpath5(projectRoot);
|
|
@@ -70764,7 +70860,7 @@ async function registeredArticleSourceReader(projectRoot) {
|
|
|
70764
70860
|
const managed = kind === "note" || kind === "sessions";
|
|
70765
70861
|
const root = await realpath5(resolve19(workspace, managed ? dirname12(entry.materializedAt) : entry.materializedAt)).catch((error) => {
|
|
70766
70862
|
if (kind === "repo")
|
|
70767
|
-
throw new SourceReadError(
|
|
70863
|
+
throw new SourceReadError(`The registered source checkout of ${sourceRef} is not accessible. Restore the source before checking citations.`, "context source recovery-plan --format json");
|
|
70768
70864
|
throw error;
|
|
70769
70865
|
});
|
|
70770
70866
|
inside(workspace, root);
|
|
@@ -70813,8 +70909,10 @@ async function registeredArticleSourceReader(projectRoot) {
|
|
|
70813
70909
|
pending = (async () => {
|
|
70814
70910
|
try {
|
|
70815
70911
|
const { root, files, commit } = await scope2(sourceRef);
|
|
70816
|
-
if (files && !files.has(path2))
|
|
70817
|
-
|
|
70912
|
+
if (files && !files.has(path2)) {
|
|
70913
|
+
const owned = [...files.keys()];
|
|
70914
|
+
throw new SourceUnavailableError(`Source path ${path2} is not owned by the registered document ${sourceRef}; cite one of its files: ` + `${owned.slice(0, 10).join(", ")}${owned.length > 10 ? `, and ${owned.length - 10} more` : ""}.`, "source-path-unregistered");
|
|
70915
|
+
}
|
|
70818
70916
|
const lexical = resolve19(root, path2);
|
|
70819
70917
|
inside(root, lexical);
|
|
70820
70918
|
let bytes;
|
|
@@ -70855,6 +70953,7 @@ async function registeredArticleSourceReader(projectRoot) {
|
|
|
70855
70953
|
}
|
|
70856
70954
|
var execute;
|
|
70857
70955
|
var init_articleSourceReader = __esm(() => {
|
|
70956
|
+
init_gitProgress();
|
|
70858
70957
|
init_src2();
|
|
70859
70958
|
init_documentBatchManifest();
|
|
70860
70959
|
init_repoContentEvidence();
|
|
@@ -77056,12 +77155,13 @@ function formatPackageBuildSummary(pkg) {
|
|
|
77056
77155
|
...formatPackageChangeLines("removed", pkg.changes.removed)
|
|
77057
77156
|
];
|
|
77058
77157
|
}
|
|
77059
|
-
function formatProjectBuildResult(result, format2 = "text", verbose = false) {
|
|
77158
|
+
function formatProjectBuildResult(result, format2 = "text", verbose = false, extra = {}) {
|
|
77060
77159
|
if (format2 === "json") {
|
|
77061
77160
|
if (verbose)
|
|
77062
|
-
return `${JSON.stringify(result, null, 2)}
|
|
77161
|
+
return `${JSON.stringify({ ...result, ...extra }, null, 2)}
|
|
77063
77162
|
`;
|
|
77064
77163
|
return `${JSON.stringify({
|
|
77164
|
+
...extra,
|
|
77065
77165
|
agent_hints: result.agent_hints,
|
|
77066
77166
|
packages: result.packages.map((pkg) => ({
|
|
77067
77167
|
name: pkg.name,
|
|
@@ -78131,8 +78231,9 @@ import { execFile as execFile5 } from "node:child_process";
|
|
|
78131
78231
|
import { promisify as promisify4 } from "node:util";
|
|
78132
78232
|
import { mkdir as mkdir13, mkdtemp as mkdtemp2, rm as rm7, writeFile as writeFile8 } from "node:fs/promises";
|
|
78133
78233
|
import { join as join21 } from "node:path";
|
|
78134
|
-
|
|
78135
|
-
|
|
78234
|
+
import { tmpdir } from "node:os";
|
|
78235
|
+
async function hunks(_root, before, after) {
|
|
78236
|
+
const parent = join21(tmpdir(), "context-reference-diff");
|
|
78136
78237
|
await mkdir13(parent, { recursive: true });
|
|
78137
78238
|
const directory = await mkdtemp2(join21(parent, "compare-"));
|
|
78138
78239
|
try {
|
|
@@ -78315,9 +78416,9 @@ async function collectReferenceEvidence(root, references, previous2 = [], cited
|
|
|
78315
78416
|
}));
|
|
78316
78417
|
}
|
|
78317
78418
|
function articleReferenceHistoryReader(root, previous2 = []) {
|
|
78318
|
-
|
|
78419
|
+
let repoHistory;
|
|
78319
78420
|
const objects = commandGitObjectReader();
|
|
78320
|
-
|
|
78421
|
+
let registry2;
|
|
78321
78422
|
const logs = new Map;
|
|
78322
78423
|
function verified(reference2, text5, commit) {
|
|
78323
78424
|
try {
|
|
@@ -78332,7 +78433,7 @@ function articleReferenceHistoryReader(root, previous2 = []) {
|
|
|
78332
78433
|
if (reference2.source_ref.startsWith("repo:")) {
|
|
78333
78434
|
for (const scope2 of versions) {
|
|
78334
78435
|
try {
|
|
78335
|
-
const text5 = await (await repoHistory)(reference2.source_ref, reference2.locator.path, scope2.processed_version);
|
|
78436
|
+
const text5 = await (await (repoHistory ??= registeredRepoHistoryReader(root)))(reference2.source_ref, reference2.locator.path, scope2.processed_version);
|
|
78336
78437
|
const result = verified(reference2, text5, scope2.processed_version);
|
|
78337
78438
|
if (result)
|
|
78338
78439
|
return result;
|
|
@@ -78341,7 +78442,7 @@ function articleReferenceHistoryReader(root, previous2 = []) {
|
|
|
78341
78442
|
return baseline === undefined ? undefined : { region: baseline };
|
|
78342
78443
|
}
|
|
78343
78444
|
const [kind, name2] = reference2.source_ref.split(":", 2);
|
|
78344
|
-
const sources = await registry2;
|
|
78445
|
+
const sources = await (registry2 ??= loadSourcesRegistry({ rootDir: root }));
|
|
78345
78446
|
const entries = kind === "lark" ? sources.larks : kind === "file" ? sources.files : kind === "note" ? sources.notes : kind === "sessions" ? sources.sessions : [];
|
|
78346
78447
|
const entry = entries.find((candidate) => candidate.id === name2 || candidate.name === name2);
|
|
78347
78448
|
if (!entry)
|
|
@@ -78367,7 +78468,7 @@ function articleReferenceHistoryReader(root, previous2 = []) {
|
|
|
78367
78468
|
return baseline === undefined ? undefined : { region: baseline };
|
|
78368
78469
|
};
|
|
78369
78470
|
}
|
|
78370
|
-
var hashRegion = (text5) => `sha256:${createHash13("sha256").update(text5, "utf8").digest("hex")}`, referenceEvidenceKey = (reference2) => indexerProtocolDigest(reference2), exec3;
|
|
78471
|
+
var LOCAL_SOURCE_REASONS, hashRegion = (text5) => `sha256:${createHash13("sha256").update(text5, "utf8").digest("hex")}`, referenceEvidenceKey = (reference2) => indexerProtocolDigest(reference2), exec3;
|
|
78371
78472
|
var init_articleReferenceObservation = __esm(() => {
|
|
78372
78473
|
init_src2();
|
|
78373
78474
|
init_articleRegionBaselines();
|
|
@@ -78375,6 +78476,10 @@ var init_articleReferenceObservation = __esm(() => {
|
|
|
78375
78476
|
init_articleSourceReader();
|
|
78376
78477
|
init_gitObjectReader();
|
|
78377
78478
|
init_referenceRangeMap();
|
|
78479
|
+
LOCAL_SOURCE_REASONS = {
|
|
78480
|
+
"source-content-missing": "The cited file contents are not downloaded in the source checkout.",
|
|
78481
|
+
"source-history-missing": "The registered commit is not in the source checkout."
|
|
78482
|
+
};
|
|
78378
78483
|
exec3 = promisify5(execFile6);
|
|
78379
78484
|
});
|
|
78380
78485
|
|
|
@@ -80419,6 +80524,7 @@ var init_productionArticleTarget = __esm(() => {
|
|
|
80419
80524
|
var exports_productionFeedback = {};
|
|
80420
80525
|
__export(exports_productionFeedback, {
|
|
80421
80526
|
withProductionFeedback: () => withProductionFeedback,
|
|
80527
|
+
SubmissionInputErrors: () => SubmissionInputErrors,
|
|
80422
80528
|
SubmissionInputError: () => SubmissionInputError
|
|
80423
80529
|
});
|
|
80424
80530
|
async function withProductionFeedback(input, run) {
|
|
@@ -80447,7 +80553,7 @@ async function withProductionFeedback(input, run) {
|
|
|
80447
80553
|
throw new ContextError(existing?.code ?? (schemaError2 || syntaxError || inputError ? ExitCode.UserError : ExitCode.WorkspaceStateError), error instanceof Error ? error.message : String(error), detail);
|
|
80448
80554
|
}
|
|
80449
80555
|
}
|
|
80450
|
-
var import_yaml19, SubmissionInputError;
|
|
80556
|
+
var import_yaml19, SubmissionInputError, SubmissionInputErrors;
|
|
80451
80557
|
var init_productionFeedback = __esm(() => {
|
|
80452
80558
|
init_zod();
|
|
80453
80559
|
init_esm();
|
|
@@ -80464,6 +80570,13 @@ var init_productionFeedback = __esm(() => {
|
|
|
80464
80570
|
this.reason = reason;
|
|
80465
80571
|
}
|
|
80466
80572
|
};
|
|
80573
|
+
SubmissionInputErrors = class SubmissionInputErrors extends SubmissionInputError {
|
|
80574
|
+
errors;
|
|
80575
|
+
constructor(errors4) {
|
|
80576
|
+
super(`${errors4.length} problems: ${errors4.map((error, index2) => `(${index2 + 1}) ${error.message}`).join(" ")}`, errors4[0]?.path ?? [], errors4[0]?.reason);
|
|
80577
|
+
this.errors = errors4;
|
|
80578
|
+
}
|
|
80579
|
+
};
|
|
80467
80580
|
});
|
|
80468
80581
|
|
|
80469
80582
|
// src/project/productionStage.ts
|
|
@@ -81035,6 +81148,27 @@ import { execFile as execFile8 } from "node:child_process";
|
|
|
81035
81148
|
import { promisify as promisify7 } from "node:util";
|
|
81036
81149
|
import { readFile as readFile30 } from "node:fs/promises";
|
|
81037
81150
|
import { basename as basename5, join as join35 } from "node:path";
|
|
81151
|
+
async function checkoutMatchesCommit(root, ref2, files) {
|
|
81152
|
+
const timeout = 30000 + files * 2;
|
|
81153
|
+
let reason = "";
|
|
81154
|
+
for (let attempt = 0;attempt < 2; attempt++) {
|
|
81155
|
+
try {
|
|
81156
|
+
await execute2("git", ["-C", root, "diff", "--quiet", ref2, "--", "."], {
|
|
81157
|
+
timeout,
|
|
81158
|
+
maxBuffer: 64 * 1024,
|
|
81159
|
+
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" }
|
|
81160
|
+
});
|
|
81161
|
+
return { state: "same" };
|
|
81162
|
+
} catch (error) {
|
|
81163
|
+
const failure = error;
|
|
81164
|
+
if (failure.code === 1)
|
|
81165
|
+
return { state: "differs" };
|
|
81166
|
+
reason = failure.killed ? `timed out after ${Math.round(timeout / 1000)} s` : String(failure.stderr ?? (error instanceof Error ? error.message : error)).trim().split(`
|
|
81167
|
+
`)[0].slice(0, 200);
|
|
81168
|
+
}
|
|
81169
|
+
}
|
|
81170
|
+
return { state: "unchecked", reason };
|
|
81171
|
+
}
|
|
81038
81172
|
function productionDocumentSkeleton(path2, markdown) {
|
|
81039
81173
|
const lines = markdown.split(/\r?\n/u);
|
|
81040
81174
|
let title;
|
|
@@ -81146,10 +81280,6 @@ This entire source is explicitly excluded from every selected requirement; no in
|
|
|
81146
81280
|
const repo = registry2.repos.find((repo2) => repo2.id === name3 || repo2.name === name3);
|
|
81147
81281
|
if (!/^[a-f0-9]{40}(?:[a-f0-9]{24})?$/u.test(repo.ref))
|
|
81148
81282
|
throw new TypeError("Planning requires a captured fixed commit, not a moving ref");
|
|
81149
|
-
await execute2("git", ["-C", root, "diff", "--quiet", repo.ref, "--", "."], {
|
|
81150
|
-
timeout: 5000,
|
|
81151
|
-
maxBuffer: 64 * 1024
|
|
81152
|
-
});
|
|
81153
81283
|
const targets = input.requirements.requirements.flatMap((item) => [
|
|
81154
81284
|
...item.target_scope.targets,
|
|
81155
81285
|
...item.evidence_source_scope?.targets ?? []
|
|
@@ -81157,10 +81287,14 @@ This entire source is explicitly excluded from every selected requirement; no in
|
|
|
81157
81287
|
const modules = [...new Set(targets.flatMap((target) => target.module_refs ?? []))];
|
|
81158
81288
|
const result = await execute2("git", ["-C", root, "ls-tree", "-r", "--name-only", "-z", repo.ref], {
|
|
81159
81289
|
encoding: "utf8",
|
|
81160
|
-
timeout:
|
|
81161
|
-
maxBuffer:
|
|
81290
|
+
timeout: 60000,
|
|
81291
|
+
maxBuffer: 64 * 1024 * 1024
|
|
81162
81292
|
});
|
|
81163
|
-
const
|
|
81293
|
+
const tracked = result.stdout.split("\x00").filter(Boolean);
|
|
81294
|
+
const checkout = await checkoutMatchesCommit(root, repo.ref, tracked.length);
|
|
81295
|
+
if (checkout.state === "differs")
|
|
81296
|
+
throw new TypeError(`The checkout differs from the registered commit ${repo.ref}; restore it (context source recovery-plan --format json) before planning`);
|
|
81297
|
+
const files = tracked.filter((path2) => !sourceExcludes(input.requirements, scope2, path2));
|
|
81164
81298
|
const directories = new Map;
|
|
81165
81299
|
for (const file of files) {
|
|
81166
81300
|
const directory = file.includes("/") ? file.split("/")[0] : "(root)";
|
|
@@ -81174,6 +81308,7 @@ This entire source is explicitly excluded from every selected requirement; no in
|
|
|
81174
81308
|
...modules.length ? [`Module focus: ${modules.join(", ")}`] : [],
|
|
81175
81309
|
"Choose relevant directories while investigating. Module names are work guidance, not inferred path permissions; put useful reading scope in the task brief without a separate mapping or receipt.",
|
|
81176
81310
|
`Complete authorized tracked-file count: ${files.length}`,
|
|
81311
|
+
...checkout.state === "unchecked" ? [`Checkout check did not complete (${checkout.reason}); the skeleton is read from the registered commit. Read source files through the commit, not the working tree.`] : [],
|
|
81177
81312
|
"",
|
|
81178
81313
|
"## Directory skeleton",
|
|
81179
81314
|
"",
|
|
@@ -81242,6 +81377,15 @@ var init_productionPlanningMaterials = __esm(() => {
|
|
|
81242
81377
|
});
|
|
81243
81378
|
|
|
81244
81379
|
// src/project/submittedSourceLocator.ts
|
|
81380
|
+
function assertNoCaptureGap(locator, capturedText) {
|
|
81381
|
+
const lines = capturedText.replace(/\r\n/gu, `
|
|
81382
|
+
`).split(`
|
|
81383
|
+
`).slice(locator.start_line - 1, locator.end_line);
|
|
81384
|
+
const gapOnly = (line) => CAPTURE_GAP.test(line) && line.replace(new RegExp(CAPTURE_GAP.source, "gu"), "").replace(/<br\s*\/?>|[|>\s]/giu, "") === "";
|
|
81385
|
+
const gap = lines.findIndex(gapOnly);
|
|
81386
|
+
if (gap >= 0)
|
|
81387
|
+
throw new SubmissionInputError(`${locator.path}:${locator.start_line + gap} is a capture gap (the resource was not captured), ` + "not evidence. Cite only captured lines; the missing content cannot support a claim until it is captured.");
|
|
81388
|
+
}
|
|
81245
81389
|
function resolveSubmittedSourceLocator(input, capturedText) {
|
|
81246
81390
|
const locator = submittedSourceLocatorSchema.parse(input);
|
|
81247
81391
|
if ("start_line" in locator)
|
|
@@ -81297,11 +81441,208 @@ function resolveSubmittedSourceLocator(input, capturedText) {
|
|
|
81297
81441
|
throw new SubmissionInputError(`Source locator matched ${matches.length} regions in ${locator.path}; candidates: ${matches.slice(0, 5).map((m) => `${m.start_line}-${m.end_line}`).join(", ") || "none"}. Use a unique heading/quote or explicit start_line/end_line.`);
|
|
81298
81442
|
return articleSourceLocatorSchema.parse({ path: locator.path, ...matches[0] });
|
|
81299
81443
|
}
|
|
81300
|
-
var submittedSourceLocatorSchema;
|
|
81444
|
+
var submittedSourceLocatorSchema, CAPTURE_GAP;
|
|
81301
81445
|
var init_submittedSourceLocator = __esm(() => {
|
|
81302
81446
|
init_src2();
|
|
81303
81447
|
init_productionFeedback();
|
|
81304
81448
|
submittedSourceLocatorSchema = articleSourceLocatorInputSchema;
|
|
81449
|
+
CAPTURE_GAP = /(?:> ?)?Resource unavailable: .+? \([^;()]+; [^()]+\)\. <!-- [^>]+ -->/u;
|
|
81450
|
+
});
|
|
81451
|
+
|
|
81452
|
+
// src/project/approvedRevisionReferences.ts
|
|
81453
|
+
async function resolveSubmittedReference(context, id3, at2, reference2) {
|
|
81454
|
+
if (!context.inScope(reference2.source_ref))
|
|
81455
|
+
throw new SubmissionInputError(`Fragment ${id3} cites ${reference2.source_ref}, which is outside this revision; allowed sources: ${context.sourceRefs.join(", ")}. ` + "To cite new independent evidence, register it as a source, associate it with the selected requirement in src/indexers.yaml, then run context task adjust for this revision.", [...at2, "source_ref"], "source-outside-revision");
|
|
81456
|
+
const submitted = reference2.locator;
|
|
81457
|
+
const previous2 = context.previous.find((section) => section.id === id3)?.references ?? [];
|
|
81458
|
+
const kept = "start_line" in submitted ? previous2.find((old) => old.source_ref === reference2.source_ref && old.locator.path === submitted.path && old.locator.start_line === submitted.start_line && old.locator.end_line === submitted.end_line) : undefined;
|
|
81459
|
+
if (kept) {
|
|
81460
|
+
const observed = await relocateUnchangedReference(context.projectRoot, context.readSource, kept);
|
|
81461
|
+
if (observed.state === "current" || observed.state === "moved")
|
|
81462
|
+
return observed.reference;
|
|
81463
|
+
throw new SubmissionInputError(`Fragment ${id3}: ${reference2.source_ref} ${kept.locator.path}:${kept.locator.start_line}-${kept.locator.end_line} ` + `repeats an earlier citation, so it keeps that evidence, which is ${observed.state} in the current source. ` + "To keep the earlier evidence, cite its current position. To cite the text now at these lines (it may be the correct new content), use a quote or heading locator.", [...at2, "locator"], "kept-reference-unresolved");
|
|
81464
|
+
}
|
|
81465
|
+
const text5 = await context.readSource(reference2.source_ref, reference2.locator.path, true);
|
|
81466
|
+
let locator;
|
|
81467
|
+
try {
|
|
81468
|
+
locator = resolveSubmittedSourceLocator(reference2.locator, text5);
|
|
81469
|
+
assertNoCaptureGap(locator, text5);
|
|
81470
|
+
} catch (error) {
|
|
81471
|
+
if (error instanceof SubmissionInputError)
|
|
81472
|
+
throw new SubmissionInputError(`Fragment ${id3}: ${error.message}`, [...at2, "locator"]);
|
|
81473
|
+
throw error;
|
|
81474
|
+
}
|
|
81475
|
+
let resolved;
|
|
81476
|
+
try {
|
|
81477
|
+
resolved = createArticleSourceReference(reference2.source_ref, locator, text5);
|
|
81478
|
+
} catch (error) {
|
|
81479
|
+
if (!(error instanceof RangeError))
|
|
81480
|
+
throw error;
|
|
81481
|
+
throw new SubmissionInputError(`Fragment ${id3}: ${reference2.source_ref} ${locator.path}:${locator.start_line}-${locator.end_line} ` + `is outside the file, which has ${text5.replace(/\r\n/gu, `
|
|
81482
|
+
`).split(`
|
|
81483
|
+
`).length} lines. Cite existing lines, or use a quote or heading locator.`, [...at2, "locator"], "locator-out-of-range");
|
|
81484
|
+
}
|
|
81485
|
+
if (context.remember)
|
|
81486
|
+
rememberArticleRegion(context.projectRoot, resolved, text5);
|
|
81487
|
+
return resolved;
|
|
81488
|
+
}
|
|
81489
|
+
async function prepareRevisionReferences(input) {
|
|
81490
|
+
const edits = new Map(input.edits?.map((edit) => [edit.section_id, edit]));
|
|
81491
|
+
if (edits.size !== (input.edits?.length ?? 0))
|
|
81492
|
+
throw new TypeError("Repeated revision fragment identity");
|
|
81493
|
+
for (const id3 of edits.keys())
|
|
81494
|
+
if (!input.sectionIds.includes(id3)) {
|
|
81495
|
+
throw new TypeError(`Reference edit targets a missing fragment: ${id3}`);
|
|
81496
|
+
}
|
|
81497
|
+
let read;
|
|
81498
|
+
const inScope = (source2) => input.sourceRefs.some((scope2) => repoContentScopeMatches(scope2, source2));
|
|
81499
|
+
const context = {
|
|
81500
|
+
projectRoot: input.projectRoot,
|
|
81501
|
+
remember: input.remember !== false,
|
|
81502
|
+
previous: input.previous,
|
|
81503
|
+
sourceRefs: input.sourceRefs,
|
|
81504
|
+
inScope,
|
|
81505
|
+
readSource: Object.assign(async (source2, path2) => {
|
|
81506
|
+
if (!inScope(source2))
|
|
81507
|
+
throw new TypeError(`Source is outside this revision: ${source2}`);
|
|
81508
|
+
read ??= await registeredArticleSourceReader(input.projectRoot);
|
|
81509
|
+
return read(source2, path2, true);
|
|
81510
|
+
}, { incomplete: async (source2) => {
|
|
81511
|
+
read ??= await registeredArticleSourceReader(input.projectRoot);
|
|
81512
|
+
return await read.incomplete?.(source2) ?? false;
|
|
81513
|
+
} })
|
|
81514
|
+
};
|
|
81515
|
+
const result = [];
|
|
81516
|
+
const problems = [];
|
|
81517
|
+
for (const id3 of input.sectionIds) {
|
|
81518
|
+
const edit = edits.get(id3);
|
|
81519
|
+
if (edit?.references !== undefined) {
|
|
81520
|
+
const at2 = ["sections", input.edits.indexOf(edit), "references"];
|
|
81521
|
+
const references2 = [];
|
|
81522
|
+
for (const [index2, reference2] of edit.references.entries()) {
|
|
81523
|
+
try {
|
|
81524
|
+
references2.push(await resolveSubmittedReference(context, id3, [...at2, index2], reference2));
|
|
81525
|
+
} catch (error) {
|
|
81526
|
+
if (error instanceof SourceReadError || error instanceof SourceUnavailableError) {
|
|
81527
|
+
problems.push(new SubmissionInputError(`Fragment ${id3}: ${reference2.source_ref} ${reference2.locator.path}: ${error.message}`, [...at2, index2, "source_ref"], String(error.detail?.reason_code ?? "source-unavailable")));
|
|
81528
|
+
} else if (error instanceof SubmissionInputError)
|
|
81529
|
+
problems.push(error);
|
|
81530
|
+
else
|
|
81531
|
+
throw error;
|
|
81532
|
+
}
|
|
81533
|
+
}
|
|
81534
|
+
try {
|
|
81535
|
+
result.push({ id: id3, references: articleFragmentReferences(references2) });
|
|
81536
|
+
} catch (error) {
|
|
81537
|
+
if (error instanceof ZodError)
|
|
81538
|
+
problems.push(new SubmissionInputError(`Fragment ${id3}: ${error.issues.map((issue) => issue.message).join("; ")}`, at2));
|
|
81539
|
+
else
|
|
81540
|
+
throw error;
|
|
81541
|
+
}
|
|
81542
|
+
continue;
|
|
81543
|
+
}
|
|
81544
|
+
const references = [];
|
|
81545
|
+
const retained = input.previous.find((section) => section.id === id3)?.references ?? [];
|
|
81546
|
+
for (const [index2, reference2] of retained.entries()) {
|
|
81547
|
+
references.push(await retainReference(input, context, id3, ["fragments", id3, "references", index2], reference2, problems));
|
|
81548
|
+
}
|
|
81549
|
+
result.push({ id: id3, references });
|
|
81550
|
+
}
|
|
81551
|
+
if (problems.length === 1)
|
|
81552
|
+
throw problems[0];
|
|
81553
|
+
if (problems.length)
|
|
81554
|
+
throw new SubmissionInputErrors(problems);
|
|
81555
|
+
return result;
|
|
81556
|
+
}
|
|
81557
|
+
async function retainReference(input, context, id3, at2, reference2, problems) {
|
|
81558
|
+
const changed = input.changedBodies?.has(id3) === true;
|
|
81559
|
+
const where = `${reference2.source_ref} ${reference2.locator.path}:${reference2.locator.start_line}-${reference2.locator.end_line}`;
|
|
81560
|
+
let observed;
|
|
81561
|
+
try {
|
|
81562
|
+
observed = await relocateUnchangedReference(context.projectRoot, context.readSource, reference2);
|
|
81563
|
+
} catch (error) {
|
|
81564
|
+
if (!(error instanceof SourceReadError))
|
|
81565
|
+
throw error;
|
|
81566
|
+
if (changed)
|
|
81567
|
+
problems.push(new SubmissionInputError(`Fragment ${id3}: the text changed, but ${where} cannot be checked: ${error.message}`, at2, "reference-unverifiable"));
|
|
81568
|
+
return reference2;
|
|
81569
|
+
}
|
|
81570
|
+
if (observed.state === "current" || observed.state === "moved")
|
|
81571
|
+
return observed.reference;
|
|
81572
|
+
if (observed.state === "unavailable" && (observed.reason ?? "") in LOCAL_SOURCE_REASONS) {
|
|
81573
|
+
if (changed)
|
|
81574
|
+
problems.push(new SubmissionInputError(`Fragment ${id3}: the text changed, but ${where} cannot be checked on this machine (${observed.reason}). Make the source available, then submit again.`, at2, "reference-unverifiable"));
|
|
81575
|
+
return reference2;
|
|
81576
|
+
}
|
|
81577
|
+
if (citesScope(input.processedScopes ?? [], reference2.source_ref)) {
|
|
81578
|
+
const hint = await input.suggest?.(reference2).catch(() => {
|
|
81579
|
+
return;
|
|
81580
|
+
});
|
|
81581
|
+
problems.push(new SubmissionInputError(`Fragment ${id3}: ${where} is ${observed.state}${observed.reason ? ` (${observed.reason})` : ""} in the source version this revision processes. ` + `Rewrite the paragraph, cite its current text${hint ? ` (${hint})` : ""}, or remove the citation.`, at2, "processed-reference-stale"));
|
|
81582
|
+
return reference2;
|
|
81583
|
+
}
|
|
81584
|
+
input.onReminder?.({
|
|
81585
|
+
section_id: id3,
|
|
81586
|
+
state: observed.state,
|
|
81587
|
+
...observed.reason ? { reason: observed.reason } : {},
|
|
81588
|
+
source_ref: reference2.source_ref,
|
|
81589
|
+
locator: reference2.locator
|
|
81590
|
+
});
|
|
81591
|
+
return reference2;
|
|
81592
|
+
}
|
|
81593
|
+
async function suggestedCitation(projectRoot, reference2, sections) {
|
|
81594
|
+
const history = await articleReferenceHistoryReader(projectRoot, readProcessedScopes((await readKnowledgeStructure(projectRoot)).parsed))(reference2);
|
|
81595
|
+
if (!history?.text)
|
|
81596
|
+
return;
|
|
81597
|
+
const current3 = await (await registeredArticleSourceReader(projectRoot))(reference2.source_ref, reference2.locator.path, true);
|
|
81598
|
+
const cited = sections.flatMap((section) => section.references.map((item) => ({
|
|
81599
|
+
source_ref: item.source_ref,
|
|
81600
|
+
path: item.locator.path,
|
|
81601
|
+
start_line: item.locator.start_line,
|
|
81602
|
+
end_line: item.locator.end_line
|
|
81603
|
+
})));
|
|
81604
|
+
const suggested = await suggestedRange(projectRoot, reference2, history.text, current3, cited);
|
|
81605
|
+
if (!suggested)
|
|
81606
|
+
return;
|
|
81607
|
+
return "quote" in suggested.locator ? `the old text now maps to lines ${suggested.start_line}-${suggested.end_line}; cite them with a quote locator` : `the old text now maps to lines ${suggested.start_line}-${suggested.end_line}`;
|
|
81608
|
+
}
|
|
81609
|
+
function removedCitations(previous2, next) {
|
|
81610
|
+
const removed = [];
|
|
81611
|
+
for (const section of previous2) {
|
|
81612
|
+
const current3 = next.find((item) => item.id === section.id)?.references ?? [];
|
|
81613
|
+
for (const reference2 of section.references) {
|
|
81614
|
+
const kept = current3.some((item) => item.source_ref === reference2.source_ref && item.locator.path === reference2.locator.path && item.content_digest === reference2.content_digest);
|
|
81615
|
+
if (!kept)
|
|
81616
|
+
removed.push({
|
|
81617
|
+
section_id: section.id,
|
|
81618
|
+
source_ref: reference2.source_ref,
|
|
81619
|
+
path: reference2.locator.path,
|
|
81620
|
+
start_line: reference2.locator.start_line,
|
|
81621
|
+
end_line: reference2.locator.end_line
|
|
81622
|
+
});
|
|
81623
|
+
}
|
|
81624
|
+
}
|
|
81625
|
+
return removed;
|
|
81626
|
+
}
|
|
81627
|
+
function citationNotes(removed, reminders) {
|
|
81628
|
+
return {
|
|
81629
|
+
...removed.length ? { removed_citations: [...removed], removed_citations_note: REMOVED_CITATIONS_NOTE } : {},
|
|
81630
|
+
...reminders.length ? { reference_warnings: [...reminders], reference_warning_instruction: REFERENCE_REMINDER_NOTE } : {}
|
|
81631
|
+
};
|
|
81632
|
+
}
|
|
81633
|
+
var citesScope = (scopes, ref2) => scopes.some((scope2) => repoContentScopeMatches(scope2, ref2) || ref2.startsWith(`${scope2}#`) || ref2.startsWith(`${scope2}/`)), REFERENCE_REMINDER_NOTE = "These paragraphs keep citations their sources no longer confirm. The sources are outside what this revision processes, so the citations were kept; check them in a source update or a separate revision.", REMOVED_CITATIONS_NOTE = "These earlier citations are no longer in their sections. If you meant to replace or remove them, nothing needs doing; otherwise repeat each with its earlier lines to keep that evidence.";
|
|
81634
|
+
var init_approvedRevisionReferences = __esm(() => {
|
|
81635
|
+
init_zod();
|
|
81636
|
+
init_submittedSourceLocator();
|
|
81637
|
+
init_productionFeedback();
|
|
81638
|
+
init_src2();
|
|
81639
|
+
init_articleRegionBaselines();
|
|
81640
|
+
init_settledReferenceRelocation();
|
|
81641
|
+
init_articleSourceReader();
|
|
81642
|
+
init_gitObjectReader();
|
|
81643
|
+
init_articleReferenceObservation();
|
|
81644
|
+
init_packageBuildInventory();
|
|
81645
|
+
init_src2();
|
|
81305
81646
|
});
|
|
81306
81647
|
|
|
81307
81648
|
// src/project/productionArticleEdits.ts
|
|
@@ -81470,6 +81811,19 @@ function articleError(task, file, message, section) {
|
|
|
81470
81811
|
next: "Fix this task's indicated file or fragment, then resubmit only failed tasks using the existing input handles."
|
|
81471
81812
|
});
|
|
81472
81813
|
}
|
|
81814
|
+
function earlierCitation(base, retained, fragment2, ref2) {
|
|
81815
|
+
if (!("start_line" in ref2.locator))
|
|
81816
|
+
return;
|
|
81817
|
+
const signed = (value) => !!value.content_digest && ("start_line" in value.locator);
|
|
81818
|
+
const same = (value) => value.source_ref === ref2.source_ref && value.locator.path === ref2.locator.path && value.locator.start_line === ref2.locator.start_line && value.locator.end_line === ref2.locator.end_line;
|
|
81819
|
+
const from = (references) => references?.filter(signed).find(same);
|
|
81820
|
+
return from(base?.sections.find((section) => section.id === fragment2)?.references) ?? from(retained?.get(fragment2));
|
|
81821
|
+
}
|
|
81822
|
+
function outsideSourceMessage(task, source2, authorization) {
|
|
81823
|
+
const owners = authorization?.requirements.length ? `requirement ${authorization.requirements.join(", ")}` : "the requirement that owns this article";
|
|
81824
|
+
const replaced = [task.id, ...authorization?.dependents ?? []];
|
|
81825
|
+
return `Source is outside this task's authorized inputs: ${source2}. Cite only ${task.sources.map((item) => item.scope).join(", ")}, ` + `or authorize it: add ${source2} to evidence_source_scope of ${owners} in src/indexers.yaml, then submit a plan amendment ` + `whose replaces lists ${replaced.join(", ")}${replaced.length > 1 ? " (this task and the tasks that depend on it)" : ""} with a new task that includes the source.`;
|
|
81826
|
+
}
|
|
81473
81827
|
async function prepareProductionArticle(input) {
|
|
81474
81828
|
const { task } = input;
|
|
81475
81829
|
let files = input.files;
|
|
@@ -81546,33 +81900,50 @@ async function prepareProductionArticle(input) {
|
|
|
81546
81900
|
if (oversized.length)
|
|
81547
81901
|
throw articleError(task, files.references.path, `Split the claims or choose sufficient references for these fragments: ${oversized.join("; ")}.`);
|
|
81548
81902
|
const read = input.sourceReader ?? await registeredArticleSourceReader(input.projectRoot);
|
|
81903
|
+
const observe = createArticleReferenceObserver(read);
|
|
81549
81904
|
const allowed = new Set(task.sources.map((source2) => source2.scope));
|
|
81905
|
+
const problems = [];
|
|
81550
81906
|
const sections = [];
|
|
81551
81907
|
for (const fragment2 of fragments) {
|
|
81552
81908
|
const references = [];
|
|
81553
81909
|
for (const ref2 of byId.get(fragment2.id)) {
|
|
81554
81910
|
try {
|
|
81911
|
+
const earlier = earlierCitation(input.trustedBase ?? input.base, retained, fragment2.id, ref2);
|
|
81555
81912
|
const inherited = retained?.get(fragment2.id)?.some((value) => value.source_ref === ref2.source_ref && indexerProtocolDigest(value.locator) === indexerProtocolDigest(ref2.locator));
|
|
81556
|
-
const trusted = inherited
|
|
81557
|
-
if (!trusted
|
|
81558
|
-
throw new TypeError(
|
|
81559
|
-
|
|
81560
|
-
|
|
81561
|
-
|
|
81562
|
-
|
|
81563
|
-
|
|
81913
|
+
const trusted = inherited && earlier && input.trustedBase?.sections.find((section) => section.id === fragment2.id)?.references.some((value) => value.content_digest === earlier.content_digest);
|
|
81914
|
+
if (!trusted && ![...allowed].some((scope2) => repoContentScopeMatches(scope2, ref2.source_ref)))
|
|
81915
|
+
throw new TypeError(outsideSourceMessage(task, ref2.source_ref, await input.authorization?.()));
|
|
81916
|
+
if (earlier) {
|
|
81917
|
+
const observed = await observe(earlier);
|
|
81918
|
+
if (observed.state === "current" || observed.state === "moved") {
|
|
81919
|
+
references.push(observed.reference);
|
|
81920
|
+
continue;
|
|
81921
|
+
}
|
|
81922
|
+
const hint = observed.state === "not-found" ? await suggestedCitation(input.projectRoot, earlier, signedSections(input.trustedBase)).catch(() => {
|
|
81923
|
+
return;
|
|
81924
|
+
}) : undefined;
|
|
81925
|
+
throw new TypeError(`${earlier.source_ref} ${earlier.locator.path}:${earlier.locator.start_line}-${earlier.locator.end_line} repeats an earlier citation, ` + `which is ${observed.state}${observed.reason ? ` (${observed.reason})` : ""} in the current source. ` + `Rewrite the fragment, cite its current text${hint ? ` (${hint})` : ""} with a quote or new lines, or remove the citation.`);
|
|
81564
81926
|
}
|
|
81565
|
-
|
|
81927
|
+
const text5 = await read(ref2.source_ref, ref2.locator.path, true);
|
|
81928
|
+
const locator = resolveSubmittedSourceLocator(ref2.locator, text5);
|
|
81929
|
+
assertNoCaptureGap(locator, text5);
|
|
81930
|
+
const reference2 = createArticleSourceReference(ref2.source_ref, locator, text5);
|
|
81931
|
+
if (!input.preview)
|
|
81932
|
+
rememberArticleRegion(input.projectRoot, reference2, text5);
|
|
81566
81933
|
references.push(reference2);
|
|
81567
81934
|
} catch (error) {
|
|
81568
|
-
|
|
81935
|
+
if (error instanceof ContextError && error.detail?.reason_code !== "source-read-failed" && !(error instanceof SourceUnavailableError))
|
|
81936
|
+
throw error;
|
|
81937
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
81938
|
+
problems.push({ section: fragment2.id, message: error instanceof RangeError && "start_line" in ref2.locator ? `${ref2.source_ref} ${ref2.locator.path}:${ref2.locator.start_line}-${ref2.locator.end_line}: ${message}` : message });
|
|
81569
81939
|
}
|
|
81570
81940
|
}
|
|
81571
81941
|
let unique;
|
|
81572
81942
|
try {
|
|
81573
81943
|
unique = articleFragmentReferences(references);
|
|
81574
81944
|
} catch (error) {
|
|
81575
|
-
|
|
81945
|
+
problems.push({ section: fragment2.id, message: error instanceof ZodError ? error.issues.map((issue) => issue.message).join("; ") : error instanceof Error ? error.message : String(error) });
|
|
81946
|
+
continue;
|
|
81576
81947
|
}
|
|
81577
81948
|
sections.push({
|
|
81578
81949
|
section_ref: `${task.article_id}#${fragment2.id}`,
|
|
@@ -81582,6 +81953,11 @@ async function prepareProductionArticle(input) {
|
|
|
81582
81953
|
markdown_digest: indexerProtocolDigest(fragment2.readerVisibleBody)
|
|
81583
81954
|
});
|
|
81584
81955
|
}
|
|
81956
|
+
if (problems.length) {
|
|
81957
|
+
const error = articleError(task, files.references.path, problems.length === 1 ? problems[0].message : `${problems.length} reference problems: ${problems.map((item, index2) => `(${index2 + 1}) ${item.section}: ${item.message}`).join(" ")}`, problems[0].section);
|
|
81958
|
+
error.detail.problems = problems;
|
|
81959
|
+
throw error;
|
|
81960
|
+
}
|
|
81585
81961
|
const fingerprint = indexerProtocolDigest({ input: task.input, markdown, sections });
|
|
81586
81962
|
return parseCandidateRecord({
|
|
81587
81963
|
candidate_id: indexerCandidateId(fingerprint),
|
|
@@ -81609,7 +81985,10 @@ async function prepareProductionArticle(input) {
|
|
|
81609
81985
|
updated: new Date().toISOString()
|
|
81610
81986
|
}, 1);
|
|
81611
81987
|
}
|
|
81612
|
-
var import_yaml23, productionReferencesSchema
|
|
81988
|
+
var import_yaml23, productionReferencesSchema, signedSections = (base) => (base?.sections ?? []).map((section) => ({
|
|
81989
|
+
id: section.id,
|
|
81990
|
+
references: section.references.filter((value) => !!value.content_digest && ("start_line" in value.locator))
|
|
81991
|
+
}));
|
|
81613
81992
|
var init_productionArticle = __esm(() => {
|
|
81614
81993
|
init_submittedSourceLocator();
|
|
81615
81994
|
init_zod();
|
|
@@ -81619,6 +81998,9 @@ var init_productionArticle = __esm(() => {
|
|
|
81619
81998
|
init_exitCode();
|
|
81620
81999
|
init_candidateLedger();
|
|
81621
82000
|
init_articleSourceReader();
|
|
82001
|
+
init_articleReferenceObservation();
|
|
82002
|
+
init_approvedRevisionReferences();
|
|
82003
|
+
init_gitObjectReader();
|
|
81622
82004
|
init_articleRegionBaselines();
|
|
81623
82005
|
init_productionArticleEdits();
|
|
81624
82006
|
init_okfTypes();
|
|
@@ -81766,7 +82148,10 @@ function writeTarget3(path2, previous2, content3) {
|
|
|
81766
82148
|
content: content3
|
|
81767
82149
|
};
|
|
81768
82150
|
}
|
|
81769
|
-
|
|
82151
|
+
function completeProductionSubmission(input) {
|
|
82152
|
+
return completeProductionSubmissionImpl(input);
|
|
82153
|
+
}
|
|
82154
|
+
async function completeProductionSubmissionImpl(input) {
|
|
81770
82155
|
return withProjectWriteLock(input.projectRoot, "production-submit", async () => {
|
|
81771
82156
|
await recoverDurableMultiFileTransactions(input.projectRoot);
|
|
81772
82157
|
const snapshot = await readProductionStageSnapshot(input.projectRoot);
|
|
@@ -81866,7 +82251,7 @@ async function completeProductionSubmission(input) {
|
|
|
81866
82251
|
if (files.edits) {
|
|
81867
82252
|
base = await readProductionRepairDraft({ projectRoot: input.projectRoot, stage: stage.id, task }) ?? base;
|
|
81868
82253
|
}
|
|
81869
|
-
retainDraft = !!files.content && !!files.references;
|
|
82254
|
+
retainDraft = !input.preview && !!files.content && !!files.references;
|
|
81870
82255
|
const candidate = await measureContextDebugOperation({ projectRoot: input.projectRoot, operation: "production.submit.validate" }, () => prepareProductionArticle({
|
|
81871
82256
|
projectRoot: input.projectRoot,
|
|
81872
82257
|
task,
|
|
@@ -81875,7 +82260,9 @@ async function completeProductionSubmission(input) {
|
|
|
81875
82260
|
approvedBaseDigest: target.approvedBaseDigest,
|
|
81876
82261
|
...base ? { base } : {},
|
|
81877
82262
|
...target.base ? { trustedBase: target.base } : {},
|
|
81878
|
-
visibility: target.visibility
|
|
82263
|
+
visibility: target.visibility,
|
|
82264
|
+
preview: input.preview === true,
|
|
82265
|
+
authorization: () => productionAuthorization(input.projectRoot, stage, task)
|
|
81879
82266
|
}));
|
|
81880
82267
|
const key = knowledgeTargetPathKey(candidate.path);
|
|
81881
82268
|
byPath.set(key, [...(byPath.get(key) ?? []).filter((item) => item.article_id !== task.article_id), candidate]);
|
|
@@ -81883,22 +82270,35 @@ async function completeProductionSubmission(input) {
|
|
|
81883
82270
|
pending.set(task.id, { candidate, digest: contentDigest });
|
|
81884
82271
|
} catch (error) {
|
|
81885
82272
|
const detail = error && typeof error === "object" && "detail" in error ? error.detail : undefined;
|
|
81886
|
-
|
|
82273
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
82274
|
+
let note = "";
|
|
81887
82275
|
if (retainDraft) {
|
|
81888
82276
|
try {
|
|
81889
82277
|
await retainProductionRepairDraft({ projectRoot: input.projectRoot, stage: stage.id, task, files });
|
|
81890
82278
|
} catch {
|
|
81891
|
-
|
|
82279
|
+
note = " The temporary repair draft could not be retained; resubmit the complete draft.";
|
|
81892
82280
|
}
|
|
81893
82281
|
}
|
|
81894
|
-
|
|
81895
|
-
|
|
81896
|
-
|
|
81897
|
-
|
|
81898
|
-
|
|
81899
|
-
|
|
82282
|
+
const problems = Array.isArray(detail?.problems) ? detail.problems : [{ section: detail?.section, message: reason }];
|
|
82283
|
+
for (const item of problems) {
|
|
82284
|
+
result.failed.push({
|
|
82285
|
+
task: task.id,
|
|
82286
|
+
reason: item.message + note,
|
|
82287
|
+
...typeof detail?.file === "string" ? { file: detail.file } : {},
|
|
82288
|
+
...typeof item.section === "string" ? { section: item.section } : {}
|
|
82289
|
+
});
|
|
82290
|
+
}
|
|
81900
82291
|
}
|
|
81901
82292
|
}
|
|
82293
|
+
if (input.preview) {
|
|
82294
|
+
const order2 = new Map(fixed2.tasks.map((task, index2) => [task.task, index2]));
|
|
82295
|
+
return {
|
|
82296
|
+
protocol: "context.production-submission-preview/v1",
|
|
82297
|
+
written: false,
|
|
82298
|
+
ok: [...result.accepted.map((item) => item.task), ...pending.keys()].sort((a, b) => order2.get(a) - order2.get(b)),
|
|
82299
|
+
failed: result.failed
|
|
82300
|
+
};
|
|
82301
|
+
}
|
|
81902
82302
|
if (pending.size) {
|
|
81903
82303
|
const changedArticles = new Set([...pending.values()].map((proposal) => proposal.candidate.article_id));
|
|
81904
82304
|
const nextCandidates = [
|
|
@@ -81963,6 +82363,24 @@ async function completeProductionSubmission(input) {
|
|
|
81963
82363
|
return result;
|
|
81964
82364
|
});
|
|
81965
82365
|
}
|
|
82366
|
+
async function productionAuthorization(projectRoot, stage, task) {
|
|
82367
|
+
const { readProductionRequirements: readProductionRequirements2 } = await Promise.resolve().then(() => (init_productionRequirements(), exports_productionRequirements));
|
|
82368
|
+
const sources = new Set(task.sources.map((source2) => source2.scope));
|
|
82369
|
+
const requirements = await readProductionRequirements2(projectRoot).then((value) => value.requirements.filter((item) => [...item.target_scope.targets, ...item.evidence_source_scope?.targets ?? []].some((target) => sources.has(target.source_ref))).map((item) => item.id), () => []);
|
|
82370
|
+
const dependents = [];
|
|
82371
|
+
for (let added = true;added; ) {
|
|
82372
|
+
added = false;
|
|
82373
|
+
for (const other of stage.tasks) {
|
|
82374
|
+
if (dependents.includes(other.id) || ["accepted", "excluded", "replaced"].includes(other.status))
|
|
82375
|
+
continue;
|
|
82376
|
+
if (other.after.some((id3) => id3 === task.id || dependents.includes(id3))) {
|
|
82377
|
+
dependents.push(other.id);
|
|
82378
|
+
added = true;
|
|
82379
|
+
}
|
|
82380
|
+
}
|
|
82381
|
+
}
|
|
82382
|
+
return { requirements, dependents };
|
|
82383
|
+
}
|
|
81966
82384
|
var init_productionSubmission = __esm(() => {
|
|
81967
82385
|
init_submissionState();
|
|
81968
82386
|
init_src2();
|
|
@@ -82688,6 +83106,12 @@ var init_siteTheme2 = __esm(() => {
|
|
|
82688
83106
|
});
|
|
82689
83107
|
|
|
82690
83108
|
// src/project/workspaceContentSnapshot.ts
|
|
83109
|
+
var exports_workspaceContentSnapshot = {};
|
|
83110
|
+
__export(exports_workspaceContentSnapshot, {
|
|
83111
|
+
workspaceContentSnapshot: () => workspaceContentSnapshot,
|
|
83112
|
+
observeWorkspaceContent: () => observeWorkspaceContent,
|
|
83113
|
+
excludedWorkspaceContent: () => excludedWorkspaceContent
|
|
83114
|
+
});
|
|
82691
83115
|
import { createHash as createHash15 } from "node:crypto";
|
|
82692
83116
|
import { execFile as execFile10 } from "node:child_process";
|
|
82693
83117
|
import { lstat as lstat8, readFile as readFile38, readdir as readdir9, realpath as realpath9 } from "node:fs/promises";
|
|
@@ -82833,6 +83257,26 @@ async function migrateCheckpoint(root, original, value) {
|
|
|
82833
83257
|
});
|
|
82834
83258
|
} catch {}
|
|
82835
83259
|
}
|
|
83260
|
+
async function versionMergedTo(root, version3) {
|
|
83261
|
+
const git2 = (args) => exec5("git", args, { cwd: root, timeout: 1e4, maxBuffer: 16 * 1024 * 1024 }).then((value) => value.stdout.trim(), () => {
|
|
83262
|
+
return;
|
|
83263
|
+
});
|
|
83264
|
+
const prefix = await git2(["rev-parse", "--show-prefix"]);
|
|
83265
|
+
if (prefix === undefined)
|
|
83266
|
+
return;
|
|
83267
|
+
const head = await git2(["symbolic-ref", "--quiet", "--short", "refs/remotes/origin/HEAD"]);
|
|
83268
|
+
for (const ref2 of [...head ? [head] : [], "origin/main", "origin/master"]) {
|
|
83269
|
+
const text7 = await git2(["show", `${ref2}:${prefix}changelog.yaml`]);
|
|
83270
|
+
if (text7 === undefined)
|
|
83271
|
+
continue;
|
|
83272
|
+
try {
|
|
83273
|
+
if (ledgerSchema.parse(import_yaml28.parse(text7)).entries.some((entry) => entry.version === version3))
|
|
83274
|
+
return ref2;
|
|
83275
|
+
} catch {}
|
|
83276
|
+
return;
|
|
83277
|
+
}
|
|
83278
|
+
return;
|
|
83279
|
+
}
|
|
82836
83280
|
async function inspectWorkspaceVersion(root, baseRef) {
|
|
82837
83281
|
const snapshot = await observeWorkspaceContent(root);
|
|
82838
83282
|
const { files } = snapshot;
|
|
@@ -82858,11 +83302,13 @@ async function inspectWorkspaceVersion(root, baseRef) {
|
|
|
82858
83302
|
const recorded = entries[0]?.version === version3;
|
|
82859
83303
|
const matches = checkpoint?.version === version3 && checkpoint.digest === digest3;
|
|
82860
83304
|
const changed = checkpoint?.version === version3 ? !matches : comparison.added.length + comparison.updated.length + comparison.removed.length > 0 || !recorded;
|
|
83305
|
+
const mergedTo = recorded && !comparison.tagged ? await versionMergedTo(root, version3) : undefined;
|
|
82861
83306
|
return {
|
|
82862
83307
|
version: version3,
|
|
82863
83308
|
previous_version: version3,
|
|
82864
83309
|
changed,
|
|
82865
|
-
reusable_version: recorded && !comparison.tagged ? version3 : null,
|
|
83310
|
+
reusable_version: recorded && !comparison.tagged && !mergedTo ? version3 : null,
|
|
83311
|
+
...mergedTo ? { merged_to: mergedTo } : {},
|
|
82866
83312
|
current: recorded && (matches || checkpoint?.version !== version3 && (comparison.base_commit === null || !changed)),
|
|
82867
83313
|
expected_digest: hash2({ files, version: version3, entries, base: comparison.base_commit }),
|
|
82868
83314
|
...comparison,
|
|
@@ -82919,7 +83365,7 @@ async function recordWorkspaceVersion(root, value) {
|
|
|
82919
83365
|
const a = previous2.split(".").map(Number), b = input.version.split(".").map(Number);
|
|
82920
83366
|
const amend = status.reusable_version === input.version;
|
|
82921
83367
|
if (!amend && !(b[0] > a[0] || b[0] === a[0] && (b[1] > a[1] || b[1] === a[1] && b[2] > a[2])))
|
|
82922
|
-
throw new TypeError("The new SemVer must be greater than the previous workspace version; only an untagged current entry
|
|
83368
|
+
throw new TypeError("The new SemVer must be greater than the previous workspace version; only an untagged current entry that is not yet on the remote default branch may be amended.");
|
|
82923
83369
|
let actor = input.actor ?? (amend ? previousEntries[0]?.actor : undefined);
|
|
82924
83370
|
if (!actor) {
|
|
82925
83371
|
try {
|
|
@@ -85124,7 +85570,7 @@ import {
|
|
|
85124
85570
|
renameSync as renameSync2,
|
|
85125
85571
|
writeFileSync as writeFileSync3
|
|
85126
85572
|
} from "node:fs";
|
|
85127
|
-
import { spawn as
|
|
85573
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
85128
85574
|
import { dirname as dirname25, join as join60 } from "node:path";
|
|
85129
85575
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
85130
85576
|
function isRecord10(value) {
|
|
@@ -85201,7 +85647,7 @@ async function describeRuntimeEventSink(sink, cwd) {
|
|
|
85201
85647
|
}, RUNTIME_EVENT_SINK_DESCRIPTION_TIMEOUT_MS);
|
|
85202
85648
|
let child;
|
|
85203
85649
|
try {
|
|
85204
|
-
const spawned =
|
|
85650
|
+
const spawned = spawn4(sink.command, describeArgs, {
|
|
85205
85651
|
cwd,
|
|
85206
85652
|
env: process.env,
|
|
85207
85653
|
shell: false,
|
|
@@ -85316,7 +85762,7 @@ function dispatchCommand(sink, batch, cwd) {
|
|
|
85316
85762
|
})();
|
|
85317
85763
|
};
|
|
85318
85764
|
try {
|
|
85319
|
-
const child =
|
|
85765
|
+
const child = spawn4(sink.command, sink.args, {
|
|
85320
85766
|
cwd,
|
|
85321
85767
|
env: process.env,
|
|
85322
85768
|
shell: false,
|
|
@@ -85644,6 +86090,38 @@ var init_runtimeEvents = __esm(() => {
|
|
|
85644
86090
|
});
|
|
85645
86091
|
|
|
85646
86092
|
// src/project/approvedKnowledgeDependencyWarnings.ts
|
|
86093
|
+
async function classifyCitation(sectionId, reference2, observe, repoImpact) {
|
|
86094
|
+
const where = `${sectionId}: ${reference2.source_ref}/${reference2.locator.path}`;
|
|
86095
|
+
try {
|
|
86096
|
+
if (reference2.source_ref.startsWith("repo-content:")) {
|
|
86097
|
+
const impact = await (await repoImpact)(reference2);
|
|
86098
|
+
if (impact.state === "unchanged")
|
|
86099
|
+
return { kind: "current" };
|
|
86100
|
+
if (impact.state === "moved")
|
|
86101
|
+
return { kind: "moved", text: `${sectionId}: ${reference2.source_ref}/${impact.current_path ?? reference2.locator.path}` };
|
|
86102
|
+
return { kind: "changed", text: `${where} (changed)` };
|
|
86103
|
+
}
|
|
86104
|
+
const result = await observe(reference2);
|
|
86105
|
+
if (result.state === "current")
|
|
86106
|
+
return { kind: "current" };
|
|
86107
|
+
if (result.state === "moved") {
|
|
86108
|
+
const locator = result.reference.locator;
|
|
86109
|
+
return { kind: "moved", text: `${sectionId}: ${reference2.source_ref}/${locator.path} L${locator.start_line}–L${locator.end_line}` };
|
|
86110
|
+
}
|
|
86111
|
+
if (result.state === "unavailable" && (result.reason ?? "") in LOCAL_SOURCE_REASONS) {
|
|
86112
|
+
return { kind: "unchecked", reason: `${LOCAL_SOURCE_REASONS[result.reason]} (${reference2.source_ref}, ${result.reason})` };
|
|
86113
|
+
}
|
|
86114
|
+
return {
|
|
86115
|
+
kind: "changed",
|
|
86116
|
+
state: { section_id: sectionId, state: result.state, ...result.reason ? { reason: result.reason } : {} },
|
|
86117
|
+
text: `${where} L${reference2.locator.start_line}–L${reference2.locator.end_line} (${result.state}${result.reason ? `, ${result.reason}` : ""})`
|
|
86118
|
+
};
|
|
86119
|
+
} catch (error) {
|
|
86120
|
+
if (!(error instanceof SourceReadError))
|
|
86121
|
+
throw error;
|
|
86122
|
+
return { kind: "unchecked", reason: error.message };
|
|
86123
|
+
}
|
|
86124
|
+
}
|
|
85647
86125
|
async function approvedKnowledgeDependencyWarnings(projectRoot, structureOverride) {
|
|
85648
86126
|
const articles = approvedKnowledgeSnapshotsFromStructure(structureOverride ?? (await readKnowledgeStructure(projectRoot)).parsed);
|
|
85649
86127
|
if (!articles.some((article) => article.sections.some((section) => section.references.length)))
|
|
@@ -85653,46 +86131,28 @@ async function approvedKnowledgeDependencyWarnings(projectRoot, structureOverrid
|
|
|
85653
86131
|
const issues = [];
|
|
85654
86132
|
let repoImpact;
|
|
85655
86133
|
let pending;
|
|
86134
|
+
const unreadable = new Map;
|
|
85656
86135
|
for (const article of articles) {
|
|
85657
86136
|
const changed = [];
|
|
85658
86137
|
const moved = [];
|
|
85659
86138
|
const referenceStates = [];
|
|
85660
86139
|
for (const section of article.sections) {
|
|
85661
86140
|
for (const reference2 of section.references) {
|
|
85662
|
-
|
|
85663
|
-
|
|
85664
|
-
|
|
85665
|
-
|
|
85666
|
-
|
|
85667
|
-
|
|
85668
|
-
|
|
85669
|
-
|
|
85670
|
-
|
|
85671
|
-
|
|
85672
|
-
|
|
85673
|
-
|
|
85674
|
-
|
|
85675
|
-
|
|
85676
|
-
|
|
85677
|
-
continue;
|
|
85678
|
-
if (result.state === "moved") {
|
|
85679
|
-
const locator = result.reference.locator;
|
|
85680
|
-
moved.push(`${section.id}: ${reference2.source_ref}/${locator.path} L${locator.start_line}–L${locator.end_line}`);
|
|
85681
|
-
continue;
|
|
85682
|
-
}
|
|
85683
|
-
referenceStates.push({ section_id: section.id, state: result.state, ...result.reason ? { reason: result.reason } : {} });
|
|
85684
|
-
changed.push(section.id);
|
|
85685
|
-
break;
|
|
85686
|
-
} catch (error) {
|
|
85687
|
-
if (!(error instanceof SourceReadError))
|
|
85688
|
-
throw error;
|
|
85689
|
-
issues.push({
|
|
85690
|
-
severity: "warning",
|
|
85691
|
-
code: "source-read-failed",
|
|
85692
|
-
path: article.path,
|
|
85693
|
-
source_keys: [reference2.source_ref],
|
|
85694
|
-
message: `${reference2.source_ref}/${reference2.locator.path}: ${error.message} No citation state was determined. Run context source recovery-plan --format json, then retry verification.`
|
|
85695
|
-
});
|
|
86141
|
+
if (reference2.source_ref.startsWith("repo-content:"))
|
|
86142
|
+
repoImpact ??= repoContentImpactReader(projectRoot);
|
|
86143
|
+
const citation = await classifyCitation(section.id, reference2, observe, repoImpact);
|
|
86144
|
+
if (citation.kind === "moved")
|
|
86145
|
+
moved.push(citation.text);
|
|
86146
|
+
else if (citation.kind === "changed") {
|
|
86147
|
+
changed.push(citation.text);
|
|
86148
|
+
if (citation.state)
|
|
86149
|
+
referenceStates.push(citation.state);
|
|
86150
|
+
} else if (citation.kind === "unchecked") {
|
|
86151
|
+
const entry = unreadable.get(reference2.source_ref) ?? { pages: [], citations: 0, reason: citation.reason };
|
|
86152
|
+
entry.citations++;
|
|
86153
|
+
if (!entry.pages.includes(article.path))
|
|
86154
|
+
entry.pages.push(article.path);
|
|
86155
|
+
unreadable.set(reference2.source_ref, entry);
|
|
85696
86156
|
}
|
|
85697
86157
|
}
|
|
85698
86158
|
}
|
|
@@ -85706,7 +86166,7 @@ async function approvedKnowledgeDependencyWarnings(projectRoot, structureOverrid
|
|
|
85706
86166
|
code: "approved-source-region-changed",
|
|
85707
86167
|
path: article.path,
|
|
85708
86168
|
...referenceStates.length ? { reference_states: referenceStates } : {},
|
|
85709
|
-
message: `
|
|
86169
|
+
message: `Cited source regions changed or are unavailable: ${changed.join("; ")}.${update || " Inspect current sources and revise this article;"} Verification does not rewrite approved references.`
|
|
85710
86170
|
});
|
|
85711
86171
|
if (moved.length)
|
|
85712
86172
|
issues.push({
|
|
@@ -85716,6 +86176,16 @@ async function approvedKnowledgeDependencyWarnings(projectRoot, structureOverrid
|
|
|
85716
86176
|
message: `Cited regions are unchanged but their location or surrounding source changed: ${moved.join("; ")}.${update || " Check locators during the source update;"} Do not rewrite unaffected prose.`
|
|
85717
86177
|
});
|
|
85718
86178
|
}
|
|
86179
|
+
for (const [source2, entry] of unreadable) {
|
|
86180
|
+
const shown = entry.pages.slice(0, 5).join(", ") + (entry.pages.length > 5 ? `, and ${entry.pages.length - 5} more` : "");
|
|
86181
|
+
issues.push({
|
|
86182
|
+
severity: "warning",
|
|
86183
|
+
code: "source-read-failed",
|
|
86184
|
+
path: entry.pages[0],
|
|
86185
|
+
source_keys: [source2],
|
|
86186
|
+
message: `${entry.reason} ${entry.citations} citation(s) in ${entry.pages.length} page(s) were not checked (${shown}). ` + "This is not a citation change. Restore a missing checkout with context source recovery-plan --format json; " + "context update --pending downloads missing commits and contents. Then retry verification."
|
|
86187
|
+
});
|
|
86188
|
+
}
|
|
85719
86189
|
return issues;
|
|
85720
86190
|
}
|
|
85721
86191
|
var init_approvedKnowledgeDependencyWarnings = __esm(() => {
|
|
@@ -88094,13 +88564,6 @@ async function missingObjects(root, commit, paths) {
|
|
|
88094
88564
|
return checked.split(`
|
|
88095
88565
|
`).filter((line) => line.endsWith(" missing")).map((line) => line.split(" ")[0]);
|
|
88096
88566
|
}
|
|
88097
|
-
function failureSummary(error) {
|
|
88098
|
-
const text7 = error && typeof error === "object" && "stderr" in error ? String(error.stderr ?? "") : String(error);
|
|
88099
|
-
const line = text7.split(`
|
|
88100
|
-
`).map((part) => part.trim()).find((part) => /^(fatal|error):/iu.test(part)) ?? text7.split(`
|
|
88101
|
-
`)[0]?.trim() ?? "";
|
|
88102
|
-
return line.replace(/\/\/[^/@\s]+@/gu, "//").slice(0, 200) || "fetch failed";
|
|
88103
|
-
}
|
|
88104
88567
|
async function prepareRepositoryContents(projectRoot, requests) {
|
|
88105
88568
|
const registry2 = await loadSourcesRegistry({ rootDir: projectRoot });
|
|
88106
88569
|
const results = [];
|
|
@@ -88127,7 +88590,9 @@ async function prepareRepositoryContents(projectRoot, requests) {
|
|
|
88127
88590
|
else {
|
|
88128
88591
|
try {
|
|
88129
88592
|
for (let index2 = 0;index2 < missing2.length; index2 += FETCH_BATCH) {
|
|
88130
|
-
await
|
|
88593
|
+
await runGitWithProgress([
|
|
88594
|
+
"-C",
|
|
88595
|
+
root,
|
|
88131
88596
|
"-c",
|
|
88132
88597
|
"fetch.negotiationAlgorithm=noop",
|
|
88133
88598
|
"fetch",
|
|
@@ -88137,10 +88602,10 @@ async function prepareRepositoryContents(projectRoot, requests) {
|
|
|
88137
88602
|
"--filter=blob:none",
|
|
88138
88603
|
remote,
|
|
88139
88604
|
...missing2.slice(index2, index2 + FETCH_BATCH)
|
|
88140
|
-
], { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" },
|
|
88605
|
+
], { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, label: `git fetch of ${request.source_ref} contents` });
|
|
88141
88606
|
}
|
|
88142
88607
|
} catch (error) {
|
|
88143
|
-
result.reason =
|
|
88608
|
+
result.reason = redactRemoteCredentials(error instanceof Error ? error.message : String(error)).slice(0, 400);
|
|
88144
88609
|
}
|
|
88145
88610
|
result.unresolved = (await missingObjects(root, commit, paths)).length;
|
|
88146
88611
|
if (!result.unresolved)
|
|
@@ -88154,6 +88619,7 @@ async function prepareRepositoryContents(projectRoot, requests) {
|
|
|
88154
88619
|
var execute3, offline, FETCH_BATCH = 1000, PATH_BATCH = 500;
|
|
88155
88620
|
var init_repoContentPrefetch = __esm(() => {
|
|
88156
88621
|
init_src2();
|
|
88622
|
+
init_gitProgress();
|
|
88157
88623
|
execute3 = promisify10(execFile12);
|
|
88158
88624
|
offline = { ...process.env, GIT_NO_LAZY_FETCH: "1" };
|
|
88159
88625
|
});
|
|
@@ -88267,10 +88733,11 @@ async function readKnowledgeUpdate(projectRoot) {
|
|
|
88267
88733
|
throw new TypeError("Source update request digest is invalid");
|
|
88268
88734
|
return update;
|
|
88269
88735
|
}
|
|
88270
|
-
function stopOnUnreadableSources(unresolved, prepared2, network) {
|
|
88736
|
+
function stopOnUnreadableSources(unresolved, prepared2, network, fetchFailures = new Map, registered = new Map) {
|
|
88271
88737
|
const missingCommits = [...new Set(unresolved.filter((item) => item.reason === "source-history-missing").map((item) => item.reference.source_ref))];
|
|
88272
88738
|
if (missingCommits.length) {
|
|
88273
|
-
|
|
88739
|
+
const why = missingCommits.map((source2) => fetchFailures.get(registered.get(source2) ?? "")).filter(Boolean);
|
|
88740
|
+
throw new TypeError(`The registered commit of ${missingCommits.join(", ")} is not in its source checkout${network ? " and could not be fetched" : ""}` + `${why.length ? ` (${why.join("; ")})` : ""}. ` + "Check that the registered commit SHA exists in the remote repository. " + (network ? "If it does, fetch and check out the registered commit in the source checkout (see context source list --format json), then rerun context update --pending --format json." : "context update --pending fetches it; an explicit update reads only what the checkout has, so fetch and check out the commit first, then rerun this update."));
|
|
88274
88741
|
}
|
|
88275
88742
|
const contentMissing = [...new Set(unresolved.filter((item) => item.reason === "source-content-missing").map((item) => item.reference.source_ref))];
|
|
88276
88743
|
if (contentMissing.length) {
|
|
@@ -88334,15 +88801,16 @@ async function beginKnowledgeUpdate(projectRoot, value, options = {}) {
|
|
|
88334
88801
|
});
|
|
88335
88802
|
const network = options.pending === true;
|
|
88336
88803
|
let prepared2 = [];
|
|
88804
|
+
let fetchFailures = new Map;
|
|
88337
88805
|
if (network) {
|
|
88338
|
-
await fetchSourceCommits(projectRoot, [
|
|
88806
|
+
fetchFailures = await fetchSourceCommits(projectRoot, [
|
|
88339
88807
|
...repoScopes.map((source_ref) => ({ source_ref })),
|
|
88340
88808
|
...comparisons.map((item) => ({ source_ref: item.source_ref, commit: item.from }))
|
|
88341
88809
|
]);
|
|
88342
88810
|
prepared2 = await prepareRepositoryContents(projectRoot, repoScopes.map((source2) => ({ source_ref: source2, paths: citedPaths(source2, cited) })));
|
|
88343
88811
|
}
|
|
88344
88812
|
const inspected = await inspectSettledReferences(projectRoot, cited, scopes.map((scope2) => scope2.source_ref), settled);
|
|
88345
|
-
stopOnUnreadableSources(inspected.unresolved, prepared2, network);
|
|
88813
|
+
stopOnUnreadableSources(inspected.unresolved, prepared2, network, fetchFailures, new Map(scopes.map((scope2) => [scope2.source_ref, scope2.processed_version])));
|
|
88346
88814
|
if (network)
|
|
88347
88815
|
await prepareRepositoryContents(projectRoot, repoScopes.flatMap((source2) => {
|
|
88348
88816
|
const scope2 = scopes.find((item) => item.source_ref === source2);
|
|
@@ -94442,7 +94910,7 @@ var init_packageSiteLocales = __esm(() => {
|
|
|
94442
94910
|
|
|
94443
94911
|
// src/project/packageSite.ts
|
|
94444
94912
|
import { createHash as createHash27 } from "node:crypto";
|
|
94445
|
-
import { spawn as
|
|
94913
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
94446
94914
|
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";
|
|
94447
94915
|
import { createRequire as createRequire5 } from "node:module";
|
|
94448
94916
|
import { dirname as dirname38, join as join86, posix as posix10 } from "node:path";
|
|
@@ -94565,7 +95033,7 @@ function siteSections(entries2) {
|
|
|
94565
95033
|
async function compileSite(root, outDir) {
|
|
94566
95034
|
const vitepressRoot = dirname38(require2.resolve("vitepress/package.json"));
|
|
94567
95035
|
await new Promise((resolve8, reject) => {
|
|
94568
|
-
const child =
|
|
95036
|
+
const child = spawn5(process.versions.bun ? "node" : process.execPath, [join86(vitepressRoot, "bin/vitepress.js"), "build", root, "--outDir", outDir], { stdio: ["ignore", "pipe", "pipe"] });
|
|
94569
95037
|
let tail = "";
|
|
94570
95038
|
const receive = (chunk) => {
|
|
94571
95039
|
tail = (tail + chunk.toString()).slice(-16000);
|
|
@@ -95819,7 +96287,13 @@ async function runProjectBuildCommand(input) {
|
|
|
95819
96287
|
const deliveryHint = runtimeEventPendingAgentHint(await flushQueuedContextRuntimeEvents(result.projectRoot));
|
|
95820
96288
|
if (deliveryHint !== undefined)
|
|
95821
96289
|
result.agent_hints.push(deliveryHint);
|
|
95822
|
-
|
|
96290
|
+
let extra = {};
|
|
96291
|
+
if (input.format === "json") {
|
|
96292
|
+
try {
|
|
96293
|
+
extra = { workflow: (await (await Promise.resolve().then(() => (init_status(), exports_status))).collectProjectStatus(found.projectRoot, input.execution ?? {})).workflow };
|
|
96294
|
+
} catch {}
|
|
96295
|
+
}
|
|
96296
|
+
process.stdout.write(formatProjectBuildResult(result, input.format ?? "text", input.verbose === true, extra));
|
|
95823
96297
|
return true;
|
|
95824
96298
|
}
|
|
95825
96299
|
var import_yaml44, PACKAGE_FINGERPRINT_ROOT, PACKAGE_BUILDER_PROTOCOL_VERSION = "v23-sibling-site-output";
|
|
@@ -97142,103 +97616,6 @@ var init_approvedRevisionEdits = __esm(() => {
|
|
|
97142
97616
|
init_approvedRevisionPrograms();
|
|
97143
97617
|
});
|
|
97144
97618
|
|
|
97145
|
-
// src/project/approvedRevisionReferences.ts
|
|
97146
|
-
async function prepareRevisionReferences(input) {
|
|
97147
|
-
const edits = new Map(input.edits?.map((edit) => [edit.section_id, edit]));
|
|
97148
|
-
if (edits.size !== (input.edits?.length ?? 0))
|
|
97149
|
-
throw new TypeError("Repeated revision fragment identity");
|
|
97150
|
-
for (const id3 of edits.keys())
|
|
97151
|
-
if (!input.sectionIds.includes(id3)) {
|
|
97152
|
-
throw new TypeError(`Reference edit targets a missing fragment: ${id3}`);
|
|
97153
|
-
}
|
|
97154
|
-
let read;
|
|
97155
|
-
const inScope = (source2) => input.sourceRefs.some((scope2) => repoContentScopeMatches(scope2, source2));
|
|
97156
|
-
const readSource = async (source2, path2) => {
|
|
97157
|
-
if (!inScope(source2))
|
|
97158
|
-
throw new TypeError(`Source is outside this revision: ${source2}`);
|
|
97159
|
-
read ??= await registeredArticleSourceReader(input.projectRoot);
|
|
97160
|
-
return read(source2, path2, true);
|
|
97161
|
-
};
|
|
97162
|
-
const result = [];
|
|
97163
|
-
for (const id3 of input.sectionIds) {
|
|
97164
|
-
const edit = edits.get(id3);
|
|
97165
|
-
if (edit?.references !== undefined) {
|
|
97166
|
-
const at2 = ["sections", input.edits.indexOf(edit), "references"];
|
|
97167
|
-
const previous2 = input.previous.find((section) => section.id === id3)?.references ?? [];
|
|
97168
|
-
const references2 = [];
|
|
97169
|
-
for (const [index3, reference2] of edit.references.entries()) {
|
|
97170
|
-
if (!inScope(reference2.source_ref))
|
|
97171
|
-
throw new SubmissionInputError(`Fragment ${id3} cites ${reference2.source_ref}, which is outside this revision; allowed sources: ${input.sourceRefs.join(", ")}. ` + "To cite new independent evidence, register it as a source, associate it with the selected requirement in src/indexers.yaml, then run context task adjust for this revision.", [...at2, index3, "source_ref"], "source-outside-revision");
|
|
97172
|
-
const submitted = reference2.locator;
|
|
97173
|
-
const kept = "start_line" in submitted ? previous2.find((old) => old.source_ref === reference2.source_ref && old.locator.path === submitted.path && old.locator.start_line === submitted.start_line && old.locator.end_line === submitted.end_line) : undefined;
|
|
97174
|
-
if (kept) {
|
|
97175
|
-
const observed = await relocateUnchangedReference(input.projectRoot, readSource, kept);
|
|
97176
|
-
if (observed.state === "current" || observed.state === "moved") {
|
|
97177
|
-
references2.push(observed.reference);
|
|
97178
|
-
continue;
|
|
97179
|
-
}
|
|
97180
|
-
throw new SubmissionInputError(`Fragment ${id3}: ${reference2.source_ref} ${kept.locator.path}:${kept.locator.start_line}-${kept.locator.end_line} ` + `repeats an earlier citation, so it keeps that evidence, which is ${observed.state} in the current source. ` + "To keep the earlier evidence, cite its current position. To cite the text now at these lines (it may be the correct new content), use a quote or heading locator.", [...at2, index3, "locator"], "kept-reference-unresolved");
|
|
97181
|
-
}
|
|
97182
|
-
const text8 = await readSource(reference2.source_ref, reference2.locator.path);
|
|
97183
|
-
let locator;
|
|
97184
|
-
try {
|
|
97185
|
-
locator = resolveSubmittedSourceLocator(reference2.locator, text8);
|
|
97186
|
-
} catch (error) {
|
|
97187
|
-
if (error instanceof SubmissionInputError)
|
|
97188
|
-
throw new SubmissionInputError(`Fragment ${id3}: ${error.message}`, [...at2, index3, "locator"]);
|
|
97189
|
-
throw error;
|
|
97190
|
-
}
|
|
97191
|
-
const resolved = createArticleSourceReference(reference2.source_ref, locator, text8);
|
|
97192
|
-
if (input.remember !== false)
|
|
97193
|
-
rememberArticleRegion(input.projectRoot, resolved, text8);
|
|
97194
|
-
references2.push(resolved);
|
|
97195
|
-
}
|
|
97196
|
-
try {
|
|
97197
|
-
result.push({ id: id3, references: articleFragmentReferences(references2) });
|
|
97198
|
-
} catch (error) {
|
|
97199
|
-
if (error instanceof ZodError)
|
|
97200
|
-
throw new SubmissionInputError(`Fragment ${id3}: ${error.issues.map((issue) => issue.message).join("; ")}`, at2);
|
|
97201
|
-
throw error;
|
|
97202
|
-
}
|
|
97203
|
-
continue;
|
|
97204
|
-
}
|
|
97205
|
-
const references = [];
|
|
97206
|
-
for (const reference2 of input.previous.find((section) => section.id === id3)?.references ?? []) {
|
|
97207
|
-
references.push((await relocateUnchangedReference(input.projectRoot, readSource, reference2)).reference);
|
|
97208
|
-
}
|
|
97209
|
-
result.push({ id: id3, references });
|
|
97210
|
-
}
|
|
97211
|
-
return result;
|
|
97212
|
-
}
|
|
97213
|
-
function removedCitations(previous2, next) {
|
|
97214
|
-
const removed = [];
|
|
97215
|
-
for (const section of previous2) {
|
|
97216
|
-
const current3 = next.find((item) => item.id === section.id)?.references ?? [];
|
|
97217
|
-
for (const reference2 of section.references) {
|
|
97218
|
-
const kept = current3.some((item) => item.source_ref === reference2.source_ref && item.locator.path === reference2.locator.path && item.content_digest === reference2.content_digest);
|
|
97219
|
-
if (!kept)
|
|
97220
|
-
removed.push({
|
|
97221
|
-
section_id: section.id,
|
|
97222
|
-
source_ref: reference2.source_ref,
|
|
97223
|
-
path: reference2.locator.path,
|
|
97224
|
-
start_line: reference2.locator.start_line,
|
|
97225
|
-
end_line: reference2.locator.end_line
|
|
97226
|
-
});
|
|
97227
|
-
}
|
|
97228
|
-
}
|
|
97229
|
-
return removed;
|
|
97230
|
-
}
|
|
97231
|
-
var REMOVED_CITATIONS_NOTE = "These earlier citations are no longer in their sections. If you meant to replace or remove them, nothing needs doing; otherwise repeat each with its earlier lines to keep that evidence.";
|
|
97232
|
-
var init_approvedRevisionReferences = __esm(() => {
|
|
97233
|
-
init_zod();
|
|
97234
|
-
init_submittedSourceLocator();
|
|
97235
|
-
init_productionFeedback();
|
|
97236
|
-
init_src2();
|
|
97237
|
-
init_articleRegionBaselines();
|
|
97238
|
-
init_settledReferenceRelocation();
|
|
97239
|
-
init_articleSourceReader();
|
|
97240
|
-
});
|
|
97241
|
-
|
|
97242
97619
|
// src/project/approvedPageMove.ts
|
|
97243
97620
|
var exports_approvedPageMove = {};
|
|
97244
97621
|
__export(exports_approvedPageMove, {
|
|
@@ -97589,13 +97966,19 @@ async function composeRevisionCandidate(projectRoot, request, input, options) {
|
|
|
97589
97966
|
throw new TypeError("Revision section identities must be unique");
|
|
97590
97967
|
}
|
|
97591
97968
|
const title = exports_external.string().trim().min(1).parse(metadata.title);
|
|
97969
|
+
const before = new Map(approvedContextSectionsInMarkdown(request.target.markdown).map((section) => [section.id, section.readerVisibleBody]));
|
|
97970
|
+
const reminders = [];
|
|
97592
97971
|
const references = await prepareRevisionReferences({
|
|
97593
97972
|
projectRoot,
|
|
97594
97973
|
sourceRefs: request.target.source_refs,
|
|
97595
97974
|
previous: request.target.sections,
|
|
97596
97975
|
sectionIds: sections.map((section) => section.id),
|
|
97597
97976
|
edits: input.sections,
|
|
97598
|
-
remember: options.remember
|
|
97977
|
+
remember: options.remember,
|
|
97978
|
+
processedScopes: (request.processed_scopes ?? []).map((scope2) => scope2.source_ref),
|
|
97979
|
+
changedBodies: new Set(sections.filter((section) => before.get(section.id) !== section.readerVisibleBody).map((section) => section.id)),
|
|
97980
|
+
onReminder: (reminder) => reminders.push(reminder),
|
|
97981
|
+
suggest: (reference2) => suggestedCitation(projectRoot, reference2, request.target.sections)
|
|
97599
97982
|
});
|
|
97600
97983
|
const projectedSections = sections.map((section) => ({
|
|
97601
97984
|
section_ref: `${request.target.article_id}#${section.id}`,
|
|
@@ -97604,7 +97987,7 @@ async function composeRevisionCandidate(projectRoot, request, input, options) {
|
|
|
97604
97987
|
markdown: section.readerVisibleBody,
|
|
97605
97988
|
markdown_digest: indexerProtocolDigest(section.readerVisibleBody)
|
|
97606
97989
|
}));
|
|
97607
|
-
return { markdown, metadata, title, references, projectedSections };
|
|
97990
|
+
return { markdown, metadata, title, references, projectedSections, reference_warnings: reminders };
|
|
97608
97991
|
}
|
|
97609
97992
|
async function completeApprovedRevision(input) {
|
|
97610
97993
|
return withProjectWriteLock(input.projectRoot, "compile-approved-revision", async () => {
|
|
@@ -97617,7 +98000,7 @@ async function completeApprovedRevision(input) {
|
|
|
97617
98000
|
if (request.refresh_sources)
|
|
97618
98001
|
throw new TypeError("Import the explicitly adjusted source inputs, then run context task adjust with refresh: true before submitting page content.");
|
|
97619
98002
|
await assertApprovedRevisionBase(input.projectRoot, request);
|
|
97620
|
-
const { markdown, metadata, title, references, projectedSections } = await composeRevisionCandidate(input.projectRoot, request, input, { remember: !input.preview });
|
|
98003
|
+
const { markdown, metadata, title, references, projectedSections, reference_warnings } = await composeRevisionCandidate(input.projectRoot, request, input, { remember: !input.preview });
|
|
97621
98004
|
await assertRevisionRequirements(input.projectRoot, request);
|
|
97622
98005
|
const approved = request.target.base_digest === null ? undefined : hydrateApprovedKnowledgeMarkdown({
|
|
97623
98006
|
content: await targetBytes(input.projectRoot, request.target.previous_path ?? request.target.path),
|
|
@@ -97660,7 +98043,7 @@ async function completeApprovedRevision(input) {
|
|
|
97660
98043
|
},
|
|
97661
98044
|
updated: new Date().toISOString()
|
|
97662
98045
|
}, 1);
|
|
97663
|
-
const
|
|
98046
|
+
const notes = citationNotes(removedCitations(request.target.sections, references), reference_warnings);
|
|
97664
98047
|
if (input.preview)
|
|
97665
98048
|
return {
|
|
97666
98049
|
protocol: "context.approved-revision-preview/v1",
|
|
@@ -97669,10 +98052,10 @@ async function completeApprovedRevision(input) {
|
|
|
97669
98052
|
before: request.target.markdown,
|
|
97670
98053
|
markdown,
|
|
97671
98054
|
changed: markdown !== request.target.markdown || indexerProtocolDigest(references) !== indexerProtocolDigest(request.target.sections),
|
|
97672
|
-
...
|
|
98055
|
+
...notes
|
|
97673
98056
|
};
|
|
97674
|
-
if (
|
|
97675
|
-
input.
|
|
98057
|
+
if (Object.keys(notes).length)
|
|
98058
|
+
input.onCitationNotes?.(notes);
|
|
97676
98059
|
if (request.processed_scopes)
|
|
97677
98060
|
await captureProcessedScopes(input.projectRoot, request.processed_scopes);
|
|
97678
98061
|
const approvedSections = validateArticleStructureEntries((await readKnowledgeStructure(input.projectRoot)).parsed?.articles ?? []).find((article) => article.article_id === request.target.article_id)?.sections;
|
|
@@ -99361,7 +99744,7 @@ function createContextWorkflowFacts(observation, authorities) {
|
|
|
99361
99744
|
const buildLogPending = runtimeEvents.configured && runtimeEvents.pending_kinds.includes("package.build.completed");
|
|
99362
99745
|
return {
|
|
99363
99746
|
workspace: {
|
|
99364
|
-
task_start_authorized: observation.taskPreparation !== "cleared",
|
|
99747
|
+
task_start_authorized: observation.taskPreparation !== "cleared" || outputOnlyMaintenance,
|
|
99365
99748
|
project_entry_valid: observation.projectEntryValid,
|
|
99366
99749
|
state_valid: workspaceStateValid(observation)
|
|
99367
99750
|
},
|
|
@@ -101062,7 +101445,8 @@ async function collectProjectStatusSnapshotInternal(projectRoot, options = {}) {
|
|
|
101062
101445
|
const maintenanceState = await readMaintenance2(projectRoot);
|
|
101063
101446
|
const maintenance = maintenanceState.active;
|
|
101064
101447
|
const authoring = production && !production.delivery && (dispatchProductionStage(production, productionCapabilitiesSchema.parse({})).state !== "ended" || draftStatus.count > 0 && draftStatus.diagnostics.length === 0);
|
|
101065
|
-
const
|
|
101448
|
+
const navigationOnly = !maintenance && !localRevision && !localUpdate && !localRollback && taskPreparation === "cleared" && !production && phaseStatus.projectEntryValid && await navigationOnlyChange(projectRoot, phaseStatus.packages);
|
|
101449
|
+
const deferDeliveryChecks = !maintenance && !localRevision && !localUpdate && !localRollback && !navigationOnly && (taskPreparation === "cleared" && !production || !!authoring);
|
|
101066
101450
|
const collectionsWithPages = new Set;
|
|
101067
101451
|
const approvedPages = await countFiles(join104(projectRoot, "knowledge"), (rel) => {
|
|
101068
101452
|
if (!isApprovedKnowledgeMarkdownPath(rel) || rel.startsWith("assets/"))
|
|
@@ -101096,7 +101480,7 @@ async function collectProjectStatusSnapshotInternal(projectRoot, options = {}) {
|
|
|
101096
101480
|
const indexerDrafts = productionCandidates.filter((candidate) => candidate.status === "draft");
|
|
101097
101481
|
const indexerRejected = productionCandidates.filter((candidate) => candidate.status === "rejected");
|
|
101098
101482
|
const draftCollections = [...new Set(indexerDrafts.map((candidate) => candidate.collection))].sort();
|
|
101099
|
-
const maintenanceOutputOnly = maintenance?.input.operation === "rebuild" || maintenance?.phase === "finishing" || maintenance?.phase === "cancelling" && indexerDrafts.length === 0;
|
|
101483
|
+
const maintenanceOutputOnly = navigationOnly || maintenance?.input.operation === "rebuild" || maintenance?.phase === "finishing" || maintenance?.phase === "cancelling" && indexerDrafts.length === 0;
|
|
101100
101484
|
const sourceUpdate = !maintenance && !localRevision && !localUpdate && !localRollback && !production && draftStatus.count === 0 && approvedPages > 0 ? await Promise.resolve().then(() => (init_pendingSourceUpdates(), exports_pendingSourceUpdates)).then(({ inspectPendingSourceUpdates: inspectPendingSourceUpdates2 }) => inspectPendingSourceUpdates2(projectRoot)) : undefined;
|
|
101101
101485
|
const observation = {
|
|
101102
101486
|
versionCurrent: phaseStatus.projectEntryValid && !deferDeliveryChecks ? (await inspectWorkspaceVersion(projectRoot)).current : false,
|
|
@@ -101296,6 +101680,28 @@ async function reevaluateProjectStatusWorkflow(input) {
|
|
|
101296
101680
|
async function collectProjectStatus(projectRoot, options = {}) {
|
|
101297
101681
|
return (await collectProjectStatusSnapshot(projectRoot, options)).status;
|
|
101298
101682
|
}
|
|
101683
|
+
async function navigationOnlyChange(projectRoot, packages) {
|
|
101684
|
+
const { KNOWLEDGE_MAP_PATH: KNOWLEDGE_MAP_PATH2 } = await Promise.resolve().then(() => (init_knowledgeMap2(), exports_knowledgeMap));
|
|
101685
|
+
const { excludedWorkspaceContent: excludedWorkspaceContent2 } = await Promise.resolve().then(() => (init_workspaceContentSnapshot(), exports_workspaceContentSnapshot));
|
|
101686
|
+
const { execFile: execFile17 } = await import("node:child_process");
|
|
101687
|
+
const git4 = (...args) => new Promise((done) => execFile17("git", ["-C", projectRoot, ...args], { env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" }, timeout: 30000, maxBuffer: 67108864 }, (error, stdout) => done(error ? undefined : stdout)));
|
|
101688
|
+
const recorded = (await git4("log", "-1", "--format=%H", "--", "changelog.yaml"))?.trim();
|
|
101689
|
+
if (recorded) {
|
|
101690
|
+
const changed = [
|
|
101691
|
+
...(await git4("diff", "--name-only", "--relative", recorded, "--"))?.split(`
|
|
101692
|
+
`) ?? [],
|
|
101693
|
+
...(await git4("ls-files", "--others", "--exclude-standard"))?.split(`
|
|
101694
|
+
`) ?? []
|
|
101695
|
+
].filter((path2) => path2 && path2 !== "package.json" && !excludedWorkspaceContent2(path2));
|
|
101696
|
+
if (changed.includes(KNOWLEDGE_MAP_PATH2) && changed.every((path2) => path2 === KNOWLEDGE_MAP_PATH2 || !/^(?:knowledge|sources|src)\//u.test(path2)))
|
|
101697
|
+
return true;
|
|
101698
|
+
}
|
|
101699
|
+
const latest = (await readWorkspaceChangelog(projectRoot).catch(() => []))[0];
|
|
101700
|
+
if (!latest || !latest.triggers.every((trigger) => trigger.kind === "navigation"))
|
|
101701
|
+
return false;
|
|
101702
|
+
const freshness = await readPackageFreshnessStatus(projectRoot, packages);
|
|
101703
|
+
return freshness.diagnostics.length > 0 || freshness.packages.length < packages.length || freshness.packages.some((item) => item.state !== "ready");
|
|
101704
|
+
}
|
|
101299
101705
|
var init_status = __esm(() => {
|
|
101300
101706
|
init_documentCaptureAvailability();
|
|
101301
101707
|
init_productionPlanning();
|
|
@@ -106745,14 +107151,19 @@ async function runLarkResourceCommand(runner2, args, options) {
|
|
|
106745
107151
|
}
|
|
106746
107152
|
return result.stdout;
|
|
106747
107153
|
}
|
|
107154
|
+
function larkPermissionGuidance(error) {
|
|
107155
|
+
const stderr = error instanceof Error && "stderr" in error && typeof error.stderr === "string" ? error.stderr : "";
|
|
107156
|
+
const scope2 = error instanceof LarkResourceCommandError && error.missingScope || hasMissingScope(errorDetail(stderr)) || hasMissingScope(stderr);
|
|
107157
|
+
return scope2 ? "Request the missing permission for the app at https://open.larkoffice.com/app, then capture again." : "Ask the document's owner to share it with the capturing identity, then capture again.";
|
|
107158
|
+
}
|
|
106748
107159
|
function isLarkResourcePermissionDenied(error) {
|
|
106749
107160
|
if (!(error instanceof Error))
|
|
106750
107161
|
return false;
|
|
106751
107162
|
const stderr = "stderr" in error && typeof error.stderr === "string" ? error.stderr : "";
|
|
106752
107163
|
const detail = error instanceof LarkResourceCommandError ? { type: error.errorType, subtype: error.errorSubtype, code: error.code } : errorDetail(stderr);
|
|
106753
|
-
return error instanceof LarkResourceCommandError && error.missingScope || hasMissingScope(detail) || hasMissingScope(stderr) || String(detail?.code) === "403" || detail?.type === "authorization" && ["permission_denied", "access_denied", "missing_scope"].includes(String(detail.subtype ?? ""));
|
|
107164
|
+
return error instanceof LarkResourceCommandError && error.missingScope || hasMissingScope(detail) || hasMissingScope(stderr) || String(detail?.code) === "403" || String(detail?.code) === LARK_DOCUMENT_ACCESS_DENIED_CODE || errorDetail(error.message)?.code === Number(LARK_DOCUMENT_ACCESS_DENIED_CODE) || detail?.type === "authorization" && ["permission_denied", "access_denied", "missing_scope"].includes(String(detail.subtype ?? ""));
|
|
106754
107165
|
}
|
|
106755
|
-
var LarkResourceCommandError;
|
|
107166
|
+
var LarkResourceCommandError, LARK_DOCUMENT_ACCESS_DENIED_CODE = "3380004";
|
|
106756
107167
|
var init_larkResourceCommand = __esm(() => {
|
|
106757
107168
|
LarkResourceCommandError = class LarkResourceCommandError extends Error {
|
|
106758
107169
|
errorType;
|
|
@@ -106795,7 +107206,7 @@ var init_larkMediaDownload = __esm(() => {
|
|
|
106795
107206
|
|
|
106796
107207
|
// src/lib/larkWhiteboardExport.ts
|
|
106797
107208
|
import { mkdtemp as mkdtemp5, readFile as readFile91, rm as rm26 } from "node:fs/promises";
|
|
106798
|
-
import { tmpdir } from "node:os";
|
|
107209
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
106799
107210
|
import { join as join114 } from "node:path";
|
|
106800
107211
|
function stableJson2(value) {
|
|
106801
107212
|
if (value === undefined)
|
|
@@ -106826,7 +107237,7 @@ function canonicalWhiteboardPayload(value) {
|
|
|
106826
107237
|
};
|
|
106827
107238
|
}
|
|
106828
107239
|
async function exportLarkWhiteboardRaw(runner2, identity2, token) {
|
|
106829
|
-
const tempRoot = await mkdtemp5(join114(
|
|
107240
|
+
const tempRoot = await mkdtemp5(join114(tmpdir2(), "context-lark-whiteboard-"));
|
|
106830
107241
|
try {
|
|
106831
107242
|
await runLarkResourceCommand(runner2, [
|
|
106832
107243
|
"whiteboard",
|
|
@@ -106884,7 +107295,7 @@ var init_larkImagePolicy = __esm(() => {
|
|
|
106884
107295
|
import { createHash as createHash36 } from "node:crypto";
|
|
106885
107296
|
import { mkdtemp as mkdtemp6, readFile as readFile92, readdir as readdir27, rm as rm27 } from "node:fs/promises";
|
|
106886
107297
|
import { extname as extname12, join as join115 } from "node:path";
|
|
106887
|
-
import { tmpdir as
|
|
107298
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
106888
107299
|
function countByKind(items, status) {
|
|
106889
107300
|
const counts2 = new Map;
|
|
106890
107301
|
for (const item of items) {
|
|
@@ -106991,7 +107402,7 @@ async function downloadedFile(input) {
|
|
|
106991
107402
|
const bytes = await readFile92(input.localPath);
|
|
106992
107403
|
return { path: input.localPath, bytes, mediaType: mediaTypeFor(input.localPath, bytes), representation: "original" };
|
|
106993
107404
|
}
|
|
106994
|
-
const tempRoot = await mkdtemp6(join115(
|
|
107405
|
+
const tempRoot = await mkdtemp6(join115(tmpdir3(), "context-lark-resource-"));
|
|
106995
107406
|
try {
|
|
106996
107407
|
const representation = await downloadLarkMedia({ ...input, cwd: tempRoot });
|
|
106997
107408
|
const entries2 = (await readdir27(tempRoot, { withFileTypes: true })).filter((entry) => entry.isFile());
|
|
@@ -107070,7 +107481,7 @@ async function sheetMaterialization(resource, runner2, identity2) {
|
|
|
107070
107481
|
const sheetId = resource.attributes["sheet-id"];
|
|
107071
107482
|
if (token === undefined || sheetId === undefined)
|
|
107072
107483
|
throw new Error("embedded Sheet requires token and sheet-id");
|
|
107073
|
-
const tempRoot = await mkdtemp6(join115(
|
|
107484
|
+
const tempRoot = await mkdtemp6(join115(tmpdir3(), "context-lark-sheet-"));
|
|
107074
107485
|
try {
|
|
107075
107486
|
const outputPath = join115(tempRoot, "sheet.json");
|
|
107076
107487
|
const stdout = await runLarkResourceCommand(runner2, [
|
|
@@ -107479,7 +107890,7 @@ async function materializeLarkResources(input) {
|
|
|
107479
107890
|
required,
|
|
107480
107891
|
asset_paths: [],
|
|
107481
107892
|
...reasonCode === undefined ? {} : { reason_code: reasonCode },
|
|
107482
|
-
reason: error instanceof Error ? error.message : String(error)
|
|
107893
|
+
reason: `${error instanceof Error ? error.message : String(error)}${reasonCode === DOCUMENT_RESOURCE_PERMISSION_DENIED_REASON_CODE ? ` ${larkPermissionGuidance(error)}` : ""}`
|
|
107483
107894
|
});
|
|
107484
107895
|
}
|
|
107485
107896
|
};
|
|
@@ -107677,7 +108088,7 @@ var init_larkReadIdentity = __esm(() => {
|
|
|
107677
108088
|
});
|
|
107678
108089
|
|
|
107679
108090
|
// src/lib/feishu.ts
|
|
107680
|
-
import { spawn as
|
|
108091
|
+
import { spawn as spawn6 } from "node:child_process";
|
|
107681
108092
|
async function detectDocsFetchCapabilities(runner2) {
|
|
107682
108093
|
const result = await runner2(["docs", "+fetch", "--help"]).catch(() => ({
|
|
107683
108094
|
stdout: "",
|
|
@@ -108138,7 +108549,7 @@ async function readPrefetchedLarkDocument(url, prefetched) {
|
|
|
108138
108549
|
}, prefetched.identity);
|
|
108139
108550
|
}
|
|
108140
108551
|
var LARK_BIN = "lark-cli", MAX_FETCH_PAGES = 50, MAX_STRUCTURAL_FETCH_ATTEMPTS = 2, LarkCliNotInstalledError, LarkCliError, defaultRunner = (args, options) => new Promise((resolve8, reject) => {
|
|
108141
|
-
const child =
|
|
108552
|
+
const child = spawn6(process.env.CONTEXT_LARK_CLI_BIN?.trim() || LARK_BIN, args, {
|
|
108142
108553
|
...options?.cwd === undefined ? {} : { cwd: options.cwd },
|
|
108143
108554
|
stdio: ["ignore", "pipe", "pipe"]
|
|
108144
108555
|
});
|
|
@@ -108832,13 +109243,16 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
108832
109243
|
next_action: workspaceRouteReevaluation(input.phase.id)
|
|
108833
109244
|
};
|
|
108834
109245
|
}
|
|
109246
|
+
let degraded = [];
|
|
108835
109247
|
if (previousManifest && previousRevision !== undefined && fetched.revisionId === previousRevision) {
|
|
108836
109248
|
const previous3 = documentSnapshotFidelityState(previousManifest, readDocumentSnapshotCaptureReport({
|
|
108837
109249
|
projectRoot: input.projectRoot,
|
|
108838
109250
|
materializedAt,
|
|
108839
109251
|
manifest: previousManifest
|
|
108840
109252
|
}));
|
|
108841
|
-
|
|
109253
|
+
let lost = fetched.resourceMaterialization.items.filter((item) => previous3.resourceMaterialization?.items.some((old) => old.kind === item.kind && old.locator === item.locator && old.status === "materialized" && (item.status !== "materialized" || item.reason_code === "document.resource.preview" && old.reason_code !== "document.resource.preview")));
|
|
109254
|
+
degraded = lost.filter((item) => item.status === "materialized" || isNonBlockingDocumentResourceFailureReasonCode(item.reason_code));
|
|
109255
|
+
lost = lost.filter((item) => !degraded.includes(item));
|
|
108842
109256
|
if (lost.length)
|
|
108843
109257
|
throw new ContextError(ExitCode.WorkspaceStateError, "Previously captured resources were degraded; the existing snapshot was preserved. Check resource policy and access before retrying the explicit refresh.", {
|
|
108844
109258
|
category: ErrorCategory.PartialFailure,
|
|
@@ -109045,7 +109459,9 @@ async function runCaptureLarkPhaseUnlocked(input) {
|
|
|
109045
109459
|
...recovery === undefined ? [] : [recovery.diagnostic],
|
|
109046
109460
|
...fetched.identityFallback ? [`info: lark.capture.identity-fallback: capture used an identity fallback; document identity: ${fetched.accessIdentity}; embedded reads may use the fallback identity`] : [],
|
|
109047
109461
|
...fetched.fidelity.issues.map((issue) => `${issue.severity}: ${issue.code}: ${issue.block_type} × ${issue.count}: ${issue.reason}`),
|
|
109048
|
-
...fetched.resourceMaterialization.items.filter((item) => item.status === "failed" || item.kind === "poll" && item.reason?.includes("absent") === true).map((item) => `${item.status}: lark.capture.resource-${item.status}: ${item.kind}: ${item.reason ?? item.locator}`)
|
|
109462
|
+
...fetched.resourceMaterialization.items.filter((item) => item.status === "failed" || item.kind === "poll" && item.reason?.includes("absent") === true).map((item) => `${item.status}: lark.capture.resource-${item.status}: ${item.kind}: ${item.reason ?? item.locator}`),
|
|
109463
|
+
...fetched.resourceMaterialization.items.filter((item) => item.reason_code === "document.resource.preview").map((item) => `warning: lark.capture.resource-preview: ${item.kind}: ${item.reason ?? item.locator}`),
|
|
109464
|
+
...degraded.map((item) => `warning: lark.capture.resource-degraded: ${item.kind} ${item.locator} was captured before and is now ${item.status === "materialized" ? "a preview" : "a gap"}; its placeholder is not citable evidence`)
|
|
109049
109465
|
],
|
|
109050
109466
|
next_action: workspaceRouteReevaluation(input.phase.id)
|
|
109051
109467
|
};
|
|
@@ -109707,8 +110123,6 @@ async function completeCurrentProductionAction(input) {
|
|
|
109707
110123
|
});
|
|
109708
110124
|
if (!stage)
|
|
109709
110125
|
throw invalid3("The production stage expired. Read the current route; do not restore a previous process.");
|
|
109710
|
-
if (input.preview)
|
|
109711
|
-
throw invalid3("Stage files do not use the retired Author preview. Submit the current task files.");
|
|
109712
110126
|
if (!input.submissionPath || input.submissionPath === "-")
|
|
109713
110127
|
throw invalid3("Production requires a stage-local manifest file, not stdin.");
|
|
109714
110128
|
const path3 = relative32(resolve41(input.projectRoot, productionAgentDirectory(stage.id)), resolve41(input.cwd, input.submissionPath));
|
|
@@ -109718,13 +110132,19 @@ async function completeCurrentProductionAction(input) {
|
|
|
109718
110132
|
throw invalid3("The manifest must identify the current production stage. No tasks were saved.");
|
|
109719
110133
|
}
|
|
109720
110134
|
const submission = { projectRoot: input.projectRoot, stage: stage.id, path: path3, manifest, multiAgent: input.multiAgent === true };
|
|
109721
|
-
if ("decision" in value)
|
|
110135
|
+
if ("decision" in value) {
|
|
110136
|
+
if (input.preview)
|
|
110137
|
+
throw invalid3("--preview checks article task files; a report decision has nothing to preview.");
|
|
109722
110138
|
return approveProductionReport({ ...submission, revision: input.revision });
|
|
110139
|
+
}
|
|
109723
110140
|
if (input.revision !== stage.id)
|
|
109724
110141
|
throw invalid3("Use the current stage revision; task input handles protect independent submissions.");
|
|
109725
|
-
if (!stage.planning_complete || "articles" in value)
|
|
110142
|
+
if (!stage.planning_complete || "articles" in value) {
|
|
110143
|
+
if (input.preview)
|
|
110144
|
+
throw invalid3("--preview checks article task files; submit the plan to have it checked.");
|
|
109726
110145
|
return submitProductionPlan(submission);
|
|
109727
|
-
|
|
110146
|
+
}
|
|
110147
|
+
return completeProductionSubmission({ ...submission, preview: input.preview === true });
|
|
109728
110148
|
}));
|
|
109729
110149
|
}
|
|
109730
110150
|
var import_yaml54;
|
|
@@ -109822,19 +110242,19 @@ async function completeCurrentIndexerActionInternal(input) {
|
|
|
109822
110242
|
...content3,
|
|
109823
110243
|
preview: true
|
|
109824
110244
|
});
|
|
109825
|
-
let
|
|
110245
|
+
let notes = {};
|
|
109826
110246
|
const candidate = await completeApprovedRevision2({
|
|
109827
110247
|
projectRoot: found.projectRoot,
|
|
109828
110248
|
revision: input.revision,
|
|
109829
110249
|
...content3,
|
|
109830
|
-
|
|
109831
|
-
|
|
110250
|
+
onCitationNotes: (value) => {
|
|
110251
|
+
notes = value;
|
|
109832
110252
|
}
|
|
109833
110253
|
});
|
|
109834
110254
|
return completedRevisionReceipt(found.projectRoot, semantic.stage, {
|
|
109835
110255
|
outcome: candidate === undefined ? "unchanged" : "candidate-prepared",
|
|
109836
110256
|
...candidate === undefined ? {} : { candidate_id: candidate.candidate_id },
|
|
109837
|
-
...
|
|
110257
|
+
...notes
|
|
109838
110258
|
}, input.managed === true, authorities);
|
|
109839
110259
|
}
|
|
109840
110260
|
if (semantic.stage === "structure-review") {
|
|
@@ -109877,7 +110297,6 @@ async function completedRevisionReceipt(projectRoot2, stage, result, managed, au
|
|
|
109877
110297
|
}
|
|
109878
110298
|
}
|
|
109879
110299
|
var init_indexerCurrentAction = __esm(() => {
|
|
109880
|
-
init_approvedRevisionReferences();
|
|
109881
110300
|
init_src2();
|
|
109882
110301
|
init_cliFeedback();
|
|
109883
110302
|
init_errors3();
|
|
@@ -110041,7 +110460,8 @@ async function completeApprovedRevisionSubmission(input) {
|
|
|
110041
110460
|
input: task.input,
|
|
110042
110461
|
outcome: receipt2.outcome ?? "candidate-prepared",
|
|
110043
110462
|
committed: state === "committed",
|
|
110044
|
-
...receipt2.removed_citations?.length ? { removed_citations: receipt2.removed_citations, removed_citations_note: receipt2.removed_citations_note } : {}
|
|
110463
|
+
...receipt2.removed_citations?.length ? { removed_citations: receipt2.removed_citations, removed_citations_note: receipt2.removed_citations_note } : {},
|
|
110464
|
+
...receipt2.reference_warnings?.length ? { reference_warnings: receipt2.reference_warnings, reference_warning_instruction: receipt2.reference_warning_instruction } : {}
|
|
110045
110465
|
});
|
|
110046
110466
|
workflow = receipt2.workflow;
|
|
110047
110467
|
const next2 = workflow?.current;
|
|
@@ -110119,7 +110539,7 @@ async function previewApprovedRevisionSubmission(input) {
|
|
|
110119
110539
|
return first < 0 || !issuedTask || !now2 || issuedTask.task !== fixed2.tasks[index3].task || issuedTask.input !== fixed2.tasks[index3].input || now2.revision !== issuedTask.revision || now2.context !== issuedTask.context;
|
|
110120
110540
|
};
|
|
110121
110541
|
const { composeRevisionCandidate: composeRevisionCandidate2 } = await Promise.resolve().then(() => (init_approvedRevision(), exports_approvedRevision));
|
|
110122
|
-
const { SubmissionInputError: SubmissionInputError2 } = await Promise.resolve().then(() => (init_productionFeedback(), exports_productionFeedback));
|
|
110542
|
+
const { SubmissionInputError: SubmissionInputError2, SubmissionInputErrors: SubmissionInputErrors2 } = await Promise.resolve().then(() => (init_productionFeedback(), exports_productionFeedback));
|
|
110123
110543
|
const issue = (error) => error instanceof SubmissionInputError2 ? { message: error.message, path: error.path, ...error.reason ? { reason_code: error.reason } : {} } : error instanceof exports_external.ZodError ? { message: error.issues.map((item) => item.message).join("; ") } : { message: error instanceof Error ? error.message : String(error) };
|
|
110124
110544
|
const pages = [];
|
|
110125
110545
|
for (const [index3, task] of fixed2.tasks.entries()) {
|
|
@@ -110145,18 +110565,17 @@ async function previewApprovedRevisionSubmission(input) {
|
|
|
110145
110565
|
throw new TypeError(`Task ${task.task} is not an approved revision.`);
|
|
110146
110566
|
const request = JSON.parse((await readProductionFile({ projectRoot: input.projectRoot, stage: manifest.stage, path: `${task.task}.input.json` })).text);
|
|
110147
110567
|
const content3 = "markdown" in semantic ? { markdown: semantic.markdown, ...semantic.sections === undefined ? {} : { sections: semantic.sections } } : { sections: semantic.sections };
|
|
110148
|
-
const { markdown, references } = await composeRevisionCandidate2(input.projectRoot, request, content3, { remember: false });
|
|
110149
|
-
const removed = removedCitations(request.target.sections, references);
|
|
110568
|
+
const { markdown, references, reference_warnings } = await composeRevisionCandidate2(input.projectRoot, request, content3, { remember: false });
|
|
110150
110569
|
pages.push({
|
|
110151
110570
|
task: task.task,
|
|
110152
110571
|
path: request.target.path,
|
|
110153
110572
|
ok: true,
|
|
110154
110573
|
issues: [],
|
|
110155
110574
|
changed: markdown !== request.target.markdown || indexerProtocolDigest(references) !== indexerProtocolDigest(request.target.sections),
|
|
110156
|
-
...
|
|
110575
|
+
...citationNotes(removedCitations(request.target.sections, references), reference_warnings)
|
|
110157
110576
|
});
|
|
110158
110577
|
} catch (error) {
|
|
110159
|
-
pages.push({ task: task.task, ok: false, issues: [issue(error)] });
|
|
110578
|
+
pages.push({ task: task.task, ok: false, issues: error instanceof SubmissionInputErrors2 ? error.errors.map(issue) : [issue(error)] });
|
|
110160
110579
|
}
|
|
110161
110580
|
}
|
|
110162
110581
|
const reissue = pages.some((page) => page.issues.some((issue2) => issue2.reason_code === "task-input-stale"));
|
|
@@ -116032,7 +116451,7 @@ init_debugTrace();
|
|
|
116032
116451
|
init_src();
|
|
116033
116452
|
init_debugTrace();
|
|
116034
116453
|
import { createHash as createHash39 } from "node:crypto";
|
|
116035
|
-
import { spawn as
|
|
116454
|
+
import { spawn as spawn7 } from "node:child_process";
|
|
116036
116455
|
function digestText2(value, includeTail) {
|
|
116037
116456
|
const filtered = redactIndexerOutputText({
|
|
116038
116457
|
channel: includeTail ? "stderr" : "stdout",
|
|
@@ -116168,7 +116587,7 @@ execution scope cleanup failed`, true)
|
|
|
116168
116587
|
try {
|
|
116169
116588
|
receipt2 = await new Promise((resolve8, reject) => {
|
|
116170
116589
|
let settled = false;
|
|
116171
|
-
const child =
|
|
116590
|
+
const child = spawn7(process.execPath, [this.cliEntryPath, ...args], {
|
|
116172
116591
|
cwd: input.cwd,
|
|
116173
116592
|
env: { ...process.env, ...debugChildEnvironment() },
|
|
116174
116593
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -117676,14 +118095,16 @@ async function executeClose(cwd, command2) {
|
|
|
117676
118095
|
throw new Error("unsupported close command");
|
|
117677
118096
|
await runProjectCloseCommand({ cwd, format: outputFormat(options) ?? "text" });
|
|
117678
118097
|
}
|
|
117679
|
-
async function executeBuild(cwd,
|
|
118098
|
+
async function executeBuild(cwd, invocation) {
|
|
118099
|
+
const command2 = invocation.command;
|
|
117680
118100
|
const options = parseOptions(command2.slice(1), new Set(["--format"]), new Set(["--verbose"]));
|
|
117681
118101
|
if (options === undefined || options.positionals.length > 0)
|
|
117682
118102
|
throw new Error("unsupported build command");
|
|
117683
118103
|
await runProjectBuildCommand({
|
|
117684
118104
|
cwd,
|
|
117685
118105
|
format: outputFormat(options) ?? "text",
|
|
117686
|
-
verbose: options.flags.has("--verbose")
|
|
118106
|
+
verbose: options.flags.has("--verbose"),
|
|
118107
|
+
execution: { managed: invocation.managed, authorities: invocation.authorities }
|
|
117687
118108
|
});
|
|
117688
118109
|
}
|
|
117689
118110
|
async function executeReviewApproveAll(cwd, invocation) {
|
|
@@ -117740,7 +118161,7 @@ async function executeCommand(cwd, invocation) {
|
|
|
117740
118161
|
return;
|
|
117741
118162
|
}
|
|
117742
118163
|
if (command2 === "build") {
|
|
117743
|
-
await executeBuild(cwd, invocation
|
|
118164
|
+
await executeBuild(cwd, invocation);
|
|
117744
118165
|
return;
|
|
117745
118166
|
}
|
|
117746
118167
|
if (command2 === "review" && subcommand === "approve-all") {
|
|
@@ -118139,6 +118560,28 @@ function registerDebugCommands(program2) {
|
|
|
118139
118560
|
});
|
|
118140
118561
|
}
|
|
118141
118562
|
|
|
118563
|
+
// src/commands/nextRoute.ts
|
|
118564
|
+
init_workflowCommandOptions();
|
|
118565
|
+
function nextRouteExecution(program2, command2 = {}) {
|
|
118566
|
+
const root2 = program2.opts();
|
|
118567
|
+
return {
|
|
118568
|
+
managed: root2.workflowManaged === true || command2.managed === true,
|
|
118569
|
+
authorities: mergedWorkflowAuthorities(root2.workflowAuthority, command2.authorities ?? [])
|
|
118570
|
+
};
|
|
118571
|
+
}
|
|
118572
|
+
async function withNextRoute(program2, projectRoot, result, command2 = {}) {
|
|
118573
|
+
const next2 = result?.next_action;
|
|
118574
|
+
if (next2 !== undefined && next2.command !== "context status --format json")
|
|
118575
|
+
return result;
|
|
118576
|
+
try {
|
|
118577
|
+
const { collectProjectStatus: collectProjectStatus2 } = await Promise.resolve().then(() => (init_status(), exports_status));
|
|
118578
|
+
const status = await collectProjectStatus2(projectRoot, nextRouteExecution(program2, command2));
|
|
118579
|
+
return { ...result, workflow: status.workflow };
|
|
118580
|
+
} catch {
|
|
118581
|
+
return result;
|
|
118582
|
+
}
|
|
118583
|
+
}
|
|
118584
|
+
|
|
118142
118585
|
// src/commands/documentRevisionCommands.ts
|
|
118143
118586
|
init_cliFeedback();
|
|
118144
118587
|
init_errors3();
|
|
@@ -118493,7 +118936,8 @@ function registerDocumentRevisionCommand(program2) {
|
|
|
118493
118936
|
parseFailureNext: "Provide valid YAML or JSON."
|
|
118494
118937
|
});
|
|
118495
118938
|
const { registerKnowledgeMaintenance: registerKnowledgeMaintenance2 } = await Promise.resolve().then(() => (init_knowledgeMaintenance(), exports_knowledgeMaintenance));
|
|
118496
|
-
|
|
118939
|
+
const projectRoot = requireProjectRoot2();
|
|
118940
|
+
process.stdout.write(`${JSON.stringify(await withNextRoute(program2, projectRoot, await registerKnowledgeMaintenance2(projectRoot, value)))}
|
|
118497
118941
|
`);
|
|
118498
118942
|
});
|
|
118499
118943
|
task.command("record-fix").description("Record a mechanical correction made after the batch's approval and before its delivery").option("--input <file>", "YAML/JSON path and reason; - for stdin").option("--format <format>", "output format: json", "json").action(async (options) => {
|
|
@@ -118518,7 +118962,8 @@ function registerDocumentRevisionCommand(program2) {
|
|
|
118518
118962
|
if (options.format !== "json")
|
|
118519
118963
|
throw new TypeError("--format must be json");
|
|
118520
118964
|
const { advanceKnowledgeMaintenance: advanceKnowledgeMaintenance2 } = await Promise.resolve().then(() => (init_knowledgeMaintenance(), exports_knowledgeMaintenance));
|
|
118521
|
-
|
|
118965
|
+
const projectRoot = requireProjectRoot2();
|
|
118966
|
+
process.stdout.write(`${JSON.stringify(await withNextRoute(program2, projectRoot, await advanceKnowledgeMaintenance2(projectRoot, options.revision)))}
|
|
118522
118967
|
`);
|
|
118523
118968
|
});
|
|
118524
118969
|
task.command("maintenance-status").description("Inspect maintenance requests and the current cancellation revision").option("--format <format>", "output format: json", "json").action(async (options) => {
|
|
@@ -118645,6 +119090,10 @@ function registerDocumentRevisionCommand(program2) {
|
|
|
118645
119090
|
}
|
|
118646
119091
|
|
|
118647
119092
|
// src/commands/versionCommands.ts
|
|
119093
|
+
init_candidateLedger();
|
|
119094
|
+
init_errors3();
|
|
119095
|
+
init_cliFeedback();
|
|
119096
|
+
init_exitCode();
|
|
118648
119097
|
init_workspace();
|
|
118649
119098
|
init_workspaceChangelog();
|
|
118650
119099
|
init_status();
|
|
@@ -118657,10 +119106,20 @@ function registerVersionCommands(program2) {
|
|
|
118657
119106
|
if (!root2)
|
|
118658
119107
|
throw new TypeError("Run inside a Context workspace");
|
|
118659
119108
|
const { files: _, content_digest: _digest, snapshot_format: _format, ...status } = await inspectWorkspaceVersion(root2, options.base);
|
|
119109
|
+
const first = status.version === "0.0.0";
|
|
119110
|
+
const [major, minor, patch] = status.version.split(".").map(Number);
|
|
119111
|
+
const suggested = status.reusable_version ?? (first ? "0.1.0" : `${major}.${minor}.${patch + 1}`);
|
|
118660
119112
|
process.stdout.write(JSON.stringify({
|
|
118661
119113
|
...status,
|
|
118662
119114
|
next_action: { command: "context version record --input <file> --format json" },
|
|
118663
|
-
input_example: {
|
|
119115
|
+
input_example: {
|
|
119116
|
+
expected_digest: status.expected_digest,
|
|
119117
|
+
...options.base ? { base_ref: options.base } : {},
|
|
119118
|
+
version: suggested,
|
|
119119
|
+
title: "Summary",
|
|
119120
|
+
changes: ["Reader-visible changes"],
|
|
119121
|
+
triggers: [first ? { kind: "initial", description: "User requested initial knowledge production" } : { kind: "other", description: "What caused this change" }]
|
|
119122
|
+
}
|
|
118664
119123
|
}, null, 2) + `
|
|
118665
119124
|
`);
|
|
118666
119125
|
});
|
|
@@ -118682,6 +119141,20 @@ function registerVersionCommands(program2) {
|
|
|
118682
119141
|
...reference2 === undefined ? {} : { resourceReceiptsReference: reference2 }
|
|
118683
119142
|
};
|
|
118684
119143
|
const resourceReceipts = execution.resourceReceiptsReference === undefined ? undefined : await parseWorkflowResourceReceipts(execution.resourceReceiptsReference, root2);
|
|
119144
|
+
if ((await readCandidateRecords(root2)).some((candidate) => candidate.status === "draft")) {
|
|
119145
|
+
const current3 = (await collectProjectStatus(root2, {
|
|
119146
|
+
...execution,
|
|
119147
|
+
...resourceReceipts === undefined ? {} : { resourceReceipts }
|
|
119148
|
+
})).workflow.current;
|
|
119149
|
+
if (current3?.node !== "record-workspace-version") {
|
|
119150
|
+
throw new ContextError(ExitCode.WorkspaceStateError, `Drafts are still awaiting review; the current step is ${current3?.node ?? "unknown"}, not version recording.`, {
|
|
119151
|
+
category: ErrorCategory.WorkspaceStateInvalid,
|
|
119152
|
+
reason_code: "version-review-pending",
|
|
119153
|
+
next_action: { command: current3?.commands?.[0]?.command ?? workflowStatusCommand(execution) },
|
|
119154
|
+
next: "Finish the current step and Review first; the workflow reaches version recording after approval."
|
|
119155
|
+
});
|
|
119156
|
+
}
|
|
119157
|
+
}
|
|
118685
119158
|
const recorded = await recordWorkspaceVersion(root2, value);
|
|
118686
119159
|
let result;
|
|
118687
119160
|
try {
|
|
@@ -118956,9 +119429,10 @@ async function prepareActionCompletionOutput(input) {
|
|
|
118956
119429
|
...Array.isArray(result.reference_warnings) ? { reference_warning_count: result.reference_warnings.length } : {},
|
|
118957
119430
|
...Array.isArray(result.removed_citations) && result.removed_citations.length ? pick(result, ["removed_citations", "removed_citations_note"]) : {},
|
|
118958
119431
|
...result.removed_citations_note === undefined && outcomes.some((item) => Array.isArray(item.removed_citations)) ? { removed_citations_note: outcomes.find((item) => item.removed_citations_note !== undefined)?.removed_citations_note } : {},
|
|
119432
|
+
...result.reference_warning_instruction === undefined && outcomes.some((item) => Array.isArray(item.reference_warnings)) ? { reference_warning_instruction: outcomes.find((item) => item.reference_warning_instruction !== undefined)?.reference_warning_instruction } : {},
|
|
118959
119433
|
committed_count: Array.isArray(result.outcomes) ? outcomes.filter((item) => item.committed === true).length : null,
|
|
118960
119434
|
outcomes: outcomes.map((item) => ({
|
|
118961
|
-
...pick(item, ["task_key", "outcome", "committed", "removed_citations"]),
|
|
119435
|
+
...pick(item, ["task_key", "outcome", "committed", "removed_citations", "reference_warnings"]),
|
|
118962
119436
|
...item.message === undefined ? {} : { message: shortText(item.message) }
|
|
118963
119437
|
})),
|
|
118964
119438
|
outcomes_omitted: 0,
|
|
@@ -119048,21 +119522,32 @@ async function prepareKnownProductionTasks(input) {
|
|
|
119048
119522
|
if (!request || stage?.report_approved || (stage ? ![stage.id, request.revision].includes(input.revision) : request.revision !== input.revision)) {
|
|
119049
119523
|
throw invalid3("Use known tasks before report approval, with the current preparation revision. Approved stages use ordinary task amendments.");
|
|
119050
119524
|
}
|
|
119051
|
-
if (!stage) {
|
|
119525
|
+
if (!stage || stage.gaps.length) {
|
|
119052
119526
|
await prepareCurrentProductionStage({
|
|
119053
119527
|
projectRoot: input.projectRoot,
|
|
119054
|
-
revision: input.revision,
|
|
119528
|
+
revision: stage?.id ?? input.revision,
|
|
119055
119529
|
sources: [...new Set([...plan.articles.flatMap((article) => article.sources), ...plan.pending_scopes ?? []])]
|
|
119056
119530
|
});
|
|
119057
119531
|
stage = await readProductionStage(input.projectRoot);
|
|
119058
119532
|
}
|
|
119059
119533
|
const text11 = import_yaml57.default.stringify({ ...plan, stage: stage.id });
|
|
119060
|
-
|
|
119061
|
-
|
|
119062
|
-
|
|
119063
|
-
|
|
119064
|
-
|
|
119065
|
-
|
|
119534
|
+
let result;
|
|
119535
|
+
try {
|
|
119536
|
+
result = await submitProductionPlan({
|
|
119537
|
+
projectRoot: input.projectRoot,
|
|
119538
|
+
stage: stage.id,
|
|
119539
|
+
path: fixed2.path,
|
|
119540
|
+
manifest: { path: fixed2.path, text: text11, bytes: Buffer.byteLength(text11), digest: durableContentDigest(text11) }
|
|
119541
|
+
});
|
|
119542
|
+
} catch (error) {
|
|
119543
|
+
if (error instanceof ContextError && error.detail?.reason_code === "production-planning-refresh-required") {
|
|
119544
|
+
error.detail.next_action = {
|
|
119545
|
+
command: `context action prepare-current --revision ${stage.id} --input ${input.path} --format json`,
|
|
119546
|
+
instruction: "Restore or check the listed sources if needed, then rerun this command; it checks them again and submits the same tasks."
|
|
119547
|
+
};
|
|
119548
|
+
}
|
|
119549
|
+
throw error;
|
|
119550
|
+
}
|
|
119066
119551
|
return { ...result, next_action: { command: "context status --format json" } };
|
|
119067
119552
|
}));
|
|
119068
119553
|
}
|
|
@@ -119119,8 +119604,9 @@ function registerProjectActionCommands(program2) {
|
|
|
119119
119604
|
multiAgent: options.multiAgent === true,
|
|
119120
119605
|
...options.source.length ? { sources: options.source } : {}
|
|
119121
119606
|
});
|
|
119607
|
+
const output = "stage_state" in result || options.input ? await withNextRoute(program2, root2.projectRoot, result, { managed: options.managed === true }) : result;
|
|
119122
119608
|
await new Promise((resolve8, reject) => {
|
|
119123
|
-
process.stdout.write(serializeActionCompletion(
|
|
119609
|
+
process.stdout.write(serializeActionCompletion(output, options.format), (error) => {
|
|
119124
119610
|
if (error)
|
|
119125
119611
|
reject(error);
|
|
119126
119612
|
else
|
|
@@ -119128,7 +119614,7 @@ function registerProjectActionCommands(program2) {
|
|
|
119128
119614
|
});
|
|
119129
119615
|
});
|
|
119130
119616
|
});
|
|
119131
|
-
action.command("complete-current").description("Submit minimal semantic output for the exact current workflow revision").requiredOption("--revision <revision>", "workflow revision returned by context status").requiredOption("--input <file>", "YAML/JSON input path, or - for stdin").option("--managed", "continue under explicit current-conversation managed approval").option("--multi-agent", "this caller supports coordinating multiple independent production batch directories; default is one batch").addOption(new Option("--authority <authority>").hideHelp().argParser(collectWorkflowAuthorityOption).default([])).option("--preview", "
|
|
119617
|
+
action.command("complete-current").description("Submit minimal semantic output for the exact current workflow revision").requiredOption("--revision <revision>", "workflow revision returned by context status").requiredOption("--input <file>", "YAML/JSON input path, or - for stdin").option("--managed", "continue under explicit current-conversation managed approval").option("--multi-agent", "this caller supports coordinating multiple independent production batch directories; default is one batch").addOption(new Option("--authority <authority>").hideHelp().argParser(collectWorkflowAuthorityOption).default([])).option("--preview", "check without submitting: an approved revision, every page of a prepared revision batch, or production stage article files").option("--verbose", "include the full completion and next Route inline").option("--format <format>", "output format: json | yaml", "json").action(async (options) => withSubmissionState(async () => {
|
|
119132
119618
|
const format2 = options.format;
|
|
119133
119619
|
if (format2 !== "json" && format2 !== "yaml") {
|
|
119134
119620
|
throw new ContextError(ExitCode.UserError, "--format must be json or yaml", {
|
|
@@ -119299,6 +119785,7 @@ init_repoSources();
|
|
|
119299
119785
|
var import_yaml64 = __toESM(require_dist(), 1);
|
|
119300
119786
|
|
|
119301
119787
|
// src/project/repoSourceRecovery.ts
|
|
119788
|
+
init_gitProgress();
|
|
119302
119789
|
init_cliFeedback();
|
|
119303
119790
|
init_errors3();
|
|
119304
119791
|
init_exitCode();
|
|
@@ -119441,7 +119928,7 @@ async function repositoryRecoveryPlan(input) {
|
|
|
119441
119928
|
command: "context source restore --input .tmp/agent-payloads/repository-source-recovery.json --format json",
|
|
119442
119929
|
input: ".tmp/agent-payloads/repository-source-recovery.json",
|
|
119443
119930
|
input_example: { schema: RECOVERY_SCHEMA, repositories: groups.filter((group) => !group.ready).map((group) => ({ source: group.sources[0], mode: "clone" })) },
|
|
119444
|
-
input_note: "Save input_example as the input file. Each entry restores every source of its group. " + "To reuse an existing checkout instead of cloning, set mode to local and add path."
|
|
119931
|
+
input_note: "Save input_example as the input file. Each entry restores every source of its group. " + "mode clone is already small: a shallow, partial clone of the registered commit that checks out only the group's required_subpaths. " + "To reuse an existing checkout instead of cloning, set mode to local and add path."
|
|
119445
119932
|
}
|
|
119446
119933
|
};
|
|
119447
119934
|
}
|
|
@@ -119496,18 +119983,18 @@ async function cloneCheckout(input) {
|
|
|
119496
119983
|
}
|
|
119497
119984
|
await mkdir42(dirname51(target), { recursive: true });
|
|
119498
119985
|
const cloneArgs = ["clone", "--no-checkout", "--depth=1", "--filter=blob:none", input.remote, target];
|
|
119986
|
+
const clone = (args) => runGitWithProgress(args, { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, label: "git clone" });
|
|
119499
119987
|
try {
|
|
119500
|
-
await
|
|
119501
|
-
} catch {
|
|
119988
|
+
await clone(cloneArgs);
|
|
119989
|
+
} catch (first) {
|
|
119502
119990
|
await rm29(target, { recursive: true, force: true });
|
|
119503
119991
|
try {
|
|
119504
|
-
|
|
119505
|
-
|
|
119506
|
-
|
|
119507
|
-
});
|
|
119992
|
+
if (first instanceof GitProgressError && first.kind !== "failed")
|
|
119993
|
+
throw first;
|
|
119994
|
+
await clone(["clone", "--no-checkout", "--depth=1", input.remote, target]);
|
|
119508
119995
|
} catch (error) {
|
|
119509
119996
|
await rm29(target, { recursive: true, force: true });
|
|
119510
|
-
const detail = error
|
|
119997
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
119511
119998
|
throw new ContextError(ExitCode.ExternalToolError, `cannot clone registered repository: ${input.remote}`, {
|
|
119512
119999
|
category: ErrorCategory.ExternalToolFailed,
|
|
119513
120000
|
remote: input.remote,
|
|
@@ -119518,9 +120005,11 @@ async function cloneCheckout(input) {
|
|
|
119518
120005
|
}
|
|
119519
120006
|
try {
|
|
119520
120007
|
try {
|
|
119521
|
-
await
|
|
119522
|
-
} catch {
|
|
119523
|
-
|
|
120008
|
+
await runGitWithProgress(["-C", target, "fetch", "--depth=1", "--filter=blob:none", "origin", input.ref], { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, label: "git fetch" });
|
|
120009
|
+
} catch (first) {
|
|
120010
|
+
if (first instanceof GitProgressError && first.kind !== "failed")
|
|
120011
|
+
throw first;
|
|
120012
|
+
await runGitWithProgress(["-C", target, "fetch", "--depth=1", "origin", input.ref], { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, label: "git fetch" });
|
|
119524
120013
|
}
|
|
119525
120014
|
const sparseDirectories = input.subpaths.length > 0 && (await Promise.all(input.subpaths.map((subpath) => git4(target, ["cat-file", "-t", `${input.ref}:${subpath}`])))).every((type) => type === "tree");
|
|
119526
120015
|
if (sparseDirectories) {
|
|
@@ -120972,7 +121461,7 @@ var import_yaml60 = __toESM(require_dist(), 1);
|
|
|
120972
121461
|
// src/lib/wikiDiscoveryProvider.ts
|
|
120973
121462
|
init_larkResourceCommand();
|
|
120974
121463
|
init_larkResourceScheduler();
|
|
120975
|
-
import { spawn as
|
|
121464
|
+
import { spawn as spawn8 } from "node:child_process";
|
|
120976
121465
|
|
|
120977
121466
|
class WikiDiscoveryError extends Error {
|
|
120978
121467
|
reason;
|
|
@@ -121055,7 +121544,7 @@ function defaultRunner2(signal) {
|
|
|
121055
121544
|
failure2 = new WikiDiscoveryError("request-interrupted", true, "Wiki request was interrupted or exceeded its 30 second deadline");
|
|
121056
121545
|
terminate();
|
|
121057
121546
|
};
|
|
121058
|
-
const child =
|
|
121547
|
+
const child = spawn8(process.env.CONTEXT_LARK_CLI_BIN?.trim() || "lark-cli", args, {
|
|
121059
121548
|
...options?.cwd ? { cwd: options.cwd } : {},
|
|
121060
121549
|
detached: process.platform !== "win32",
|
|
121061
121550
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -121693,6 +122182,35 @@ async function yamlReferences(input) {
|
|
|
121693
122182
|
collectStrings(parsed, strings);
|
|
121694
122183
|
return strings.some((value) => stringReferencesSource(value, input.source));
|
|
121695
122184
|
}
|
|
122185
|
+
var SOURCES_REGISTRY_EXCLUSION2 = Symbol.for("c4a.context.sources-registry-exclusion");
|
|
122186
|
+
function projectReferences(project, source2) {
|
|
122187
|
+
const references = [];
|
|
122188
|
+
project.sources.forEach((declared, index3) => {
|
|
122189
|
+
if (sourceIdentity(declared) === source2.name)
|
|
122190
|
+
references.push(`project.sources[${index3}]`);
|
|
122191
|
+
});
|
|
122192
|
+
project.phases.forEach((phase, index3) => {
|
|
122193
|
+
const direct = "source" in phase && sourceIdentity(phase.source) === source2.name;
|
|
122194
|
+
const resource = phase.reads.some((read) => resourceReferencesSource(read, source2));
|
|
122195
|
+
if (direct || resource)
|
|
122196
|
+
references.push(`project.phases[${index3}] (${phase.id})`);
|
|
122197
|
+
});
|
|
122198
|
+
return references;
|
|
122199
|
+
}
|
|
122200
|
+
async function declaredReferences(projectRoot2, source2) {
|
|
122201
|
+
const global = globalThis;
|
|
122202
|
+
const previous3 = global[SOURCES_REGISTRY_EXCLUSION2];
|
|
122203
|
+
global[SOURCES_REGISTRY_EXCLUSION2] = new Set([source2.name]);
|
|
122204
|
+
let project;
|
|
122205
|
+
try {
|
|
122206
|
+
project = (await loadContextProjectModule(projectRoot2)).project;
|
|
122207
|
+
} catch {
|
|
122208
|
+
project = undefined;
|
|
122209
|
+
} finally {
|
|
122210
|
+
global[SOURCES_REGISTRY_EXCLUSION2] = previous3;
|
|
122211
|
+
}
|
|
122212
|
+
return projectReferences(project ?? (await loadContextProjectModule(projectRoot2)).project, source2);
|
|
122213
|
+
}
|
|
121696
122214
|
async function collectSourceReferences(projectRoot2, source2) {
|
|
121697
122215
|
const references = new Set;
|
|
121698
122216
|
const { currentLedger: currentLedger2, currentSpec: currentSpec2 } = await Promise.resolve().then(() => (init_indexerMainRunStoreRecords(), exports_indexerMainRunStoreRecords));
|
|
@@ -121704,17 +122222,8 @@ async function collectSourceReferences(projectRoot2, source2) {
|
|
|
121704
122222
|
if (values2.some((value) => stringReferencesSource(value, source2)))
|
|
121705
122223
|
references.add(`active Indexer ${entry.indexer_id}`);
|
|
121706
122224
|
}
|
|
121707
|
-
const
|
|
121708
|
-
|
|
121709
|
-
if (sourceIdentity(declared) === source2.name)
|
|
121710
|
-
references.add(`project.sources[${index3}]`);
|
|
121711
|
-
});
|
|
121712
|
-
loaded.project.phases.forEach((phase, index3) => {
|
|
121713
|
-
const direct = "source" in phase && sourceIdentity(phase.source) === source2.name;
|
|
121714
|
-
const resource = phase.reads.some((read) => resourceReferencesSource(read, source2));
|
|
121715
|
-
if (direct || resource)
|
|
121716
|
-
references.add(`project.phases[${index3}] (${phase.id})`);
|
|
121717
|
-
});
|
|
122225
|
+
for (const reference2 of await declaredReferences(projectRoot2, source2))
|
|
122226
|
+
references.add(reference2);
|
|
121718
122227
|
for (const candidate of await readCandidateRecords(projectRoot2)) {
|
|
121719
122228
|
if (candidate.source_refs.some((ref2) => stringReferencesSource(ref2, source2))) {
|
|
121720
122229
|
references.add(`draft candidate ${candidate.candidate_id}`);
|
|
@@ -123282,10 +123791,13 @@ function registerProjectCloseAndBuildCommands(program2) {
|
|
|
123282
123791
|
category: ErrorCategory.UserInputInvalid
|
|
123283
123792
|
});
|
|
123284
123793
|
}
|
|
123794
|
+
const { workflowAuthorities: workflowAuthorities2 } = await Promise.resolve().then(() => (init_workflowCommandOptions(), exports_workflowCommandOptions));
|
|
123795
|
+
const root2 = program2.opts();
|
|
123285
123796
|
if (await runProjectBuildCommand({
|
|
123286
123797
|
cwd: process.cwd(),
|
|
123287
123798
|
format: options.format === "json" ? "json" : "text",
|
|
123288
|
-
verbose: options.verbose === true
|
|
123799
|
+
verbose: options.verbose === true,
|
|
123800
|
+
execution: { managed: root2.workflowManaged === true, authorities: workflowAuthorities2(root2.workflowAuthority) }
|
|
123289
123801
|
})) {
|
|
123290
123802
|
return;
|
|
123291
123803
|
}
|
|
@@ -123380,6 +123892,21 @@ async function digest9(root2) {
|
|
|
123380
123892
|
await visit4(root2, "");
|
|
123381
123893
|
return hash5.digest("hex");
|
|
123382
123894
|
}
|
|
123895
|
+
async function assertOwnedDirectory(target, existing) {
|
|
123896
|
+
if (!existing.isDirectory() || existing.isSymbolicLink())
|
|
123897
|
+
conflict(target);
|
|
123898
|
+
const markerPath = join140(target, MARKER);
|
|
123899
|
+
if (!(await stat11(markerPath))?.isFile())
|
|
123900
|
+
conflict(target);
|
|
123901
|
+
let marker;
|
|
123902
|
+
try {
|
|
123903
|
+
marker = JSON.parse(await readFile115(markerPath, "utf8"));
|
|
123904
|
+
} catch {
|
|
123905
|
+
conflict(target);
|
|
123906
|
+
}
|
|
123907
|
+
if (marker?.owner !== "context-plugin-local" || marker.digest !== await digest9(target))
|
|
123908
|
+
conflict(target);
|
|
123909
|
+
}
|
|
123383
123910
|
async function installLocalSkills(root2, path3, dryRun, agent) {
|
|
123384
123911
|
if (!path3.trim())
|
|
123385
123912
|
conflict("--local requires a non-empty path");
|
|
@@ -123399,14 +123926,7 @@ async function installLocalSkills(root2, path3, dryRun, agent) {
|
|
|
123399
123926
|
for (const entry of await readdir35(join140(root2, agent, "commands"), { withFileTypes: true })) {
|
|
123400
123927
|
if (!entry.isFile() || !entry.name.endsWith(".md"))
|
|
123401
123928
|
continue;
|
|
123402
|
-
|
|
123403
|
-
if (agent === "claude" && !["context-plan.md", "context-repo-content.md"].includes(entry.name)) {
|
|
123404
|
-
const frontmatter2 = /^(---\r?\n)([\s\S]*?)(\r?\n---(?:\r?\n|$))/.exec(content3);
|
|
123405
|
-
if (!frontmatter2)
|
|
123406
|
-
conflict(join140(root2, agent, "commands", entry.name));
|
|
123407
|
-
content3 = `${frontmatter2[1]}disable-model-invocation: true
|
|
123408
|
-
${frontmatter2[2].replace(/^disable-model-invocation:.*\r?\n?/mu, "")}${frontmatter2[3]}${content3.slice(frontmatter2[0].length)}`;
|
|
123409
|
-
}
|
|
123929
|
+
const content3 = await readFile115(join140(root2, agent, "commands", entry.name), "utf8");
|
|
123410
123930
|
const target = join140(commandsRoot, entry.name);
|
|
123411
123931
|
const marker = join140(commandsRoot, `.context-${entry.name}.json`);
|
|
123412
123932
|
for (const file of [target, marker]) {
|
|
@@ -123443,35 +123963,43 @@ ${frontmatter2[2].replace(/^disable-model-invocation:.*\r?\n?/mu, "")}${frontmat
|
|
|
123443
123963
|
continue;
|
|
123444
123964
|
}
|
|
123445
123965
|
const existing = await stat11(target);
|
|
123446
|
-
if (existing)
|
|
123447
|
-
|
|
123448
|
-
conflict(target);
|
|
123449
|
-
const markerPath = join140(target, MARKER);
|
|
123450
|
-
if (!(await stat11(markerPath))?.isFile())
|
|
123451
|
-
conflict(target);
|
|
123452
|
-
let marker;
|
|
123453
|
-
try {
|
|
123454
|
-
marker = JSON.parse(await readFile115(markerPath, "utf8"));
|
|
123455
|
-
} catch {
|
|
123456
|
-
conflict(target);
|
|
123457
|
-
}
|
|
123458
|
-
if (marker?.owner !== "context-plugin-local" || marker.digest !== await digest9(target))
|
|
123459
|
-
conflict(target);
|
|
123460
|
-
}
|
|
123966
|
+
if (existing)
|
|
123967
|
+
await assertOwnedDirectory(target, existing);
|
|
123461
123968
|
plans.push({ name: entry.name, source: source2, target, hash: await digest9(source2), exists: !!existing });
|
|
123462
123969
|
}
|
|
123463
123970
|
if (!plans.length)
|
|
123464
123971
|
conflict(sourceRoot);
|
|
123972
|
+
const resourcePlans = [];
|
|
123973
|
+
const resourcesRoot = join140(targetRoot, "resources");
|
|
123974
|
+
if (agent === "claude" || agent === "cursor") {
|
|
123975
|
+
const resourceSource = join140(root2, agent, "resources");
|
|
123976
|
+
if (await stat11(resourceSource)) {
|
|
123977
|
+
await checkParents(resourcesRoot);
|
|
123978
|
+
for (const entry of (await readdir35(resourceSource, { withFileTypes: true })).sort((a2, b) => a2.name.localeCompare(b.name))) {
|
|
123979
|
+
if (!entry.isDirectory())
|
|
123980
|
+
continue;
|
|
123981
|
+
const source2 = join140(resourceSource, entry.name);
|
|
123982
|
+
const target = join140(resourcesRoot, entry.name);
|
|
123983
|
+
const existing = await stat11(target);
|
|
123984
|
+
if (existing)
|
|
123985
|
+
await assertOwnedDirectory(target, existing);
|
|
123986
|
+
resourcePlans.push({ name: entry.name, source: source2, target, hash: await digest9(source2), exists: !!existing });
|
|
123987
|
+
}
|
|
123988
|
+
}
|
|
123989
|
+
}
|
|
123465
123990
|
if (!dryRun) {
|
|
123466
123991
|
await mkdir45(skillsRoot, { recursive: true });
|
|
123467
|
-
|
|
123468
|
-
|
|
123992
|
+
if (resourcePlans.length)
|
|
123993
|
+
await mkdir45(resourcesRoot, { recursive: true });
|
|
123994
|
+
for (const plan of [...plans, ...resourcePlans]) {
|
|
123995
|
+
const resource = resourcePlans.includes(plan);
|
|
123996
|
+
const staging = await mkdtemp7(join140(dirname54(plan.target), ".context-install-"));
|
|
123469
123997
|
const candidate = join140(staging, "candidate");
|
|
123470
123998
|
const previous3 = join140(staging, "previous");
|
|
123471
123999
|
let moved = false;
|
|
123472
124000
|
try {
|
|
123473
124001
|
await cp3(plan.source, candidate, { recursive: true });
|
|
123474
|
-
if (agent === "claude" || agent === "cursor" && ["context-plan", "context-repo-content"].includes(plan.name)) {
|
|
124002
|
+
if (!resource && (agent === "claude" || agent === "cursor" && ["context-plan", "context-repo-content"].includes(plan.name))) {
|
|
123475
124003
|
const skillFile = join140(candidate, "SKILL.md");
|
|
123476
124004
|
const content3 = await readFile115(skillFile, "utf8");
|
|
123477
124005
|
const parts = /^(---\r?\n)([\s\S]*?)(\r?\n---(?:\r?\n|$))/.exec(content3);
|
|
@@ -123524,7 +124052,8 @@ ${frontmatter2}${parts[3]}${content3.slice(parts[0].length)}`);
|
|
|
123524
124052
|
...agent === "codex" ? ["Codex uses skill entries, not a commands directory; bundled invocation policies are preserved."] : [],
|
|
123525
124053
|
...agent === "cursor" ? ["Cursor command entries are separated; hiding Provider skills from its command menu is not guaranteed."] : [],
|
|
123526
124054
|
...plans.map((plan) => `skills/${plan.name}`),
|
|
123527
|
-
...commandPlans.map((plan) => `commands/${plan.name}`)
|
|
124055
|
+
...commandPlans.map((plan) => `commands/${plan.name}`),
|
|
124056
|
+
...resourcePlans.map((plan) => `resources/${plan.name}`)
|
|
123528
124057
|
]
|
|
123529
124058
|
});
|
|
123530
124059
|
}
|
|
@@ -124699,6 +125228,12 @@ function isDirectCliInvocation(metaUrl, argv1) {
|
|
|
124699
125228
|
}
|
|
124700
125229
|
var isDirectInvocation = typeof process !== "undefined" && isDirectCliInvocation(import.meta.url, process.argv[1]);
|
|
124701
125230
|
if (isDirectInvocation) {
|
|
125231
|
+
for (const stream of [process.stdout, process.stderr]) {
|
|
125232
|
+
stream.on("error", (error) => {
|
|
125233
|
+
if (error.code !== "EPIPE")
|
|
125234
|
+
throw error;
|
|
125235
|
+
});
|
|
125236
|
+
}
|
|
124702
125237
|
cli_main().catch((err) => {
|
|
124703
125238
|
handleCliFailure(err);
|
|
124704
125239
|
});
|