sidekick-shared 0.27.5 → 0.28.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/CHANGELOG.md +58 -0
- package/README.md +93 -52
- package/dist/accountHealth.d.ts +14 -0
- package/dist/accountHealth.js +61 -14
- package/dist/accountLaunch.d.ts +6 -0
- package/dist/accountLaunch.js +61 -4
- package/dist/accountLease.d.ts +5 -0
- package/dist/accountLease.js +98 -0
- package/dist/accountManager.d.ts +7 -0
- package/dist/accountManager.js +226 -89
- package/dist/accountSync.d.ts +1 -5
- package/dist/accountSync.js +22 -6
- package/dist/accountSyncTypes.d.ts +9 -0
- package/dist/accounts.d.ts +75 -18
- package/dist/accounts.js +712 -189
- package/dist/browser.d.ts +13 -2
- package/dist/browser.js +30 -2
- package/dist/claudeCredentialDoctor.d.ts +50 -0
- package/dist/claudeCredentialDoctor.js +277 -0
- package/dist/claudeCredentialLedger.d.ts +15 -0
- package/dist/claudeCredentialLedger.js +130 -0
- package/dist/claudeCredentials.d.ts +20 -3
- package/dist/claudeCredentials.js +50 -3
- package/dist/claudeLiveGuard.d.ts +33 -0
- package/dist/claudeLiveGuard.js +46 -0
- package/dist/claudePaths.d.ts +11 -0
- package/dist/claudePaths.js +61 -0
- package/dist/claudeProfiles.d.ts +15 -8
- package/dist/claudeProfiles.js +30 -23
- package/dist/claudeRefreshLock.d.ts +15 -0
- package/dist/claudeRefreshLock.js +145 -0
- package/dist/codexAuth.d.ts +4 -0
- package/dist/codexAuth.js +18 -0
- package/dist/codexCredentialDoctor.d.ts +33 -0
- package/dist/codexCredentialDoctor.js +302 -0
- package/dist/codexCredentialStore.d.ts +29 -0
- package/dist/codexCredentialStore.js +213 -0
- package/dist/codexKeepAlive.d.ts +2 -0
- package/dist/codexKeepAlive.js +116 -0
- package/dist/codexPaths.d.ts +30 -2
- package/dist/codexPaths.js +118 -7
- package/dist/codexProfiles.d.ts +38 -35
- package/dist/codexProfiles.js +848 -715
- package/dist/credentialIO.d.ts +67 -7
- package/dist/credentialIO.js +211 -47
- package/dist/doctor.js +2 -2
- package/dist/ensureDefaultAccounts.js +1 -8
- package/dist/esm/accountChangeSignal.js +15 -0
- package/dist/esm/accountChanges.js +152 -0
- package/dist/esm/accountHealth.js +288 -0
- package/dist/esm/accountLaunch.js +145 -0
- package/dist/esm/accountLease.js +60 -0
- package/dist/esm/accountManager.js +606 -0
- package/dist/esm/accountRegistry.js +214 -0
- package/dist/esm/accountStatus.js +51 -0
- package/dist/esm/accountSwitch.js +74 -0
- package/dist/esm/accountSync.js +156 -0
- package/dist/esm/accountSyncTypes.js +4 -0
- package/dist/esm/accounts.js +1291 -0
- package/dist/esm/aggregation/EventAggregator.js +2034 -0
- package/dist/esm/aggregation/FrequencyTracker.js +69 -0
- package/dist/esm/aggregation/HeatmapTracker.js +89 -0
- package/dist/esm/aggregation/PatternExtractor.js +168 -0
- package/dist/esm/aggregation/costProvenance.js +31 -0
- package/dist/esm/aggregation/snapshot.js +161 -0
- package/dist/esm/aggregation/types.js +5 -0
- package/dist/esm/analytics/codeImpact.js +18 -0
- package/dist/esm/analytics/compactionLedger.js +37 -0
- package/dist/esm/analytics/qualityScore.js +112 -0
- package/dist/esm/autoSwitch.js +185 -0
- package/dist/esm/browser.js +34 -0
- package/dist/esm/claudeCredentialDoctor.js +239 -0
- package/dist/esm/claudeCredentialLedger.js +91 -0
- package/dist/esm/claudeCredentials.js +111 -0
- package/dist/esm/claudeLiveGuard.js +43 -0
- package/dist/esm/claudePaths.js +22 -0
- package/dist/esm/claudeProfiles.js +142 -0
- package/dist/esm/claudeRefreshLock.js +106 -0
- package/dist/esm/codexAuth.js +101 -0
- package/dist/esm/codexCredentialDoctor.js +265 -0
- package/dist/esm/codexCredentialStore.js +164 -0
- package/dist/esm/codexKeepAlive.js +112 -0
- package/dist/esm/codexPaths.js +172 -0
- package/dist/esm/codexProfiles.js +1251 -0
- package/dist/esm/codexQuota.js +564 -0
- package/dist/esm/codexQuotaWatcher.js +363 -0
- package/dist/esm/context/composer.js +71 -0
- package/dist/esm/context/sessionContext.js +546 -0
- package/dist/esm/credentialIO.js +283 -0
- package/dist/esm/credentials.js +49 -0
- package/dist/esm/doctor.js +305 -0
- package/dist/esm/ensureDefaultAccounts.js +62 -0
- package/dist/esm/errorHistory.js +56 -0
- package/dist/esm/extractors/errorTaxonomy.js +43 -0
- package/dist/esm/extractors/gatherAssets.js +32 -0
- package/dist/esm/extractors/sessionAssets.js +176 -0
- package/dist/esm/extractors/sources/claudeAssets.js +158 -0
- package/dist/esm/extractors/sources/codexAssets.js +234 -0
- package/dist/esm/extractors/tokenUsage.js +41 -0
- package/dist/esm/extractors/toolCall.js +142 -0
- package/dist/esm/failingTools.js +65 -0
- package/dist/esm/fileHead.js +27 -0
- package/dist/esm/formatters/eventHighlighter.js +332 -0
- package/dist/esm/formatters/noiseClassifier.js +209 -0
- package/dist/esm/formatters/sessionDump.js +328 -0
- package/dist/esm/formatters/toolSummary.js +226 -0
- package/dist/esm/formatting.js +82 -0
- package/dist/esm/handoffUrl.js +23 -0
- package/dist/esm/historicalStore.js +305 -0
- package/dist/esm/humanPrompt.js +88 -0
- package/dist/esm/index.js +213 -0
- package/dist/esm/keepAlive.js +189 -0
- package/dist/esm/liveCredentialGuard.js +33 -0
- package/dist/esm/modelAliases.js +51 -0
- package/dist/esm/modelCatalog.js +139 -0
- package/dist/esm/modelContext.js +280 -0
- package/dist/esm/modelInfo.js +832 -0
- package/dist/esm/multiProviderQuotaService.js +450 -0
- package/dist/esm/node.js +46 -0
- package/dist/esm/observedContextWindows.js +165 -0
- package/dist/esm/observedSessionCollector.js +939 -0
- package/dist/esm/parsers/changelogParser.js +71 -0
- package/dist/esm/parsers/codexHistory.js +89 -0
- package/dist/esm/parsers/codexParser.js +906 -0
- package/dist/esm/parsers/debugLogParser.js +126 -0
- package/dist/esm/parsers/jsonl.js +66 -0
- package/dist/esm/parsers/mcpToolName.js +28 -0
- package/dist/esm/parsers/openCodeParser.js +625 -0
- package/dist/esm/parsers/planExtractor.js +335 -0
- package/dist/esm/parsers/sessionActivityDetector.js +246 -0
- package/dist/esm/parsers/sessionPathResolver.js +713 -0
- package/dist/esm/parsers/subagentScanner.js +360 -0
- package/dist/esm/parsers/subagentStatsCache.js +45 -0
- package/dist/esm/parsers/subagentTraceParser.js +325 -0
- package/dist/esm/paths.js +134 -0
- package/dist/esm/peakHours.js +194 -0
- package/dist/esm/phrases.js +1330 -0
- package/dist/esm/pricingCatalog.js +247 -0
- package/dist/esm/processDetection.js +200 -0
- package/dist/esm/projectMigration.js +59 -0
- package/dist/esm/promptHistory.js +1221 -0
- package/dist/esm/providerFailure.js +362 -0
- package/dist/esm/providerIds.js +6 -0
- package/dist/esm/providerQuota.js +1 -0
- package/dist/esm/providerServiceStatus.js +145 -0
- package/dist/esm/providerServiceStatusTypes.js +1 -0
- package/dist/esm/providerStatus.js +117 -0
- package/dist/esm/providers/claudeCode.js +575 -0
- package/dist/esm/providers/claudeListing.js +121 -0
- package/dist/esm/providers/codex.js +1034 -0
- package/dist/esm/providers/codexDatabase.js +297 -0
- package/dist/esm/providers/codexRollouts.js +215 -0
- package/dist/esm/providers/detect.js +185 -0
- package/dist/esm/providers/diagnostics.js +83 -0
- package/dist/esm/providers/directoryListingCache.js +206 -0
- package/dist/esm/providers/factory.js +54 -0
- package/dist/esm/providers/openCode.js +2008 -0
- package/dist/esm/providers/openCodeDatabase.js +419 -0
- package/dist/esm/providers/rolloutWalker.js +252 -0
- package/dist/esm/providers/types.js +12 -0
- package/dist/esm/quota.js +182 -0
- package/dist/esm/quotaHistory.js +364 -0
- package/dist/esm/quotaPoller.js +230 -0
- package/dist/esm/quotaPresentation.js +97 -0
- package/dist/esm/quotaResolver.js +231 -0
- package/dist/esm/quotaSnapshots.js +130 -0
- package/dist/esm/quotaThresholds.js +85 -0
- package/dist/esm/readers/decisions.js +24 -0
- package/dist/esm/readers/handoff.js +20 -0
- package/dist/esm/readers/helpers.js +27 -0
- package/dist/esm/readers/history.js +9 -0
- package/dist/esm/readers/notes.js +48 -0
- package/dist/esm/readers/plans.js +225 -0
- package/dist/esm/readers/tasks.js +19 -0
- package/dist/esm/report/htmlHelpers.js +280 -0
- package/dist/esm/report/htmlReportGenerator.js +704 -0
- package/dist/esm/report/index.js +7 -0
- package/dist/esm/report/logo.js +2 -0
- package/dist/esm/report/openBrowser.js +19 -0
- package/dist/esm/report/sessionReportInputs.js +33 -0
- package/dist/esm/report/transcriptParser.js +83 -0
- package/dist/esm/report/types.js +4 -0
- package/dist/esm/schemas/accountManager.js +204 -0
- package/dist/esm/schemas/accountStatus.js +25 -0
- package/dist/esm/schemas/assistantTurn.js +74 -0
- package/dist/esm/schemas/index.js +25 -0
- package/dist/esm/schemas/observedSessionV1.js +77 -0
- package/dist/esm/schemas/providerFailure.js +37 -0
- package/dist/esm/schemas/quota.js +132 -0
- package/dist/esm/schemas/quotaHistory.js +40 -0
- package/dist/esm/schemas/sessionEvent.js +216 -0
- package/dist/esm/schemas/stateFile.js +75 -0
- package/dist/esm/schemas/tokenEstimation.js +7 -0
- package/dist/esm/schemas/transcript.js +86 -0
- package/dist/esm/schemas/usageNormalization.js +38 -0
- package/dist/esm/search/advancedFilter.js +197 -0
- package/dist/esm/search/sessionSearch.js +66 -0
- package/dist/esm/sessionFingerprint.js +40 -0
- package/dist/esm/sessionMonitor.js +198 -0
- package/dist/esm/sessionPreviews.js +522 -0
- package/dist/esm/sessionPromptHistory.js +254 -0
- package/dist/esm/sessionPromptSignals.js +364 -0
- package/dist/esm/sessionStats.js +160 -0
- package/dist/esm/sessionTokenTotals.js +98 -0
- package/dist/esm/sessionTranscripts.js +49 -0
- package/dist/esm/stateFile.js +119 -0
- package/dist/esm/statusline/BurnRateCalculator.js +40 -0
- package/dist/esm/statusline/claudeStatuslinePayload.js +148 -0
- package/dist/esm/statusline/formatter.js +122 -0
- package/dist/esm/statusline/index.js +8 -0
- package/dist/esm/terminalSync.js +95 -0
- package/dist/esm/testing/credentialGuard.js +197 -0
- package/dist/esm/testing/index.js +12 -0
- package/dist/esm/testing/sessionLogFixtures.js +128 -0
- package/dist/esm/tokenEstimation.js +67 -0
- package/dist/esm/tokenSummary.js +113 -0
- package/dist/esm/toolCategory.js +82 -0
- package/dist/esm/transcript.js +257 -0
- package/dist/esm/turns/assistantTurn.js +373 -0
- package/dist/esm/types/codex.js +23 -0
- package/dist/esm/types/decisionLog.js +5 -0
- package/dist/esm/types/historicalData.js +47 -0
- package/dist/esm/types/knowledgeNote.js +15 -0
- package/dist/esm/types/observedSessionV1.js +257 -0
- package/dist/esm/types/opencode.js +12 -0
- package/dist/esm/types/plan.js +7 -0
- package/dist/esm/types/sessionEvent.js +10 -0
- package/dist/esm/types/taskPersistence.js +12 -0
- package/dist/esm/usage/billingBlocks.js +148 -0
- package/dist/esm/usage/claudeUsageDedupe.js +189 -0
- package/dist/esm/usage/importSessionHistory.js +84 -0
- package/dist/esm/usage/subagentUsage.js +18 -0
- package/dist/esm/usage/usageEvents.js +402 -0
- package/dist/esm/usage/usageReports.js +202 -0
- package/dist/esm/usageNormalization.js +95 -0
- package/dist/esm/watchers/eventBridge.js +219 -0
- package/dist/esm/watchers/factory.js +63 -0
- package/dist/esm/watchers/jsonlTail.js +289 -0
- package/dist/esm/watchers/jsonlWatcher.js +435 -0
- package/dist/esm/watchers/providerReaderWatcher.js +118 -0
- package/dist/esm/watchers/sqliteWatcher.js +285 -0
- package/dist/esm/watchers/types.js +4 -0
- package/dist/esm/workspaceRoots.js +56 -0
- package/dist/esm/writers/atomic.js +375 -0
- package/dist/esm/writers/decisions.js +51 -0
- package/dist/esm/writers/notes.js +46 -0
- package/dist/esm/writers/tasks.js +63 -0
- package/dist/esm/zaiQuota.js +323 -0
- package/dist/esm/zaiQuotaApi.js +271 -0
- package/dist/esm/zaiQuotaWatcher.js +265 -0
- package/dist/fileHead.d.ts +22 -0
- package/dist/fileHead.js +33 -0
- package/dist/index.d.ts +30 -11
- package/dist/index.js +72 -15
- package/dist/keepAlive.d.ts +2 -1
- package/dist/keepAlive.js +116 -29
- package/dist/liveCredentialGuard.d.ts +28 -0
- package/dist/liveCredentialGuard.js +36 -0
- package/dist/node.d.ts +13 -1
- package/dist/node.js +43 -2
- package/dist/parsers/codexHistory.js +2 -2
- package/dist/parsers/codexParser.d.ts +12 -0
- package/dist/parsers/codexParser.js +34 -12
- package/dist/parsers/debugLogParser.js +2 -2
- package/dist/parsers/sessionPathResolver.js +5 -4
- package/dist/processDetection.d.ts +10 -3
- package/dist/processDetection.js +44 -11
- package/dist/promptHistory.d.ts +32 -0
- package/dist/promptHistory.js +115 -59
- package/dist/providerFailure.d.ts +12 -6
- package/dist/providerFailure.js +45 -0
- package/dist/providers/claudeCode.js +7 -99
- package/dist/providers/claudeListing.d.ts +22 -0
- package/dist/providers/claudeListing.js +158 -0
- package/dist/providers/codex.d.ts +3 -1
- package/dist/providers/codex.js +26 -227
- package/dist/providers/codexRollouts.d.ts +44 -0
- package/dist/providers/codexRollouts.js +261 -0
- package/dist/providers/detect.js +4 -4
- package/dist/readers/plans.js +3 -3
- package/dist/schemas/accountManager.d.ts +22 -0
- package/dist/schemas/accountManager.js +4 -0
- package/dist/schemas/assistantTurn.d.ts +2 -2
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas/index.js +7 -2
- package/dist/schemas/providerFailure.d.ts +154 -0
- package/dist/schemas/providerFailure.js +40 -0
- package/dist/sessionPromptHistory.d.ts +12 -7
- package/dist/sessionPromptHistory.js +15 -3
- package/dist/sessionPromptSignals.d.ts +9 -0
- package/dist/sessionPromptSignals.js +13 -0
- package/dist/terminalSync.d.ts +12 -2
- package/dist/terminalSync.js +27 -2
- package/dist/testing/credentialGuard.d.ts +23 -0
- package/dist/testing/credentialGuard.js +233 -0
- package/dist/testing/index.d.ts +14 -0
- package/dist/testing/index.js +22 -0
- package/dist/testing/sessionLogFixtures.d.ts +28 -0
- package/dist/testing/sessionLogFixtures.js +169 -0
- package/dist/tokenEstimation.d.ts +2 -0
- package/dist/tokenEstimation.js +21 -11
- package/dist/toolCategory.d.ts +18 -0
- package/dist/toolCategory.js +86 -0
- package/dist/types/codex.d.ts +4 -0
- package/dist/usage/usageEvents.d.ts +16 -0
- package/dist/usage/usageEvents.js +53 -9
- package/dist/watchers/jsonlTail.d.ts +26 -1
- package/dist/watchers/jsonlTail.js +136 -28
- package/dist/watchers/jsonlWatcher.js +7 -0
- package/dist/watchers/providerReaderWatcher.js +1 -0
- package/dist/watchers/types.d.ts +6 -0
- package/dist/workspaceRoots.d.ts +23 -0
- package/dist/workspaceRoots.js +93 -0
- package/package.json +22 -2
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Claude Code and Codex session-log builders shared by the prompt-history
|
|
4
|
+
* tests, published through `sidekick-shared/testing`.
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.ts = ts;
|
|
41
|
+
exports.writeJsonl = writeJsonl;
|
|
42
|
+
exports.appendJsonl = appendJsonl;
|
|
43
|
+
exports.claudeFiller = claudeFiller;
|
|
44
|
+
exports.codexFiller = codexFiller;
|
|
45
|
+
exports.createSessionLogFixtures = createSessionLogFixtures;
|
|
46
|
+
const fs = __importStar(require("fs"));
|
|
47
|
+
const path = __importStar(require("path"));
|
|
48
|
+
const sessionPathResolver_1 = require("../parsers/sessionPathResolver");
|
|
49
|
+
function ts(second) {
|
|
50
|
+
return new Date(Date.UTC(2026, 8, 1, 10, 0, second)).toISOString();
|
|
51
|
+
}
|
|
52
|
+
function writeJsonl(file, rows) {
|
|
53
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
54
|
+
fs.writeFileSync(file, rows.map((row) => JSON.stringify(row)).join('\n') + '\n');
|
|
55
|
+
}
|
|
56
|
+
function appendJsonl(file, rows) {
|
|
57
|
+
fs.appendFileSync(file, rows.map((row) => JSON.stringify(row)).join('\n') + '\n');
|
|
58
|
+
}
|
|
59
|
+
/** A Claude Code line with no message: read and ignored, like progress records. */
|
|
60
|
+
function claudeFiller(bytes, second) {
|
|
61
|
+
return { type: 'system', subtype: 'filler', timestamp: ts(second), content: 'f'.repeat(bytes) };
|
|
62
|
+
}
|
|
63
|
+
/** A Codex line that is neither a prompt nor usage. */
|
|
64
|
+
function codexFiller(bytes, second) {
|
|
65
|
+
return {
|
|
66
|
+
timestamp: ts(second),
|
|
67
|
+
type: 'event_msg',
|
|
68
|
+
payload: { type: 'agent_message', message: 'f'.repeat(bytes) },
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Builders that read the per-test home and repo lazily from `context`. */
|
|
72
|
+
function createSessionLogFixtures(context) {
|
|
73
|
+
let codexCounter = 0;
|
|
74
|
+
function claudeFile(workspace, sessionId) {
|
|
75
|
+
return path.join(context().home, '.claude', 'projects', (0, sessionPathResolver_1.encodeWorkspacePath)(workspace), `${sessionId}.jsonl`);
|
|
76
|
+
}
|
|
77
|
+
function claudeUser(content, second, extra = {}) {
|
|
78
|
+
return {
|
|
79
|
+
type: 'user',
|
|
80
|
+
entrypoint: 'cli',
|
|
81
|
+
cwd: context().repo,
|
|
82
|
+
gitBranch: 'main',
|
|
83
|
+
timestamp: ts(second),
|
|
84
|
+
message: { role: 'user', content },
|
|
85
|
+
...extra,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** One Claude Code assistant record; `message` fields are merged over the defaults. */
|
|
89
|
+
function claudeAssistant(id, second, extra = {}, message = {}) {
|
|
90
|
+
return {
|
|
91
|
+
type: 'assistant',
|
|
92
|
+
entrypoint: 'cli',
|
|
93
|
+
cwd: context().repo,
|
|
94
|
+
timestamp: ts(second),
|
|
95
|
+
message: {
|
|
96
|
+
id,
|
|
97
|
+
role: 'assistant',
|
|
98
|
+
model: 'claude-opus-5',
|
|
99
|
+
content: [{ type: 'text', text: 'ok' }],
|
|
100
|
+
stop_reason: 'end_turn',
|
|
101
|
+
usage: {
|
|
102
|
+
input_tokens: 10,
|
|
103
|
+
output_tokens: 20,
|
|
104
|
+
cache_read_input_tokens: 30,
|
|
105
|
+
cache_creation_input_tokens: 40,
|
|
106
|
+
},
|
|
107
|
+
...message,
|
|
108
|
+
},
|
|
109
|
+
...extra,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function codexFile() {
|
|
113
|
+
codexCounter++;
|
|
114
|
+
const id = `019d86b0-b20c-7b02-a3b2-${String(codexCounter).padStart(12, '0')}`;
|
|
115
|
+
return path.join(context().home, '.codex', 'sessions', '2026', '09', '01', `rollout-2026-09-01T10-00-${String(codexCounter).padStart(2, '0')}-${id}.jsonl`);
|
|
116
|
+
}
|
|
117
|
+
function codexMeta(cwd, source = 'cli', extra = {}) {
|
|
118
|
+
return {
|
|
119
|
+
timestamp: ts(0),
|
|
120
|
+
type: 'session_meta',
|
|
121
|
+
payload: {
|
|
122
|
+
id: 'meta',
|
|
123
|
+
timestamp: ts(0),
|
|
124
|
+
...(cwd !== undefined ? { cwd } : {}),
|
|
125
|
+
originator: 'codex-tui',
|
|
126
|
+
source,
|
|
127
|
+
git: { branch: 'feature/x' },
|
|
128
|
+
...extra,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function codexUser(texts, second) {
|
|
133
|
+
return {
|
|
134
|
+
timestamp: ts(second),
|
|
135
|
+
type: 'response_item',
|
|
136
|
+
payload: {
|
|
137
|
+
type: 'message',
|
|
138
|
+
role: 'user',
|
|
139
|
+
content: texts.map((text) => ({ type: 'input_text', text })),
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function codexTokenCount(second) {
|
|
144
|
+
return {
|
|
145
|
+
timestamp: ts(second),
|
|
146
|
+
type: 'event_msg',
|
|
147
|
+
payload: {
|
|
148
|
+
type: 'token_count',
|
|
149
|
+
info: {
|
|
150
|
+
last_token_usage: {
|
|
151
|
+
input_tokens: 100,
|
|
152
|
+
cached_input_tokens: 60,
|
|
153
|
+
output_tokens: 7,
|
|
154
|
+
cache_write_input_tokens: 5,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
claudeFile,
|
|
162
|
+
claudeUser,
|
|
163
|
+
claudeAssistant,
|
|
164
|
+
codexFile,
|
|
165
|
+
codexMeta,
|
|
166
|
+
codexUser,
|
|
167
|
+
codexTokenCount,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
@@ -13,6 +13,8 @@ export interface TokenEstimate {
|
|
|
13
13
|
confidence: TokenEstimationConfidence;
|
|
14
14
|
provenance: string;
|
|
15
15
|
}
|
|
16
|
+
/** Latin/source-code characters per token in the fallback estimate. */
|
|
17
|
+
export declare const ASCII_CHARS_PER_TOKEN = 3.5;
|
|
16
18
|
/**
|
|
17
19
|
* Estimate tokens without bundling a tokenizer.
|
|
18
20
|
*
|
package/dist/tokenEstimation.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ASCII_CHARS_PER_TOKEN = void 0;
|
|
3
4
|
exports.estimateTextTokens = estimateTextTokens;
|
|
4
5
|
exports.estimateSerializedTokens = estimateSerializedTokens;
|
|
6
|
+
/** Latin/source-code characters per token in the fallback estimate. */
|
|
7
|
+
exports.ASCII_CHARS_PER_TOKEN = 3.5;
|
|
5
8
|
const CJK = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u;
|
|
6
9
|
const EMOJI = /\p{Extended_Pictographic}/u;
|
|
7
10
|
/**
|
|
@@ -30,19 +33,26 @@ function estimateTextTokens(text, options = {}) {
|
|
|
30
33
|
provenance: options.model ?? 'injected-counter',
|
|
31
34
|
};
|
|
32
35
|
}
|
|
33
|
-
|
|
36
|
+
// ASCII is never CJK or pictographic, so the leading ASCII run is counted
|
|
37
|
+
// without the per-code-point regex tests; most source text is all ASCII.
|
|
38
|
+
let firstNonAscii = 0;
|
|
39
|
+
while (firstNonAscii < text.length && text.charCodeAt(firstNonAscii) <= 127)
|
|
40
|
+
firstNonAscii++;
|
|
41
|
+
let asciiChars = firstNonAscii;
|
|
34
42
|
let conservativeTokens = 0;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
if (firstNonAscii < text.length) {
|
|
44
|
+
for (const codePoint of text.slice(firstNonAscii)) {
|
|
45
|
+
if (EMOJI.test(codePoint))
|
|
46
|
+
conservativeTokens += 2;
|
|
47
|
+
else if (CJK.test(codePoint))
|
|
48
|
+
conservativeTokens += 1;
|
|
49
|
+
else if ((codePoint.codePointAt(0) ?? 128) <= 127)
|
|
50
|
+
asciiChars += codePoint.length;
|
|
51
|
+
else
|
|
52
|
+
conservativeTokens += 1;
|
|
53
|
+
}
|
|
44
54
|
}
|
|
45
|
-
const count = Math.ceil(asciiChars /
|
|
55
|
+
const count = Math.ceil(asciiChars / exports.ASCII_CHARS_PER_TOKEN) + conservativeTokens;
|
|
46
56
|
return {
|
|
47
57
|
count: Number.isFinite(count) && count >= 0 ? count : 0,
|
|
48
58
|
method: 'sidekick-fallback-v1',
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One vocabulary for what a tool call does, across Claude Code, Codex, and
|
|
3
|
+
* OpenCode tool names. Browser-safe: no Node imports.
|
|
4
|
+
*
|
|
5
|
+
* @module toolCategory
|
|
6
|
+
*/
|
|
7
|
+
export declare const TOOL_CATEGORIES: readonly ["shell", "file_read", "file_edit", "search", "web", "subagent", "planning", "mcp", "other"];
|
|
8
|
+
export type ToolCategory = (typeof TOOL_CATEGORIES)[number];
|
|
9
|
+
export interface ClassifyToolOptions {
|
|
10
|
+
/** The MCP server the call went to, when the log records it separately (Codex). */
|
|
11
|
+
mcpServer?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Classifies a tool name from any supported provider. `mcp__<server>__<tool>`
|
|
15
|
+
* names and calls with a known `mcpServer` are `mcp`; unknown names are
|
|
16
|
+
* `other`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function classifyTool(name: string, options?: ClassifyToolOptions): ToolCategory;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* One vocabulary for what a tool call does, across Claude Code, Codex, and
|
|
4
|
+
* OpenCode tool names. Browser-safe: no Node imports.
|
|
5
|
+
*
|
|
6
|
+
* @module toolCategory
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TOOL_CATEGORIES = void 0;
|
|
10
|
+
exports.classifyTool = classifyTool;
|
|
11
|
+
const mcpToolName_1 = require("./parsers/mcpToolName");
|
|
12
|
+
exports.TOOL_CATEGORIES = [
|
|
13
|
+
'shell',
|
|
14
|
+
'file_read',
|
|
15
|
+
'file_edit',
|
|
16
|
+
'search',
|
|
17
|
+
'web',
|
|
18
|
+
'subagent',
|
|
19
|
+
'planning',
|
|
20
|
+
'mcp',
|
|
21
|
+
'other',
|
|
22
|
+
];
|
|
23
|
+
/** Lower-cased tool names of every provider, by category. */
|
|
24
|
+
const CATEGORY_BY_NAME = new Map([
|
|
25
|
+
[
|
|
26
|
+
'shell',
|
|
27
|
+
[
|
|
28
|
+
'bash',
|
|
29
|
+
'bashoutput',
|
|
30
|
+
'killbash',
|
|
31
|
+
'killshell',
|
|
32
|
+
'exec_command',
|
|
33
|
+
'shell',
|
|
34
|
+
'local_shell',
|
|
35
|
+
'local_shell_call',
|
|
36
|
+
'container.exec',
|
|
37
|
+
'write_stdin',
|
|
38
|
+
],
|
|
39
|
+
],
|
|
40
|
+
['file_read', ['read', 'notebookread', 'ls', 'list', 'view_image']],
|
|
41
|
+
[
|
|
42
|
+
'file_edit',
|
|
43
|
+
['edit', 'multiedit', 'write', 'notebookedit', 'apply_patch', 'patch', 'patch_applied'],
|
|
44
|
+
],
|
|
45
|
+
['search', ['grep', 'glob', 'codesearch', 'toolsearch']],
|
|
46
|
+
['web', ['webfetch', 'websearch', 'web_search', 'web_search_call', 'fetch']],
|
|
47
|
+
[
|
|
48
|
+
'subagent',
|
|
49
|
+
[
|
|
50
|
+
'task',
|
|
51
|
+
'agent',
|
|
52
|
+
'spawn_agent',
|
|
53
|
+
'wait_agent',
|
|
54
|
+
'send_message',
|
|
55
|
+
'followup_task',
|
|
56
|
+
'list_agents',
|
|
57
|
+
'wait',
|
|
58
|
+
],
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
'planning',
|
|
62
|
+
[
|
|
63
|
+
'todowrite',
|
|
64
|
+
'todoread',
|
|
65
|
+
'update_plan',
|
|
66
|
+
'updateplan',
|
|
67
|
+
'enterplanmode',
|
|
68
|
+
'exitplanmode',
|
|
69
|
+
'taskcreate',
|
|
70
|
+
'taskupdate',
|
|
71
|
+
'tasklist',
|
|
72
|
+
'askuserquestion',
|
|
73
|
+
'request_user_input',
|
|
74
|
+
],
|
|
75
|
+
],
|
|
76
|
+
].flatMap(([category, names]) => names.map((name) => [name, category])));
|
|
77
|
+
/**
|
|
78
|
+
* Classifies a tool name from any supported provider. `mcp__<server>__<tool>`
|
|
79
|
+
* names and calls with a known `mcpServer` are `mcp`; unknown names are
|
|
80
|
+
* `other`.
|
|
81
|
+
*/
|
|
82
|
+
function classifyTool(name, options = {}) {
|
|
83
|
+
if (options.mcpServer || (0, mcpToolName_1.parseMcpToolName)(name))
|
|
84
|
+
return 'mcp';
|
|
85
|
+
return CATEGORY_BY_NAME.get(name.trim().toLowerCase()) ?? 'other';
|
|
86
|
+
}
|
package/dist/types/codex.d.ts
CHANGED
|
@@ -291,4 +291,8 @@ export interface CodexDbThread {
|
|
|
291
291
|
source?: string;
|
|
292
292
|
agent_nickname?: string | null;
|
|
293
293
|
agent_role?: string | null;
|
|
294
|
+
/** 1 once the thread is archived; Codex then moves its rollout to `archived_sessions/`. */
|
|
295
|
+
archived?: number;
|
|
296
|
+
/** Unix seconds when the thread was archived. */
|
|
297
|
+
archived_at?: number | null;
|
|
294
298
|
}
|
|
@@ -50,6 +50,8 @@ export interface UsageEventRecord {
|
|
|
50
50
|
};
|
|
51
51
|
costUsd: number | null;
|
|
52
52
|
costProvenance: PricingProvenance;
|
|
53
|
+
/** Session file the event came from; tells apart two files with one session id. */
|
|
54
|
+
filePath?: string;
|
|
53
55
|
}
|
|
54
56
|
/** One session that contributed events. */
|
|
55
57
|
export interface UsageSessionRecord {
|
|
@@ -71,6 +73,18 @@ export interface CollectUsageEventsOptions {
|
|
|
71
73
|
until?: Date | string;
|
|
72
74
|
/** Restrict to one workspace's sessions. */
|
|
73
75
|
workspacePath?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Restrict to the sessions of several workspaces, listed once each and
|
|
78
|
+
* counted once even when roots overlap. Takes precedence over
|
|
79
|
+
* `workspacePath`. Roots that do not resolve are dropped; when none
|
|
80
|
+
* resolves, no session is read.
|
|
81
|
+
*/
|
|
82
|
+
workspacePaths?: string[];
|
|
83
|
+
/**
|
|
84
|
+
* Also list each root's main checkout and git worktree siblings. Default
|
|
85
|
+
* true with `workspacePaths`, false with `workspacePath`.
|
|
86
|
+
*/
|
|
87
|
+
includeWorktrees?: boolean;
|
|
74
88
|
/** Preview-read concurrency (see `listSessionPreviewsAsync`). */
|
|
75
89
|
concurrency?: number;
|
|
76
90
|
/** Cache directory (default `<configDir>/usage-cache`). */
|
|
@@ -93,6 +107,8 @@ export interface CollectUsageEventsResult {
|
|
|
93
107
|
diagnostics: SessionProviderDiagnostic[];
|
|
94
108
|
cacheHits: number;
|
|
95
109
|
cacheMisses: number;
|
|
110
|
+
/** Realpaths of the roots listed, after worktree expansion, when the call was scoped. */
|
|
111
|
+
roots?: string[];
|
|
96
112
|
}
|
|
97
113
|
export declare function getUsageCacheDir(): string;
|
|
98
114
|
/** Deletes all but the `keep` most recently used cache files (by mtime). Best-effort. */
|
|
@@ -64,6 +64,7 @@ const paths_1 = require("../paths");
|
|
|
64
64
|
const sessionPreviews_1 = require("../sessionPreviews");
|
|
65
65
|
const usageNormalization_1 = require("../usageNormalization");
|
|
66
66
|
const atomic_1 = require("../writers/atomic");
|
|
67
|
+
const workspaceRoots_1 = require("../workspaceRoots");
|
|
67
68
|
/**
|
|
68
69
|
* Bump when the cached record shape or the counting rules change; older files
|
|
69
70
|
* are re-read. v2: Claude split lines and duplicate Codex `token_count` events
|
|
@@ -162,7 +163,7 @@ function cachedEventFromUsage(usage, timestamp, model) {
|
|
|
162
163
|
return record;
|
|
163
164
|
}
|
|
164
165
|
/** Price a cached event with the current catalog (or its provider-reported cost). */
|
|
165
|
-
function priceCachedEvent(cached, provider, sessionId, project) {
|
|
166
|
+
function priceCachedEvent(cached, provider, sessionId, project, sessionFile) {
|
|
166
167
|
const usage = {
|
|
167
168
|
uncachedInputTokens: cached.i,
|
|
168
169
|
cacheReadTokens: cached.cr,
|
|
@@ -195,6 +196,7 @@ function priceCachedEvent(cached, provider, sessionId, project) {
|
|
|
195
196
|
},
|
|
196
197
|
costUsd: priced.costUsd,
|
|
197
198
|
costProvenance: priced.source,
|
|
199
|
+
filePath: sessionFile,
|
|
198
200
|
};
|
|
199
201
|
}
|
|
200
202
|
const CLAUDE_AGENT_FILE = /^agent-.+\.jsonl$/;
|
|
@@ -292,12 +294,8 @@ async function collectUsageEvents(options) {
|
|
|
292
294
|
const useCache = !options.noCache;
|
|
293
295
|
const signal = options.signal;
|
|
294
296
|
signal?.throwIfAborted();
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
workspacePath: options.workspacePath,
|
|
298
|
-
limit: Number.MAX_SAFE_INTEGER,
|
|
299
|
-
concurrency: options.concurrency,
|
|
300
|
-
});
|
|
297
|
+
const scope = usageScope(options);
|
|
298
|
+
const listed = await listScopedPreviews(options, scope?.listingRoots);
|
|
301
299
|
signal?.throwIfAborted();
|
|
302
300
|
const diagnostics = [...listed.diagnostics];
|
|
303
301
|
for (const diagnostic of listed.diagnostics)
|
|
@@ -373,7 +371,7 @@ async function collectUsageEvents(options) {
|
|
|
373
371
|
continue;
|
|
374
372
|
if (untilMs !== null && cached.t > untilMs)
|
|
375
373
|
continue;
|
|
376
|
-
events.push(priceCachedEvent(cached, preview.provider, preview.sessionId, project));
|
|
374
|
+
events.push(priceCachedEvent(cached, preview.provider, preview.sessionId, project, preview.filePath));
|
|
377
375
|
first = first === null ? cached.t : Math.min(first, cached.t);
|
|
378
376
|
last = last === null ? cached.t : Math.max(last, cached.t);
|
|
379
377
|
count += 1;
|
|
@@ -393,5 +391,51 @@ async function collectUsageEvents(options) {
|
|
|
393
391
|
if (wroteCache)
|
|
394
392
|
pruneUsageCache(exports.MAX_USAGE_CACHE_FILES, cacheDir);
|
|
395
393
|
events.sort((a, b) => a.timestamp - b.timestamp);
|
|
396
|
-
return {
|
|
394
|
+
return {
|
|
395
|
+
events,
|
|
396
|
+
sessions,
|
|
397
|
+
diagnostics,
|
|
398
|
+
cacheHits,
|
|
399
|
+
cacheMisses,
|
|
400
|
+
...(scope ? { roots: scope.roots } : {}),
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
/** The roots to list, or undefined for an unscoped (or legacy single-root) call. */
|
|
404
|
+
function usageScope(options) {
|
|
405
|
+
if (options.workspacePaths) {
|
|
406
|
+
return (0, workspaceRoots_1.resolveWorkspaceRoots)(options.workspacePaths, {
|
|
407
|
+
includeWorktrees: options.includeWorktrees !== false,
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
if (options.workspacePath && options.includeWorktrees === true) {
|
|
411
|
+
return (0, workspaceRoots_1.resolveWorkspaceRoots)([options.workspacePath], { includeWorktrees: true });
|
|
412
|
+
}
|
|
413
|
+
return undefined;
|
|
414
|
+
}
|
|
415
|
+
/** Lists previews once per root and keeps each session file once. */
|
|
416
|
+
async function listScopedPreviews(options, listingRoots) {
|
|
417
|
+
const list = (workspacePath) => (0, sessionPreviews_1.listSessionPreviewsAsync)(options.providers, {
|
|
418
|
+
since: options.since,
|
|
419
|
+
workspacePath,
|
|
420
|
+
limit: Number.MAX_SAFE_INTEGER,
|
|
421
|
+
concurrency: options.concurrency,
|
|
422
|
+
});
|
|
423
|
+
if (!listingRoots)
|
|
424
|
+
return list(options.workspacePath);
|
|
425
|
+
const byFile = new Map();
|
|
426
|
+
const diagnostics = new Map();
|
|
427
|
+
for (const root of listingRoots) {
|
|
428
|
+
options.signal?.throwIfAborted();
|
|
429
|
+
const listed = await list(root);
|
|
430
|
+
// Each root lists every provider again; report each problem once.
|
|
431
|
+
for (const diagnostic of listed.diagnostics) {
|
|
432
|
+
diagnostics.set(JSON.stringify(diagnostic), diagnostic);
|
|
433
|
+
}
|
|
434
|
+
for (const preview of listed.previews) {
|
|
435
|
+
if (!byFile.has(preview.filePath))
|
|
436
|
+
byFile.set(preview.filePath, preview);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
const previews = [...byFile.values()].sort((left, right) => Date.parse(right.modifiedAt) - Date.parse(left.modifiedAt));
|
|
440
|
+
return { previews, diagnostics: [...diagnostics.values()] };
|
|
397
441
|
}
|
|
@@ -3,11 +3,30 @@
|
|
|
3
3
|
* their own aggregation lifecycle.
|
|
4
4
|
*/
|
|
5
5
|
import type { ZodType } from 'zod';
|
|
6
|
+
/** Default bytes read from the file per chunk. */
|
|
7
|
+
export declare const DEFAULT_JSONL_TAIL_READ_BYTES: number;
|
|
8
|
+
/** Default longest line parsed; longer lines are skipped and reported. */
|
|
9
|
+
export declare const DEFAULT_JSONL_TAIL_MAX_LINE_BYTES: number;
|
|
6
10
|
export interface JsonlTailBatch {
|
|
7
11
|
bytesRead: number;
|
|
8
12
|
eventsRead: number;
|
|
9
13
|
offset: number;
|
|
10
14
|
}
|
|
15
|
+
/** Where an event's line sits in the file. */
|
|
16
|
+
export interface JsonlTailLine {
|
|
17
|
+
/** Byte offset where the line starts. */
|
|
18
|
+
offset: number;
|
|
19
|
+
/** Line length in bytes, without the newline. */
|
|
20
|
+
length: number;
|
|
21
|
+
}
|
|
22
|
+
export type JsonlTailResetReason = 'truncated' | 'rewritten' | 'replaced';
|
|
23
|
+
/** The tail started over from the beginning of the file. */
|
|
24
|
+
export interface JsonlTailReset {
|
|
25
|
+
/** `truncated`: the file shrank; `rewritten`: its first bytes or the resume point changed; `replaced`: another file now has the path. */
|
|
26
|
+
reason: JsonlTailResetReason;
|
|
27
|
+
/** The committed offset before the reset. */
|
|
28
|
+
previousOffset: number;
|
|
29
|
+
}
|
|
11
30
|
export interface JsonlTailOptions<T> {
|
|
12
31
|
path: string;
|
|
13
32
|
schema?: ZodType<T>;
|
|
@@ -15,9 +34,15 @@ export interface JsonlTailOptions<T> {
|
|
|
15
34
|
startAtEnd?: boolean;
|
|
16
35
|
debounceMs?: number;
|
|
17
36
|
catchupIntervalMs?: number;
|
|
18
|
-
onEvent: (event: T) => void;
|
|
37
|
+
onEvent: (event: T, line: JsonlTailLine) => void;
|
|
19
38
|
onBatchComplete?: (batch: JsonlTailBatch) => void;
|
|
20
39
|
onError?: (error: Error, line?: string) => void;
|
|
40
|
+
/** Called after the tail resets to offset 0; events from the start follow. */
|
|
41
|
+
onReset?: (reset: JsonlTailReset) => void;
|
|
42
|
+
/** Bytes read per chunk (default 1 MiB); one poll reads chunk by chunk to the end. */
|
|
43
|
+
maxReadBytes?: number;
|
|
44
|
+
/** Longest line parsed (default 16 MiB); a longer line is skipped and reported to `onError`. */
|
|
45
|
+
maxLineBytes?: number;
|
|
21
46
|
}
|
|
22
47
|
export interface JsonlTail {
|
|
23
48
|
readonly isActive: boolean;
|