@c4a/context-cli 0.7.93 → 0.7.94

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 CHANGED
@@ -70646,25 +70646,31 @@ function inside(root, path2) {
70646
70646
  throw new SourceUnavailableError("Article source path escapes its captured scope", "source-path-outside-scope");
70647
70647
  }
70648
70648
  }
70649
- async function registeredRepoHistoryReader(projectRoot) {
70650
- const workspace = await realpath5(projectRoot);
70651
- const registry2 = await loadSourcesRegistry({ rootDir: projectRoot });
70652
- const roots = new Map;
70653
- const fetched = new Map;
70654
- const reads = new Map;
70655
- const objects = commandGitObjectReader();
70656
- const available = (directory, commit) => {
70649
+ function commitAvailability(fetched, fetch = true) {
70650
+ return (directory, commit) => {
70657
70651
  const key = `${directory}\x00${commit}`;
70658
70652
  let result = fetched.get(key);
70659
70653
  if (!result) {
70660
- result = execute("git", ["-C", directory, "cat-file", "-e", `${commit}^{commit}`], { timeout: 5000, env: { ...process.env, GIT_NO_LAZY_FETCH: "1" } }).then(() => true, () => execute("git", ["-C", directory, "fetch", "--quiet", "--depth=1", "origin", commit], { timeout: 120000 }).then(() => true, () => false));
70654
+ result = execute("git", ["-C", directory, "cat-file", "-e", `${commit}^{commit}`], { timeout: 5000, env: { ...process.env, GIT_NO_LAZY_FETCH: "1" } }).then(() => true, () => !fetch ? false : execute("git", ["-C", directory, "fetch", "--quiet", "--depth=1", "origin", commit], { timeout: 120000 }).then(() => true, () => false));
70661
70655
  fetched.set(key, result);
70662
70656
  }
70663
70657
  return result;
70664
70658
  };
70659
+ }
70660
+ function missingCommit(commit) {
70661
+ return new SourceUnavailableError(`Commit ${commit} is not available in the registered checkout; fetch and check out the registered commit, then retry`, "source-history-missing");
70662
+ }
70663
+ async function registeredRepoHistoryReader(projectRoot) {
70664
+ const workspace = await realpath5(projectRoot);
70665
+ const registry2 = await loadSourcesRegistry({ rootDir: projectRoot });
70666
+ const roots = new Map;
70667
+ const fetched = new Map;
70668
+ const reads = new Map;
70669
+ const objects = commandGitObjectReader();
70670
+ const available = commitAvailability(fetched);
70665
70671
  async function readAt(directory, path2, commit) {
70666
70672
  if (!await available(directory, commit))
70667
- throw new SourceUnavailableError(`Commit ${commit} is not available in the registered checkout`, "source-history-missing");
70673
+ throw missingCommit(commit);
70668
70674
  return decodeSource(await objects.read(directory, commit, path2));
70669
70675
  }
70670
70676
  return async (sourceRef, path2, commit) => {
@@ -70702,11 +70708,12 @@ function decodeSource(bytes) {
70702
70708
  throw new SourceUnavailableError("The cited source is not UTF-8 text", "source-not-text");
70703
70709
  }
70704
70710
  }
70705
- async function registeredArticleSourceReader(projectRoot) {
70711
+ async function registeredArticleSourceReader(projectRoot, options = {}) {
70706
70712
  let repoContentRead;
70707
70713
  const workspace = await realpath5(projectRoot);
70708
70714
  const registry2 = await loadSourcesRegistry({ rootDir: projectRoot });
70709
70715
  const objects = commandGitObjectReader();
70716
+ const available = commitAvailability(new Map, options.fetchMissingCommits === true);
70710
70717
  const sources = new Map;
70711
70718
  for (const [kind, entries] of [
70712
70719
  ["repo", registry2.repos],
@@ -70741,6 +70748,8 @@ async function registeredArticleSourceReader(projectRoot) {
70741
70748
  if (!("ref" in entry) || !/^[a-f0-9]{40}(?:[a-f0-9]{24})?$/u.test(entry.ref)) {
70742
70749
  throw new SourceUnavailableError("Article source requires a captured fixed commit, not a moving ref", "source-ref-unpinned");
70743
70750
  }
70751
+ if (!await available(root, entry.ref))
70752
+ throw missingCommit(entry.ref);
70744
70753
  return { root, commit: entry.ref };
70745
70754
  }
70746
70755
  const manifestPath = resolve19(workspace, ("snapshot" in entry ? entry.snapshot?.manifest : undefined) ?? `${entry.materializedAt}/manifest.json`);
@@ -78250,7 +78259,7 @@ async function relocateUnchangedReference(_root, read, reference2) {
78250
78259
  return createArticleReferenceObserver(read)(reference2);
78251
78260
  }
78252
78261
  async function inspectSettledReferences(root, articles, scopes, _previous = [], options = {}) {
78253
- const read = await registeredArticleSourceReader(root);
78262
+ const read = await registeredArticleSourceReader(root, { fetchMissingCommits: options.fetchMissingCommits === true });
78254
78263
  const observe = createArticleReferenceObserver(read);
78255
78264
  const observations = [];
78256
78265
  const fileDigests = {};
@@ -82454,12 +82463,12 @@ import { promisify as promisify7 } from "node:util";
82454
82463
  import { realpath as realpath8 } from "node:fs/promises";
82455
82464
  async function workspaceVersionComparison(root, version3, paths, requested) {
82456
82465
  const git = async (...args) => (await exec3("git", args, { cwd: root, maxBuffer: 16 * 1024 * 1024 })).stdout;
82466
+ let embedded;
82457
82467
  try {
82458
- if (await realpath8((await git("rev-parse", "--show-toplevel")).trim()) !== await realpath8(root))
82459
- throw new Error("Not an independent Git workspace");
82468
+ embedded = await realpath8((await git("rev-parse", "--show-toplevel")).trim()) !== await realpath8(root);
82460
82469
  } catch {
82461
82470
  if (requested)
82462
- throw new TypeError("A Git comparison base requires an independent Git workspace");
82471
+ throw new TypeError("A Git comparison base requires the workspace to be inside a Git repository");
82463
82472
  return { base_ref: null, base_commit: null, tagged: false, added: paths, updated: [], removed: [] };
82464
82473
  }
82465
82474
  const commit = async (ref2) => {
@@ -82470,7 +82479,7 @@ async function workspaceVersionComparison(root, version3, paths, requested) {
82470
82479
  }
82471
82480
  };
82472
82481
  const tag = `refs/tags/v${version3}`;
82473
- const tagged = await commit(tag);
82482
+ const tagged = embedded ? null : await commit(tag);
82474
82483
  const base_ref = requested ?? (tagged ? tag : "HEAD");
82475
82484
  const base_commit = await commit(base_ref);
82476
82485
  if (requested && !base_commit)
@@ -82478,7 +82487,7 @@ async function workspaceVersionComparison(root, version3, paths, requested) {
82478
82487
  if (!base_commit)
82479
82488
  return { base_ref: null, base_commit: null, tagged: false, added: paths, updated: [], removed: [] };
82480
82489
  const tracked = new Set((await git("ls-tree", "-r", "--name-only", "-z", base_commit)).split("\x00").filter(Boolean));
82481
- const changed = new Set((await git("diff", "--name-only", "--no-renames", "-z", base_commit, "--")).split("\x00").filter(Boolean));
82490
+ const changed = new Set((await git("diff", "--name-only", "--relative", "--no-renames", "-z", base_commit, "--")).split("\x00").filter(Boolean));
82482
82491
  const current3 = new Set(paths);
82483
82492
  return {
82484
82493
  base_ref,
@@ -88031,7 +88040,11 @@ async function beginKnowledgeUpdate(projectRoot, value, options = {}) {
88031
88040
  const settled = readProcessedScopes(structure.parsed);
88032
88041
  const articles = validateArticleStructureEntries(structure.parsed.articles ?? []);
88033
88042
  const cited = articles.filter((article) => article.sections.some((section) => section.references.some((reference2) => scopes.some((scope2) => repoContentScopeMatches(scope2.source_ref, reference2.source_ref)))));
88034
- const inspected = await inspectSettledReferences(projectRoot, cited, scopes.map((scope2) => scope2.source_ref), settled);
88043
+ const inspected = await inspectSettledReferences(projectRoot, cited, scopes.map((scope2) => scope2.source_ref), settled, { fetchMissingCommits: true });
88044
+ const missingCommits = [...new Set(inspected.unresolved.filter((item) => item.reason === "source-history-missing").map((item) => item.reference.source_ref))];
88045
+ if (missingCommits.length) {
88046
+ throw new TypeError(`The registered commit of ${missingCommits.join(", ")} is not available in its checkout and could not be fetched. Fetch and check out the registered commit in the source checkout (see context source list --format json), then rerun context update --pending --format json.`);
88047
+ }
88035
88048
  const changedPaths = new Set(inspected.unresolved.map((item) => item.path));
88036
88049
  const candidates = await Promise.all(cited.filter((article) => changedPaths.has(article.path) || article.sections.some((section) => section.references.some((reference2) => reference2.source_ref.startsWith("repo-content:")))).map(async (article) => {
88037
88050
  const title = parseFrontmatterLoose(await targetBytes(projectRoot, article.path)).title;
@@ -108888,7 +108901,7 @@ __export(exports_taskRecovery, {
108888
108901
  TRANSACTIONS_PATH: () => TRANSACTIONS_PATH,
108889
108902
  RECOVERY_COMMAND: () => RECOVERY_COMMAND
108890
108903
  });
108891
- import { existsSync as existsSync30 } from "node:fs";
108904
+ import { existsSync as existsSync31 } from "node:fs";
108892
108905
  import { basename as basename11, dirname as dirname50, join as join122 } from "node:path";
108893
108906
  import { lstat as lstat17, readdir as readdir30, readFile as readFile101 } from "node:fs/promises";
108894
108907
  async function recoveryText(root2, path3) {
@@ -108933,7 +108946,7 @@ function recoveryResources() {
108933
108946
  skill: join122(root2, "skills/recover-workspace/SKILL.md"),
108934
108947
  issue_template: join122(root2, "resources/templates/recovery-issue.md")
108935
108948
  };
108936
- if (!Object.values(resources).every((path3) => existsSync30(path3)))
108949
+ if (!Object.values(resources).every((path3) => existsSync31(path3)))
108937
108950
  throw new Error("Recovery resources are absent from this Provider.");
108938
108951
  return resources;
108939
108952
  } catch {
@@ -110149,7 +110162,7 @@ var init_managedDocumentRename = __esm(() => {
110149
110162
  });
110150
110163
 
110151
110164
  // src/cli.ts
110152
- import { existsSync as existsSync39, realpathSync as realpathSync3 } from "node:fs";
110165
+ import { existsSync as existsSync40, realpathSync as realpathSync3 } from "node:fs";
110153
110166
  import { dirname as dirname57, join as join143 } from "node:path";
110154
110167
  import { fileURLToPath as fileURLToPath12, pathToFileURL as pathToFileURL3 } from "node:url";
110155
110168
 
@@ -110194,7 +110207,7 @@ import { join as join110 } from "node:path";
110194
110207
  // src/project/reviewHtml.ts
110195
110208
  init_candidateLedger();
110196
110209
  init_reviewShared();
110197
- import { mkdir as mkdir37, readFile as readFile88, writeFile as writeFile29 } from "node:fs/promises";
110210
+ import { copyFile, mkdir as mkdir37, readFile as readFile88, writeFile as writeFile29 } from "node:fs/promises";
110198
110211
  import { fileURLToPath as fileURLToPath8 } from "node:url";
110199
110212
  import { dirname as dirname46, isAbsolute as isAbsolute17, join as join108, resolve as resolve34 } from "node:path";
110200
110213
 
@@ -113455,6 +113468,7 @@ async function collectReviewSiteModel(root2, candidates) {
113455
113468
  storageScope: hash4(root2),
113456
113469
  themeCss,
113457
113470
  title: siteTitle ?? pkg.name ?? "Knowledge reading report",
113471
+ language: pkg.context?.language === "en" ? "en" : "zh",
113458
113472
  baselineHash: await reviewSiteBaselineHash(root2, candidates.map((c2) => c2.record.approved_revision?.previous_path ?? c2.record.path)),
113459
113473
  nodes,
113460
113474
  pages,
@@ -113514,10 +113528,11 @@ init_reviewShared();
113514
113528
  import { readFile as readFile87 } from "node:fs/promises";
113515
113529
  import { join as join107 } from "node:path";
113516
113530
  var scopePath = (root2, scope2) => join107(root2, ".tmp/context-runtime/review", `${scope2}.scope.json`);
113517
- async function saveReviewReportScope(root2, scope2, candidates, baselineHash) {
113531
+ async function saveReviewReportScope(root2, scope2, candidates, baselineHash, reportPath) {
113518
113532
  const ids = candidates.map((candidate) => candidate.record.candidate_id).sort();
113519
113533
  const value = {
113520
113534
  baseline_hash: baselineHash,
113535
+ ...reportPath === undefined ? {} : { report_path: reportPath },
113521
113536
  scope: {
113522
113537
  kind: scope2 === "all" ? "all" : "collection",
113523
113538
  ...scope2 === "all" ? {} : { collection: scope2 },
@@ -113575,7 +113590,7 @@ const words = {
113575
113590
  previousPage: ['上一页 −', 'Previous −'], nextPage: ['下一页 +', 'Next +'],
113576
113591
  previousHint: ['上一页(快捷键 -)', 'Previous article (key -)'], nextHint: ['下一页(快捷键 +)', 'Next article (key +)'],
113577
113592
  };
113578
- let language = 'zh';
113593
+ let language = DATA.language === 'en' ? 'en' : 'zh';
113579
113594
  const t = key => words[key]?.[language === 'zh' ? 0 : 1] || key;
113580
113595
  const candidates = DATA.pages.filter(page => page.candidate_id);
113581
113596
  const pagesById = new Map(DATA.pages.map(page => [page.id, page]));
@@ -113595,7 +113610,7 @@ function restore() {
113595
113610
  }
113596
113611
  try {
113597
113612
  const saved = JSON.parse(localStorage.getItem(storageKey) || '{}');
113598
- language = saved.language === 'en' ? 'en' : 'zh';
113613
+ if (saved.language === 'en' || saved.language === 'zh') language = saved.language;
113599
113614
  document.body.classList.toggle('dark', saved.dark === true);
113600
113615
  for (const page of candidates) {
113601
113616
  const entry = saved.pages?.[page.id];
@@ -114125,6 +114140,14 @@ function resolveOutputPath(projectRoot, outPath, reviewScope) {
114125
114140
  return join108(projectRoot, REVIEW_HTML_ROOT, `${reviewScope}.html`);
114126
114141
  return isAbsolute17(outPath) ? outPath : resolve34(projectRoot, outPath);
114127
114142
  }
114143
+ var APPLIED_REVIEW_REPORT_ROOT = join108(".tmp", "review-reports");
114144
+ async function archiveAppliedReviewReport(projectRoot, reportPath, scope2) {
114145
+ const stamp = new Date().toISOString().replace(/[:.]/gu, "-");
114146
+ const target = join108(projectRoot, APPLIED_REVIEW_REPORT_ROOT, `${stamp}-${scope2}.html`);
114147
+ await mkdir37(dirname46(target), { recursive: true });
114148
+ await copyFile(reportPath, target);
114149
+ return target;
114150
+ }
114128
114151
  function retirementBlockerFix(path3) {
114129
114152
  if (path3.startsWith("knowledge/") && path3.endsWith(".md")) {
114130
114153
  const page = path3.slice("knowledge/".length).replace(/'/gu, "'\\''");
@@ -114164,7 +114187,7 @@ async function writeReviewHtml(input) {
114164
114187
  }
114165
114188
  }
114166
114189
  await writeFile29(outPath, renderReviewHtml(model, diagramScript), "utf8");
114167
- await saveReviewReportScope(input.projectRoot, reviewScope, candidates, model.baselineHash);
114190
+ await saveReviewReportScope(input.projectRoot, reviewScope, candidates, model.baselineHash, outPath);
114168
114191
  const menu = await projectMenuTargets(input.projectRoot);
114169
114192
  const unplaced = model.pages.filter((page) => page.candidate_id && !menu.has(page.id) && !model.nodes.some((node3) => node3.page === page.id && node3.parent !== "review-unplaced" && !node3.removed)).map((page) => ({ article_id: page.id, candidate_id: page.candidate_id, path: page.path, title: page.title }));
114170
114193
  const retirementFixes = model.retirement?.blockers.map((blocker) => ({ ...blocker, fix: retirementBlockerFix(blocker.path) }));
@@ -116137,6 +116160,7 @@ async function readLegacyReviewPayload(raw, projectRoot) {
116137
116160
  init_cliFeedback();
116138
116161
  init_errors3();
116139
116162
  init_exitCode();
116163
+ import { existsSync as existsSync30 } from "node:fs";
116140
116164
  import { readFile as readFile97 } from "node:fs/promises";
116141
116165
  import { isAbsolute as isAbsolute21, resolve as resolve37 } from "node:path";
116142
116166
 
@@ -117013,7 +117037,7 @@ async function runReviewApplyCommand(input) {
117013
117037
  await recoverDurableMultiFileTransactions(projectRoot);
117014
117038
  const report = await writeReviewHtml({ projectRoot, ...payload.collection ? { collection: payload.collection } : { all: true } });
117015
117039
  const applied = await applyReviewDecisions({ projectRoot, payload });
117016
- return { ...applied, report_path: report.path };
117040
+ return { ...applied, report_path: await archiveAppliedReviewReport(projectRoot, report.path, payload.collection ?? "all") };
117017
117041
  });
117018
117042
  const continuation = await input.afterApply?.(projectRoot);
117019
117043
  process.stdout.write(formatApplyResult({ ...result, ...continuation === undefined ? {} : { continuation } }, input.format ?? "text"));
@@ -117037,7 +117061,7 @@ async function runReviewApproveAllCommand(input) {
117037
117061
  warnLegacyReview("--force");
117038
117062
  const decisionSource = input.managed === true ? "managed-session" : "explicit-user-confirmation";
117039
117063
  const projectRoot = projectRootFromCwd(input.cwd);
117040
- const { scoped, report, result } = await withProjectWriteLock(projectRoot, "review-with-report", async () => {
117064
+ const { scoped, reportPath, result } = await withProjectWriteLock(projectRoot, "review-with-report", async () => {
117041
117065
  await recoverDurableMultiFileTransactions(projectRoot);
117042
117066
  const scoped2 = await reviewCommandScope({
117043
117067
  projectRoot,
@@ -117045,11 +117069,11 @@ async function runReviewApproveAllCommand(input) {
117045
117069
  ...input.all === true ? { all: true } : {}
117046
117070
  });
117047
117071
  const confirmedScope = input.confirmed === true ? await readConfirmedReviewScope(projectRoot, scoped2.collection ?? "all") : undefined;
117048
- const report2 = input.managed === true ? await writeReviewHtml({
117072
+ const report = input.managed === true ? await writeReviewHtml({
117049
117073
  projectRoot,
117050
117074
  ...scoped2.collection ? { collection: scoped2.collection } : { all: true }
117051
117075
  }) : undefined;
117052
- const appliedScope = report2 ? await readConfirmedReviewScope(projectRoot, scoped2.collection ?? "all") : confirmedScope;
117076
+ const appliedScope = report ? await readConfirmedReviewScope(projectRoot, scoped2.collection ?? "all") : confirmedScope;
117053
117077
  const result2 = await applyReviewDecisions({
117054
117078
  projectRoot,
117055
117079
  payload: {
@@ -117061,7 +117085,11 @@ async function runReviewApproveAllCommand(input) {
117061
117085
  scope: appliedScope?.scope ?? scoped2.scope
117062
117086
  }
117063
117087
  });
117064
- return { scoped: scoped2, report: report2, result: result2 };
117088
+ const scope2 = scoped2.collection ?? "all";
117089
+ const confirmedReport = typeof confirmedScope?.report_path === "string" && existsSync30(confirmedScope.report_path) ? confirmedScope.report_path : undefined;
117090
+ const shown = report?.path ?? confirmedReport;
117091
+ const reportPath2 = shown ? await archiveAppliedReviewReport(projectRoot, shown, scope2) : undefined;
117092
+ return { scoped: scoped2, reportPath: reportPath2, result: result2 };
117065
117093
  });
117066
117094
  const continuation = await input.afterApply?.(projectRoot);
117067
117095
  if ((input.format ?? "text") === "json") {
@@ -117069,7 +117097,7 @@ async function runReviewApproveAllCommand(input) {
117069
117097
  process.stdout.write(`${JSON.stringify({
117070
117098
  kind: "review.approve-all.result",
117071
117099
  decision_source: decisionSource,
117072
- ...report ? { report_path: report.path } : {},
117100
+ ...reportPath ? { report_path: reportPath } : {},
117073
117101
  scope: compactScope,
117074
117102
  applied: result.applied,
117075
117103
  approved: result.approved,
@@ -117099,7 +117127,7 @@ async function runReviewApproveAllCommand(input) {
117099
117127
  headline: `${result.approved} candidate(s) approved`,
117100
117128
  body: [
117101
117129
  `decision source: ${decisionSource}`,
117102
- ...report ? [`review report: ${report.path}`] : [],
117130
+ ...reportPath ? [`review report: ${reportPath}`] : [],
117103
117131
  `materialized: ${result.materialized}`,
117104
117132
  `unchanged: ${result.unchanged}`,
117105
117133
  `removed: ${result.removed}`,
@@ -118806,7 +118834,7 @@ function registerProjectActionCommands(program2) {
118806
118834
 
118807
118835
  // src/commands/cleanClaudePluginCache.ts
118808
118836
  init_cliFeedback();
118809
- import { existsSync as existsSync31 } from "node:fs";
118837
+ import { existsSync as existsSync32 } from "node:fs";
118810
118838
  import { readdir as readdir31, rm as rm28 } from "node:fs/promises";
118811
118839
  import { homedir } from "node:os";
118812
118840
  import { join as join127 } from "node:path";
@@ -118818,7 +118846,7 @@ async function cleanClaudePluginCache(opts = {}) {
118818
118846
  const lines = [];
118819
118847
  let removed = 0;
118820
118848
  let scanned = 0;
118821
- if (!existsSync31(cacheRoot)) {
118849
+ if (!existsSync32(cacheRoot)) {
118822
118850
  lines.push("· claude plugin cache: missing — nothing to clean");
118823
118851
  return { lines, removed, scanned };
118824
118852
  }
@@ -118839,7 +118867,7 @@ async function cleanClaudePluginCache(opts = {}) {
118839
118867
  scanned += 1;
118840
118868
  const verDir = join127(plDir, ver.name);
118841
118869
  const markerPath = join127(verDir, ORPHAN_MARKER);
118842
- if (!existsSync31(markerPath))
118870
+ if (!existsSync32(markerPath))
118843
118871
  continue;
118844
118872
  const label2 = `${mp.name}/${pl.name}/${ver.name}`;
118845
118873
  if (opts.dryRun) {
@@ -118922,7 +118950,7 @@ init_repoSources();
118922
118950
  init_repoSourceRegistry();
118923
118951
  init_writeLock();
118924
118952
  import { execFile as execFile17 } from "node:child_process";
118925
- import { existsSync as existsSync32 } from "node:fs";
118953
+ import { existsSync as existsSync33 } from "node:fs";
118926
118954
  import { lstat as lstat18, mkdir as mkdir42, readlink as readlink3, realpath as realpath14, rm as rm29, symlink as symlink5 } from "node:fs/promises";
118927
118955
  import { basename as basename12, dirname as dirname51, isAbsolute as isAbsolute23, relative as relative34, resolve as resolve42 } from "node:path";
118928
118956
  import { promisify as promisify14 } from "node:util";
@@ -119077,7 +119105,7 @@ async function git3(cwd, args) {
119077
119105
  }
119078
119106
  async function resolveGitRoot2(path3) {
119079
119107
  const root2 = await git3(path3, ["rev-parse", "--show-toplevel"]);
119080
- if (root2.length === 0 || !existsSync32(root2)) {
119108
+ if (root2.length === 0 || !existsSync33(root2)) {
119081
119109
  throw userInputError3(`local repository path is not a Git checkout: ${path3}`, { path: path3 });
119082
119110
  }
119083
119111
  return realpath14(root2);
@@ -119102,7 +119130,7 @@ async function verifyCheckout(input) {
119102
119130
  }
119103
119131
  async function cloneCheckout(input) {
119104
119132
  const target = resolve42(input.projectRoot, input.target ?? `.tmp/repo/${repositorySlug(input.remote)}-${input.ref.slice(0, 12)}`);
119105
- if (existsSync32(target)) {
119133
+ if (existsSync33(target)) {
119106
119134
  throw userInputError3(`clone target already exists: ${target}`, {
119107
119135
  target,
119108
119136
  next: `Use local mode with path ${JSON.stringify(target)} after inspecting the existing checkout.`
@@ -119268,7 +119296,7 @@ async function restoreRepositorySources(input) {
119268
119296
  // src/project/sourceDocumentStatus.ts
119269
119297
  init_src2();
119270
119298
  init_documentCapture();
119271
- import { existsSync as existsSync33 } from "node:fs";
119299
+ import { existsSync as existsSync34 } from "node:fs";
119272
119300
  import { readFile as readFile104 } from "node:fs/promises";
119273
119301
  import { join as join129 } from "node:path";
119274
119302
 
@@ -119386,7 +119414,7 @@ function documentSourceManifestPath2(source2) {
119386
119414
  async function documentSnapshotState(input) {
119387
119415
  const manifest = documentSourceManifestPath2(input.source);
119388
119416
  const manifestPath = join129(input.projectRoot, manifest);
119389
- if (!existsSync33(manifestPath)) {
119417
+ if (!existsSync34(manifestPath)) {
119390
119418
  return {
119391
119419
  snapshotReady: false,
119392
119420
  state: "needs-capture",
@@ -119464,7 +119492,7 @@ async function documentSnapshotState(input) {
119464
119492
  const missing2 = [
119465
119493
  ...parsed.files.map((file) => file.path),
119466
119494
  ...(parsed.assets ?? []).filter((asset) => asset.content_hash !== undefined).map((asset) => asset.path)
119467
- ].find((path3) => !existsSync33(join129(input.projectRoot, input.source.materializedAt, path3)));
119495
+ ].find((path3) => !existsSync34(join129(input.projectRoot, input.source.materializedAt, path3)));
119468
119496
  if (missing2 !== undefined) {
119469
119497
  return {
119470
119498
  snapshotReady: false,
@@ -121264,7 +121292,7 @@ init_documentBatchManifest();
121264
121292
  init_workspace();
121265
121293
  init_writeLock();
121266
121294
  var import_yaml62 = __toESM(require_dist(), 1);
121267
- import { existsSync as existsSync34 } from "node:fs";
121295
+ import { existsSync as existsSync35 } from "node:fs";
121268
121296
  import { createHash as createHash45 } from "node:crypto";
121269
121297
  import { readFile as readFile109, readdir as readdir33, rm as rm31 } from "node:fs/promises";
121270
121298
  import { isAbsolute as isAbsolute25, join as join135, relative as relative38, resolve as resolve46, sep as sep12 } from "node:path";
@@ -121300,7 +121328,7 @@ function collectStrings(value, output) {
121300
121328
  }
121301
121329
  async function yamlReferences(input) {
121302
121330
  const absolutePath = join135(input.projectRoot, input.path);
121303
- if (!existsSync34(absolutePath))
121331
+ if (!existsSync35(absolutePath))
121304
121332
  return false;
121305
121333
  const parsed = import_yaml62.default.parse(await readFile109(absolutePath, "utf8"));
121306
121334
  const strings = [];
@@ -121429,7 +121457,7 @@ async function registryRemovalWrite(projectRoot2, source2) {
121429
121457
  if (path3 === null)
121430
121458
  return;
121431
121459
  const absolutePath = join135(projectRoot2, path3);
121432
- const document4 = existsSync34(absolutePath) ? import_yaml62.default.parse(await readFile109(absolutePath, "utf8")) : { sources: [] };
121460
+ const document4 = existsSync35(absolutePath) ? import_yaml62.default.parse(await readFile109(absolutePath, "utf8")) : { sources: [] };
121433
121461
  return {
121434
121462
  path: absolutePath,
121435
121463
  bytes: import_yaml62.default.stringify(removeDocumentEntry(document4, source2))
@@ -121562,7 +121590,7 @@ async function createRemovalPlan(projectRoot2, selector) {
121562
121590
  }
121563
121591
  } else {
121564
121592
  const materializedPath = safeManagedMaterializedPath(projectRoot2, source2);
121565
- if (materializedPath !== undefined && sharedMaterializedBy.length === 0 && existsSync34(materializedPath)) {
121593
+ if (materializedPath !== undefined && sharedMaterializedBy.length === 0 && existsSync35(materializedPath)) {
121566
121594
  absoluteRemovals.push(materializedPath);
121567
121595
  cleanup = {
121568
121596
  mode: "exclusive-materialization",
@@ -121611,7 +121639,7 @@ function publicRemovalResult(plan, action) {
121611
121639
  async function pruneExtractRuntime(projectRoot2, source2) {
121612
121640
  const fingerprintPath = join135(projectRoot2, ".tmp/context-runtime/extract/source-fingerprints.json");
121613
121641
  const removedPhaseIds = new Set;
121614
- if (existsSync34(fingerprintPath)) {
121642
+ if (existsSync35(fingerprintPath)) {
121615
121643
  const parsed = JSON.parse(await readFile109(fingerprintPath, "utf8"));
121616
121644
  const phases = parsed.phases ?? {};
121617
121645
  const next2 = Object.fromEntries(Object.entries(phases).filter(([phaseId, raw]) => {
@@ -121627,14 +121655,14 @@ async function pruneExtractRuntime(projectRoot2, source2) {
121627
121655
  `);
121628
121656
  }
121629
121657
  const phaseOwnershipPath = join135(projectRoot2, ".tmp/context-runtime/extract/custom-phase-candidates.json");
121630
- if (existsSync34(phaseOwnershipPath) && removedPhaseIds.size > 0) {
121658
+ if (existsSync35(phaseOwnershipPath) && removedPhaseIds.size > 0) {
121631
121659
  const parsed = JSON.parse(await readFile109(phaseOwnershipPath, "utf8"));
121632
121660
  const phases = Object.fromEntries(Object.entries(parsed.phases ?? {}).filter(([phaseId]) => !removedPhaseIds.has(phaseId)));
121633
121661
  await atomicWriteFile(phaseOwnershipPath, `${JSON.stringify({ ...parsed, phases }, null, 2)}
121634
121662
  `);
121635
121663
  }
121636
121664
  const symbolPath = join135(projectRoot2, ".tmp/context-runtime/extract/source-symbols.json");
121637
- if (existsSync34(symbolPath)) {
121665
+ if (existsSync35(symbolPath)) {
121638
121666
  const parsed = JSON.parse(await readFile109(symbolPath, "utf8"));
121639
121667
  const symbols = Array.isArray(parsed.symbols) ? parsed.symbols.filter((entry) => entry === null || typeof entry !== "object" || Array.isArray(entry) || entry.source !== source2.name) : [];
121640
121668
  const phaseFingerprints = Object.fromEntries(Object.entries(parsed.phaseFingerprints ?? {}).filter(([phaseId]) => !removedPhaseIds.has(phaseId)));
@@ -121643,7 +121671,7 @@ async function pruneExtractRuntime(projectRoot2, source2) {
121643
121671
  }
121644
121672
  const snapshotRoot = join135(projectRoot2, ".tmp/context-runtime/extract/candidates");
121645
121673
  const visit4 = async (directory) => {
121646
- if (!existsSync34(directory))
121674
+ if (!existsSync35(directory))
121647
121675
  return;
121648
121676
  for (const entry of await readdir33(directory, { withFileTypes: true })) {
121649
121677
  const path3 = join135(directory, entry.name);
@@ -122503,13 +122531,13 @@ init_errors3();
122503
122531
  init_cliFeedback();
122504
122532
  init_exitCode();
122505
122533
  var import_yaml65 = __toESM(require_dist(), 1);
122506
- import { constants as constants6, existsSync as existsSync35 } from "node:fs";
122534
+ import { constants as constants6, existsSync as existsSync36 } from "node:fs";
122507
122535
  import { lstat as lstat21, open as open5, readdir as readdir34 } from "node:fs/promises";
122508
122536
  import { dirname as dirname52, join as join138, resolve as resolve49 } from "node:path";
122509
122537
  import { fileURLToPath as fileURLToPath10 } from "node:url";
122510
122538
  function bundledSkillRoot() {
122511
122539
  const directory = dirname52(fileURLToPath10(import.meta.url));
122512
- const root2 = [resolve49(directory, "indexers/bundles"), resolve49(directory, "../../dist/indexers/bundles")].find((path3) => existsSync35(path3));
122540
+ const root2 = [resolve49(directory, "indexers/bundles"), resolve49(directory, "../../dist/indexers/bundles")].find((path3) => existsSync36(path3));
122513
122541
  if (!root2)
122514
122542
  throw new TypeError("Bundled skill files are unavailable; build or reinstall the Context CLI.");
122515
122543
  return root2;
@@ -122672,7 +122700,7 @@ init_exitCode();
122672
122700
  // src/project/entryCommand.ts
122673
122701
  init_workflowProvider();
122674
122702
  init_workspace();
122675
- import { existsSync as existsSync36 } from "node:fs";
122703
+ import { existsSync as existsSync37 } from "node:fs";
122676
122704
  import { dirname as dirname53, resolve as resolve50 } from "node:path";
122677
122705
  function shellQuote7(value) {
122678
122706
  return /^[A-Za-z0-9._/=-]+$/u.test(value) ? value : `'${value.replaceAll("'", `'"'"'`)}'`;
@@ -122729,7 +122757,7 @@ function resolveContextEntry(input) {
122729
122757
  const cwd = resolve50(input.cwd);
122730
122758
  if (input.projectDir !== undefined) {
122731
122759
  const target2 = resolveContextProjectInitTarget(cwd, input.projectDir);
122732
- if (existsSync36(target2) && isContextProjectRoot(target2)) {
122760
+ if (existsSync37(target2) && isContextProjectRoot(target2)) {
122733
122761
  return readyResult(input, target2, target2 !== cwd);
122734
122762
  }
122735
122763
  return {
@@ -122738,7 +122766,7 @@ function resolveContextEntry(input) {
122738
122766
  cwd,
122739
122767
  workspace: {
122740
122768
  root: target2,
122741
- exists: existsSync36(target2)
122769
+ exists: existsSync37(target2)
122742
122770
  },
122743
122771
  next_action: {
122744
122772
  kind: "initialize-workspace",
@@ -122782,7 +122810,7 @@ function resolveContextEntry(input) {
122782
122810
  cwd,
122783
122811
  workspace: {
122784
122812
  root: target,
122785
- exists: existsSync36(target)
122813
+ exists: existsSync37(target)
122786
122814
  },
122787
122815
  next_action: {
122788
122816
  kind: "initialize-workspace",
@@ -123208,7 +123236,7 @@ init_exitCode();
123208
123236
  init_cliFeedback();
123209
123237
  init_errors3();
123210
123238
  init_exitCode();
123211
- import { existsSync as existsSync38 } from "node:fs";
123239
+ import { existsSync as existsSync39 } from "node:fs";
123212
123240
  import { dirname as dirname56, join as join142, resolve as resolve53 } from "node:path";
123213
123241
  import { fileURLToPath as fileURLToPath11 } from "node:url";
123214
123242
 
@@ -123217,7 +123245,7 @@ init_cliFeedback();
123217
123245
  init_errors3();
123218
123246
  init_exitCode();
123219
123247
  import { execFile as execFile19 } from "node:child_process";
123220
- import { existsSync as existsSync37 } from "node:fs";
123248
+ import { existsSync as existsSync38 } from "node:fs";
123221
123249
  import { cp as cp4, mkdir as mkdir46, readdir as readdir36, readFile as readFile116, rename as rename13, rm as rm33, writeFile as writeFile35 } from "node:fs/promises";
123222
123250
  import { homedir as homedir2 } from "node:os";
123223
123251
  import { dirname as dirname55, join as join141 } from "node:path";
@@ -123359,7 +123387,7 @@ async function pruneLegacyCodexConfig(dryRun, steps) {
123359
123387
  }
123360
123388
  async function pruneCodexPluginCacheForName(pluginName, keepVersion, dryRun, steps) {
123361
123389
  const cacheRoot = join141(codexHome(), "plugins", "cache", MARKETPLACE_NAME, pluginName);
123362
- if (!existsSync37(cacheRoot))
123390
+ if (!existsSync38(cacheRoot))
123363
123391
  return;
123364
123392
  const versions = (await readdir36(cacheRoot, { withFileTypes: true }).catch(() => [])).filter((entry) => entry.isDirectory() && entry.name !== keepVersion).map((entry) => entry.name).sort();
123365
123393
  if (versions.length === 0)
@@ -123387,7 +123415,7 @@ async function isEmptyDir2(dir) {
123387
123415
  }
123388
123416
  async function pruneClaudeOrphanContextCache(dryRun, steps) {
123389
123417
  const cacheRoot = claudePluginCacheRoot();
123390
- if (!existsSync37(cacheRoot))
123418
+ if (!existsSync38(cacheRoot))
123391
123419
  return;
123392
123420
  const removed = [];
123393
123421
  const marketplaces = await readdir36(cacheRoot, { withFileTypes: true }).catch(() => []);
@@ -123395,14 +123423,14 @@ async function pruneClaudeOrphanContextCache(dryRun, steps) {
123395
123423
  if (!marketplace.isDirectory())
123396
123424
  continue;
123397
123425
  const pluginDir = join141(cacheRoot, marketplace.name, PLUGIN_NAME);
123398
- if (!existsSync37(pluginDir))
123426
+ if (!existsSync38(pluginDir))
123399
123427
  continue;
123400
123428
  const versions = await readdir36(pluginDir, { withFileTypes: true }).catch(() => []);
123401
123429
  for (const version3 of versions) {
123402
123430
  if (!version3.isDirectory())
123403
123431
  continue;
123404
123432
  const versionDir = join141(pluginDir, version3.name);
123405
- if (!existsSync37(join141(versionDir, ORPHAN_MARKER2)))
123433
+ if (!existsSync38(join141(versionDir, ORPHAN_MARKER2)))
123406
123434
  continue;
123407
123435
  removed.push(`${marketplace.name}/${PLUGIN_NAME}/${version3.name}`);
123408
123436
  if (!dryRun) {
@@ -123429,12 +123457,12 @@ async function pruneClaudeLegacyPluginCache(dryRun, steps) {
123429
123457
  if (LEGACY_PLUGIN_NAMES.length === 0)
123430
123458
  return;
123431
123459
  const cacheRoot = claudePluginCacheRoot();
123432
- if (!existsSync37(cacheRoot))
123460
+ if (!existsSync38(cacheRoot))
123433
123461
  return;
123434
123462
  const removed = [];
123435
123463
  for (const pluginName of LEGACY_PLUGIN_NAMES) {
123436
123464
  const pluginDir = join141(cacheRoot, MARKETPLACE_NAME, pluginName);
123437
- if (!existsSync37(pluginDir))
123465
+ if (!existsSync38(pluginDir))
123438
123466
  continue;
123439
123467
  removed.push(`${MARKETPLACE_NAME}/${pluginName}`);
123440
123468
  if (!dryRun) {
@@ -123562,7 +123590,7 @@ async function replaceDirectoryFromSource(source2, target) {
123562
123590
  const previous3 = `${target}.previous-${process.pid}-${Date.now()}`;
123563
123591
  await rm33(temporary, { recursive: true, force: true });
123564
123592
  await cp4(source2, temporary, { recursive: true, force: true });
123565
- const hadPrevious = existsSync37(target);
123593
+ const hadPrevious = existsSync38(target);
123566
123594
  try {
123567
123595
  if (hadPrevious)
123568
123596
  await rename13(target, previous3);
@@ -123571,7 +123599,7 @@ async function replaceDirectoryFromSource(source2, target) {
123571
123599
  await rm33(previous3, { recursive: true, force: true });
123572
123600
  } catch (error) {
123573
123601
  await rm33(temporary, { recursive: true, force: true });
123574
- if (hadPrevious && !existsSync37(target) && existsSync37(previous3))
123602
+ if (hadPrevious && !existsSync38(target) && existsSync38(previous3))
123575
123603
  await rename13(previous3, target);
123576
123604
  throw error;
123577
123605
  }
@@ -123596,7 +123624,7 @@ async function bundledProviderSkillNames(root2) {
123596
123624
  if (!entry.isDirectory() || entry.name === "context")
123597
123625
  continue;
123598
123626
  const skillPath = join141(skillsRoot, entry.name, "SKILL.md");
123599
- if (!existsSync37(skillPath))
123627
+ if (!existsSync38(skillPath))
123600
123628
  continue;
123601
123629
  const skill = await readFile116(skillPath, "utf8");
123602
123630
  if (!/^\s*context-role:\s*["']?indexer-provider["']?\s*$/mu.test(skill))
@@ -123745,7 +123773,7 @@ function pluginRootCandidates() {
123745
123773
  return [...new Set(candidates)];
123746
123774
  }
123747
123775
  function isInstallablePluginRoot(root2) {
123748
- return existsSync38(join142(root2, ".claude-plugin", "marketplace.json")) && existsSync38(join142(root2, ".agents", "plugins", "marketplace.json")) && existsSync38(join142(root2, "claude", ".claude-plugin", "plugin.json")) && existsSync38(join142(root2, "codex", ".codex-plugin", "plugin.json")) && existsSync38(join142(root2, "cursor", ".cursor-plugin", "plugin.json")) && existsSync38(join142(root2, "skills"));
123776
+ return existsSync39(join142(root2, ".claude-plugin", "marketplace.json")) && existsSync39(join142(root2, ".agents", "plugins", "marketplace.json")) && existsSync39(join142(root2, "claude", ".claude-plugin", "plugin.json")) && existsSync39(join142(root2, "codex", ".codex-plugin", "plugin.json")) && existsSync39(join142(root2, "cursor", ".cursor-plugin", "plugin.json")) && existsSync39(join142(root2, "skills"));
123749
123777
  }
123750
123778
  function resolveBundledPluginsRoot() {
123751
123779
  const candidates = pluginRootCandidates();
@@ -124012,10 +124040,10 @@ function readQuickstartPath() {
124012
124040
  let dir = dirname57(fileURLToPath12(import.meta.url));
124013
124041
  for (let i2 = 0;i2 < 8; i2++) {
124014
124042
  const candidate = join143(dir, "docs", "quickstart.md");
124015
- if (existsSync39(candidate))
124043
+ if (existsSync40(candidate))
124016
124044
  return candidate;
124017
124045
  const pkg = join143(dir, "package.json");
124018
- if (existsSync39(pkg))
124046
+ if (existsSync40(pkg))
124019
124047
  return candidate;
124020
124048
  const parent = dirname57(dir);
124021
124049
  if (parent === dir)