sidekick-shared 0.27.6 → 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 +28 -0
- package/README.md +58 -18
- package/dist/browser.d.ts +13 -2
- package/dist/browser.js +30 -2
- package/dist/claudePaths.d.ts +11 -0
- package/dist/claudePaths.js +61 -0
- package/dist/claudeProfiles.d.ts +2 -9
- package/dist/claudeProfiles.js +10 -25
- package/dist/codexPaths.d.ts +22 -0
- package/dist/codexPaths.js +67 -0
- package/dist/codexProfiles.d.ts +1 -4
- package/dist/codexProfiles.js +5 -43
- package/dist/doctor.js +2 -2
- 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 +16 -7
- package/dist/index.js +49 -15
- 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/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/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/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,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Codex rollout-file helpers shared by the provider and by callers that only
|
|
4
|
+
* list rollouts: bounded first-line reads, session_meta and cwd lookups, and
|
|
5
|
+
* the async session-file listing. Kept apart from the provider class so a
|
|
6
|
+
* listing does not bundle the provider's stats, context and reader code.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.getSessionsDirs = getSessionsDirs;
|
|
43
|
+
exports.readFirstLines = readFirstLines;
|
|
44
|
+
exports.readSessionMeta = readSessionMeta;
|
|
45
|
+
exports.readFirstLineAsync = readFirstLineAsync;
|
|
46
|
+
exports.parseSessionMetaLine = parseSessionMetaLine;
|
|
47
|
+
exports.readSessionCwd = readSessionCwd;
|
|
48
|
+
exports.readSessionCwdAsync = readSessionCwdAsync;
|
|
49
|
+
exports.initializeCounters = initializeCounters;
|
|
50
|
+
exports.cwdMatches = cwdMatches;
|
|
51
|
+
exports.normalizePath = normalizePath;
|
|
52
|
+
exports.listCodexSessionFilesAsync = listCodexSessionFilesAsync;
|
|
53
|
+
const fs = __importStar(require("fs"));
|
|
54
|
+
const path = __importStar(require("path"));
|
|
55
|
+
const codexPaths_1 = require("../codexPaths");
|
|
56
|
+
const directoryListingCache_1 = require("./directoryListingCache");
|
|
57
|
+
const rolloutWalker_1 = require("./rolloutWalker");
|
|
58
|
+
/** Every directory across the monitored homes that may hold rollouts, archived ones included. */
|
|
59
|
+
function getSessionsDirs() {
|
|
60
|
+
return (0, codexPaths_1.getCodexSessionsDirs)();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Read the first N complete lines from a file using chunked reads.
|
|
64
|
+
* Handles arbitrarily long lines (Codex session_meta can be 10KB+).
|
|
65
|
+
*/
|
|
66
|
+
function readFirstLines(filePath, maxLines, maxBytes = 256 * 1024) {
|
|
67
|
+
const lines = [];
|
|
68
|
+
let fd;
|
|
69
|
+
try {
|
|
70
|
+
fd = fs.openSync(filePath, 'r');
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
let pending = '';
|
|
76
|
+
let totalRead = 0;
|
|
77
|
+
const chunkSize = 16384;
|
|
78
|
+
try {
|
|
79
|
+
while (totalRead < maxBytes && lines.length < maxLines) {
|
|
80
|
+
const buf = Buffer.alloc(Math.min(chunkSize, maxBytes - totalRead));
|
|
81
|
+
const bytesRead = fs.readSync(fd, buf, 0, buf.length, totalRead);
|
|
82
|
+
if (bytesRead === 0)
|
|
83
|
+
break;
|
|
84
|
+
totalRead += bytesRead;
|
|
85
|
+
pending += buf.toString('utf-8', 0, bytesRead);
|
|
86
|
+
let nlIdx;
|
|
87
|
+
while ((nlIdx = pending.indexOf('\n')) !== -1 && lines.length < maxLines) {
|
|
88
|
+
lines.push(pending.substring(0, nlIdx));
|
|
89
|
+
pending = pending.substring(nlIdx + 1);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (pending.trim() && lines.length < maxLines) {
|
|
93
|
+
lines.push(pending);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
fs.closeSync(fd);
|
|
98
|
+
}
|
|
99
|
+
return lines;
|
|
100
|
+
}
|
|
101
|
+
/** Read session_meta from the beginning of a rollout file. */
|
|
102
|
+
function readSessionMeta(rolloutPath) {
|
|
103
|
+
try {
|
|
104
|
+
const lines = readFirstLines(rolloutPath, 1);
|
|
105
|
+
const firstLine = lines[0]?.trim();
|
|
106
|
+
if (!firstLine)
|
|
107
|
+
return null;
|
|
108
|
+
const parsed = JSON.parse(firstLine);
|
|
109
|
+
if (parsed.type === 'session_meta') {
|
|
110
|
+
return parsed.payload;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// Skip
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* First line of a rollout, chunk-read under the same 256 KiB cap as
|
|
120
|
+
* readFirstLines(). `complete` is false while the line has no newline yet
|
|
121
|
+
* (a rollout that was just created) or the file could not be read, so
|
|
122
|
+
* callers know not to cache the answer.
|
|
123
|
+
*/
|
|
124
|
+
async function readFirstLineAsync(rolloutPath) {
|
|
125
|
+
// Mirrors readSessionMeta()/readFirstLines(): chunk-read until the first
|
|
126
|
+
// line is complete under the same 256 KiB cap — session_meta carries
|
|
127
|
+
// `instructions` and can far exceed a single chunk.
|
|
128
|
+
const maxBytes = 256 * 1024;
|
|
129
|
+
const chunkSize = 64 * 1024;
|
|
130
|
+
let handle = null;
|
|
131
|
+
try {
|
|
132
|
+
handle = await fs.promises.open(rolloutPath, 'r');
|
|
133
|
+
const chunks = [];
|
|
134
|
+
let totalRead = 0;
|
|
135
|
+
let newlineFound = false;
|
|
136
|
+
while (totalRead < maxBytes && !newlineFound) {
|
|
137
|
+
const buffer = Buffer.alloc(Math.min(chunkSize, maxBytes - totalRead));
|
|
138
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, totalRead);
|
|
139
|
+
if (bytesRead === 0)
|
|
140
|
+
break;
|
|
141
|
+
const chunk = buffer.subarray(0, bytesRead);
|
|
142
|
+
chunks.push(chunk);
|
|
143
|
+
totalRead += bytesRead;
|
|
144
|
+
newlineFound = chunk.includes(0x0a);
|
|
145
|
+
}
|
|
146
|
+
const firstLine = Buffer.concat(chunks).toString('utf8').split('\n', 1)[0]?.trim();
|
|
147
|
+
return { line: firstLine || null, complete: newlineFound || totalRead >= maxBytes };
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return { line: null, complete: false };
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
await handle?.close().catch(() => undefined);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function parseSessionMetaLine(line) {
|
|
157
|
+
if (!line)
|
|
158
|
+
return null;
|
|
159
|
+
try {
|
|
160
|
+
const parsed = JSON.parse(line);
|
|
161
|
+
return parsed.type === 'session_meta' ? parsed.payload : null;
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Read the CWD from a rollout file's session_meta. Cached per path, bounded
|
|
169
|
+
* so a long-lived host watching a large history cannot grow it without limit
|
|
170
|
+
* (insertion order doubles as an eviction order).
|
|
171
|
+
*/
|
|
172
|
+
const CWD_CACHE_LIMIT = 5000;
|
|
173
|
+
const cwdCache = new Map();
|
|
174
|
+
function rememberCwd(rolloutPath, cwd) {
|
|
175
|
+
if (!cwdCache.has(rolloutPath) && cwdCache.size >= CWD_CACHE_LIMIT) {
|
|
176
|
+
const oldest = cwdCache.keys().next().value;
|
|
177
|
+
if (oldest !== undefined)
|
|
178
|
+
cwdCache.delete(oldest);
|
|
179
|
+
}
|
|
180
|
+
cwdCache.set(rolloutPath, cwd);
|
|
181
|
+
}
|
|
182
|
+
function readSessionCwd(rolloutPath) {
|
|
183
|
+
const cached = cwdCache.get(rolloutPath);
|
|
184
|
+
if (cached !== undefined)
|
|
185
|
+
return cached;
|
|
186
|
+
const meta = readSessionMeta(rolloutPath);
|
|
187
|
+
const cwd = meta?.cwd || null;
|
|
188
|
+
rememberCwd(rolloutPath, cwd);
|
|
189
|
+
return cwd;
|
|
190
|
+
}
|
|
191
|
+
/** Async twin of readSessionCwd, sharing its cache so repeat listings do no content reads. */
|
|
192
|
+
async function readSessionCwdAsync(rolloutPath) {
|
|
193
|
+
const cached = cwdCache.get(rolloutPath);
|
|
194
|
+
if (cached !== undefined)
|
|
195
|
+
return cached;
|
|
196
|
+
const { line, complete } = await readFirstLineAsync(rolloutPath);
|
|
197
|
+
const cwd = parseSessionMetaLine(line)?.cwd || null;
|
|
198
|
+
// A rollout observed before its session_meta line is flushed has no cwd
|
|
199
|
+
// yet; caching that null would hide the session from its workspace until
|
|
200
|
+
// the entry aged out, so only conclusive answers are remembered.
|
|
201
|
+
if (cwd !== null || complete)
|
|
202
|
+
rememberCwd(rolloutPath, cwd);
|
|
203
|
+
return cwd;
|
|
204
|
+
}
|
|
205
|
+
/** Built-in enumerators report explicit zeros rather than leaving a counter unset. */
|
|
206
|
+
function initializeCounters(stats) {
|
|
207
|
+
if (!stats)
|
|
208
|
+
return;
|
|
209
|
+
stats.directoriesListed ??= 0;
|
|
210
|
+
stats.directoriesStatted ??= 0;
|
|
211
|
+
stats.filesStatted ??= 0;
|
|
212
|
+
}
|
|
213
|
+
/** Check if a session's CWD matches a workspace path. */
|
|
214
|
+
function cwdMatches(sessionCwd, workspacePath) {
|
|
215
|
+
const normalizedSession = normalizePath(sessionCwd);
|
|
216
|
+
const normalizedWorkspace = normalizePath(workspacePath);
|
|
217
|
+
return (normalizedSession === normalizedWorkspace ||
|
|
218
|
+
normalizedWorkspace.startsWith(normalizedSession + path.sep) ||
|
|
219
|
+
normalizedSession.startsWith(normalizedWorkspace + path.sep));
|
|
220
|
+
}
|
|
221
|
+
/** Normalize a path using realpathSync. */
|
|
222
|
+
function normalizePath(input) {
|
|
223
|
+
try {
|
|
224
|
+
return fs.realpathSync(input);
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
return path.resolve(input);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* List rollout files across the monitored Codex homes, newest first. With
|
|
232
|
+
* `workspacePath`, keeps rollouts whose session_meta cwd equals, contains, or
|
|
233
|
+
* sits inside it.
|
|
234
|
+
*/
|
|
235
|
+
async function listCodexSessionFilesAsync(workspacePath, options = {}, cache = new directoryListingCache_1.DirectoryListingCache()) {
|
|
236
|
+
const results = [];
|
|
237
|
+
initializeCounters(options.stats);
|
|
238
|
+
// One capped walk across the homes (deduplicated, newest first) through
|
|
239
|
+
// the directory cache. With a workspace filter the limit applies after
|
|
240
|
+
// filtering, so the walk itself is bounded only by its file cap.
|
|
241
|
+
const files = await (0, rolloutWalker_1.walkRolloutFilesAsync)(getSessionsDirs(), {
|
|
242
|
+
limit: workspacePath ? undefined : options.limit,
|
|
243
|
+
since: options.since,
|
|
244
|
+
cache,
|
|
245
|
+
revalidateRecent: options.revalidateRecent,
|
|
246
|
+
stats: options.stats,
|
|
247
|
+
});
|
|
248
|
+
for (const file of files) {
|
|
249
|
+
if (options.limit !== undefined && results.length >= options.limit)
|
|
250
|
+
break;
|
|
251
|
+
const info = { ...file };
|
|
252
|
+
if (workspacePath) {
|
|
253
|
+
const cwd = await readSessionCwdAsync(file.path);
|
|
254
|
+
if (!cwd || !cwdMatches(cwd, workspacePath))
|
|
255
|
+
continue;
|
|
256
|
+
info.workspacePath = cwd;
|
|
257
|
+
}
|
|
258
|
+
results.push(info);
|
|
259
|
+
}
|
|
260
|
+
return results;
|
|
261
|
+
}
|
package/dist/providers/detect.js
CHANGED
|
@@ -42,12 +42,12 @@ exports._resetProviderDetectionCache = _resetProviderDetectionCache;
|
|
|
42
42
|
exports.getAllDetectedProviders = getAllDetectedProviders;
|
|
43
43
|
exports.detectProvider = detectProvider;
|
|
44
44
|
const fs = __importStar(require("fs"));
|
|
45
|
-
const os = __importStar(require("os"));
|
|
46
45
|
const path = __importStar(require("path"));
|
|
47
|
-
const
|
|
46
|
+
const codexPaths_1 = require("../codexPaths");
|
|
48
47
|
const openCode_1 = require("./openCode");
|
|
48
|
+
const claudePaths_1 = require("../claudePaths");
|
|
49
49
|
function getCodexHomes() {
|
|
50
|
-
return (0,
|
|
50
|
+
return (0, codexPaths_1.getCodexMonitoringHomes)();
|
|
51
51
|
}
|
|
52
52
|
function hasCodexStateDb(codexHome) {
|
|
53
53
|
try {
|
|
@@ -160,7 +160,7 @@ function getCodexActivityMtime() {
|
|
|
160
160
|
return latest;
|
|
161
161
|
}
|
|
162
162
|
function getProviderPaths() {
|
|
163
|
-
const claudeBase =
|
|
163
|
+
const claudeBase = (0, claudePaths_1.getClaudeProjectsDir)();
|
|
164
164
|
const openCodeDataDir = (0, openCode_1.getOpenCodeDataDir)();
|
|
165
165
|
const codexHomes = getCodexHomes();
|
|
166
166
|
return {
|
package/dist/readers/plans.js
CHANGED
|
@@ -43,12 +43,12 @@ exports.writePlans = writePlans;
|
|
|
43
43
|
exports.readClaudeCodePlanFiles = readClaudeCodePlanFiles;
|
|
44
44
|
const fs = __importStar(require("fs"));
|
|
45
45
|
const path = __importStar(require("path"));
|
|
46
|
-
const os = __importStar(require("os"));
|
|
47
46
|
const plan_1 = require("../types/plan");
|
|
48
47
|
const paths_1 = require("../paths");
|
|
49
48
|
const helpers_1 = require("./helpers");
|
|
50
49
|
const planExtractor_1 = require("../parsers/planExtractor");
|
|
51
50
|
const atomic_1 = require("../writers/atomic");
|
|
51
|
+
const claudePaths_1 = require("../claudePaths");
|
|
52
52
|
async function readPlans(slug, opts) {
|
|
53
53
|
const filePath = (0, paths_1.getProjectDataPath)(slug, 'plans');
|
|
54
54
|
const store = await (0, helpers_1.readJsonStore)(filePath);
|
|
@@ -178,8 +178,8 @@ async function writePlans(slug, plans) {
|
|
|
178
178
|
* sessions in the given workspace. Maps session JSONL slugs to plan filenames.
|
|
179
179
|
*/
|
|
180
180
|
async function readClaudeCodePlanFiles(workspacePath) {
|
|
181
|
-
const claudePlansDir = path.join(
|
|
182
|
-
const claudeProjectsDir =
|
|
181
|
+
const claudePlansDir = path.join((0, claudePaths_1.getLiveClaudeHome)(), 'plans');
|
|
182
|
+
const claudeProjectsDir = (0, claudePaths_1.getClaudeProjectsDir)();
|
|
183
183
|
// Find the project directory in ~/.claude/projects/
|
|
184
184
|
const cwd = workspacePath || process.cwd();
|
|
185
185
|
const encoded = (0, paths_1.encodeWorkspacePath)(path.resolve(cwd));
|
package/dist/schemas/index.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export { normalizedUsageSchema, normalizedUsageCostSchema } from './usageNormali
|
|
|
17
17
|
export type { NormalizedUsage, NormalizedUsageCost } from '../usageNormalization';
|
|
18
18
|
export { tokenEstimateSchema } from './tokenEstimation';
|
|
19
19
|
export type { TokenEstimate } from '../tokenEstimation';
|
|
20
|
+
export { providerAuthenticationEvidenceSchema, providerFailureEvidenceSchema, providerRetryAfterSchema, providerFailureDiagnosisSchema, } from './providerFailure';
|
|
21
|
+
export type { ProviderAuthenticationEvidence, ProviderFailureDiagnosis, ProviderFailureEvidence, ProviderRetryAfter, } from '../providerFailure';
|
|
20
22
|
export { transcriptSourceProvenanceSchema, canonicalTranscriptBlockSchema, canonicalToolCallSchema, canonicalTranscriptMessageSchema, canonicalSessionTranscriptSchema, } from './transcript';
|
|
21
23
|
export type { CanonicalSessionTranscript, CanonicalTranscriptMessage, CanonicalToolCall, TranscriptSourceProvenance, } from '../transcript';
|
|
22
24
|
export { observationProvenanceV1Schema, observedAgentSessionV1Schema, observedValueV1Schema, pendingUserRequestV1Schema, providerCapabilitiesV1Schema, providerSessionAdapterV1Schema, sessionEvidenceRefV1Schema, } from './observedSessionV1';
|
package/dist/schemas/index.js
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* subpath is self-sufficient for boundary-validation modules.
|
|
13
13
|
*/
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
exports.stateFileWriterSchema = exports.stateFileSessionSchema = exports.stateFileQuotaWindowSchema = exports.stateFileQuotaSchema = exports.stateFileContextSchema = exports.stateFileBillingBlockSchema = exports.stateFileAccountSchema = exports.sidekickStateFileSchema = exports.assistantTurnToolRefSchema = exports.assistantTurnToolGroupStepSchema = exports.assistantTurnTimelineItemSchema = exports.assistantTurnSubagentStatusSchema = exports.assistantTurnSubagentSchema = exports.assistantTurnReasoningTimelineItemSchema = exports.assistantTurnProjectionSchema = exports.assistantTurnProcessStepSchema = exports.assistantTurnProcessSchema = exports.assistantTurnNarrationStepSchema = exports.assistantTurnEventTypeSchema = exports.assistantTurnEventSchema = exports.accountLaunchEnvSchema = exports.syncReportSchema = exports.providerSyncReportSchema = exports.lastSwitchRecordSchema = exports.switchAccountResultSchema = exports.runningAccountConsumerSchema = exports.accountConsumerKindSchema = exports.runningProcessSchema = exports.accountViewSchema = exports.accountHealthSchema = exports.accountHealthSidecarSchema = exports.accountHealthSourceSchema = exports.accountHealthStateSchema = exports.listAllAccountsResultSchema = exports.savedAccountProfileSchema = exports.accountEntrySchema = exports.accountLoginStatusSchema = exports.beginAccountLoginResultSchema = exports.accountManagerResultSchema = exports.accountProviderIdSchema = void 0;
|
|
15
|
+
exports.quotaHistoryRuntimeProviderSchema = exports.providerQuotaMapSchema = exports.zaiProviderQuotaStateSchema = exports.codexProviderQuotaStateSchema = exports.claudeProviderQuotaStateSchema = exports.providerQuotaStateSchema = exports.runtimeQuotaProviderSchema = exports.quotaFailureDescriptorSchema = exports.peakHoursStateSchema = exports.codexResetCreditsSnapshotSchema = exports.codexResetCreditSchema = exports.quotaSourceSchema = exports.quotaProviderIdSchema = exports.quotaFailureKindSchema = exports.quotaStateSchema = exports.quotaWindowSchema = exports.sessionEvidenceRefV1Schema = exports.providerSessionAdapterV1Schema = exports.providerCapabilitiesV1Schema = exports.pendingUserRequestV1Schema = exports.observedValueV1Schema = exports.observedAgentSessionV1Schema = exports.observationProvenanceV1Schema = exports.canonicalSessionTranscriptSchema = exports.canonicalTranscriptMessageSchema = exports.canonicalToolCallSchema = exports.canonicalTranscriptBlockSchema = exports.transcriptSourceProvenanceSchema = exports.providerFailureDiagnosisSchema = exports.providerRetryAfterSchema = exports.providerFailureEvidenceSchema = exports.providerAuthenticationEvidenceSchema = exports.tokenEstimateSchema = exports.normalizedUsageCostSchema = exports.normalizedUsageSchema = exports.toolResultSessionEventSchema = exports.toolUseSessionEventSchema = exports.systemSessionEventSchema = exports.summarySessionEventSchema = exports.assistantSessionEventSchema = exports.userSessionEventSchema = exports.extractSessionEvents = exports.permissionModeSchema = exports.sessionEventSchema = exports.sessionMessageSchema = exports.messageUsageSchema = exports.SESSION_PROVIDER_IDS = exports.RUNTIME_QUOTA_PROVIDER_IDS = exports.QUOTA_PROVIDER_IDS = exports.ACCOUNT_PROVIDER_IDS = void 0;
|
|
16
|
+
exports.stateFileWriterSchema = exports.stateFileSessionSchema = exports.stateFileQuotaWindowSchema = exports.stateFileQuotaSchema = exports.stateFileContextSchema = exports.stateFileBillingBlockSchema = exports.stateFileAccountSchema = exports.sidekickStateFileSchema = exports.assistantTurnToolRefSchema = exports.assistantTurnToolGroupStepSchema = exports.assistantTurnTimelineItemSchema = exports.assistantTurnSubagentStatusSchema = exports.assistantTurnSubagentSchema = exports.assistantTurnReasoningTimelineItemSchema = exports.assistantTurnProjectionSchema = exports.assistantTurnProcessStepSchema = exports.assistantTurnProcessSchema = exports.assistantTurnNarrationStepSchema = exports.assistantTurnEventTypeSchema = exports.assistantTurnEventSchema = exports.accountLaunchEnvSchema = exports.syncReportSchema = exports.providerSyncReportSchema = exports.lastSwitchRecordSchema = exports.switchAccountResultSchema = exports.runningAccountConsumerSchema = exports.accountConsumerKindSchema = exports.runningProcessSchema = exports.accountViewSchema = exports.accountHealthSchema = exports.accountHealthSidecarSchema = exports.accountHealthSourceSchema = exports.accountHealthStateSchema = exports.listAllAccountsResultSchema = exports.savedAccountProfileSchema = exports.accountEntrySchema = exports.accountLoginStatusSchema = exports.beginAccountLoginResultSchema = exports.accountManagerResultSchema = exports.accountProviderIdSchema = exports.activeAccountStatusSchema = exports.activeProviderAccountStatusSchema = exports.quotaHistoryDailyBucketSchema = exports.quotaHistorySampleSchema = void 0;
|
|
17
17
|
var providerIds_1 = require("../providerIds");
|
|
18
18
|
Object.defineProperty(exports, "ACCOUNT_PROVIDER_IDS", { enumerable: true, get: function () { return providerIds_1.ACCOUNT_PROVIDER_IDS; } });
|
|
19
19
|
Object.defineProperty(exports, "QUOTA_PROVIDER_IDS", { enumerable: true, get: function () { return providerIds_1.QUOTA_PROVIDER_IDS; } });
|
|
@@ -36,6 +36,11 @@ Object.defineProperty(exports, "normalizedUsageSchema", { enumerable: true, get:
|
|
|
36
36
|
Object.defineProperty(exports, "normalizedUsageCostSchema", { enumerable: true, get: function () { return usageNormalization_1.normalizedUsageCostSchema; } });
|
|
37
37
|
var tokenEstimation_1 = require("./tokenEstimation");
|
|
38
38
|
Object.defineProperty(exports, "tokenEstimateSchema", { enumerable: true, get: function () { return tokenEstimation_1.tokenEstimateSchema; } });
|
|
39
|
+
var providerFailure_1 = require("./providerFailure");
|
|
40
|
+
Object.defineProperty(exports, "providerAuthenticationEvidenceSchema", { enumerable: true, get: function () { return providerFailure_1.providerAuthenticationEvidenceSchema; } });
|
|
41
|
+
Object.defineProperty(exports, "providerFailureEvidenceSchema", { enumerable: true, get: function () { return providerFailure_1.providerFailureEvidenceSchema; } });
|
|
42
|
+
Object.defineProperty(exports, "providerRetryAfterSchema", { enumerable: true, get: function () { return providerFailure_1.providerRetryAfterSchema; } });
|
|
43
|
+
Object.defineProperty(exports, "providerFailureDiagnosisSchema", { enumerable: true, get: function () { return providerFailure_1.providerFailureDiagnosisSchema; } });
|
|
39
44
|
var transcript_1 = require("./transcript");
|
|
40
45
|
Object.defineProperty(exports, "transcriptSourceProvenanceSchema", { enumerable: true, get: function () { return transcript_1.transcriptSourceProvenanceSchema; } });
|
|
41
46
|
Object.defineProperty(exports, "canonicalTranscriptBlockSchema", { enumerable: true, get: function () { return transcript_1.canonicalTranscriptBlockSchema; } });
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schema for runtime validation of provider-failure diagnoses.
|
|
3
|
+
*
|
|
4
|
+
* The enums are built from the same `as const` arrays that define the
|
|
5
|
+
* TypeScript unions in `providerFailure.ts`, so a new failure code or recovery
|
|
6
|
+
* action reaches the schema without a second edit.
|
|
7
|
+
*
|
|
8
|
+
* @module schemas/providerFailure
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
export declare const providerAuthenticationEvidenceSchema: z.ZodObject<{
|
|
12
|
+
credentialKind: z.ZodEnum<{
|
|
13
|
+
unknown: "unknown";
|
|
14
|
+
"api-key": "api-key";
|
|
15
|
+
oauth: "oauth";
|
|
16
|
+
}>;
|
|
17
|
+
state: z.ZodEnum<{
|
|
18
|
+
unknown: "unknown";
|
|
19
|
+
expired: "expired";
|
|
20
|
+
missing: "missing";
|
|
21
|
+
authenticated: "authenticated";
|
|
22
|
+
"signed-out": "signed-out";
|
|
23
|
+
rejected: "rejected";
|
|
24
|
+
}>;
|
|
25
|
+
checkedAt: z.ZodString;
|
|
26
|
+
source: z.ZodEnum<{
|
|
27
|
+
"local-check": "local-check";
|
|
28
|
+
"provider-response": "provider-response";
|
|
29
|
+
}>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
export declare const providerFailureEvidenceSchema: z.ZodObject<{
|
|
32
|
+
source: z.ZodEnum<{
|
|
33
|
+
message: "message";
|
|
34
|
+
"structured-error": "structured-error";
|
|
35
|
+
"http-status": "http-status";
|
|
36
|
+
"authentication-check": "authentication-check";
|
|
37
|
+
}>;
|
|
38
|
+
rule: z.ZodEnum<{
|
|
39
|
+
unknown: "unknown";
|
|
40
|
+
timeout: "timeout";
|
|
41
|
+
missing_credentials: "missing_credentials";
|
|
42
|
+
oauth_reauthentication_required: "oauth_reauthentication_required";
|
|
43
|
+
api_credentials_rejected: "api_credentials_rejected";
|
|
44
|
+
authentication_rejected: "authentication_rejected";
|
|
45
|
+
invalid_provider_session: "invalid_provider_session";
|
|
46
|
+
service_unavailable: "service_unavailable";
|
|
47
|
+
connection_failed: "connection_failed";
|
|
48
|
+
rate_limited: "rate_limited";
|
|
49
|
+
overloaded: "overloaded";
|
|
50
|
+
execution_policy_denied: "execution_policy_denied";
|
|
51
|
+
runtime_unavailable: "runtime_unavailable";
|
|
52
|
+
context_overflow: "context_overflow";
|
|
53
|
+
}>;
|
|
54
|
+
checkedAt: z.ZodOptional<z.ZodString>;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
export declare const providerRetryAfterSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
57
|
+
kind: z.ZodLiteral<"delay">;
|
|
58
|
+
delayMs: z.ZodNumber;
|
|
59
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
60
|
+
kind: z.ZodLiteral<"date">;
|
|
61
|
+
at: z.ZodString;
|
|
62
|
+
}, z.core.$strip>], "kind">;
|
|
63
|
+
export declare const providerFailureDiagnosisSchema: z.ZodObject<{
|
|
64
|
+
provider: z.ZodEnum<{
|
|
65
|
+
"claude-code": "claude-code";
|
|
66
|
+
codex: "codex";
|
|
67
|
+
}>;
|
|
68
|
+
credentialKind: z.ZodEnum<{
|
|
69
|
+
unknown: "unknown";
|
|
70
|
+
"api-key": "api-key";
|
|
71
|
+
oauth: "oauth";
|
|
72
|
+
}>;
|
|
73
|
+
diagnosis: z.ZodEnum<{
|
|
74
|
+
unknown: "unknown";
|
|
75
|
+
timeout: "timeout";
|
|
76
|
+
missing_credentials: "missing_credentials";
|
|
77
|
+
oauth_reauthentication_required: "oauth_reauthentication_required";
|
|
78
|
+
api_credentials_rejected: "api_credentials_rejected";
|
|
79
|
+
authentication_rejected: "authentication_rejected";
|
|
80
|
+
invalid_provider_session: "invalid_provider_session";
|
|
81
|
+
service_unavailable: "service_unavailable";
|
|
82
|
+
connection_failed: "connection_failed";
|
|
83
|
+
rate_limited: "rate_limited";
|
|
84
|
+
overloaded: "overloaded";
|
|
85
|
+
execution_policy_denied: "execution_policy_denied";
|
|
86
|
+
runtime_unavailable: "runtime_unavailable";
|
|
87
|
+
context_overflow: "context_overflow";
|
|
88
|
+
}>;
|
|
89
|
+
recovery: z.ZodEnum<{
|
|
90
|
+
sign_in: "sign_in";
|
|
91
|
+
update_credentials: "update_credentials";
|
|
92
|
+
check_authentication: "check_authentication";
|
|
93
|
+
start_new_session: "start_new_session";
|
|
94
|
+
retry_later: "retry_later";
|
|
95
|
+
check_connection: "check_connection";
|
|
96
|
+
review_execution_policy: "review_execution_policy";
|
|
97
|
+
repair_runtime: "repair_runtime";
|
|
98
|
+
reduce_context: "reduce_context";
|
|
99
|
+
inspect_error: "inspect_error";
|
|
100
|
+
}>;
|
|
101
|
+
evidence: z.ZodArray<z.ZodObject<{
|
|
102
|
+
source: z.ZodEnum<{
|
|
103
|
+
message: "message";
|
|
104
|
+
"structured-error": "structured-error";
|
|
105
|
+
"http-status": "http-status";
|
|
106
|
+
"authentication-check": "authentication-check";
|
|
107
|
+
}>;
|
|
108
|
+
rule: z.ZodEnum<{
|
|
109
|
+
unknown: "unknown";
|
|
110
|
+
timeout: "timeout";
|
|
111
|
+
missing_credentials: "missing_credentials";
|
|
112
|
+
oauth_reauthentication_required: "oauth_reauthentication_required";
|
|
113
|
+
api_credentials_rejected: "api_credentials_rejected";
|
|
114
|
+
authentication_rejected: "authentication_rejected";
|
|
115
|
+
invalid_provider_session: "invalid_provider_session";
|
|
116
|
+
service_unavailable: "service_unavailable";
|
|
117
|
+
connection_failed: "connection_failed";
|
|
118
|
+
rate_limited: "rate_limited";
|
|
119
|
+
overloaded: "overloaded";
|
|
120
|
+
execution_policy_denied: "execution_policy_denied";
|
|
121
|
+
runtime_unavailable: "runtime_unavailable";
|
|
122
|
+
context_overflow: "context_overflow";
|
|
123
|
+
}>;
|
|
124
|
+
checkedAt: z.ZodOptional<z.ZodString>;
|
|
125
|
+
}, z.core.$strip>>;
|
|
126
|
+
authentication: z.ZodOptional<z.ZodObject<{
|
|
127
|
+
credentialKind: z.ZodEnum<{
|
|
128
|
+
unknown: "unknown";
|
|
129
|
+
"api-key": "api-key";
|
|
130
|
+
oauth: "oauth";
|
|
131
|
+
}>;
|
|
132
|
+
state: z.ZodEnum<{
|
|
133
|
+
unknown: "unknown";
|
|
134
|
+
expired: "expired";
|
|
135
|
+
missing: "missing";
|
|
136
|
+
authenticated: "authenticated";
|
|
137
|
+
"signed-out": "signed-out";
|
|
138
|
+
rejected: "rejected";
|
|
139
|
+
}>;
|
|
140
|
+
checkedAt: z.ZodString;
|
|
141
|
+
source: z.ZodEnum<{
|
|
142
|
+
"local-check": "local-check";
|
|
143
|
+
"provider-response": "provider-response";
|
|
144
|
+
}>;
|
|
145
|
+
}, z.core.$strip>>;
|
|
146
|
+
httpStatus: z.ZodOptional<z.ZodNumber>;
|
|
147
|
+
retryAfter: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
148
|
+
kind: z.ZodLiteral<"delay">;
|
|
149
|
+
delayMs: z.ZodNumber;
|
|
150
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
151
|
+
kind: z.ZodLiteral<"date">;
|
|
152
|
+
at: z.ZodString;
|
|
153
|
+
}, z.core.$strip>], "kind">>;
|
|
154
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for runtime validation of provider-failure diagnoses.
|
|
4
|
+
*
|
|
5
|
+
* The enums are built from the same `as const` arrays that define the
|
|
6
|
+
* TypeScript unions in `providerFailure.ts`, so a new failure code or recovery
|
|
7
|
+
* action reaches the schema without a second edit.
|
|
8
|
+
*
|
|
9
|
+
* @module schemas/providerFailure
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.providerFailureDiagnosisSchema = exports.providerRetryAfterSchema = exports.providerFailureEvidenceSchema = exports.providerAuthenticationEvidenceSchema = void 0;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const providerIds_1 = require("../providerIds");
|
|
15
|
+
const providerFailure_1 = require("../providerFailure");
|
|
16
|
+
exports.providerAuthenticationEvidenceSchema = zod_1.z.object({
|
|
17
|
+
credentialKind: zod_1.z.enum(providerFailure_1.PROVIDER_CREDENTIAL_KINDS),
|
|
18
|
+
state: zod_1.z.enum(providerFailure_1.PROVIDER_AUTHENTICATION_STATES),
|
|
19
|
+
checkedAt: zod_1.z.string(),
|
|
20
|
+
source: zod_1.z.enum(providerFailure_1.PROVIDER_AUTHENTICATION_SOURCES),
|
|
21
|
+
});
|
|
22
|
+
exports.providerFailureEvidenceSchema = zod_1.z.object({
|
|
23
|
+
source: zod_1.z.enum(providerFailure_1.PROVIDER_FAILURE_EVIDENCE_SOURCES),
|
|
24
|
+
rule: zod_1.z.enum(providerFailure_1.PROVIDER_FAILURE_CODES),
|
|
25
|
+
checkedAt: zod_1.z.string().optional(),
|
|
26
|
+
});
|
|
27
|
+
exports.providerRetryAfterSchema = zod_1.z.discriminatedUnion('kind', [
|
|
28
|
+
zod_1.z.object({ kind: zod_1.z.literal('delay'), delayMs: zod_1.z.number() }),
|
|
29
|
+
zod_1.z.object({ kind: zod_1.z.literal('date'), at: zod_1.z.string() }),
|
|
30
|
+
]);
|
|
31
|
+
exports.providerFailureDiagnosisSchema = zod_1.z.object({
|
|
32
|
+
provider: zod_1.z.enum(providerIds_1.ACCOUNT_PROVIDER_IDS),
|
|
33
|
+
credentialKind: zod_1.z.enum(providerFailure_1.PROVIDER_CREDENTIAL_KINDS),
|
|
34
|
+
diagnosis: zod_1.z.enum(providerFailure_1.PROVIDER_FAILURE_CODES),
|
|
35
|
+
recovery: zod_1.z.enum(providerFailure_1.PROVIDER_RECOVERY_ACTIONS),
|
|
36
|
+
evidence: zod_1.z.array(exports.providerFailureEvidenceSchema),
|
|
37
|
+
authentication: exports.providerAuthenticationEvidenceSchema.optional(),
|
|
38
|
+
httpStatus: zod_1.z.number().optional(),
|
|
39
|
+
retryAfter: exports.providerRetryAfterSchema.optional(),
|
|
40
|
+
});
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* `sessionIds` continues. Scope fails closed as in `collectPromptHistory()`,
|
|
14
14
|
* and replies or signals that belong to an out-of-scope prompt are dropped.
|
|
15
15
|
*/
|
|
16
|
-
import { type PromptHistoryEntry, type PromptHistoryExclusion, type PromptHistoryProvider } from './promptHistory';
|
|
16
|
+
import { type PromptHistoryEntry, type PromptHistoryExclusion, type PromptHistoryProvider, type PromptHistorySessionRef } from './promptHistory';
|
|
17
17
|
import { type PromptHistoryReply, type PromptHistorySignal } from './sessionPromptSignals';
|
|
18
18
|
export interface SessionPromptHistoryInclude {
|
|
19
19
|
/** Interrupts, rejected and failed tool calls, compactions, API errors, rollbacks. */
|
|
@@ -40,8 +40,14 @@ export interface CollectSessionPromptHistoryOptions {
|
|
|
40
40
|
includeWorktrees?: boolean;
|
|
41
41
|
/** Default both. */
|
|
42
42
|
providers?: PromptHistoryProvider[];
|
|
43
|
-
/** Only these sessions (exact ids). */
|
|
43
|
+
/** Only these sessions (exact ids, any provider). */
|
|
44
44
|
sessionIds?: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Only these sessions, matched on provider and id, or on the exact file
|
|
47
|
+
* when `sessionKey` is given. Combined with `sessionIds`, a session that
|
|
48
|
+
* matches either is read.
|
|
49
|
+
*/
|
|
50
|
+
sessionRefs?: PromptHistorySessionRef[];
|
|
45
51
|
/** Only sessions whose file changed at or after this. Each comes back whole. */
|
|
46
52
|
since?: Date;
|
|
47
53
|
/** Return at most this many sessions, most recently modified first. */
|
|
@@ -51,7 +57,7 @@ export interface CollectSessionPromptHistoryOptions {
|
|
|
51
57
|
bounds?: SessionPromptHistoryBounds;
|
|
52
58
|
signal?: AbortSignal;
|
|
53
59
|
}
|
|
54
|
-
export interface PromptHistorySessionPrompt extends Omit<PromptHistoryEntry, 'provider' | 'sessionId'> {
|
|
60
|
+
export interface PromptHistorySessionPrompt extends Omit<PromptHistoryEntry, 'provider' | 'sessionId' | 'sessionKey'> {
|
|
55
61
|
/** With `include.replies`: the agent's last text for this prompt's turn. */
|
|
56
62
|
reply?: PromptHistoryReply;
|
|
57
63
|
}
|
|
@@ -80,11 +86,10 @@ export interface PromptHistorySession {
|
|
|
80
86
|
droppedPrompts: number;
|
|
81
87
|
/** Records left out as oversized or malformed (see `exclusions`). */
|
|
82
88
|
excludedRecords: number;
|
|
89
|
+
/** Opaque key of the session file; tells apart two files with one session id. */
|
|
90
|
+
sessionKey?: string;
|
|
83
91
|
}
|
|
84
|
-
export
|
|
85
|
-
provider: PromptHistoryProvider;
|
|
86
|
-
sessionId: string;
|
|
87
|
-
}
|
|
92
|
+
export type { PromptHistorySessionRef };
|
|
88
93
|
export type SessionPromptHistoryBound = 'maxSessions' | 'maxSessionBytes' | 'maxTotalBytes' | 'deadline' | 'aborted';
|
|
89
94
|
export interface SessionPromptHistoryStats {
|
|
90
95
|
/** Session files that matched the provider, id, and `since` filters. */
|
|
@@ -117,6 +117,7 @@ async function collectSessionPromptHistory(options) {
|
|
|
117
117
|
const refOf = ({ candidate }) => ({
|
|
118
118
|
provider: candidate.provider,
|
|
119
119
|
sessionId: candidate.sessionId,
|
|
120
|
+
sessionKey: candidate.key,
|
|
120
121
|
});
|
|
121
122
|
let totalBytes = 0;
|
|
122
123
|
for (let index = 0; index < selected.length && sessions.length < limit; index++) {
|
|
@@ -224,9 +225,19 @@ async function selectCandidates(options, listingRoots) {
|
|
|
224
225
|
const sinceMs = options.since ? options.since.getTime() : null;
|
|
225
226
|
const providers = options.providers ?? ['claude-code', 'codex'];
|
|
226
227
|
let candidates = await (0, promptHistory_1.listCandidates)(providers, listingRoots, sinceMs);
|
|
227
|
-
if (options.sessionIds) {
|
|
228
|
-
const
|
|
229
|
-
|
|
228
|
+
if (options.sessionIds || options.sessionRefs) {
|
|
229
|
+
const ids = new Set(options.sessionIds ?? []);
|
|
230
|
+
const keys = new Set();
|
|
231
|
+
const refs = new Set();
|
|
232
|
+
for (const ref of options.sessionRefs ?? []) {
|
|
233
|
+
if (ref.sessionKey)
|
|
234
|
+
keys.add(ref.sessionKey);
|
|
235
|
+
else
|
|
236
|
+
refs.add(`${ref.provider}:${ref.sessionId}`);
|
|
237
|
+
}
|
|
238
|
+
candidates = candidates.filter((candidate) => ids.has(candidate.sessionId) ||
|
|
239
|
+
keys.has(candidate.key) ||
|
|
240
|
+
refs.has(`${candidate.provider}:${candidate.sessionId}`));
|
|
230
241
|
}
|
|
231
242
|
const selected = [];
|
|
232
243
|
for (const candidate of candidates) {
|
|
@@ -251,6 +262,7 @@ function buildSession(candidate, entries, lastOrdinal, extraction, include, read
|
|
|
251
262
|
const session = {
|
|
252
263
|
provider: candidate.provider,
|
|
253
264
|
sessionId: candidate.sessionId,
|
|
265
|
+
sessionKey: candidate.key,
|
|
254
266
|
startedAt: extraction.firstTimestamp ?? ordered[0].timestamp,
|
|
255
267
|
lastActivityAt: extraction.lastTimestamp ?? ordered[ordered.length - 1].timestamp,
|
|
256
268
|
cwds: distinct(ordered.map((entry) => entry.cwd)),
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* ordinals of `collectPromptHistory()`.
|
|
10
10
|
*/
|
|
11
11
|
import type { PromptHistoryProvider } from './promptHistory';
|
|
12
|
+
import { type ToolCategory } from './toolCategory';
|
|
12
13
|
export type PromptHistorySignalKind = 'interrupt' | 'toolRejected' | 'toolError' | 'compaction' | 'apiError' | 'rollback';
|
|
13
14
|
export interface PromptHistorySignal {
|
|
14
15
|
kind: PromptHistorySignalKind;
|
|
@@ -18,6 +19,14 @@ export interface PromptHistorySignal {
|
|
|
18
19
|
afterOrdinal: number;
|
|
19
20
|
/** The tool involved, for `toolRejected` and `toolError`, when the log names it. */
|
|
20
21
|
tool?: string;
|
|
22
|
+
/** What `tool` does (`shell`, `file_edit`, `mcp`, …), from `classifyTool()`. */
|
|
23
|
+
toolCategory?: ToolCategory;
|
|
24
|
+
/**
|
|
25
|
+
* The MCP server of an MCP tool call: from `mcp__<server>__<tool>` names
|
|
26
|
+
* (Claude Code) or the call's own server field (Codex, whose `tool` is the
|
|
27
|
+
* bare tool name).
|
|
28
|
+
*/
|
|
29
|
+
mcpServer?: string;
|
|
21
30
|
/**
|
|
22
31
|
* `toolRejected`: the reason the person typed, untruncated. `toolError` and
|
|
23
32
|
* `apiError`: the error text, cut to 1024 characters (`textTruncated`).
|