archondev 2.19.53 → 2.19.55
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/{chunk-TZNB4BPI.js → chunk-DDAOREZF.js} +1 -1
- package/dist/{chunk-TG3ELXS3.js → chunk-ICPOD7FC.js} +73 -12
- package/dist/{chunk-L3FRKAIO.js → chunk-K6A6CWUG.js} +1 -1
- package/dist/{chunk-SAM5CXO4.js → chunk-LM5UBTSS.js} +38 -1
- package/dist/{chunk-R4A2C42M.js → chunk-QKHRSVUO.js} +76 -12
- package/dist/chunk-R664NEAA.js +66 -0
- package/dist/{chunk-XHIVKDU5.js → chunk-TNS5OLCD.js} +1 -1
- package/dist/{execute-HQ5XANCR.js → execute-4KDY6MOO.js} +3 -2
- package/dist/index.js +141 -60
- package/dist/{list-QKB55FIY.js → list-D4THOSHG.js} +3 -2
- package/dist/{parallel-WCUTC4FM.js → parallel-HUAAE6PS.js} +3 -2
- package/dist/{plan-V57SS7O6.js → plan-7YU2U4RY.js} +2 -1
- package/dist/{preferences-MTGN2VZK.js → preferences-QTPQLCXN.js} +2 -1
- package/dist/{show-QDTDTY4P.js → show-VLTLYZDI.js} +3 -2
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
UsageRecorder,
|
|
8
8
|
handleInsufficientCreditsRecovery,
|
|
9
9
|
loadAtom
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-QKHRSVUO.js";
|
|
11
11
|
import {
|
|
12
12
|
transitionAtom
|
|
13
13
|
} from "./chunk-WGLVDEZC.js";
|
|
@@ -15,6 +15,10 @@ import {
|
|
|
15
15
|
AnthropicClient,
|
|
16
16
|
getDefaultModel
|
|
17
17
|
} from "./chunk-F7R3QKHP.js";
|
|
18
|
+
import {
|
|
19
|
+
debugLog,
|
|
20
|
+
getDebugLogPath
|
|
21
|
+
} from "./chunk-R664NEAA.js";
|
|
18
22
|
import {
|
|
19
23
|
createAuthedSupabaseClient
|
|
20
24
|
} from "./chunk-Q3GIFHIQ.js";
|
|
@@ -4208,11 +4212,12 @@ var ExecutorAgent = class {
|
|
|
4208
4212
|
rollbackPerformed: false
|
|
4209
4213
|
};
|
|
4210
4214
|
}
|
|
4211
|
-
const
|
|
4215
|
+
const reconciledDiffs = this.reconcileOutOfScopeDiffs(diffs, plan);
|
|
4216
|
+
const violations = this.checkArchitectureViolations(reconciledDiffs, plan, architecture);
|
|
4212
4217
|
if (violations.length > 0) {
|
|
4213
4218
|
return {
|
|
4214
4219
|
success: false,
|
|
4215
|
-
diffs,
|
|
4220
|
+
diffs: reconciledDiffs,
|
|
4216
4221
|
usage: response.usage,
|
|
4217
4222
|
qualityChecksPassed: false,
|
|
4218
4223
|
errorMessage: `Architecture violations: ${violations.join(", ")}`,
|
|
@@ -4221,7 +4226,7 @@ var ExecutorAgent = class {
|
|
|
4221
4226
|
}
|
|
4222
4227
|
const originalContents = /* @__PURE__ */ new Map();
|
|
4223
4228
|
try {
|
|
4224
|
-
for (const diff of
|
|
4229
|
+
for (const diff of reconciledDiffs) {
|
|
4225
4230
|
const fullPath = `${cwd}/${diff.path}`;
|
|
4226
4231
|
if (existsSync6(fullPath)) {
|
|
4227
4232
|
originalContents.set(diff.path, await readFile5(fullPath, "utf-8"));
|
|
@@ -4229,7 +4234,7 @@ var ExecutorAgent = class {
|
|
|
4229
4234
|
originalContents.set(diff.path, null);
|
|
4230
4235
|
}
|
|
4231
4236
|
}
|
|
4232
|
-
for (const diff of
|
|
4237
|
+
for (const diff of reconciledDiffs) {
|
|
4233
4238
|
const fullPath = `${cwd}/${diff.path}`;
|
|
4234
4239
|
if (diff.operation === "DELETE") {
|
|
4235
4240
|
continue;
|
|
@@ -4242,10 +4247,10 @@ var ExecutorAgent = class {
|
|
|
4242
4247
|
}
|
|
4243
4248
|
const qualityChecksPassed = await this.runQualityChecks(cwd);
|
|
4244
4249
|
if (!qualityChecksPassed) {
|
|
4245
|
-
await this.rollback(cwd, originalContents,
|
|
4250
|
+
await this.rollback(cwd, originalContents, reconciledDiffs);
|
|
4246
4251
|
return {
|
|
4247
4252
|
success: false,
|
|
4248
|
-
diffs,
|
|
4253
|
+
diffs: reconciledDiffs,
|
|
4249
4254
|
usage: response.usage,
|
|
4250
4255
|
qualityChecksPassed: false,
|
|
4251
4256
|
errorMessage: "Quality checks failed - changes rolled back",
|
|
@@ -4254,16 +4259,16 @@ var ExecutorAgent = class {
|
|
|
4254
4259
|
}
|
|
4255
4260
|
return {
|
|
4256
4261
|
success: true,
|
|
4257
|
-
diffs,
|
|
4262
|
+
diffs: reconciledDiffs,
|
|
4258
4263
|
usage: response.usage,
|
|
4259
4264
|
qualityChecksPassed: true,
|
|
4260
4265
|
rollbackPerformed: false
|
|
4261
4266
|
};
|
|
4262
4267
|
} catch (error) {
|
|
4263
|
-
await this.rollback(cwd, originalContents,
|
|
4268
|
+
await this.rollback(cwd, originalContents, reconciledDiffs);
|
|
4264
4269
|
return {
|
|
4265
4270
|
success: false,
|
|
4266
|
-
diffs,
|
|
4271
|
+
diffs: reconciledDiffs,
|
|
4267
4272
|
usage: response.usage,
|
|
4268
4273
|
qualityChecksPassed: false,
|
|
4269
4274
|
errorMessage: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -4436,6 +4441,33 @@ var ExecutorAgent = class {
|
|
|
4436
4441
|
const regexPattern = pattern.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*").replace(/\//g, "\\/");
|
|
4437
4442
|
return new RegExp(`^${regexPattern}$`).test(path);
|
|
4438
4443
|
}
|
|
4444
|
+
reconcileOutOfScopeDiffs(diffs, plan) {
|
|
4445
|
+
const allowedFiles = plan.files_to_modify;
|
|
4446
|
+
if (allowedFiles.length !== 1 || diffs.length !== 1) {
|
|
4447
|
+
return diffs;
|
|
4448
|
+
}
|
|
4449
|
+
const onlyAllowed = this.normalizePath(allowedFiles[0]);
|
|
4450
|
+
const candidate = diffs[0];
|
|
4451
|
+
if (!onlyAllowed || !candidate) {
|
|
4452
|
+
return diffs;
|
|
4453
|
+
}
|
|
4454
|
+
const normalizedDiffPath = this.normalizePath(candidate.path);
|
|
4455
|
+
if (normalizedDiffPath === onlyAllowed) {
|
|
4456
|
+
return diffs;
|
|
4457
|
+
}
|
|
4458
|
+
const contentLike = /\.(md|markdown|txt)$/i.test(onlyAllowed) && /\.(md|markdown|txt)$/i.test(normalizedDiffPath);
|
|
4459
|
+
const sameDir = dirname2(normalizedDiffPath) === dirname2(onlyAllowed);
|
|
4460
|
+
if (!contentLike || !sameDir) {
|
|
4461
|
+
return diffs;
|
|
4462
|
+
}
|
|
4463
|
+
return [{
|
|
4464
|
+
...candidate,
|
|
4465
|
+
path: onlyAllowed
|
|
4466
|
+
}];
|
|
4467
|
+
}
|
|
4468
|
+
normalizePath(path) {
|
|
4469
|
+
return path.replace(/\\/g, "/").replace(/^\.?\//, "");
|
|
4470
|
+
}
|
|
4439
4471
|
/**
|
|
4440
4472
|
* Run quality checks (typecheck, lint)
|
|
4441
4473
|
*/
|
|
@@ -4835,7 +4867,7 @@ async function attemptPathScopeAutoRecovery(atom, cwd, parseSchema, options) {
|
|
|
4835
4867
|
if (allowedPaths.length === 0) {
|
|
4836
4868
|
return false;
|
|
4837
4869
|
}
|
|
4838
|
-
const { listLocalAtoms, plan } = await import("./plan-
|
|
4870
|
+
const { listLocalAtoms, plan } = await import("./plan-7YU2U4RY.js");
|
|
4839
4871
|
const before = await listLocalAtoms();
|
|
4840
4872
|
const recoveryStartedAt = Date.now();
|
|
4841
4873
|
const recoverySource = atom.description ?? atom.title;
|
|
@@ -4903,13 +4935,18 @@ async function execute(atomId, options) {
|
|
|
4903
4935
|
process.exit(1);
|
|
4904
4936
|
};
|
|
4905
4937
|
if (options.parallel && options.parallel.length > 0) {
|
|
4906
|
-
const { parallelExecute } = await import("./parallel-
|
|
4938
|
+
const { parallelExecute } = await import("./parallel-HUAAE6PS.js");
|
|
4907
4939
|
const allAtomIds = [atomId, ...options.parallel];
|
|
4908
4940
|
await parallelExecute(allAtomIds, { skipGates: options.skipGates === true });
|
|
4909
4941
|
return;
|
|
4910
4942
|
}
|
|
4911
4943
|
const prompt = createPrompt();
|
|
4912
4944
|
const cwd = process.cwd();
|
|
4945
|
+
const debugPath = getDebugLogPath();
|
|
4946
|
+
if (debugPath) {
|
|
4947
|
+
console.log(chalk2.dim(`Debug logging enabled: ${debugPath}`));
|
|
4948
|
+
}
|
|
4949
|
+
debugLog("execute", "start", "Execute command started", { atomId, options });
|
|
4913
4950
|
try {
|
|
4914
4951
|
if (options.cloud) {
|
|
4915
4952
|
const config2 = await loadConfig();
|
|
@@ -5121,9 +5158,23 @@ ${conflictReport.blockerCount} blocking conflict(s) found.`));
|
|
|
5121
5158
|
}
|
|
5122
5159
|
}
|
|
5123
5160
|
const executionResult = await executor.executeAtom(atom, atom.plan, parseResult.schema, cwd);
|
|
5161
|
+
debugLog("execute", "result.received", "Executor returned execution result", {
|
|
5162
|
+
success: executionResult.success,
|
|
5163
|
+
rollbackPerformed: executionResult.rollbackPerformed,
|
|
5164
|
+
diffPaths: executionResult.diffs.map((d) => d.path),
|
|
5165
|
+
errorMessage: executionResult.errorMessage ?? null,
|
|
5166
|
+
plannedFiles: atom.plan.files_to_modify
|
|
5167
|
+
});
|
|
5124
5168
|
const filesChanged = executionResult.diffs.map((d) => d.path);
|
|
5125
5169
|
if (!executionResult.success) {
|
|
5126
5170
|
if (isGovernanceViolation(executionResult.errorMessage)) {
|
|
5171
|
+
debugLog("execute", "result.governance_violation", "Execution blocked by governance", {
|
|
5172
|
+
atomId: atom.externalId,
|
|
5173
|
+
errorMessage: executionResult.errorMessage ?? null,
|
|
5174
|
+
diffPaths: executionResult.diffs.map((d) => d.path),
|
|
5175
|
+
plannedFiles: atom.plan.files_to_modify,
|
|
5176
|
+
violations: extractGovernanceViolations(executionResult.errorMessage)
|
|
5177
|
+
});
|
|
5127
5178
|
console.log(chalk2.yellow("\n\u26A0\uFE0F Execution paused by governance guidance"));
|
|
5128
5179
|
console.log(chalk2.dim("No changes were committed. Update the plan/path scope, then continue."));
|
|
5129
5180
|
const violations = extractGovernanceViolations(executionResult.errorMessage);
|
|
@@ -5164,6 +5215,10 @@ ${conflictReport.blockerCount} blocking conflict(s) found.`));
|
|
|
5164
5215
|
if (isGovernanceViolation(executionResult.errorMessage)) {
|
|
5165
5216
|
const pathScopeViolation = isPathScopeGovernanceViolation(executionResult.errorMessage);
|
|
5166
5217
|
if (pathScopeViolation && options.pathScopeAutoRecover !== false) {
|
|
5218
|
+
debugLog("execute", "auto_recover.attempt", "Attempting path-scope auto recovery", {
|
|
5219
|
+
atomId: atom.externalId,
|
|
5220
|
+
autoRecoverDepth: options.autoRecoverDepth ?? 0
|
|
5221
|
+
});
|
|
5167
5222
|
const recovered = await attemptPathScopeAutoRecovery(
|
|
5168
5223
|
atom,
|
|
5169
5224
|
cwd,
|
|
@@ -5171,8 +5226,14 @@ ${conflictReport.blockerCount} blocking conflict(s) found.`));
|
|
|
5171
5226
|
options
|
|
5172
5227
|
);
|
|
5173
5228
|
if (recovered) {
|
|
5229
|
+
debugLog("execute", "auto_recover.success", "Path-scope auto recovery succeeded", {
|
|
5230
|
+
atomId: atom.externalId
|
|
5231
|
+
});
|
|
5174
5232
|
return;
|
|
5175
5233
|
}
|
|
5234
|
+
debugLog("execute", "auto_recover.failed", "Path-scope auto recovery did not produce a replacement atom", {
|
|
5235
|
+
atomId: atom.externalId
|
|
5236
|
+
});
|
|
5176
5237
|
}
|
|
5177
5238
|
printExecuteNextActions(
|
|
5178
5239
|
atom.externalId,
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
debugLog,
|
|
3
|
+
getDebugLogPath
|
|
4
|
+
} from "./chunk-R664NEAA.js";
|
|
1
5
|
import {
|
|
2
6
|
createAuthedSupabaseClient
|
|
3
7
|
} from "./chunk-Q3GIFHIQ.js";
|
|
@@ -1312,12 +1316,26 @@ function aggregateUsageRows(rows, start, end) {
|
|
|
1312
1316
|
return { totalInputTokens, totalOutputTokens, totalCost, byModel };
|
|
1313
1317
|
}
|
|
1314
1318
|
async function showUsageDetails(options = {}) {
|
|
1315
|
-
const { pauseForInput = false } = options;
|
|
1319
|
+
const { pauseForInput = false, debug = false } = options;
|
|
1316
1320
|
console.log(chalk.bold("\n-- Usage Details --\n"));
|
|
1321
|
+
if (debug) {
|
|
1322
|
+
const debugPath = getDebugLogPath();
|
|
1323
|
+
if (debugPath) {
|
|
1324
|
+
console.log(chalk.dim(`Debug logging enabled: ${debugPath}`));
|
|
1325
|
+
} else {
|
|
1326
|
+
console.log(chalk.dim("Tip: set ARCHON_DEBUG=1 to persist diagnostics to .archon/debug/*.log"));
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1317
1329
|
const spinner = ora("Loading usage data...").start();
|
|
1318
1330
|
const config = await loadConfig();
|
|
1319
1331
|
const authToken = getAuthToken(config);
|
|
1320
1332
|
const authId = config.userId;
|
|
1333
|
+
if (debug) {
|
|
1334
|
+
debugLog("usage", "start", "Usage command started", {
|
|
1335
|
+
authId: authId ?? null,
|
|
1336
|
+
hasToken: !!authToken
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1321
1339
|
if (!authToken) {
|
|
1322
1340
|
spinner.fail("Not logged in");
|
|
1323
1341
|
return;
|
|
@@ -1327,6 +1345,11 @@ async function showUsageDetails(options = {}) {
|
|
|
1327
1345
|
const response = await fetch(`${apiUrl}/api/usage`, {
|
|
1328
1346
|
headers: { "Authorization": `Bearer ${authToken}` }
|
|
1329
1347
|
});
|
|
1348
|
+
if (debug) {
|
|
1349
|
+
debugLog("usage", "api.response", "Received /api/usage response", {
|
|
1350
|
+
status: response.status
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1330
1353
|
spinner.stop();
|
|
1331
1354
|
if (!response.ok) {
|
|
1332
1355
|
console.log(chalk.yellow("Unable to fetch usage data."));
|
|
@@ -1335,6 +1358,9 @@ async function showUsageDetails(options = {}) {
|
|
|
1335
1358
|
const data = await response.json();
|
|
1336
1359
|
if (data.tier === "BYOK") {
|
|
1337
1360
|
const ids = await resolveAuthAndProfileIds(authToken, authId);
|
|
1361
|
+
if (debug) {
|
|
1362
|
+
debugLog("usage", "byok.identity", "Resolved auth/profile IDs for BYOK usage command", ids);
|
|
1363
|
+
}
|
|
1338
1364
|
if (!ids.authId || !ids.profileId) {
|
|
1339
1365
|
console.log(chalk.yellow("Unable to resolve user ID for usage details."));
|
|
1340
1366
|
return;
|
|
@@ -1342,6 +1368,14 @@ async function showUsageDetails(options = {}) {
|
|
|
1342
1368
|
const now = /* @__PURE__ */ new Date();
|
|
1343
1369
|
const yearStart = new Date(now.getFullYear(), 0, 1);
|
|
1344
1370
|
const usageRows = await fetchUsageRows(authToken, ids.profileId, yearStart.toISOString(), now.toISOString());
|
|
1371
|
+
if (debug) {
|
|
1372
|
+
debugLog("usage", "byok.rows", "Fetched BYOK token usage rows", {
|
|
1373
|
+
profileId: ids.profileId,
|
|
1374
|
+
rowCount: usageRows?.length ?? 0,
|
|
1375
|
+
start: yearStart.toISOString(),
|
|
1376
|
+
end: now.toISOString()
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1345
1379
|
if (!usageRows) {
|
|
1346
1380
|
console.log(chalk.yellow("Unable to fetch BYOK usage data."));
|
|
1347
1381
|
return;
|
|
@@ -1412,6 +1446,9 @@ async function showUsageDetails(options = {}) {
|
|
|
1412
1446
|
}
|
|
1413
1447
|
}
|
|
1414
1448
|
} catch {
|
|
1449
|
+
if (debug) {
|
|
1450
|
+
debugLog("usage", "error", "Usage command threw exception");
|
|
1451
|
+
}
|
|
1415
1452
|
spinner.stop();
|
|
1416
1453
|
console.log(chalk.yellow("Error fetching usage data."));
|
|
1417
1454
|
}
|
|
@@ -9,6 +9,9 @@ import {
|
|
|
9
9
|
AnthropicClient,
|
|
10
10
|
getDefaultModel
|
|
11
11
|
} from "./chunk-F7R3QKHP.js";
|
|
12
|
+
import {
|
|
13
|
+
debugLog
|
|
14
|
+
} from "./chunk-R664NEAA.js";
|
|
12
15
|
import {
|
|
13
16
|
createAuthedSupabaseClient
|
|
14
17
|
} from "./chunk-Q3GIFHIQ.js";
|
|
@@ -38,7 +41,7 @@ import {
|
|
|
38
41
|
import chalk2 from "chalk";
|
|
39
42
|
import { existsSync } from "fs";
|
|
40
43
|
import { readFile, writeFile, mkdir, stat } from "fs/promises";
|
|
41
|
-
import { join, dirname, basename, extname } from "path";
|
|
44
|
+
import { join, dirname, basename, extname, isAbsolute, resolve, relative } from "path";
|
|
42
45
|
import { createInterface } from "readline";
|
|
43
46
|
|
|
44
47
|
// src/agents/sentinel.ts
|
|
@@ -851,14 +854,14 @@ function isUuid(value) {
|
|
|
851
854
|
import chalk from "chalk";
|
|
852
855
|
import readline from "readline";
|
|
853
856
|
function prompt(question) {
|
|
854
|
-
return new Promise((
|
|
857
|
+
return new Promise((resolve2) => {
|
|
855
858
|
const rl = readline.createInterface({
|
|
856
859
|
input: process.stdin,
|
|
857
860
|
output: process.stdout
|
|
858
861
|
});
|
|
859
862
|
rl.question(`${chalk.cyan("?")} ${question}: `, (answer) => {
|
|
860
863
|
rl.close();
|
|
861
|
-
|
|
864
|
+
resolve2(answer.trim());
|
|
862
865
|
});
|
|
863
866
|
});
|
|
864
867
|
}
|
|
@@ -899,8 +902,8 @@ function createPrompt() {
|
|
|
899
902
|
output: process.stdout
|
|
900
903
|
});
|
|
901
904
|
return {
|
|
902
|
-
ask: (question) => new Promise((
|
|
903
|
-
rl.question(question,
|
|
905
|
+
ask: (question) => new Promise((resolve2) => {
|
|
906
|
+
rl.question(question, resolve2);
|
|
904
907
|
}),
|
|
905
908
|
close: () => rl.close()
|
|
906
909
|
};
|
|
@@ -930,7 +933,15 @@ async function plan(description, options) {
|
|
|
930
933
|
}
|
|
931
934
|
const requirements = extractNumberedRequirements(description);
|
|
932
935
|
const references = extractReferencedFiles(description);
|
|
936
|
+
debugLog("plan", "references.extracted", "Referenced files extracted from prompt", {
|
|
937
|
+
references
|
|
938
|
+
});
|
|
933
939
|
const { foundFiles, missingFiles, fileSummaries } = await loadReferencedFileSummaries(references);
|
|
940
|
+
debugLog("plan", "references.resolved", "Referenced files resolved on disk", {
|
|
941
|
+
foundFiles,
|
|
942
|
+
missingFiles,
|
|
943
|
+
summaryCount: fileSummaries.length
|
|
944
|
+
});
|
|
934
945
|
if (references.length > 0) {
|
|
935
946
|
console.log(chalk2.dim("\nReferenced inputs detected:"));
|
|
936
947
|
for (const ref of references) {
|
|
@@ -1595,9 +1606,8 @@ function resolveContentOutputTargets(description, referencedFiles, deliverableTa
|
|
|
1595
1606
|
}
|
|
1596
1607
|
function deriveDefaultContentOutputPath(description, referencedFiles) {
|
|
1597
1608
|
const sampleSuffix = /\b(sample|first lesson)\b/i.test(description) ? ".sample-capsule" : ".capsule";
|
|
1598
|
-
const
|
|
1599
|
-
|
|
1600
|
-
);
|
|
1609
|
+
const desiredDay = inferRequestedDay(description);
|
|
1610
|
+
const preferredRef = pickPreferredReference(referencedFiles, desiredDay);
|
|
1601
1611
|
const primaryRef = preferredRef ?? referencedFiles.find((ref) => /\.(md|txt|markdown)$/i.test(ref));
|
|
1602
1612
|
if (!primaryRef) {
|
|
1603
1613
|
return `daily-exercises/capsule-output${sampleSuffix}.md`;
|
|
@@ -1606,12 +1616,19 @@ function deriveDefaultContentOutputPath(description, referencedFiles) {
|
|
|
1606
1616
|
const fileBase = basename(primaryRef, extname(primaryRef));
|
|
1607
1617
|
const outName = `${fileBase}${sampleSuffix}.md`;
|
|
1608
1618
|
const output = baseDir === "." ? `daily-exercises/${outName}` : join(baseDir, outName);
|
|
1609
|
-
|
|
1619
|
+
const normalizedOutput = output.replace(/\\/g, "/");
|
|
1620
|
+
debugLog("plan", "outputs.derived", "Derived default content output path", {
|
|
1621
|
+
desiredDay,
|
|
1622
|
+
primaryRef,
|
|
1623
|
+
output: normalizedOutput
|
|
1624
|
+
});
|
|
1625
|
+
return normalizedOutput;
|
|
1610
1626
|
}
|
|
1611
1627
|
function extractReferencedFiles(description) {
|
|
1612
1628
|
const references = /* @__PURE__ */ new Set();
|
|
1613
1629
|
const barePattern = /\b[\w./-]+\.(md|txt|json|yaml|yml|png|jpg|jpeg|gif|svg|pdf)\b/gi;
|
|
1614
|
-
const
|
|
1630
|
+
const absolutePattern = /(?:^|[\s("'`])((?:\/[^"'`\s]+)+\.(?:md|txt|json|yaml|yml|png|jpg|jpeg|gif|svg|pdf))/gi;
|
|
1631
|
+
const quotedPattern = /["']([^"']+\.(?:md|txt|json|yaml|yml|png|jpg|jpeg|gif|svg|pdf))["']/gi;
|
|
1615
1632
|
let match;
|
|
1616
1633
|
while ((match = quotedPattern.exec(description)) !== null) {
|
|
1617
1634
|
if (match[1]) {
|
|
@@ -1623,6 +1640,11 @@ function extractReferencedFiles(description) {
|
|
|
1623
1640
|
references.add(match[0].replace(/["'`,]/g, "").trim());
|
|
1624
1641
|
}
|
|
1625
1642
|
}
|
|
1643
|
+
while ((match = absolutePattern.exec(description)) !== null) {
|
|
1644
|
+
if (match[1]) {
|
|
1645
|
+
references.add(match[1].replace(/["'`,]/g, "").trim());
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1626
1648
|
return Array.from(references).filter((ref) => ref.length > 0);
|
|
1627
1649
|
}
|
|
1628
1650
|
async function loadReferencedFileSummaries(references) {
|
|
@@ -1630,13 +1652,21 @@ async function loadReferencedFileSummaries(references) {
|
|
|
1630
1652
|
const missingFiles = [];
|
|
1631
1653
|
const fileSummaries = [];
|
|
1632
1654
|
for (const ref of references) {
|
|
1633
|
-
const
|
|
1634
|
-
const absolute = join(process.cwd(), normalized);
|
|
1655
|
+
const absolute = resolveReferencePath(process.cwd(), ref);
|
|
1635
1656
|
if (!existsSync(absolute)) {
|
|
1636
1657
|
missingFiles.push(ref);
|
|
1658
|
+
debugLog("plan", "references.missing", "Referenced file missing on disk", {
|
|
1659
|
+
ref,
|
|
1660
|
+
absolute
|
|
1661
|
+
});
|
|
1637
1662
|
continue;
|
|
1638
1663
|
}
|
|
1639
1664
|
foundFiles.push(ref);
|
|
1665
|
+
debugLog("plan", "references.found", "Referenced file found on disk", {
|
|
1666
|
+
ref,
|
|
1667
|
+
absolute,
|
|
1668
|
+
relative: relative(process.cwd(), absolute).replace(/\\/g, "/")
|
|
1669
|
+
});
|
|
1640
1670
|
const isImage = /\.(png|jpg|jpeg|gif|svg)$/i.test(ref);
|
|
1641
1671
|
if (isImage) {
|
|
1642
1672
|
try {
|
|
@@ -1669,6 +1699,40 @@ async function loadReferencedFileSummaries(references) {
|
|
|
1669
1699
|
}
|
|
1670
1700
|
return { foundFiles, missingFiles, fileSummaries };
|
|
1671
1701
|
}
|
|
1702
|
+
function resolveReferencePath(cwd, ref) {
|
|
1703
|
+
const cleaned = ref.trim().replace(/^["']|["']$/g, "");
|
|
1704
|
+
if (isAbsolute(cleaned)) {
|
|
1705
|
+
return resolve(cleaned);
|
|
1706
|
+
}
|
|
1707
|
+
return resolve(cwd, cleaned.replace(/^\.?\//, ""));
|
|
1708
|
+
}
|
|
1709
|
+
function inferRequestedDay(description) {
|
|
1710
|
+
if (/\bfirst lesson\b/i.test(description)) return 1;
|
|
1711
|
+
const dayMatch = description.match(/\bday[\s_-]*0?(\d{1,2})\b/i);
|
|
1712
|
+
if (!dayMatch?.[1]) return null;
|
|
1713
|
+
const parsed = Number.parseInt(dayMatch[1], 10);
|
|
1714
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
1715
|
+
}
|
|
1716
|
+
function pickPreferredReference(referencedFiles, desiredDay) {
|
|
1717
|
+
const markdownRefs = referencedFiles.filter((ref) => /\.(md|txt|markdown)$/i.test(ref));
|
|
1718
|
+
if (markdownRefs.length === 0) return void 0;
|
|
1719
|
+
const prioritized = markdownRefs.slice().sort((a, b) => {
|
|
1720
|
+
const aOld = /(^|\/)oldies(\/|$)/i.test(a) ? 1 : 0;
|
|
1721
|
+
const bOld = /(^|\/)oldies(\/|$)/i.test(b) ? 1 : 0;
|
|
1722
|
+
if (aOld !== bOld) return aOld - bOld;
|
|
1723
|
+
const aCore = /^(daily-exercises|curriculum|research)\//i.test(a) ? 0 : 1;
|
|
1724
|
+
const bCore = /^(daily-exercises|curriculum|research)\//i.test(b) ? 0 : 1;
|
|
1725
|
+
return aCore - bCore;
|
|
1726
|
+
});
|
|
1727
|
+
if (desiredDay !== null) {
|
|
1728
|
+
const matchByDay = prioritized.find((ref) => {
|
|
1729
|
+
const dayPattern = new RegExp(`\\b(day|lesson|email[-_ ]day)[-_ ]?0*${desiredDay}\\b`, "i");
|
|
1730
|
+
return dayPattern.test(ref);
|
|
1731
|
+
});
|
|
1732
|
+
if (matchByDay) return matchByDay;
|
|
1733
|
+
}
|
|
1734
|
+
return prioritized[0];
|
|
1735
|
+
}
|
|
1672
1736
|
async function promptForDeliverableTarget(prompt2, requirements, references) {
|
|
1673
1737
|
const mentionsResearch = requirements.some((req) => req.toLowerCase().includes("research"));
|
|
1674
1738
|
const defaultTarget = references.find((ref) => ref.toLowerCase().endsWith(".md"));
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/cli/debug.ts
|
|
2
|
+
import { appendFileSync, existsSync, mkdirSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
function isDebugEnabled() {
|
|
5
|
+
const value = process.env["ARCHON_DEBUG"]?.trim().toLowerCase();
|
|
6
|
+
return value === "1" || value === "true" || value === "yes" || value === "on";
|
|
7
|
+
}
|
|
8
|
+
function createRunId() {
|
|
9
|
+
const now = /* @__PURE__ */ new Date();
|
|
10
|
+
const yyyy = String(now.getFullYear());
|
|
11
|
+
const mm = String(now.getMonth() + 1).padStart(2, "0");
|
|
12
|
+
const dd = String(now.getDate()).padStart(2, "0");
|
|
13
|
+
const hh = String(now.getHours()).padStart(2, "0");
|
|
14
|
+
const mi = String(now.getMinutes()).padStart(2, "0");
|
|
15
|
+
const ss = String(now.getSeconds()).padStart(2, "0");
|
|
16
|
+
return `${yyyy}${mm}${dd}-${hh}${mi}${ss}-${process.pid}`;
|
|
17
|
+
}
|
|
18
|
+
var RUN_ID = createRunId();
|
|
19
|
+
var LOG_PATH = join(process.cwd(), ".archon", "debug", `${RUN_ID}.log`);
|
|
20
|
+
function redactValue(value) {
|
|
21
|
+
if (typeof value === "string") {
|
|
22
|
+
if (value.length > 3e3) {
|
|
23
|
+
return `${value.slice(0, 3e3)}... [truncated]`;
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(value)) {
|
|
28
|
+
return value.map(redactValue);
|
|
29
|
+
}
|
|
30
|
+
if (value && typeof value === "object") {
|
|
31
|
+
const out = {};
|
|
32
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
33
|
+
if (/(token|secret|key|password|authorization|auth)/i.test(key)) {
|
|
34
|
+
out[key] = "[redacted]";
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
out[key] = redactValue(nested);
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
function getDebugLogPath() {
|
|
44
|
+
return isDebugEnabled() ? LOG_PATH : null;
|
|
45
|
+
}
|
|
46
|
+
function debugLog(scope, stage, message, data) {
|
|
47
|
+
if (!isDebugEnabled()) return;
|
|
48
|
+
const payload = {
|
|
49
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
50
|
+
scope,
|
|
51
|
+
stage,
|
|
52
|
+
message,
|
|
53
|
+
data: redactValue(data)
|
|
54
|
+
};
|
|
55
|
+
const dir = join(process.cwd(), ".archon", "debug");
|
|
56
|
+
if (!existsSync(dir)) {
|
|
57
|
+
mkdirSync(dir, { recursive: true });
|
|
58
|
+
}
|
|
59
|
+
appendFileSync(LOG_PATH, `${JSON.stringify(payload)}
|
|
60
|
+
`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export {
|
|
64
|
+
getDebugLogPath,
|
|
65
|
+
debugLog
|
|
66
|
+
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
execute
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ICPOD7FC.js";
|
|
4
4
|
import "./chunk-EBHHIUCB.js";
|
|
5
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-QKHRSVUO.js";
|
|
6
6
|
import "./chunk-WGLVDEZC.js";
|
|
7
7
|
import "./chunk-3MZOEZUH.js";
|
|
8
8
|
import "./chunk-F7R3QKHP.js";
|
|
9
|
+
import "./chunk-R664NEAA.js";
|
|
9
10
|
import "./chunk-Q3GIFHIQ.js";
|
|
10
11
|
import "./chunk-5EVHUDQX.js";
|
|
11
12
|
import "./chunk-7C6JELBL.js";
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "./chunk-6URKZ7NB.js";
|
|
14
14
|
import {
|
|
15
15
|
show
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-DDAOREZF.js";
|
|
17
17
|
import {
|
|
18
18
|
bugReport
|
|
19
19
|
} from "./chunk-AHK2ITJX.js";
|
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
showExecutionPreferences,
|
|
39
39
|
showPreferences,
|
|
40
40
|
showUsageDetails
|
|
41
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-LM5UBTSS.js";
|
|
42
42
|
import {
|
|
43
43
|
init,
|
|
44
44
|
isInitialized
|
|
@@ -50,13 +50,13 @@ import {
|
|
|
50
50
|
parallelRunWaves,
|
|
51
51
|
parallelSchedule,
|
|
52
52
|
parallelStatus
|
|
53
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-K6A6CWUG.js";
|
|
54
54
|
import {
|
|
55
55
|
DependencyParser,
|
|
56
56
|
EnvironmentConfigLoader,
|
|
57
57
|
EnvironmentValidator,
|
|
58
58
|
execute
|
|
59
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-ICPOD7FC.js";
|
|
60
60
|
import {
|
|
61
61
|
cloudCancel,
|
|
62
62
|
cloudLogs,
|
|
@@ -64,12 +64,12 @@ import {
|
|
|
64
64
|
} from "./chunk-EBHHIUCB.js";
|
|
65
65
|
import {
|
|
66
66
|
list
|
|
67
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-TNS5OLCD.js";
|
|
68
68
|
import {
|
|
69
69
|
listLocalAtoms,
|
|
70
70
|
loadAtom,
|
|
71
71
|
plan
|
|
72
|
-
} from "./chunk-
|
|
72
|
+
} from "./chunk-QKHRSVUO.js";
|
|
73
73
|
import "./chunk-WGLVDEZC.js";
|
|
74
74
|
import "./chunk-3MZOEZUH.js";
|
|
75
75
|
import {
|
|
@@ -77,6 +77,10 @@ import {
|
|
|
77
77
|
ok,
|
|
78
78
|
sleep
|
|
79
79
|
} from "./chunk-F7R3QKHP.js";
|
|
80
|
+
import {
|
|
81
|
+
debugLog,
|
|
82
|
+
getDebugLogPath
|
|
83
|
+
} from "./chunk-R664NEAA.js";
|
|
80
84
|
import {
|
|
81
85
|
createAuthedSupabaseClient
|
|
82
86
|
} from "./chunk-Q3GIFHIQ.js";
|
|
@@ -2714,6 +2718,11 @@ function uiSeparator() {
|
|
|
2714
2718
|
}
|
|
2715
2719
|
async function start(options = {}) {
|
|
2716
2720
|
const cwd = process.cwd();
|
|
2721
|
+
const debugPath = getDebugLogPath();
|
|
2722
|
+
if (debugPath) {
|
|
2723
|
+
console.log(chalk6.dim(`Debug logging enabled: ${debugPath}`));
|
|
2724
|
+
}
|
|
2725
|
+
debugLog("start", "session.begin", "Starting archon session", { cwd });
|
|
2717
2726
|
displayBrandedHeader();
|
|
2718
2727
|
const updateCheckPromise = startBackgroundUpdateCheck();
|
|
2719
2728
|
let config = await loadConfig();
|
|
@@ -2844,13 +2853,40 @@ async function start(options = {}) {
|
|
|
2844
2853
|
if (currentTier === "BYOK" && config.accessToken) {
|
|
2845
2854
|
try {
|
|
2846
2855
|
const resolvedAuthId = await resolveAuthIdFromToken(config.accessToken, config.userId);
|
|
2856
|
+
debugLog("start", "byok_usage.identity", "Resolved auth/profile identity for BYOK startup usage", {
|
|
2857
|
+
configUserId: config.userId ?? null,
|
|
2858
|
+
resolvedAuthId
|
|
2859
|
+
});
|
|
2847
2860
|
let usageStats = await fetchByokUsageStats(config.accessToken);
|
|
2848
2861
|
const apiLooksEmpty = !!usageStats && usageStats.totalInputTokens === 0 && usageStats.totalOutputTokens === 0 && usageStats.totalBaseCost === 0 && usageStats.byModel.length === 0;
|
|
2862
|
+
debugLog("start", "byok_usage.api", "Fetched BYOK usage from /api/usage", {
|
|
2863
|
+
usageStatsPresent: !!usageStats,
|
|
2864
|
+
apiLooksEmpty,
|
|
2865
|
+
totals: usageStats ? {
|
|
2866
|
+
totalInputTokens: usageStats.totalInputTokens,
|
|
2867
|
+
totalOutputTokens: usageStats.totalOutputTokens,
|
|
2868
|
+
totalBaseCost: usageStats.totalBaseCost,
|
|
2869
|
+
byModelCount: usageStats.byModel.length
|
|
2870
|
+
} : null
|
|
2871
|
+
});
|
|
2849
2872
|
if (!usageStats || apiLooksEmpty && resolvedAuthId) {
|
|
2850
2873
|
const supabaseStats = resolvedAuthId ? await fetchByokUsageStatsFromSupabase(config.accessToken, resolvedAuthId) : null;
|
|
2851
2874
|
if (supabaseStats) {
|
|
2852
2875
|
usageStats = supabaseStats;
|
|
2853
2876
|
}
|
|
2877
|
+
debugLog("start", "byok_usage.supabase_fallback", "Fetched BYOK usage from Supabase fallback", {
|
|
2878
|
+
fallbackAttempted: !!resolvedAuthId,
|
|
2879
|
+
fallbackReturned: !!supabaseStats,
|
|
2880
|
+
totals: supabaseStats ? {
|
|
2881
|
+
totalInputTokens: supabaseStats.totalInputTokens,
|
|
2882
|
+
totalOutputTokens: supabaseStats.totalOutputTokens,
|
|
2883
|
+
totalBaseCost: supabaseStats.totalBaseCost,
|
|
2884
|
+
byModelCount: supabaseStats.byModel.length,
|
|
2885
|
+
periodStart: supabaseStats.periodStart,
|
|
2886
|
+
periodEnd: supabaseStats.periodEnd,
|
|
2887
|
+
periodSource: supabaseStats.periodSource
|
|
2888
|
+
} : null
|
|
2889
|
+
});
|
|
2854
2890
|
}
|
|
2855
2891
|
const usageStatsUnavailable = !usageStats;
|
|
2856
2892
|
if (!usageStats) {
|
|
@@ -2892,7 +2928,7 @@ async function start(options = {}) {
|
|
|
2892
2928
|
}
|
|
2893
2929
|
console.log(chalk6.dim(uiSeparator()));
|
|
2894
2930
|
if (usageStatsUnavailable) {
|
|
2895
|
-
console.log(chalk6.dim("Usage details may be delayed. Run `archon usage` to
|
|
2931
|
+
console.log(chalk6.dim("Usage details may be delayed. Run `archon usage --debug` to inspect identity/source windows."));
|
|
2896
2932
|
}
|
|
2897
2933
|
console.log(chalk6.dim("View details: archon usage | Models: archon preferences | Switch tier: archon upgrade"));
|
|
2898
2934
|
} catch {
|
|
@@ -3078,6 +3114,9 @@ async function fetchByokUsageStats(accessToken) {
|
|
|
3078
3114
|
}
|
|
3079
3115
|
});
|
|
3080
3116
|
if (!response.ok) {
|
|
3117
|
+
debugLog("start", "byok_usage.api_error", "BYOK /api/usage returned non-OK status", {
|
|
3118
|
+
status: response.status
|
|
3119
|
+
});
|
|
3081
3120
|
return null;
|
|
3082
3121
|
}
|
|
3083
3122
|
const data = await response.json();
|
|
@@ -3098,6 +3137,7 @@ async function fetchByokUsageStats(accessToken) {
|
|
|
3098
3137
|
periodSource: data.periodSource
|
|
3099
3138
|
};
|
|
3100
3139
|
} catch {
|
|
3140
|
+
debugLog("start", "byok_usage.api_exception", "BYOK /api/usage request threw exception");
|
|
3101
3141
|
return null;
|
|
3102
3142
|
}
|
|
3103
3143
|
}
|
|
@@ -3106,43 +3146,84 @@ async function fetchByokUsageStatsFromSupabase(accessToken, authId) {
|
|
|
3106
3146
|
const { SUPABASE_URL: SUPABASE_URL2, SUPABASE_ANON_KEY: SUPABASE_ANON_KEY2 } = await import("./constants-XDIWFFPN.js");
|
|
3107
3147
|
const { createAuthedSupabaseClient: createAuthedSupabaseClient2 } = await import("./client-PHW2C2HB.js");
|
|
3108
3148
|
const supabase = createAuthedSupabaseClient2(SUPABASE_URL2, SUPABASE_ANON_KEY2, accessToken);
|
|
3109
|
-
const
|
|
3110
|
-
|
|
3111
|
-
|
|
3149
|
+
const profileId = await resolveProfileIdForUsage(supabase, authId);
|
|
3150
|
+
if (!profileId) {
|
|
3151
|
+
debugLog("start", "byok_usage.profile_missing", "Could not resolve profile ID for BYOK Supabase fallback", {
|
|
3152
|
+
authId
|
|
3153
|
+
});
|
|
3112
3154
|
return null;
|
|
3113
3155
|
}
|
|
3114
3156
|
const now = /* @__PURE__ */ new Date();
|
|
3115
|
-
const
|
|
3116
|
-
const
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
byModelMap.set(row.model, (byModelMap.get(row.model) ?? 0) + baseCost);
|
|
3157
|
+
const monthStart = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
3158
|
+
const monthStats = await fetchByokUsageWindow(supabase, profileId, monthStart, now);
|
|
3159
|
+
if (hasAnyByokUsage(monthStats)) {
|
|
3160
|
+
debugLog("start", "byok_usage.window", "Using month-to-date BYOK fallback window", {
|
|
3161
|
+
profileId,
|
|
3162
|
+
start: monthStart.toISOString(),
|
|
3163
|
+
end: now.toISOString(),
|
|
3164
|
+
totals: monthStats
|
|
3165
|
+
});
|
|
3166
|
+
return {
|
|
3167
|
+
...monthStats,
|
|
3168
|
+
periodStart: monthStart.toISOString(),
|
|
3169
|
+
periodEnd: now.toISOString(),
|
|
3170
|
+
periodSource: "month"
|
|
3171
|
+
};
|
|
3131
3172
|
}
|
|
3132
|
-
const
|
|
3173
|
+
const trailingStart = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1e3);
|
|
3174
|
+
const trailingStats = await fetchByokUsageWindow(supabase, profileId, trailingStart, now);
|
|
3175
|
+
debugLog("start", "byok_usage.window", "Using trailing 30-day BYOK fallback window", {
|
|
3176
|
+
profileId,
|
|
3177
|
+
start: trailingStart.toISOString(),
|
|
3178
|
+
end: now.toISOString(),
|
|
3179
|
+
totals: trailingStats
|
|
3180
|
+
});
|
|
3133
3181
|
return {
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
periodStart: periodStart.toISOString(),
|
|
3139
|
-
periodEnd: periodEnd.toISOString(),
|
|
3140
|
-
periodSource: profile.current_period_start ? "profile_period" : "month"
|
|
3182
|
+
...trailingStats,
|
|
3183
|
+
periodStart: trailingStart.toISOString(),
|
|
3184
|
+
periodEnd: now.toISOString(),
|
|
3185
|
+
periodSource: "profile_period"
|
|
3141
3186
|
};
|
|
3142
3187
|
} catch {
|
|
3188
|
+
debugLog("start", "byok_usage.supabase_exception", "BYOK Supabase fallback threw exception");
|
|
3143
3189
|
return null;
|
|
3144
3190
|
}
|
|
3145
3191
|
}
|
|
3192
|
+
async function resolveProfileIdForUsage(supabase, authId) {
|
|
3193
|
+
const { data: byAuthRaw } = await supabase.from("user_profiles").select("id").eq("auth_id", authId).maybeSingle();
|
|
3194
|
+
const byAuth = byAuthRaw;
|
|
3195
|
+
if (byAuth?.id) {
|
|
3196
|
+
return byAuth.id;
|
|
3197
|
+
}
|
|
3198
|
+
const { data: byProfileRaw } = await supabase.from("user_profiles").select("id").eq("id", authId).maybeSingle();
|
|
3199
|
+
const byProfile = byProfileRaw;
|
|
3200
|
+
return byProfile?.id ?? null;
|
|
3201
|
+
}
|
|
3202
|
+
async function fetchByokUsageWindow(supabase, profileId, start2, end) {
|
|
3203
|
+
const { data: rawUsageRows } = await supabase.from("token_usage").select("model, input_tokens, output_tokens, base_cost, total_cents, marked_up_cost").eq("user_id", profileId).gte("created_at", start2.toISOString()).lte("created_at", end.toISOString());
|
|
3204
|
+
const usageRows = rawUsageRows;
|
|
3205
|
+
let totalInputTokens = 0;
|
|
3206
|
+
let totalOutputTokens = 0;
|
|
3207
|
+
let totalBaseCost = 0;
|
|
3208
|
+
const byModelMap = /* @__PURE__ */ new Map();
|
|
3209
|
+
for (const row of usageRows ?? []) {
|
|
3210
|
+
totalInputTokens += row.input_tokens ?? 0;
|
|
3211
|
+
totalOutputTokens += row.output_tokens ?? 0;
|
|
3212
|
+
const baseCost = typeof row.base_cost === "number" ? row.base_cost : typeof row.total_cents === "number" ? row.total_cents / 100 : typeof row.marked_up_cost === "number" ? row.marked_up_cost : 0;
|
|
3213
|
+
totalBaseCost += baseCost;
|
|
3214
|
+
byModelMap.set(row.model, (byModelMap.get(row.model) ?? 0) + baseCost);
|
|
3215
|
+
}
|
|
3216
|
+
const byModel = Array.from(byModelMap.entries()).map(([model, cost]) => ({ model, cost })).sort((a, b) => b.cost - a.cost);
|
|
3217
|
+
return {
|
|
3218
|
+
totalInputTokens,
|
|
3219
|
+
totalOutputTokens,
|
|
3220
|
+
totalBaseCost,
|
|
3221
|
+
byModel
|
|
3222
|
+
};
|
|
3223
|
+
}
|
|
3224
|
+
function hasAnyByokUsage(stats) {
|
|
3225
|
+
return stats.totalInputTokens > 0 || stats.totalOutputTokens > 0 || stats.totalBaseCost > 0 || stats.byModel.length > 0;
|
|
3226
|
+
}
|
|
3146
3227
|
async function fetchCreditsUsageStatsFromSupabase(accessToken, authId) {
|
|
3147
3228
|
try {
|
|
3148
3229
|
const { SUPABASE_URL: SUPABASE_URL2, SUPABASE_ANON_KEY: SUPABASE_ANON_KEY2 } = await import("./constants-XDIWFFPN.js");
|
|
@@ -3394,7 +3475,7 @@ async function runExploreFlow(cwd, followUpInput, options = {}) {
|
|
|
3394
3475
|
case "1": {
|
|
3395
3476
|
const description = await promptWithCommands("Describe what you want to do", { allowMultiline: true });
|
|
3396
3477
|
if (description.trim()) {
|
|
3397
|
-
const { plan: plan2 } = await import("./plan-
|
|
3478
|
+
const { plan: plan2 } = await import("./plan-7YU2U4RY.js");
|
|
3398
3479
|
await plan2(description, { conversational: true });
|
|
3399
3480
|
}
|
|
3400
3481
|
await showMainMenu();
|
|
@@ -3639,7 +3720,7 @@ ${state.forbiddenPatterns?.length ? `- **Forbidden patterns:** ${state.forbidden
|
|
|
3639
3720
|
const hintedTask = initialTaskHint?.trim() ?? "";
|
|
3640
3721
|
if (hintedTask) {
|
|
3641
3722
|
console.log(chalk6.dim("Using your request above as the first task.\n"));
|
|
3642
|
-
const { plan: plan2 } = await import("./plan-
|
|
3723
|
+
const { plan: plan2 } = await import("./plan-7YU2U4RY.js");
|
|
3643
3724
|
await plan2(hintedTask, { conversational: true });
|
|
3644
3725
|
return;
|
|
3645
3726
|
}
|
|
@@ -3664,7 +3745,7 @@ ${state.forbiddenPatterns?.length ? `- **Forbidden patterns:** ${state.forbidden
|
|
|
3664
3745
|
description = continueAnswer.trim();
|
|
3665
3746
|
}
|
|
3666
3747
|
if (description.trim()) {
|
|
3667
|
-
const { plan: plan2 } = await import("./plan-
|
|
3748
|
+
const { plan: plan2 } = await import("./plan-7YU2U4RY.js");
|
|
3668
3749
|
await plan2(description, { conversational: true });
|
|
3669
3750
|
}
|
|
3670
3751
|
}
|
|
@@ -3893,7 +3974,7 @@ async function handleAgentConversationInput(cwd, input) {
|
|
|
3893
3974
|
return true;
|
|
3894
3975
|
}
|
|
3895
3976
|
console.log(chalk6.dim("\n> Got it! Creating a task for this...\n"));
|
|
3896
|
-
const { plan: plan2 } = await import("./plan-
|
|
3977
|
+
const { plan: plan2 } = await import("./plan-7YU2U4RY.js");
|
|
3897
3978
|
await plan2(await withAllowedPathScope(cwd, input), { conversational: true });
|
|
3898
3979
|
if (shouldAutoExecuteAfterPlanning(input)) {
|
|
3899
3980
|
await continueWithCurrentTask(cwd, { runAllReady: true });
|
|
@@ -3940,7 +4021,7 @@ async function showProposalForApproval(input) {
|
|
|
3940
4021
|
}
|
|
3941
4022
|
}
|
|
3942
4023
|
async function showLatestPlannedAtom(cwd) {
|
|
3943
|
-
const { listLocalAtoms: listLocalAtoms2 } = await import("./plan-
|
|
4024
|
+
const { listLocalAtoms: listLocalAtoms2 } = await import("./plan-7YU2U4RY.js");
|
|
3944
4025
|
const atoms = await listLocalAtoms2();
|
|
3945
4026
|
if (atoms.length === 0) {
|
|
3946
4027
|
console.log(chalk6.yellow("No atoms found yet. Tell me what to plan."));
|
|
@@ -3958,7 +4039,7 @@ async function showLatestPlannedAtom(cwd) {
|
|
|
3958
4039
|
console.log(chalk6.dim(`
|
|
3959
4040
|
Showing latest planned atom (${latest.externalId})...
|
|
3960
4041
|
`));
|
|
3961
|
-
const { show: show2 } = await import("./show-
|
|
4042
|
+
const { show: show2 } = await import("./show-VLTLYZDI.js");
|
|
3962
4043
|
await show2(latest.externalId);
|
|
3963
4044
|
}
|
|
3964
4045
|
function isContinuationDirective(input) {
|
|
@@ -4091,7 +4172,7 @@ async function applyApprovedProposal(cwd) {
|
|
|
4091
4172
|
console.log(chalk6.dim('\nReply "continue" when you want execution to start.'));
|
|
4092
4173
|
}
|
|
4093
4174
|
async function createTaskFromRequest(cwd, request) {
|
|
4094
|
-
const { plan: plan2, listLocalAtoms: listLocalAtoms2 } = await import("./plan-
|
|
4175
|
+
const { plan: plan2, listLocalAtoms: listLocalAtoms2 } = await import("./plan-7YU2U4RY.js");
|
|
4095
4176
|
const before = await listLocalAtoms2();
|
|
4096
4177
|
const beforeIds = new Set(before.map((atom) => atom.externalId));
|
|
4097
4178
|
await plan2(await withAllowedPathScope(cwd, request), { conversational: true });
|
|
@@ -4267,13 +4348,13 @@ function buildSampleCapsuleDraft(cwd, files, capsuleCount) {
|
|
|
4267
4348
|
].join("\n");
|
|
4268
4349
|
}
|
|
4269
4350
|
async function continueWithCurrentTask(cwd, options = {}) {
|
|
4270
|
-
const { listLocalAtoms: listLocalAtoms2 } = await import("./plan-
|
|
4351
|
+
const { listLocalAtoms: listLocalAtoms2 } = await import("./plan-7YU2U4RY.js");
|
|
4271
4352
|
const byMostRecent = (a, b) => {
|
|
4272
4353
|
const aTime = new Date(String(a.updatedAt ?? a.createdAt ?? "")).getTime() || 0;
|
|
4273
4354
|
const bTime = new Date(String(b.updatedAt ?? b.createdAt ?? "")).getTime() || 0;
|
|
4274
4355
|
return bTime - aTime;
|
|
4275
4356
|
};
|
|
4276
|
-
const { execute: execute2 } = await import("./execute-
|
|
4357
|
+
const { execute: execute2 } = await import("./execute-4KDY6MOO.js");
|
|
4277
4358
|
const runAllReady = options.runAllReady === true;
|
|
4278
4359
|
const scopeIds = options.onlyAtomIds ? new Set(options.onlyAtomIds) : null;
|
|
4279
4360
|
const attempted = /* @__PURE__ */ new Set();
|
|
@@ -4333,7 +4414,7 @@ Continuing with ${nextAtom.externalId}...
|
|
|
4333
4414
|
}
|
|
4334
4415
|
await execute2(nextAtom.externalId, {
|
|
4335
4416
|
nonTerminating: true,
|
|
4336
|
-
pathScopeAutoRecover:
|
|
4417
|
+
pathScopeAutoRecover: true
|
|
4337
4418
|
});
|
|
4338
4419
|
if (!runAllReady) {
|
|
4339
4420
|
return;
|
|
@@ -4349,7 +4430,7 @@ Continuing with ${nextAtom.externalId}...
|
|
|
4349
4430
|
}
|
|
4350
4431
|
}
|
|
4351
4432
|
async function replanLatestBlockedAtom(cwd) {
|
|
4352
|
-
const { listLocalAtoms: listLocalAtoms2, plan: plan2 } = await import("./plan-
|
|
4433
|
+
const { listLocalAtoms: listLocalAtoms2, plan: plan2 } = await import("./plan-7YU2U4RY.js");
|
|
4353
4434
|
const atoms = await listLocalAtoms2();
|
|
4354
4435
|
const blocked = atoms.filter((a) => a.status === "BLOCKED" && (a.errorMessage ?? "").toLowerCase().includes("outside the allowed paths")).sort((a, b) => {
|
|
4355
4436
|
const aTime = new Date(String(a.updatedAt ?? a.createdAt ?? "")).getTime() || 0;
|
|
@@ -4463,7 +4544,7 @@ async function handleFreeformJourneyInput(cwd, input) {
|
|
|
4463
4544
|
const state = detectProjectState(cwd);
|
|
4464
4545
|
if (state.hasArchitecture) {
|
|
4465
4546
|
console.log(chalk6.dim("\n> Got it! Creating a task for this...\n"));
|
|
4466
|
-
const { plan: plan3 } = await import("./plan-
|
|
4547
|
+
const { plan: plan3 } = await import("./plan-7YU2U4RY.js");
|
|
4467
4548
|
await plan3(await withAllowedPathScope(cwd, freeform), { conversational: true });
|
|
4468
4549
|
return true;
|
|
4469
4550
|
}
|
|
@@ -4472,7 +4553,7 @@ async function handleFreeformJourneyInput(cwd, input) {
|
|
|
4472
4553
|
return true;
|
|
4473
4554
|
}
|
|
4474
4555
|
console.log(chalk6.dim("\n> Got it! Creating a task for this...\n"));
|
|
4475
|
-
const { plan: plan2 } = await import("./plan-
|
|
4556
|
+
const { plan: plan2 } = await import("./plan-7YU2U4RY.js");
|
|
4476
4557
|
await plan2(await withAllowedPathScope(cwd, freeform), { conversational: true });
|
|
4477
4558
|
return true;
|
|
4478
4559
|
}
|
|
@@ -4521,7 +4602,7 @@ function isFileLocationQuestion(input) {
|
|
|
4521
4602
|
return true;
|
|
4522
4603
|
}
|
|
4523
4604
|
async function answerLatestOutputLocation(cwd) {
|
|
4524
|
-
const { listLocalAtoms: listLocalAtoms2 } = await import("./plan-
|
|
4605
|
+
const { listLocalAtoms: listLocalAtoms2 } = await import("./plan-7YU2U4RY.js");
|
|
4525
4606
|
const atoms = await listLocalAtoms2();
|
|
4526
4607
|
const latestDone = atoms.filter((atom) => atom.status === "DONE").sort((a, b) => {
|
|
4527
4608
|
const aTime = new Date(String(a.updatedAt ?? a.createdAt ?? "")).getTime() || 0;
|
|
@@ -4570,7 +4651,7 @@ async function handlePostExploreAction(cwd, request, options = {}) {
|
|
|
4570
4651
|
} else {
|
|
4571
4652
|
console.log(chalk6.dim("> Got it! Creating a task for this...\n"));
|
|
4572
4653
|
}
|
|
4573
|
-
const { plan: plan2 } = await import("./plan-
|
|
4654
|
+
const { plan: plan2 } = await import("./plan-7YU2U4RY.js");
|
|
4574
4655
|
await plan2(await withAllowedPathScope(cwd, request), { conversational: true });
|
|
4575
4656
|
if (options.agentMode) {
|
|
4576
4657
|
if (shouldAutoExecuteAfterPlanning(sourceInput)) {
|
|
@@ -4594,20 +4675,20 @@ Constraints:
|
|
|
4594
4675
|
- If required files are outside this scope, propose the minimum architecture path update first.`;
|
|
4595
4676
|
}
|
|
4596
4677
|
async function planTask() {
|
|
4597
|
-
const { plan: plan2 } = await import("./plan-
|
|
4678
|
+
const { plan: plan2 } = await import("./plan-7YU2U4RY.js");
|
|
4598
4679
|
const description = await promptWithCommands("Describe what you want to build", { allowMultiline: true });
|
|
4599
4680
|
if (description.trim()) {
|
|
4600
4681
|
await plan2(description, { conversational: true });
|
|
4601
4682
|
}
|
|
4602
4683
|
}
|
|
4603
4684
|
async function listAtoms() {
|
|
4604
|
-
const { list: list2 } = await import("./list-
|
|
4685
|
+
const { list: list2 } = await import("./list-D4THOSHG.js");
|
|
4605
4686
|
await list2({});
|
|
4606
4687
|
}
|
|
4607
4688
|
async function executeNext() {
|
|
4608
|
-
const { listLocalAtoms: listLocalAtoms2 } = await import("./plan-
|
|
4689
|
+
const { listLocalAtoms: listLocalAtoms2 } = await import("./plan-7YU2U4RY.js");
|
|
4609
4690
|
const { analyzeProject, getComplexityDescription, getModeDescription } = await import("./orchestration-HIF3KP25.js");
|
|
4610
|
-
const { loadExecutionPreferences } = await import("./preferences-
|
|
4691
|
+
const { loadExecutionPreferences } = await import("./preferences-QTPQLCXN.js");
|
|
4611
4692
|
const cwd = process.cwd();
|
|
4612
4693
|
const atoms = await listLocalAtoms2();
|
|
4613
4694
|
const pendingAtoms = atoms.filter((a) => a.status === "READY" || a.status === "IN_PROGRESS");
|
|
@@ -4676,11 +4757,11 @@ async function executeNext() {
|
|
|
4676
4757
|
}
|
|
4677
4758
|
}
|
|
4678
4759
|
if (selectedMode === "parallel-cloud") {
|
|
4679
|
-
const { parallelExecuteCloud: parallelExecuteCloud2 } = await import("./parallel-
|
|
4760
|
+
const { parallelExecuteCloud: parallelExecuteCloud2 } = await import("./parallel-HUAAE6PS.js");
|
|
4680
4761
|
await parallelExecuteCloud2(runIds);
|
|
4681
4762
|
return;
|
|
4682
4763
|
}
|
|
4683
|
-
const { parallelExecute } = await import("./parallel-
|
|
4764
|
+
const { parallelExecute } = await import("./parallel-HUAAE6PS.js");
|
|
4684
4765
|
await parallelExecute(runIds);
|
|
4685
4766
|
return;
|
|
4686
4767
|
}
|
|
@@ -4688,7 +4769,7 @@ async function executeNext() {
|
|
|
4688
4769
|
const atomId = await prompt("Enter atom ID to execute (or press Enter for first pending)");
|
|
4689
4770
|
const targetId = atomId.trim() || pendingAtoms[0]?.id;
|
|
4690
4771
|
if (targetId) {
|
|
4691
|
-
const { execute: execute2 } = await import("./execute-
|
|
4772
|
+
const { execute: execute2 } = await import("./execute-4KDY6MOO.js");
|
|
4692
4773
|
await execute2(targetId, {});
|
|
4693
4774
|
} else {
|
|
4694
4775
|
console.log(chalk6.yellow("No atom to execute."));
|
|
@@ -4706,7 +4787,7 @@ async function viewStatus() {
|
|
|
4706
4787
|
await status2();
|
|
4707
4788
|
}
|
|
4708
4789
|
async function settingsMenu() {
|
|
4709
|
-
const { interactiveSettings } = await import("./preferences-
|
|
4790
|
+
const { interactiveSettings } = await import("./preferences-QTPQLCXN.js");
|
|
4710
4791
|
await interactiveSettings();
|
|
4711
4792
|
}
|
|
4712
4793
|
async function reviewCode() {
|
|
@@ -4837,7 +4918,7 @@ async function handleSlashCommand(input) {
|
|
|
4837
4918
|
const arg = parts.slice(1).join(" ").trim();
|
|
4838
4919
|
switch (command) {
|
|
4839
4920
|
case "/plan": {
|
|
4840
|
-
const { plan: plan2 } = await import("./plan-
|
|
4921
|
+
const { plan: plan2 } = await import("./plan-7YU2U4RY.js");
|
|
4841
4922
|
if (arg) {
|
|
4842
4923
|
await plan2(arg, { conversational: true });
|
|
4843
4924
|
} else {
|
|
@@ -9224,8 +9305,8 @@ creditsCommand.command("audit").description("Show billing audit log (immutable r
|
|
|
9224
9305
|
creditsCommand.action(async () => {
|
|
9225
9306
|
await showCredits();
|
|
9226
9307
|
});
|
|
9227
|
-
program.command("usage").description("Show usage by period and model").action(async () => {
|
|
9228
|
-
await showUsageDetails();
|
|
9308
|
+
program.command("usage").description("Show usage by period and model").option("--debug", "Show usage diagnostics (identity/window/source details)").action(async (options) => {
|
|
9309
|
+
await showUsageDetails({ debug: options.debug === true });
|
|
9229
9310
|
});
|
|
9230
9311
|
var preferencesCommand = program.command("preferences").description("Manage default model preferences");
|
|
9231
9312
|
preferencesCommand.command("set <key> <model>").description("Set a model preference (fast-model, thinking-model, primary-adversarial, secondary-adversarial)").action(async (key, model) => {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
list
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-TNS5OLCD.js";
|
|
4
|
+
import "./chunk-QKHRSVUO.js";
|
|
5
5
|
import "./chunk-WGLVDEZC.js";
|
|
6
6
|
import "./chunk-3MZOEZUH.js";
|
|
7
7
|
import "./chunk-F7R3QKHP.js";
|
|
8
|
+
import "./chunk-R664NEAA.js";
|
|
8
9
|
import "./chunk-Q3GIFHIQ.js";
|
|
9
10
|
import "./chunk-5EVHUDQX.js";
|
|
10
11
|
import "./chunk-7C6JELBL.js";
|
|
@@ -6,12 +6,13 @@ import {
|
|
|
6
6
|
parallelRunWaves,
|
|
7
7
|
parallelSchedule,
|
|
8
8
|
parallelStatus
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-K6A6CWUG.js";
|
|
10
10
|
import "./chunk-EBHHIUCB.js";
|
|
11
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-QKHRSVUO.js";
|
|
12
12
|
import "./chunk-WGLVDEZC.js";
|
|
13
13
|
import "./chunk-3MZOEZUH.js";
|
|
14
14
|
import "./chunk-F7R3QKHP.js";
|
|
15
|
+
import "./chunk-R664NEAA.js";
|
|
15
16
|
import "./chunk-Q3GIFHIQ.js";
|
|
16
17
|
import "./chunk-5EVHUDQX.js";
|
|
17
18
|
import "./chunk-7C6JELBL.js";
|
|
@@ -3,10 +3,11 @@ import {
|
|
|
3
3
|
loadAtom,
|
|
4
4
|
parseAtomDescription,
|
|
5
5
|
plan
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-QKHRSVUO.js";
|
|
7
7
|
import "./chunk-WGLVDEZC.js";
|
|
8
8
|
import "./chunk-3MZOEZUH.js";
|
|
9
9
|
import "./chunk-F7R3QKHP.js";
|
|
10
|
+
import "./chunk-R664NEAA.js";
|
|
10
11
|
import "./chunk-Q3GIFHIQ.js";
|
|
11
12
|
import "./chunk-5EVHUDQX.js";
|
|
12
13
|
import "./chunk-7C6JELBL.js";
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
showExecutionPreferences,
|
|
10
10
|
showPreferences,
|
|
11
11
|
showUsageDetails
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-LM5UBTSS.js";
|
|
13
|
+
import "./chunk-R664NEAA.js";
|
|
13
14
|
import "./chunk-Q3GIFHIQ.js";
|
|
14
15
|
import "./chunk-7C6JELBL.js";
|
|
15
16
|
import "./chunk-TFSHS7EN.js";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
show
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-DDAOREZF.js";
|
|
4
|
+
import "./chunk-QKHRSVUO.js";
|
|
5
5
|
import "./chunk-WGLVDEZC.js";
|
|
6
6
|
import "./chunk-3MZOEZUH.js";
|
|
7
7
|
import "./chunk-F7R3QKHP.js";
|
|
8
|
+
import "./chunk-R664NEAA.js";
|
|
8
9
|
import "./chunk-Q3GIFHIQ.js";
|
|
9
10
|
import "./chunk-5EVHUDQX.js";
|
|
10
11
|
import "./chunk-7C6JELBL.js";
|