@ascenda-one/codex-hooks 0.1.27 → 0.1.33
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 +12 -7
- package/dist/cli.js +1579 -102
- package/dist/cli.js.map +1 -1
- package/dist/liveSignal.js +9 -4
- package/dist/liveSignal.js.map +1 -1
- package/dist/setup.js +3 -0
- package/dist/setup.js.map +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -407,39 +407,44 @@ var require_metricKeys = __commonJS({
|
|
|
407
407
|
exports.METRIC_KEYS = {
|
|
408
408
|
// ── Read by a backend reader ────────────────────────────────────────────
|
|
409
409
|
contextWindowPeakPct: {
|
|
410
|
+
family: "context",
|
|
410
411
|
readBy: ["backend", "handoff"],
|
|
411
412
|
backendAliases: CONTEXT_WINDOW_CANONICAL_ALIASES,
|
|
412
413
|
unit: "fraction of the context window (0\u20131; uncapped for >200k contexts)",
|
|
413
414
|
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."
|
|
414
415
|
},
|
|
415
416
|
contextUsagePercent: {
|
|
417
|
+
family: "context",
|
|
416
418
|
readBy: ["backend", "handoff"],
|
|
417
419
|
backendAliases: CONTEXT_WINDOW_CURSOR_PERCENT_ALIASES,
|
|
418
420
|
unit: "percent (0\u2013100)",
|
|
419
421
|
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."
|
|
420
422
|
},
|
|
421
|
-
promptCount: { readBy: ["backend", "handoff"], backendAliases: ["promptCount", "prompt_count"] },
|
|
422
|
-
sessionMinutes: { readBy: ["backend"], backendAliases: ["sessionMinutes", "session_minutes"], unit: "minutes" },
|
|
423
|
-
durationBucket: { readBy: ["backend", "handoff"], backendAliases: ["durationBucket", "duration_bucket"] },
|
|
424
|
-
afterHoursPrompts: { readBy: ["backend", "handoff"], backendAliases: ["afterHoursPrompts", "after_hours_prompts"] },
|
|
425
|
-
inputTokens: { readBy: ["backend"], backendAliases: ["inputTokens", "input_tokens"], unit: "tokens" },
|
|
426
|
-
outputTokens: { readBy: ["backend"], backendAliases: ["outputTokens", "output_tokens"], unit: "tokens" },
|
|
427
|
-
cacheReadTokens: { readBy: ["backend"], backendAliases: ["cacheReadTokens", "cache_read_tokens"], unit: "tokens" },
|
|
428
|
-
queuedPrompts: { readBy: ["backend"], backendAliases: ["queuedPrompts", "queued_prompts"] },
|
|
429
|
-
linesChangedBucket: { readBy: ["backend"], backendAliases: ["linesChangedBucket", "lines_changed_bucket"] },
|
|
423
|
+
promptCount: { family: "counts", readBy: ["backend", "handoff"], backendAliases: ["promptCount", "prompt_count"] },
|
|
424
|
+
sessionMinutes: { family: "session", readBy: ["backend"], backendAliases: ["sessionMinutes", "session_minutes"], unit: "minutes" },
|
|
425
|
+
durationBucket: { family: "session", readBy: ["backend", "handoff"], backendAliases: ["durationBucket", "duration_bucket"] },
|
|
426
|
+
afterHoursPrompts: { family: "clock", readBy: ["backend", "handoff"], backendAliases: ["afterHoursPrompts", "after_hours_prompts"] },
|
|
427
|
+
inputTokens: { family: "context", readBy: ["backend"], backendAliases: ["inputTokens", "input_tokens"], unit: "tokens" },
|
|
428
|
+
outputTokens: { family: "context", readBy: ["backend"], backendAliases: ["outputTokens", "output_tokens"], unit: "tokens" },
|
|
429
|
+
cacheReadTokens: { family: "context", readBy: ["backend"], backendAliases: ["cacheReadTokens", "cache_read_tokens"], unit: "tokens" },
|
|
430
|
+
queuedPrompts: { family: "counts", readBy: ["backend"], backendAliases: ["queuedPrompts", "queued_prompts"] },
|
|
431
|
+
linesChangedBucket: { family: "edits", readBy: ["backend"], backendAliases: ["linesChangedBucket", "lines_changed_bucket"] },
|
|
430
432
|
// ── Read by the local handoff only ──────────────────────────────────────
|
|
431
|
-
activeMinutes: { readBy: ["handoff"], unit: "minutes" },
|
|
433
|
+
activeMinutes: { family: "session", readBy: ["handoff"], unit: "minutes" },
|
|
432
434
|
syntheticPromptLines: {
|
|
435
|
+
family: "reading",
|
|
433
436
|
readBy: ["handoff"],
|
|
434
437
|
unit: "lines",
|
|
435
438
|
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."
|
|
436
439
|
},
|
|
437
440
|
dispatchedPromptLines: {
|
|
441
|
+
family: "reading",
|
|
438
442
|
readBy: ["handoff"],
|
|
439
443
|
unit: "lines",
|
|
440
444
|
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."
|
|
441
445
|
},
|
|
442
446
|
interruptedRuns: {
|
|
447
|
+
family: "waiting",
|
|
443
448
|
readBy: ["handoff"],
|
|
444
449
|
unit: "runs",
|
|
445
450
|
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."
|
|
@@ -455,11 +460,13 @@ var require_metricKeys = __commonJS({
|
|
|
455
460
|
* they are.
|
|
456
461
|
*/
|
|
457
462
|
handsOnMinutes: {
|
|
463
|
+
family: "session",
|
|
458
464
|
readBy: ["handoff"],
|
|
459
465
|
unit: "minutes",
|
|
460
466
|
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."
|
|
461
467
|
},
|
|
462
468
|
agentSupervisingMinutes: {
|
|
469
|
+
family: "session",
|
|
463
470
|
readBy: ["handoff"],
|
|
464
471
|
unit: "minutes",
|
|
465
472
|
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."
|
|
@@ -469,127 +476,147 @@ var require_metricKeys = __commonJS({
|
|
|
469
476
|
// a complete one, and a reader that ignores them is choosing to, rather than
|
|
470
477
|
// being unable to.
|
|
471
478
|
activeSplitInstants: {
|
|
479
|
+
family: "session",
|
|
472
480
|
readBy: ["diagnostic"],
|
|
473
481
|
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."
|
|
474
482
|
},
|
|
475
483
|
activeSplitUndatedLines: {
|
|
484
|
+
family: "session",
|
|
476
485
|
readBy: ["diagnostic"],
|
|
477
486
|
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."
|
|
478
487
|
},
|
|
479
488
|
activeSplitUnposturedInstants: {
|
|
489
|
+
family: "posture",
|
|
480
490
|
readBy: ["diagnostic"],
|
|
481
491
|
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."
|
|
482
492
|
},
|
|
483
|
-
afterHoursRequests: { readBy: ["handoff"] },
|
|
484
|
-
approximateLintErrorsCount: { readBy: ["handoff"] },
|
|
485
|
-
canceledCount: { readBy: ["handoff"] },
|
|
486
|
-
chatEditCount: { readBy: ["handoff"] },
|
|
493
|
+
afterHoursRequests: { family: "clock", readBy: ["handoff"] },
|
|
494
|
+
approximateLintErrorsCount: { family: "outcome", readBy: ["handoff"] },
|
|
495
|
+
canceledCount: { family: "outcome", readBy: ["handoff"] },
|
|
496
|
+
chatEditCount: { family: "edits", readBy: ["handoff"] },
|
|
487
497
|
compactionCount: {
|
|
498
|
+
family: "context",
|
|
488
499
|
readBy: ["handoff"],
|
|
489
500
|
note: "The backend counts context_compression_* event rows, not this key. Both are emitted; this one is for the handoff."
|
|
490
501
|
},
|
|
491
502
|
contextWindowPeakTokens: {
|
|
503
|
+
family: "context",
|
|
492
504
|
readBy: ["handoff"],
|
|
493
505
|
unit: "tokens",
|
|
494
506
|
note: "The measured quantity, with no assumed denominator. Prefer this to the ratio for any within-person baseline."
|
|
495
507
|
},
|
|
496
508
|
contextWindowTokens: {
|
|
509
|
+
family: "context",
|
|
497
510
|
readBy: ["handoff"],
|
|
498
511
|
unit: "tokens",
|
|
499
512
|
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."
|
|
500
513
|
},
|
|
501
|
-
date: { readBy: ["handoff"] },
|
|
502
|
-
errorCount: { readBy: ["handoff"] },
|
|
503
|
-
filesChangedCount: { readBy: ["handoff"] },
|
|
504
|
-
humanChangesCount: { readBy: ["handoff"] },
|
|
505
|
-
linesAdded: { readBy: ["handoff"] },
|
|
506
|
-
linesRemoved: { readBy: ["handoff"] },
|
|
507
|
-
primaryModel: {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
514
|
+
date: { family: "clock", readBy: ["handoff"] },
|
|
515
|
+
errorCount: { family: "outcome", readBy: ["handoff"] },
|
|
516
|
+
filesChangedCount: { family: "edits", readBy: ["handoff"] },
|
|
517
|
+
humanChangesCount: { family: "edits", readBy: ["handoff"] },
|
|
518
|
+
linesAdded: { family: "edits", readBy: ["handoff"] },
|
|
519
|
+
linesRemoved: { family: "edits", readBy: ["handoff"] },
|
|
520
|
+
primaryModel: {
|
|
521
|
+
family: "model",
|
|
522
|
+
readBy: ["backend", "handoff"],
|
|
523
|
+
backendAliases: ["primaryModel", "primary_model"],
|
|
524
|
+
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."
|
|
525
|
+
},
|
|
526
|
+
requestCount: { family: "counts", readBy: ["handoff"] },
|
|
527
|
+
sessionStartedAt: { family: "session", readBy: ["handoff"] },
|
|
528
|
+
subagentComposers: { family: "counts", readBy: ["handoff"] },
|
|
511
529
|
subagentToolCallCount: {
|
|
530
|
+
family: "tools",
|
|
512
531
|
readBy: ["handoff"],
|
|
513
532
|
note: "Claude Code only: calls made inside subagent transcripts, kept out of toolCallCount so the main-loop count matches what the wire events carry."
|
|
514
533
|
},
|
|
515
|
-
subagentTranscripts: { readBy: ["handoff"] },
|
|
534
|
+
subagentTranscripts: { family: "counts", readBy: ["handoff"] },
|
|
516
535
|
toolCallCount: {
|
|
536
|
+
family: "tools",
|
|
517
537
|
readBy: ["handoff"],
|
|
518
538
|
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."
|
|
519
539
|
},
|
|
520
540
|
toolCallsUndated: {
|
|
541
|
+
family: "tools",
|
|
521
542
|
readBy: ["handoff"],
|
|
522
543
|
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."
|
|
523
544
|
},
|
|
524
|
-
toolFailureCount: { readBy: ["handoff"] },
|
|
525
|
-
totalEntryCount: { readBy: ["handoff"] },
|
|
545
|
+
toolFailureCount: { family: "outcome", readBy: ["handoff"] },
|
|
546
|
+
totalEntryCount: { family: "counts", readBy: ["handoff"] },
|
|
526
547
|
userModifiedEditCount: {
|
|
548
|
+
family: "edits",
|
|
527
549
|
readBy: ["handoff"],
|
|
528
550
|
note: "Null, never 0 \u2014 Claude Code never sets userModified true, so 0 would assert 'no AI edit was ever corrected by hand'."
|
|
529
551
|
},
|
|
530
552
|
// ── Diagnostic: read by nobody, on purpose ──────────────────────────────
|
|
531
|
-
abandonedPromptCount: { readBy: ["diagnostic"] },
|
|
553
|
+
abandonedPromptCount: { family: "counts", readBy: ["diagnostic"] },
|
|
532
554
|
// Epoch-marker metrics. The marker is local-only and never reaches the wire
|
|
533
555
|
// (see EXTRACTION_EPOCH_KIND), but it travels as a NormalizedHistoricalEvent
|
|
534
556
|
// and so is keyed by the same vocabulary.
|
|
535
|
-
windowOldest: { readBy: ["handoff"], note: "Oldest event the extraction saw \u2014 the marker's left edge." },
|
|
536
|
-
windowNewest: { readBy: ["handoff"], note: "Newest event the extraction saw \u2014 the marker's right edge." },
|
|
537
|
-
projectsWithNoReadableTranscript: { readBy: ["diagnostic"] },
|
|
538
|
-
unparsedComposerHeaders: { readBy: ["diagnostic"] },
|
|
539
|
-
unknownComposerHeaderTypes: { readBy: ["diagnostic"] },
|
|
540
|
-
orphanedBubbles: { readBy: ["diagnostic"] },
|
|
541
|
-
orphanedSubagentBubbles: { readBy: ["diagnostic"] },
|
|
542
|
-
sessionsWithoutTimeline: { readBy: ["diagnostic"] },
|
|
557
|
+
windowOldest: { family: "session", readBy: ["handoff"], note: "Oldest event the extraction saw \u2014 the marker's left edge." },
|
|
558
|
+
windowNewest: { family: "session", readBy: ["handoff"], note: "Newest event the extraction saw \u2014 the marker's right edge." },
|
|
559
|
+
projectsWithNoReadableTranscript: { family: "reading", readBy: ["diagnostic"] },
|
|
560
|
+
unparsedComposerHeaders: { family: "reading", readBy: ["diagnostic"] },
|
|
561
|
+
unknownComposerHeaderTypes: { family: "reading", readBy: ["diagnostic"] },
|
|
562
|
+
orphanedBubbles: { family: "reading", readBy: ["diagnostic"] },
|
|
563
|
+
orphanedSubagentBubbles: { family: "reading", readBy: ["diagnostic"] },
|
|
564
|
+
sessionsWithoutTimeline: { family: "reading", readBy: ["diagnostic"] },
|
|
543
565
|
sessionsWithOnlyInheritedLines: {
|
|
566
|
+
family: "reading",
|
|
544
567
|
readBy: ["diagnostic"],
|
|
545
568
|
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."
|
|
546
569
|
},
|
|
547
|
-
emptyComposers: { readBy: ["diagnostic"] },
|
|
548
|
-
apiErrorCount: { readBy: ["diagnostic"] },
|
|
549
|
-
assistantTurns: { readBy: ["diagnostic"] },
|
|
550
|
-
compactionAutoCount: { readBy: ["diagnostic"] },
|
|
551
|
-
compactionManualCount: { readBy: ["diagnostic"] },
|
|
552
|
-
editDayCount: { readBy: ["diagnostic"] },
|
|
553
|
-
emptyChatSessions: { readBy: ["diagnostic"] },
|
|
554
|
-
gitBranch: { readBy: ["diagnostic"] },
|
|
555
|
-
linesChanged: { readBy: ["diagnostic"] },
|
|
556
|
-
malformedChatSessionLines: { readBy: ["diagnostic"] },
|
|
557
|
-
malformedHistoryEntries: { readBy: ["diagnostic"] },
|
|
558
|
-
mode: { readBy: ["diagnostic"] },
|
|
559
|
-
modelCount: { readBy: ["diagnostic"] },
|
|
560
|
-
modelSwitchCount: { readBy: ["diagnostic"] },
|
|
561
|
-
rapidRepromptCount: { readBy: ["diagnostic"] },
|
|
562
|
-
schemaUnreadable: { readBy: ["diagnostic"] },
|
|
563
|
-
sessionCount: { readBy: ["diagnostic"] },
|
|
564
|
-
sessionsFromBubbleTimeline: { readBy: ["diagnostic"] },
|
|
565
|
-
sessionsFromCheckpointTimeline: { readBy: ["diagnostic"] },
|
|
566
|
-
sessionsFromRecencyTimeline: { readBy: ["diagnostic"] },
|
|
567
|
-
subagentAssistantTurns: { readBy: ["diagnostic"] },
|
|
568
|
-
subagentPrompts: { readBy: ["diagnostic"] },
|
|
569
|
-
subagentTokensTotal: { readBy: ["diagnostic"] },
|
|
570
|
+
emptyComposers: { family: "reading", readBy: ["diagnostic"] },
|
|
571
|
+
apiErrorCount: { family: "outcome", readBy: ["diagnostic"] },
|
|
572
|
+
assistantTurns: { family: "counts", readBy: ["diagnostic"] },
|
|
573
|
+
compactionAutoCount: { family: "context", readBy: ["diagnostic"] },
|
|
574
|
+
compactionManualCount: { family: "context", readBy: ["diagnostic"] },
|
|
575
|
+
editDayCount: { family: "clock", readBy: ["diagnostic"] },
|
|
576
|
+
emptyChatSessions: { family: "reading", readBy: ["diagnostic"] },
|
|
577
|
+
gitBranch: { family: "repo", readBy: ["diagnostic"] },
|
|
578
|
+
linesChanged: { family: "edits", readBy: ["diagnostic"] },
|
|
579
|
+
malformedChatSessionLines: { family: "reading", readBy: ["diagnostic"] },
|
|
580
|
+
malformedHistoryEntries: { family: "reading", readBy: ["diagnostic"] },
|
|
581
|
+
mode: { family: "posture", readBy: ["diagnostic"] },
|
|
582
|
+
modelCount: { family: "model", readBy: ["diagnostic"] },
|
|
583
|
+
modelSwitchCount: { family: "model", readBy: ["diagnostic"] },
|
|
584
|
+
rapidRepromptCount: { family: "counts", readBy: ["diagnostic"] },
|
|
585
|
+
schemaUnreadable: { family: "reading", readBy: ["diagnostic"] },
|
|
586
|
+
sessionCount: { family: "session", readBy: ["diagnostic"] },
|
|
587
|
+
sessionsFromBubbleTimeline: { family: "reading", readBy: ["diagnostic"] },
|
|
588
|
+
sessionsFromCheckpointTimeline: { family: "reading", readBy: ["diagnostic"] },
|
|
589
|
+
sessionsFromRecencyTimeline: { family: "reading", readBy: ["diagnostic"] },
|
|
590
|
+
subagentAssistantTurns: { family: "counts", readBy: ["diagnostic"] },
|
|
591
|
+
subagentPrompts: { family: "counts", readBy: ["diagnostic"] },
|
|
592
|
+
subagentTokensTotal: { family: "context", readBy: ["diagnostic"] },
|
|
570
593
|
toolName: {
|
|
571
|
-
|
|
572
|
-
|
|
594
|
+
family: "tools",
|
|
595
|
+
readBy: ["backend"],
|
|
596
|
+
backendAliases: ["toolName", "tool_name"],
|
|
597
|
+
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."
|
|
573
598
|
},
|
|
574
|
-
toolResultCount: { readBy: ["diagnostic"] },
|
|
575
|
-
toolResultErrorCount: { readBy: ["diagnostic"] },
|
|
576
|
-
unknownBubbles: { readBy: ["diagnostic"] },
|
|
577
|
-
unknownLines: { readBy: ["diagnostic"] },
|
|
599
|
+
toolResultCount: { family: "tools", readBy: ["diagnostic"] },
|
|
600
|
+
toolResultErrorCount: { family: "outcome", readBy: ["diagnostic"] },
|
|
601
|
+
unknownBubbles: { family: "reading", readBy: ["diagnostic"] },
|
|
602
|
+
unknownLines: { family: "reading", readBy: ["diagnostic"] },
|
|
578
603
|
metaLines: {
|
|
604
|
+
family: "reading",
|
|
579
605
|
readBy: ["diagnostic"],
|
|
580
606
|
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.'
|
|
581
607
|
},
|
|
582
|
-
unparsedBubbles: { readBy: ["diagnostic"] },
|
|
583
|
-
unparsedChatSessionFiles: { readBy: ["diagnostic"] },
|
|
584
|
-
unparsedHistoryFiles: { readBy: ["diagnostic"] },
|
|
585
|
-
unparsedLines: { readBy: ["diagnostic"] },
|
|
586
|
-
unreadableChatSessionFiles: { readBy: ["diagnostic"] },
|
|
587
|
-
unreadableHistoryFiles: { readBy: ["diagnostic"] },
|
|
608
|
+
unparsedBubbles: { family: "reading", readBy: ["diagnostic"] },
|
|
609
|
+
unparsedChatSessionFiles: { family: "reading", readBy: ["diagnostic"] },
|
|
610
|
+
unparsedHistoryFiles: { family: "reading", readBy: ["diagnostic"] },
|
|
611
|
+
unparsedLines: { family: "reading", readBy: ["diagnostic"] },
|
|
612
|
+
unreadableChatSessionFiles: { family: "reading", readBy: ["diagnostic"] },
|
|
613
|
+
unreadableHistoryFiles: { family: "reading", readBy: ["diagnostic"] },
|
|
588
614
|
unreadableRolloutFiles: {
|
|
615
|
+
family: "reading",
|
|
589
616
|
readBy: ["diagnostic"],
|
|
590
617
|
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."
|
|
591
618
|
},
|
|
592
|
-
unrecognisedChatSessionFiles: { readBy: ["diagnostic"] }
|
|
619
|
+
unrecognisedChatSessionFiles: { family: "reading", readBy: ["diagnostic"] }
|
|
593
620
|
};
|
|
594
621
|
function backendMetricKeys() {
|
|
595
622
|
return Object.entries(exports.METRIC_KEYS).filter(([, spec]) => spec.readBy.includes("backend")).map(([key, spec]) => [key, spec.backendAliases ?? [key]]);
|
|
@@ -602,7 +629,7 @@ var require_out = __commonJS({
|
|
|
602
629
|
"../packages/tool-contract/out/index.js"(exports) {
|
|
603
630
|
"use strict";
|
|
604
631
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
605
|
-
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;
|
|
632
|
+
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;
|
|
606
633
|
exports.combineDisjointHalves = combineDisjointHalves;
|
|
607
634
|
exports.requireComparableQuantities = requireComparableQuantities;
|
|
608
635
|
exports.ASCENDA_TELEMETRY_SOURCES = [
|
|
@@ -670,6 +697,55 @@ var require_out = __commonJS({
|
|
|
670
697
|
"review_given",
|
|
671
698
|
"pull_request_opened"
|
|
672
699
|
];
|
|
700
|
+
exports.EVENT_METADATA_DISCLOSURE = {
|
|
701
|
+
language: "edits",
|
|
702
|
+
fileType: "edits",
|
|
703
|
+
durationBucket: "session",
|
|
704
|
+
tokenPressureBucket: "context",
|
|
705
|
+
linesChangedBucket: "edits",
|
|
706
|
+
commandClass: "counts",
|
|
707
|
+
gitAction: "git",
|
|
708
|
+
milestoneKind: "git",
|
|
709
|
+
branchHash: "repo",
|
|
710
|
+
autonomyMode: "posture",
|
|
711
|
+
modelClass: "model",
|
|
712
|
+
modelId: "model",
|
|
713
|
+
userModified: "edits",
|
|
714
|
+
outcome: "outcome",
|
|
715
|
+
trigger: "outcome",
|
|
716
|
+
promptClass: "counts",
|
|
717
|
+
reason: "outcome",
|
|
718
|
+
afterHours: "clock",
|
|
719
|
+
activity: "counts",
|
|
720
|
+
// One constant word, from the agent itself. The session sentence names it.
|
|
721
|
+
sessionEndReason: "session",
|
|
722
|
+
interruptionKind: "waiting",
|
|
723
|
+
// Claude Code's own opaque id for one subagent, and the class it belongs
|
|
724
|
+
// to. Never the agent's name or anything it was asked.
|
|
725
|
+
subagentId: "subagents",
|
|
726
|
+
subagentClass: "subagents",
|
|
727
|
+
// Free text by type, and written by no hook mapper — the IDE extension's
|
|
728
|
+
// test signal is the only producer. The setup disclosure's third refusal
|
|
729
|
+
// line says as much, and tool-kit's guard test fails if a mapper starts.
|
|
730
|
+
message: "counts",
|
|
731
|
+
host: "session",
|
|
732
|
+
// One constant word from the host's own environment: this machine, or a
|
|
733
|
+
// hosted session. The session sentence names it.
|
|
734
|
+
runtime: "session",
|
|
735
|
+
toolName: "tools",
|
|
736
|
+
simulated: "transport",
|
|
737
|
+
relatedEventType: "transport",
|
|
738
|
+
skillVersion: "transport",
|
|
739
|
+
// A hash computed before it reaches any collector; the task itself is never
|
|
740
|
+
// seen by this code, so there is nothing about the work here to disclose.
|
|
741
|
+
taskFingerprint: "transport",
|
|
742
|
+
importKey: "transport",
|
|
743
|
+
extractionId: "transport",
|
|
744
|
+
importSchema: "transport",
|
|
745
|
+
// The version of the Ascenda collector that sent this event. Names the
|
|
746
|
+
// build, and nothing about the work it observed.
|
|
747
|
+
collectorVersion: "transport"
|
|
748
|
+
};
|
|
673
749
|
exports.EVENT_METADATA_FIELDS = [
|
|
674
750
|
"language",
|
|
675
751
|
"fileType",
|
|
@@ -693,13 +769,19 @@ var require_out = __commonJS({
|
|
|
693
769
|
"message",
|
|
694
770
|
"host",
|
|
695
771
|
"toolName",
|
|
772
|
+
"runtime",
|
|
773
|
+
"sessionEndReason",
|
|
774
|
+
"interruptionKind",
|
|
775
|
+
"subagentId",
|
|
776
|
+
"subagentClass",
|
|
696
777
|
"simulated",
|
|
697
778
|
"relatedEventType",
|
|
698
779
|
"skillVersion",
|
|
699
780
|
"taskFingerprint",
|
|
700
781
|
"importKey",
|
|
701
782
|
"extractionId",
|
|
702
|
-
"importSchema"
|
|
783
|
+
"importSchema",
|
|
784
|
+
"collectorVersion"
|
|
703
785
|
];
|
|
704
786
|
exports.IDEMPOTENCY_KEY_MAX_LENGTH = 128;
|
|
705
787
|
exports.TOOL_EVENT_DELIVERED_STATUSES = ["accepted", "duplicate"];
|
|
@@ -739,6 +821,12 @@ var require_out = __commonJS({
|
|
|
739
821
|
// `ai_prompt_submitted` closes. Neutral so a marker sent once per turn
|
|
740
822
|
// doesn't weigh on any workload leg.
|
|
741
823
|
ai_turn_completed: "neutral",
|
|
824
|
+
// A subagent began or finished under a session. Boundaries, not work: the
|
|
825
|
+
// subagent's own tool calls and edits arrive as their own events and carry
|
|
826
|
+
// their own categories. A reader pairs these on `subagentId` to count how
|
|
827
|
+
// many agents ran at once; neutral so that count weighs on no workload leg.
|
|
828
|
+
subagent_started: "neutral",
|
|
829
|
+
subagent_stopped: "neutral",
|
|
742
830
|
// The agent stopped and is waiting on the person: Claude Code's
|
|
743
831
|
// `Notification`, Codex's `PermissionRequest`. Supervision, beside the other
|
|
744
832
|
// oversight overhead, because that is what it is — time the person spends
|
|
@@ -865,6 +953,21 @@ var require_payload = __commonJS({
|
|
|
865
953
|
}
|
|
866
954
|
});
|
|
867
955
|
|
|
956
|
+
// ../packages/tool-kit/out/collectorVersion.js
|
|
957
|
+
var require_collectorVersion = __commonJS({
|
|
958
|
+
"../packages/tool-kit/out/collectorVersion.js"(exports) {
|
|
959
|
+
"use strict";
|
|
960
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
961
|
+
exports.COLLECTOR_VERSION = exports.UNRELEASED_COLLECTOR_VERSION = void 0;
|
|
962
|
+
exports.describeCollectorVersion = describeCollectorVersion;
|
|
963
|
+
exports.UNRELEASED_COLLECTOR_VERSION = "unreleased";
|
|
964
|
+
exports.COLLECTOR_VERSION = "0.1.33" ? "0.1.33" : exports.UNRELEASED_COLLECTOR_VERSION;
|
|
965
|
+
function describeCollectorVersion(version = exports.COLLECTOR_VERSION) {
|
|
966
|
+
return version === exports.UNRELEASED_COLLECTOR_VERSION ? `${version} (built from a checkout, not a release)` : version;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
|
|
868
971
|
// ../packages/tool-kit/out/eventLog.js
|
|
869
972
|
var require_eventLog = __commonJS({
|
|
870
973
|
"../packages/tool-kit/out/eventLog.js"(exports) {
|
|
@@ -960,6 +1063,12 @@ var require_http = __commonJS({
|
|
|
960
1063
|
exports.AscendaApiError = void 0;
|
|
961
1064
|
exports.createPairingSession = createPairingSession;
|
|
962
1065
|
exports.getPairingStatus = getPairingStatus;
|
|
1066
|
+
exports.startStudyJoin = startStudyJoin;
|
|
1067
|
+
exports.getStudyJoinStatus = getStudyJoinStatus;
|
|
1068
|
+
exports.readInitiatives = readInitiatives;
|
|
1069
|
+
exports.readStudyNotices = readStudyNotices;
|
|
1070
|
+
exports.setStudyObjection = setStudyObjection;
|
|
1071
|
+
exports.markStudyNoticeShown = markStudyNoticeShown;
|
|
963
1072
|
exports.renewToolToken = renewToolToken;
|
|
964
1073
|
exports.isRetryableStatus = isRetryableStatus;
|
|
965
1074
|
exports.postToolEvent = postToolEvent;
|
|
@@ -996,6 +1105,108 @@ var require_http = __commonJS({
|
|
|
996
1105
|
throw new AscendaApiError(response.status, void 0, await response.text());
|
|
997
1106
|
return await response.json();
|
|
998
1107
|
}
|
|
1108
|
+
async function startStudyJoin(apiBaseUrl, eventWriteToken, joinCode, mode) {
|
|
1109
|
+
const response = await fetch(`${apiBaseUrl}/v1/org-study-join-sessions`, {
|
|
1110
|
+
method: "POST",
|
|
1111
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1112
|
+
body: JSON.stringify({ joinCode, mode })
|
|
1113
|
+
});
|
|
1114
|
+
if (!response.ok)
|
|
1115
|
+
throw await apiError(response);
|
|
1116
|
+
return await response.json();
|
|
1117
|
+
}
|
|
1118
|
+
async function getStudyJoinStatus(apiBaseUrl, eventWriteToken, joinSessionId) {
|
|
1119
|
+
const response = await fetch(`${apiBaseUrl}/v1/org-study-join-sessions/${encodeURIComponent(joinSessionId)}/status`, {
|
|
1120
|
+
method: "GET",
|
|
1121
|
+
headers: { Accept: "application/json", Authorization: `Bearer ${eventWriteToken}` }
|
|
1122
|
+
});
|
|
1123
|
+
if (!response.ok)
|
|
1124
|
+
throw await apiError(response);
|
|
1125
|
+
return await response.json();
|
|
1126
|
+
}
|
|
1127
|
+
async function readInitiatives(apiBaseUrl, eventWriteToken, signal) {
|
|
1128
|
+
let response;
|
|
1129
|
+
try {
|
|
1130
|
+
response = await fetch(`${apiBaseUrl}/v1/tool-installations/initiatives`, {
|
|
1131
|
+
method: "GET",
|
|
1132
|
+
headers: { Accept: "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1133
|
+
signal
|
|
1134
|
+
});
|
|
1135
|
+
} catch (error) {
|
|
1136
|
+
return { kind: "failed", reason: error instanceof Error && error.name === "TimeoutError" ? "the request timed out" : "the server could not be reached" };
|
|
1137
|
+
}
|
|
1138
|
+
if (response.status === 401)
|
|
1139
|
+
return { kind: "rejected", httpStatus: 401 };
|
|
1140
|
+
if (!response.ok)
|
|
1141
|
+
return { kind: "failed", reason: `the server answered HTTP ${response.status}` };
|
|
1142
|
+
let body;
|
|
1143
|
+
try {
|
|
1144
|
+
body = await response.json();
|
|
1145
|
+
} catch {
|
|
1146
|
+
return { kind: "failed", reason: "the reply was not readable" };
|
|
1147
|
+
}
|
|
1148
|
+
if (!Array.isArray(body))
|
|
1149
|
+
return { kind: "failed", reason: "the reply was not a list" };
|
|
1150
|
+
return { kind: "ok", initiatives: body };
|
|
1151
|
+
}
|
|
1152
|
+
async function readStudyNotices(apiBaseUrl, eventWriteToken, signal) {
|
|
1153
|
+
let response;
|
|
1154
|
+
try {
|
|
1155
|
+
response = await fetch(`${apiBaseUrl}/v1/tool-installations/study-notices`, {
|
|
1156
|
+
method: "GET",
|
|
1157
|
+
headers: { Accept: "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1158
|
+
signal
|
|
1159
|
+
});
|
|
1160
|
+
} catch (error) {
|
|
1161
|
+
return { kind: "failed", reason: error instanceof Error && error.name === "TimeoutError" ? "the request timed out" : "the server could not be reached" };
|
|
1162
|
+
}
|
|
1163
|
+
if (response.status === 404)
|
|
1164
|
+
return { kind: "absent" };
|
|
1165
|
+
if (response.status === 401)
|
|
1166
|
+
return { kind: "rejected", httpStatus: 401 };
|
|
1167
|
+
if (!response.ok)
|
|
1168
|
+
return { kind: "failed", reason: `the server answered HTTP ${response.status}` };
|
|
1169
|
+
let body;
|
|
1170
|
+
try {
|
|
1171
|
+
body = await response.json();
|
|
1172
|
+
} catch {
|
|
1173
|
+
return { kind: "absent" };
|
|
1174
|
+
}
|
|
1175
|
+
if (!Array.isArray(body))
|
|
1176
|
+
return { kind: "absent" };
|
|
1177
|
+
return { kind: "ok", notices: body };
|
|
1178
|
+
}
|
|
1179
|
+
async function setStudyObjection(apiBaseUrl, eventWriteToken, code, objected) {
|
|
1180
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-installations/study-notices/${encodeURIComponent(String(code))}/objection`, {
|
|
1181
|
+
method: objected ? "POST" : "DELETE",
|
|
1182
|
+
headers: { Authorization: `Bearer ${eventWriteToken}` }
|
|
1183
|
+
});
|
|
1184
|
+
if (!response.ok)
|
|
1185
|
+
throw await apiError(response);
|
|
1186
|
+
}
|
|
1187
|
+
async function markStudyNoticeShown(apiBaseUrl, eventWriteToken, organisationId, code, signal) {
|
|
1188
|
+
try {
|
|
1189
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-installations/study-notices/${encodeURIComponent(organisationId)}/${encodeURIComponent(String(code))}/shown`, {
|
|
1190
|
+
method: "POST",
|
|
1191
|
+
headers: { Authorization: `Bearer ${eventWriteToken}` },
|
|
1192
|
+
signal
|
|
1193
|
+
});
|
|
1194
|
+
return response.ok;
|
|
1195
|
+
} catch {
|
|
1196
|
+
return false;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
async function apiError(response) {
|
|
1200
|
+
const body = await response.text();
|
|
1201
|
+
let errorCode;
|
|
1202
|
+
try {
|
|
1203
|
+
const parsed = JSON.parse(body);
|
|
1204
|
+
errorCode = parsed.code ?? parsed.error;
|
|
1205
|
+
} catch {
|
|
1206
|
+
errorCode = void 0;
|
|
1207
|
+
}
|
|
1208
|
+
return new AscendaApiError(response.status, errorCode, body);
|
|
1209
|
+
}
|
|
999
1210
|
async function renewToolToken(apiBaseUrl, eventWriteToken, signal) {
|
|
1000
1211
|
const response = await fetch(`${apiBaseUrl}/v1/tool-events/renew-token`, {
|
|
1001
1212
|
method: "POST",
|
|
@@ -1138,9 +1349,12 @@ var require_tokenStore = __commonJS({
|
|
|
1138
1349
|
};
|
|
1139
1350
|
}();
|
|
1140
1351
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1352
|
+
exports.EVENT_TOKEN_TTL_MS = void 0;
|
|
1141
1353
|
exports.ascendaHome = ascendaHome;
|
|
1142
1354
|
exports.defaultTokenFilePath = defaultTokenFilePath;
|
|
1355
|
+
exports.tokenExpiryFilePath = tokenExpiryFilePath;
|
|
1143
1356
|
exports.persistEventWriteToken = persistEventWriteToken;
|
|
1357
|
+
exports.readTokenExpiry = readTokenExpiry;
|
|
1144
1358
|
exports.listPersistedToolInstallationIds = listPersistedToolInstallationIds;
|
|
1145
1359
|
exports.readTokenFile = readTokenFile;
|
|
1146
1360
|
exports.sanitizeFilePart = sanitizeFilePart;
|
|
@@ -1153,7 +1367,10 @@ var require_tokenStore = __commonJS({
|
|
|
1153
1367
|
function defaultTokenFilePath(toolInstallationId) {
|
|
1154
1368
|
return path2.join(ascendaHome(), "tokens", sanitizeFilePart(toolInstallationId));
|
|
1155
1369
|
}
|
|
1156
|
-
function
|
|
1370
|
+
function tokenExpiryFilePath(tokenFilePath) {
|
|
1371
|
+
return path2.join(path2.dirname(tokenFilePath), "expiry", path2.basename(tokenFilePath));
|
|
1372
|
+
}
|
|
1373
|
+
function persistEventWriteToken(tokenFilePath, token, expiresAt) {
|
|
1157
1374
|
const dir = path2.dirname(tokenFilePath);
|
|
1158
1375
|
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1159
1376
|
fs.writeFileSync(tokenFilePath, token, { encoding: "utf8", mode: 384 });
|
|
@@ -1161,6 +1378,30 @@ var require_tokenStore = __commonJS({
|
|
|
1161
1378
|
fs.chmodSync(dir, 448);
|
|
1162
1379
|
fs.chmodSync(tokenFilePath, 384);
|
|
1163
1380
|
}
|
|
1381
|
+
const expiryFile = tokenExpiryFilePath(tokenFilePath);
|
|
1382
|
+
try {
|
|
1383
|
+
if (expiresAt && Number.isFinite(Date.parse(expiresAt))) {
|
|
1384
|
+
fs.mkdirSync(path2.dirname(expiryFile), { recursive: true, mode: 448 });
|
|
1385
|
+
fs.writeFileSync(expiryFile, expiresAt, { encoding: "utf8", mode: 384 });
|
|
1386
|
+
} else {
|
|
1387
|
+
fs.rmSync(expiryFile, { force: true });
|
|
1388
|
+
}
|
|
1389
|
+
} catch {
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
exports.EVENT_TOKEN_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
1393
|
+
function readTokenExpiry(tokenFilePath) {
|
|
1394
|
+
try {
|
|
1395
|
+
const recorded = Date.parse(fs.readFileSync(tokenExpiryFilePath(tokenFilePath), "utf8").trim());
|
|
1396
|
+
if (Number.isFinite(recorded))
|
|
1397
|
+
return recorded;
|
|
1398
|
+
} catch {
|
|
1399
|
+
}
|
|
1400
|
+
try {
|
|
1401
|
+
return fs.statSync(tokenFilePath).mtimeMs + exports.EVENT_TOKEN_TTL_MS;
|
|
1402
|
+
} catch {
|
|
1403
|
+
return void 0;
|
|
1404
|
+
}
|
|
1164
1405
|
}
|
|
1165
1406
|
function listPersistedToolInstallationIds(toolType) {
|
|
1166
1407
|
const prefix = `${sanitizeFilePart(toolType)}_`;
|
|
@@ -1607,7 +1848,7 @@ var require_eventSender = __commonJS({
|
|
|
1607
1848
|
"../packages/tool-kit/out/eventSender.js"(exports) {
|
|
1608
1849
|
"use strict";
|
|
1609
1850
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1610
|
-
exports.AscendaEventSender = exports.AscendaSemanticEventError = void 0;
|
|
1851
|
+
exports.AscendaEventSender = exports.TOKEN_RENEW_LEAD_MS = exports.AscendaSemanticEventError = void 0;
|
|
1611
1852
|
exports.buildEventPayload = buildEventPayload;
|
|
1612
1853
|
var afterHours_1 = require_afterHours();
|
|
1613
1854
|
var tool_contract_1 = require_out();
|
|
@@ -1618,6 +1859,7 @@ var require_eventSender = __commonJS({
|
|
|
1618
1859
|
var tokenStore_1 = require_tokenStore();
|
|
1619
1860
|
var stateStore_1 = require_stateStore();
|
|
1620
1861
|
var payload_1 = require_payload();
|
|
1862
|
+
var collectorVersion_1 = require_collectorVersion();
|
|
1621
1863
|
var AscendaSemanticEventError = class extends Error {
|
|
1622
1864
|
constructor(message) {
|
|
1623
1865
|
super(message);
|
|
@@ -1639,11 +1881,15 @@ var require_eventSender = __commonJS({
|
|
|
1639
1881
|
provenance: tool_contract_1.ASCENDA_PROVENANCE,
|
|
1640
1882
|
privacyMode: "metadata_only",
|
|
1641
1883
|
...mapped,
|
|
1642
|
-
metadata: mapped.metadata
|
|
1884
|
+
metadata: withCollectorVersion(mapped.metadata)
|
|
1643
1885
|
};
|
|
1644
1886
|
}
|
|
1887
|
+
function withCollectorVersion(metadata) {
|
|
1888
|
+
return { ...metadata, collectorVersion: collectorVersion_1.COLLECTOR_VERSION };
|
|
1889
|
+
}
|
|
1645
1890
|
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
1646
1891
|
var RETRY_DELAY_MS = 250;
|
|
1892
|
+
exports.TOKEN_RENEW_LEAD_MS = 21 * 24 * 60 * 60 * 1e3;
|
|
1647
1893
|
var AscendaEventSender = class {
|
|
1648
1894
|
config;
|
|
1649
1895
|
eventWriteToken;
|
|
@@ -1651,6 +1897,8 @@ var require_eventSender = __commonJS({
|
|
|
1651
1897
|
lastDrain;
|
|
1652
1898
|
/** One outbox pass per sender, i.e. per hook process. The hook is on the user's critical path. */
|
|
1653
1899
|
outboxServiced = false;
|
|
1900
|
+
/** One look at the token's expiry per sender, for the same reason. */
|
|
1901
|
+
expiryChecked = false;
|
|
1654
1902
|
/** Resolved once, so every clock read in one pass sees the same instant. */
|
|
1655
1903
|
time;
|
|
1656
1904
|
constructor(config) {
|
|
@@ -1661,6 +1909,30 @@ var require_eventSender = __commonJS({
|
|
|
1661
1909
|
async send(mapped) {
|
|
1662
1910
|
return this.post(buildEventPayload(this.config, mapped));
|
|
1663
1911
|
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Writes the event to the outbox and returns without touching the network.
|
|
1914
|
+
* The next outbox pass delivers it, from whichever hook of this
|
|
1915
|
+
* installation sends next.
|
|
1916
|
+
*
|
|
1917
|
+
* For a hook whose host is exiting. A process the host may kill at any
|
|
1918
|
+
* moment can't wait on a send, and one killed mid-send dies before
|
|
1919
|
+
* {@link post} gets to queue the payload, so the event goes with it. Here
|
|
1920
|
+
* the payload is on disk before anything can go wrong.
|
|
1921
|
+
*
|
|
1922
|
+
* Returns whether it is. When the write fails the journal says the event
|
|
1923
|
+
* was lost; nothing else could have kept it.
|
|
1924
|
+
*/
|
|
1925
|
+
queue(mapped) {
|
|
1926
|
+
const payload = buildEventPayload(this.config, mapped);
|
|
1927
|
+
const queued = this.enqueue(payload);
|
|
1928
|
+
if (!queued) {
|
|
1929
|
+
this.lastState = (0, stateStore_1.recordSendOutcome)(this.stateFilePath(), this.config.toolInstallationId, "other", {
|
|
1930
|
+
detail: `${payload.eventType}: outbox write failed, event lost`
|
|
1931
|
+
});
|
|
1932
|
+
}
|
|
1933
|
+
this.log(payload, "not_sent", queued ? "queued" : void 0);
|
|
1934
|
+
return queued;
|
|
1935
|
+
}
|
|
1664
1936
|
/**
|
|
1665
1937
|
* Sends one of the six agent-observed types (dark-flow-gap-analysis §2.1).
|
|
1666
1938
|
* Distinct from {@link send} rather than an option on it, because the
|
|
@@ -1701,7 +1973,7 @@ var require_eventSender = __commonJS({
|
|
|
1701
1973
|
consentScope: tool_contract_1.ASCENDA_SEMANTIC_CONSENT_SCOPE,
|
|
1702
1974
|
provenance: tool_contract_1.ASCENDA_SEMANTIC_PROVENANCE,
|
|
1703
1975
|
privacyMode: "metadata_only",
|
|
1704
|
-
metadata: mapped.metadata
|
|
1976
|
+
metadata: withCollectorVersion(mapped.metadata)
|
|
1705
1977
|
};
|
|
1706
1978
|
return this.post(payload);
|
|
1707
1979
|
}
|
|
@@ -1732,7 +2004,7 @@ var require_eventSender = __commonJS({
|
|
|
1732
2004
|
consentScope: tool_contract_1.ASCENDA_COLLABORATION_CONSENT_SCOPE,
|
|
1733
2005
|
provenance: tool_contract_1.ASCENDA_PROVENANCE,
|
|
1734
2006
|
privacyMode: "metadata_only",
|
|
1735
|
-
metadata: mapped.metadata
|
|
2007
|
+
metadata: withCollectorVersion(mapped.metadata)
|
|
1736
2008
|
};
|
|
1737
2009
|
return this.post(payload);
|
|
1738
2010
|
}
|
|
@@ -1750,6 +2022,7 @@ var require_eventSender = __commonJS({
|
|
|
1750
2022
|
* hook during an outage to one bounded round trip instead of three.
|
|
1751
2023
|
*/
|
|
1752
2024
|
async post(payload) {
|
|
2025
|
+
await this.renewIfExpiring();
|
|
1753
2026
|
const halted = await this.serviceOutbox();
|
|
1754
2027
|
let outcome;
|
|
1755
2028
|
let queued = false;
|
|
@@ -1955,19 +2228,49 @@ var require_eventSender = __commonJS({
|
|
|
1955
2228
|
return;
|
|
1956
2229
|
(0, eventLog_1.appendEventLog)(logFile, { loggedAt: (/* @__PURE__ */ new Date()).toISOString(), delivery, payload, ...outbox ? { outbox } : {} });
|
|
1957
2230
|
}
|
|
1958
|
-
/**
|
|
2231
|
+
/**
|
|
2232
|
+
* Renews ahead of expiry, at most once per sender. Waiting for the 401
|
|
2233
|
+
* doesn't work: by then the token has expired, and the server won't renew
|
|
2234
|
+
* an expired token.
|
|
2235
|
+
*/
|
|
2236
|
+
async renewIfExpiring() {
|
|
2237
|
+
if (this.expiryChecked || this.config.renewToken === false)
|
|
2238
|
+
return;
|
|
2239
|
+
this.expiryChecked = true;
|
|
2240
|
+
const expiresAt = (0, tokenStore_1.readTokenExpiry)(this.config.tokenFilePath);
|
|
2241
|
+
if (expiresAt === void 0 || this.time.now() < expiresAt - exports.TOKEN_RENEW_LEAD_MS)
|
|
2242
|
+
return;
|
|
2243
|
+
await this.renewEventToken();
|
|
2244
|
+
}
|
|
2245
|
+
/**
|
|
2246
|
+
* Never throws: a renewal that errors is a failed renewal, not a failed turn.
|
|
2247
|
+
*
|
|
2248
|
+
* A refused renewal usually means another process got there first. Hooks
|
|
2249
|
+
* and the MCP server share one token file, and renewing revokes the token
|
|
2250
|
+
* it replaces, so the loser holds a revoked token while the winner's
|
|
2251
|
+
* replacement is already on disk. Adopting that counts as a renewal.
|
|
2252
|
+
*/
|
|
1959
2253
|
async renewEventToken() {
|
|
2254
|
+
if (this.config.renewToken === false)
|
|
2255
|
+
return false;
|
|
1960
2256
|
try {
|
|
1961
2257
|
const renewed = await (0, http_1.renewToolToken)(this.config.apiBaseUrl, this.eventWriteToken, this.signal());
|
|
1962
2258
|
if (!renewed)
|
|
1963
|
-
return
|
|
2259
|
+
return this.adoptPersistedToken();
|
|
1964
2260
|
this.eventWriteToken = renewed.eventWriteToken;
|
|
1965
|
-
(0, tokenStore_1.persistEventWriteToken)(this.config.tokenFilePath, renewed.eventWriteToken);
|
|
2261
|
+
(0, tokenStore_1.persistEventWriteToken)(this.config.tokenFilePath, renewed.eventWriteToken, renewed.expiresAt);
|
|
1966
2262
|
return true;
|
|
1967
2263
|
} catch {
|
|
1968
2264
|
return false;
|
|
1969
2265
|
}
|
|
1970
2266
|
}
|
|
2267
|
+
adoptPersistedToken() {
|
|
2268
|
+
const persisted = (0, tokenStore_1.readTokenFile)(this.config.tokenFilePath);
|
|
2269
|
+
if (!persisted || persisted === this.eventWriteToken)
|
|
2270
|
+
return false;
|
|
2271
|
+
this.eventWriteToken = persisted;
|
|
2272
|
+
return true;
|
|
2273
|
+
}
|
|
1971
2274
|
signal() {
|
|
1972
2275
|
return AbortSignal.timeout(this.config.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
1973
2276
|
}
|
|
@@ -2169,6 +2472,7 @@ var require_credentials = __commonJS({
|
|
|
2169
2472
|
exports.readMachineCredentials = readMachineCredentials;
|
|
2170
2473
|
exports.writeMachineCredentials = writeMachineCredentials;
|
|
2171
2474
|
exports.writeTopLevelCredentials = writeTopLevelCredentials;
|
|
2475
|
+
exports.isLocalOnlyHostInstall = isLocalOnlyHostInstall;
|
|
2172
2476
|
exports.readHostCredentials = readHostCredentials;
|
|
2173
2477
|
exports.writeHostCredentials = writeHostCredentials;
|
|
2174
2478
|
exports.removeHostCredentials = removeHostCredentials;
|
|
@@ -2205,6 +2509,14 @@ var require_credentials = __commonJS({
|
|
|
2205
2509
|
const existing = readMachineCredentials();
|
|
2206
2510
|
writeMachineCredentials({ ...credentials, ...existing?.tools ? { tools: existing.tools } : {} });
|
|
2207
2511
|
}
|
|
2512
|
+
function isLocalOnlyHostInstall(host, hasToken) {
|
|
2513
|
+
const credentials = readHostCredentials(host);
|
|
2514
|
+
if (!credentials?.localOnly)
|
|
2515
|
+
return false;
|
|
2516
|
+
if (process.env.ASCENDA_EVENT_WRITE_TOKEN)
|
|
2517
|
+
return false;
|
|
2518
|
+
return !(credentials.toolInstallationId && hasToken(credentials.toolInstallationId));
|
|
2519
|
+
}
|
|
2208
2520
|
function readHostCredentials(host) {
|
|
2209
2521
|
const entry = readMachineCredentials()?.tools?.[host];
|
|
2210
2522
|
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
@@ -2773,6 +3085,9 @@ var require_hookAdapter = __commonJS({
|
|
|
2773
3085
|
if (events.length === 0)
|
|
2774
3086
|
return;
|
|
2775
3087
|
const notice = options.onNotice ?? ((message) => console.error(message));
|
|
3088
|
+
const hasToken = (id) => (0, tokenStore_1.readTokenFile)(process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0, tokenStore_1.defaultTokenFilePath)(id)) !== void 0;
|
|
3089
|
+
if (options.host && (0, credentials_1.isLocalOnlyHostInstall)(options.host, hasToken))
|
|
3090
|
+
return;
|
|
2776
3091
|
let config;
|
|
2777
3092
|
try {
|
|
2778
3093
|
config = loadCliAgentConfig(options.toolType, options.sessionId, options.cwd, options);
|
|
@@ -2838,6 +3153,728 @@ var require_hookAdapter = __commonJS({
|
|
|
2838
3153
|
}
|
|
2839
3154
|
});
|
|
2840
3155
|
|
|
3156
|
+
// ../packages/tool-kit/out/hookSet.js
|
|
3157
|
+
var require_hookSet = __commonJS({
|
|
3158
|
+
"../packages/tool-kit/out/hookSet.js"(exports) {
|
|
3159
|
+
"use strict";
|
|
3160
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3161
|
+
exports.UNVERSIONED_HOOK_SET = exports.HOOK_SET_FLAG = void 0;
|
|
3162
|
+
exports.hookSetArgument = hookSetArgument;
|
|
3163
|
+
exports.readHookSet = readHookSet;
|
|
3164
|
+
exports.isHookSet = isHookSet;
|
|
3165
|
+
exports.readViaPlugin = readViaPlugin;
|
|
3166
|
+
exports.hookSetOfCommand = hookSetOfCommand;
|
|
3167
|
+
exports.hookSetChanges = hookSetChanges;
|
|
3168
|
+
exports.describeHookSetChanges = describeHookSetChanges;
|
|
3169
|
+
exports.HOOK_SET_FLAG = "--hook-set";
|
|
3170
|
+
exports.UNVERSIONED_HOOK_SET = 1;
|
|
3171
|
+
function hookSetArgument(hookSet) {
|
|
3172
|
+
return hookSet === void 0 ? "" : ` ${exports.HOOK_SET_FLAG} ${hookSet}`;
|
|
3173
|
+
}
|
|
3174
|
+
function readHookSet(argv) {
|
|
3175
|
+
const index = argv.indexOf(exports.HOOK_SET_FLAG);
|
|
3176
|
+
if (index === -1)
|
|
3177
|
+
return void 0;
|
|
3178
|
+
const raw = argv[index + 1];
|
|
3179
|
+
if (raw === void 0 || !/^[1-9]\d*$/.test(raw))
|
|
3180
|
+
return void 0;
|
|
3181
|
+
const value = Number(raw);
|
|
3182
|
+
return isHookSet(value) ? value : void 0;
|
|
3183
|
+
}
|
|
3184
|
+
function isHookSet(value) {
|
|
3185
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 1;
|
|
3186
|
+
}
|
|
3187
|
+
function readViaPlugin(env) {
|
|
3188
|
+
return env.CLAUDE_PLUGIN_ROOT ? true : void 0;
|
|
3189
|
+
}
|
|
3190
|
+
function hookSetOfCommand(command) {
|
|
3191
|
+
const match = command.match(/--hook-set\s+(\d+)/);
|
|
3192
|
+
return match ? Number(match[1]) : exports.UNVERSIONED_HOOK_SET;
|
|
3193
|
+
}
|
|
3194
|
+
function hookSetChanges(before, events) {
|
|
3195
|
+
const added = events.filter((event) => !before.has(event));
|
|
3196
|
+
const sets = [...before.values()];
|
|
3197
|
+
return sets.length ? { added, previousSet: Math.min(...sets) } : { added };
|
|
3198
|
+
}
|
|
3199
|
+
function describeHookSetChanges(changes, hookSet) {
|
|
3200
|
+
if (changes.previousSet === void 0)
|
|
3201
|
+
return void 0;
|
|
3202
|
+
const parts = [];
|
|
3203
|
+
if (changes.added.length)
|
|
3204
|
+
parts.push(`added ${changes.added.join(", ")}`);
|
|
3205
|
+
if (changes.previousSet < hookSet)
|
|
3206
|
+
parts.push(`hook set ${changes.previousSet} \u2192 ${hookSet}`);
|
|
3207
|
+
return parts.length ? `upgraded: ${parts.join("; ")}` : void 0;
|
|
3208
|
+
}
|
|
3209
|
+
}
|
|
3210
|
+
});
|
|
3211
|
+
|
|
3212
|
+
// ../packages/tool-kit/out/studyJoin.js
|
|
3213
|
+
var require_studyJoin = __commonJS({
|
|
3214
|
+
"../packages/tool-kit/out/studyJoin.js"(exports) {
|
|
3215
|
+
"use strict";
|
|
3216
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
3217
|
+
if (k2 === void 0) k2 = k;
|
|
3218
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
3219
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
3220
|
+
desc = { enumerable: true, get: function() {
|
|
3221
|
+
return m[k];
|
|
3222
|
+
} };
|
|
3223
|
+
}
|
|
3224
|
+
Object.defineProperty(o, k2, desc);
|
|
3225
|
+
} : function(o, m, k, k2) {
|
|
3226
|
+
if (k2 === void 0) k2 = k;
|
|
3227
|
+
o[k2] = m[k];
|
|
3228
|
+
});
|
|
3229
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
3230
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
3231
|
+
} : function(o, v) {
|
|
3232
|
+
o["default"] = v;
|
|
3233
|
+
});
|
|
3234
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
3235
|
+
var ownKeys = function(o) {
|
|
3236
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
3237
|
+
var ar = [];
|
|
3238
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
3239
|
+
return ar;
|
|
3240
|
+
};
|
|
3241
|
+
return ownKeys(o);
|
|
3242
|
+
};
|
|
3243
|
+
return function(mod) {
|
|
3244
|
+
if (mod && mod.__esModule) return mod;
|
|
3245
|
+
var result = {};
|
|
3246
|
+
if (mod != null) {
|
|
3247
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
3248
|
+
}
|
|
3249
|
+
__setModuleDefault(result, mod);
|
|
3250
|
+
return result;
|
|
3251
|
+
};
|
|
3252
|
+
}();
|
|
3253
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3254
|
+
exports.runStudyJoin = runStudyJoin;
|
|
3255
|
+
exports.formatWindow = formatWindow;
|
|
3256
|
+
var readline = __importStar(__require("node:readline"));
|
|
3257
|
+
var http_1 = require_http();
|
|
3258
|
+
var STUDY_JOIN_MODE = "report";
|
|
3259
|
+
var POLL_INTERVAL_MS = 3e3;
|
|
3260
|
+
var POLL_TIMEOUT_MS = 11 * 60 * 1e3;
|
|
3261
|
+
async function runStudyJoin(ctx) {
|
|
3262
|
+
const stdin = ctx.stdin ?? process.stdin;
|
|
3263
|
+
const stdout = ctx.stdout ?? process.stdout;
|
|
3264
|
+
const stderr = ctx.stderr ?? process.stderr;
|
|
3265
|
+
const print = (line) => stdout.write(`${line}
|
|
3266
|
+
`);
|
|
3267
|
+
if (!stdin.isTTY || !stdout.isTTY) {
|
|
3268
|
+
stderr.write("join needs an interactive terminal (stdin and stdout). Run it directly, not from a script or a pipe.\n");
|
|
3269
|
+
return 0;
|
|
3270
|
+
}
|
|
3271
|
+
if (!ctx.joinCode) {
|
|
3272
|
+
stderr.write("Usage: join <code>\n");
|
|
3273
|
+
return 1;
|
|
3274
|
+
}
|
|
3275
|
+
let start;
|
|
3276
|
+
try {
|
|
3277
|
+
start = await (0, http_1.startStudyJoin)(ctx.apiBaseUrl, ctx.eventWriteToken, ctx.joinCode, STUDY_JOIN_MODE);
|
|
3278
|
+
} catch (error) {
|
|
3279
|
+
stderr.write(`${describeStartError(error)}
|
|
3280
|
+
`);
|
|
3281
|
+
return 1;
|
|
3282
|
+
}
|
|
3283
|
+
print("");
|
|
3284
|
+
print(`${start.organisationName}: ${describeStudyKind(start.studyKind)}`);
|
|
3285
|
+
print(formatWindow(start.windowStartUtc, start.windowEndUtc));
|
|
3286
|
+
print("");
|
|
3287
|
+
print("Report (30 days) grants:");
|
|
3288
|
+
for (const grant of start.grants)
|
|
3289
|
+
print(` ${describeGrant(grant)}`);
|
|
3290
|
+
print("");
|
|
3291
|
+
print("Study mode needs the Ascenda app. Open the app to join that way instead.");
|
|
3292
|
+
print("");
|
|
3293
|
+
print("Join in:");
|
|
3294
|
+
print(" 1) Report (30 days)");
|
|
3295
|
+
print(" 2) Not now");
|
|
3296
|
+
print("");
|
|
3297
|
+
const answer = await askChoice(stdin, stdout);
|
|
3298
|
+
if (!/^(1|report)$/i.test(answer)) {
|
|
3299
|
+
print("Not now.");
|
|
3300
|
+
return 0;
|
|
3301
|
+
}
|
|
3302
|
+
print("");
|
|
3303
|
+
print(`Confirm in the Ascenda app with code ${start.deviceCode}`);
|
|
3304
|
+
print(`Waiting for confirmation (expires ${formatLocalTime(start.expiresAt)})...`);
|
|
3305
|
+
const pollIntervalMs = ctx.pollIntervalMs ?? POLL_INTERVAL_MS;
|
|
3306
|
+
const deadline = Math.min(Date.parse(start.expiresAt) || Date.now() + POLL_TIMEOUT_MS, Date.now() + POLL_TIMEOUT_MS);
|
|
3307
|
+
while (Date.now() < deadline) {
|
|
3308
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
3309
|
+
let poll;
|
|
3310
|
+
try {
|
|
3311
|
+
poll = await (0, http_1.getStudyJoinStatus)(ctx.apiBaseUrl, ctx.eventWriteToken, start.joinSessionId);
|
|
3312
|
+
} catch (error) {
|
|
3313
|
+
if (isRetryablePollError(error))
|
|
3314
|
+
continue;
|
|
3315
|
+
stderr.write(`${describeStartError(error)}
|
|
3316
|
+
`);
|
|
3317
|
+
return 1;
|
|
3318
|
+
}
|
|
3319
|
+
if (poll.status === "pending")
|
|
3320
|
+
continue;
|
|
3321
|
+
if (poll.status === "confirmed") {
|
|
3322
|
+
const granted = poll.granted ?? [];
|
|
3323
|
+
if (granted.length === 0) {
|
|
3324
|
+
print("");
|
|
3325
|
+
print("Nothing was granted. Run join again, or check with your organisation.");
|
|
3326
|
+
return 1;
|
|
3327
|
+
}
|
|
3328
|
+
print("");
|
|
3329
|
+
print("Joined. Granted:");
|
|
3330
|
+
for (const grant of granted)
|
|
3331
|
+
print(` ${describeGrant(grant)}`);
|
|
3332
|
+
print("");
|
|
3333
|
+
print("Each of these can be turned off separately, in the app's consent settings.");
|
|
3334
|
+
print("The organisation sees group counts, never who joined.");
|
|
3335
|
+
return 0;
|
|
3336
|
+
}
|
|
3337
|
+
if (poll.status === "expired") {
|
|
3338
|
+
print("");
|
|
3339
|
+
print("This code expired before it was confirmed. Run join again for a fresh code.");
|
|
3340
|
+
return 1;
|
|
3341
|
+
}
|
|
3342
|
+
if (poll.refusedReason === "grant_failed") {
|
|
3343
|
+
print("");
|
|
3344
|
+
print("Join failed partway through. Some grants may not have gone through.");
|
|
3345
|
+
const granted = poll.granted ?? [];
|
|
3346
|
+
if (granted.length > 0) {
|
|
3347
|
+
print("");
|
|
3348
|
+
print("Granted before the failure:");
|
|
3349
|
+
for (const grant of granted)
|
|
3350
|
+
print(` ${describeGrant(grant)}`);
|
|
3351
|
+
print("");
|
|
3352
|
+
print("Each of these can be turned off separately, in the app's consent settings.");
|
|
3353
|
+
}
|
|
3354
|
+
print("Run join again, or check with your organisation.");
|
|
3355
|
+
return 1;
|
|
3356
|
+
}
|
|
3357
|
+
print("");
|
|
3358
|
+
print(describeRefusal(poll.refusedReason));
|
|
3359
|
+
return 1;
|
|
3360
|
+
}
|
|
3361
|
+
print("");
|
|
3362
|
+
print("Timed out waiting for confirmation. Run join again for a fresh code.");
|
|
3363
|
+
return 1;
|
|
3364
|
+
}
|
|
3365
|
+
function isRetryablePollError(error) {
|
|
3366
|
+
if (error instanceof http_1.AscendaApiError)
|
|
3367
|
+
return error.status >= 500 && error.status <= 599;
|
|
3368
|
+
return true;
|
|
3369
|
+
}
|
|
3370
|
+
function askChoice(stdin, stdout) {
|
|
3371
|
+
return new Promise((resolve) => {
|
|
3372
|
+
const rl = readline.createInterface({ input: stdin, output: stdout });
|
|
3373
|
+
let settled = false;
|
|
3374
|
+
const finish = (value) => {
|
|
3375
|
+
if (settled)
|
|
3376
|
+
return;
|
|
3377
|
+
settled = true;
|
|
3378
|
+
rl.close();
|
|
3379
|
+
resolve(value.trim());
|
|
3380
|
+
};
|
|
3381
|
+
rl.question("Choice [Not now]: ", finish);
|
|
3382
|
+
rl.once("close", () => finish(""));
|
|
3383
|
+
});
|
|
3384
|
+
}
|
|
3385
|
+
function formatLocalTime(iso) {
|
|
3386
|
+
const date = new Date(iso);
|
|
3387
|
+
if (Number.isNaN(date.getTime()))
|
|
3388
|
+
return iso;
|
|
3389
|
+
return new Intl.DateTimeFormat(void 0, { day: "numeric", month: "short", hour: "numeric", minute: "2-digit" }).format(date);
|
|
3390
|
+
}
|
|
3391
|
+
function formatWindow(startUtc, endUtc) {
|
|
3392
|
+
const start = new Date(startUtc);
|
|
3393
|
+
const end = new Date(endUtc);
|
|
3394
|
+
const sameYear = start.getUTCFullYear() === end.getUTCFullYear();
|
|
3395
|
+
const dayMonth = { day: "numeric", month: "short", timeZone: "UTC" };
|
|
3396
|
+
const withYear = { ...dayMonth, year: "numeric" };
|
|
3397
|
+
const startFmt = new Intl.DateTimeFormat("en-GB", sameYear ? dayMonth : withYear);
|
|
3398
|
+
const endFmt = new Intl.DateTimeFormat("en-GB", withYear);
|
|
3399
|
+
return `${startFmt.format(start)} \u2013 ${endFmt.format(end)}`;
|
|
3400
|
+
}
|
|
3401
|
+
var GRANT_SENTENCES = {
|
|
3402
|
+
501: "AI assistant data processing consent",
|
|
3403
|
+
507: "Import of the AI-work history already on your machine"
|
|
3404
|
+
};
|
|
3405
|
+
function describeGrant(grant) {
|
|
3406
|
+
return GRANT_SENTENCES[grant.code] ?? humanise(grant.name);
|
|
3407
|
+
}
|
|
3408
|
+
var STUDY_KIND_SENTENCES = {
|
|
3409
|
+
Report30: "a 30-day report",
|
|
3410
|
+
Study90: "a 90-day study"
|
|
3411
|
+
};
|
|
3412
|
+
function describeStudyKind(studyKind) {
|
|
3413
|
+
return STUDY_KIND_SENTENCES[studyKind] ?? humanise(studyKind);
|
|
3414
|
+
}
|
|
3415
|
+
function humanise(name) {
|
|
3416
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").trim() || name;
|
|
3417
|
+
}
|
|
3418
|
+
var REFUSED_REASON_MESSAGES = {
|
|
3419
|
+
study_no_longer_live: "That study is no longer open to join.",
|
|
3420
|
+
withdrawn: "You're no longer an active participant in that study.",
|
|
3421
|
+
// Handled as its own branch above, with its granted list, before this
|
|
3422
|
+
// table is ever consulted — present so the type stays exhaustive, and as
|
|
3423
|
+
// a plain fallback should something call this function with it directly.
|
|
3424
|
+
grant_failed: "Join failed partway through. Some grants may not have gone through.",
|
|
3425
|
+
declined: "You declined in the app. Nothing was granted.",
|
|
3426
|
+
not_enrolled: "That study couldn't enrol you, so nothing was granted."
|
|
3427
|
+
};
|
|
3428
|
+
function describeRefusal(refusedReason) {
|
|
3429
|
+
if (refusedReason && REFUSED_REASON_MESSAGES[refusedReason])
|
|
3430
|
+
return REFUSED_REASON_MESSAGES[refusedReason];
|
|
3431
|
+
return "The join didn't go through. Nothing new was granted.";
|
|
3432
|
+
}
|
|
3433
|
+
var START_ERROR_MESSAGES = {
|
|
3434
|
+
join_code_not_found: "That code is not a study anyone can join. Check it and try again.",
|
|
3435
|
+
unknown_mode: "This tool only offers Report mode from the command line.",
|
|
3436
|
+
no_live_study: "There's nothing open to join with that code right now.",
|
|
3437
|
+
too_many_open_sessions: "This tool has too many joins waiting to be confirmed. Confirm one, or let one expire, then try again.",
|
|
3438
|
+
unknown_session: "That join can no longer be found. Run join again for a fresh code."
|
|
3439
|
+
};
|
|
3440
|
+
function describeStartError(error) {
|
|
3441
|
+
if (error instanceof http_1.AscendaApiError) {
|
|
3442
|
+
if (error.errorCode && START_ERROR_MESSAGES[error.errorCode])
|
|
3443
|
+
return START_ERROR_MESSAGES[error.errorCode];
|
|
3444
|
+
if (error.status === 401)
|
|
3445
|
+
return "This tool's pairing was rejected. Re-pair it, then try again.";
|
|
3446
|
+
return `Could not reach the join code (HTTP ${error.status}).`;
|
|
3447
|
+
}
|
|
3448
|
+
return error instanceof Error ? error.message : String(error);
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
});
|
|
3452
|
+
|
|
3453
|
+
// ../packages/tool-kit/out/initiatives.js
|
|
3454
|
+
var require_initiatives = __commonJS({
|
|
3455
|
+
"../packages/tool-kit/out/initiatives.js"(exports) {
|
|
3456
|
+
"use strict";
|
|
3457
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3458
|
+
exports.INITIATIVE_COPY = void 0;
|
|
3459
|
+
exports.initiativesStatusLines = initiativesStatusLines;
|
|
3460
|
+
exports.renderInitiatives = renderInitiatives;
|
|
3461
|
+
var http_1 = require_http();
|
|
3462
|
+
var studyJoin_1 = require_studyJoin();
|
|
3463
|
+
var READ_TIMEOUT_MS = 5e3;
|
|
3464
|
+
exports.INITIATIVE_COPY = {
|
|
3465
|
+
outcomes: {
|
|
3466
|
+
moved_as_declared: "Moved the way declared, beyond the cohort's own variation",
|
|
3467
|
+
moved_against_declared: "Moved the other way, beyond the cohort's own variation",
|
|
3468
|
+
moved_no_direction_declared: "Moved beyond the cohort's own variation; no direction was declared",
|
|
3469
|
+
within_own_variation: "No further from the baseline than the cohort's own week-to-week variation",
|
|
3470
|
+
withheld: "Withheld"
|
|
3471
|
+
},
|
|
3472
|
+
withheldReasons: {
|
|
3473
|
+
cohort_below_minimum: "the cohort was too small to report on when the scoring window closed",
|
|
3474
|
+
below_minimum_cohort: "the cohort was too small to report on when the scoring window closed",
|
|
3475
|
+
below_minimum_cohort_size: "the cohort was too small to report on when the scoring window closed",
|
|
3476
|
+
baseline_withheld: "the baseline was withheld"
|
|
3477
|
+
}
|
|
3478
|
+
};
|
|
3479
|
+
var OUTCOME_EMPTY = "Not stated";
|
|
3480
|
+
var OUTCOME_UNKNOWN = "An outcome this app does not recognise";
|
|
3481
|
+
var WITHHELD_UNKNOWN = "Withheld, for a reason this version of the app doesn't name yet.";
|
|
3482
|
+
var DIRECTION_WORDS = {
|
|
3483
|
+
up: "Expected to rise",
|
|
3484
|
+
down: "Expected to fall",
|
|
3485
|
+
none_declared: "No direction declared"
|
|
3486
|
+
};
|
|
3487
|
+
var DIRECTION_UNKNOWN = "A direction this app does not recognise";
|
|
3488
|
+
async function initiativesStatusLines(ctx) {
|
|
3489
|
+
const heading = "Changes your organisation has published to you";
|
|
3490
|
+
if (!ctx.eventWriteToken) {
|
|
3491
|
+
return [heading, " Not checked: this install holds no token, so nothing was fetched."];
|
|
3492
|
+
}
|
|
3493
|
+
const read = await (0, http_1.readInitiatives)(ctx.apiBaseUrl, ctx.eventWriteToken, AbortSignal.timeout(ctx.fetchTimeoutMs ?? READ_TIMEOUT_MS));
|
|
3494
|
+
if (read.kind === "rejected") {
|
|
3495
|
+
return [
|
|
3496
|
+
heading,
|
|
3497
|
+
` Couldn't check: the server turned this install's request down. If that keeps happening, pair again with \`${ctx.pairCommand}\`.`
|
|
3498
|
+
];
|
|
3499
|
+
}
|
|
3500
|
+
if (read.kind === "failed") {
|
|
3501
|
+
return [heading, ` Couldn't check: ${read.reason}. Run status again to retry.`];
|
|
3502
|
+
}
|
|
3503
|
+
return [heading, ...renderInitiatives(read.initiatives)];
|
|
3504
|
+
}
|
|
3505
|
+
function renderInitiatives(entries, copy = exports.INITIATIVE_COPY) {
|
|
3506
|
+
if (entries.length === 0)
|
|
3507
|
+
return [" None published to you."];
|
|
3508
|
+
const lines = [];
|
|
3509
|
+
let unreadable = 0;
|
|
3510
|
+
for (const entry of entries) {
|
|
3511
|
+
const initiative = asInitiative(entry);
|
|
3512
|
+
if (!initiative) {
|
|
3513
|
+
unreadable += 1;
|
|
3514
|
+
continue;
|
|
3515
|
+
}
|
|
3516
|
+
lines.push(...renderOne(initiative, copy));
|
|
3517
|
+
}
|
|
3518
|
+
if (unreadable > 0) {
|
|
3519
|
+
lines.push(` ${unreadable === 1 ? "1 entry" : `${unreadable} entries`} in the list couldn't be read by this version of the tool.`);
|
|
3520
|
+
}
|
|
3521
|
+
return lines;
|
|
3522
|
+
}
|
|
3523
|
+
function renderOne(initiative, copy) {
|
|
3524
|
+
const lines = [` ${initiative.organisationName}: ${initiative.title}`];
|
|
3525
|
+
lines.push(` ${describeStatus(initiative)}`);
|
|
3526
|
+
if (initiative.summaryForCohort) {
|
|
3527
|
+
for (const line of initiative.summaryForCohort.split(/\r?\n/))
|
|
3528
|
+
lines.push(` ${line}`);
|
|
3529
|
+
}
|
|
3530
|
+
if (initiative.direction)
|
|
3531
|
+
lines.push(` ${DIRECTION_WORDS[initiative.direction] ?? DIRECTION_UNKNOWN}`);
|
|
3532
|
+
lines.push(` Scoring window: ${formatWindowOrRaw(initiative.scoringStartUtc, initiative.scoringEndUtc)}`);
|
|
3533
|
+
if (initiative.result)
|
|
3534
|
+
lines.push(...renderResult(initiative.result, initiative.measureUnit, copy));
|
|
3535
|
+
lines.push("");
|
|
3536
|
+
return lines;
|
|
3537
|
+
}
|
|
3538
|
+
function describeStatus(initiative) {
|
|
3539
|
+
switch (initiative.status) {
|
|
3540
|
+
case "published":
|
|
3541
|
+
return "Published, not scored yet.";
|
|
3542
|
+
case "scored":
|
|
3543
|
+
return "Scored.";
|
|
3544
|
+
case "withdrawn":
|
|
3545
|
+
return initiative.withdrawnUtc ? `Withdrawn on ${formatDay(initiative.withdrawnUtc)}. It won't be scored.` : "Withdrawn. It won't be scored.";
|
|
3546
|
+
default:
|
|
3547
|
+
return "Status not recognised.";
|
|
3548
|
+
}
|
|
3549
|
+
}
|
|
3550
|
+
function renderResult(result, unit, copy) {
|
|
3551
|
+
const lines = [];
|
|
3552
|
+
const show = (n) => unit ? `${figure(n)} ${unit}` : figure(n);
|
|
3553
|
+
if (result.value === null) {
|
|
3554
|
+
const why = copy.withheldReasons[result.withheldReason ?? ""];
|
|
3555
|
+
lines.push(` ${why ? `Withheld: ${why}.` : WITHHELD_UNKNOWN}`);
|
|
3556
|
+
return lines;
|
|
3557
|
+
}
|
|
3558
|
+
lines.push(` Result: ${show(result.value)}`);
|
|
3559
|
+
lines.push(` ${movementLine(result)}`);
|
|
3560
|
+
lines.push(` ${result.outcome ? copy.outcomes[result.outcome] ?? OUTCOME_UNKNOWN : OUTCOME_EMPTY}`);
|
|
3561
|
+
return lines;
|
|
3562
|
+
}
|
|
3563
|
+
function movementLine(result) {
|
|
3564
|
+
if (result.outcome === "within_own_variation")
|
|
3565
|
+
return "No material change against frozen baseline";
|
|
3566
|
+
if (result.delta === null)
|
|
3567
|
+
return "No reading";
|
|
3568
|
+
if (result.delta > 0)
|
|
3569
|
+
return `Up ${figure(result.delta)} against frozen baseline`;
|
|
3570
|
+
if (result.delta < 0)
|
|
3571
|
+
return `Down ${figure(Math.abs(result.delta))} against frozen baseline`;
|
|
3572
|
+
return "No change against frozen baseline";
|
|
3573
|
+
}
|
|
3574
|
+
function figure(n) {
|
|
3575
|
+
return String(Number(n.toPrecision(12)));
|
|
3576
|
+
}
|
|
3577
|
+
function asInitiative(value) {
|
|
3578
|
+
if (!value || typeof value !== "object")
|
|
3579
|
+
return void 0;
|
|
3580
|
+
const o = value;
|
|
3581
|
+
if (typeof o.title !== "string" || typeof o.status !== "string")
|
|
3582
|
+
return void 0;
|
|
3583
|
+
return {
|
|
3584
|
+
id: typeof o.id === "string" ? o.id : "",
|
|
3585
|
+
organisationName: typeof o.organisationName === "string" ? o.organisationName : "Your organisation",
|
|
3586
|
+
title: o.title,
|
|
3587
|
+
summaryForCohort: typeof o.summaryForCohort === "string" ? o.summaryForCohort : "",
|
|
3588
|
+
measureUnit: typeof o.measureUnit === "string" ? o.measureUnit : null,
|
|
3589
|
+
scoringStartUtc: typeof o.scoringStartUtc === "string" ? o.scoringStartUtc : "",
|
|
3590
|
+
scoringEndUtc: typeof o.scoringEndUtc === "string" ? o.scoringEndUtc : "",
|
|
3591
|
+
withdrawnUtc: typeof o.withdrawnUtc === "string" ? o.withdrawnUtc : null,
|
|
3592
|
+
status: o.status,
|
|
3593
|
+
direction: typeof o.direction === "string" ? o.direction : null,
|
|
3594
|
+
result: asResult(o.result)
|
|
3595
|
+
};
|
|
3596
|
+
}
|
|
3597
|
+
function asResult(value) {
|
|
3598
|
+
if (!value || typeof value !== "object")
|
|
3599
|
+
return null;
|
|
3600
|
+
const r = value;
|
|
3601
|
+
const num = (x) => typeof x === "number" && Number.isFinite(x) ? x : null;
|
|
3602
|
+
return {
|
|
3603
|
+
scoredAtUtc: typeof r.scoredAtUtc === "string" ? r.scoredAtUtc : "",
|
|
3604
|
+
value: num(r.value),
|
|
3605
|
+
baselineValue: num(r.baselineValue),
|
|
3606
|
+
delta: num(r.delta),
|
|
3607
|
+
movement: typeof r.movement === "string" ? r.movement : null,
|
|
3608
|
+
outcome: typeof r.outcome === "string" ? r.outcome : "",
|
|
3609
|
+
withheldReason: typeof r.withheldReason === "string" ? r.withheldReason : null,
|
|
3610
|
+
basis: typeof r.basis === "string" ? r.basis : null
|
|
3611
|
+
};
|
|
3612
|
+
}
|
|
3613
|
+
function formatWindowOrRaw(startUtc, endUtc) {
|
|
3614
|
+
if (Number.isNaN(Date.parse(startUtc)) || Number.isNaN(Date.parse(endUtc)))
|
|
3615
|
+
return "not given";
|
|
3616
|
+
return (0, studyJoin_1.formatWindow)(startUtc, endUtc);
|
|
3617
|
+
}
|
|
3618
|
+
function formatDay(iso) {
|
|
3619
|
+
const date = new Date(iso);
|
|
3620
|
+
if (Number.isNaN(date.getTime()))
|
|
3621
|
+
return iso;
|
|
3622
|
+
return new Intl.DateTimeFormat("en-GB", { day: "numeric", month: "short", year: "numeric", timeZone: "UTC" }).format(date);
|
|
3623
|
+
}
|
|
3624
|
+
}
|
|
3625
|
+
});
|
|
3626
|
+
|
|
3627
|
+
// ../packages/tool-kit/out/setupDisclosure.js
|
|
3628
|
+
var require_setupDisclosure = __commonJS({
|
|
3629
|
+
"../packages/tool-kit/out/setupDisclosure.js"(exports) {
|
|
3630
|
+
"use strict";
|
|
3631
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3632
|
+
exports.FREE_TEXT_KEYS = exports.REFUSALS = exports.ALWAYS_SENT = exports.FAMILY_SENTENCES = void 0;
|
|
3633
|
+
exports.renderSetupDisclosure = renderSetupDisclosure;
|
|
3634
|
+
exports.FAMILY_SENTENCES = {
|
|
3635
|
+
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",
|
|
3636
|
+
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",
|
|
3637
|
+
tools: "the name of each tool your agent calls",
|
|
3638
|
+
outcome: "whether a call succeeded, failed, or was interrupted",
|
|
3639
|
+
clock: "your machine's offset from UTC, so an evening is read as an evening",
|
|
3640
|
+
repo: "your project and branch as digests computed on this machine \u2014 never the names themselves",
|
|
3641
|
+
model: "which model served the session, by name and by tier",
|
|
3642
|
+
posture: "the permission posture your agent was working under \u2014 asking each time, accepting edits, and so on",
|
|
3643
|
+
git: "that a commit, push or revert happened, and when a pull request opened or merged",
|
|
3644
|
+
edits: "roughly how much a file changed, as a bucket, and whether you edited it after the agent wrote it",
|
|
3645
|
+
context: "how full the context window got",
|
|
3646
|
+
waiting: "that your agent stopped and waited for you, as one word: permission_request, idle_prompt, or other",
|
|
3647
|
+
subagents: "when a subagent starts and stops, the id your agent gives it, and whether it was built in, from a plugin or one you defined \u2014 never its name or what it was asked",
|
|
3648
|
+
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"
|
|
3649
|
+
};
|
|
3650
|
+
exports.ALWAYS_SENT = ["session", "counts", "tools", "outcome", "repo", "clock"];
|
|
3651
|
+
exports.REFUSALS = [
|
|
3652
|
+
"Never your prompts, your agent's replies, or anything inside a file.",
|
|
3653
|
+
"Never a file path, a command line, or a repository or branch name.",
|
|
3654
|
+
"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."
|
|
3655
|
+
];
|
|
3656
|
+
exports.FREE_TEXT_KEYS = ["message"];
|
|
3657
|
+
function renderSetupDisclosure({ sends, displayName }) {
|
|
3658
|
+
const declared = /* @__PURE__ */ new Set([...exports.ALWAYS_SENT, ...sends]);
|
|
3659
|
+
const ordered = Object.keys(exports.FAMILY_SENTENCES).filter((family) => declared.has(family));
|
|
3660
|
+
const lines = [
|
|
3661
|
+
`What this sends from ${displayName}, once paired:`,
|
|
3662
|
+
...ordered.map((family) => ` \xB7 ${exports.FAMILY_SENTENCES[family]}`),
|
|
3663
|
+
"",
|
|
3664
|
+
...exports.REFUSALS.map((line) => ` ${line}`),
|
|
3665
|
+
"",
|
|
3666
|
+
" Turn it off by revoking this tool in the Ascenda app."
|
|
3667
|
+
];
|
|
3668
|
+
return lines.join("\n");
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3671
|
+
});
|
|
3672
|
+
|
|
3673
|
+
// ../packages/tool-kit/out/studyNotices.js
|
|
3674
|
+
var require_studyNotices = __commonJS({
|
|
3675
|
+
"../packages/tool-kit/out/studyNotices.js"(exports) {
|
|
3676
|
+
"use strict";
|
|
3677
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3678
|
+
exports.NOTICED_PURPOSES = void 0;
|
|
3679
|
+
exports.studyNoticeStatus = studyNoticeStatus;
|
|
3680
|
+
exports.renderStudyNotices = renderStudyNotices;
|
|
3681
|
+
exports.runStudyObjection = runStudyObjection;
|
|
3682
|
+
var http_1 = require_http();
|
|
3683
|
+
var READ_TIMEOUT_MS = 5e3;
|
|
3684
|
+
var NOTICE_LABEL = "Counted unless you object";
|
|
3685
|
+
var PROCESSOR = "Ascenda";
|
|
3686
|
+
exports.NOTICED_PURPOSES = [
|
|
3687
|
+
{ code: 501, slug: "telemetry", title: "Live tool telemetry" },
|
|
3688
|
+
{ code: 507, slug: "import", title: "One-time import of past AI work" },
|
|
3689
|
+
{ code: 11, slug: "work-patterns", title: "Work-pattern axes in the group figures" }
|
|
3690
|
+
];
|
|
3691
|
+
var BASIS_WORDS = {
|
|
3692
|
+
legitimate_interests: "legitimate interests",
|
|
3693
|
+
collective_agreement: "a collective agreement"
|
|
3694
|
+
};
|
|
3695
|
+
async function studyNoticeStatus(ctx) {
|
|
3696
|
+
const nothing = { lines: [], markShown: async () => {
|
|
3697
|
+
} };
|
|
3698
|
+
const token = ctx.eventWriteToken;
|
|
3699
|
+
if (!token)
|
|
3700
|
+
return nothing;
|
|
3701
|
+
const read = await (0, http_1.readStudyNotices)(ctx.apiBaseUrl, token, AbortSignal.timeout(ctx.fetchTimeoutMs ?? READ_TIMEOUT_MS));
|
|
3702
|
+
if (read.kind !== "ok")
|
|
3703
|
+
return nothing;
|
|
3704
|
+
const lines = renderStudyNotices(read.notices, ctx.commandPrefix, ctx.now);
|
|
3705
|
+
if (lines.length === 0)
|
|
3706
|
+
return nothing;
|
|
3707
|
+
const unshown = shownPurposes(read.notices).filter((n) => !n.noticeFromUtc && n.organisationId);
|
|
3708
|
+
return {
|
|
3709
|
+
lines,
|
|
3710
|
+
markShown: async () => {
|
|
3711
|
+
const signal = AbortSignal.timeout(ctx.fetchTimeoutMs ?? READ_TIMEOUT_MS);
|
|
3712
|
+
await Promise.all(unshown.map((n) => (0, http_1.markStudyNoticeShown)(ctx.apiBaseUrl, token, n.organisationId, n.code, signal)));
|
|
3713
|
+
}
|
|
3714
|
+
};
|
|
3715
|
+
}
|
|
3716
|
+
function shownPurposes(entries) {
|
|
3717
|
+
return entries.map(asNotice).filter((n) => n !== void 0 && exports.NOTICED_PURPOSES.some((p) => p.code === n.code));
|
|
3718
|
+
}
|
|
3719
|
+
function renderStudyNotices(entries, commandPrefix, now = /* @__PURE__ */ new Date()) {
|
|
3720
|
+
const body = [];
|
|
3721
|
+
let unreadable = 0;
|
|
3722
|
+
for (const entry of entries) {
|
|
3723
|
+
const notice = asNotice(entry);
|
|
3724
|
+
const purpose = notice && exports.NOTICED_PURPOSES.find((p) => p.code === notice.code);
|
|
3725
|
+
if (!notice || !purpose) {
|
|
3726
|
+
unreadable += 1;
|
|
3727
|
+
continue;
|
|
3728
|
+
}
|
|
3729
|
+
body.push(...renderOne(notice, purpose, commandPrefix, now));
|
|
3730
|
+
}
|
|
3731
|
+
if (body.length === 0)
|
|
3732
|
+
return [];
|
|
3733
|
+
if (unreadable > 0) {
|
|
3734
|
+
body.push(` ${unreadable === 1 ? "1 entry" : `${unreadable} entries`} in the list couldn't be read by this version of the tool.`);
|
|
3735
|
+
}
|
|
3736
|
+
return ["", "Your organisation's study", ...body];
|
|
3737
|
+
}
|
|
3738
|
+
function renderOne(notice, purpose, commandPrefix, now) {
|
|
3739
|
+
const org = notice.organisationName;
|
|
3740
|
+
const command = `${commandPrefix} object ${purpose.slug}`;
|
|
3741
|
+
const lines = [` ${org}: ${purpose.title}`];
|
|
3742
|
+
lines.push(` ${notice.label || NOTICE_LABEL}`);
|
|
3743
|
+
lines.push(` ${basisLine(notice)}`);
|
|
3744
|
+
if (notice.signatoryName)
|
|
3745
|
+
lines.push(` Recorded by ${notice.signatoryName}.`);
|
|
3746
|
+
lines.push(` ${notice.processor || PROCESSOR} processes this for ${org}.`);
|
|
3747
|
+
if (notice.objected === true) {
|
|
3748
|
+
lines.push(" You objected. You are left out from the next report on.");
|
|
3749
|
+
lines.push(` To undo: ${command} --undo`);
|
|
3750
|
+
} else if (notice.objected === false) {
|
|
3751
|
+
lines.push(" You haven't objected.");
|
|
3752
|
+
if (notice.noticeFromUtc && isDate(notice.noticeFromUtc)) {
|
|
3753
|
+
const starts = notice.countingFromUtc && isDate(notice.countingFromUtc) ? notice.countingFromUtc : new Date(Date.parse(notice.noticeFromUtc) + NOTICE_PERIOD_MS).toISOString();
|
|
3754
|
+
if (Date.parse(starts) > now.getTime()) {
|
|
3755
|
+
lines.push(` Notice given ${formatDay(notice.noticeFromUtc)}. Counting starts ${formatDay(starts)}.`);
|
|
3756
|
+
}
|
|
3757
|
+
}
|
|
3758
|
+
lines.push(` To object: ${command}. No reason is asked. You are left out from the next report on, and earlier reports stay as they were.`);
|
|
3759
|
+
} else {
|
|
3760
|
+
lines.push(" This version of the tool couldn't read whether you've objected. Run status again.");
|
|
3761
|
+
lines.push(` To object: ${command}`);
|
|
3762
|
+
lines.push(` To undo: ${command} --undo`);
|
|
3763
|
+
}
|
|
3764
|
+
lines.push("");
|
|
3765
|
+
return lines;
|
|
3766
|
+
}
|
|
3767
|
+
function basisLine(notice) {
|
|
3768
|
+
const words = notice.basisLabel ?? BASIS_WORDS[notice.basis];
|
|
3769
|
+
const head = words ? `${notice.organisationName}'s basis is ${words}.` : `${notice.organisationName}'s basis is one this version of the tool can't name.`;
|
|
3770
|
+
const dated = notice.documentDate && isDate(notice.documentDate) ? formatDay(notice.documentDate) : null;
|
|
3771
|
+
const ref = notice.documentReference ? `ref ${notice.documentReference}` : null;
|
|
3772
|
+
const title = notice.documentTitle ? dated ? `${notice.documentTitle} (${dated})` : notice.documentTitle : null;
|
|
3773
|
+
const document = [title, ref].filter((part) => Boolean(part)).join(", ");
|
|
3774
|
+
return document ? `${head} Document: ${document}.` : head;
|
|
3775
|
+
}
|
|
3776
|
+
var NOTICE_PERIOD_MS = 14 * 24 * 60 * 60 * 1e3;
|
|
3777
|
+
function asNotice(value) {
|
|
3778
|
+
if (!value || typeof value !== "object")
|
|
3779
|
+
return void 0;
|
|
3780
|
+
const o = value;
|
|
3781
|
+
if (typeof o.code !== "number")
|
|
3782
|
+
return void 0;
|
|
3783
|
+
if (typeof o.mode === "string" && o.mode.trim().toLowerCase() !== "notice")
|
|
3784
|
+
return void 0;
|
|
3785
|
+
const str = (x) => typeof x === "string" && x.trim() ? x : null;
|
|
3786
|
+
return {
|
|
3787
|
+
organisationId: str(o.organisationId),
|
|
3788
|
+
organisationName: str(o.organisationName) ?? "Your organisation",
|
|
3789
|
+
code: o.code,
|
|
3790
|
+
name: str(o.name),
|
|
3791
|
+
label: str(o.label),
|
|
3792
|
+
processor: str(o.processor),
|
|
3793
|
+
basis: typeof o.basis === "string" ? o.basis : "",
|
|
3794
|
+
basisLabel: str(o.basisLabel),
|
|
3795
|
+
documentTitle: str(o.documentTitle),
|
|
3796
|
+
documentDate: str(o.documentDate),
|
|
3797
|
+
documentReference: str(o.documentReference),
|
|
3798
|
+
signatoryName: str(o.signatoryName),
|
|
3799
|
+
objected: typeof o.objected === "boolean" ? o.objected : null,
|
|
3800
|
+
objectedAtUtc: str(o.objectedAtUtc),
|
|
3801
|
+
noticeFromUtc: str(o.noticeFromUtc),
|
|
3802
|
+
countingFromUtc: str(o.countingFromUtc)
|
|
3803
|
+
};
|
|
3804
|
+
}
|
|
3805
|
+
async function runStudyObjection(ctx) {
|
|
3806
|
+
const stdin = ctx.stdin ?? process.stdin;
|
|
3807
|
+
const stdout = ctx.stdout ?? process.stdout;
|
|
3808
|
+
const stderr = ctx.stderr ?? process.stderr;
|
|
3809
|
+
const print = (line) => stdout.write(`${line}
|
|
3810
|
+
`);
|
|
3811
|
+
if (!stdin.isTTY || !stdout.isTTY) {
|
|
3812
|
+
stderr.write("object needs an interactive terminal (stdin and stdout). Run it directly, not from a script or a pipe.\n");
|
|
3813
|
+
return 1;
|
|
3814
|
+
}
|
|
3815
|
+
const undo = ctx.argv.includes("--undo");
|
|
3816
|
+
const rest = ctx.argv.filter((a) => a !== "--undo");
|
|
3817
|
+
const purpose = rest.length === 1 ? exports.NOTICED_PURPOSES.find((p) => p.slug === rest[0]) : void 0;
|
|
3818
|
+
if (!purpose) {
|
|
3819
|
+
stderr.write(objectionUsage(ctx.commandPrefix));
|
|
3820
|
+
return 1;
|
|
3821
|
+
}
|
|
3822
|
+
if (!ctx.eventWriteToken) {
|
|
3823
|
+
stderr.write(`This install isn't paired, so there's nothing to object to. Pair with \`${ctx.pairCommand}\`.
|
|
3824
|
+
`);
|
|
3825
|
+
return 1;
|
|
3826
|
+
}
|
|
3827
|
+
const command = `${ctx.commandPrefix} object ${purpose.slug}`;
|
|
3828
|
+
try {
|
|
3829
|
+
await (0, http_1.setStudyObjection)(ctx.apiBaseUrl, ctx.eventWriteToken, purpose.code, !undo);
|
|
3830
|
+
} catch (error) {
|
|
3831
|
+
stderr.write(`${describeObjectionError(error, purpose, undo, ctx.pairCommand)}
|
|
3832
|
+
`);
|
|
3833
|
+
return 1;
|
|
3834
|
+
}
|
|
3835
|
+
if (undo) {
|
|
3836
|
+
print(`Objection withdrawn: ${purpose.title}.`);
|
|
3837
|
+
print("You're counted again from the next report.");
|
|
3838
|
+
print(`To object again: ${command}`);
|
|
3839
|
+
} else {
|
|
3840
|
+
print(`Objected: ${purpose.title}.`);
|
|
3841
|
+
print("You objected. You are left out from the next report on, and earlier reports stay as they were.");
|
|
3842
|
+
print(`To undo: ${command} --undo`);
|
|
3843
|
+
}
|
|
3844
|
+
return 0;
|
|
3845
|
+
}
|
|
3846
|
+
function objectionUsage(commandPrefix) {
|
|
3847
|
+
const lines = [`Usage: ${commandPrefix} object <purpose> [--undo]`, "", "Purposes:"];
|
|
3848
|
+
for (const p of exports.NOTICED_PURPOSES)
|
|
3849
|
+
lines.push(` ${p.slug.padEnd(14)}${p.title}`);
|
|
3850
|
+
lines.push("", "status shows which of these your organisation counts unless you object.");
|
|
3851
|
+
return `${lines.join("\n")}
|
|
3852
|
+
`;
|
|
3853
|
+
}
|
|
3854
|
+
function describeObjectionError(error, purpose, undo, pairCommand) {
|
|
3855
|
+
if (error instanceof http_1.AscendaApiError) {
|
|
3856
|
+
if (error.status === 404 && error.errorCode === "not_noticed") {
|
|
3857
|
+
return undo ? `Your organisation doesn't count you for ${purpose.title} unless you object, so there's no objection to undo.` : `Your organisation doesn't count you for ${purpose.title} unless you object, so there's nothing to object to.`;
|
|
3858
|
+
}
|
|
3859
|
+
if (error.status === 401)
|
|
3860
|
+
return `The server turned this install's request down. If that keeps happening, pair again with \`${pairCommand}\`.`;
|
|
3861
|
+
if (error.status === 404)
|
|
3862
|
+
return "This server doesn't take objections yet. Nothing changed.";
|
|
3863
|
+
return `Couldn't record that (HTTP ${error.status}). Nothing changed. Run it again to retry.`;
|
|
3864
|
+
}
|
|
3865
|
+
return "Couldn't reach the server. Nothing changed. Run it again to retry.";
|
|
3866
|
+
}
|
|
3867
|
+
function isDate(iso) {
|
|
3868
|
+
return !Number.isNaN(Date.parse(iso));
|
|
3869
|
+
}
|
|
3870
|
+
var MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
3871
|
+
function formatDay(iso) {
|
|
3872
|
+
const date = new Date(iso);
|
|
3873
|
+
return `${date.getUTCDate()} ${MONTHS[date.getUTCMonth()]} ${date.getUTCFullYear()}`;
|
|
3874
|
+
}
|
|
3875
|
+
}
|
|
3876
|
+
});
|
|
3877
|
+
|
|
2841
3878
|
// ../packages/tool-kit/out/cliAgentSetup.js
|
|
2842
3879
|
var require_cliAgentSetup = __commonJS({
|
|
2843
3880
|
"../packages/tool-kit/out/cliAgentSetup.js"(exports) {
|
|
@@ -2884,16 +3921,24 @@ var require_cliAgentSetup = __commonJS({
|
|
|
2884
3921
|
exports.cliAgentHookBinPath = cliAgentHookBinPath;
|
|
2885
3922
|
exports.runCliAgentSetup = runCliAgentSetup2;
|
|
2886
3923
|
exports.writeHookSettings = writeHookSettings;
|
|
3924
|
+
exports.registeredHookSets = registeredHookSets;
|
|
2887
3925
|
exports.findStaleHookCommands = findStaleHookCommands;
|
|
2888
3926
|
var crypto = __importStar(__require("crypto"));
|
|
2889
3927
|
var fs = __importStar(__require("fs"));
|
|
2890
3928
|
var os2 = __importStar(__require("os"));
|
|
2891
3929
|
var path2 = __importStar(__require("path"));
|
|
3930
|
+
var collectorVersion_1 = require_collectorVersion();
|
|
2892
3931
|
var credentials_1 = require_credentials();
|
|
2893
3932
|
var hookAdapter_1 = require_hookAdapter();
|
|
2894
3933
|
var http_1 = require_http();
|
|
3934
|
+
var hookSet_1 = require_hookSet();
|
|
3935
|
+
var initiatives_1 = require_initiatives();
|
|
3936
|
+
var setupDisclosure_1 = require_setupDisclosure();
|
|
3937
|
+
var stateStore_1 = require_stateStore();
|
|
3938
|
+
var studyJoin_1 = require_studyJoin();
|
|
3939
|
+
var studyNotices_1 = require_studyNotices();
|
|
2895
3940
|
var tokenStore_1 = require_tokenStore();
|
|
2896
|
-
var MANAGEMENT_COMMANDS = /* @__PURE__ */ new Set(["setup", "install", "status", "uninstall", "-h", "--help"]);
|
|
3941
|
+
var MANAGEMENT_COMMANDS = /* @__PURE__ */ new Set(["setup", "install", "status", "uninstall", "join", "object", "-h", "--help"]);
|
|
2897
3942
|
function isCliAgentManagementCommand2(argument) {
|
|
2898
3943
|
return argument !== void 0 && MANAGEMENT_COMMANDS.has(argument);
|
|
2899
3944
|
}
|
|
@@ -2906,12 +3951,15 @@ var require_cliAgentSetup = __commonJS({
|
|
|
2906
3951
|
npx ${spec.packageName} setup [options]
|
|
2907
3952
|
npx ${spec.packageName} status
|
|
2908
3953
|
npx ${spec.packageName} uninstall
|
|
3954
|
+
npx ${spec.packageName} join <code>
|
|
3955
|
+
npx ${spec.packageName} object <purpose> [--undo]
|
|
2909
3956
|
|
|
2910
3957
|
Options
|
|
2911
3958
|
--api-base-url <url> ingest host (default ${hookAdapter_1.DEFAULT_API_BASE_URL})
|
|
2912
3959
|
--local [port] shorthand for the local dev server (default port 4477)
|
|
2913
3960
|
--tool-installation-id <id> reuse an existing pairing instead of creating one
|
|
2914
3961
|
--token <eventWriteToken> reuse an existing token (stored 0600, never printed)
|
|
3962
|
+
--no-pair install without pairing: local features on, nothing sent
|
|
2915
3963
|
--scope project|user where hooks are registered (default project)
|
|
2916
3964
|
--project-dir <path> project root for --scope project (default cwd)
|
|
2917
3965
|
--dry-run print what would change, write nothing
|
|
@@ -2919,6 +3967,10 @@ Options
|
|
|
2919
3967
|
`;
|
|
2920
3968
|
}
|
|
2921
3969
|
async function runCliAgentSetup2(argv, spec) {
|
|
3970
|
+
if (argv[0] === "join")
|
|
3971
|
+
return runCliAgentStudyJoin(argv.slice(1), spec);
|
|
3972
|
+
if (argv[0] === "object")
|
|
3973
|
+
return runCliAgentStudyObjection(argv.slice(1), spec);
|
|
2922
3974
|
let options;
|
|
2923
3975
|
try {
|
|
2924
3976
|
options = parseArgs(argv, spec);
|
|
@@ -2931,32 +3983,60 @@ Options
|
|
|
2931
3983
|
return 0;
|
|
2932
3984
|
}
|
|
2933
3985
|
if (options.action === "status")
|
|
2934
|
-
return printStatus(options, spec);
|
|
3986
|
+
return await printStatus(options, spec);
|
|
2935
3987
|
if (options.action === "uninstall")
|
|
2936
3988
|
return uninstall(options, spec);
|
|
2937
3989
|
const apiBaseUrl = (options.apiBaseUrl ?? (0, credentials_1.readHostCredentials)(spec.host)?.apiBaseUrl ?? hookAdapter_1.DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
2938
3990
|
console.log(`Ascenda setup for ${spec.displayName} \u2014 ${apiBaseUrl}`);
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
3991
|
+
console.log(`
|
|
3992
|
+
${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName: spec.displayName })}
|
|
3993
|
+
`);
|
|
3994
|
+
let identity;
|
|
3995
|
+
let unpairedReason;
|
|
3996
|
+
if (options.skipPairing) {
|
|
3997
|
+
unpairedReason = "asked not to pair (--no-pair)";
|
|
3998
|
+
} else {
|
|
3999
|
+
identity = await resolveIdentity(apiBaseUrl, options, spec);
|
|
4000
|
+
if (identity) {
|
|
4001
|
+
console.log(` pairing ${identity.toolInstallationId}${identity.paired ? " (new)" : " (existing)"}`);
|
|
4002
|
+
} else {
|
|
4003
|
+
unpairedReason = "pairing did not finish \u2014 installing the local half anyway";
|
|
4004
|
+
}
|
|
4005
|
+
}
|
|
4006
|
+
if (unpairedReason) {
|
|
4007
|
+
console.log(` pairing none: ${unpairedReason}`);
|
|
4008
|
+
console.log(" local features on, nothing is sent");
|
|
4009
|
+
}
|
|
2943
4010
|
const binary = installBinary(spec, options.dryRun);
|
|
2944
4011
|
console.log(` hook binary ${binary}`);
|
|
2945
4012
|
if (!options.dryRun) {
|
|
2946
|
-
|
|
4013
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
4014
|
+
const toolInstallationId = identity?.toolInstallationId ?? options.toolInstallationId ?? (0, credentials_1.readHostCredentials)(spec.host)?.toolInstallationId ?? `${spec.toolType}:${crypto.randomUUID()}`;
|
|
4015
|
+
(0, credentials_1.writeHostCredentials)(spec.host, {
|
|
4016
|
+
apiBaseUrl,
|
|
4017
|
+
toolInstallationId,
|
|
4018
|
+
...identity ? { pairedAt: now } : { localOnly: true, installedAt: now }
|
|
4019
|
+
});
|
|
2947
4020
|
}
|
|
2948
4021
|
console.log(` credentials ${(0, credentials_1.credentialsFilePath)()} (tools.${spec.host})`);
|
|
2949
4022
|
const settingsFile = spec.settings.settingsPath(options.scope, options.projectDir);
|
|
4023
|
+
const before = registeredHookSets(readSettings(settingsFile), spec);
|
|
2950
4024
|
const written = writeHookSettings(settingsFile, binary, spec, options.dryRun);
|
|
2951
4025
|
if (written === null)
|
|
2952
4026
|
return 1;
|
|
2953
4027
|
console.log(` hooks ${settingsFile} (${spec.hookEvents.length} events${written ? "" : ", already current"})`);
|
|
4028
|
+
const changes = spec.hookSet === void 0 ? void 0 : (0, hookSet_1.describeHookSetChanges)((0, hookSet_1.hookSetChanges)(before, spec.hookEvents), spec.hookSet);
|
|
4029
|
+
if (changes)
|
|
4030
|
+
console.log(` ${changes}`);
|
|
2954
4031
|
if (options.dryRun) {
|
|
2955
4032
|
console.log("\nDry run \u2014 nothing was written.");
|
|
2956
4033
|
return 0;
|
|
2957
4034
|
}
|
|
2958
4035
|
console.log(`
|
|
2959
4036
|
Done. ${spec.restartHint}`);
|
|
4037
|
+
if (!identity) {
|
|
4038
|
+
console.log(`Pair later: npx ${spec.packageName} setup`);
|
|
4039
|
+
}
|
|
2960
4040
|
console.log(`Check anytime: npx ${spec.packageName} status`);
|
|
2961
4041
|
return 0;
|
|
2962
4042
|
}
|
|
@@ -2965,6 +4045,7 @@ Done. ${spec.restartHint}`);
|
|
|
2965
4045
|
scope: "project",
|
|
2966
4046
|
projectDir: process.cwd(),
|
|
2967
4047
|
dryRun: false,
|
|
4048
|
+
skipPairing: false,
|
|
2968
4049
|
action: "install"
|
|
2969
4050
|
};
|
|
2970
4051
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -3014,6 +4095,14 @@ Done. ${spec.restartHint}`);
|
|
|
3014
4095
|
case "--dry-run":
|
|
3015
4096
|
options.dryRun = true;
|
|
3016
4097
|
break;
|
|
4098
|
+
case "--no-pair":
|
|
4099
|
+
// `--no-pairing` is the spelling this landed under first. Both appeared
|
|
4100
|
+
// only in an unreleased changelog, so this alias exists to spare anyone
|
|
4101
|
+
// reading that draft, and `--no-pair` — the Claude Code adapter's own
|
|
4102
|
+
// spelling — is the documented one.
|
|
4103
|
+
case "--no-pairing":
|
|
4104
|
+
options.skipPairing = true;
|
|
4105
|
+
break;
|
|
3017
4106
|
case "-h":
|
|
3018
4107
|
case "--help":
|
|
3019
4108
|
options.action = "help";
|
|
@@ -3026,6 +4115,45 @@ ${usage(spec)}`);
|
|
|
3026
4115
|
}
|
|
3027
4116
|
return options;
|
|
3028
4117
|
}
|
|
4118
|
+
async function runCliAgentStudyJoin(argv, spec) {
|
|
4119
|
+
const joinCode = argv[0];
|
|
4120
|
+
if (!joinCode || joinCode.startsWith("-")) {
|
|
4121
|
+
console.error(`Usage: npx ${spec.packageName} join <code>`);
|
|
4122
|
+
return 1;
|
|
4123
|
+
}
|
|
4124
|
+
const pairing = resolvePairedToken(spec);
|
|
4125
|
+
if (!pairing)
|
|
4126
|
+
return 1;
|
|
4127
|
+
return (0, studyJoin_1.runStudyJoin)({ ...pairing, displayName: spec.displayName, joinCode });
|
|
4128
|
+
}
|
|
4129
|
+
async function runCliAgentStudyObjection(argv, spec) {
|
|
4130
|
+
const pairing = resolvePairedToken(spec);
|
|
4131
|
+
if (!pairing)
|
|
4132
|
+
return 1;
|
|
4133
|
+
return (0, studyNotices_1.runStudyObjection)({
|
|
4134
|
+
...pairing,
|
|
4135
|
+
commandPrefix: `npx ${spec.packageName}`,
|
|
4136
|
+
pairCommand: `npx ${spec.packageName} setup`,
|
|
4137
|
+
argv
|
|
4138
|
+
});
|
|
4139
|
+
}
|
|
4140
|
+
function resolvePairedToken(spec) {
|
|
4141
|
+
const setupCommand = `npx ${spec.packageName} setup`;
|
|
4142
|
+
let toolInstallationId;
|
|
4143
|
+
try {
|
|
4144
|
+
({ toolInstallationId } = (0, hookAdapter_1.resolveCliAgentInstallationId)(spec.toolType, { host: spec.host, setupCommand }));
|
|
4145
|
+
} catch (error) {
|
|
4146
|
+
console.error(error instanceof hookAdapter_1.MissingInstallationIdError ? error.message : error instanceof Error ? error.message : String(error));
|
|
4147
|
+
return void 0;
|
|
4148
|
+
}
|
|
4149
|
+
const eventWriteToken = (0, tokenStore_1.readTokenFile)(process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0, tokenStore_1.defaultTokenFilePath)(toolInstallationId)) ?? process.env.ASCENDA_EVENT_WRITE_TOKEN;
|
|
4150
|
+
if (!eventWriteToken) {
|
|
4151
|
+
console.error(`Not paired: no write token for ${toolInstallationId}. Run: ${setupCommand}`);
|
|
4152
|
+
return void 0;
|
|
4153
|
+
}
|
|
4154
|
+
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? (0, credentials_1.readHostCredentials)(spec.host)?.apiBaseUrl ?? hookAdapter_1.DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
4155
|
+
return { apiBaseUrl, eventWriteToken };
|
|
4156
|
+
}
|
|
3029
4157
|
async function resolveIdentity(apiBaseUrl, options, spec) {
|
|
3030
4158
|
const existingId = options.toolInstallationId ?? (0, credentials_1.readHostCredentials)(spec.host)?.toolInstallationId;
|
|
3031
4159
|
if (existingId && options.token) {
|
|
@@ -3033,8 +4161,13 @@ ${usage(spec)}`);
|
|
|
3033
4161
|
(0, tokenStore_1.persistEventWriteToken)((0, tokenStore_1.defaultTokenFilePath)(existingId), options.token);
|
|
3034
4162
|
return { toolInstallationId: existingId, paired: false };
|
|
3035
4163
|
}
|
|
3036
|
-
|
|
3037
|
-
|
|
4164
|
+
const existingToken = existingId ? (0, tokenStore_1.readTokenFile)((0, tokenStore_1.defaultTokenFilePath)(existingId)) : void 0;
|
|
4165
|
+
if (existingId && existingToken) {
|
|
4166
|
+
const check = await checkSavedToken(apiBaseUrl, existingId, existingToken);
|
|
4167
|
+
if (check === "keep")
|
|
4168
|
+
return { toolInstallationId: existingId, paired: false };
|
|
4169
|
+
console.log(`
|
|
4170
|
+
The saved token for ${existingId} isn't accepted any more. Pairing again.`);
|
|
3038
4171
|
}
|
|
3039
4172
|
if (options.dryRun) {
|
|
3040
4173
|
return { toolInstallationId: existingId ?? `${spec.toolType}:<paired at run time>`, paired: false };
|
|
@@ -3055,6 +4188,18 @@ Could not reach ${apiBaseUrl} to pair: ${error instanceof Error ? error.message
|
|
|
3055
4188
|
(0, tokenStore_1.persistEventWriteToken)((0, tokenStore_1.defaultTokenFilePath)(toolInstallationId), token);
|
|
3056
4189
|
return { toolInstallationId, paired: true };
|
|
3057
4190
|
}
|
|
4191
|
+
var TOKEN_CHECK_TIMEOUT_MS = 5e3;
|
|
4192
|
+
async function checkSavedToken(apiBaseUrl, toolInstallationId, token) {
|
|
4193
|
+
const read = await (0, http_1.readInitiatives)(apiBaseUrl, token, AbortSignal.timeout(TOKEN_CHECK_TIMEOUT_MS));
|
|
4194
|
+
if (read.kind === "rejected")
|
|
4195
|
+
return "repair";
|
|
4196
|
+
if (read.kind === "failed" && (0, stateStore_1.readCollectorState)((0, stateStore_1.defaultStateFilePath)(toolInstallationId))?.lastOutcome === "auth_failed") {
|
|
4197
|
+
console.log(`
|
|
4198
|
+
Couldn't check the saved token (${read.reason}), and the last send was refused.`);
|
|
4199
|
+
console.log(" Keeping it for now. Run setup again once the server is reachable.");
|
|
4200
|
+
}
|
|
4201
|
+
return "keep";
|
|
4202
|
+
}
|
|
3058
4203
|
async function pollForToken(apiBaseUrl, pairingSessionId, code, expiresAt) {
|
|
3059
4204
|
const deadline = Math.min(Date.parse(expiresAt) || Date.now() + 3e5, Date.now() + 3e5);
|
|
3060
4205
|
let announced = false;
|
|
@@ -3106,7 +4251,7 @@ ${settingsFile} is not valid JSON. Fix or move it, then run setup again.`);
|
|
|
3106
4251
|
}
|
|
3107
4252
|
}
|
|
3108
4253
|
}
|
|
3109
|
-
const command = hookCommand(binary);
|
|
4254
|
+
const command = hookCommand(binary, spec);
|
|
3110
4255
|
const hooks = { ...settings.hooks ?? {} };
|
|
3111
4256
|
for (const event of spec.hookEvents) {
|
|
3112
4257
|
const kept = (hooks[event] ?? []).filter((entry) => !isOurs(entry, spec));
|
|
@@ -3129,8 +4274,20 @@ ${serialised}`);
|
|
|
3129
4274
|
fs.writeFileSync(settingsFile, serialised, "utf8");
|
|
3130
4275
|
return true;
|
|
3131
4276
|
}
|
|
3132
|
-
function hookCommand(binary) {
|
|
3133
|
-
return `"${process.execPath}" "${binary}"`;
|
|
4277
|
+
function hookCommand(binary, spec) {
|
|
4278
|
+
return `"${process.execPath}" "${binary}"${(0, hookSet_1.hookSetArgument)(spec.hookSet)}`;
|
|
4279
|
+
}
|
|
4280
|
+
function registeredHookSets(settings, spec) {
|
|
4281
|
+
const sets = /* @__PURE__ */ new Map();
|
|
4282
|
+
for (const [event, entries] of Object.entries(settings.hooks ?? {})) {
|
|
4283
|
+
for (const entry of entries ?? []) {
|
|
4284
|
+
if (!isOurs(entry, spec))
|
|
4285
|
+
continue;
|
|
4286
|
+
const set = (0, hookSet_1.hookSetOfCommand)(spec.settings.commandOf(entry));
|
|
4287
|
+
sets.set(event, Math.min(set, sets.get(event) ?? set));
|
|
4288
|
+
}
|
|
4289
|
+
}
|
|
4290
|
+
return sets;
|
|
3134
4291
|
}
|
|
3135
4292
|
function isOurs(entry, spec) {
|
|
3136
4293
|
const command = spec.settings.commandOf(entry);
|
|
@@ -3157,7 +4314,7 @@ ${serialised}`);
|
|
|
3157
4314
|
return {};
|
|
3158
4315
|
}
|
|
3159
4316
|
}
|
|
3160
|
-
function printStatus(options, spec) {
|
|
4317
|
+
async function printStatus(options, spec) {
|
|
3161
4318
|
const credentials = (0, credentials_1.readHostCredentials)(spec.host);
|
|
3162
4319
|
const settingsFile = spec.settings.settingsPath(options.scope, options.projectDir);
|
|
3163
4320
|
const binary = cliAgentHookBinPath(spec.binaryName);
|
|
@@ -3165,18 +4322,39 @@ ${serialised}`);
|
|
|
3165
4322
|
const settings = readSettings(settingsFile);
|
|
3166
4323
|
const registered = spec.hookEvents.filter((event) => (settings.hooks?.[event] ?? []).some((entry) => isOurs(entry, spec))).length;
|
|
3167
4324
|
const stale = findStaleHookCommands(settings, binary, spec);
|
|
4325
|
+
const localOnly = (0, credentials_1.isLocalOnlyHostInstall)(spec.host, (id) => (0, tokenStore_1.readTokenFile)((0, tokenStore_1.defaultTokenFilePath)(id)) !== void 0);
|
|
4326
|
+
console.log(`version ${(0, collectorVersion_1.describeCollectorVersion)()}`);
|
|
3168
4327
|
console.log(`api base url ${credentials?.apiBaseUrl ?? "\u2014 not configured"}`);
|
|
3169
|
-
console.log(`pairing ${credentials?.toolInstallationId ?? "\u2014 not paired"}`);
|
|
3170
|
-
console.log(`token ${tokenFile && (0, tokenStore_1.readTokenFile)(tokenFile) ? "present" : "\u2014 missing"}`);
|
|
4328
|
+
console.log(`pairing ${credentials?.toolInstallationId ?? "\u2014 not paired"}${localOnly ? " (installed, not paired \u2014 local features active, telemetry inactive)" : ""}`);
|
|
4329
|
+
console.log(`token ${localOnly ? "\u2014 none needed until this install is paired" : tokenFile && (0, tokenStore_1.readTokenFile)(tokenFile) ? "present" : "\u2014 missing"}`);
|
|
3171
4330
|
console.log(`hook binary ${fs.existsSync(binary) ? binary : "\u2014 not installed"}`);
|
|
3172
4331
|
console.log(`hooks ${registered}/${spec.hookEvents.length} registered in ${settingsFile}`);
|
|
4332
|
+
if (spec.hookSet !== void 0 && registered > 0) {
|
|
4333
|
+
const sets = [...registeredHookSets(settings, spec).values()];
|
|
4334
|
+
const oldest = Math.min(...sets);
|
|
4335
|
+
console.log(oldest < spec.hookSet ? `hook set ${oldest}, this version registers ${spec.hookSet}. Upgrade: npx ${spec.packageName} setup${options.scope === "user" ? " --scope user" : ""}` : `hook set ${spec.hookSet} (current)`);
|
|
4336
|
+
}
|
|
3173
4337
|
if (stale.length) {
|
|
3174
4338
|
console.log(`stale hooks ${stale.length} not pointing at the installed binary \u2014 each one fails silently per event:`);
|
|
3175
4339
|
for (const command of stale)
|
|
3176
4340
|
console.log(` ${command}`);
|
|
3177
4341
|
console.log(` Remove them from ${settingsFile} by hand; setup cannot tell them from a hook you wrote.`);
|
|
3178
4342
|
}
|
|
3179
|
-
const
|
|
4343
|
+
const tokenValue = localOnly ? void 0 : (tokenFile ? (0, tokenStore_1.readTokenFile)(tokenFile) : void 0) ?? (process.env.ASCENDA_EVENT_WRITE_TOKEN?.trim() || void 0);
|
|
4344
|
+
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? credentials?.apiBaseUrl ?? hookAdapter_1.DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
4345
|
+
const [initiativeLines, notices] = await Promise.all([
|
|
4346
|
+
(0, initiatives_1.initiativesStatusLines)({ apiBaseUrl, eventWriteToken: tokenValue, pairCommand: `npx ${spec.packageName} setup` }),
|
|
4347
|
+
(0, studyNotices_1.studyNoticeStatus)({ apiBaseUrl, eventWriteToken: tokenValue, commandPrefix: `npx ${spec.packageName}` })
|
|
4348
|
+
]);
|
|
4349
|
+
console.log("");
|
|
4350
|
+
for (const line of initiativeLines)
|
|
4351
|
+
console.log(line);
|
|
4352
|
+
for (const line of notices.lines)
|
|
4353
|
+
console.log(line);
|
|
4354
|
+
if (process.stdout.isTTY)
|
|
4355
|
+
await notices.markShown();
|
|
4356
|
+
const paired = localOnly || credentials?.toolInstallationId !== void 0;
|
|
4357
|
+
const healthy = paired && registered === spec.hookEvents.length && fs.existsSync(binary) && !stale.length;
|
|
3180
4358
|
return healthy ? 0 : 1;
|
|
3181
4359
|
}
|
|
3182
4360
|
function uninstall(options, spec) {
|
|
@@ -3341,6 +4519,7 @@ var require_liveBus = __commonJS({
|
|
|
3341
4519
|
};
|
|
3342
4520
|
}();
|
|
3343
4521
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4522
|
+
exports.LIVE_BUS_BACKGROUND_TRUST_MS = void 0;
|
|
3344
4523
|
exports.liveBusSocketCandidates = liveBusSocketCandidates;
|
|
3345
4524
|
exports.liveBusSocketPath = liveBusSocketPath;
|
|
3346
4525
|
exports.bucketPromptSize = bucketPromptSize2;
|
|
@@ -3349,7 +4528,9 @@ var require_liveBus = __commonJS({
|
|
|
3349
4528
|
var net = __importStar(__require("net"));
|
|
3350
4529
|
var os2 = __importStar(__require("os"));
|
|
3351
4530
|
var path2 = __importStar(__require("path"));
|
|
4531
|
+
var hookSet_1 = require_hookSet();
|
|
3352
4532
|
var WRITE_TIMEOUT_MS = 50;
|
|
4533
|
+
exports.LIVE_BUS_BACKGROUND_TRUST_MS = 60 * 60 * 1e3;
|
|
3353
4534
|
var APP_BUNDLE_ID = "one.ascenda.ascendaMissionControl";
|
|
3354
4535
|
var SAVER_HOST_BUNDLE_ID = "com.apple.ScreenSaver.Engine.legacyScreenSaver";
|
|
3355
4536
|
function liveBusSocketCandidates() {
|
|
@@ -3389,6 +4570,14 @@ var require_liveBus = __commonJS({
|
|
|
3389
4570
|
return "xl";
|
|
3390
4571
|
}
|
|
3391
4572
|
var NOBODY_LISTENING = /* @__PURE__ */ new Set(["ECONNREFUSED", "ENOENT"]);
|
|
4573
|
+
function onTheWire(signal) {
|
|
4574
|
+
const out = { ...signal };
|
|
4575
|
+
if ("hookSet" in out && !(0, hookSet_1.isHookSet)(out.hookSet))
|
|
4576
|
+
delete out.hookSet;
|
|
4577
|
+
if ("viaPlugin" in out && out.viaPlugin !== true)
|
|
4578
|
+
delete out.viaPlugin;
|
|
4579
|
+
return out;
|
|
4580
|
+
}
|
|
3392
4581
|
function emitLiveSignal2(signal) {
|
|
3393
4582
|
return new Promise((resolve) => {
|
|
3394
4583
|
const candidates = existingSocketCandidates();
|
|
@@ -3449,7 +4638,7 @@ var require_liveBus = __commonJS({
|
|
|
3449
4638
|
return;
|
|
3450
4639
|
connected = true;
|
|
3451
4640
|
try {
|
|
3452
|
-
attempt.write(`${JSON.stringify(signal)}
|
|
4641
|
+
attempt.write(`${JSON.stringify(onTheWire(signal))}
|
|
3453
4642
|
`, done);
|
|
3454
4643
|
} catch {
|
|
3455
4644
|
done();
|
|
@@ -3462,14 +4651,153 @@ var require_liveBus = __commonJS({
|
|
|
3462
4651
|
}
|
|
3463
4652
|
});
|
|
3464
4653
|
|
|
4654
|
+
// ../packages/tool-kit/out/agentProcess.js
|
|
4655
|
+
var require_agentProcess = __commonJS({
|
|
4656
|
+
"../packages/tool-kit/out/agentProcess.js"(exports) {
|
|
4657
|
+
"use strict";
|
|
4658
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4659
|
+
if (k2 === void 0) k2 = k;
|
|
4660
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4661
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
4662
|
+
desc = { enumerable: true, get: function() {
|
|
4663
|
+
return m[k];
|
|
4664
|
+
} };
|
|
4665
|
+
}
|
|
4666
|
+
Object.defineProperty(o, k2, desc);
|
|
4667
|
+
} : function(o, m, k, k2) {
|
|
4668
|
+
if (k2 === void 0) k2 = k;
|
|
4669
|
+
o[k2] = m[k];
|
|
4670
|
+
});
|
|
4671
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
4672
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
4673
|
+
} : function(o, v) {
|
|
4674
|
+
o["default"] = v;
|
|
4675
|
+
});
|
|
4676
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
4677
|
+
var ownKeys = function(o) {
|
|
4678
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
4679
|
+
var ar = [];
|
|
4680
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
4681
|
+
return ar;
|
|
4682
|
+
};
|
|
4683
|
+
return ownKeys(o);
|
|
4684
|
+
};
|
|
4685
|
+
return function(mod) {
|
|
4686
|
+
if (mod && mod.__esModule) return mod;
|
|
4687
|
+
var result = {};
|
|
4688
|
+
if (mod != null) {
|
|
4689
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
4690
|
+
}
|
|
4691
|
+
__setModuleDefault(result, mod);
|
|
4692
|
+
return result;
|
|
4693
|
+
};
|
|
4694
|
+
}();
|
|
4695
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4696
|
+
exports.psArgsLookup = exports.psLookup = exports.AGENT_PROCESS = void 0;
|
|
4697
|
+
exports.scriptMarkerIn = scriptMarkerIn;
|
|
4698
|
+
exports.findAgentProcess = findAgentProcess;
|
|
4699
|
+
exports.findAgentPid = findAgentPid2;
|
|
4700
|
+
exports.livePidFields = livePidFields;
|
|
4701
|
+
var child_process_1 = __require("child_process");
|
|
4702
|
+
var path2 = __importStar(__require("path"));
|
|
4703
|
+
exports.AGENT_PROCESS = {
|
|
4704
|
+
claude_code: {
|
|
4705
|
+
executable: (command) => path2.basename(command) === "claude" || /\/claude\/versions\/[^/]+$/.test(command) || /\/@anthropic-ai\/claude-code\/bin\/claude\.exe$/.test(command),
|
|
4706
|
+
scriptMarkers: ["@anthropic-ai/claude-code"]
|
|
4707
|
+
},
|
|
4708
|
+
codex: {
|
|
4709
|
+
executable: (command) => /^codex(-(aarch64|x86_64)-apple-darwin)?$/.test(path2.basename(command)),
|
|
4710
|
+
args: (args) => !/\s(app-server|mcp-server)(\s|$)/.test(args)
|
|
4711
|
+
},
|
|
4712
|
+
gemini_cli: {
|
|
4713
|
+
executable: () => false,
|
|
4714
|
+
args: (args) => !/\s--(experimental-)?acp(\s|=|$)/.test(args),
|
|
4715
|
+
scriptMarkers: ["@google/gemini-cli"]
|
|
4716
|
+
}
|
|
4717
|
+
};
|
|
4718
|
+
var SCRIPT_RUNTIME = /^(node|bun|deno)$/;
|
|
4719
|
+
function scriptMarkerIn(args, markers) {
|
|
4720
|
+
return markers.find((marker) => args.includes(`/${marker}/`));
|
|
4721
|
+
}
|
|
4722
|
+
var MAX_DEPTH = 6;
|
|
4723
|
+
var PS_TIMEOUT_MS = 100;
|
|
4724
|
+
function ps(columns, pid) {
|
|
4725
|
+
try {
|
|
4726
|
+
const result = (0, child_process_1.spawnSync)("/bin/ps", ["-o", columns, "-p", String(pid)], {
|
|
4727
|
+
encoding: "utf8",
|
|
4728
|
+
timeout: PS_TIMEOUT_MS
|
|
4729
|
+
});
|
|
4730
|
+
if (result.status !== 0 || typeof result.stdout !== "string")
|
|
4731
|
+
return void 0;
|
|
4732
|
+
const line = result.stdout.trim();
|
|
4733
|
+
return line === "" ? void 0 : line;
|
|
4734
|
+
} catch {
|
|
4735
|
+
return void 0;
|
|
4736
|
+
}
|
|
4737
|
+
}
|
|
4738
|
+
var psLookup = (pid) => {
|
|
4739
|
+
const line = ps("ppid=,comm=", pid);
|
|
4740
|
+
const match = line ? /^(\d+)\s+(.+)$/.exec(line) : null;
|
|
4741
|
+
return match ? { ppid: Number(match[1]), command: match[2] } : void 0;
|
|
4742
|
+
};
|
|
4743
|
+
exports.psLookup = psLookup;
|
|
4744
|
+
var psArgsLookup = (pid) => ps("args=", pid);
|
|
4745
|
+
exports.psArgsLookup = psArgsLookup;
|
|
4746
|
+
function findAgentProcess(rule, options = {}) {
|
|
4747
|
+
if (!rule)
|
|
4748
|
+
return void 0;
|
|
4749
|
+
if ((options.platform ?? process.platform) !== "darwin")
|
|
4750
|
+
return void 0;
|
|
4751
|
+
const lookup = options.lookup ?? exports.psLookup;
|
|
4752
|
+
const argsLookup = options.argsLookup ?? exports.psArgsLookup;
|
|
4753
|
+
const markers = rule.scriptMarkers ?? [];
|
|
4754
|
+
let pid = options.startPid ?? process.ppid;
|
|
4755
|
+
for (let depth = 0; depth < MAX_DEPTH && pid > 1; depth++) {
|
|
4756
|
+
const info = lookup(pid);
|
|
4757
|
+
if (!info)
|
|
4758
|
+
return void 0;
|
|
4759
|
+
if (pid !== process.pid) {
|
|
4760
|
+
if (rule.executable(info.command)) {
|
|
4761
|
+
return accepts(rule, rule.args ? argsLookup(pid) : "") ? { pid, match: "executable" } : void 0;
|
|
4762
|
+
}
|
|
4763
|
+
if (markers.length > 0 && SCRIPT_RUNTIME.test(path2.basename(info.command))) {
|
|
4764
|
+
const args = argsLookup(pid);
|
|
4765
|
+
const marker = args === void 0 ? void 0 : scriptMarkerIn(args, markers);
|
|
4766
|
+
if (marker !== void 0) {
|
|
4767
|
+
return accepts(rule, args) ? { pid, match: "path", marker } : void 0;
|
|
4768
|
+
}
|
|
4769
|
+
}
|
|
4770
|
+
}
|
|
4771
|
+
pid = info.ppid;
|
|
4772
|
+
}
|
|
4773
|
+
return void 0;
|
|
4774
|
+
}
|
|
4775
|
+
function accepts(rule, args) {
|
|
4776
|
+
if (!rule.args)
|
|
4777
|
+
return true;
|
|
4778
|
+
return args !== void 0 && rule.args(args);
|
|
4779
|
+
}
|
|
4780
|
+
function findAgentPid2(rule, options = {}) {
|
|
4781
|
+
return findAgentProcess(rule, options)?.pid;
|
|
4782
|
+
}
|
|
4783
|
+
function livePidFields(match) {
|
|
4784
|
+
if (!match)
|
|
4785
|
+
return {};
|
|
4786
|
+
if (match.match === "executable")
|
|
4787
|
+
return { pid: match.pid };
|
|
4788
|
+
return { pid: match.pid, pidMatch: "path", pidMarker: match.marker };
|
|
4789
|
+
}
|
|
4790
|
+
}
|
|
4791
|
+
});
|
|
4792
|
+
|
|
3465
4793
|
// ../packages/tool-kit/out/index.js
|
|
3466
4794
|
var require_out2 = __commonJS({
|
|
3467
4795
|
"../packages/tool-kit/out/index.js"(exports) {
|
|
3468
4796
|
"use strict";
|
|
3469
4797
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3470
|
-
exports.
|
|
3471
|
-
exports.
|
|
3472
|
-
exports.isRetryableStatus = exports.parseIngestResponse = exports.postToolEventsBatch = exports.postToolEvent = exports.renewToolToken = void 0;
|
|
4798
|
+
exports.FREE_TEXT_KEYS = exports.FAMILY_SENTENCES = exports.ALWAYS_SENT = exports.writeHookSettings = exports.runCliAgentSetup = exports.registeredHookSets = 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.TOKEN_RENEW_LEAD_MS = 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;
|
|
4799
|
+
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.tokenExpiryFilePath = exports.readTokenFile = exports.readTokenExpiry = exports.persistEventWriteToken = exports.listPersistedToolInstallationIds = exports.defaultTokenFilePath = exports.ascendaHome = exports.EVENT_TOKEN_TTL_MS = exports.recordTurnStart = exports.consumeTurnDurationMs = exports.writeTopLevelCredentials = exports.writeMachineCredentials = exports.writeHostCredentials = exports.removeHostCredentials = exports.readMachineCredentials = exports.readHostCredentials = exports.isLocalOnlyHostInstall = exports.credentialsFilePath = exports.renderSetupDisclosure = exports.REFUSALS = void 0;
|
|
4800
|
+
exports.runStudyJoin = exports.studyNoticeStatus = exports.runStudyObjection = exports.renderStudyNotices = exports.NOTICED_PURPOSES = exports.renderInitiatives = exports.initiativesStatusLines = exports.INITIATIVE_COPY = exports.startStudyJoin = exports.setStudyObjection = exports.markStudyNoticeShown = exports.readStudyNotices = exports.readInitiatives = exports.isRetryableStatus = exports.parseIngestResponse = exports.postToolEventsBatch = exports.postToolEvent = exports.renewToolToken = exports.getStudyJoinStatus = exports.getPairingStatus = exports.createPairingSession = exports.AscendaApiError = exports.scriptMarkerIn = exports.psLookup = exports.psArgsLookup = exports.livePidFields = exports.findAgentProcess = exports.findAgentPid = exports.AGENT_PROCESS = exports.readViaPlugin = exports.readHookSet = exports.isHookSet = exports.hookSetOfCommand = exports.hookSetChanges = exports.hookSetArgument = exports.describeHookSetChanges = exports.UNVERSIONED_HOOK_SET = exports.HOOK_SET_FLAG = exports.LIVE_BUS_BACKGROUND_TRUST_MS = exports.liveBusSocketCandidates = exports.liveBusSocketPath = exports.bucketPromptSize = exports.emitLiveSignal = exports.recordForgeProjectAlias = exports.forgeFullNameFromConfig = exports.readForgeFullName = exports.parseForgeFullName = exports.forgeProjectHash = exports.workContextRegistryFilePath = exports.readWorkContextRegistry = void 0;
|
|
3473
4801
|
var commandClassifier_1 = require_commandClassifier();
|
|
3474
4802
|
Object.defineProperty(exports, "classifyCommand", { enumerable: true, get: function() {
|
|
3475
4803
|
return commandClassifier_1.classifyCommand;
|
|
@@ -3550,6 +4878,16 @@ var require_out2 = __commonJS({
|
|
|
3550
4878
|
Object.defineProperty(exports, "mintIdempotencyKey", { enumerable: true, get: function() {
|
|
3551
4879
|
return payload_1.mintIdempotencyKey;
|
|
3552
4880
|
} });
|
|
4881
|
+
var collectorVersion_1 = require_collectorVersion();
|
|
4882
|
+
Object.defineProperty(exports, "COLLECTOR_VERSION", { enumerable: true, get: function() {
|
|
4883
|
+
return collectorVersion_1.COLLECTOR_VERSION;
|
|
4884
|
+
} });
|
|
4885
|
+
Object.defineProperty(exports, "UNRELEASED_COLLECTOR_VERSION", { enumerable: true, get: function() {
|
|
4886
|
+
return collectorVersion_1.UNRELEASED_COLLECTOR_VERSION;
|
|
4887
|
+
} });
|
|
4888
|
+
Object.defineProperty(exports, "describeCollectorVersion", { enumerable: true, get: function() {
|
|
4889
|
+
return collectorVersion_1.describeCollectorVersion;
|
|
4890
|
+
} });
|
|
3553
4891
|
var eventSender_1 = require_eventSender();
|
|
3554
4892
|
Object.defineProperty(exports, "AscendaEventSender", { enumerable: true, get: function() {
|
|
3555
4893
|
return eventSender_1.AscendaEventSender;
|
|
@@ -3557,6 +4895,9 @@ var require_out2 = __commonJS({
|
|
|
3557
4895
|
Object.defineProperty(exports, "AscendaSemanticEventError", { enumerable: true, get: function() {
|
|
3558
4896
|
return eventSender_1.AscendaSemanticEventError;
|
|
3559
4897
|
} });
|
|
4898
|
+
Object.defineProperty(exports, "TOKEN_RENEW_LEAD_MS", { enumerable: true, get: function() {
|
|
4899
|
+
return eventSender_1.TOKEN_RENEW_LEAD_MS;
|
|
4900
|
+
} });
|
|
3560
4901
|
Object.defineProperty(exports, "buildEventPayload", { enumerable: true, get: function() {
|
|
3561
4902
|
return eventSender_1.buildEventPayload;
|
|
3562
4903
|
} });
|
|
@@ -3602,16 +4943,38 @@ var require_out2 = __commonJS({
|
|
|
3602
4943
|
Object.defineProperty(exports, "isCliAgentManagementCommand", { enumerable: true, get: function() {
|
|
3603
4944
|
return cliAgentSetup_1.isCliAgentManagementCommand;
|
|
3604
4945
|
} });
|
|
4946
|
+
Object.defineProperty(exports, "registeredHookSets", { enumerable: true, get: function() {
|
|
4947
|
+
return cliAgentSetup_1.registeredHookSets;
|
|
4948
|
+
} });
|
|
3605
4949
|
Object.defineProperty(exports, "runCliAgentSetup", { enumerable: true, get: function() {
|
|
3606
4950
|
return cliAgentSetup_1.runCliAgentSetup;
|
|
3607
4951
|
} });
|
|
3608
4952
|
Object.defineProperty(exports, "writeHookSettings", { enumerable: true, get: function() {
|
|
3609
4953
|
return cliAgentSetup_1.writeHookSettings;
|
|
3610
4954
|
} });
|
|
4955
|
+
var setupDisclosure_1 = require_setupDisclosure();
|
|
4956
|
+
Object.defineProperty(exports, "ALWAYS_SENT", { enumerable: true, get: function() {
|
|
4957
|
+
return setupDisclosure_1.ALWAYS_SENT;
|
|
4958
|
+
} });
|
|
4959
|
+
Object.defineProperty(exports, "FAMILY_SENTENCES", { enumerable: true, get: function() {
|
|
4960
|
+
return setupDisclosure_1.FAMILY_SENTENCES;
|
|
4961
|
+
} });
|
|
4962
|
+
Object.defineProperty(exports, "FREE_TEXT_KEYS", { enumerable: true, get: function() {
|
|
4963
|
+
return setupDisclosure_1.FREE_TEXT_KEYS;
|
|
4964
|
+
} });
|
|
4965
|
+
Object.defineProperty(exports, "REFUSALS", { enumerable: true, get: function() {
|
|
4966
|
+
return setupDisclosure_1.REFUSALS;
|
|
4967
|
+
} });
|
|
4968
|
+
Object.defineProperty(exports, "renderSetupDisclosure", { enumerable: true, get: function() {
|
|
4969
|
+
return setupDisclosure_1.renderSetupDisclosure;
|
|
4970
|
+
} });
|
|
3611
4971
|
var credentials_1 = require_credentials();
|
|
3612
4972
|
Object.defineProperty(exports, "credentialsFilePath", { enumerable: true, get: function() {
|
|
3613
4973
|
return credentials_1.credentialsFilePath;
|
|
3614
4974
|
} });
|
|
4975
|
+
Object.defineProperty(exports, "isLocalOnlyHostInstall", { enumerable: true, get: function() {
|
|
4976
|
+
return credentials_1.isLocalOnlyHostInstall;
|
|
4977
|
+
} });
|
|
3615
4978
|
Object.defineProperty(exports, "readHostCredentials", { enumerable: true, get: function() {
|
|
3616
4979
|
return credentials_1.readHostCredentials;
|
|
3617
4980
|
} });
|
|
@@ -3638,6 +5001,9 @@ var require_out2 = __commonJS({
|
|
|
3638
5001
|
return turnState_1.recordTurnStart;
|
|
3639
5002
|
} });
|
|
3640
5003
|
var tokenStore_1 = require_tokenStore();
|
|
5004
|
+
Object.defineProperty(exports, "EVENT_TOKEN_TTL_MS", { enumerable: true, get: function() {
|
|
5005
|
+
return tokenStore_1.EVENT_TOKEN_TTL_MS;
|
|
5006
|
+
} });
|
|
3641
5007
|
Object.defineProperty(exports, "ascendaHome", { enumerable: true, get: function() {
|
|
3642
5008
|
return tokenStore_1.ascendaHome;
|
|
3643
5009
|
} });
|
|
@@ -3650,9 +5016,15 @@ var require_out2 = __commonJS({
|
|
|
3650
5016
|
Object.defineProperty(exports, "persistEventWriteToken", { enumerable: true, get: function() {
|
|
3651
5017
|
return tokenStore_1.persistEventWriteToken;
|
|
3652
5018
|
} });
|
|
5019
|
+
Object.defineProperty(exports, "readTokenExpiry", { enumerable: true, get: function() {
|
|
5020
|
+
return tokenStore_1.readTokenExpiry;
|
|
5021
|
+
} });
|
|
3653
5022
|
Object.defineProperty(exports, "readTokenFile", { enumerable: true, get: function() {
|
|
3654
5023
|
return tokenStore_1.readTokenFile;
|
|
3655
5024
|
} });
|
|
5025
|
+
Object.defineProperty(exports, "tokenExpiryFilePath", { enumerable: true, get: function() {
|
|
5026
|
+
return tokenStore_1.tokenExpiryFilePath;
|
|
5027
|
+
} });
|
|
3656
5028
|
var stateStore_1 = require_stateStore();
|
|
3657
5029
|
Object.defineProperty(exports, "defaultStateFilePath", { enumerable: true, get: function() {
|
|
3658
5030
|
return stateStore_1.defaultStateFilePath;
|
|
@@ -3784,6 +5156,59 @@ var require_out2 = __commonJS({
|
|
|
3784
5156
|
Object.defineProperty(exports, "liveBusSocketCandidates", { enumerable: true, get: function() {
|
|
3785
5157
|
return liveBus_1.liveBusSocketCandidates;
|
|
3786
5158
|
} });
|
|
5159
|
+
Object.defineProperty(exports, "LIVE_BUS_BACKGROUND_TRUST_MS", { enumerable: true, get: function() {
|
|
5160
|
+
return liveBus_1.LIVE_BUS_BACKGROUND_TRUST_MS;
|
|
5161
|
+
} });
|
|
5162
|
+
var hookSet_1 = require_hookSet();
|
|
5163
|
+
Object.defineProperty(exports, "HOOK_SET_FLAG", { enumerable: true, get: function() {
|
|
5164
|
+
return hookSet_1.HOOK_SET_FLAG;
|
|
5165
|
+
} });
|
|
5166
|
+
Object.defineProperty(exports, "UNVERSIONED_HOOK_SET", { enumerable: true, get: function() {
|
|
5167
|
+
return hookSet_1.UNVERSIONED_HOOK_SET;
|
|
5168
|
+
} });
|
|
5169
|
+
Object.defineProperty(exports, "describeHookSetChanges", { enumerable: true, get: function() {
|
|
5170
|
+
return hookSet_1.describeHookSetChanges;
|
|
5171
|
+
} });
|
|
5172
|
+
Object.defineProperty(exports, "hookSetArgument", { enumerable: true, get: function() {
|
|
5173
|
+
return hookSet_1.hookSetArgument;
|
|
5174
|
+
} });
|
|
5175
|
+
Object.defineProperty(exports, "hookSetChanges", { enumerable: true, get: function() {
|
|
5176
|
+
return hookSet_1.hookSetChanges;
|
|
5177
|
+
} });
|
|
5178
|
+
Object.defineProperty(exports, "hookSetOfCommand", { enumerable: true, get: function() {
|
|
5179
|
+
return hookSet_1.hookSetOfCommand;
|
|
5180
|
+
} });
|
|
5181
|
+
Object.defineProperty(exports, "isHookSet", { enumerable: true, get: function() {
|
|
5182
|
+
return hookSet_1.isHookSet;
|
|
5183
|
+
} });
|
|
5184
|
+
Object.defineProperty(exports, "readHookSet", { enumerable: true, get: function() {
|
|
5185
|
+
return hookSet_1.readHookSet;
|
|
5186
|
+
} });
|
|
5187
|
+
Object.defineProperty(exports, "readViaPlugin", { enumerable: true, get: function() {
|
|
5188
|
+
return hookSet_1.readViaPlugin;
|
|
5189
|
+
} });
|
|
5190
|
+
var agentProcess_1 = require_agentProcess();
|
|
5191
|
+
Object.defineProperty(exports, "AGENT_PROCESS", { enumerable: true, get: function() {
|
|
5192
|
+
return agentProcess_1.AGENT_PROCESS;
|
|
5193
|
+
} });
|
|
5194
|
+
Object.defineProperty(exports, "findAgentPid", { enumerable: true, get: function() {
|
|
5195
|
+
return agentProcess_1.findAgentPid;
|
|
5196
|
+
} });
|
|
5197
|
+
Object.defineProperty(exports, "findAgentProcess", { enumerable: true, get: function() {
|
|
5198
|
+
return agentProcess_1.findAgentProcess;
|
|
5199
|
+
} });
|
|
5200
|
+
Object.defineProperty(exports, "livePidFields", { enumerable: true, get: function() {
|
|
5201
|
+
return agentProcess_1.livePidFields;
|
|
5202
|
+
} });
|
|
5203
|
+
Object.defineProperty(exports, "psArgsLookup", { enumerable: true, get: function() {
|
|
5204
|
+
return agentProcess_1.psArgsLookup;
|
|
5205
|
+
} });
|
|
5206
|
+
Object.defineProperty(exports, "psLookup", { enumerable: true, get: function() {
|
|
5207
|
+
return agentProcess_1.psLookup;
|
|
5208
|
+
} });
|
|
5209
|
+
Object.defineProperty(exports, "scriptMarkerIn", { enumerable: true, get: function() {
|
|
5210
|
+
return agentProcess_1.scriptMarkerIn;
|
|
5211
|
+
} });
|
|
3787
5212
|
var http_1 = require_http();
|
|
3788
5213
|
Object.defineProperty(exports, "AscendaApiError", { enumerable: true, get: function() {
|
|
3789
5214
|
return http_1.AscendaApiError;
|
|
@@ -3794,6 +5219,9 @@ var require_out2 = __commonJS({
|
|
|
3794
5219
|
Object.defineProperty(exports, "getPairingStatus", { enumerable: true, get: function() {
|
|
3795
5220
|
return http_1.getPairingStatus;
|
|
3796
5221
|
} });
|
|
5222
|
+
Object.defineProperty(exports, "getStudyJoinStatus", { enumerable: true, get: function() {
|
|
5223
|
+
return http_1.getStudyJoinStatus;
|
|
5224
|
+
} });
|
|
3797
5225
|
Object.defineProperty(exports, "renewToolToken", { enumerable: true, get: function() {
|
|
3798
5226
|
return http_1.renewToolToken;
|
|
3799
5227
|
} });
|
|
@@ -3809,6 +5237,48 @@ var require_out2 = __commonJS({
|
|
|
3809
5237
|
Object.defineProperty(exports, "isRetryableStatus", { enumerable: true, get: function() {
|
|
3810
5238
|
return http_1.isRetryableStatus;
|
|
3811
5239
|
} });
|
|
5240
|
+
Object.defineProperty(exports, "readInitiatives", { enumerable: true, get: function() {
|
|
5241
|
+
return http_1.readInitiatives;
|
|
5242
|
+
} });
|
|
5243
|
+
Object.defineProperty(exports, "readStudyNotices", { enumerable: true, get: function() {
|
|
5244
|
+
return http_1.readStudyNotices;
|
|
5245
|
+
} });
|
|
5246
|
+
Object.defineProperty(exports, "markStudyNoticeShown", { enumerable: true, get: function() {
|
|
5247
|
+
return http_1.markStudyNoticeShown;
|
|
5248
|
+
} });
|
|
5249
|
+
Object.defineProperty(exports, "setStudyObjection", { enumerable: true, get: function() {
|
|
5250
|
+
return http_1.setStudyObjection;
|
|
5251
|
+
} });
|
|
5252
|
+
Object.defineProperty(exports, "startStudyJoin", { enumerable: true, get: function() {
|
|
5253
|
+
return http_1.startStudyJoin;
|
|
5254
|
+
} });
|
|
5255
|
+
var initiatives_1 = require_initiatives();
|
|
5256
|
+
Object.defineProperty(exports, "INITIATIVE_COPY", { enumerable: true, get: function() {
|
|
5257
|
+
return initiatives_1.INITIATIVE_COPY;
|
|
5258
|
+
} });
|
|
5259
|
+
Object.defineProperty(exports, "initiativesStatusLines", { enumerable: true, get: function() {
|
|
5260
|
+
return initiatives_1.initiativesStatusLines;
|
|
5261
|
+
} });
|
|
5262
|
+
Object.defineProperty(exports, "renderInitiatives", { enumerable: true, get: function() {
|
|
5263
|
+
return initiatives_1.renderInitiatives;
|
|
5264
|
+
} });
|
|
5265
|
+
var studyNotices_1 = require_studyNotices();
|
|
5266
|
+
Object.defineProperty(exports, "NOTICED_PURPOSES", { enumerable: true, get: function() {
|
|
5267
|
+
return studyNotices_1.NOTICED_PURPOSES;
|
|
5268
|
+
} });
|
|
5269
|
+
Object.defineProperty(exports, "renderStudyNotices", { enumerable: true, get: function() {
|
|
5270
|
+
return studyNotices_1.renderStudyNotices;
|
|
5271
|
+
} });
|
|
5272
|
+
Object.defineProperty(exports, "runStudyObjection", { enumerable: true, get: function() {
|
|
5273
|
+
return studyNotices_1.runStudyObjection;
|
|
5274
|
+
} });
|
|
5275
|
+
Object.defineProperty(exports, "studyNoticeStatus", { enumerable: true, get: function() {
|
|
5276
|
+
return studyNotices_1.studyNoticeStatus;
|
|
5277
|
+
} });
|
|
5278
|
+
var studyJoin_1 = require_studyJoin();
|
|
5279
|
+
Object.defineProperty(exports, "runStudyJoin", { enumerable: true, get: function() {
|
|
5280
|
+
return studyJoin_1.runStudyJoin;
|
|
5281
|
+
} });
|
|
3812
5282
|
}
|
|
3813
5283
|
});
|
|
3814
5284
|
|
|
@@ -3976,6 +5446,8 @@ function liveSignalFor(hookName, input) {
|
|
|
3976
5446
|
return { event: "compaction" };
|
|
3977
5447
|
case "Stop":
|
|
3978
5448
|
return { event: "stop" };
|
|
5449
|
+
case "PermissionRequest":
|
|
5450
|
+
return { event: "awaiting" };
|
|
3979
5451
|
default:
|
|
3980
5452
|
return void 0;
|
|
3981
5453
|
}
|
|
@@ -4003,6 +5475,9 @@ var SETUP = {
|
|
|
4003
5475
|
binaryName: "ascenda-codex-hook",
|
|
4004
5476
|
hookEvents: HOOK_EVENTS,
|
|
4005
5477
|
restartHint: "Restart Codex, then open /hooks to review and trust the Ascenda hooks. Registration alone does not enable execution. After a session, verify the cli_agent send journal and metadata.host: codex in the event log.",
|
|
5478
|
+
// Codex reports the posture it was working under and its approval gate; it
|
|
5479
|
+
// sends no model, no git action and no per-file change size.
|
|
5480
|
+
sends: ["posture", "waiting"],
|
|
4006
5481
|
settings: {
|
|
4007
5482
|
settingsPath: (scope, projectDir) => scope === "user" ? path.join(os.homedir(), ".codex", "hooks.json") : path.join(projectDir, ".codex", "hooks.json"),
|
|
4008
5483
|
// Codex nests as Gemini does — each event maps to an array of
|
|
@@ -4048,6 +5523,7 @@ async function emitLive(hookName, input, sessionId) {
|
|
|
4048
5523
|
const body = liveSignalFor(hookName, input);
|
|
4049
5524
|
if (!body) return;
|
|
4050
5525
|
try {
|
|
5526
|
+
const pid = (0, import_tool_kit3.findAgentPid)(import_tool_kit3.AGENT_PROCESS.codex);
|
|
4051
5527
|
await (0, import_tool_kit3.emitLiveSignal)({
|
|
4052
5528
|
// This host's own name, not the shared `cli_agent` tool type the cloud
|
|
4053
5529
|
// path files these events under. The app keys one decaying envelope per
|
|
@@ -4062,6 +5538,7 @@ async function emitLive(hookName, input, sessionId) {
|
|
|
4062
5538
|
// this process's parent — still per-session in practice, since the hook
|
|
4063
5539
|
// is spawned from the session process.
|
|
4064
5540
|
session: sessionId ?? `ppid-${process.ppid}`,
|
|
5541
|
+
...pid !== void 0 ? { pid } : {},
|
|
4065
5542
|
...body
|
|
4066
5543
|
});
|
|
4067
5544
|
} catch {
|