topchester-ai 0.30.0 → 0.32.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
|
@@ -952,8 +952,8 @@ function summarizeDiff(diff) {
|
|
|
952
952
|
let removed = 0;
|
|
953
953
|
for (const line of diff.split("\n")) {
|
|
954
954
|
if (line.startsWith("+++") || line.startsWith("---")) continue;
|
|
955
|
-
if (line.startsWith("+")) added += 1;
|
|
956
|
-
else if (line.startsWith("-")) removed += 1;
|
|
955
|
+
if (line.startsWith("+") || /^\+\s*\d+ \|/.test(line)) added += 1;
|
|
956
|
+
else if (line.startsWith("-") || /^-\s*\d+ \|/.test(line)) removed += 1;
|
|
957
957
|
}
|
|
958
958
|
return `+${added}/-${removed}`;
|
|
959
959
|
}
|
|
@@ -1047,12 +1047,17 @@ function createUnifiedDiff(path, oldContent, newContent) {
|
|
|
1047
1047
|
`+++ b/${path}`,
|
|
1048
1048
|
`@@ -${formatHunkRange(hunkOldStart, hunkOldEnd)} +${formatHunkRange(hunkNewStart, hunkNewEnd)} @@`
|
|
1049
1049
|
];
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
for (let index =
|
|
1053
|
-
for (let index =
|
|
1050
|
+
const oldLineNumberWidth = String(Math.max(1, hunkOldEnd)).length;
|
|
1051
|
+
const newLineNumberWidth = String(Math.max(1, hunkNewEnd)).length;
|
|
1052
|
+
for (let index = hunkOldStart; index < prefixLength; index += 1) lines.push(formatDiffLine(" ", index + 1, oldLineNumberWidth, oldLines[index]));
|
|
1053
|
+
for (let index = prefixLength; index < oldChangedEnd; index += 1) lines.push(formatDiffLine("-", index + 1, oldLineNumberWidth, oldLines[index]));
|
|
1054
|
+
for (let index = prefixLength; index < newChangedEnd; index += 1) lines.push(formatDiffLine("+", index + 1, newLineNumberWidth, newLines[index]));
|
|
1055
|
+
for (let index = newChangedEnd; index < hunkNewEnd; index += 1) lines.push(formatDiffLine(" ", index + 1, newLineNumberWidth, newLines[index]));
|
|
1054
1056
|
return lines.join("\n");
|
|
1055
1057
|
}
|
|
1058
|
+
function formatDiffLine(prefix, lineNumber, width, content) {
|
|
1059
|
+
return `${prefix}${String(lineNumber).padStart(width, " ")} │ ${content}`;
|
|
1060
|
+
}
|
|
1056
1061
|
function formatHunkRange(startIndex, endIndex) {
|
|
1057
1062
|
const lineCount = endIndex - startIndex;
|
|
1058
1063
|
return `${lineCount === 0 ? startIndex : startIndex + 1},${lineCount}`;
|
|
@@ -10777,7 +10782,7 @@ function formatToolResultForPrompt(result) {
|
|
|
10777
10782
|
`bytes_changed: ${result.bytesChanged}`,
|
|
10778
10783
|
`first_changed_line: ${result.firstChangedLine}`,
|
|
10779
10784
|
"```diff",
|
|
10780
|
-
result.diff,
|
|
10785
|
+
formatDiffForPrompt(result.diff),
|
|
10781
10786
|
"```"
|
|
10782
10787
|
].join("\n");
|
|
10783
10788
|
if (result.tool === "write_file" && "hash" in result) return [
|
|
@@ -11020,6 +11025,9 @@ function formatWriteFileChangeSummary(result) {
|
|
|
11020
11025
|
if (result?.tool !== "write_file" || isToolErrorResult(result) || !("writeEvent" in result)) return "";
|
|
11021
11026
|
return ` (${result.writeEvent.writeSummary})`;
|
|
11022
11027
|
}
|
|
11028
|
+
function formatDiffForPrompt(diff) {
|
|
11029
|
+
return diff.split("\n").map((line) => line.replace(/^([ +-])\s*\d+\s+│\s?/u, "$1")).join("\n");
|
|
11030
|
+
}
|
|
11023
11031
|
function isProjectInstructionRetryResult(result) {
|
|
11024
11032
|
return Boolean(!isToolErrorResult(result) && result.projectInstructions && (result.tool === "edit_file" || result.tool === "write_file"));
|
|
11025
11033
|
}
|
|
@@ -11310,7 +11318,6 @@ var TopchesterAgentRuntime = class TopchesterAgentRuntime {
|
|
|
11310
11318
|
for (let toolCalls = 0; toolCalls <= MAX_TOOL_CALLS_PER_TURN; toolCalls += 1) {
|
|
11311
11319
|
const startedAt = Date.now();
|
|
11312
11320
|
const projectInstructions = await this.resolveBaseProjectInstructions();
|
|
11313
|
-
for (const sourceKey of projectInstructions.sourceKeys) projectInstructionToolState.shownSourceKeys.add(sourceKey);
|
|
11314
11321
|
for (const event of createInstructionContextEventsFromProjectInstructions(projectInstructions, persistedProjectInstructionKeys)) yield event;
|
|
11315
11322
|
const system = this.buildSystemPromptWithProjectInstructions({
|
|
11316
11323
|
profile,
|
|
@@ -13385,12 +13392,37 @@ async function runSelfUpdate(options = {}) {
|
|
|
13385
13392
|
if (code !== 0) throw new Error(`Update command failed with exit code ${code ?? "unknown"}: ${updateCommand.display}`);
|
|
13386
13393
|
return updateCommand;
|
|
13387
13394
|
}
|
|
13395
|
+
async function checkSelfUpdate(options) {
|
|
13396
|
+
const updateCommand = createSelfUpdateCommand(options);
|
|
13397
|
+
if (!updateCommand) throw new Error(formatSelfUpdateUnsupportedMessage());
|
|
13398
|
+
const args = [
|
|
13399
|
+
"view",
|
|
13400
|
+
`${TOPCHESTER_PACKAGE_NAME}@${updateCommand.target}`,
|
|
13401
|
+
"version"
|
|
13402
|
+
];
|
|
13403
|
+
const result = await (options.runner ?? defaultSelfUpdateCheckRunner)(updateCommand.command, args);
|
|
13404
|
+
if (result.code !== 0) throw new Error(`Update check failed with exit code ${result.code ?? "unknown"}: ${[updateCommand.command, ...args].map(quoteDisplayArg).join(" ")}`);
|
|
13405
|
+
const availableVersion = result.stdout.trim().split(/\s+/).at(-1) ?? "";
|
|
13406
|
+
if (!availableVersion) throw new Error("Update check did not return an available version.");
|
|
13407
|
+
return {
|
|
13408
|
+
command: updateCommand,
|
|
13409
|
+
currentVersion: normalizeTarget(options.currentVersion),
|
|
13410
|
+
availableVersion: normalizeTarget(availableVersion),
|
|
13411
|
+
updateAvailable: normalizeTarget(options.currentVersion) !== normalizeTarget(availableVersion)
|
|
13412
|
+
};
|
|
13413
|
+
}
|
|
13388
13414
|
function formatSelfUpdateUnsupportedMessage() {
|
|
13389
13415
|
return ["Could not detect whether Topchester was installed with npm, pnpm, or bun.", `Update it with the package manager that installed it, for example: npm install -g ${TOPCHESTER_PACKAGE_NAME}@latest`].join("\n");
|
|
13390
13416
|
}
|
|
13391
13417
|
function formatSelfUpdateSuccess(command) {
|
|
13392
13418
|
return [`Updated Topchester with ${command.display}.`, "Restart Topchester to use the new version."];
|
|
13393
13419
|
}
|
|
13420
|
+
function formatSelfUpdateCheckResult(result) {
|
|
13421
|
+
const lines = [`Current Topchester version: ${result.currentVersion}`, `Available Topchester version: ${result.availableVersion}`];
|
|
13422
|
+
if (result.updateAvailable) lines.push(`Update available. Run ${result.command.display} to install it.`);
|
|
13423
|
+
else lines.push("Topchester is already up to date.");
|
|
13424
|
+
return lines;
|
|
13425
|
+
}
|
|
13394
13426
|
function normalizeTarget(target = "latest") {
|
|
13395
13427
|
const trimmed = target.trim();
|
|
13396
13428
|
if (!trimmed) return "latest";
|
|
@@ -13410,6 +13442,28 @@ function defaultSelfUpdateRunner(command, args) {
|
|
|
13410
13442
|
child.on("close", resolve);
|
|
13411
13443
|
});
|
|
13412
13444
|
}
|
|
13445
|
+
function defaultSelfUpdateCheckRunner(command, args) {
|
|
13446
|
+
return new Promise((resolve, reject) => {
|
|
13447
|
+
let stdout = "";
|
|
13448
|
+
const child = spawn(command, args, {
|
|
13449
|
+
stdio: [
|
|
13450
|
+
"ignore",
|
|
13451
|
+
"pipe",
|
|
13452
|
+
"inherit"
|
|
13453
|
+
],
|
|
13454
|
+
shell: process.platform === "win32"
|
|
13455
|
+
});
|
|
13456
|
+
child.stdout?.setEncoding("utf8");
|
|
13457
|
+
child.stdout?.on("data", (chunk) => {
|
|
13458
|
+
stdout += chunk;
|
|
13459
|
+
});
|
|
13460
|
+
child.on("error", reject);
|
|
13461
|
+
child.on("close", (code) => resolve({
|
|
13462
|
+
code,
|
|
13463
|
+
stdout
|
|
13464
|
+
}));
|
|
13465
|
+
});
|
|
13466
|
+
}
|
|
13413
13467
|
//#endregion
|
|
13414
13468
|
//#region src/cli.ts
|
|
13415
13469
|
async function runTopchesterCli(argv = process.argv, options = {}) {
|
|
@@ -13419,7 +13473,7 @@ async function runTopchesterCli(argv = process.argv, options = {}) {
|
|
|
13419
13473
|
}
|
|
13420
13474
|
function createTopchesterProgram() {
|
|
13421
13475
|
const program = new Command();
|
|
13422
|
-
program.name("topchester").description("KB-first terminal coding agent").version(getTopchesterVersion());
|
|
13476
|
+
program.name("topchester").description("KB-first terminal coding agent").version(getTopchesterVersion()).configureHelp({ helpWidth: 120 });
|
|
13423
13477
|
program.option("-c, --config <path>", "explicit config file path").option("--workspace <path>", "workspace root", cwd()).option("--resume <session>", "resume a project session: latest or an exact session id").option("--dev <flag>", "enable a development flag", collectDevFlag, []);
|
|
13424
13478
|
program.action(async () => {
|
|
13425
13479
|
const context = createContextFromOptions(program);
|
|
@@ -13506,8 +13560,16 @@ function createTopchesterProgram() {
|
|
|
13506
13560
|
const result = await ui.spinner("Checking KB file status...", async () => filterNonCleanKnowledgeCompileResult(await dryRunKnowledgeCompile(context.workspaceRoot, { config: context.config })));
|
|
13507
13561
|
console.log(formatKnowledgeCompileStatusResult(result, { formatSyncStatus: formatDryRunSyncStatus }).join("\n"));
|
|
13508
13562
|
});
|
|
13509
|
-
program.command("update").alias("upgrade").description("update Topchester with the package manager that installed it").argument("[target]", "version or npm dist tag to install", "latest").action(async (target) => {
|
|
13563
|
+
program.command("update").alias("upgrade").description("update Topchester with the package manager that installed it").argument("[target]", "version or npm dist tag to install", "latest").option("--check", "check the available version without updating").action(async (target, options) => {
|
|
13510
13564
|
try {
|
|
13565
|
+
if (options.check) {
|
|
13566
|
+
const result = await checkSelfUpdate({
|
|
13567
|
+
target,
|
|
13568
|
+
currentVersion: getTopchesterVersion()
|
|
13569
|
+
});
|
|
13570
|
+
console.log(formatSelfUpdateCheckResult(result).join("\n"));
|
|
13571
|
+
return;
|
|
13572
|
+
}
|
|
13511
13573
|
const command = await runSelfUpdate({ target });
|
|
13512
13574
|
console.log(formatSelfUpdateSuccess(command).join("\n"));
|
|
13513
13575
|
} catch (error) {
|
|
@@ -13603,4 +13665,4 @@ function formatDryRunSyncStatus(status) {
|
|
|
13603
13665
|
//#endregion
|
|
13604
13666
|
export { runTopchesterCli as t };
|
|
13605
13667
|
|
|
13606
|
-
//# sourceMappingURL=cli-
|
|
13668
|
+
//# sourceMappingURL=cli-lwrowwaC.mjs.map
|