topchester-ai 0.58.0 → 0.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as runTopchesterCli } from "./cli-Fw-z_PsS.mjs";
2
+ import { t as runTopchesterCli } from "./cli-BCDXfYWi.mjs";
3
3
  //#region src/bin.ts
4
4
  await runTopchesterCli();
5
5
  //#endregion
@@ -249,7 +249,7 @@ async function readAuthStore(options = {}) {
249
249
  try {
250
250
  source = await readFile(path, "utf8");
251
251
  } catch (error) {
252
- if (isNodeError$5(error) && error.code === "ENOENT") return createEmptyAuthStore();
252
+ if (isNodeError$4(error) && error.code === "ENOENT") return createEmptyAuthStore();
253
253
  throw error;
254
254
  }
255
255
  let parsed;
@@ -297,7 +297,7 @@ async function getAuthStoreStatus(options = {}) {
297
297
  try {
298
298
  await stat(path);
299
299
  } catch (error) {
300
- if (isNodeError$5(error) && error.code === "ENOENT") return {
300
+ if (isNodeError$4(error) && error.code === "ENOENT") return {
301
301
  path,
302
302
  exists: false,
303
303
  providers: []
@@ -388,14 +388,14 @@ function redactProviderStatus(id, record, now) {
388
388
  }
389
389
  async function setModeIfSupported(path, mode) {
390
390
  await chmod(path, mode).catch((error) => {
391
- if (isNodeError$5(error) && (error.code === "ENOSYS" || error.code === "EPERM" || error.code === "EINVAL")) return;
391
+ if (isNodeError$4(error) && (error.code === "ENOSYS" || error.code === "EPERM" || error.code === "EINVAL")) return;
392
392
  throw error;
393
393
  });
394
394
  }
395
395
  function isPlainObject$2(value) {
396
396
  return typeof value === "object" && value !== null && !Array.isArray(value);
397
397
  }
398
- function isNodeError$5(error) {
398
+ function isNodeError$4(error) {
399
399
  return error instanceof Error && "code" in error;
400
400
  }
401
401
  function formatErrorMessage$3(error) {
@@ -1299,7 +1299,7 @@ async function statExistingFile(resolvedPath, originalPath) {
1299
1299
  try {
1300
1300
  fileStat = await stat(resolvedPath);
1301
1301
  } catch (error) {
1302
- if (isNodeError$4(error) && error.code === "ENOENT") throw new Error(`edit_file can only edit existing files: ${originalPath}`);
1302
+ if (isNodeError$3(error) && error.code === "ENOENT") throw new Error(`edit_file can only edit existing files: ${originalPath}`);
1303
1303
  throw error;
1304
1304
  }
1305
1305
  if (!fileStat.isFile()) throw new Error(`edit_file can only edit regular files: ${originalPath}`);
@@ -1341,7 +1341,7 @@ function summarizeDiff(diff) {
1341
1341
  }
1342
1342
  return `+${added}/-${removed}`;
1343
1343
  }
1344
- function isNodeError$4(error) {
1344
+ function isNodeError$3(error) {
1345
1345
  return error instanceof Error && "code" in error;
1346
1346
  }
1347
1347
  function normalizeEdits(edits) {
@@ -4859,7 +4859,7 @@ async function statTarget(path) {
4859
4859
  try {
4860
4860
  return await stat(path);
4861
4861
  } catch (error) {
4862
- if (isNodeError$3(error) && error.code === "ENOENT") return;
4862
+ if (isNodeError$2(error) && error.code === "ENOENT") return;
4863
4863
  throw error;
4864
4864
  }
4865
4865
  }
@@ -4869,7 +4869,7 @@ async function ensureParentDirectory(workspaceRoot, path, relativePath, createPa
4869
4869
  if (!(await stat(parent)).isDirectory()) throw new Error(`write_file parent path is not a directory: ${dirname(relativePath)}`);
4870
4870
  return [];
4871
4871
  } catch (error) {
4872
- if (!isNodeError$3(error) || error.code !== "ENOENT") throw error;
4872
+ if (!isNodeError$2(error) || error.code !== "ENOENT") throw error;
4873
4873
  }
4874
4874
  if (!createParentDirs) throw new Error(`write_file parent directory does not exist: ${dirname(relativePath)}`);
4875
4875
  const createdParentDirs = await collectMissingParentDirs(workspaceRoot, parent);
@@ -4883,7 +4883,7 @@ async function collectMissingParentDirs(workspaceRoot, parent) {
4883
4883
  if (!(await stat(current)).isDirectory()) throw new Error(`write_file parent path is not a directory: ${relative(workspaceRoot, current)}`);
4884
4884
  break;
4885
4885
  } catch (error) {
4886
- if (!isNodeError$3(error) || error.code !== "ENOENT") throw error;
4886
+ if (!isNodeError$2(error) || error.code !== "ENOENT") throw error;
4887
4887
  missing.push(relative(workspaceRoot, current));
4888
4888
  current = dirname(current);
4889
4889
  }
@@ -4924,7 +4924,7 @@ function countLogicalLines$1(content) {
4924
4924
  const withoutTrailingLineEnding = content.replace(/\r?\n$/u, "");
4925
4925
  return withoutTrailingLineEnding.length === 0 ? 1 : withoutTrailingLineEnding.split(/\r?\n/u).length;
4926
4926
  }
4927
- function isNodeError$3(error) {
4927
+ function isNodeError$2(error) {
4928
4928
  return error instanceof Error && "code" in error;
4929
4929
  }
4930
4930
  //#endregion
@@ -8215,11 +8215,11 @@ async function directoryExists(path) {
8215
8215
  if (!(await stat(path)).isDirectory()) throw new Error(`${path} exists but is not a folder`);
8216
8216
  return true;
8217
8217
  } catch (error) {
8218
- if (isNodeError$2(error) && error.code === "ENOENT") return false;
8218
+ if (isNodeError$1(error) && error.code === "ENOENT") return false;
8219
8219
  throw error;
8220
8220
  }
8221
8221
  }
8222
- function isNodeError$2(error) {
8222
+ function isNodeError$1(error) {
8223
8223
  return error instanceof Error && "code" in error;
8224
8224
  }
8225
8225
  //#endregion
@@ -8258,7 +8258,7 @@ async function removeIfPresent(path) {
8258
8258
  });
8259
8259
  return true;
8260
8260
  } catch (error) {
8261
- if (isNodeError$1(error) && error.code === "ENOENT") return false;
8261
+ if (isNodeError(error) && error.code === "ENOENT") return false;
8262
8262
  throw error;
8263
8263
  }
8264
8264
  }
@@ -8271,7 +8271,7 @@ function assertSafeResetPath(workspaceRoot, path) {
8271
8271
  if (target === workspace) throw new Error(`Refusing to reset KB because the configured KB path is the workspace root: ${target}`);
8272
8272
  if (dirname(target) === target) throw new Error(`Refusing to reset KB because the configured KB path is a filesystem root: ${target}`);
8273
8273
  }
8274
- function isNodeError$1(error) {
8274
+ function isNodeError(error) {
8275
8275
  return error instanceof Error && "code" in error;
8276
8276
  }
8277
8277
  //#endregion
@@ -9870,19 +9870,11 @@ const slashCommandSuggestions = [
9870
9870
  },
9871
9871
  {
9872
9872
  value: "/effort",
9873
- description: "show or set reasoning effort"
9874
- },
9875
- {
9876
- value: "/effort high",
9877
- description: "set reasoning effort to high"
9873
+ description: `show or set reasoning effort (${reasoningEfforts.join(", ")}, clear)`
9878
9874
  },
9879
9875
  {
9880
9876
  value: "/reasoning",
9881
- description: "show or set reasoning effort"
9882
- },
9883
- {
9884
- value: "/reasoning high",
9885
- description: "set reasoning effort to high"
9877
+ description: `show or set reasoning effort (${reasoningEfforts.join(", ")}, clear)`
9886
9878
  },
9887
9879
  {
9888
9880
  value: "/kb status",
@@ -10119,8 +10111,24 @@ function getSlashCommandSuggestions(input) {
10119
10111
  const trimmed = input.trimStart();
10120
10112
  if (!trimmed.startsWith("/")) return [];
10121
10113
  const query = trimmed.toLowerCase();
10114
+ const reasoningSuggestions = getReasoningEffortValueSuggestions(query);
10115
+ if (reasoningSuggestions) return reasoningSuggestions;
10122
10116
  return slashCommandSuggestions.filter((suggestion) => suggestion.value.toLowerCase().startsWith(query));
10123
10117
  }
10118
+ function getReasoningEffortValueSuggestions(query) {
10119
+ const match = /^\/(?<command>effort|reasoning)\s+(?<value>\S*)$/u.exec(query);
10120
+ if (!match?.groups) return;
10121
+ const command = match.groups.command;
10122
+ const valuePrefix = match.groups.value;
10123
+ return [
10124
+ ...reasoningEfforts,
10125
+ "clear",
10126
+ "default"
10127
+ ].filter((option) => option.startsWith(valuePrefix)).map((option) => ({
10128
+ value: `/${command} ${option}`,
10129
+ description: option === "clear" || option === "default" ? "use provider default reasoning effort" : `set reasoning effort to ${option}`
10130
+ }));
10131
+ }
10124
10132
  async function executeKbCommand(args, context) {
10125
10133
  const subcommand = args[0];
10126
10134
  if (subcommand === "status") return { messages: formatKnowledgeCompileStatusResult(filterNonCleanKnowledgeCompileResult(await dryRunKnowledgeCompile(context.workspaceRoot, { config: context.config })), { formatSyncStatus: context.formatSyncStatus }) };
@@ -12116,16 +12124,10 @@ const agentMetadataSchema = z.object({
12116
12124
  capabilities: z.array(z.string().min(1)).optional(),
12117
12125
  model_support: agentModelSupportSchema.optional()
12118
12126
  }).strict();
12119
- const agentsMetadata = z.object({
12127
+ z.object({
12120
12128
  version: z.literal(1),
12121
12129
  agents: z.record(z.string().min(1), agentMetadataSchema)
12122
12130
  }).strict().parse(agents_default);
12123
- function listAgentMetadata() {
12124
- return Object.entries(agentsMetadata.agents).map(([id, metadata]) => ({
12125
- id,
12126
- metadata
12127
- })).sort((left, right) => left.id.localeCompare(right.id));
12128
- }
12129
12131
  //#endregion
12130
12132
  //#region src/agent/prompts.ts
12131
12133
  function getChatSystemPrompt(options = {}) {
@@ -15669,135 +15671,6 @@ function formatInfoError(error) {
15669
15671
  return error instanceof Error ? error.message : String(error);
15670
15672
  }
15671
15673
  //#endregion
15672
- //#region src/cli/integrations.ts
15673
- const TOPCHESTER_CODEX_BLOCK_START = "# >>> topchester integration: codex";
15674
- const TOPCHESTER_CODEX_BLOCK_END = "# <<< topchester integration: codex";
15675
- function listIntegrationStatuses() {
15676
- return listAgentMetadata().filter(({ id }) => id !== "topchester").map(({ id, metadata }) => getIntegrationStatus(id, metadata.display_name));
15677
- }
15678
- function getIntegrationStatus(agent, displayName) {
15679
- const normalizedAgent = normalizeAgentId(agent);
15680
- const metadata = listAgentMetadata().find(({ id }) => id === normalizedAgent)?.metadata;
15681
- const name = displayName ?? metadata?.display_name ?? normalizedAgent;
15682
- if (normalizedAgent !== "codex") return {
15683
- agent: normalizedAgent,
15684
- displayName: name,
15685
- supported: false,
15686
- installed: false,
15687
- detail: "not supported yet"
15688
- };
15689
- return {
15690
- agent: normalizedAgent,
15691
- displayName: name,
15692
- supported: true,
15693
- installed: false,
15694
- configPath: getCodexConfigPath(),
15695
- detail: "not installed"
15696
- };
15697
- }
15698
- async function getIntegrationStatusAsync(agent) {
15699
- const status = getIntegrationStatus(agent);
15700
- if (status.agent !== "codex" || !status.configPath) return status;
15701
- const contents = await readTextIfExists(status.configPath);
15702
- const installed = contents.includes(TOPCHESTER_CODEX_BLOCK_START) && contents.includes(TOPCHESTER_CODEX_BLOCK_END);
15703
- return {
15704
- ...status,
15705
- installed,
15706
- detail: installed ? "installed" : "not installed"
15707
- };
15708
- }
15709
- async function listIntegrationStatusesAsync(agent) {
15710
- if (agent) return [await getIntegrationStatusAsync(agent)];
15711
- return await Promise.all(listIntegrationStatuses().map((status) => getIntegrationStatusAsync(status.agent)));
15712
- }
15713
- async function installIntegration(agent, action = "installed") {
15714
- const status = await getIntegrationStatusAsync(agent);
15715
- if (!status.supported || status.agent !== "codex" || !status.configPath) throw new Error(`Unsupported integration: ${agent}`);
15716
- const next = appendMarkedBlock(removeMarkedBlock(await readTextIfExists(status.configPath)), formatCodexIntegrationBlock());
15717
- await mkdir(dirname(status.configPath), { recursive: true });
15718
- await writeFile(status.configPath, next);
15719
- return {
15720
- action,
15721
- status: await getIntegrationStatusAsync(status.agent)
15722
- };
15723
- }
15724
- async function removeIntegration(agent) {
15725
- const status = await getIntegrationStatusAsync(agent);
15726
- if (!status.supported || status.agent !== "codex" || !status.configPath) throw new Error(`Unsupported integration: ${agent}`);
15727
- const before = await readTextIfExists(status.configPath);
15728
- await mkdir(dirname(status.configPath), { recursive: true });
15729
- await writeFile(status.configPath, ensureTrailingNewline(removeMarkedBlock(before)));
15730
- return {
15731
- action: "removed",
15732
- status: await getIntegrationStatusAsync(status.agent)
15733
- };
15734
- }
15735
- function formatIntegrationStatuses(statuses) {
15736
- const lines = ["Integrations"];
15737
- for (const status of statuses) {
15738
- const state = status.supported ? status.installed ? "installed" : "not installed" : "unsupported";
15739
- lines.push(`${status.agent}: ${state}`);
15740
- if (status.configPath) lines.push(` config: ${status.configPath}`);
15741
- if (!status.supported) lines.push(` detail: ${status.detail}`);
15742
- }
15743
- return lines;
15744
- }
15745
- function formatIntegrationAction(action, status) {
15746
- return [
15747
- action === "installed" ? "Integration installed" : action === "repaired" ? "Integration repaired" : "Integration removed",
15748
- `agent: ${status.agent}`,
15749
- `state: ${status.installed ? "installed" : "not installed"}`,
15750
- ...status.configPath ? [`config: ${status.configPath}`] : []
15751
- ];
15752
- }
15753
- async function executeHookStop(agent) {
15754
- if (normalizeAgentId(agent ?? "") !== "codex") throw new Error(agent ? `Unsupported hook agent: ${agent}` : "Usage: topchester hook stop <agent>");
15755
- }
15756
- function getCodexConfigPath() {
15757
- return join(process.env.CODEX_HOME?.trim() || join(process.env.HOME || homedir(), ".codex"), "config.toml");
15758
- }
15759
- function formatCodexIntegrationBlock() {
15760
- return [
15761
- TOPCHESTER_CODEX_BLOCK_START,
15762
- "[[Stop]]",
15763
- "",
15764
- "[[Stop.hooks]]",
15765
- "type = \"command\"",
15766
- "command = \"topchester hook stop codex\"",
15767
- "timeout = 10",
15768
- "statusMessage = \"Notifying Topchester\"",
15769
- TOPCHESTER_CODEX_BLOCK_END
15770
- ].join("\n");
15771
- }
15772
- function appendMarkedBlock(contents, block) {
15773
- const base = contents.trimEnd();
15774
- return `${base ? `${base}\n\n` : ""}${block}\n`;
15775
- }
15776
- function removeMarkedBlock(contents) {
15777
- const start = contents.indexOf(TOPCHESTER_CODEX_BLOCK_START);
15778
- if (start === -1) return contents;
15779
- const end = contents.indexOf(TOPCHESTER_CODEX_BLOCK_END, start);
15780
- if (end === -1) return contents;
15781
- return `${contents.slice(0, start)}${contents.slice(end + 35)}`.trimEnd();
15782
- }
15783
- async function readTextIfExists(path) {
15784
- try {
15785
- return await readFile(path, "utf8");
15786
- } catch (error) {
15787
- if (isNodeError(error) && error.code === "ENOENT") return "";
15788
- throw error;
15789
- }
15790
- }
15791
- function ensureTrailingNewline(value) {
15792
- return value ? `${value.trimEnd()}\n` : "";
15793
- }
15794
- function normalizeAgentId(value) {
15795
- return value.trim().toLowerCase();
15796
- }
15797
- function isNodeError(error) {
15798
- return error instanceof Error && "code" in error;
15799
- }
15800
- //#endregion
15801
15674
  //#region src/cli.ts
15802
15675
  async function runTopchesterCli(argv = process.argv, options = {}) {
15803
15676
  const program = createTopchesterProgram();
@@ -15888,58 +15761,6 @@ function createTopchesterProgram() {
15888
15761
  program.command("search").description("search compiled L1 knowledge entries").argument("<query...>", "search query").option("--limit <count>", "maximum number of matches", parsePositiveInteger).option("--json", "write full JSON search result to stdout").action(async (queryParts, options) => {
15889
15762
  await executeKbSearchCommand(program, queryParts, options);
15890
15763
  });
15891
- const integrationsCommand = program.command("integrations").description("manage Topchester integrations with other agents");
15892
- integrationsCommand.command("list").description("list supported integrations").action(async () => {
15893
- try {
15894
- console.log(formatIntegrationStatuses(await listIntegrationStatusesAsync()).join("\n"));
15895
- } catch (error) {
15896
- console.error(formatStartupError(error));
15897
- process.exitCode = 1;
15898
- }
15899
- });
15900
- integrationsCommand.command("status").description("check whether integrations are installed").argument("[agent]", "agent id").action(async (agent) => {
15901
- try {
15902
- console.log(formatIntegrationStatuses(await listIntegrationStatusesAsync(agent)).join("\n"));
15903
- } catch (error) {
15904
- console.error(formatStartupError(error));
15905
- process.exitCode = 1;
15906
- }
15907
- });
15908
- integrationsCommand.command("install").description("install Topchester lifecycle hooks for another agent").argument("<agent>", "agent id").action(async (agent) => {
15909
- try {
15910
- const result = await installIntegration(agent);
15911
- console.log(formatIntegrationAction(result.action, result.status).join("\n"));
15912
- } catch (error) {
15913
- console.error(formatStartupError(error));
15914
- process.exitCode = 1;
15915
- }
15916
- });
15917
- integrationsCommand.command("repair").description("repair a Topchester integration").argument("<agent>", "agent id").action(async (agent) => {
15918
- try {
15919
- const result = await installIntegration(agent, "repaired");
15920
- console.log(formatIntegrationAction(result.action, result.status).join("\n"));
15921
- } catch (error) {
15922
- console.error(formatStartupError(error));
15923
- process.exitCode = 1;
15924
- }
15925
- });
15926
- integrationsCommand.command("remove").description("remove a Topchester integration").argument("<agent>", "agent id").action(async (agent) => {
15927
- try {
15928
- const result = await removeIntegration(agent);
15929
- console.log(formatIntegrationAction(result.action, result.status).join("\n"));
15930
- } catch (error) {
15931
- console.error(formatStartupError(error));
15932
- process.exitCode = 1;
15933
- }
15934
- });
15935
- program.command("hook").description("low-level lifecycle hook endpoints").command("stop").description("receive a Stop hook from another agent").argument("<agent>", "agent id").action(async (agent) => {
15936
- try {
15937
- await executeHookStop(agent);
15938
- } catch (error) {
15939
- console.error(formatStartupError(error));
15940
- process.exitCode = 1;
15941
- }
15942
- });
15943
15764
  const kbCommand = program.command("kb").description("knowledge base commands");
15944
15765
  kbCommand.command("init").description("initialize a project knowledge base").action(async () => {
15945
15766
  const context = createContextFromOptions(program);
@@ -16183,4 +16004,4 @@ function formatDryRunSyncStatus(status) {
16183
16004
  //#endregion
16184
16005
  export { runTopchesterCli as t };
16185
16006
 
16186
- //# sourceMappingURL=cli-Fw-z_PsS.mjs.map
16007
+ //# sourceMappingURL=cli-BCDXfYWi.mjs.map