@ironbee-ai/cli 0.6.2 → 0.7.1
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 +12 -0
- package/README.md +167 -39
- package/dist/analysis/code-changes.js.map +1 -1
- package/dist/analysis/cross-session.js.map +1 -1
- package/dist/analysis/fix-effectiveness.js.map +1 -1
- package/dist/analysis/time-analysis.js.map +1 -1
- package/dist/analysis/verdict-details.js.map +1 -1
- package/dist/analysis/verification-quality.js.map +1 -1
- package/dist/analytics/classifier.d.ts +99 -0
- package/dist/analytics/classifier.d.ts.map +1 -0
- package/dist/analytics/classifier.js +380 -0
- package/dist/analytics/classifier.js.map +1 -0
- package/dist/analytics/emit.d.ts +67 -0
- package/dist/analytics/emit.d.ts.map +1 -0
- package/dist/analytics/emit.js +901 -0
- package/dist/analytics/emit.js.map +1 -0
- package/dist/analytics/errors.d.ts +33 -0
- package/dist/analytics/errors.d.ts.map +1 -0
- package/dist/analytics/errors.js +93 -0
- package/dist/analytics/errors.js.map +1 -0
- package/dist/analytics/hook-trigger.d.ts +39 -0
- package/dist/analytics/hook-trigger.d.ts.map +1 -0
- package/dist/analytics/hook-trigger.js +127 -0
- package/dist/analytics/hook-trigger.js.map +1 -0
- package/dist/analytics/log.d.ts +44 -0
- package/dist/analytics/log.d.ts.map +1 -0
- package/dist/analytics/log.js +158 -0
- package/dist/analytics/log.js.map +1 -0
- package/dist/analytics/merge.d.ts +40 -0
- package/dist/analytics/merge.d.ts.map +1 -0
- package/dist/analytics/merge.js +527 -0
- package/dist/analytics/merge.js.map +1 -0
- package/dist/analytics/pricing.d.ts +149 -0
- package/dist/analytics/pricing.d.ts.map +1 -0
- package/dist/analytics/pricing.js +179 -0
- package/dist/analytics/pricing.js.map +1 -0
- package/dist/analytics/projection.d.ts +356 -0
- package/dist/analytics/projection.d.ts.map +1 -0
- package/dist/analytics/projection.js +2281 -0
- package/dist/analytics/projection.js.map +1 -0
- package/dist/analytics/spawn.d.ts +28 -0
- package/dist/analytics/spawn.d.ts.map +1 -0
- package/dist/analytics/spawn.js +57 -0
- package/dist/analytics/spawn.js.map +1 -0
- package/dist/analytics/state.d.ts +58 -0
- package/dist/analytics/state.d.ts.map +1 -0
- package/dist/analytics/state.js +329 -0
- package/dist/analytics/state.js.map +1 -0
- package/dist/analytics/transcript.d.ts +150 -0
- package/dist/analytics/transcript.d.ts.map +1 -0
- package/dist/analytics/transcript.js +276 -0
- package/dist/analytics/transcript.js.map +1 -0
- package/dist/analytics/types.d.ts +875 -0
- package/dist/analytics/types.d.ts.map +1 -0
- package/dist/analytics/types.js +31 -0
- package/dist/analytics/types.js.map +1 -0
- package/dist/clients/base.d.ts +21 -2
- package/dist/clients/base.d.ts.map +1 -1
- package/dist/clients/claude/commands/ironbee-verify.md +15 -7
- package/dist/clients/claude/fragments/command-verify.node.md +33 -0
- package/dist/clients/claude/fragments/rule.node.md +29 -0
- package/dist/clients/claude/fragments/skill.node.md +77 -0
- package/dist/clients/claude/hooks/activity-end.d.ts +13 -0
- package/dist/clients/claude/hooks/activity-end.d.ts.map +1 -0
- package/dist/clients/claude/hooks/activity-end.js +42 -0
- package/dist/clients/claude/hooks/activity-end.js.map +1 -0
- package/dist/clients/claude/hooks/require-verdict.d.ts +3 -2
- package/dist/clients/claude/hooks/require-verdict.d.ts.map +1 -1
- package/dist/clients/claude/hooks/require-verdict.js +6 -5
- package/dist/clients/claude/hooks/require-verdict.js.map +1 -1
- package/dist/clients/claude/hooks/require-verification.d.ts +7 -4
- package/dist/clients/claude/hooks/require-verification.d.ts.map +1 -1
- package/dist/clients/claude/hooks/require-verification.js +44 -22
- package/dist/clients/claude/hooks/require-verification.js.map +1 -1
- package/dist/clients/claude/hooks/session-end.d.ts.map +1 -1
- package/dist/clients/claude/hooks/session-end.js +17 -2
- package/dist/clients/claude/hooks/session-end.js.map +1 -1
- package/dist/clients/claude/hooks/session-start.d.ts.map +1 -1
- package/dist/clients/claude/hooks/session-start.js +2 -1
- package/dist/clients/claude/hooks/session-start.js.map +1 -1
- package/dist/clients/claude/hooks/track-action-monitor.d.ts +27 -0
- package/dist/clients/claude/hooks/track-action-monitor.d.ts.map +1 -0
- package/dist/clients/claude/hooks/track-action-monitor.js +126 -0
- package/dist/clients/claude/hooks/track-action-monitor.js.map +1 -0
- package/dist/clients/claude/hooks/track-action.d.ts.map +1 -1
- package/dist/clients/claude/hooks/track-action.js +29 -20
- package/dist/clients/claude/hooks/track-action.js.map +1 -1
- package/dist/clients/claude/hooks/verify-gate.d.ts.map +1 -1
- package/dist/clients/claude/hooks/verify-gate.js +18 -1
- package/dist/clients/claude/hooks/verify-gate.js.map +1 -1
- package/dist/clients/claude/index.d.ts +4 -1
- package/dist/clients/claude/index.d.ts.map +1 -1
- package/dist/clients/claude/index.js +171 -94
- package/dist/clients/claude/index.js.map +1 -1
- package/dist/clients/claude/rules/ironbee-verification.md +41 -33
- package/dist/clients/claude/skills/ironbee-verification.md +93 -76
- package/dist/clients/cursor/commands/ironbee-verify/SKILL.md +18 -10
- package/dist/clients/cursor/fragments/command-verify.node.md +33 -0
- package/dist/clients/cursor/fragments/rule.node.md +29 -0
- package/dist/clients/cursor/fragments/skill.node.md +77 -0
- package/dist/clients/cursor/hooks/activity-end.d.ts +14 -0
- package/dist/clients/cursor/hooks/activity-end.d.ts.map +1 -0
- package/dist/clients/cursor/hooks/activity-end.js +45 -0
- package/dist/clients/cursor/hooks/activity-end.js.map +1 -0
- package/dist/clients/cursor/hooks/require-verdict.d.ts +1 -1
- package/dist/clients/cursor/hooks/require-verdict.js +4 -4
- package/dist/clients/cursor/hooks/require-verification.d.ts.map +1 -1
- package/dist/clients/cursor/hooks/require-verification.js +42 -16
- package/dist/clients/cursor/hooks/require-verification.js.map +1 -1
- package/dist/clients/cursor/hooks/session-end.d.ts.map +1 -1
- package/dist/clients/cursor/hooks/session-end.js +18 -2
- package/dist/clients/cursor/hooks/session-end.js.map +1 -1
- package/dist/clients/cursor/hooks/session-start.d.ts.map +1 -1
- package/dist/clients/cursor/hooks/session-start.js +2 -1
- package/dist/clients/cursor/hooks/session-start.js.map +1 -1
- package/dist/clients/cursor/hooks/track-action-monitor.d.ts +27 -0
- package/dist/clients/cursor/hooks/track-action-monitor.d.ts.map +1 -0
- package/dist/clients/cursor/hooks/track-action-monitor.js +133 -0
- package/dist/clients/cursor/hooks/track-action-monitor.js.map +1 -0
- package/dist/clients/cursor/hooks/track-action.d.ts.map +1 -1
- package/dist/clients/cursor/hooks/track-action.js +51 -23
- package/dist/clients/cursor/hooks/track-action.js.map +1 -1
- package/dist/clients/cursor/hooks/verify-gate.d.ts.map +1 -1
- package/dist/clients/cursor/hooks/verify-gate.js +14 -1
- package/dist/clients/cursor/hooks/verify-gate.js.map +1 -1
- package/dist/clients/cursor/index.d.ts +4 -1
- package/dist/clients/cursor/index.d.ts.map +1 -1
- package/dist/clients/cursor/index.js +117 -71
- package/dist/clients/cursor/index.js.map +1 -1
- package/dist/clients/cursor/rules/ironbee-verification.mdc +37 -29
- package/dist/clients/cursor/skills/ironbee-verification.md +93 -76
- package/dist/clients/registry.d.ts +14 -0
- package/dist/clients/registry.d.ts.map +1 -1
- package/dist/clients/registry.js +34 -0
- package/dist/clients/registry.js.map +1 -1
- package/dist/commands/analyze.d.ts.map +1 -1
- package/dist/commands/analyze.js +40 -0
- package/dist/commands/analyze.js.map +1 -1
- package/dist/commands/backend-toggle.d.ts +45 -0
- package/dist/commands/backend-toggle.d.ts.map +1 -0
- package/dist/commands/backend-toggle.js +192 -0
- package/dist/commands/backend-toggle.js.map +1 -0
- package/dist/commands/disable-backend.d.ts +14 -0
- package/dist/commands/disable-backend.d.ts.map +1 -0
- package/dist/commands/disable-backend.js +34 -0
- package/dist/commands/disable-backend.js.map +1 -0
- package/dist/commands/disable-verification.d.ts +16 -0
- package/dist/commands/disable-verification.d.ts.map +1 -0
- package/dist/commands/disable-verification.js +36 -0
- package/dist/commands/disable-verification.js.map +1 -0
- package/dist/commands/enable-backend.d.ts +15 -0
- package/dist/commands/enable-backend.d.ts.map +1 -0
- package/dist/commands/enable-backend.js +35 -0
- package/dist/commands/enable-backend.js.map +1 -0
- package/dist/commands/enable-verification.d.ts +14 -0
- package/dist/commands/enable-verification.d.ts.map +1 -0
- package/dist/commands/enable-verification.js +34 -0
- package/dist/commands/enable-verification.js.map +1 -0
- package/dist/commands/hook.d.ts.map +1 -1
- package/dist/commands/hook.js +60 -0
- package/dist/commands/hook.js.map +1 -1
- package/dist/commands/import.d.ts +39 -0
- package/dist/commands/import.d.ts.map +1 -0
- package/dist/commands/import.js +369 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/install.d.ts.map +1 -1
- package/dist/commands/install.js +15 -20
- package/dist/commands/install.js.map +1 -1
- package/dist/commands/process-analytics.d.ts +18 -0
- package/dist/commands/process-analytics.d.ts.map +1 -0
- package/dist/commands/process-analytics.js +57 -0
- package/dist/commands/process-analytics.js.map +1 -0
- package/dist/commands/queue.d.ts +2 -3
- package/dist/commands/queue.d.ts.map +1 -1
- package/dist/commands/queue.js +2 -3
- package/dist/commands/queue.js.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +29 -1
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/verification-toggle.d.ts +47 -0
- package/dist/commands/verification-toggle.d.ts.map +1 -0
- package/dist/commands/verification-toggle.js +122 -0
- package/dist/commands/verification-toggle.js.map +1 -0
- package/dist/commands/verify.d.ts.map +1 -1
- package/dist/commands/verify.js +28 -0
- package/dist/commands/verify.js.map +1 -1
- package/dist/hooks/core/actions.d.ts +72 -70
- package/dist/hooks/core/actions.d.ts.map +1 -1
- package/dist/hooks/core/actions.js +191 -28
- package/dist/hooks/core/actions.js.map +1 -1
- package/dist/hooks/core/activity-end.d.ts +20 -0
- package/dist/hooks/core/activity-end.d.ts.map +1 -0
- package/dist/hooks/core/activity-end.js +23 -0
- package/dist/hooks/core/activity-end.js.map +1 -0
- package/dist/hooks/core/required-tools.d.ts +30 -0
- package/dist/hooks/core/required-tools.d.ts.map +1 -0
- package/dist/hooks/core/required-tools.js +70 -0
- package/dist/hooks/core/required-tools.js.map +1 -0
- package/dist/hooks/core/session-state.d.ts +12 -3
- package/dist/hooks/core/session-state.d.ts.map +1 -1
- package/dist/hooks/core/session-state.js +59 -0
- package/dist/hooks/core/session-state.js.map +1 -1
- package/dist/hooks/core/submit-verdict.d.ts.map +1 -1
- package/dist/hooks/core/submit-verdict.js +16 -12
- package/dist/hooks/core/submit-verdict.js.map +1 -1
- package/dist/hooks/core/verify-gate.d.ts +17 -3
- package/dist/hooks/core/verify-gate.d.ts.map +1 -1
- package/dist/hooks/core/verify-gate.js +312 -116
- package/dist/hooks/core/verify-gate.js.map +1 -1
- package/dist/import/claude/analytics-runner.d.ts +42 -0
- package/dist/import/claude/analytics-runner.d.ts.map +1 -0
- package/dist/import/claude/analytics-runner.js +213 -0
- package/dist/import/claude/analytics-runner.js.map +1 -0
- package/dist/import/claude/discovery.d.ts +22 -0
- package/dist/import/claude/discovery.d.ts.map +1 -0
- package/dist/import/claude/discovery.js +197 -0
- package/dist/import/claude/discovery.js.map +1 -0
- package/dist/import/claude/encoding.d.ts +50 -0
- package/dist/import/claude/encoding.d.ts.map +1 -0
- package/dist/import/claude/encoding.js +110 -0
- package/dist/import/claude/encoding.js.map +1 -0
- package/dist/import/claude/events/file-change.d.ts +28 -0
- package/dist/import/claude/events/file-change.d.ts.map +1 -0
- package/dist/import/claude/events/file-change.js +112 -0
- package/dist/import/claude/events/file-change.js.map +1 -0
- package/dist/import/claude/events/tool-call.d.ts +61 -0
- package/dist/import/claude/events/tool-call.d.ts.map +1 -0
- package/dist/import/claude/events/tool-call.js +119 -0
- package/dist/import/claude/events/tool-call.js.map +1 -0
- package/dist/import/claude/runner.d.ts +31 -0
- package/dist/import/claude/runner.d.ts.map +1 -0
- package/dist/import/claude/runner.js +280 -0
- package/dist/import/claude/runner.js.map +1 -0
- package/dist/import/claude/summary.d.ts +23 -0
- package/dist/import/claude/summary.d.ts.map +1 -0
- package/dist/import/claude/summary.js +186 -0
- package/dist/import/claude/summary.js.map +1 -0
- package/dist/import/claude/transcript-walk.d.ts +52 -0
- package/dist/import/claude/transcript-walk.d.ts.map +1 -0
- package/dist/import/claude/transcript-walk.js +187 -0
- package/dist/import/claude/transcript-walk.js.map +1 -0
- package/dist/import/concurrent-pool.d.ts +45 -0
- package/dist/import/concurrent-pool.d.ts.map +1 -0
- package/dist/import/concurrent-pool.js +95 -0
- package/dist/import/concurrent-pool.js.map +1 -0
- package/dist/import/emitter.d.ts +29 -0
- package/dist/import/emitter.d.ts.map +1 -0
- package/dist/import/emitter.js +66 -0
- package/dist/import/emitter.js.map +1 -0
- package/dist/import/events/activity.d.ts +23 -0
- package/dist/import/events/activity.d.ts.map +1 -0
- package/dist/import/events/activity.js +45 -0
- package/dist/import/events/activity.js.map +1 -0
- package/dist/import/events/session.d.ts +24 -0
- package/dist/import/events/session.d.ts.map +1 -0
- package/dist/import/events/session.js +47 -0
- package/dist/import/events/session.js.map +1 -0
- package/dist/import/filter.d.ts +47 -0
- package/dist/import/filter.d.ts.map +1 -0
- package/dist/import/filter.js +90 -0
- package/dist/import/filter.js.map +1 -0
- package/dist/import/ids.d.ts +56 -0
- package/dist/import/ids.d.ts.map +1 -0
- package/dist/import/ids.js +87 -0
- package/dist/import/ids.js.map +1 -0
- package/dist/import/index.d.ts +29 -0
- package/dist/import/index.d.ts.map +1 -0
- package/dist/import/index.js +52 -0
- package/dist/import/index.js.map +1 -0
- package/dist/import/marker.d.ts +20 -0
- package/dist/import/marker.d.ts.map +1 -0
- package/dist/import/marker.js +71 -0
- package/dist/import/marker.js.map +1 -0
- package/dist/import/pipeline.d.ts +41 -0
- package/dist/import/pipeline.d.ts.map +1 -0
- package/dist/import/pipeline.js +47 -0
- package/dist/import/pipeline.js.map +1 -0
- package/dist/import/progress.d.ts +20 -0
- package/dist/import/progress.d.ts.map +1 -0
- package/dist/import/progress.js +69 -0
- package/dist/import/progress.js.map +1 -0
- package/dist/import/skip.d.ts +13 -0
- package/dist/import/skip.d.ts.map +1 -0
- package/dist/import/skip.js +24 -0
- package/dist/import/skip.js.map +1 -0
- package/dist/import/types.d.ts +125 -0
- package/dist/import/types.d.ts.map +1 -0
- package/dist/import/types.js +28 -0
- package/dist/import/types.js.map +1 -0
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/collector.d.ts +29 -3
- package/dist/lib/collector.d.ts.map +1 -1
- package/dist/lib/collector.js +118 -8
- package/dist/lib/collector.js.map +1 -1
- package/dist/lib/config.d.ts +240 -83
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +482 -89
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/event.d.ts +72 -0
- package/dist/lib/event.d.ts.map +1 -0
- package/dist/lib/event.js +42 -0
- package/dist/lib/event.js.map +1 -0
- package/dist/lib/gitignore.d.ts +21 -0
- package/dist/lib/gitignore.d.ts.map +1 -0
- package/dist/lib/gitignore.js +54 -0
- package/dist/lib/gitignore.js.map +1 -0
- package/dist/lib/runtime-section.d.ts +118 -0
- package/dist/lib/runtime-section.d.ts.map +1 -0
- package/dist/lib/runtime-section.js +256 -0
- package/dist/lib/runtime-section.js.map +1 -0
- package/dist/lib/telemetry.d.ts +1 -1
- package/dist/lib/telemetry.d.ts.map +1 -1
- package/dist/lib/telemetry.js +4 -1
- package/dist/lib/telemetry.js.map +1 -1
- package/dist/queue/dead-letter.d.ts +5 -1
- package/dist/queue/dead-letter.d.ts.map +1 -1
- package/dist/queue/dead-letter.js +5 -1
- package/dist/queue/dead-letter.js.map +1 -1
- package/dist/queue/drain.d.ts +3 -2
- package/dist/queue/drain.d.ts.map +1 -1
- package/dist/queue/drain.js +3 -2
- package/dist/queue/drain.js.map +1 -1
- package/dist/queue/flush.d.ts +28 -12
- package/dist/queue/flush.d.ts.map +1 -1
- package/dist/queue/flush.js +43 -18
- package/dist/queue/flush.js.map +1 -1
- package/dist/queue/handlers/send-event.d.ts.map +1 -1
- package/dist/queue/handlers/send-event.js.map +1 -1
- package/dist/queue/index.d.ts +1 -2
- package/dist/queue/index.d.ts.map +1 -1
- package/dist/queue/index.js +2 -2
- package/dist/queue/index.js.map +1 -1
- package/dist/queue/paths.d.ts +4 -2
- package/dist/queue/paths.d.ts.map +1 -1
- package/dist/queue/paths.js +4 -2
- package/dist/queue/paths.js.map +1 -1
- package/dist/queue/process-file.d.ts +5 -1
- package/dist/queue/process-file.d.ts.map +1 -1
- package/dist/queue/process-file.js +5 -1
- package/dist/queue/process-file.js.map +1 -1
- package/dist/queue/snapshot.d.ts +4 -1
- package/dist/queue/snapshot.d.ts.map +1 -1
- package/dist/queue/snapshot.js +4 -1
- package/dist/queue/snapshot.js.map +1 -1
- package/dist/queue/spawn.d.ts +1 -3
- package/dist/queue/spawn.d.ts.map +1 -1
- package/dist/queue/spawn.js +1 -3
- package/dist/queue/spawn.js.map +1 -1
- package/dist/queue/submit.d.ts +6 -1
- package/dist/queue/submit.d.ts.map +1 -1
- package/dist/queue/submit.js +6 -1
- package/dist/queue/submit.js.map +1 -1
- package/dist/queue/types.d.ts +5 -1
- package/dist/queue/types.d.ts.map +1 -1
- package/dist/queue/types.js +5 -1
- package/dist/queue/types.js.map +1 -1
- package/dist/queue/worker-log.d.ts +3 -1
- package/dist/queue/worker-log.d.ts.map +1 -1
- package/dist/queue/worker-log.js +3 -1
- package/dist/queue/worker-log.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IronBee CLI — Claude Import Dry-Run Summary Estimator
|
|
3
|
+
*
|
|
4
|
+
* Pre-pass over each candidate Claude transcript to estimate event counts
|
|
5
|
+
* + cost + wire bytes. Same projection primitives as the live pipeline
|
|
6
|
+
* (`runImportAnalytics`) but discarding events instead of POSTing.
|
|
7
|
+
*
|
|
8
|
+
* Produces the `ImportSummary` rendered by `commands/import.ts` before
|
|
9
|
+
* the confirm prompt. The estimate is a real walk over file bytes —
|
|
10
|
+
* not a heuristic — so the displayed cost is the exact `cost_usd` users
|
|
11
|
+
* will see in the dashboard after import completes.
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
import { ImportSummary, ImportTarget, ImportTimeRange } from "../types";
|
|
16
|
+
export interface SummaryOpts {
|
|
17
|
+
targets: ImportTarget[];
|
|
18
|
+
timeRange: ImportTimeRange | null;
|
|
19
|
+
concurrency: number;
|
|
20
|
+
force: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function estimateClaudeImport(opts: SummaryOpts): ImportSummary;
|
|
23
|
+
//# sourceMappingURL=summary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../../../src/import/claude/summary.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAUH,OAAO,EAIH,aAAa,EACb,YAAY,EACZ,eAAe,EAClB,MAAM,UAAU,CAAC;AAOlB,MAAM,WAAW,WAAW;IACxB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,GAAG,aAAa,CAgErE"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* IronBee CLI — Claude Import Dry-Run Summary Estimator
|
|
4
|
+
*
|
|
5
|
+
* Pre-pass over each candidate Claude transcript to estimate event counts
|
|
6
|
+
* + cost + wire bytes. Same projection primitives as the live pipeline
|
|
7
|
+
* (`runImportAnalytics`) but discarding events instead of POSTing.
|
|
8
|
+
*
|
|
9
|
+
* Produces the `ImportSummary` rendered by `commands/import.ts` before
|
|
10
|
+
* the confirm prompt. The estimate is a real walk over file bytes —
|
|
11
|
+
* not a heuristic — so the displayed cost is the exact `cost_usd` users
|
|
12
|
+
* will see in the dashboard after import completes.
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.estimateClaudeImport = estimateClaudeImport;
|
|
18
|
+
const fs_1 = require("fs");
|
|
19
|
+
const buffer_1 = require("buffer");
|
|
20
|
+
const logger_1 = require("../../lib/logger");
|
|
21
|
+
const collector_1 = require("../../lib/collector");
|
|
22
|
+
const config_1 = require("../../lib/config");
|
|
23
|
+
const transcript_1 = require("../../analytics/transcript");
|
|
24
|
+
const analytics_runner_1 = require("./analytics-runner");
|
|
25
|
+
const skip_1 = require("../skip");
|
|
26
|
+
const types_1 = require("../types");
|
|
27
|
+
const transcript_walk_1 = require("./transcript-walk");
|
|
28
|
+
function estimateClaudeImport(opts) {
|
|
29
|
+
const counts = (0, types_1.emptyEventCounts)();
|
|
30
|
+
let costUsdSum = 0;
|
|
31
|
+
let wireBytesSum = 0;
|
|
32
|
+
let toImport = 0;
|
|
33
|
+
let skipped = 0;
|
|
34
|
+
const perProject = new Map();
|
|
35
|
+
for (const target of opts.targets) {
|
|
36
|
+
const key = target.projectDir;
|
|
37
|
+
let row = perProject.get(key);
|
|
38
|
+
if (row === undefined) {
|
|
39
|
+
row = { projectDir: key, found: 0, skipped: 0, toImport: 0 };
|
|
40
|
+
perProject.set(key, row);
|
|
41
|
+
}
|
|
42
|
+
row.found += 1;
|
|
43
|
+
if ((0, skip_1.shouldSkip)(target.projectDir, target.sessionId, opts.force)) {
|
|
44
|
+
row.skipped += 1;
|
|
45
|
+
skipped += 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
row.toImport += 1;
|
|
49
|
+
toImport += 1;
|
|
50
|
+
try {
|
|
51
|
+
// Per-target gate: import emits analytics events only when the
|
|
52
|
+
// target project's `analytics` config is enabled (presence + not
|
|
53
|
+
// explicitly disabled). Mirrors live mode's master-switch
|
|
54
|
+
// semantic; --skip-analytics CLI flag is intentionally NOT a thing.
|
|
55
|
+
const analyticsEnabled = (0, config_1.isAnalyticsEnabled)(target.projectDir);
|
|
56
|
+
const perSession = estimateOne(target, !analyticsEnabled);
|
|
57
|
+
counts.session_start += perSession.counts.session_start;
|
|
58
|
+
counts.session_end += perSession.counts.session_end;
|
|
59
|
+
counts.activity_start += perSession.counts.activity_start;
|
|
60
|
+
counts.activity_end += perSession.counts.activity_end;
|
|
61
|
+
counts.tool_call += perSession.counts.tool_call;
|
|
62
|
+
counts.file_change += perSession.counts.file_change;
|
|
63
|
+
counts.session_analytics += perSession.counts.session_analytics;
|
|
64
|
+
counts.session_turn_analytics += perSession.counts.session_turn_analytics;
|
|
65
|
+
counts.session_turn_step_analytics += perSession.counts.session_turn_step_analytics;
|
|
66
|
+
counts.api_request += perSession.counts.api_request;
|
|
67
|
+
costUsdSum += perSession.costUsd;
|
|
68
|
+
wireBytesSum += perSession.wireBytes;
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
logger_1.logger.debug(`import summary: estimate failed for session ${target.sessionId}: ${e instanceof Error ? e.message : e}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const collectorTarget = opts.targets.length > 0
|
|
75
|
+
? (0, collector_1.getCollectorTarget)(opts.targets[0].projectDir)
|
|
76
|
+
: null;
|
|
77
|
+
return {
|
|
78
|
+
projects: Array.from(perProject.values()),
|
|
79
|
+
timeRange: opts.timeRange,
|
|
80
|
+
toImportCount: toImport,
|
|
81
|
+
skippedCount: skipped,
|
|
82
|
+
estimatedEvents: counts,
|
|
83
|
+
estimatedCostUsd: costUsdSum,
|
|
84
|
+
estimatedWireBytes: wireBytesSum,
|
|
85
|
+
concurrency: opts.concurrency,
|
|
86
|
+
collectorUrl: collectorTarget !== null ? collectorTarget.url : null,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function estimateOne(target, skipAnalytics) {
|
|
90
|
+
const counts = (0, types_1.emptyEventCounts)();
|
|
91
|
+
counts.session_start = 1;
|
|
92
|
+
counts.session_end = 1;
|
|
93
|
+
const analytics = (0, analytics_runner_1.runImportAnalytics)({
|
|
94
|
+
sessionId: target.sessionId,
|
|
95
|
+
projectName: target.projectName,
|
|
96
|
+
projectDir: target.projectDir,
|
|
97
|
+
transcriptPath: target.transcriptPath,
|
|
98
|
+
});
|
|
99
|
+
if (!skipAnalytics) {
|
|
100
|
+
counts.session_analytics = 1;
|
|
101
|
+
counts.session_turn_analytics = analytics.turnEvents.length;
|
|
102
|
+
counts.session_turn_step_analytics = analytics.stepEvents.length;
|
|
103
|
+
counts.api_request = analytics.apiRequestEvents.length;
|
|
104
|
+
}
|
|
105
|
+
const fileBytes = (0, fs_1.readFileSync)(target.transcriptPath);
|
|
106
|
+
const parsed = (0, transcript_1.parseJsonl)(fileBytes, 0);
|
|
107
|
+
const lines = parsed.lines
|
|
108
|
+
.filter((ln) => ln.parsed !== null)
|
|
109
|
+
.map((ln) => ln.parsed);
|
|
110
|
+
const activityCount = analytics.turnEvents.length > 0
|
|
111
|
+
? analytics.turnEvents.filter((te) => te.turn.triggered_by === "user_msg").length
|
|
112
|
+
: countNonHostInjectTurnsFromTranscript(lines);
|
|
113
|
+
counts.activity_start = activityCount;
|
|
114
|
+
counts.activity_end = activityCount;
|
|
115
|
+
const config = (0, config_1.loadConfig)(target.projectDir);
|
|
116
|
+
let toolCalls = 0;
|
|
117
|
+
let fileChanges = 0;
|
|
118
|
+
for (const line of lines) {
|
|
119
|
+
if (line.type !== "assistant") {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const toolUses = (0, transcript_walk_1.extractToolUsesFromLine)(line);
|
|
123
|
+
toolCalls += toolUses.length;
|
|
124
|
+
for (const tu of toolUses) {
|
|
125
|
+
if (tu.name === "Write" || tu.name === "Edit") {
|
|
126
|
+
const filePath = tu.input.file_path;
|
|
127
|
+
if (typeof filePath === "string" && (0, config_1.requiresVerification)(filePath, config)) {
|
|
128
|
+
fileChanges += 1;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
counts.tool_call = toolCalls;
|
|
134
|
+
counts.file_change = fileChanges;
|
|
135
|
+
// cost_usd is shown to the operator regardless of skipAnalytics — it's
|
|
136
|
+
// useful "what the agent actually cost" info even when the session_analytics
|
|
137
|
+
// event itself isn't shipping. Set to 0 when skipped to avoid implying
|
|
138
|
+
// we'll surface it in the dashboard.
|
|
139
|
+
const costUsd = skipAnalytics ? 0 : analytics.sessionAnalytics.analytics.usage.cost_usd;
|
|
140
|
+
const analyticsWireBytes = skipAnalytics
|
|
141
|
+
? 0
|
|
142
|
+
: buffer_1.Buffer.byteLength(JSON.stringify(analytics.sessionAnalytics), "utf-8")
|
|
143
|
+
+ analytics.turnEvents.reduce((acc, te) => acc + buffer_1.Buffer.byteLength(JSON.stringify(te), "utf-8"), 0)
|
|
144
|
+
+ analytics.stepEvents.reduce((acc, se) => acc + buffer_1.Buffer.byteLength(JSON.stringify(se), "utf-8"), 0)
|
|
145
|
+
+ analytics.apiRequestEvents.reduce((acc, are) => acc + buffer_1.Buffer.byteLength(JSON.stringify(are), "utf-8"), 0);
|
|
146
|
+
const ESTIMATED_NON_ANALYTICS_EVENT_BYTES = 256;
|
|
147
|
+
const nonAnalyticsCount = counts.session_start + counts.session_end
|
|
148
|
+
+ counts.activity_start + counts.activity_end
|
|
149
|
+
+ counts.tool_call + counts.file_change;
|
|
150
|
+
const wireBytes = analyticsWireBytes + nonAnalyticsCount * ESTIMATED_NON_ANALYTICS_EVENT_BYTES;
|
|
151
|
+
return { counts, costUsd, wireBytes };
|
|
152
|
+
}
|
|
153
|
+
function countNonHostInjectTurnsFromTranscript(lines) {
|
|
154
|
+
let count = 0;
|
|
155
|
+
let opened = false;
|
|
156
|
+
let openHasAssistant = false;
|
|
157
|
+
let openIsHostInject = false;
|
|
158
|
+
const close = () => {
|
|
159
|
+
if (opened && !openIsHostInject) {
|
|
160
|
+
count += 1;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
for (const line of lines) {
|
|
164
|
+
if (line.type === "user") {
|
|
165
|
+
const isMeta = line.isMeta === true;
|
|
166
|
+
if (!(0, transcript_walk_1.isHumanTextUserLine)(line)) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (isMeta && opened && openHasAssistant) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
close();
|
|
173
|
+
opened = true;
|
|
174
|
+
openHasAssistant = false;
|
|
175
|
+
openIsHostInject = isMeta;
|
|
176
|
+
}
|
|
177
|
+
else if (line.type === "assistant") {
|
|
178
|
+
if (opened) {
|
|
179
|
+
openHasAssistant = true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
close();
|
|
184
|
+
return count;
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=summary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summary.js","sourceRoot":"","sources":["../../../src/import/claude/summary.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AA+BH,oDAgEC;AA7FD,2BAAkC;AAClC,mCAAgC;AAChC,6CAA0C;AAC1C,mDAA0E;AAC1E,6CAAuG;AACvG,2DAAoF;AACpF,yDAA+E;AAC/E,kCAAqC;AACrC,oCAOkB;AAClB,uDAG2B;AAU3B,SAAgB,oBAAoB,CAAC,IAAiB;IAClD,MAAM,MAAM,GAAsB,IAAA,wBAAgB,GAAE,CAAC;IACrD,IAAI,UAAU,GAAW,CAAC,CAAC;IAC3B,IAAI,YAAY,GAAW,CAAC,CAAC;IAC7B,IAAI,QAAQ,GAAW,CAAC,CAAC;IACzB,IAAI,OAAO,GAAW,CAAC,CAAC;IACxB,MAAM,UAAU,GAAsC,IAAI,GAAG,EAAgC,CAAC;IAE9F,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAChC,MAAM,GAA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,IAAI,gBAAgB,GAAY,KAAK,CAAC;IACtC,IAAI,gBAAgB,GAAY,KAAK,CAAC;IACtC,MAAM,KAAK,GAAe,GAAS,EAAE;QACjC,IAAI,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC9B,KAAK,IAAI,CAAC,CAAC;QACf,CAAC;IACL,CAAC,CAAC;IACF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACvB,MAAM,MAAM,GAAa,IAA6B,CAAC,MAAM,KAAK,IAAI,CAAC;YACvE,IAAI,CAAC,IAAA,qCAAmB,EAAC,IAAI,CAAC,EAAE,CAAC;gBAC7B,SAAS;YACb,CAAC;YACD,IAAI,MAAM,IAAI,MAAM,IAAI,gBAAgB,EAAE,CAAC;gBACvC,SAAS;YACb,CAAC;YACD,KAAK,EAAE,CAAC;YACR,MAAM,GAAG,IAAI,CAAC;YACd,gBAAgB,GAAG,KAAK,CAAC;YACzB,gBAAgB,GAAG,MAAM,CAAC;QAC9B,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACnC,IAAI,MAAM,EAAE,CAAC;gBACT,gBAAgB,GAAG,IAAI,CAAC;YAC5B,CAAC;QACL,CAAC;IACL,CAAC;IACD,KAAK,EAAE,CAAC;IACR,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IronBee CLI — Claude Transcript Walker Helpers
|
|
3
|
+
*
|
|
4
|
+
* Shared between `claude/runner.ts` (pipeline) and `claude/summary.ts`
|
|
5
|
+
* (dry-run estimator). Pure helpers — no I/O, no config — that operate
|
|
6
|
+
* on parsed Claude transcript lines.
|
|
7
|
+
*
|
|
8
|
+
* Claude transcript shape: each `.jsonl` line is a `TranscriptLine` with
|
|
9
|
+
* `type` ∈ {`user`, `assistant`, `system`, `summary`}. Tool calls live in
|
|
10
|
+
* assistant `message.content[]` as `tool_use` blocks; tool_results live
|
|
11
|
+
* in the next user `message.content[]` as `tool_result` blocks (joined by
|
|
12
|
+
* `tool_use_id`).
|
|
13
|
+
*/
|
|
14
|
+
import { TranscriptLine } from "../../analytics/transcript";
|
|
15
|
+
import { RawToolUse, RawToolResult } from "./events/tool-call";
|
|
16
|
+
/**
|
|
17
|
+
* `true` iff the user line carries human-typed text (not a tool_result-only
|
|
18
|
+
* synthesized user line). Mirrors `src/analytics/projection.ts:isHumanTextUser`
|
|
19
|
+
* but typed against `TranscriptLine` — equivalent semantics.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isHumanTextUserLine(line: TranscriptLine): boolean;
|
|
22
|
+
/** Extract every `tool_use` block from an assistant line's `message.content[]`. */
|
|
23
|
+
export declare function extractToolUsesFromLine(assistantLine: TranscriptLine): RawToolUse[];
|
|
24
|
+
/** Map `tool_use_id` → `tool_result` from a user line's `message.content[]`. */
|
|
25
|
+
export declare function extractToolResultsByToolUseId(userLine: TranscriptLine): Map<string, RawToolResult>;
|
|
26
|
+
/** Find the next user line after `afterIdx`, or undefined. */
|
|
27
|
+
export declare function findNextUserLine(lines: TranscriptLine[], afterIdx: number): TranscriptLine | undefined;
|
|
28
|
+
/** Read the optional `summary` line at the tail; returns its `endReason` field. */
|
|
29
|
+
export declare function readSummaryEndReason(lines: TranscriptLine[]): string | null;
|
|
30
|
+
export interface TurnDescriptor {
|
|
31
|
+
turnIndex: number;
|
|
32
|
+
startTime: string;
|
|
33
|
+
endTime: string;
|
|
34
|
+
triggeredBy: "user_msg" | "host_inject";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Walk transcript lines and produce per-turn descriptors. Used as a
|
|
38
|
+
* fallback when `analytics.emitTurnEvents=false` suppresses analytics-runner's
|
|
39
|
+
* `turnEvents` array (we still need turn metadata for activity_*).
|
|
40
|
+
*
|
|
41
|
+
* Mirrors analytics' projection-side turn-open logic:
|
|
42
|
+
* - `isMeta=true` user msg with no open turn → host_inject opener
|
|
43
|
+
* - `isMeta=true` user msg with an open turn that has assistants → continuation
|
|
44
|
+
* - human-text user msg without isMeta → new user_msg turn
|
|
45
|
+
*/
|
|
46
|
+
export declare function deriveTurnBoundariesFromTranscript(lines: TranscriptLine[]): TurnDescriptor[];
|
|
47
|
+
/** Build a fast turn lookup: assistant line timestamp → owning turn_index. */
|
|
48
|
+
export interface TurnLookup {
|
|
49
|
+
lookup: (timestamp: string) => number | null;
|
|
50
|
+
}
|
|
51
|
+
export declare function buildTurnLookup(boundaries: TurnDescriptor[]): TurnLookup;
|
|
52
|
+
//# sourceMappingURL=transcript-walk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript-walk.d.ts","sourceRoot":"","sources":["../../../src/import/claude/transcript-walk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE/D;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAsBjE;AAED,mFAAmF;AACnF,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,cAAc,GAAG,UAAU,EAAE,CAmBnF;AAED,gFAAgF;AAChF,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,cAAc,GAAG,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAmBlG;AAED,8DAA8D;AAC9D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAOtG;AAED,mFAAmF;AACnF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,MAAM,GAAG,IAAI,CAY3E;AAED,MAAM,WAAW,cAAc;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,UAAU,GAAG,aAAa,CAAC;CAC3C;AAED;;;;;;;;;GASG;AACH,wBAAgB,kCAAkC,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAqC5F;AAED,8EAA8E;AAC9E,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CAChD;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,cAAc,EAAE,GAAG,UAAU,CAsBxE"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* IronBee CLI — Claude Transcript Walker Helpers
|
|
4
|
+
*
|
|
5
|
+
* Shared between `claude/runner.ts` (pipeline) and `claude/summary.ts`
|
|
6
|
+
* (dry-run estimator). Pure helpers — no I/O, no config — that operate
|
|
7
|
+
* on parsed Claude transcript lines.
|
|
8
|
+
*
|
|
9
|
+
* Claude transcript shape: each `.jsonl` line is a `TranscriptLine` with
|
|
10
|
+
* `type` ∈ {`user`, `assistant`, `system`, `summary`}. Tool calls live in
|
|
11
|
+
* assistant `message.content[]` as `tool_use` blocks; tool_results live
|
|
12
|
+
* in the next user `message.content[]` as `tool_result` blocks (joined by
|
|
13
|
+
* `tool_use_id`).
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.isHumanTextUserLine = isHumanTextUserLine;
|
|
17
|
+
exports.extractToolUsesFromLine = extractToolUsesFromLine;
|
|
18
|
+
exports.extractToolResultsByToolUseId = extractToolResultsByToolUseId;
|
|
19
|
+
exports.findNextUserLine = findNextUserLine;
|
|
20
|
+
exports.readSummaryEndReason = readSummaryEndReason;
|
|
21
|
+
exports.deriveTurnBoundariesFromTranscript = deriveTurnBoundariesFromTranscript;
|
|
22
|
+
exports.buildTurnLookup = buildTurnLookup;
|
|
23
|
+
/**
|
|
24
|
+
* `true` iff the user line carries human-typed text (not a tool_result-only
|
|
25
|
+
* synthesized user line). Mirrors `src/analytics/projection.ts:isHumanTextUser`
|
|
26
|
+
* but typed against `TranscriptLine` — equivalent semantics.
|
|
27
|
+
*/
|
|
28
|
+
function isHumanTextUserLine(line) {
|
|
29
|
+
if (line.type !== "user" || line.message === undefined) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const content = line.message.content;
|
|
33
|
+
if (typeof content === "string") {
|
|
34
|
+
return content.length > 0;
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(content)) {
|
|
37
|
+
for (const block of content) {
|
|
38
|
+
if (block !== null && typeof block === "object") {
|
|
39
|
+
const t = block.type;
|
|
40
|
+
if (t === "text" && typeof block.text === "string") {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (t === "tool_result") {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
/** Extract every `tool_use` block from an assistant line's `message.content[]`. */
|
|
52
|
+
function extractToolUsesFromLine(assistantLine) {
|
|
53
|
+
const content = assistantLine.message?.content;
|
|
54
|
+
if (!Array.isArray(content)) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
const out = [];
|
|
58
|
+
for (const block of content) {
|
|
59
|
+
if (block !== null && typeof block === "object") {
|
|
60
|
+
const b = block;
|
|
61
|
+
if (b.type === "tool_use" && typeof b.id === "string" && typeof b.name === "string") {
|
|
62
|
+
out.push({
|
|
63
|
+
id: b.id,
|
|
64
|
+
name: b.name,
|
|
65
|
+
input: (b.input !== null && typeof b.input === "object") ? b.input : {},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
/** Map `tool_use_id` → `tool_result` from a user line's `message.content[]`. */
|
|
73
|
+
function extractToolResultsByToolUseId(userLine) {
|
|
74
|
+
const out = new Map();
|
|
75
|
+
const content = userLine.message?.content;
|
|
76
|
+
if (!Array.isArray(content)) {
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
for (const block of content) {
|
|
80
|
+
if (block !== null && typeof block === "object") {
|
|
81
|
+
const b = block;
|
|
82
|
+
if (b.type === "tool_result" && typeof b.tool_use_id === "string") {
|
|
83
|
+
out.set(b.tool_use_id, {
|
|
84
|
+
tool_use_id: b.tool_use_id,
|
|
85
|
+
is_error: b.is_error === true,
|
|
86
|
+
content: b.content,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
/** Find the next user line after `afterIdx`, or undefined. */
|
|
94
|
+
function findNextUserLine(lines, afterIdx) {
|
|
95
|
+
for (let i = afterIdx + 1; i < lines.length; i++) {
|
|
96
|
+
if (lines[i].type === "user") {
|
|
97
|
+
return lines[i];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
/** Read the optional `summary` line at the tail; returns its `endReason` field. */
|
|
103
|
+
function readSummaryEndReason(lines) {
|
|
104
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
105
|
+
const ln = lines[i];
|
|
106
|
+
if (ln.type === "summary") {
|
|
107
|
+
const reason = ln.endReason;
|
|
108
|
+
if (typeof reason === "string" && reason.length > 0) {
|
|
109
|
+
return reason;
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Walk transcript lines and produce per-turn descriptors. Used as a
|
|
118
|
+
* fallback when `analytics.emitTurnEvents=false` suppresses analytics-runner's
|
|
119
|
+
* `turnEvents` array (we still need turn metadata for activity_*).
|
|
120
|
+
*
|
|
121
|
+
* Mirrors analytics' projection-side turn-open logic:
|
|
122
|
+
* - `isMeta=true` user msg with no open turn → host_inject opener
|
|
123
|
+
* - `isMeta=true` user msg with an open turn that has assistants → continuation
|
|
124
|
+
* - human-text user msg without isMeta → new user_msg turn
|
|
125
|
+
*/
|
|
126
|
+
function deriveTurnBoundariesFromTranscript(lines) {
|
|
127
|
+
const out = [];
|
|
128
|
+
let current = null;
|
|
129
|
+
let nextIdx = 1;
|
|
130
|
+
for (const line of lines) {
|
|
131
|
+
const ts = line.timestamp ?? "";
|
|
132
|
+
if (line.type === "user") {
|
|
133
|
+
const isMeta = line.isMeta === true;
|
|
134
|
+
if (!isHumanTextUserLine(line)) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (isMeta && current !== null && current.assistantSeen) {
|
|
138
|
+
current.end = ts;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (current !== null) {
|
|
142
|
+
out.push({ turnIndex: current.idx, startTime: current.start, endTime: current.end, triggeredBy: current.triggered });
|
|
143
|
+
}
|
|
144
|
+
current = {
|
|
145
|
+
idx: nextIdx,
|
|
146
|
+
start: ts,
|
|
147
|
+
end: ts,
|
|
148
|
+
triggered: isMeta ? "host_inject" : "user_msg",
|
|
149
|
+
assistantSeen: false,
|
|
150
|
+
};
|
|
151
|
+
nextIdx += 1;
|
|
152
|
+
}
|
|
153
|
+
else if (line.type === "assistant") {
|
|
154
|
+
if (current !== null) {
|
|
155
|
+
current.assistantSeen = true;
|
|
156
|
+
current.end = ts;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (current !== null) {
|
|
161
|
+
out.push({ turnIndex: current.idx, startTime: current.start, endTime: current.end, triggeredBy: current.triggered });
|
|
162
|
+
}
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
function buildTurnLookup(boundaries) {
|
|
166
|
+
const sorted = [...boundaries].sort((a, b) => Date.parse(a.startTime) - Date.parse(b.startTime));
|
|
167
|
+
return {
|
|
168
|
+
lookup: (timestamp) => {
|
|
169
|
+
const ts = Date.parse(timestamp);
|
|
170
|
+
if (!Number.isFinite(ts)) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
let chosen = null;
|
|
174
|
+
for (const b of sorted) {
|
|
175
|
+
const startMs = Date.parse(b.startTime);
|
|
176
|
+
if (startMs <= ts) {
|
|
177
|
+
chosen = b;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return chosen !== null ? chosen.turnIndex : null;
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=transcript-walk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript-walk.js","sourceRoot":"","sources":["../../../src/import/claude/transcript-walk.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAUH,kDAsBC;AAGD,0DAmBC;AAGD,sEAmBC;AAGD,4CAOC;AAGD,oDAYC;AAmBD,gFAqCC;AAOD,0CAsBC;AArLD;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,IAAoB;IACpD,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACrD,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,MAAM,OAAO,GAAa,IAAI,CAAC,OAAiC,CAAC,OAAO,CAAC;IACzE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9B,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,KAAK,MAAM,KAAK,IAAI,OAAoB,EAAE,CAAC;YACvC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAA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AC,EAAE,CAAC,EAAE,CAAC;gBACvB,OAAO,IAAI,CAAC;YAChB,CAAC;YACD,IAAI,MAAM,GAA0B,IAAI,CAAC;YACzC,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;gBACrB,MAAM,OAAO,GAAW,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;gBAChD,IAAI,OAAO,IAAI,EAAE,EAAE,CAAC;oBAChB,MAAM,GAAG,CAAC,CAAC;gBACf,CAAC;qBAAM,CAAC;oBACJ,MAAM;gBACV,CAAC;YACL,CAAC;YACD,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;QACrD,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IronBee CLI — Generic Bounded-Concurrency Pool
|
|
3
|
+
*
|
|
4
|
+
* Used by `commands/import.ts` to drive per-session imports in parallel
|
|
5
|
+
* with a fixed concurrency cap. Pure logic — no client-specific code, no
|
|
6
|
+
* CLI dependencies — so the pool's runtime behavior (slot refill, cancel
|
|
7
|
+
* signal, completion ordering) can be unit-tested in isolation.
|
|
8
|
+
*
|
|
9
|
+
* Per-item failures are the caller's responsibility: `process` is expected
|
|
10
|
+
* to absorb its own errors and return a result envelope. If `process`
|
|
11
|
+
* throws, the pool finishes its in-flight items and then re-throws the
|
|
12
|
+
* FIRST captured error — guarantees no swallowed rejections + no torn
|
|
13
|
+
* intermediate state.
|
|
14
|
+
*/
|
|
15
|
+
export interface ConcurrentPoolOpts<T, R> {
|
|
16
|
+
/** Items to process (one `process(item)` call each). */
|
|
17
|
+
items: T[];
|
|
18
|
+
/** Maximum number of `process` invocations in flight at once. */
|
|
19
|
+
concurrency: number;
|
|
20
|
+
/** Per-item worker. Called with the item and a 1-based index. */
|
|
21
|
+
process: (item: T, oneBasedIndex: number) => Promise<R>;
|
|
22
|
+
/** Optional pre-`process` hook (e.g. for progress reporting). */
|
|
23
|
+
onStart?: (item: T, oneBasedIndex: number) => void;
|
|
24
|
+
/** Optional post-`process` hook (e.g. for progress reporting). */
|
|
25
|
+
onComplete?: (result: R, item: T, oneBasedIndex: number) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Optional cancellation signal. When the function returns `true`, no
|
|
28
|
+
* NEW items are started; in-flight items continue to completion. The
|
|
29
|
+
* pool resolves once every in-flight item finishes.
|
|
30
|
+
*/
|
|
31
|
+
shouldCancel?: () => boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Run a bounded-concurrency pool over `items`. Returns results in
|
|
35
|
+
* **completion order** (not input order — fastest items finish first).
|
|
36
|
+
*
|
|
37
|
+
* If any `process` invocation throws, the pool waits for the remaining
|
|
38
|
+
* in-flight items to settle, then re-throws the first captured error.
|
|
39
|
+
* Successful results from earlier items are discarded — callers wanting
|
|
40
|
+
* partial-result-on-error must absorb errors inside `process` and return
|
|
41
|
+
* a typed envelope (this is what `commands/import.ts` does — `importSession`
|
|
42
|
+
* itself returns `ImportResult` with `status: "failed"`).
|
|
43
|
+
*/
|
|
44
|
+
export declare function runConcurrentPool<T, R>(opts: ConcurrentPoolOpts<T, R>): Promise<R[]>;
|
|
45
|
+
//# sourceMappingURL=concurrent-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concurrent-pool.d.ts","sourceRoot":"","sources":["../../src/import/concurrent-pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,kBAAkB,CAAC,CAAC,EAAE,CAAC;IACpC,wDAAwD;IACxD,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,iEAAiE;IACjE,WAAW,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IACxD,iEAAiE;IACjE,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,kEAAkE;IAClE,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;IACjE;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC;CAChC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAsE1F"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* IronBee CLI — Generic Bounded-Concurrency Pool
|
|
4
|
+
*
|
|
5
|
+
* Used by `commands/import.ts` to drive per-session imports in parallel
|
|
6
|
+
* with a fixed concurrency cap. Pure logic — no client-specific code, no
|
|
7
|
+
* CLI dependencies — so the pool's runtime behavior (slot refill, cancel
|
|
8
|
+
* signal, completion ordering) can be unit-tested in isolation.
|
|
9
|
+
*
|
|
10
|
+
* Per-item failures are the caller's responsibility: `process` is expected
|
|
11
|
+
* to absorb its own errors and return a result envelope. If `process`
|
|
12
|
+
* throws, the pool finishes its in-flight items and then re-throws the
|
|
13
|
+
* FIRST captured error — guarantees no swallowed rejections + no torn
|
|
14
|
+
* intermediate state.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.runConcurrentPool = runConcurrentPool;
|
|
18
|
+
/**
|
|
19
|
+
* Run a bounded-concurrency pool over `items`. Returns results in
|
|
20
|
+
* **completion order** (not input order — fastest items finish first).
|
|
21
|
+
*
|
|
22
|
+
* If any `process` invocation throws, the pool waits for the remaining
|
|
23
|
+
* in-flight items to settle, then re-throws the first captured error.
|
|
24
|
+
* Successful results from earlier items are discarded — callers wanting
|
|
25
|
+
* partial-result-on-error must absorb errors inside `process` and return
|
|
26
|
+
* a typed envelope (this is what `commands/import.ts` does — `importSession`
|
|
27
|
+
* itself returns `ImportResult` with `status: "failed"`).
|
|
28
|
+
*/
|
|
29
|
+
async function runConcurrentPool(opts) {
|
|
30
|
+
const concurrency = Math.max(1, opts.concurrency);
|
|
31
|
+
const results = [];
|
|
32
|
+
let cursor = 0;
|
|
33
|
+
let firstError = null;
|
|
34
|
+
const inflight = new Set();
|
|
35
|
+
const startNext = () => {
|
|
36
|
+
if (firstError !== null) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (opts.shouldCancel !== undefined && opts.shouldCancel()) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (cursor >= opts.items.length) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (inflight.size >= concurrency) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const idx = cursor;
|
|
49
|
+
const oneBasedIndex = idx + 1;
|
|
50
|
+
const item = opts.items[idx];
|
|
51
|
+
cursor += 1;
|
|
52
|
+
if (opts.onStart !== undefined) {
|
|
53
|
+
opts.onStart(item, oneBasedIndex);
|
|
54
|
+
}
|
|
55
|
+
// The `p` ref is needed inside `.finally()` to remove itself from
|
|
56
|
+
// `inflight`. Declared as `let` then assigned because the assignment
|
|
57
|
+
// expression is the value being added to the Set — TS narrows safer
|
|
58
|
+
// when we capture the binding by name.
|
|
59
|
+
let p;
|
|
60
|
+
p = opts.process(item, oneBasedIndex)
|
|
61
|
+
.then((r) => {
|
|
62
|
+
results.push(r);
|
|
63
|
+
if (opts.onComplete !== undefined) {
|
|
64
|
+
opts.onComplete(r, item, oneBasedIndex);
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
.catch((e) => {
|
|
68
|
+
if (firstError === null) {
|
|
69
|
+
firstError = e instanceof Error ? e : new Error(String(e));
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
.finally(() => {
|
|
73
|
+
inflight.delete(p);
|
|
74
|
+
});
|
|
75
|
+
inflight.add(p);
|
|
76
|
+
return true;
|
|
77
|
+
};
|
|
78
|
+
// Prime the pool — startNext caps itself at `concurrency` so this just
|
|
79
|
+
// adds until the pool is full or items are exhausted.
|
|
80
|
+
while (startNext()) {
|
|
81
|
+
/* fill priming slots */
|
|
82
|
+
}
|
|
83
|
+
// Drain. After each completion, refill any freed slot up to `concurrency`.
|
|
84
|
+
while (inflight.size > 0) {
|
|
85
|
+
await Promise.race(inflight);
|
|
86
|
+
while (startNext()) {
|
|
87
|
+
/* fill freed slots */
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (firstError !== null) {
|
|
91
|
+
throw firstError;
|
|
92
|
+
}
|
|
93
|
+
return results;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=concurrent-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concurrent-pool.js","sourceRoot":"","sources":["../../src/import/concurrent-pool.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AAgCH,8CAsEC;AAjFD;;;;;;;;;;GAUG;AACI,KAAK,UAAU,iBAAiB,CAAO,IAA8B;IACxE,MAAM,WAAW,GAAW,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAQ,EAAE,CAAC;IACxB,IAAI,MAAM,GAAW,CAAC,CAAC;IACvB,IAAI,UAAU,GAAiB,IAAI,CAAC;IACpC,MAAM,QAAQ,GAAuB,IAAI,GAAG,EAAiB,CAAC;IAE9D,MAAM,SAAS,GAAkB,GAAY,EAAE;QAC3C,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACtB,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,IAAI,IAAI,CAAC,YAAY,KAAK,SA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