@ascenda-one/claude-code-hooks 0.1.27 → 0.1.28
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/README.md +98 -11
- package/dist/ascendaClient.js +5 -0
- package/dist/ascendaClient.js.map +1 -1
- package/dist/cli.js +642 -246
- package/dist/cli.js.map +1 -1
- package/dist/config.js +34 -1
- package/dist/config.js.map +1 -1
- package/dist/mapClaudeEvent.js +46 -2
- package/dist/mapClaudeEvent.js.map +1 -1
- package/dist/paths.js +20 -1
- package/dist/paths.js.map +1 -1
- package/dist/setup.js +176 -37
- package/dist/setup.js.map +1 -1
- package/dist/types.js +11 -1
- package/dist/types.js.map +1 -1
- package/examples/settings.local.json +10 -9
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -414,39 +414,44 @@ var require_metricKeys = __commonJS({
|
|
|
414
414
|
exports.METRIC_KEYS = {
|
|
415
415
|
// ── Read by a backend reader ────────────────────────────────────────────
|
|
416
416
|
contextWindowPeakPct: {
|
|
417
|
+
family: "context",
|
|
417
418
|
readBy: ["backend", "handoff"],
|
|
418
419
|
backendAliases: CONTEXT_WINDOW_CANONICAL_ALIASES,
|
|
419
420
|
unit: "fraction of the context window (0\u20131; uncapped for >200k contexts)",
|
|
420
421
|
note: "Claude Code reports a true per-session peak. Cursor reports its composer's last known occupancy under the same key \u2014 the closest its store can answer, and not the same measurement."
|
|
421
422
|
},
|
|
422
423
|
contextUsagePercent: {
|
|
424
|
+
family: "context",
|
|
423
425
|
readBy: ["backend", "handoff"],
|
|
424
426
|
backendAliases: CONTEXT_WINDOW_CURSOR_PERCENT_ALIASES,
|
|
425
427
|
unit: "percent (0\u2013100)",
|
|
426
428
|
note: "Cursor's own column name. Superseded by contextWindowPeakPct on the wire; kept because the handoff reads it and imported rows carry it. Unit-explicit on the backend: always divided by 100, never put through the fraction-or-percent heuristic."
|
|
427
429
|
},
|
|
428
|
-
promptCount: { readBy: ["backend", "handoff"], backendAliases: ["promptCount", "prompt_count"] },
|
|
429
|
-
sessionMinutes: { readBy: ["backend"], backendAliases: ["sessionMinutes", "session_minutes"], unit: "minutes" },
|
|
430
|
-
durationBucket: { readBy: ["backend", "handoff"], backendAliases: ["durationBucket", "duration_bucket"] },
|
|
431
|
-
afterHoursPrompts: { readBy: ["backend", "handoff"], backendAliases: ["afterHoursPrompts", "after_hours_prompts"] },
|
|
432
|
-
inputTokens: { readBy: ["backend"], backendAliases: ["inputTokens", "input_tokens"], unit: "tokens" },
|
|
433
|
-
outputTokens: { readBy: ["backend"], backendAliases: ["outputTokens", "output_tokens"], unit: "tokens" },
|
|
434
|
-
cacheReadTokens: { readBy: ["backend"], backendAliases: ["cacheReadTokens", "cache_read_tokens"], unit: "tokens" },
|
|
435
|
-
queuedPrompts: { readBy: ["backend"], backendAliases: ["queuedPrompts", "queued_prompts"] },
|
|
436
|
-
linesChangedBucket: { readBy: ["backend"], backendAliases: ["linesChangedBucket", "lines_changed_bucket"] },
|
|
430
|
+
promptCount: { family: "counts", readBy: ["backend", "handoff"], backendAliases: ["promptCount", "prompt_count"] },
|
|
431
|
+
sessionMinutes: { family: "session", readBy: ["backend"], backendAliases: ["sessionMinutes", "session_minutes"], unit: "minutes" },
|
|
432
|
+
durationBucket: { family: "session", readBy: ["backend", "handoff"], backendAliases: ["durationBucket", "duration_bucket"] },
|
|
433
|
+
afterHoursPrompts: { family: "clock", readBy: ["backend", "handoff"], backendAliases: ["afterHoursPrompts", "after_hours_prompts"] },
|
|
434
|
+
inputTokens: { family: "context", readBy: ["backend"], backendAliases: ["inputTokens", "input_tokens"], unit: "tokens" },
|
|
435
|
+
outputTokens: { family: "context", readBy: ["backend"], backendAliases: ["outputTokens", "output_tokens"], unit: "tokens" },
|
|
436
|
+
cacheReadTokens: { family: "context", readBy: ["backend"], backendAliases: ["cacheReadTokens", "cache_read_tokens"], unit: "tokens" },
|
|
437
|
+
queuedPrompts: { family: "counts", readBy: ["backend"], backendAliases: ["queuedPrompts", "queued_prompts"] },
|
|
438
|
+
linesChangedBucket: { family: "edits", readBy: ["backend"], backendAliases: ["linesChangedBucket", "lines_changed_bucket"] },
|
|
437
439
|
// ── Read by the local handoff only ──────────────────────────────────────
|
|
438
|
-
activeMinutes: { readBy: ["handoff"], unit: "minutes" },
|
|
440
|
+
activeMinutes: { family: "session", readBy: ["handoff"], unit: "minutes" },
|
|
439
441
|
syntheticPromptLines: {
|
|
442
|
+
family: "reading",
|
|
440
443
|
readBy: ["handoff"],
|
|
441
444
|
unit: "lines",
|
|
442
445
|
note: "Main-thread user lines the runtime wrote on the person's behalf (notifications, its own bookkeeping, slash-command wrappers, interrupt markers) and promptCount left out. Claude Code only; the receipt for the handoff's promptBasis. Counted per transcript, so a resumed transcript's copies count again."
|
|
443
446
|
},
|
|
444
447
|
dispatchedPromptLines: {
|
|
448
|
+
family: "reading",
|
|
445
449
|
readBy: ["handoff"],
|
|
446
450
|
unit: "lines",
|
|
447
451
|
note: "Main-thread user lines that read as typed but are the prompt of a chip that launched the session, so promptCount left them out. Counted once per line across the store, as prompts are. Claude Code only; written beside promptBasis: typed_once."
|
|
448
452
|
},
|
|
449
453
|
interruptedRuns: {
|
|
454
|
+
family: "waiting",
|
|
450
455
|
readBy: ["handoff"],
|
|
451
456
|
unit: "runs",
|
|
452
457
|
note: "Agent turns the person cut short with an interrupt while the turn was still going. A count per session, never a rate. Claude Code only; a handoff that counted them says so with interruptedRunsCounted, and absent means not counted, never zero."
|
|
@@ -462,11 +467,13 @@ var require_metricKeys = __commonJS({
|
|
|
462
467
|
* they are.
|
|
463
468
|
*/
|
|
464
469
|
handsOnMinutes: {
|
|
470
|
+
family: "session",
|
|
465
471
|
readBy: ["handoff"],
|
|
466
472
|
unit: "minutes",
|
|
467
473
|
note: "Active time immediately preceding a human prompt \u2014 the only interval a transcript can show a person present for, because the prompt at its end is the evidence."
|
|
468
474
|
},
|
|
469
475
|
agentSupervisingMinutes: {
|
|
476
|
+
family: "session",
|
|
470
477
|
readBy: ["handoff"],
|
|
471
478
|
unit: "minutes",
|
|
472
479
|
note: "The remaining active time: the agent was working and the person was not typing. NOT a claim that anyone watched it \u2014 nothing in a transcript could show that. Never render as attention."
|
|
@@ -476,127 +483,147 @@ var require_metricKeys = __commonJS({
|
|
|
476
483
|
// a complete one, and a reader that ignores them is choosing to, rather than
|
|
477
484
|
// being unable to.
|
|
478
485
|
activeSplitInstants: {
|
|
486
|
+
family: "session",
|
|
479
487
|
readBy: ["diagnostic"],
|
|
480
488
|
note: "Distinct timestamps the split ran over, after collapsing ties. The denominator: two minutes off four instants and off four hundred are not the same measurement."
|
|
481
489
|
},
|
|
482
490
|
activeSplitUndatedLines: {
|
|
491
|
+
family: "session",
|
|
483
492
|
readBy: ["diagnostic"],
|
|
484
493
|
note: "Known lines carrying a timestamp that would not parse. Absent from the timeline, so both halves are short by an unknown amount and only this says so."
|
|
485
494
|
},
|
|
486
495
|
activeSplitUnposturedInstants: {
|
|
496
|
+
family: "posture",
|
|
487
497
|
readBy: ["diagnostic"],
|
|
488
498
|
note: "Instants reached before any permissionMode had been declared. Their supervising time lands in the unknown band, which is a blind spot rather than a posture."
|
|
489
499
|
},
|
|
490
|
-
afterHoursRequests: { readBy: ["handoff"] },
|
|
491
|
-
approximateLintErrorsCount: { readBy: ["handoff"] },
|
|
492
|
-
canceledCount: { readBy: ["handoff"] },
|
|
493
|
-
chatEditCount: { readBy: ["handoff"] },
|
|
500
|
+
afterHoursRequests: { family: "clock", readBy: ["handoff"] },
|
|
501
|
+
approximateLintErrorsCount: { family: "outcome", readBy: ["handoff"] },
|
|
502
|
+
canceledCount: { family: "outcome", readBy: ["handoff"] },
|
|
503
|
+
chatEditCount: { family: "edits", readBy: ["handoff"] },
|
|
494
504
|
compactionCount: {
|
|
505
|
+
family: "context",
|
|
495
506
|
readBy: ["handoff"],
|
|
496
507
|
note: "The backend counts context_compression_* event rows, not this key. Both are emitted; this one is for the handoff."
|
|
497
508
|
},
|
|
498
509
|
contextWindowPeakTokens: {
|
|
510
|
+
family: "context",
|
|
499
511
|
readBy: ["handoff"],
|
|
500
512
|
unit: "tokens",
|
|
501
513
|
note: "The measured quantity, with no assumed denominator. Prefer this to the ratio for any within-person baseline."
|
|
502
514
|
},
|
|
503
515
|
contextWindowTokens: {
|
|
516
|
+
family: "context",
|
|
504
517
|
readBy: ["handoff"],
|
|
505
518
|
unit: "tokens",
|
|
506
519
|
note: "Codex only: the model_context_window the rollout itself recorded \u2014 the real denominator its contextWindowPeakPct was computed against. Claude Code records no window and its ratio assumes 200k; absent here means the store never said."
|
|
507
520
|
},
|
|
508
|
-
date: { readBy: ["handoff"] },
|
|
509
|
-
errorCount: { readBy: ["handoff"] },
|
|
510
|
-
filesChangedCount: { readBy: ["handoff"] },
|
|
511
|
-
humanChangesCount: { readBy: ["handoff"] },
|
|
512
|
-
linesAdded: { readBy: ["handoff"] },
|
|
513
|
-
linesRemoved: { readBy: ["handoff"] },
|
|
514
|
-
primaryModel: {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
521
|
+
date: { family: "clock", readBy: ["handoff"] },
|
|
522
|
+
errorCount: { family: "outcome", readBy: ["handoff"] },
|
|
523
|
+
filesChangedCount: { family: "edits", readBy: ["handoff"] },
|
|
524
|
+
humanChangesCount: { family: "edits", readBy: ["handoff"] },
|
|
525
|
+
linesAdded: { family: "edits", readBy: ["handoff"] },
|
|
526
|
+
linesRemoved: { family: "edits", readBy: ["handoff"] },
|
|
527
|
+
primaryModel: {
|
|
528
|
+
family: "model",
|
|
529
|
+
readBy: ["backend", "handoff"],
|
|
530
|
+
backendAliases: ["primaryModel", "primary_model"],
|
|
531
|
+
note: "Read twice: the desktop's local handoff folds it, and a server-side reader resolves it to group a bucket's sessions by the model that served them. Declared handoff-only until 23 Sep 2026 \u2014 see toolName for why that direction of mistake has no symptom."
|
|
532
|
+
},
|
|
533
|
+
requestCount: { family: "counts", readBy: ["handoff"] },
|
|
534
|
+
sessionStartedAt: { family: "session", readBy: ["handoff"] },
|
|
535
|
+
subagentComposers: { family: "counts", readBy: ["handoff"] },
|
|
518
536
|
subagentToolCallCount: {
|
|
537
|
+
family: "tools",
|
|
519
538
|
readBy: ["handoff"],
|
|
520
539
|
note: "Claude Code only: calls made inside subagent transcripts, kept out of toolCallCount so the main-loop count matches what the wire events carry."
|
|
521
540
|
},
|
|
522
|
-
subagentTranscripts: { readBy: ["handoff"] },
|
|
541
|
+
subagentTranscripts: { family: "counts", readBy: ["handoff"] },
|
|
523
542
|
toolCallCount: {
|
|
543
|
+
family: "tools",
|
|
524
544
|
readBy: ["handoff"],
|
|
525
545
|
note: "The backend counts ai_tool_call_started event rows, not this key \u2014 same split as compactionCount. Deduplicated on the tool-call id; see each extractor for what one call means in its store."
|
|
526
546
|
},
|
|
527
547
|
toolCallsUndated: {
|
|
548
|
+
family: "tools",
|
|
528
549
|
readBy: ["handoff"],
|
|
529
550
|
note: "Cursor only: calls whose every record carries an empty createdAt. Counted in toolCallCount, but no event exists for them \u2014 the wire total is smaller than this session count by exactly this number."
|
|
530
551
|
},
|
|
531
|
-
toolFailureCount: { readBy: ["handoff"] },
|
|
532
|
-
totalEntryCount: { readBy: ["handoff"] },
|
|
552
|
+
toolFailureCount: { family: "outcome", readBy: ["handoff"] },
|
|
553
|
+
totalEntryCount: { family: "counts", readBy: ["handoff"] },
|
|
533
554
|
userModifiedEditCount: {
|
|
555
|
+
family: "edits",
|
|
534
556
|
readBy: ["handoff"],
|
|
535
557
|
note: "Null, never 0 \u2014 Claude Code never sets userModified true, so 0 would assert 'no AI edit was ever corrected by hand'."
|
|
536
558
|
},
|
|
537
559
|
// ── Diagnostic: read by nobody, on purpose ──────────────────────────────
|
|
538
|
-
abandonedPromptCount: { readBy: ["diagnostic"] },
|
|
560
|
+
abandonedPromptCount: { family: "counts", readBy: ["diagnostic"] },
|
|
539
561
|
// Epoch-marker metrics. The marker is local-only and never reaches the wire
|
|
540
562
|
// (see EXTRACTION_EPOCH_KIND), but it travels as a NormalizedHistoricalEvent
|
|
541
563
|
// and so is keyed by the same vocabulary.
|
|
542
|
-
windowOldest: { readBy: ["handoff"], note: "Oldest event the extraction saw \u2014 the marker's left edge." },
|
|
543
|
-
windowNewest: { readBy: ["handoff"], note: "Newest event the extraction saw \u2014 the marker's right edge." },
|
|
544
|
-
projectsWithNoReadableTranscript: { readBy: ["diagnostic"] },
|
|
545
|
-
unparsedComposerHeaders: { readBy: ["diagnostic"] },
|
|
546
|
-
unknownComposerHeaderTypes: { readBy: ["diagnostic"] },
|
|
547
|
-
orphanedBubbles: { readBy: ["diagnostic"] },
|
|
548
|
-
orphanedSubagentBubbles: { readBy: ["diagnostic"] },
|
|
549
|
-
sessionsWithoutTimeline: { readBy: ["diagnostic"] },
|
|
564
|
+
windowOldest: { family: "session", readBy: ["handoff"], note: "Oldest event the extraction saw \u2014 the marker's left edge." },
|
|
565
|
+
windowNewest: { family: "session", readBy: ["handoff"], note: "Newest event the extraction saw \u2014 the marker's right edge." },
|
|
566
|
+
projectsWithNoReadableTranscript: { family: "reading", readBy: ["diagnostic"] },
|
|
567
|
+
unparsedComposerHeaders: { family: "reading", readBy: ["diagnostic"] },
|
|
568
|
+
unknownComposerHeaderTypes: { family: "reading", readBy: ["diagnostic"] },
|
|
569
|
+
orphanedBubbles: { family: "reading", readBy: ["diagnostic"] },
|
|
570
|
+
orphanedSubagentBubbles: { family: "reading", readBy: ["diagnostic"] },
|
|
571
|
+
sessionsWithoutTimeline: { family: "reading", readBy: ["diagnostic"] },
|
|
550
572
|
sessionsWithOnlyInheritedLines: {
|
|
573
|
+
family: "reading",
|
|
551
574
|
readBy: ["diagnostic"],
|
|
552
575
|
note: "Claude Code transcripts holding nothing but a copy of an ancestor's history, so no line's instant is theirs and no session is emitted for them. Excluded by rule, not a read failure: the work is in the transcript that owns it."
|
|
553
576
|
},
|
|
554
|
-
emptyComposers: { readBy: ["diagnostic"] },
|
|
555
|
-
apiErrorCount: { readBy: ["diagnostic"] },
|
|
556
|
-
assistantTurns: { readBy: ["diagnostic"] },
|
|
557
|
-
compactionAutoCount: { readBy: ["diagnostic"] },
|
|
558
|
-
compactionManualCount: { readBy: ["diagnostic"] },
|
|
559
|
-
editDayCount: { readBy: ["diagnostic"] },
|
|
560
|
-
emptyChatSessions: { readBy: ["diagnostic"] },
|
|
561
|
-
gitBranch: { readBy: ["diagnostic"] },
|
|
562
|
-
linesChanged: { readBy: ["diagnostic"] },
|
|
563
|
-
malformedChatSessionLines: { readBy: ["diagnostic"] },
|
|
564
|
-
malformedHistoryEntries: { readBy: ["diagnostic"] },
|
|
565
|
-
mode: { readBy: ["diagnostic"] },
|
|
566
|
-
modelCount: { readBy: ["diagnostic"] },
|
|
567
|
-
modelSwitchCount: { readBy: ["diagnostic"] },
|
|
568
|
-
rapidRepromptCount: { readBy: ["diagnostic"] },
|
|
569
|
-
schemaUnreadable: { readBy: ["diagnostic"] },
|
|
570
|
-
sessionCount: { readBy: ["diagnostic"] },
|
|
571
|
-
sessionsFromBubbleTimeline: { readBy: ["diagnostic"] },
|
|
572
|
-
sessionsFromCheckpointTimeline: { readBy: ["diagnostic"] },
|
|
573
|
-
sessionsFromRecencyTimeline: { readBy: ["diagnostic"] },
|
|
574
|
-
subagentAssistantTurns: { readBy: ["diagnostic"] },
|
|
575
|
-
subagentPrompts: { readBy: ["diagnostic"] },
|
|
576
|
-
subagentTokensTotal: { readBy: ["diagnostic"] },
|
|
577
|
+
emptyComposers: { family: "reading", readBy: ["diagnostic"] },
|
|
578
|
+
apiErrorCount: { family: "outcome", readBy: ["diagnostic"] },
|
|
579
|
+
assistantTurns: { family: "counts", readBy: ["diagnostic"] },
|
|
580
|
+
compactionAutoCount: { family: "context", readBy: ["diagnostic"] },
|
|
581
|
+
compactionManualCount: { family: "context", readBy: ["diagnostic"] },
|
|
582
|
+
editDayCount: { family: "clock", readBy: ["diagnostic"] },
|
|
583
|
+
emptyChatSessions: { family: "reading", readBy: ["diagnostic"] },
|
|
584
|
+
gitBranch: { family: "repo", readBy: ["diagnostic"] },
|
|
585
|
+
linesChanged: { family: "edits", readBy: ["diagnostic"] },
|
|
586
|
+
malformedChatSessionLines: { family: "reading", readBy: ["diagnostic"] },
|
|
587
|
+
malformedHistoryEntries: { family: "reading", readBy: ["diagnostic"] },
|
|
588
|
+
mode: { family: "posture", readBy: ["diagnostic"] },
|
|
589
|
+
modelCount: { family: "model", readBy: ["diagnostic"] },
|
|
590
|
+
modelSwitchCount: { family: "model", readBy: ["diagnostic"] },
|
|
591
|
+
rapidRepromptCount: { family: "counts", readBy: ["diagnostic"] },
|
|
592
|
+
schemaUnreadable: { family: "reading", readBy: ["diagnostic"] },
|
|
593
|
+
sessionCount: { family: "session", readBy: ["diagnostic"] },
|
|
594
|
+
sessionsFromBubbleTimeline: { family: "reading", readBy: ["diagnostic"] },
|
|
595
|
+
sessionsFromCheckpointTimeline: { family: "reading", readBy: ["diagnostic"] },
|
|
596
|
+
sessionsFromRecencyTimeline: { family: "reading", readBy: ["diagnostic"] },
|
|
597
|
+
subagentAssistantTurns: { family: "counts", readBy: ["diagnostic"] },
|
|
598
|
+
subagentPrompts: { family: "counts", readBy: ["diagnostic"] },
|
|
599
|
+
subagentTokensTotal: { family: "context", readBy: ["diagnostic"] },
|
|
577
600
|
toolName: {
|
|
578
|
-
|
|
579
|
-
|
|
601
|
+
family: "tools",
|
|
602
|
+
readBy: ["backend"],
|
|
603
|
+
backendAliases: ["toolName", "tool_name"],
|
|
604
|
+
note: "Set per ai_tool_call_started event by #43's extractors. Declared diagnostic until 23 Sep 2026 on the belief that nothing resolved it server-side; two backend readers do \u2014 one to see a sub-agent dispatch, one composing per-tool metrics. This is the inverse of the mismatch this module was written for: contextUsagePercent was a key nobody read, and a key a reader resolves without being declared drops nothing, so it has no symptom at all. What it costs is that readBy stops being a true census of what the server sees, which is what you consult when deciding what a collector should stop sending. Registered after the fact in the first place: #38 and #43 merged past each other, and the union caught it on the next compile \u2014 metaLines all over again."
|
|
580
605
|
},
|
|
581
|
-
toolResultCount: { readBy: ["diagnostic"] },
|
|
582
|
-
toolResultErrorCount: { readBy: ["diagnostic"] },
|
|
583
|
-
unknownBubbles: { readBy: ["diagnostic"] },
|
|
584
|
-
unknownLines: { readBy: ["diagnostic"] },
|
|
606
|
+
toolResultCount: { family: "tools", readBy: ["diagnostic"] },
|
|
607
|
+
toolResultErrorCount: { family: "outcome", readBy: ["diagnostic"] },
|
|
608
|
+
unknownBubbles: { family: "reading", readBy: ["diagnostic"] },
|
|
609
|
+
unknownLines: { family: "reading", readBy: ["diagnostic"] },
|
|
585
610
|
metaLines: {
|
|
611
|
+
family: "reading",
|
|
586
612
|
readBy: ["diagnostic"],
|
|
587
613
|
note: 'Recognised-but-skipped transcript machinery (file-history-snapshot, queued-command, \u2026). Split out of unknownLines by #43 so that number keeps meaning "a type nobody has looked at". Registered here after the fact: #41 and #43 merged past each other, and the union caught it on the next compile \u2014 which is this module doing its job.'
|
|
588
614
|
},
|
|
589
|
-
unparsedBubbles: { readBy: ["diagnostic"] },
|
|
590
|
-
unparsedChatSessionFiles: { readBy: ["diagnostic"] },
|
|
591
|
-
unparsedHistoryFiles: { readBy: ["diagnostic"] },
|
|
592
|
-
unparsedLines: { readBy: ["diagnostic"] },
|
|
593
|
-
unreadableChatSessionFiles: { readBy: ["diagnostic"] },
|
|
594
|
-
unreadableHistoryFiles: { readBy: ["diagnostic"] },
|
|
615
|
+
unparsedBubbles: { family: "reading", readBy: ["diagnostic"] },
|
|
616
|
+
unparsedChatSessionFiles: { family: "reading", readBy: ["diagnostic"] },
|
|
617
|
+
unparsedHistoryFiles: { family: "reading", readBy: ["diagnostic"] },
|
|
618
|
+
unparsedLines: { family: "reading", readBy: ["diagnostic"] },
|
|
619
|
+
unreadableChatSessionFiles: { family: "reading", readBy: ["diagnostic"] },
|
|
620
|
+
unreadableHistoryFiles: { family: "reading", readBy: ["diagnostic"] },
|
|
595
621
|
unreadableRolloutFiles: {
|
|
622
|
+
family: "reading",
|
|
596
623
|
readBy: ["diagnostic"],
|
|
597
624
|
note: "Codex only: rollout files the extractor meant to read and could not open. Summed into the import's read-failure warning, so a store that is partly unreadable says so rather than reporting a short window as the whole."
|
|
598
625
|
},
|
|
599
|
-
unrecognisedChatSessionFiles: { readBy: ["diagnostic"] }
|
|
626
|
+
unrecognisedChatSessionFiles: { family: "reading", readBy: ["diagnostic"] }
|
|
600
627
|
};
|
|
601
628
|
function backendMetricKeys() {
|
|
602
629
|
return Object.entries(exports.METRIC_KEYS).filter(([, spec]) => spec.readBy.includes("backend")).map(([key, spec]) => [key, spec.backendAliases ?? [key]]);
|
|
@@ -609,7 +636,7 @@ var require_out = __commonJS({
|
|
|
609
636
|
"../packages/tool-contract/out/index.js"(exports) {
|
|
610
637
|
"use strict";
|
|
611
638
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
612
|
-
exports.backendMetricKeys = exports.METRIC_KEYS = exports.ASCENDA_SEMANTIC_PROVENANCE = exports.ASCENDA_HISTORICAL_CONSENT_SCOPE = exports.ASCENDA_COLLABORATION_CONSENT_SCOPE = exports.ASCENDA_SEMANTIC_CONSENT_SCOPE = exports.ASCENDA_PROVENANCE = exports.ASCENDA_CONSENT_SCOPE = exports.EVENT_WORKLOAD_CATEGORY = exports.TOOL_EVENT_DELIVERED_STATUSES = exports.IDEMPOTENCY_KEY_MAX_LENGTH = exports.EVENT_METADATA_FIELDS = exports.COLLABORATION_EVENT_TYPES = exports.SEMANTIC_WORK_SIGNAL_EVENT_TYPES = exports.ASCENDA_ELAPSED_QUANTITIES = exports.ASCENDA_ACTIVE_TIME_QUANTITIES = exports.ASCENDA_TOOL_TYPES = exports.ASCENDA_TELEMETRY_SOURCES = void 0;
|
|
639
|
+
exports.backendMetricKeys = exports.METRIC_KEYS = exports.ASCENDA_SEMANTIC_PROVENANCE = exports.ASCENDA_HISTORICAL_CONSENT_SCOPE = exports.ASCENDA_COLLABORATION_CONSENT_SCOPE = exports.ASCENDA_SEMANTIC_CONSENT_SCOPE = exports.ASCENDA_PROVENANCE = exports.ASCENDA_CONSENT_SCOPE = exports.EVENT_WORKLOAD_CATEGORY = exports.TOOL_EVENT_DELIVERED_STATUSES = exports.IDEMPOTENCY_KEY_MAX_LENGTH = exports.EVENT_METADATA_FIELDS = exports.EVENT_METADATA_DISCLOSURE = exports.COLLABORATION_EVENT_TYPES = exports.SEMANTIC_WORK_SIGNAL_EVENT_TYPES = exports.ASCENDA_ELAPSED_QUANTITIES = exports.ASCENDA_ACTIVE_TIME_QUANTITIES = exports.ASCENDA_TOOL_TYPES = exports.ASCENDA_TELEMETRY_SOURCES = void 0;
|
|
613
640
|
exports.combineDisjointHalves = combineDisjointHalves;
|
|
614
641
|
exports.requireComparableQuantities = requireComparableQuantities;
|
|
615
642
|
exports.ASCENDA_TELEMETRY_SOURCES = [
|
|
@@ -677,6 +704,51 @@ var require_out = __commonJS({
|
|
|
677
704
|
"review_given",
|
|
678
705
|
"pull_request_opened"
|
|
679
706
|
];
|
|
707
|
+
exports.EVENT_METADATA_DISCLOSURE = {
|
|
708
|
+
language: "edits",
|
|
709
|
+
fileType: "edits",
|
|
710
|
+
durationBucket: "session",
|
|
711
|
+
tokenPressureBucket: "context",
|
|
712
|
+
linesChangedBucket: "edits",
|
|
713
|
+
commandClass: "counts",
|
|
714
|
+
gitAction: "git",
|
|
715
|
+
milestoneKind: "git",
|
|
716
|
+
branchHash: "repo",
|
|
717
|
+
autonomyMode: "posture",
|
|
718
|
+
modelClass: "model",
|
|
719
|
+
modelId: "model",
|
|
720
|
+
userModified: "edits",
|
|
721
|
+
outcome: "outcome",
|
|
722
|
+
trigger: "outcome",
|
|
723
|
+
promptClass: "counts",
|
|
724
|
+
reason: "outcome",
|
|
725
|
+
afterHours: "clock",
|
|
726
|
+
activity: "counts",
|
|
727
|
+
// One constant word, from the agent itself. The session sentence names it.
|
|
728
|
+
sessionEndReason: "session",
|
|
729
|
+
interruptionKind: "waiting",
|
|
730
|
+
// Free text by type, and written by no hook mapper — the IDE extension's
|
|
731
|
+
// test signal is the only producer. The setup disclosure's third refusal
|
|
732
|
+
// line says as much, and tool-kit's guard test fails if a mapper starts.
|
|
733
|
+
message: "counts",
|
|
734
|
+
host: "session",
|
|
735
|
+
// One constant word from the host's own environment: this machine, or a
|
|
736
|
+
// hosted session. The session sentence names it.
|
|
737
|
+
runtime: "session",
|
|
738
|
+
toolName: "tools",
|
|
739
|
+
simulated: "transport",
|
|
740
|
+
relatedEventType: "transport",
|
|
741
|
+
skillVersion: "transport",
|
|
742
|
+
// A hash computed before it reaches any collector; the task itself is never
|
|
743
|
+
// seen by this code, so there is nothing about the work here to disclose.
|
|
744
|
+
taskFingerprint: "transport",
|
|
745
|
+
importKey: "transport",
|
|
746
|
+
extractionId: "transport",
|
|
747
|
+
importSchema: "transport",
|
|
748
|
+
// The version of the Ascenda collector that sent this event. Names the
|
|
749
|
+
// build, and nothing about the work it observed.
|
|
750
|
+
collectorVersion: "transport"
|
|
751
|
+
};
|
|
680
752
|
exports.EVENT_METADATA_FIELDS = [
|
|
681
753
|
"language",
|
|
682
754
|
"fileType",
|
|
@@ -700,13 +772,17 @@ var require_out = __commonJS({
|
|
|
700
772
|
"message",
|
|
701
773
|
"host",
|
|
702
774
|
"toolName",
|
|
775
|
+
"runtime",
|
|
776
|
+
"sessionEndReason",
|
|
777
|
+
"interruptionKind",
|
|
703
778
|
"simulated",
|
|
704
779
|
"relatedEventType",
|
|
705
780
|
"skillVersion",
|
|
706
781
|
"taskFingerprint",
|
|
707
782
|
"importKey",
|
|
708
783
|
"extractionId",
|
|
709
|
-
"importSchema"
|
|
784
|
+
"importSchema",
|
|
785
|
+
"collectorVersion"
|
|
710
786
|
];
|
|
711
787
|
exports.IDEMPOTENCY_KEY_MAX_LENGTH = 128;
|
|
712
788
|
exports.TOOL_EVENT_DELIVERED_STATUSES = ["accepted", "duplicate"];
|
|
@@ -872,6 +948,21 @@ var require_payload = __commonJS({
|
|
|
872
948
|
}
|
|
873
949
|
});
|
|
874
950
|
|
|
951
|
+
// ../packages/tool-kit/out/collectorVersion.js
|
|
952
|
+
var require_collectorVersion = __commonJS({
|
|
953
|
+
"../packages/tool-kit/out/collectorVersion.js"(exports) {
|
|
954
|
+
"use strict";
|
|
955
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
956
|
+
exports.COLLECTOR_VERSION = exports.UNRELEASED_COLLECTOR_VERSION = void 0;
|
|
957
|
+
exports.describeCollectorVersion = describeCollectorVersion2;
|
|
958
|
+
exports.UNRELEASED_COLLECTOR_VERSION = "unreleased";
|
|
959
|
+
exports.COLLECTOR_VERSION = "0.1.28" ? "0.1.28" : exports.UNRELEASED_COLLECTOR_VERSION;
|
|
960
|
+
function describeCollectorVersion2(version = exports.COLLECTOR_VERSION) {
|
|
961
|
+
return version === exports.UNRELEASED_COLLECTOR_VERSION ? `${version} (built from a checkout, not a release)` : version;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
|
|
875
966
|
// ../packages/tool-kit/out/eventLog.js
|
|
876
967
|
var require_eventLog = __commonJS({
|
|
877
968
|
"../packages/tool-kit/out/eventLog.js"(exports) {
|
|
@@ -918,7 +1009,7 @@ var require_eventLog = __commonJS({
|
|
|
918
1009
|
exports.expandUserPath = expandUserPath;
|
|
919
1010
|
exports.resolveEventLogPath = resolveEventLogPath2;
|
|
920
1011
|
exports.appendEventLog = appendEventLog2;
|
|
921
|
-
var
|
|
1012
|
+
var fs4 = __importStar(__require("fs"));
|
|
922
1013
|
var os2 = __importStar(__require("os"));
|
|
923
1014
|
var path3 = __importStar(__require("path"));
|
|
924
1015
|
exports.EVENT_LOG_ENV_VAR = "ASCENDA_EVENT_LOG_FILE";
|
|
@@ -940,19 +1031,19 @@ var require_eventLog = __commonJS({
|
|
|
940
1031
|
try {
|
|
941
1032
|
rotateIfLarge(logFilePath);
|
|
942
1033
|
const dir = path3.dirname(logFilePath);
|
|
943
|
-
|
|
944
|
-
|
|
1034
|
+
fs4.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1035
|
+
fs4.appendFileSync(logFilePath, `${JSON.stringify(entry)}
|
|
945
1036
|
`, { encoding: "utf8", mode: 384 });
|
|
946
1037
|
if (process.platform !== "win32")
|
|
947
|
-
|
|
1038
|
+
fs4.chmodSync(logFilePath, 384);
|
|
948
1039
|
} catch {
|
|
949
1040
|
}
|
|
950
1041
|
}
|
|
951
1042
|
function rotateIfLarge(logFilePath) {
|
|
952
1043
|
try {
|
|
953
|
-
if (
|
|
1044
|
+
if (fs4.statSync(logFilePath).size < MAX_BYTES)
|
|
954
1045
|
return;
|
|
955
|
-
|
|
1046
|
+
fs4.renameSync(logFilePath, `${logFilePath}.1`);
|
|
956
1047
|
} catch {
|
|
957
1048
|
}
|
|
958
1049
|
}
|
|
@@ -1151,7 +1242,7 @@ var require_tokenStore = __commonJS({
|
|
|
1151
1242
|
exports.listPersistedToolInstallationIds = listPersistedToolInstallationIds2;
|
|
1152
1243
|
exports.readTokenFile = readTokenFile3;
|
|
1153
1244
|
exports.sanitizeFilePart = sanitizeFilePart;
|
|
1154
|
-
var
|
|
1245
|
+
var fs4 = __importStar(__require("fs"));
|
|
1155
1246
|
var os2 = __importStar(__require("os"));
|
|
1156
1247
|
var path3 = __importStar(__require("path"));
|
|
1157
1248
|
function ascendaHome3(home = os2.homedir()) {
|
|
@@ -1162,11 +1253,11 @@ var require_tokenStore = __commonJS({
|
|
|
1162
1253
|
}
|
|
1163
1254
|
function persistEventWriteToken4(tokenFilePath, token) {
|
|
1164
1255
|
const dir = path3.dirname(tokenFilePath);
|
|
1165
|
-
|
|
1166
|
-
|
|
1256
|
+
fs4.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1257
|
+
fs4.writeFileSync(tokenFilePath, token, { encoding: "utf8", mode: 384 });
|
|
1167
1258
|
if (process.platform !== "win32") {
|
|
1168
|
-
|
|
1169
|
-
|
|
1259
|
+
fs4.chmodSync(dir, 448);
|
|
1260
|
+
fs4.chmodSync(tokenFilePath, 384);
|
|
1170
1261
|
}
|
|
1171
1262
|
}
|
|
1172
1263
|
function listPersistedToolInstallationIds2(toolType) {
|
|
@@ -1174,7 +1265,7 @@ var require_tokenStore = __commonJS({
|
|
|
1174
1265
|
const dir = path3.join(ascendaHome3(), "tokens");
|
|
1175
1266
|
let names;
|
|
1176
1267
|
try {
|
|
1177
|
-
names =
|
|
1268
|
+
names = fs4.readdirSync(dir);
|
|
1178
1269
|
} catch {
|
|
1179
1270
|
return [];
|
|
1180
1271
|
}
|
|
@@ -1184,7 +1275,7 @@ var require_tokenStore = __commonJS({
|
|
|
1184
1275
|
continue;
|
|
1185
1276
|
const file = path3.join(dir, name);
|
|
1186
1277
|
try {
|
|
1187
|
-
if (!
|
|
1278
|
+
if (!fs4.statSync(file).isFile())
|
|
1188
1279
|
continue;
|
|
1189
1280
|
} catch {
|
|
1190
1281
|
continue;
|
|
@@ -1197,9 +1288,9 @@ var require_tokenStore = __commonJS({
|
|
|
1197
1288
|
}
|
|
1198
1289
|
function readTokenFile3(tokenFilePath) {
|
|
1199
1290
|
try {
|
|
1200
|
-
if (!
|
|
1291
|
+
if (!fs4.existsSync(tokenFilePath))
|
|
1201
1292
|
return void 0;
|
|
1202
|
-
const value =
|
|
1293
|
+
const value = fs4.readFileSync(tokenFilePath, "utf8").trim();
|
|
1203
1294
|
return value || void 0;
|
|
1204
1295
|
} catch {
|
|
1205
1296
|
return void 0;
|
|
@@ -1261,7 +1352,7 @@ var require_stateStore = __commonJS({
|
|
|
1261
1352
|
exports.recordOutboxDiscard = recordOutboxDiscard;
|
|
1262
1353
|
exports.shouldAnnounceFailure = shouldAnnounceFailure2;
|
|
1263
1354
|
exports.markFailureNotified = markFailureNotified2;
|
|
1264
|
-
var
|
|
1355
|
+
var fs4 = __importStar(__require("fs"));
|
|
1265
1356
|
var path3 = __importStar(__require("path"));
|
|
1266
1357
|
var tokenStore_1 = require_tokenStore();
|
|
1267
1358
|
function defaultStateFilePath2(toolInstallationId) {
|
|
@@ -1277,9 +1368,9 @@ var require_stateStore = __commonJS({
|
|
|
1277
1368
|
}
|
|
1278
1369
|
function readCollectorState2(stateFilePath) {
|
|
1279
1370
|
try {
|
|
1280
|
-
if (!
|
|
1371
|
+
if (!fs4.existsSync(stateFilePath))
|
|
1281
1372
|
return void 0;
|
|
1282
|
-
const raw =
|
|
1373
|
+
const raw = fs4.readFileSync(stateFilePath, "utf8").trim();
|
|
1283
1374
|
if (!raw)
|
|
1284
1375
|
return void 0;
|
|
1285
1376
|
const parsed = JSON.parse(raw);
|
|
@@ -1347,16 +1438,16 @@ var require_stateStore = __commonJS({
|
|
|
1347
1438
|
const temporaryPath = `${stateFilePath}.${process.pid}.tmp`;
|
|
1348
1439
|
try {
|
|
1349
1440
|
const dir = path3.dirname(stateFilePath);
|
|
1350
|
-
|
|
1351
|
-
|
|
1441
|
+
fs4.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1442
|
+
fs4.writeFileSync(temporaryPath, `${JSON.stringify(state, null, 2)}
|
|
1352
1443
|
`, { encoding: "utf8", mode: 384 });
|
|
1353
|
-
|
|
1444
|
+
fs4.renameSync(temporaryPath, stateFilePath);
|
|
1354
1445
|
if (process.platform !== "win32")
|
|
1355
|
-
|
|
1446
|
+
fs4.chmodSync(stateFilePath, 384);
|
|
1356
1447
|
} catch {
|
|
1357
1448
|
try {
|
|
1358
|
-
if (
|
|
1359
|
-
|
|
1449
|
+
if (fs4.existsSync(temporaryPath))
|
|
1450
|
+
fs4.unlinkSync(temporaryPath);
|
|
1360
1451
|
} catch {
|
|
1361
1452
|
}
|
|
1362
1453
|
}
|
|
@@ -1417,7 +1508,7 @@ var require_outbox = __commonJS({
|
|
|
1417
1508
|
exports.readOutboxSummary = readOutboxSummary2;
|
|
1418
1509
|
exports.claimOutbox = claimOutbox;
|
|
1419
1510
|
exports.enforceOutboxBounds = enforceOutboxBounds;
|
|
1420
|
-
var
|
|
1511
|
+
var fs4 = __importStar(__require("fs"));
|
|
1421
1512
|
var path3 = __importStar(__require("path"));
|
|
1422
1513
|
var stateStore_1 = require_stateStore();
|
|
1423
1514
|
var tokenStore_1 = require_tokenStore();
|
|
@@ -1440,19 +1531,19 @@ var require_outbox = __commonJS({
|
|
|
1440
1531
|
function appendToOutbox(outboxFilePath, payload, now = /* @__PURE__ */ new Date()) {
|
|
1441
1532
|
try {
|
|
1442
1533
|
const dir = path3.dirname(outboxFilePath);
|
|
1443
|
-
|
|
1534
|
+
fs4.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1444
1535
|
const entry = { queuedAt: now.toISOString(), payload };
|
|
1445
|
-
|
|
1536
|
+
fs4.appendFileSync(outboxFilePath, `${JSON.stringify(entry)}
|
|
1446
1537
|
`, { encoding: "utf8", mode: 384 });
|
|
1447
1538
|
if (process.platform !== "win32")
|
|
1448
|
-
|
|
1539
|
+
fs4.chmodSync(outboxFilePath, 384);
|
|
1449
1540
|
return true;
|
|
1450
1541
|
} catch {
|
|
1451
1542
|
return false;
|
|
1452
1543
|
}
|
|
1453
1544
|
}
|
|
1454
1545
|
function readOutboxSummary2(outboxFilePath) {
|
|
1455
|
-
const files = [outboxFilePath, ...listClaimFiles(outboxFilePath)].filter((file) =>
|
|
1546
|
+
const files = [outboxFilePath, ...listClaimFiles(outboxFilePath)].filter((file) => fs4.existsSync(file));
|
|
1456
1547
|
if (files.length === 0)
|
|
1457
1548
|
return void 0;
|
|
1458
1549
|
let depth = 0;
|
|
@@ -1473,7 +1564,7 @@ var require_outbox = __commonJS({
|
|
|
1473
1564
|
const claimPath = `${outboxFilePath}.${process.pid}${CLAIM_SUFFIX}`;
|
|
1474
1565
|
const claimed = [];
|
|
1475
1566
|
try {
|
|
1476
|
-
|
|
1567
|
+
fs4.renameSync(outboxFilePath, claimPath);
|
|
1477
1568
|
claimed.push(claimPath);
|
|
1478
1569
|
} catch {
|
|
1479
1570
|
}
|
|
@@ -1482,10 +1573,10 @@ var require_outbox = __commonJS({
|
|
|
1482
1573
|
if (claimed.includes(orphan))
|
|
1483
1574
|
continue;
|
|
1484
1575
|
try {
|
|
1485
|
-
if (now -
|
|
1576
|
+
if (now - fs4.statSync(orphan).mtimeMs < ORPHANED_CLAIM_AGE_MS)
|
|
1486
1577
|
continue;
|
|
1487
1578
|
const mine = `${claimPath}.${orphanIndex++}`;
|
|
1488
|
-
|
|
1579
|
+
fs4.renameSync(orphan, mine);
|
|
1489
1580
|
claimed.push(mine);
|
|
1490
1581
|
} catch {
|
|
1491
1582
|
}
|
|
@@ -1510,18 +1601,18 @@ var require_outbox = __commonJS({
|
|
|
1510
1601
|
released = true;
|
|
1511
1602
|
if (remainder.length > 0) {
|
|
1512
1603
|
try {
|
|
1513
|
-
|
|
1514
|
-
|
|
1604
|
+
fs4.mkdirSync(path3.dirname(outboxFilePath), { recursive: true, mode: 448 });
|
|
1605
|
+
fs4.appendFileSync(outboxFilePath, remainder.map((entry) => `${JSON.stringify(entry)}
|
|
1515
1606
|
`).join(""), { encoding: "utf8", mode: 384 });
|
|
1516
1607
|
if (process.platform !== "win32")
|
|
1517
|
-
|
|
1608
|
+
fs4.chmodSync(outboxFilePath, 384);
|
|
1518
1609
|
} catch {
|
|
1519
1610
|
return;
|
|
1520
1611
|
}
|
|
1521
1612
|
}
|
|
1522
1613
|
for (const file of claimed) {
|
|
1523
1614
|
try {
|
|
1524
|
-
|
|
1615
|
+
fs4.unlinkSync(file);
|
|
1525
1616
|
} catch {
|
|
1526
1617
|
}
|
|
1527
1618
|
}
|
|
@@ -1557,7 +1648,7 @@ var require_outbox = __commonJS({
|
|
|
1557
1648
|
const dir = path3.dirname(outboxFilePath);
|
|
1558
1649
|
const prefix = `${path3.basename(outboxFilePath)}.`;
|
|
1559
1650
|
try {
|
|
1560
|
-
return
|
|
1651
|
+
return fs4.readdirSync(dir).filter((name) => name.startsWith(prefix) && name.includes(CLAIM_SUFFIX)).map((name) => path3.join(dir, name)).sort();
|
|
1561
1652
|
} catch {
|
|
1562
1653
|
return [];
|
|
1563
1654
|
}
|
|
@@ -1565,7 +1656,7 @@ var require_outbox = __commonJS({
|
|
|
1565
1656
|
function readEntries(file) {
|
|
1566
1657
|
let raw;
|
|
1567
1658
|
try {
|
|
1568
|
-
raw =
|
|
1659
|
+
raw = fs4.readFileSync(file, "utf8");
|
|
1569
1660
|
} catch {
|
|
1570
1661
|
return { entries: [], unreadable: 0 };
|
|
1571
1662
|
}
|
|
@@ -1625,6 +1716,7 @@ var require_eventSender = __commonJS({
|
|
|
1625
1716
|
var tokenStore_1 = require_tokenStore();
|
|
1626
1717
|
var stateStore_1 = require_stateStore();
|
|
1627
1718
|
var payload_1 = require_payload();
|
|
1719
|
+
var collectorVersion_1 = require_collectorVersion();
|
|
1628
1720
|
var AscendaSemanticEventError = class extends Error {
|
|
1629
1721
|
constructor(message) {
|
|
1630
1722
|
super(message);
|
|
@@ -1646,9 +1738,12 @@ var require_eventSender = __commonJS({
|
|
|
1646
1738
|
provenance: tool_contract_1.ASCENDA_PROVENANCE,
|
|
1647
1739
|
privacyMode: "metadata_only",
|
|
1648
1740
|
...mapped,
|
|
1649
|
-
metadata: mapped.metadata
|
|
1741
|
+
metadata: withCollectorVersion(mapped.metadata)
|
|
1650
1742
|
};
|
|
1651
1743
|
}
|
|
1744
|
+
function withCollectorVersion(metadata) {
|
|
1745
|
+
return { ...metadata, collectorVersion: collectorVersion_1.COLLECTOR_VERSION };
|
|
1746
|
+
}
|
|
1652
1747
|
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
1653
1748
|
var RETRY_DELAY_MS = 250;
|
|
1654
1749
|
var AscendaEventSender2 = class {
|
|
@@ -1668,6 +1763,30 @@ var require_eventSender = __commonJS({
|
|
|
1668
1763
|
async send(mapped) {
|
|
1669
1764
|
return this.post(buildEventPayload2(this.config, mapped));
|
|
1670
1765
|
}
|
|
1766
|
+
/**
|
|
1767
|
+
* Writes the event to the outbox and returns without touching the network.
|
|
1768
|
+
* The next outbox pass delivers it, from whichever hook of this
|
|
1769
|
+
* installation sends next.
|
|
1770
|
+
*
|
|
1771
|
+
* For a hook whose host is exiting. A process the host may kill at any
|
|
1772
|
+
* moment can't wait on a send, and one killed mid-send dies before
|
|
1773
|
+
* {@link post} gets to queue the payload, so the event goes with it. Here
|
|
1774
|
+
* the payload is on disk before anything can go wrong.
|
|
1775
|
+
*
|
|
1776
|
+
* Returns whether it is. When the write fails the journal says the event
|
|
1777
|
+
* was lost; nothing else could have kept it.
|
|
1778
|
+
*/
|
|
1779
|
+
queue(mapped) {
|
|
1780
|
+
const payload = buildEventPayload2(this.config, mapped);
|
|
1781
|
+
const queued = this.enqueue(payload);
|
|
1782
|
+
if (!queued) {
|
|
1783
|
+
this.lastState = (0, stateStore_1.recordSendOutcome)(this.stateFilePath(), this.config.toolInstallationId, "other", {
|
|
1784
|
+
detail: `${payload.eventType}: outbox write failed, event lost`
|
|
1785
|
+
});
|
|
1786
|
+
}
|
|
1787
|
+
this.log(payload, "not_sent", queued ? "queued" : void 0);
|
|
1788
|
+
return queued;
|
|
1789
|
+
}
|
|
1671
1790
|
/**
|
|
1672
1791
|
* Sends one of the six agent-observed types (dark-flow-gap-analysis §2.1).
|
|
1673
1792
|
* Distinct from {@link send} rather than an option on it, because the
|
|
@@ -1708,7 +1827,7 @@ var require_eventSender = __commonJS({
|
|
|
1708
1827
|
consentScope: tool_contract_1.ASCENDA_SEMANTIC_CONSENT_SCOPE,
|
|
1709
1828
|
provenance: tool_contract_1.ASCENDA_SEMANTIC_PROVENANCE,
|
|
1710
1829
|
privacyMode: "metadata_only",
|
|
1711
|
-
metadata: mapped.metadata
|
|
1830
|
+
metadata: withCollectorVersion(mapped.metadata)
|
|
1712
1831
|
};
|
|
1713
1832
|
return this.post(payload);
|
|
1714
1833
|
}
|
|
@@ -1739,7 +1858,7 @@ var require_eventSender = __commonJS({
|
|
|
1739
1858
|
consentScope: tool_contract_1.ASCENDA_COLLABORATION_CONSENT_SCOPE,
|
|
1740
1859
|
provenance: tool_contract_1.ASCENDA_PROVENANCE,
|
|
1741
1860
|
privacyMode: "metadata_only",
|
|
1742
|
-
metadata: mapped.metadata
|
|
1861
|
+
metadata: withCollectorVersion(mapped.metadata)
|
|
1743
1862
|
};
|
|
1744
1863
|
return this.post(payload);
|
|
1745
1864
|
}
|
|
@@ -1964,6 +2083,8 @@ var require_eventSender = __commonJS({
|
|
|
1964
2083
|
}
|
|
1965
2084
|
/** Never throws: a renewal that errors is a failed renewal, not a failed turn. */
|
|
1966
2085
|
async renewEventToken() {
|
|
2086
|
+
if (this.config.renewToken === false)
|
|
2087
|
+
return false;
|
|
1967
2088
|
try {
|
|
1968
2089
|
const renewed = await (0, http_1.renewToolToken)(this.config.apiBaseUrl, this.eventWriteToken, this.signal());
|
|
1969
2090
|
if (!renewed)
|
|
@@ -2032,7 +2153,7 @@ var require_contextRegistry = __commonJS({
|
|
|
2032
2153
|
exports.readWorkContextRegistry = readWorkContextRegistry;
|
|
2033
2154
|
exports.recordWorkContext = recordWorkContext2;
|
|
2034
2155
|
exports.recordWorkContextAlias = recordWorkContextAlias;
|
|
2035
|
-
var
|
|
2156
|
+
var fs4 = __importStar(__require("fs"));
|
|
2036
2157
|
var os2 = __importStar(__require("os"));
|
|
2037
2158
|
var path3 = __importStar(__require("path"));
|
|
2038
2159
|
var MAX_PATHS_PER_ENTRY = 8;
|
|
@@ -2041,7 +2162,7 @@ var require_contextRegistry = __commonJS({
|
|
|
2041
2162
|
}
|
|
2042
2163
|
function readWorkContextRegistry(registryFilePath = workContextRegistryFilePath()) {
|
|
2043
2164
|
try {
|
|
2044
|
-
const parsed = JSON.parse(
|
|
2165
|
+
const parsed = JSON.parse(fs4.readFileSync(registryFilePath, "utf8"));
|
|
2045
2166
|
if (parsed && parsed.version === 1 && parsed.contexts && typeof parsed.contexts === "object") {
|
|
2046
2167
|
return parsed;
|
|
2047
2168
|
}
|
|
@@ -2118,13 +2239,13 @@ var require_contextRegistry = __commonJS({
|
|
|
2118
2239
|
}
|
|
2119
2240
|
function writeRegistry(registryFilePath, registry) {
|
|
2120
2241
|
const dir = path3.dirname(registryFilePath);
|
|
2121
|
-
|
|
2242
|
+
fs4.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
2122
2243
|
const tmp = `${registryFilePath}.${process.pid}.tmp`;
|
|
2123
|
-
|
|
2244
|
+
fs4.writeFileSync(tmp, `${JSON.stringify(registry, null, 2)}
|
|
2124
2245
|
`, { encoding: "utf8", mode: 384 });
|
|
2125
|
-
|
|
2246
|
+
fs4.renameSync(tmp, registryFilePath);
|
|
2126
2247
|
if (process.platform !== "win32") {
|
|
2127
|
-
|
|
2248
|
+
fs4.chmodSync(registryFilePath, 384);
|
|
2128
2249
|
}
|
|
2129
2250
|
}
|
|
2130
2251
|
}
|
|
@@ -2174,12 +2295,13 @@ var require_credentials = __commonJS({
|
|
|
2174
2295
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2175
2296
|
exports.credentialsFilePath = credentialsFilePath2;
|
|
2176
2297
|
exports.readMachineCredentials = readMachineCredentials2;
|
|
2177
|
-
exports.writeMachineCredentials =
|
|
2298
|
+
exports.writeMachineCredentials = writeMachineCredentials2;
|
|
2178
2299
|
exports.writeTopLevelCredentials = writeTopLevelCredentials2;
|
|
2300
|
+
exports.isLocalOnlyHostInstall = isLocalOnlyHostInstall;
|
|
2179
2301
|
exports.readHostCredentials = readHostCredentials;
|
|
2180
2302
|
exports.writeHostCredentials = writeHostCredentials;
|
|
2181
2303
|
exports.removeHostCredentials = removeHostCredentials;
|
|
2182
|
-
var
|
|
2304
|
+
var fs4 = __importStar(__require("fs"));
|
|
2183
2305
|
var path3 = __importStar(__require("path"));
|
|
2184
2306
|
var tokenStore_1 = require_tokenStore();
|
|
2185
2307
|
function credentialsFilePath2() {
|
|
@@ -2187,7 +2309,7 @@ var require_credentials = __commonJS({
|
|
|
2187
2309
|
}
|
|
2188
2310
|
function readMachineCredentials2() {
|
|
2189
2311
|
try {
|
|
2190
|
-
const raw =
|
|
2312
|
+
const raw = fs4.readFileSync(credentialsFilePath2(), "utf8").trim();
|
|
2191
2313
|
if (!raw)
|
|
2192
2314
|
return void 0;
|
|
2193
2315
|
const parsed = JSON.parse(raw);
|
|
@@ -2198,19 +2320,27 @@ var require_credentials = __commonJS({
|
|
|
2198
2320
|
return void 0;
|
|
2199
2321
|
}
|
|
2200
2322
|
}
|
|
2201
|
-
function
|
|
2323
|
+
function writeMachineCredentials2(credentials) {
|
|
2202
2324
|
const file = credentialsFilePath2();
|
|
2203
|
-
|
|
2204
|
-
|
|
2325
|
+
fs4.mkdirSync(path3.dirname(file), { recursive: true, mode: 448 });
|
|
2326
|
+
fs4.writeFileSync(file, `${JSON.stringify(credentials, null, 2)}
|
|
2205
2327
|
`, { encoding: "utf8", mode: 384 });
|
|
2206
2328
|
if (process.platform !== "win32") {
|
|
2207
|
-
|
|
2208
|
-
|
|
2329
|
+
fs4.chmodSync(path3.dirname(file), 448);
|
|
2330
|
+
fs4.chmodSync(file, 384);
|
|
2209
2331
|
}
|
|
2210
2332
|
}
|
|
2211
2333
|
function writeTopLevelCredentials2(credentials) {
|
|
2212
2334
|
const existing = readMachineCredentials2();
|
|
2213
|
-
|
|
2335
|
+
writeMachineCredentials2({ ...credentials, ...existing?.tools ? { tools: existing.tools } : {} });
|
|
2336
|
+
}
|
|
2337
|
+
function isLocalOnlyHostInstall(host, hasToken) {
|
|
2338
|
+
const credentials = readHostCredentials(host);
|
|
2339
|
+
if (!credentials?.localOnly)
|
|
2340
|
+
return false;
|
|
2341
|
+
if (process.env.ASCENDA_EVENT_WRITE_TOKEN)
|
|
2342
|
+
return false;
|
|
2343
|
+
return !(credentials.toolInstallationId && hasToken(credentials.toolInstallationId));
|
|
2214
2344
|
}
|
|
2215
2345
|
function readHostCredentials(host) {
|
|
2216
2346
|
const entry = readMachineCredentials2()?.tools?.[host];
|
|
@@ -2220,7 +2350,7 @@ var require_credentials = __commonJS({
|
|
|
2220
2350
|
}
|
|
2221
2351
|
function writeHostCredentials(host, credentials) {
|
|
2222
2352
|
const existing = readMachineCredentials2() ?? {};
|
|
2223
|
-
|
|
2353
|
+
writeMachineCredentials2({ ...existing, tools: { ...existing.tools ?? {}, [host]: credentials } });
|
|
2224
2354
|
}
|
|
2225
2355
|
function removeHostCredentials(host) {
|
|
2226
2356
|
const existing = readMachineCredentials2();
|
|
@@ -2233,7 +2363,7 @@ var require_credentials = __commonJS({
|
|
|
2233
2363
|
next.tools = tools;
|
|
2234
2364
|
else
|
|
2235
2365
|
delete next.tools;
|
|
2236
|
-
|
|
2366
|
+
writeMachineCredentials2(next);
|
|
2237
2367
|
}
|
|
2238
2368
|
}
|
|
2239
2369
|
});
|
|
@@ -2285,7 +2415,7 @@ var require_forgeProject = __commonJS({
|
|
|
2285
2415
|
exports.readForgeFullName = readForgeFullName;
|
|
2286
2416
|
exports.forgeFullNameFromConfig = forgeFullNameFromConfig;
|
|
2287
2417
|
exports.recordForgeProjectAlias = recordForgeProjectAlias2;
|
|
2288
|
-
var
|
|
2418
|
+
var fs4 = __importStar(__require("fs"));
|
|
2289
2419
|
var path3 = __importStar(__require("path"));
|
|
2290
2420
|
var contextRegistry_1 = require_contextRegistry();
|
|
2291
2421
|
function forgeProjectHash(value) {
|
|
@@ -2332,7 +2462,7 @@ var require_forgeProject = __commonJS({
|
|
|
2332
2462
|
return null;
|
|
2333
2463
|
let config;
|
|
2334
2464
|
try {
|
|
2335
|
-
config =
|
|
2465
|
+
config = fs4.readFileSync(path3.join(repositoryRoot, ".git", "config"), "utf8");
|
|
2336
2466
|
} catch {
|
|
2337
2467
|
return null;
|
|
2338
2468
|
}
|
|
@@ -2439,7 +2569,7 @@ var require_salt = __commonJS({
|
|
|
2439
2569
|
exports.readOrCreateMachineSalt = readOrCreateMachineSalt;
|
|
2440
2570
|
exports.hashWithMachineSalt = hashWithMachineSalt;
|
|
2441
2571
|
var crypto2 = __importStar(__require("crypto"));
|
|
2442
|
-
var
|
|
2572
|
+
var fs4 = __importStar(__require("fs"));
|
|
2443
2573
|
var path3 = __importStar(__require("path"));
|
|
2444
2574
|
var tokenStore_1 = require_tokenStore();
|
|
2445
2575
|
function machineSaltFilePath() {
|
|
@@ -2451,19 +2581,19 @@ var require_salt = __commonJS({
|
|
|
2451
2581
|
if (hit)
|
|
2452
2582
|
return hit;
|
|
2453
2583
|
const dir = path3.dirname(saltFilePath);
|
|
2454
|
-
|
|
2584
|
+
fs4.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
2455
2585
|
let salt;
|
|
2456
2586
|
try {
|
|
2457
2587
|
salt = crypto2.randomBytes(32).toString("hex");
|
|
2458
|
-
|
|
2588
|
+
fs4.writeFileSync(saltFilePath, salt, { encoding: "utf8", mode: 384, flag: "wx" });
|
|
2459
2589
|
} catch (error) {
|
|
2460
2590
|
if (error.code !== "EEXIST")
|
|
2461
2591
|
throw error;
|
|
2462
|
-
salt =
|
|
2592
|
+
salt = fs4.readFileSync(saltFilePath, "utf8").trim();
|
|
2463
2593
|
}
|
|
2464
2594
|
if (process.platform !== "win32") {
|
|
2465
|
-
|
|
2466
|
-
|
|
2595
|
+
fs4.chmodSync(dir, 448);
|
|
2596
|
+
fs4.chmodSync(saltFilePath, 384);
|
|
2467
2597
|
}
|
|
2468
2598
|
cache.set(saltFilePath, salt);
|
|
2469
2599
|
return salt;
|
|
@@ -2523,7 +2653,7 @@ var require_workContext = __commonJS({
|
|
|
2523
2653
|
exports.deriveBranchHash = deriveBranchHash;
|
|
2524
2654
|
exports.readBranchName = readBranchName;
|
|
2525
2655
|
exports.deriveBranchHashForCwd = deriveBranchHashForCwd2;
|
|
2526
|
-
var
|
|
2656
|
+
var fs4 = __importStar(__require("fs"));
|
|
2527
2657
|
var path3 = __importStar(__require("path"));
|
|
2528
2658
|
var salt_1 = require_salt();
|
|
2529
2659
|
var MAX_WALK_DEPTH = 64;
|
|
@@ -2555,14 +2685,14 @@ var require_workContext = __commonJS({
|
|
|
2555
2685
|
};
|
|
2556
2686
|
}
|
|
2557
2687
|
function resolveRepositoryRoots(startDir) {
|
|
2558
|
-
if (!
|
|
2688
|
+
if (!fs4.existsSync(startDir))
|
|
2559
2689
|
return null;
|
|
2560
2690
|
let dir = startDir;
|
|
2561
2691
|
for (let depth = 0; depth < MAX_WALK_DEPTH; depth++) {
|
|
2562
2692
|
const dotGit = path3.join(dir, ".git");
|
|
2563
2693
|
let stat = null;
|
|
2564
2694
|
try {
|
|
2565
|
-
stat =
|
|
2695
|
+
stat = fs4.statSync(dotGit);
|
|
2566
2696
|
} catch {
|
|
2567
2697
|
stat = null;
|
|
2568
2698
|
}
|
|
@@ -2582,7 +2712,7 @@ var require_workContext = __commonJS({
|
|
|
2582
2712
|
}
|
|
2583
2713
|
function readGitdirPointer(dotGitFile, containingDir) {
|
|
2584
2714
|
try {
|
|
2585
|
-
const match = /^gitdir:\s*(.+)\s*$/m.exec(
|
|
2715
|
+
const match = /^gitdir:\s*(.+)\s*$/m.exec(fs4.readFileSync(dotGitFile, "utf8"));
|
|
2586
2716
|
if (!match)
|
|
2587
2717
|
return null;
|
|
2588
2718
|
return path3.resolve(containingDir, match[1].trim());
|
|
@@ -2664,7 +2794,7 @@ var require_workContext = __commonJS({
|
|
|
2664
2794
|
return null;
|
|
2665
2795
|
let head;
|
|
2666
2796
|
try {
|
|
2667
|
-
head =
|
|
2797
|
+
head = fs4.readFileSync(path3.join(gitDir, "HEAD"), "utf8").trim();
|
|
2668
2798
|
} catch {
|
|
2669
2799
|
return null;
|
|
2670
2800
|
}
|
|
@@ -2780,6 +2910,9 @@ var require_hookAdapter = __commonJS({
|
|
|
2780
2910
|
if (events.length === 0)
|
|
2781
2911
|
return;
|
|
2782
2912
|
const notice = options.onNotice ?? ((message) => console.error(message));
|
|
2913
|
+
const hasToken = (id) => (0, tokenStore_1.readTokenFile)(process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0, tokenStore_1.defaultTokenFilePath)(id)) !== void 0;
|
|
2914
|
+
if (options.host && (0, credentials_1.isLocalOnlyHostInstall)(options.host, hasToken))
|
|
2915
|
+
return;
|
|
2783
2916
|
let config;
|
|
2784
2917
|
try {
|
|
2785
2918
|
config = loadCliAgentConfig(options.toolType, options.sessionId, options.cwd, options);
|
|
@@ -2845,6 +2978,51 @@ var require_hookAdapter = __commonJS({
|
|
|
2845
2978
|
}
|
|
2846
2979
|
});
|
|
2847
2980
|
|
|
2981
|
+
// ../packages/tool-kit/out/setupDisclosure.js
|
|
2982
|
+
var require_setupDisclosure = __commonJS({
|
|
2983
|
+
"../packages/tool-kit/out/setupDisclosure.js"(exports) {
|
|
2984
|
+
"use strict";
|
|
2985
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2986
|
+
exports.FREE_TEXT_KEYS = exports.REFUSALS = exports.ALWAYS_SENT = exports.FAMILY_SENTENCES = void 0;
|
|
2987
|
+
exports.renderSetupDisclosure = renderSetupDisclosure3;
|
|
2988
|
+
exports.FAMILY_SENTENCES = {
|
|
2989
|
+
session: "when a session starts and ends, the one-word reason for the end if your agent gives one, how long each turn took, and whether it ran on this machine or in a hosted cloud session",
|
|
2990
|
+
counts: "how many prompts you sent, how many replies came back, and what class of command ran in a terminal \u2014 test, lint, build, git and so on",
|
|
2991
|
+
tools: "the name of each tool your agent calls",
|
|
2992
|
+
outcome: "whether a call succeeded, failed, or was interrupted",
|
|
2993
|
+
clock: "your machine's offset from UTC, so an evening is read as an evening",
|
|
2994
|
+
repo: "your project and branch as digests computed on this machine \u2014 never the names themselves",
|
|
2995
|
+
model: "which model served the session, by name and by tier",
|
|
2996
|
+
posture: "the permission posture your agent was working under \u2014 asking each time, accepting edits, and so on",
|
|
2997
|
+
git: "that a commit, push or revert happened, and when a pull request opened or merged",
|
|
2998
|
+
edits: "roughly how much a file changed, as a bucket, and whether you edited it after the agent wrote it",
|
|
2999
|
+
context: "how full the context window got",
|
|
3000
|
+
waiting: "that your agent stopped and waited for you, as one word: permission_request, idle_prompt, or other",
|
|
3001
|
+
reading: "what the reader could not make sense of \u2014 lines it failed to parse, files it could not open, and prompts it judged machine-written rather than typed"
|
|
3002
|
+
};
|
|
3003
|
+
exports.ALWAYS_SENT = ["session", "counts", "tools", "outcome", "repo", "clock"];
|
|
3004
|
+
exports.REFUSALS = [
|
|
3005
|
+
"Never your prompts, your agent's replies, or anything inside a file.",
|
|
3006
|
+
"Never a file path, a command line, or a repository or branch name.",
|
|
3007
|
+
"Content is read here only to choose one of a fixed set of labels, then discarded. No mapper writes it to an event, and a test fails the build if one starts."
|
|
3008
|
+
];
|
|
3009
|
+
exports.FREE_TEXT_KEYS = ["message"];
|
|
3010
|
+
function renderSetupDisclosure3({ sends, displayName }) {
|
|
3011
|
+
const declared = /* @__PURE__ */ new Set([...exports.ALWAYS_SENT, ...sends]);
|
|
3012
|
+
const ordered = Object.keys(exports.FAMILY_SENTENCES).filter((family) => declared.has(family));
|
|
3013
|
+
const lines = [
|
|
3014
|
+
`What this sends from ${displayName}, once paired:`,
|
|
3015
|
+
...ordered.map((family) => ` \xB7 ${exports.FAMILY_SENTENCES[family]}`),
|
|
3016
|
+
"",
|
|
3017
|
+
...exports.REFUSALS.map((line) => ` ${line}`),
|
|
3018
|
+
"",
|
|
3019
|
+
" Turn it off by revoking this tool in the Ascenda app."
|
|
3020
|
+
];
|
|
3021
|
+
return lines.join("\n");
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3024
|
+
});
|
|
3025
|
+
|
|
2848
3026
|
// ../packages/tool-kit/out/cliAgentSetup.js
|
|
2849
3027
|
var require_cliAgentSetup = __commonJS({
|
|
2850
3028
|
"../packages/tool-kit/out/cliAgentSetup.js"(exports) {
|
|
@@ -2893,12 +3071,14 @@ var require_cliAgentSetup = __commonJS({
|
|
|
2893
3071
|
exports.writeHookSettings = writeHookSettings;
|
|
2894
3072
|
exports.findStaleHookCommands = findStaleHookCommands2;
|
|
2895
3073
|
var crypto2 = __importStar(__require("crypto"));
|
|
2896
|
-
var
|
|
3074
|
+
var fs4 = __importStar(__require("fs"));
|
|
2897
3075
|
var os2 = __importStar(__require("os"));
|
|
2898
3076
|
var path3 = __importStar(__require("path"));
|
|
3077
|
+
var collectorVersion_1 = require_collectorVersion();
|
|
2899
3078
|
var credentials_1 = require_credentials();
|
|
2900
3079
|
var hookAdapter_1 = require_hookAdapter();
|
|
2901
3080
|
var http_1 = require_http();
|
|
3081
|
+
var setupDisclosure_1 = require_setupDisclosure();
|
|
2902
3082
|
var tokenStore_1 = require_tokenStore();
|
|
2903
3083
|
var MANAGEMENT_COMMANDS2 = /* @__PURE__ */ new Set(["setup", "install", "status", "uninstall", "-h", "--help"]);
|
|
2904
3084
|
function isCliAgentManagementCommand(argument) {
|
|
@@ -2919,6 +3099,7 @@ Options
|
|
|
2919
3099
|
--local [port] shorthand for the local dev server (default port 4477)
|
|
2920
3100
|
--tool-installation-id <id> reuse an existing pairing instead of creating one
|
|
2921
3101
|
--token <eventWriteToken> reuse an existing token (stored 0600, never printed)
|
|
3102
|
+
--no-pair install without pairing: local features on, nothing sent
|
|
2922
3103
|
--scope project|user where hooks are registered (default project)
|
|
2923
3104
|
--project-dir <path> project root for --scope project (default cwd)
|
|
2924
3105
|
--dry-run print what would change, write nothing
|
|
@@ -2943,14 +3124,35 @@ Options
|
|
|
2943
3124
|
return uninstall2(options, spec);
|
|
2944
3125
|
const apiBaseUrl = (options.apiBaseUrl ?? (0, credentials_1.readHostCredentials)(spec.host)?.apiBaseUrl ?? hookAdapter_1.DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
2945
3126
|
console.log(`Ascenda setup for ${spec.displayName} \u2014 ${apiBaseUrl}`);
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
3127
|
+
console.log(`
|
|
3128
|
+
${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName: spec.displayName })}
|
|
3129
|
+
`);
|
|
3130
|
+
let identity;
|
|
3131
|
+
let unpairedReason;
|
|
3132
|
+
if (options.skipPairing) {
|
|
3133
|
+
unpairedReason = "asked not to pair (--no-pair)";
|
|
3134
|
+
} else {
|
|
3135
|
+
identity = await resolveIdentity2(apiBaseUrl, options, spec);
|
|
3136
|
+
if (identity) {
|
|
3137
|
+
console.log(` pairing ${identity.toolInstallationId}${identity.paired ? " (new)" : " (existing)"}`);
|
|
3138
|
+
} else {
|
|
3139
|
+
unpairedReason = "pairing did not finish \u2014 installing the local half anyway";
|
|
3140
|
+
}
|
|
3141
|
+
}
|
|
3142
|
+
if (unpairedReason) {
|
|
3143
|
+
console.log(` pairing none: ${unpairedReason}`);
|
|
3144
|
+
console.log(" local features on, nothing is sent");
|
|
3145
|
+
}
|
|
2950
3146
|
const binary = installBinary2(spec, options.dryRun);
|
|
2951
3147
|
console.log(` hook binary ${binary}`);
|
|
2952
3148
|
if (!options.dryRun) {
|
|
2953
|
-
|
|
3149
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3150
|
+
const toolInstallationId = identity?.toolInstallationId ?? options.toolInstallationId ?? (0, credentials_1.readHostCredentials)(spec.host)?.toolInstallationId ?? `${spec.toolType}:${crypto2.randomUUID()}`;
|
|
3151
|
+
(0, credentials_1.writeHostCredentials)(spec.host, {
|
|
3152
|
+
apiBaseUrl,
|
|
3153
|
+
toolInstallationId,
|
|
3154
|
+
...identity ? { pairedAt: now } : { localOnly: true, installedAt: now }
|
|
3155
|
+
});
|
|
2954
3156
|
}
|
|
2955
3157
|
console.log(` credentials ${(0, credentials_1.credentialsFilePath)()} (tools.${spec.host})`);
|
|
2956
3158
|
const settingsFile = spec.settings.settingsPath(options.scope, options.projectDir);
|
|
@@ -2964,6 +3166,9 @@ Options
|
|
|
2964
3166
|
}
|
|
2965
3167
|
console.log(`
|
|
2966
3168
|
Done. ${spec.restartHint}`);
|
|
3169
|
+
if (!identity) {
|
|
3170
|
+
console.log(`Pair later: npx ${spec.packageName} setup`);
|
|
3171
|
+
}
|
|
2967
3172
|
console.log(`Check anytime: npx ${spec.packageName} status`);
|
|
2968
3173
|
return 0;
|
|
2969
3174
|
}
|
|
@@ -2972,6 +3177,7 @@ Done. ${spec.restartHint}`);
|
|
|
2972
3177
|
scope: "project",
|
|
2973
3178
|
projectDir: process.cwd(),
|
|
2974
3179
|
dryRun: false,
|
|
3180
|
+
skipPairing: false,
|
|
2975
3181
|
action: "install"
|
|
2976
3182
|
};
|
|
2977
3183
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -3021,6 +3227,14 @@ Done. ${spec.restartHint}`);
|
|
|
3021
3227
|
case "--dry-run":
|
|
3022
3228
|
options.dryRun = true;
|
|
3023
3229
|
break;
|
|
3230
|
+
case "--no-pair":
|
|
3231
|
+
// `--no-pairing` is the spelling this landed under first. Both appeared
|
|
3232
|
+
// only in an unreleased changelog, so this alias exists to spare anyone
|
|
3233
|
+
// reading that draft, and `--no-pair` — the Claude Code adapter's own
|
|
3234
|
+
// spelling — is the documented one.
|
|
3235
|
+
case "--no-pairing":
|
|
3236
|
+
options.skipPairing = true;
|
|
3237
|
+
break;
|
|
3024
3238
|
case "-h":
|
|
3025
3239
|
case "--help":
|
|
3026
3240
|
options.action = "help";
|
|
@@ -3090,19 +3304,19 @@ Pairing ${status.status}. Run setup again.`);
|
|
|
3090
3304
|
if (dryRun)
|
|
3091
3305
|
return target;
|
|
3092
3306
|
const source = process.argv[1];
|
|
3093
|
-
|
|
3307
|
+
fs4.mkdirSync(path3.dirname(target), { recursive: true });
|
|
3094
3308
|
if (path3.resolve(source) !== path3.resolve(target)) {
|
|
3095
|
-
|
|
3309
|
+
fs4.copyFileSync(source, target);
|
|
3096
3310
|
}
|
|
3097
3311
|
if (process.platform !== "win32")
|
|
3098
|
-
|
|
3312
|
+
fs4.chmodSync(target, 493);
|
|
3099
3313
|
return target;
|
|
3100
3314
|
}
|
|
3101
3315
|
function writeHookSettings(settingsFile, binary, spec, dryRun) {
|
|
3102
3316
|
let settings = { ...spec.settings.scaffold ?? {} };
|
|
3103
|
-
const exists =
|
|
3317
|
+
const exists = fs4.existsSync(settingsFile);
|
|
3104
3318
|
if (exists) {
|
|
3105
|
-
const raw =
|
|
3319
|
+
const raw = fs4.readFileSync(settingsFile, "utf8").trim();
|
|
3106
3320
|
if (raw) {
|
|
3107
3321
|
try {
|
|
3108
3322
|
settings = JSON.parse(raw);
|
|
@@ -3122,7 +3336,7 @@ ${settingsFile} is not valid JSON. Fix or move it, then run setup again.`);
|
|
|
3122
3336
|
const updated = { ...settings, hooks };
|
|
3123
3337
|
const serialised = `${JSON.stringify(updated, null, 2)}
|
|
3124
3338
|
`;
|
|
3125
|
-
if (exists &&
|
|
3339
|
+
if (exists && fs4.readFileSync(settingsFile, "utf8") === serialised)
|
|
3126
3340
|
return false;
|
|
3127
3341
|
if (dryRun) {
|
|
3128
3342
|
console.log(`
|
|
@@ -3131,9 +3345,9 @@ ${serialised}`);
|
|
|
3131
3345
|
return true;
|
|
3132
3346
|
}
|
|
3133
3347
|
if (exists)
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3348
|
+
fs4.copyFileSync(settingsFile, `${settingsFile}.ascenda-backup`);
|
|
3349
|
+
fs4.mkdirSync(path3.dirname(settingsFile), { recursive: true });
|
|
3350
|
+
fs4.writeFileSync(settingsFile, serialised, "utf8");
|
|
3137
3351
|
return true;
|
|
3138
3352
|
}
|
|
3139
3353
|
function hookCommand2(binary) {
|
|
@@ -3159,7 +3373,7 @@ ${serialised}`);
|
|
|
3159
3373
|
}
|
|
3160
3374
|
function readSettings(settingsFile) {
|
|
3161
3375
|
try {
|
|
3162
|
-
return JSON.parse(
|
|
3376
|
+
return JSON.parse(fs4.readFileSync(settingsFile, "utf8"));
|
|
3163
3377
|
} catch {
|
|
3164
3378
|
return {};
|
|
3165
3379
|
}
|
|
@@ -3172,10 +3386,12 @@ ${serialised}`);
|
|
|
3172
3386
|
const settings = readSettings(settingsFile);
|
|
3173
3387
|
const registered = spec.hookEvents.filter((event) => (settings.hooks?.[event] ?? []).some((entry) => isOurs2(entry, spec))).length;
|
|
3174
3388
|
const stale = findStaleHookCommands2(settings, binary, spec);
|
|
3389
|
+
const localOnly = (0, credentials_1.isLocalOnlyHostInstall)(spec.host, (id) => (0, tokenStore_1.readTokenFile)((0, tokenStore_1.defaultTokenFilePath)(id)) !== void 0);
|
|
3390
|
+
console.log(`version ${(0, collectorVersion_1.describeCollectorVersion)()}`);
|
|
3175
3391
|
console.log(`api base url ${credentials?.apiBaseUrl ?? "\u2014 not configured"}`);
|
|
3176
|
-
console.log(`pairing ${credentials?.toolInstallationId ?? "\u2014 not paired"}`);
|
|
3177
|
-
console.log(`token ${tokenFile && (0, tokenStore_1.readTokenFile)(tokenFile) ? "present" : "\u2014 missing"}`);
|
|
3178
|
-
console.log(`hook binary ${
|
|
3392
|
+
console.log(`pairing ${credentials?.toolInstallationId ?? "\u2014 not paired"}${localOnly ? " (installed, not paired \u2014 local features active, telemetry inactive)" : ""}`);
|
|
3393
|
+
console.log(`token ${localOnly ? "\u2014 none needed until this install is paired" : tokenFile && (0, tokenStore_1.readTokenFile)(tokenFile) ? "present" : "\u2014 missing"}`);
|
|
3394
|
+
console.log(`hook binary ${fs4.existsSync(binary) ? binary : "\u2014 not installed"}`);
|
|
3179
3395
|
console.log(`hooks ${registered}/${spec.hookEvents.length} registered in ${settingsFile}`);
|
|
3180
3396
|
if (stale.length) {
|
|
3181
3397
|
console.log(`stale hooks ${stale.length} not pointing at the installed binary \u2014 each one fails silently per event:`);
|
|
@@ -3183,14 +3399,15 @@ ${serialised}`);
|
|
|
3183
3399
|
console.log(` ${command}`);
|
|
3184
3400
|
console.log(` Remove them from ${settingsFile} by hand; setup cannot tell them from a hook you wrote.`);
|
|
3185
3401
|
}
|
|
3186
|
-
const
|
|
3402
|
+
const paired = localOnly || credentials?.toolInstallationId !== void 0;
|
|
3403
|
+
const healthy = paired && registered === spec.hookEvents.length && fs4.existsSync(binary) && !stale.length;
|
|
3187
3404
|
return healthy ? 0 : 1;
|
|
3188
3405
|
}
|
|
3189
3406
|
function uninstall2(options, spec) {
|
|
3190
3407
|
const settingsFile = spec.settings.settingsPath(options.scope, options.projectDir);
|
|
3191
|
-
if (
|
|
3408
|
+
if (fs4.existsSync(settingsFile)) {
|
|
3192
3409
|
try {
|
|
3193
|
-
const settings = JSON.parse(
|
|
3410
|
+
const settings = JSON.parse(fs4.readFileSync(settingsFile, "utf8"));
|
|
3194
3411
|
const hooks = { ...settings.hooks ?? {} };
|
|
3195
3412
|
for (const event of Object.keys(hooks)) {
|
|
3196
3413
|
const kept = hooks[event].filter((entry) => !isOurs2(entry, spec));
|
|
@@ -3202,8 +3419,8 @@ ${serialised}`);
|
|
|
3202
3419
|
const updated = { ...settings, hooks };
|
|
3203
3420
|
if (!Object.keys(hooks).length)
|
|
3204
3421
|
delete updated.hooks;
|
|
3205
|
-
|
|
3206
|
-
|
|
3422
|
+
fs4.copyFileSync(settingsFile, `${settingsFile}.ascenda-backup`);
|
|
3423
|
+
fs4.writeFileSync(settingsFile, `${JSON.stringify(updated, null, 2)}
|
|
3207
3424
|
`, "utf8");
|
|
3208
3425
|
console.log(`hooks removed from ${settingsFile}`);
|
|
3209
3426
|
} catch {
|
|
@@ -3212,8 +3429,8 @@ ${serialised}`);
|
|
|
3212
3429
|
}
|
|
3213
3430
|
}
|
|
3214
3431
|
const binary = cliAgentHookBinPath(spec.binaryName);
|
|
3215
|
-
if (
|
|
3216
|
-
|
|
3432
|
+
if (fs4.existsSync(binary)) {
|
|
3433
|
+
fs4.rmSync(binary);
|
|
3217
3434
|
console.log(`removed ${binary}`);
|
|
3218
3435
|
}
|
|
3219
3436
|
if ((0, credentials_1.readHostCredentials)(spec.host)) {
|
|
@@ -3270,7 +3487,7 @@ var require_turnState = __commonJS({
|
|
|
3270
3487
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3271
3488
|
exports.recordTurnStart = recordTurnStart;
|
|
3272
3489
|
exports.consumeTurnDurationMs = consumeTurnDurationMs;
|
|
3273
|
-
var
|
|
3490
|
+
var fs4 = __importStar(__require("fs"));
|
|
3274
3491
|
var path3 = __importStar(__require("path"));
|
|
3275
3492
|
var tokenStore_1 = require_tokenStore();
|
|
3276
3493
|
var stateDir = () => process.env.ASCENDA_STATE_DIR ?? path3.join((0, tokenStore_1.ascendaHome)(), "state");
|
|
@@ -3284,8 +3501,8 @@ var require_turnState = __commonJS({
|
|
|
3284
3501
|
if (!sessionId)
|
|
3285
3502
|
return;
|
|
3286
3503
|
try {
|
|
3287
|
-
|
|
3288
|
-
|
|
3504
|
+
fs4.mkdirSync(stateDir(), { recursive: true });
|
|
3505
|
+
fs4.writeFileSync(turnFile(agent, sessionId), String(now), { encoding: "utf8", mode: 384 });
|
|
3289
3506
|
} catch {
|
|
3290
3507
|
}
|
|
3291
3508
|
}
|
|
@@ -3294,8 +3511,8 @@ var require_turnState = __commonJS({
|
|
|
3294
3511
|
return void 0;
|
|
3295
3512
|
const file = turnFile(agent, sessionId);
|
|
3296
3513
|
try {
|
|
3297
|
-
const started = Number(
|
|
3298
|
-
|
|
3514
|
+
const started = Number(fs4.readFileSync(file, "utf8").trim());
|
|
3515
|
+
fs4.rmSync(file, { force: true });
|
|
3299
3516
|
if (!Number.isFinite(started) || started <= 0 || started > now)
|
|
3300
3517
|
return void 0;
|
|
3301
3518
|
return now - started;
|
|
@@ -3352,7 +3569,7 @@ var require_liveBus = __commonJS({
|
|
|
3352
3569
|
exports.liveBusSocketPath = liveBusSocketPath;
|
|
3353
3570
|
exports.bucketPromptSize = bucketPromptSize2;
|
|
3354
3571
|
exports.emitLiveSignal = emitLiveSignal2;
|
|
3355
|
-
var
|
|
3572
|
+
var fs4 = __importStar(__require("fs"));
|
|
3356
3573
|
var net = __importStar(__require("net"));
|
|
3357
3574
|
var os2 = __importStar(__require("os"));
|
|
3358
3575
|
var path3 = __importStar(__require("path"));
|
|
@@ -3376,7 +3593,7 @@ var require_liveBus = __commonJS({
|
|
|
3376
3593
|
return candidates;
|
|
3377
3594
|
return candidates.filter((candidate) => {
|
|
3378
3595
|
try {
|
|
3379
|
-
return
|
|
3596
|
+
return fs4.statSync(candidate).isSocket();
|
|
3380
3597
|
} catch {
|
|
3381
3598
|
return false;
|
|
3382
3599
|
}
|
|
@@ -3474,9 +3691,9 @@ var require_out2 = __commonJS({
|
|
|
3474
3691
|
"../packages/tool-kit/out/index.js"(exports) {
|
|
3475
3692
|
"use strict";
|
|
3476
3693
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3477
|
-
exports.
|
|
3478
|
-
exports.
|
|
3479
|
-
exports.isRetryableStatus = exports.parseIngestResponse = exports.postToolEventsBatch = exports.postToolEvent = exports.renewToolToken = void 0;
|
|
3694
|
+
exports.renderSetupDisclosure = exports.REFUSALS = exports.FREE_TEXT_KEYS = exports.FAMILY_SENTENCES = exports.ALWAYS_SENT = exports.writeHookSettings = exports.runCliAgentSetup = exports.isCliAgentManagementCommand = exports.findStaleHookCommands = exports.cliAgentHookBinPath = exports.resolveContextHashes = exports.resolveCliAgentInstallationId = exports.loadCliAgentConfig = exports.deliverHookEvents = exports.MissingInstallationIdError = exports.DEFAULT_API_BASE_URL = exports.resolveEventLogPath = exports.expandUserPath = exports.appendEventLog = exports.EVENT_LOG_ENV_VAR = exports.buildEventPayload = exports.AscendaSemanticEventError = exports.AscendaEventSender = exports.describeCollectorVersion = exports.UNRELEASED_COLLECTOR_VERSION = exports.COLLECTOR_VERSION = exports.mintIdempotencyKey = exports.looksLikeCorrection = exports.outcomeForHook = exports.inferOutcome = exports.getNestedNumber = exports.getNestedString = exports.getNested = exports.getNumber = exports.getString = exports.localHourAt = exports.utcOffsetMinutesAt = exports.BUSINESS_DAY = exports.isOutsideBusinessHours = exports.isAfterHours = exports.bucketDurationMs = exports.bucketLinesChanged = exports.classifyModelClass = exports.autonomyBand = exports.invitesDebrief = exports.classifyWorkMilestone = exports.isReworkGitAction = exports.classifyGitAction = exports.isVerificationCommand = exports.classifyCommand = void 0;
|
|
3695
|
+
exports.readForgeFullName = exports.parseForgeFullName = exports.forgeProjectHash = exports.workContextRegistryFilePath = exports.readWorkContextRegistry = exports.recordWorkContextAlias = exports.recordWorkContext = exports.readBranchName = exports.normalizeBranchName = exports.deriveBranchHashForCwd = exports.deriveBranchHash = exports.deriveWorkContext = exports.hashWithMachineSalt = exports.readOrCreateMachineSalt = exports.machineSaltFilePath = exports.fixedTimeProvider = exports.systemTimeProvider = exports.enforceOutboxBounds = exports.claimOutbox = exports.readOutboxSummary = exports.appendToOutbox = exports.defaultOutboxFilePath = exports.outboxDrainEnabled = exports.DEFAULT_OUTBOX_DRAIN_BATCH_SIZE = exports.DEFAULT_OUTBOX_MAX_AGE_MS = exports.DEFAULT_OUTBOX_MAX_ENTRIES = exports.OUTBOX_DRAIN_ENV_VAR = exports.recordOutboxDiscard = exports.unresolvedToolInstallationId = exports.unresolvedStateFilePath = exports.markFailureNotified = exports.shouldAnnounceFailure = exports.recordSendOutcome = exports.readCollectorState = exports.defaultStateFilePath = exports.readTokenFile = exports.persistEventWriteToken = exports.listPersistedToolInstallationIds = exports.defaultTokenFilePath = exports.ascendaHome = exports.recordTurnStart = exports.consumeTurnDurationMs = exports.writeTopLevelCredentials = exports.writeMachineCredentials = exports.writeHostCredentials = exports.removeHostCredentials = exports.readMachineCredentials = exports.readHostCredentials = exports.isLocalOnlyHostInstall = exports.credentialsFilePath = void 0;
|
|
3696
|
+
exports.isRetryableStatus = exports.parseIngestResponse = exports.postToolEventsBatch = exports.postToolEvent = exports.renewToolToken = exports.getPairingStatus = exports.createPairingSession = exports.AscendaApiError = exports.liveBusSocketCandidates = exports.liveBusSocketPath = exports.bucketPromptSize = exports.emitLiveSignal = exports.recordForgeProjectAlias = exports.forgeFullNameFromConfig = void 0;
|
|
3480
3697
|
var commandClassifier_1 = require_commandClassifier();
|
|
3481
3698
|
Object.defineProperty(exports, "classifyCommand", { enumerable: true, get: function() {
|
|
3482
3699
|
return commandClassifier_1.classifyCommand;
|
|
@@ -3557,6 +3774,16 @@ var require_out2 = __commonJS({
|
|
|
3557
3774
|
Object.defineProperty(exports, "mintIdempotencyKey", { enumerable: true, get: function() {
|
|
3558
3775
|
return payload_1.mintIdempotencyKey;
|
|
3559
3776
|
} });
|
|
3777
|
+
var collectorVersion_1 = require_collectorVersion();
|
|
3778
|
+
Object.defineProperty(exports, "COLLECTOR_VERSION", { enumerable: true, get: function() {
|
|
3779
|
+
return collectorVersion_1.COLLECTOR_VERSION;
|
|
3780
|
+
} });
|
|
3781
|
+
Object.defineProperty(exports, "UNRELEASED_COLLECTOR_VERSION", { enumerable: true, get: function() {
|
|
3782
|
+
return collectorVersion_1.UNRELEASED_COLLECTOR_VERSION;
|
|
3783
|
+
} });
|
|
3784
|
+
Object.defineProperty(exports, "describeCollectorVersion", { enumerable: true, get: function() {
|
|
3785
|
+
return collectorVersion_1.describeCollectorVersion;
|
|
3786
|
+
} });
|
|
3560
3787
|
var eventSender_1 = require_eventSender();
|
|
3561
3788
|
Object.defineProperty(exports, "AscendaEventSender", { enumerable: true, get: function() {
|
|
3562
3789
|
return eventSender_1.AscendaEventSender;
|
|
@@ -3615,10 +3842,29 @@ var require_out2 = __commonJS({
|
|
|
3615
3842
|
Object.defineProperty(exports, "writeHookSettings", { enumerable: true, get: function() {
|
|
3616
3843
|
return cliAgentSetup_1.writeHookSettings;
|
|
3617
3844
|
} });
|
|
3845
|
+
var setupDisclosure_1 = require_setupDisclosure();
|
|
3846
|
+
Object.defineProperty(exports, "ALWAYS_SENT", { enumerable: true, get: function() {
|
|
3847
|
+
return setupDisclosure_1.ALWAYS_SENT;
|
|
3848
|
+
} });
|
|
3849
|
+
Object.defineProperty(exports, "FAMILY_SENTENCES", { enumerable: true, get: function() {
|
|
3850
|
+
return setupDisclosure_1.FAMILY_SENTENCES;
|
|
3851
|
+
} });
|
|
3852
|
+
Object.defineProperty(exports, "FREE_TEXT_KEYS", { enumerable: true, get: function() {
|
|
3853
|
+
return setupDisclosure_1.FREE_TEXT_KEYS;
|
|
3854
|
+
} });
|
|
3855
|
+
Object.defineProperty(exports, "REFUSALS", { enumerable: true, get: function() {
|
|
3856
|
+
return setupDisclosure_1.REFUSALS;
|
|
3857
|
+
} });
|
|
3858
|
+
Object.defineProperty(exports, "renderSetupDisclosure", { enumerable: true, get: function() {
|
|
3859
|
+
return setupDisclosure_1.renderSetupDisclosure;
|
|
3860
|
+
} });
|
|
3618
3861
|
var credentials_1 = require_credentials();
|
|
3619
3862
|
Object.defineProperty(exports, "credentialsFilePath", { enumerable: true, get: function() {
|
|
3620
3863
|
return credentials_1.credentialsFilePath;
|
|
3621
3864
|
} });
|
|
3865
|
+
Object.defineProperty(exports, "isLocalOnlyHostInstall", { enumerable: true, get: function() {
|
|
3866
|
+
return credentials_1.isLocalOnlyHostInstall;
|
|
3867
|
+
} });
|
|
3622
3868
|
Object.defineProperty(exports, "readHostCredentials", { enumerable: true, get: function() {
|
|
3623
3869
|
return credentials_1.readHostCredentials;
|
|
3624
3870
|
} });
|
|
@@ -3820,6 +4066,7 @@ var require_out2 = __commonJS({
|
|
|
3820
4066
|
});
|
|
3821
4067
|
|
|
3822
4068
|
// src/paths.ts
|
|
4069
|
+
import * as fs from "fs";
|
|
3823
4070
|
import * as path from "path";
|
|
3824
4071
|
function hookBinPath() {
|
|
3825
4072
|
return path.join((0, import_tool_kit3.ascendaHome)(), "bin", "ascenda-claude-hook");
|
|
@@ -3833,6 +4080,15 @@ function readCredentials() {
|
|
|
3833
4080
|
function writeCredentials(credentials) {
|
|
3834
4081
|
(0, import_tool_kit3.writeTopLevelCredentials)(credentials);
|
|
3835
4082
|
}
|
|
4083
|
+
function removeCredentials() {
|
|
4084
|
+
const credentials = (0, import_tool_kit3.readMachineCredentials)();
|
|
4085
|
+
if (!credentials) return;
|
|
4086
|
+
if (credentials.tools && Object.keys(credentials.tools).length > 0) {
|
|
4087
|
+
(0, import_tool_kit3.writeMachineCredentials)({ tools: credentials.tools });
|
|
4088
|
+
return;
|
|
4089
|
+
}
|
|
4090
|
+
fs.rmSync((0, import_tool_kit3.credentialsFilePath)(), { force: true });
|
|
4091
|
+
}
|
|
3836
4092
|
var import_tool_kit3, import_tool_kit4;
|
|
3837
4093
|
var init_paths = __esm({
|
|
3838
4094
|
"src/paths.ts"() {
|
|
@@ -3846,6 +4102,10 @@ var init_paths = __esm({
|
|
|
3846
4102
|
function isClaudeHookEventName(value) {
|
|
3847
4103
|
return CLAUDE_HOOK_EVENT_NAMES.includes(value);
|
|
3848
4104
|
}
|
|
4105
|
+
function claudeRuntime(env = process.env) {
|
|
4106
|
+
const flag = env.CLAUDE_CODE_REMOTE?.trim().toLowerCase();
|
|
4107
|
+
return flag === "true" || flag === "1" ? "cloud" : "local";
|
|
4108
|
+
}
|
|
3849
4109
|
var import_tool_contract, CLAUDE_HOOK_EVENT_NAMES, ASCENDA_TOOL_TYPE, CLAUDE_HOST;
|
|
3850
4110
|
var init_types = __esm({
|
|
3851
4111
|
"src/types.ts"() {
|
|
@@ -3860,7 +4120,8 @@ var init_types = __esm({
|
|
|
3860
4120
|
"PreCompact",
|
|
3861
4121
|
"PostCompact",
|
|
3862
4122
|
"Stop",
|
|
3863
|
-
"Notification"
|
|
4123
|
+
"Notification",
|
|
4124
|
+
"SessionEnd"
|
|
3864
4125
|
];
|
|
3865
4126
|
ASCENDA_TOOL_TYPE = "claude_code";
|
|
3866
4127
|
CLAUDE_HOST = "claude_code";
|
|
@@ -3874,6 +4135,12 @@ function resolveOutboxFilePath(toolInstallationId) {
|
|
|
3874
4135
|
function resolveStateFilePath(toolInstallationId) {
|
|
3875
4136
|
return process.env.ASCENDA_STATE_FILE ?? (toolInstallationId ? (0, import_tool_kit5.defaultStateFilePath)(toolInstallationId) : (0, import_tool_kit5.unresolvedStateFilePath)(ASCENDA_TOOL_TYPE));
|
|
3876
4137
|
}
|
|
4138
|
+
function localOnlyInstall(credentials = readCredentials()) {
|
|
4139
|
+
if (!credentials?.localOnly) return false;
|
|
4140
|
+
if (envOverride("ASCENDA_EVENT_WRITE_TOKEN")) return false;
|
|
4141
|
+
const tokenFilePath = process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (credentials.toolInstallationId ? (0, import_tool_kit5.defaultTokenFilePath)(credentials.toolInstallationId) : void 0);
|
|
4142
|
+
return !(tokenFilePath && (0, import_tool_kit5.readTokenFile)(tokenFilePath));
|
|
4143
|
+
}
|
|
3877
4144
|
function resolveToolInstallationId(credentials = readCredentials()) {
|
|
3878
4145
|
const fromEnv = process.env.ASCENDA_TOOL_INSTALLATION_ID?.trim();
|
|
3879
4146
|
if (fromEnv) return { toolInstallationId: normalizeToolInstallationId(fromEnv), source: "env" };
|
|
@@ -3899,6 +4166,11 @@ function loadConfigFromEnv() {
|
|
|
3899
4166
|
tokenFilePath,
|
|
3900
4167
|
stateFilePath: resolveStateFilePath(toolInstallationId),
|
|
3901
4168
|
outboxFilePath: resolveOutboxFilePath(toolInstallationId),
|
|
4169
|
+
// A hosted session is a fresh container on every start, with its token
|
|
4170
|
+
// supplied by the environment. A rotation there would be written to a
|
|
4171
|
+
// file that dies with the container while revoking the environment's
|
|
4172
|
+
// copy, so there it never rotates.
|
|
4173
|
+
renewToken: claudeRuntime() !== "cloud",
|
|
3902
4174
|
// Override only. When unset, main() fills it from the hook payload's own
|
|
3903
4175
|
// `session_id`, exactly as it does the context hashes below — see there.
|
|
3904
4176
|
//
|
|
@@ -3949,12 +4221,13 @@ var init_config = __esm({
|
|
|
3949
4221
|
// src/setup.ts
|
|
3950
4222
|
var setup_exports = {};
|
|
3951
4223
|
__export(setup_exports, {
|
|
4224
|
+
SENDS: () => SENDS,
|
|
3952
4225
|
findStaleHookCommands: () => findStaleHookCommands,
|
|
3953
4226
|
runSetup: () => runSetup,
|
|
3954
4227
|
writeSettings: () => writeSettings
|
|
3955
4228
|
});
|
|
3956
4229
|
import * as crypto from "crypto";
|
|
3957
|
-
import * as
|
|
4230
|
+
import * as fs2 from "fs";
|
|
3958
4231
|
import * as os from "os";
|
|
3959
4232
|
import * as path2 from "path";
|
|
3960
4233
|
async function runSetup(argv) {
|
|
@@ -3973,13 +4246,26 @@ async function runSetup(argv) {
|
|
|
3973
4246
|
if (options.action === "uninstall") return uninstall(options);
|
|
3974
4247
|
const apiBaseUrl = (options.apiBaseUrl ?? readCredentials()?.apiBaseUrl ?? DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
3975
4248
|
console.log(`Ascenda setup \u2014 ${apiBaseUrl}`);
|
|
4249
|
+
if (!options.pair) console.log("\n Nothing is sent from an install with no pairing. What pairing would start sending:");
|
|
4250
|
+
console.log(`
|
|
4251
|
+
${(0, import_tool_kit8.renderSetupDisclosure)({ sends: SENDS, displayName: "Claude Code" })}
|
|
4252
|
+
`);
|
|
3976
4253
|
const identity = await resolveIdentity(apiBaseUrl, options);
|
|
3977
|
-
|
|
3978
|
-
console.log(` pairing ${identity.toolInstallationId}${identity.
|
|
4254
|
+
const unpaired = identity.pairing === "local-only";
|
|
4255
|
+
console.log(` pairing ${unpaired ? `none \u2014 ${identity.reason}` : `${identity.toolInstallationId}${identity.pairing === "new" ? " (new)" : " (existing)"}`}`);
|
|
4256
|
+
if (unpaired) console.log(` installation ${identity.toolInstallationId} (recorded, so a later pair attaches to it)`);
|
|
3979
4257
|
const binary = installBinary(options.dryRun);
|
|
3980
4258
|
console.log(` hook binary ${binary}`);
|
|
3981
4259
|
if (!options.dryRun) {
|
|
3982
|
-
|
|
4260
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
4261
|
+
writeCredentials({
|
|
4262
|
+
apiBaseUrl,
|
|
4263
|
+
toolInstallationId: identity.toolInstallationId,
|
|
4264
|
+
// No fabricated `pairedAt` on an install that has no pairing, and no
|
|
4265
|
+
// token file either. The id is the whole record, and it is what `pair`
|
|
4266
|
+
// picks up.
|
|
4267
|
+
...unpaired ? { localOnly: true, installedAt: now } : { pairedAt: now }
|
|
4268
|
+
});
|
|
3983
4269
|
}
|
|
3984
4270
|
console.log(` credentials ${(0, import_tool_kit4.credentialsFilePath)()}`);
|
|
3985
4271
|
const settingsFile = settingsPath(options);
|
|
@@ -3990,7 +4276,16 @@ async function runSetup(argv) {
|
|
|
3990
4276
|
console.log("\nDry run \u2014 nothing was written.");
|
|
3991
4277
|
return 0;
|
|
3992
4278
|
}
|
|
3993
|
-
|
|
4279
|
+
if (unpaired) {
|
|
4280
|
+
console.log("\nInstalled, not paired.");
|
|
4281
|
+
console.log(" active the session prompts, and the live signal to a socket on this machine");
|
|
4282
|
+
console.log(` inactive delivery to ${apiBaseUrl}. Nothing is sent, and nothing is queued for later.`);
|
|
4283
|
+
if (identity.hint) console.log(` note ${identity.hint}`);
|
|
4284
|
+
console.log(" pair later npx @ascenda-one/claude-code-hooks pair");
|
|
4285
|
+
console.log("\nRestart Claude Code in this project to load the hooks.");
|
|
4286
|
+
} else {
|
|
4287
|
+
console.log("\nDone. Restart Claude Code in this project to load the hooks.");
|
|
4288
|
+
}
|
|
3994
4289
|
console.log(`Check anytime: npx @ascenda-one/claude-code-hooks status`);
|
|
3995
4290
|
return 0;
|
|
3996
4291
|
}
|
|
@@ -3999,6 +4294,7 @@ function parseArgs(argv) {
|
|
|
3999
4294
|
scope: "project",
|
|
4000
4295
|
projectDir: process.env.CLAUDE_PROJECT_DIR ?? process.cwd(),
|
|
4001
4296
|
dryRun: false,
|
|
4297
|
+
pair: true,
|
|
4002
4298
|
action: "install"
|
|
4003
4299
|
};
|
|
4004
4300
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -4043,6 +4339,14 @@ function parseArgs(argv) {
|
|
|
4043
4339
|
case "--project-dir":
|
|
4044
4340
|
options.projectDir = path2.resolve(next());
|
|
4045
4341
|
break;
|
|
4342
|
+
case "--no-pair":
|
|
4343
|
+
// `--no-pairing` is the spelling the CLI agents' setup landed under
|
|
4344
|
+
// first, and the one their README still showed for a day. Both parse
|
|
4345
|
+
// everywhere, so a person who read either page gets the install rather
|
|
4346
|
+
// than "unknown argument".
|
|
4347
|
+
case "--no-pairing":
|
|
4348
|
+
options.pair = false;
|
|
4349
|
+
break;
|
|
4046
4350
|
case "--dry-run":
|
|
4047
4351
|
options.dryRun = true;
|
|
4048
4352
|
break;
|
|
@@ -4062,40 +4366,52 @@ async function resolveIdentity(apiBaseUrl, options) {
|
|
|
4062
4366
|
const existingId = options.toolInstallationId ?? readCredentials()?.toolInstallationId;
|
|
4063
4367
|
if (existingId && options.token) {
|
|
4064
4368
|
if (!options.dryRun) (0, import_tool_kit8.persistEventWriteToken)((0, import_tool_kit8.defaultTokenFilePath)(existingId), options.token);
|
|
4065
|
-
return { toolInstallationId: existingId,
|
|
4369
|
+
return { toolInstallationId: existingId, pairing: "existing" };
|
|
4066
4370
|
}
|
|
4067
4371
|
if (existingId && (0, import_tool_kit8.readTokenFile)((0, import_tool_kit8.defaultTokenFilePath)(existingId))) {
|
|
4068
|
-
return { toolInstallationId: existingId,
|
|
4372
|
+
return { toolInstallationId: existingId, pairing: "existing" };
|
|
4373
|
+
}
|
|
4374
|
+
const toolInstallationId = existingId ?? (options.dryRun ? `${ASCENDA_TOOL_TYPE}:<minted at run time>` : `${ASCENDA_TOOL_TYPE}:${crypto.randomUUID()}`);
|
|
4375
|
+
if (!options.pair) {
|
|
4376
|
+
return { toolInstallationId, pairing: "local-only", reason: "asked not to pair (--no-pair)" };
|
|
4069
4377
|
}
|
|
4070
4378
|
if (options.dryRun) {
|
|
4071
|
-
return { toolInstallationId
|
|
4379
|
+
return { toolInstallationId, pairing: "existing" };
|
|
4072
4380
|
}
|
|
4073
|
-
const toolInstallationId = existingId ?? `${ASCENDA_TOOL_TYPE}:${crypto.randomUUID()}`;
|
|
4074
4381
|
let session;
|
|
4075
4382
|
try {
|
|
4076
4383
|
session = await (0, import_tool_kit8.createPairingSession)(apiBaseUrl, toolInstallationId, ASCENDA_TOOL_TYPE, `Claude Code on ${os.hostname()}`);
|
|
4077
4384
|
} catch (error) {
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4385
|
+
return {
|
|
4386
|
+
toolInstallationId,
|
|
4387
|
+
pairing: "local-only",
|
|
4388
|
+
reason: `could not reach ${apiBaseUrl} (${error instanceof Error ? error.message : String(error)})`,
|
|
4389
|
+
hint: "for a local dev server use --local, or name your backend with --api-base-url"
|
|
4390
|
+
};
|
|
4082
4391
|
}
|
|
4083
|
-
const
|
|
4084
|
-
if (
|
|
4085
|
-
(0, import_tool_kit8.persistEventWriteToken)((0, import_tool_kit8.defaultTokenFilePath)(toolInstallationId), token);
|
|
4086
|
-
return { toolInstallationId,
|
|
4392
|
+
const outcome = await pollForToken(apiBaseUrl, session.pairingSessionId, session.code, session.expiresAt);
|
|
4393
|
+
if ("reason" in outcome) return { toolInstallationId, pairing: "local-only", reason: outcome.reason };
|
|
4394
|
+
(0, import_tool_kit8.persistEventWriteToken)((0, import_tool_kit8.defaultTokenFilePath)(toolInstallationId), outcome.token);
|
|
4395
|
+
return { toolInstallationId, pairing: "new" };
|
|
4087
4396
|
}
|
|
4088
4397
|
async function pollForToken(apiBaseUrl, pairingSessionId, code, expiresAt) {
|
|
4089
4398
|
const deadline = Math.min(Date.parse(expiresAt) || Date.now() + 3e5, Date.now() + 3e5);
|
|
4090
4399
|
let announced = false;
|
|
4400
|
+
let failures = 0;
|
|
4091
4401
|
while (Date.now() < deadline) {
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4402
|
+
let status;
|
|
4403
|
+
try {
|
|
4404
|
+
status = await (0, import_tool_kit8.getPairingStatus)(apiBaseUrl, pairingSessionId);
|
|
4405
|
+
failures = 0;
|
|
4406
|
+
} catch (error) {
|
|
4407
|
+
if (++failures >= POLL_ERROR_TOLERANCE) {
|
|
4408
|
+
return { reason: `lost contact while waiting (${error instanceof Error ? error.message : String(error)})` };
|
|
4409
|
+
}
|
|
4410
|
+
await new Promise((resolve2) => setTimeout(resolve2, 2e3));
|
|
4411
|
+
continue;
|
|
4098
4412
|
}
|
|
4413
|
+
if (status.status === "paired" && status.eventWriteToken) return { token: status.eventWriteToken };
|
|
4414
|
+
if (status.status === "expired" || status.status === "cancelled") return { reason: `pairing ${status.status}` };
|
|
4099
4415
|
if (!announced) {
|
|
4100
4416
|
console.log(`
|
|
4101
4417
|
Confirm in the Ascenda app \u2014 code ${code}`);
|
|
@@ -4104,18 +4420,17 @@ Pairing ${status.status}. Run setup again.`);
|
|
|
4104
4420
|
}
|
|
4105
4421
|
await new Promise((resolve2) => setTimeout(resolve2, 2e3));
|
|
4106
4422
|
}
|
|
4107
|
-
|
|
4108
|
-
return void 0;
|
|
4423
|
+
return { reason: "no confirmation within 5 minutes" };
|
|
4109
4424
|
}
|
|
4110
4425
|
function installBinary(dryRun) {
|
|
4111
4426
|
const target = hookBinPath();
|
|
4112
4427
|
if (dryRun) return target;
|
|
4113
4428
|
const source = process.argv[1];
|
|
4114
|
-
|
|
4429
|
+
fs2.mkdirSync(path2.dirname(target), { recursive: true });
|
|
4115
4430
|
if (path2.resolve(source) !== path2.resolve(target)) {
|
|
4116
|
-
|
|
4431
|
+
fs2.copyFileSync(source, target);
|
|
4117
4432
|
}
|
|
4118
|
-
if (process.platform !== "win32")
|
|
4433
|
+
if (process.platform !== "win32") fs2.chmodSync(target, 493);
|
|
4119
4434
|
return target;
|
|
4120
4435
|
}
|
|
4121
4436
|
function settingsPath(options) {
|
|
@@ -4123,9 +4438,9 @@ function settingsPath(options) {
|
|
|
4123
4438
|
}
|
|
4124
4439
|
function writeSettings(settingsFile, binary, dryRun) {
|
|
4125
4440
|
let settings = {};
|
|
4126
|
-
const exists =
|
|
4441
|
+
const exists = fs2.existsSync(settingsFile);
|
|
4127
4442
|
if (exists) {
|
|
4128
|
-
const raw =
|
|
4443
|
+
const raw = fs2.readFileSync(settingsFile, "utf8").trim();
|
|
4129
4444
|
if (raw) {
|
|
4130
4445
|
try {
|
|
4131
4446
|
settings = JSON.parse(raw);
|
|
@@ -4145,16 +4460,16 @@ ${settingsFile} is not valid JSON. Fix or move it, then run setup again.`);
|
|
|
4145
4460
|
const updated = { ...settings, hooks };
|
|
4146
4461
|
const serialised = `${JSON.stringify(updated, null, 2)}
|
|
4147
4462
|
`;
|
|
4148
|
-
if (exists &&
|
|
4463
|
+
if (exists && fs2.readFileSync(settingsFile, "utf8") === serialised) return false;
|
|
4149
4464
|
if (dryRun) {
|
|
4150
4465
|
console.log(`
|
|
4151
4466
|
--- ${settingsFile} (dry run) ---
|
|
4152
4467
|
${serialised}`);
|
|
4153
4468
|
return true;
|
|
4154
4469
|
}
|
|
4155
|
-
if (exists)
|
|
4156
|
-
|
|
4157
|
-
|
|
4470
|
+
if (exists) fs2.copyFileSync(settingsFile, `${settingsFile}.ascenda-backup`);
|
|
4471
|
+
fs2.mkdirSync(path2.dirname(settingsFile), { recursive: true });
|
|
4472
|
+
fs2.writeFileSync(settingsFile, serialised, "utf8");
|
|
4158
4473
|
return true;
|
|
4159
4474
|
}
|
|
4160
4475
|
function hookCommand(binary) {
|
|
@@ -4180,7 +4495,7 @@ function findStaleHookCommands(settings, binary) {
|
|
|
4180
4495
|
function countRegistered(settingsFile, binary) {
|
|
4181
4496
|
const settings = (() => {
|
|
4182
4497
|
try {
|
|
4183
|
-
return JSON.parse(
|
|
4498
|
+
return JSON.parse(fs2.readFileSync(settingsFile, "utf8"));
|
|
4184
4499
|
} catch {
|
|
4185
4500
|
return {};
|
|
4186
4501
|
}
|
|
@@ -4192,6 +4507,7 @@ function printStatus(options) {
|
|
|
4192
4507
|
const settingsFile = settingsPath(options);
|
|
4193
4508
|
const binary = hookBinPath();
|
|
4194
4509
|
const tokenFile = credentials?.toolInstallationId ? (0, import_tool_kit8.defaultTokenFilePath)(credentials.toolInstallationId) : void 0;
|
|
4510
|
+
const unpaired = localOnlyInstall(credentials);
|
|
4195
4511
|
const here = countRegistered(settingsFile, binary);
|
|
4196
4512
|
const settings = here.settings;
|
|
4197
4513
|
const registered = here.registered;
|
|
@@ -4199,10 +4515,15 @@ function printStatus(options) {
|
|
|
4199
4515
|
const otherFile = settingsPath(otherScope);
|
|
4200
4516
|
const elsewhere = registered === 0 && otherFile !== settingsFile ? countRegistered(otherFile, binary) : void 0;
|
|
4201
4517
|
const stale = findStaleHookCommands(settings, binary);
|
|
4518
|
+
console.log(`version ${(0, import_tool_kit8.describeCollectorVersion)()}`);
|
|
4202
4519
|
console.log(`api base url ${credentials?.apiBaseUrl ?? "\u2014 not configured"}`);
|
|
4203
|
-
console.log(`pairing ${credentials
|
|
4204
|
-
|
|
4205
|
-
|
|
4520
|
+
console.log(`pairing ${describePairing(credentials, unpaired)}`);
|
|
4521
|
+
const fileToken = Boolean(tokenFile && (0, import_tool_kit8.readTokenFile)(tokenFile));
|
|
4522
|
+
const token = fileToken || Boolean(envOverride("ASCENDA_EVENT_WRITE_TOKEN"));
|
|
4523
|
+
console.log(`token ${fileToken ? "present" : token ? "from ASCENDA_EVENT_WRITE_TOKEN (no file)" : unpaired ? "\u2014 none until this install is paired" : "\u2014 missing"}`);
|
|
4524
|
+
console.log(`delivery ${token ? "active" : unpaired ? "inactive \u2014 nothing is sent, and nothing is queued for later" : "\u2014 no token for this pairing, so nothing can be sent"}`);
|
|
4525
|
+
console.log("local features active \u2014 the session prompts and the live socket signal need no pairing");
|
|
4526
|
+
console.log(`hook binary ${fs2.existsSync(binary) ? binary : "\u2014 not installed"}`);
|
|
4206
4527
|
console.log(`hooks ${registered}/${HOOK_EVENTS.length} registered in ${settingsFile}`);
|
|
4207
4528
|
if (elsewhere && elsewhere.registered > 0) {
|
|
4208
4529
|
console.log(` ${elsewhere.registered}/${HOOK_EVENTS.length} found in ${otherFile} (--scope ${otherScope.scope})`);
|
|
@@ -4212,14 +4533,26 @@ function printStatus(options) {
|
|
|
4212
4533
|
for (const command of stale) console.log(` ${command}`);
|
|
4213
4534
|
console.log(` Remove them from ${settingsFile} by hand; setup cannot tell them from a hook you wrote.`);
|
|
4214
4535
|
}
|
|
4215
|
-
|
|
4536
|
+
if (unpaired) {
|
|
4537
|
+
console.log("\nInstalled, not paired. Pair when you want the telemetry half:");
|
|
4538
|
+
console.log(" npx @ascenda-one/claude-code-hooks pair");
|
|
4539
|
+
}
|
|
4540
|
+
const wired = registered === HOOK_EVENTS.length || options.scope === "project" && elsewhere?.registered === HOOK_EVENTS.length;
|
|
4541
|
+
const healthy = credentials?.toolInstallationId && wired && fs2.existsSync(binary) && !stale.length;
|
|
4216
4542
|
return healthy ? 0 : 1;
|
|
4217
4543
|
}
|
|
4544
|
+
function describePairing(credentials, unpaired) {
|
|
4545
|
+
if (!credentials?.toolInstallationId) return "\u2014 not paired";
|
|
4546
|
+
if (!unpaired) return credentials.toolInstallationId;
|
|
4547
|
+
const when = credentials.installedAt ? `, installed ${credentials.installedAt}` : "";
|
|
4548
|
+
return `${credentials.toolInstallationId} (not paired${when})`;
|
|
4549
|
+
}
|
|
4218
4550
|
function uninstall(options) {
|
|
4551
|
+
const unpaired = localOnlyInstall();
|
|
4219
4552
|
const settingsFile = settingsPath(options);
|
|
4220
|
-
if (
|
|
4553
|
+
if (fs2.existsSync(settingsFile)) {
|
|
4221
4554
|
try {
|
|
4222
|
-
const settings = JSON.parse(
|
|
4555
|
+
const settings = JSON.parse(fs2.readFileSync(settingsFile, "utf8"));
|
|
4223
4556
|
const hooks = { ...settings.hooks ?? {} };
|
|
4224
4557
|
for (const event of Object.keys(hooks)) {
|
|
4225
4558
|
const kept = hooks[event].filter((group) => !isOurs(group));
|
|
@@ -4228,8 +4561,8 @@ function uninstall(options) {
|
|
|
4228
4561
|
}
|
|
4229
4562
|
const updated = { ...settings, hooks };
|
|
4230
4563
|
if (!Object.keys(hooks).length) delete updated.hooks;
|
|
4231
|
-
|
|
4232
|
-
|
|
4564
|
+
fs2.copyFileSync(settingsFile, `${settingsFile}.ascenda-backup`);
|
|
4565
|
+
fs2.writeFileSync(settingsFile, `${JSON.stringify(updated, null, 2)}
|
|
4233
4566
|
`, "utf8");
|
|
4234
4567
|
console.log(`hooks removed from ${settingsFile}`);
|
|
4235
4568
|
} catch {
|
|
@@ -4238,19 +4571,19 @@ function uninstall(options) {
|
|
|
4238
4571
|
}
|
|
4239
4572
|
}
|
|
4240
4573
|
const binary = hookBinPath();
|
|
4241
|
-
if (
|
|
4242
|
-
|
|
4574
|
+
if (fs2.existsSync(binary)) {
|
|
4575
|
+
fs2.rmSync(binary);
|
|
4243
4576
|
console.log(`removed ${binary}`);
|
|
4244
4577
|
}
|
|
4245
|
-
const
|
|
4246
|
-
if (
|
|
4247
|
-
|
|
4248
|
-
console.log(`removed ${
|
|
4578
|
+
const credentialsFile2 = (0, import_tool_kit4.credentialsFilePath)();
|
|
4579
|
+
if (fs2.existsSync(credentialsFile2)) {
|
|
4580
|
+
removeCredentials();
|
|
4581
|
+
console.log(fs2.existsSync(credentialsFile2) ? `cleared the Claude Code pairing from ${credentialsFile2} (other tools' pairings kept)` : `removed ${credentialsFile2}`);
|
|
4249
4582
|
}
|
|
4250
|
-
console.log(`tokens left in ${path2.join((0, import_tool_kit8.ascendaHome)(), "tokens")} \u2014 revoke in the Ascenda app to invalidate them`);
|
|
4583
|
+
console.log(unpaired ? "this install was never paired, so there is no token here and nothing to revoke" : `tokens left in ${path2.join((0, import_tool_kit8.ascendaHome)(), "tokens")} \u2014 revoke in the Ascenda app to invalidate them`);
|
|
4251
4584
|
return 0;
|
|
4252
4585
|
}
|
|
4253
|
-
var import_tool_kit8, HOOK_EVENTS, HOOK_TIMEOUT_SECONDS, HOOK_MARKER, USAGE;
|
|
4586
|
+
var import_tool_kit8, HOOK_EVENTS, HOOK_TIMEOUT_SECONDS, HOOK_MARKER, SENDS, USAGE, POLL_ERROR_TOLERANCE;
|
|
4254
4587
|
var init_setup = __esm({
|
|
4255
4588
|
"src/setup.ts"() {
|
|
4256
4589
|
"use strict";
|
|
@@ -4258,9 +4591,10 @@ var init_setup = __esm({
|
|
|
4258
4591
|
init_config();
|
|
4259
4592
|
init_paths();
|
|
4260
4593
|
init_types();
|
|
4261
|
-
HOOK_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PostToolUseFailure", "PreCompact", "PostCompact", "Stop", "Notification"];
|
|
4594
|
+
HOOK_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PostToolUseFailure", "PreCompact", "PostCompact", "Stop", "Notification", "SessionEnd"];
|
|
4262
4595
|
HOOK_TIMEOUT_SECONDS = 5;
|
|
4263
4596
|
HOOK_MARKER = "ascenda-claude-hook";
|
|
4597
|
+
SENDS = ["model", "posture", "git", "edits", "waiting"];
|
|
4264
4598
|
USAGE = `ascenda-claude-hook setup \u2014 wire Claude Code to Ascenda telemetry
|
|
4265
4599
|
|
|
4266
4600
|
npx @ascenda-one/claude-code-hooks setup [options]
|
|
@@ -4277,18 +4611,21 @@ Options
|
|
|
4277
4611
|
--local [port] shorthand for the local dev server (default port 4477)
|
|
4278
4612
|
--tool-installation-id <id> reuse an existing pairing instead of creating one
|
|
4279
4613
|
--token <eventWriteToken> reuse an existing token (stored 0600, never printed)
|
|
4614
|
+
--no-pair install without pairing: local features on, nothing sent
|
|
4615
|
+
(--no-pairing is accepted too)
|
|
4280
4616
|
--scope project|user where hooks are registered (default project)
|
|
4281
4617
|
--project-dir <path> project root for --scope project (default cwd)
|
|
4282
4618
|
--dry-run print what would change, write nothing
|
|
4283
4619
|
-h, --help
|
|
4284
4620
|
`;
|
|
4621
|
+
POLL_ERROR_TOLERANCE = 3;
|
|
4285
4622
|
}
|
|
4286
4623
|
});
|
|
4287
4624
|
|
|
4288
4625
|
// src/cli.ts
|
|
4289
4626
|
var import_tool_kit9 = __toESM(require_out2(), 1);
|
|
4290
4627
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
4291
|
-
import * as
|
|
4628
|
+
import * as fs3 from "node:fs";
|
|
4292
4629
|
|
|
4293
4630
|
// src/ascendaClient.ts
|
|
4294
4631
|
var import_tool_kit = __toESM(require_out2(), 1);
|
|
@@ -4304,6 +4641,7 @@ var AscendaClient = class {
|
|
|
4304
4641
|
tokenFilePath: config.tokenFilePath,
|
|
4305
4642
|
stateFilePath: config.stateFilePath,
|
|
4306
4643
|
outboxFilePath: config.outboxFilePath,
|
|
4644
|
+
renewToken: config.renewToken,
|
|
4307
4645
|
sessionId: config.sessionId,
|
|
4308
4646
|
workspaceHash: config.workspaceHash,
|
|
4309
4647
|
projectHash: config.projectHash
|
|
@@ -4316,6 +4654,10 @@ var AscendaClient = class {
|
|
|
4316
4654
|
async send(mapped) {
|
|
4317
4655
|
return this.sender.send(mapped);
|
|
4318
4656
|
}
|
|
4657
|
+
/** Outbox only, no network. See {@link AscendaEventSender.queue}. */
|
|
4658
|
+
queue(mapped) {
|
|
4659
|
+
return this.sender.queue(mapped);
|
|
4660
|
+
}
|
|
4319
4661
|
async renewEventToken() {
|
|
4320
4662
|
return this.sender.renewEventToken();
|
|
4321
4663
|
}
|
|
@@ -4336,9 +4678,10 @@ function mapClaudeEvent(hookName, input) {
|
|
|
4336
4678
|
const events = mapEvent(hookName, input);
|
|
4337
4679
|
if (events.length === 0) return events;
|
|
4338
4680
|
const branchHash = (0, import_tool_kit7.deriveBranchHashForCwd)((0, import_tool_kit6.getString)(input, ["cwd"]) ?? process.cwd());
|
|
4681
|
+
const runtime = claudeRuntime();
|
|
4339
4682
|
return events.map((event) => ({
|
|
4340
4683
|
...event,
|
|
4341
|
-
metadata: { host: CLAUDE_HOST, ...branchHash ? { branchHash } : {}, ...event.metadata }
|
|
4684
|
+
metadata: { host: CLAUDE_HOST, runtime, ...branchHash ? { branchHash } : {}, ...event.metadata }
|
|
4342
4685
|
}));
|
|
4343
4686
|
}
|
|
4344
4687
|
function mapEvent(hookName, input) {
|
|
@@ -4364,6 +4707,8 @@ function mapEvent(hookName, input) {
|
|
|
4364
4707
|
return mapStop(input);
|
|
4365
4708
|
case "Notification":
|
|
4366
4709
|
return mapNotification(input);
|
|
4710
|
+
case "SessionEnd":
|
|
4711
|
+
return mapSessionEnd(input);
|
|
4367
4712
|
default:
|
|
4368
4713
|
return [];
|
|
4369
4714
|
}
|
|
@@ -4392,6 +4737,23 @@ function mapSessionStart(input) {
|
|
|
4392
4737
|
}
|
|
4393
4738
|
}];
|
|
4394
4739
|
}
|
|
4740
|
+
function mapSessionEnd(input) {
|
|
4741
|
+
const raw = input["reason"];
|
|
4742
|
+
return [{
|
|
4743
|
+
eventType: "recovery_offline_period",
|
|
4744
|
+
severity: "low",
|
|
4745
|
+
metadata: {
|
|
4746
|
+
activity: "session_ended",
|
|
4747
|
+
...raw === void 0 || raw === null ? {} : { sessionEndReason: classifySessionEndReason(raw) }
|
|
4748
|
+
}
|
|
4749
|
+
}];
|
|
4750
|
+
}
|
|
4751
|
+
function classifySessionEndReason(raw) {
|
|
4752
|
+
if (typeof raw !== "string") return "unknown";
|
|
4753
|
+
const value = raw.trim().toLowerCase();
|
|
4754
|
+
return SESSION_END_REASONS.includes(value) ? value : "unknown";
|
|
4755
|
+
}
|
|
4756
|
+
var SESSION_END_REASONS = ["clear", "resume", "logout", "prompt_input_exit", "other"];
|
|
4395
4757
|
function mapUserPromptSubmit(input) {
|
|
4396
4758
|
const prompt = (0, import_tool_kit6.getString)(input, ["prompt", "userPrompt", "message"]) ?? (0, import_tool_kit6.getNestedString)(input, [["payload", "prompt"], ["payload", "message"]]);
|
|
4397
4759
|
const autonomy = autonomyModeMetadata(input);
|
|
@@ -4591,13 +4953,21 @@ init_types();
|
|
|
4591
4953
|
var INTENTION_INVITE = "Ascenda tip: if it's natural, you can ask what would make this session count before diving in \u2014 one line is enough. Not a required step, and skip it entirely if the user is already mid-task.";
|
|
4592
4954
|
var MILESTONE_DEBRIEF_INVITE = "Ascenda tip: that finished a piece of work. If the moment suits, it's worth a short debrief \u2014 what moved, what's still unresolved, and what you'd do differently next time. One or two lines. Skip it if they're already onto the next thing.";
|
|
4593
4955
|
async function runPair() {
|
|
4594
|
-
const
|
|
4956
|
+
const credentials = readCredentials();
|
|
4957
|
+
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? credentials?.apiBaseUrl ?? "https://api.ascenda.one").replace(/\/$/, "");
|
|
4595
4958
|
const flagIndex = process.argv.indexOf("--tool-type");
|
|
4596
4959
|
const requestedType = flagIndex !== -1 ? (process.argv[flagIndex + 1] ?? "").trim() : "";
|
|
4597
4960
|
const toolType = requestedType || ASCENDA_TOOL_TYPE;
|
|
4598
|
-
const existing = process.env.ASCENDA_TOOL_INSTALLATION_ID?.trim();
|
|
4961
|
+
const existing = process.env.ASCENDA_TOOL_INSTALLATION_ID?.trim() || credentials?.toolInstallationId?.trim();
|
|
4599
4962
|
const reusable = existing && existing.includes(":") && (!requestedType || existing.startsWith(`${requestedType}:`));
|
|
4600
4963
|
const toolInstallationId = reusable ? existing : `${toolType}:${randomUUID2()}`;
|
|
4964
|
+
const isClaudeCode = toolType === ASCENDA_TOOL_TYPE;
|
|
4965
|
+
const { SENDS: SENDS2 } = isClaudeCode ? await Promise.resolve().then(() => (init_setup(), setup_exports)) : { SENDS: [] };
|
|
4966
|
+
await writeStdout(
|
|
4967
|
+
`
|
|
4968
|
+
${(0, import_tool_kit9.renderSetupDisclosure)({ sends: SENDS2, displayName: isClaudeCode ? "Claude Code" : toolType })}
|
|
4969
|
+
`
|
|
4970
|
+
);
|
|
4601
4971
|
const session = await (0, import_tool_kit9.createPairingSession)(apiBaseUrl, toolInstallationId, toolType, toolType === ASCENDA_TOOL_TYPE ? "Claude Code" : toolType);
|
|
4602
4972
|
const code = session.deviceCode ?? session.code;
|
|
4603
4973
|
await writeStdout(
|
|
@@ -4699,9 +5069,13 @@ async function main() {
|
|
|
4699
5069
|
try {
|
|
4700
5070
|
config = loadConfigFromEnv();
|
|
4701
5071
|
} catch (error) {
|
|
4702
|
-
|
|
5072
|
+
const unpaired = localOnlyInstall();
|
|
5073
|
+
if (!unpaired && error instanceof MissingInstallationIdError) journalSkippedSend(error);
|
|
4703
5074
|
const logFile = (0, import_tool_kit9.resolveEventLogPath)();
|
|
4704
|
-
if (!logFile)
|
|
5075
|
+
if (!logFile) {
|
|
5076
|
+
if (unpaired) return;
|
|
5077
|
+
throw error;
|
|
5078
|
+
}
|
|
4705
5079
|
for (const event of mappedEvents) {
|
|
4706
5080
|
logUnsent(logFile, event, workContext, (0, import_tool_kit9.getString)(input, ["session_id", "sessionId"]) ?? null);
|
|
4707
5081
|
}
|
|
@@ -4711,6 +5085,12 @@ async function main() {
|
|
|
4711
5085
|
config.projectHash ??= workContext?.projectHash ?? null;
|
|
4712
5086
|
config.sessionId ??= (0, import_tool_kit9.getString)(input, ["session_id", "sessionId"]) ?? null;
|
|
4713
5087
|
const client = new AscendaClient(config);
|
|
5088
|
+
if (hookName === "SessionEnd") {
|
|
5089
|
+
for (const event of mappedEvents) {
|
|
5090
|
+
if (!client.queue(event)) console.error("Ascenda telemetry not kept: the session end could not be written to the outbox.");
|
|
5091
|
+
}
|
|
5092
|
+
return;
|
|
5093
|
+
}
|
|
4714
5094
|
for (const event of mappedEvents) {
|
|
4715
5095
|
const result = await client.send(event);
|
|
4716
5096
|
if (result === "accepted") continue;
|
|
@@ -4794,6 +5174,7 @@ function writeStdout(text) {
|
|
|
4794
5174
|
async function runDoctor() {
|
|
4795
5175
|
const lines = ["Ascenda collector doctor", ""];
|
|
4796
5176
|
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? "https://api.ascenda.one").replace(/\/$/, "");
|
|
5177
|
+
const unpaired = localOnlyInstall();
|
|
4797
5178
|
lines.push(` API base URL ${apiBaseUrl}`);
|
|
4798
5179
|
let resolved;
|
|
4799
5180
|
try {
|
|
@@ -4811,12 +5192,14 @@ async function runDoctor() {
|
|
|
4811
5192
|
lines.push(` Id source ${describeIdSource(resolved)}`);
|
|
4812
5193
|
const tokenFilePath = process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0, import_tool_kit9.defaultTokenFilePath)(toolInstallationId);
|
|
4813
5194
|
lines.push(` Token file ${tokenFilePath}`);
|
|
4814
|
-
lines.push(` Token ${describeToken(tokenFilePath)}`);
|
|
5195
|
+
lines.push(` Token ${describeToken(tokenFilePath, unpaired)}`);
|
|
5196
|
+
const hasToken = fs3.existsSync(tokenFilePath) || Boolean(process.env.ASCENDA_EVENT_WRITE_TOKEN);
|
|
5197
|
+
lines.push(` Mode ${unpaired ? "installed, not paired \u2014 local features active, telemetry inactive" : hasToken ? "paired \u2014 local features and telemetry active" : "paired, but no token on this machine \u2014 local features active, nothing can be sent"}`);
|
|
4815
5198
|
const stateFilePath = resolveStateFilePath(toolInstallationId);
|
|
4816
5199
|
lines.push(` Journal ${stateFilePath}`);
|
|
4817
5200
|
const state = (0, import_tool_kit9.readCollectorState)(stateFilePath);
|
|
4818
5201
|
if (!state) {
|
|
4819
|
-
lines.push(" Last outcome (no journal yet \u2014 no send attempted since this version was installed)");
|
|
5202
|
+
lines.push(unpaired ? " Last outcome (none \u2014 nothing is sent from an install with no pairing)" : " Last outcome (no journal yet \u2014 no send attempted since this version was installed)");
|
|
4820
5203
|
} else {
|
|
4821
5204
|
lines.push(` Last attempt ${state.lastAttemptAt}`);
|
|
4822
5205
|
lines.push(` Last success ${state.lastSuccessAt ?? "never"}`);
|
|
@@ -4828,6 +5211,18 @@ async function runDoctor() {
|
|
|
4828
5211
|
}
|
|
4829
5212
|
lines.push(...skippedSendLines(stateFilePath));
|
|
4830
5213
|
lines.push(...outboxLines(toolInstallationId, state));
|
|
5214
|
+
if (unpaired) {
|
|
5215
|
+
lines.push(
|
|
5216
|
+
"",
|
|
5217
|
+
" Nothing is sent from this install, and nothing is queued for later. The",
|
|
5218
|
+
" session prompts and the live signal to a socket on this machine run",
|
|
5219
|
+
" without a pairing. To turn delivery on:",
|
|
5220
|
+
" npx @ascenda-one/claude-code-hooks pair"
|
|
5221
|
+
);
|
|
5222
|
+
await writeStdout(`${lines.join("\n")}
|
|
5223
|
+
`);
|
|
5224
|
+
return;
|
|
5225
|
+
}
|
|
4831
5226
|
lines.push("", " Live round trip...");
|
|
4832
5227
|
lines.push(` ${await liveRoundTrip()}`);
|
|
4833
5228
|
await writeStdout(`${lines.join("\n")}
|
|
@@ -4897,12 +5292,13 @@ function describeAge(isoTimestamp) {
|
|
|
4897
5292
|
if (hours < 48) return `${hours}h ${minutes % 60}m`;
|
|
4898
5293
|
return `${Math.floor(hours / 24)}d ${hours % 24}h`;
|
|
4899
5294
|
}
|
|
4900
|
-
function describeToken(tokenFilePath) {
|
|
5295
|
+
function describeToken(tokenFilePath, unpaired) {
|
|
4901
5296
|
try {
|
|
4902
|
-
if (!
|
|
4903
|
-
|
|
5297
|
+
if (!fs3.existsSync(tokenFilePath)) {
|
|
5298
|
+
if (process.env.ASCENDA_EVENT_WRITE_TOKEN) return "from ASCENDA_EVENT_WRITE_TOKEN (no file)";
|
|
5299
|
+
return unpaired ? "none \u2014 this install has no pairing" : "MISSING \u2014 run `pair`";
|
|
4904
5300
|
}
|
|
4905
|
-
const stat =
|
|
5301
|
+
const stat = fs3.statSync(tokenFilePath);
|
|
4906
5302
|
const ageDays = Math.floor((Date.now() - stat.mtimeMs) / 864e5);
|
|
4907
5303
|
return `present, last written ${stat.mtime.toISOString()} (${ageDays}d ago)`;
|
|
4908
5304
|
} catch (error) {
|