@ascenda-one/claude-code-hooks 0.1.43 → 0.1.45
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 +1 -0
- package/dist/cli.js +1142 -549
- package/dist/cli.js.map +1 -1
- package/dist/mapClaudeEvent.js +3 -2
- package/dist/mapClaudeEvent.js.map +1 -1
- package/dist/quotaSnapshot.js +111 -0
- package/dist/quotaSnapshot.js.map +1 -0
- package/dist/setup.js +134 -1
- package/dist/setup.js.map +1 -1
- package/dist/statusline.js +51 -0
- package/dist/statusline.js.map +1 -0
- package/dist/waitTracker.js +187 -0
- package/dist/waitTracker.js.map +1 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -608,7 +608,7 @@ var require_tokenStore = __commonJS({
|
|
|
608
608
|
}();
|
|
609
609
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
610
610
|
exports.EVENT_TOKEN_TTL_MS = void 0;
|
|
611
|
-
exports.ascendaHome =
|
|
611
|
+
exports.ascendaHome = ascendaHome7;
|
|
612
612
|
exports.defaultTokenFilePath = defaultTokenFilePath4;
|
|
613
613
|
exports.tokenExpiryFilePath = tokenExpiryFilePath;
|
|
614
614
|
exports.persistEventWriteToken = persistEventWriteToken4;
|
|
@@ -616,33 +616,33 @@ var require_tokenStore = __commonJS({
|
|
|
616
616
|
exports.listPersistedToolInstallationIds = listPersistedToolInstallationIds2;
|
|
617
617
|
exports.readTokenFile = readTokenFile3;
|
|
618
618
|
exports.sanitizeFilePart = sanitizeFilePart;
|
|
619
|
-
var
|
|
619
|
+
var fs9 = __importStar(__require("fs"));
|
|
620
620
|
var os4 = __importStar(__require("os"));
|
|
621
|
-
var
|
|
622
|
-
function
|
|
623
|
-
return process.env.ASCENDA_HOME ??
|
|
621
|
+
var path8 = __importStar(__require("path"));
|
|
622
|
+
function ascendaHome7(home = os4.homedir()) {
|
|
623
|
+
return process.env.ASCENDA_HOME ?? path8.join(home, ".ascenda");
|
|
624
624
|
}
|
|
625
625
|
function defaultTokenFilePath4(toolInstallationId) {
|
|
626
|
-
return
|
|
626
|
+
return path8.join(ascendaHome7(), "tokens", sanitizeFilePart(toolInstallationId));
|
|
627
627
|
}
|
|
628
628
|
function tokenExpiryFilePath(tokenFilePath) {
|
|
629
|
-
return
|
|
629
|
+
return path8.join(path8.dirname(tokenFilePath), "expiry", path8.basename(tokenFilePath));
|
|
630
630
|
}
|
|
631
631
|
function persistEventWriteToken4(tokenFilePath, token, expiresAt) {
|
|
632
|
-
const dir =
|
|
633
|
-
|
|
634
|
-
|
|
632
|
+
const dir = path8.dirname(tokenFilePath);
|
|
633
|
+
fs9.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
634
|
+
fs9.writeFileSync(tokenFilePath, token, { encoding: "utf8", mode: 384 });
|
|
635
635
|
if (process.platform !== "win32") {
|
|
636
|
-
|
|
637
|
-
|
|
636
|
+
fs9.chmodSync(dir, 448);
|
|
637
|
+
fs9.chmodSync(tokenFilePath, 384);
|
|
638
638
|
}
|
|
639
639
|
const expiryFile = tokenExpiryFilePath(tokenFilePath);
|
|
640
640
|
try {
|
|
641
641
|
if (expiresAt && Number.isFinite(Date.parse(expiresAt))) {
|
|
642
|
-
|
|
643
|
-
|
|
642
|
+
fs9.mkdirSync(path8.dirname(expiryFile), { recursive: true, mode: 448 });
|
|
643
|
+
fs9.writeFileSync(expiryFile, expiresAt, { encoding: "utf8", mode: 384 });
|
|
644
644
|
} else {
|
|
645
|
-
|
|
645
|
+
fs9.rmSync(expiryFile, { force: true });
|
|
646
646
|
}
|
|
647
647
|
} catch {
|
|
648
648
|
}
|
|
@@ -650,23 +650,23 @@ var require_tokenStore = __commonJS({
|
|
|
650
650
|
exports.EVENT_TOKEN_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
651
651
|
function readTokenExpiry(tokenFilePath) {
|
|
652
652
|
try {
|
|
653
|
-
const recorded = Date.parse(
|
|
653
|
+
const recorded = Date.parse(fs9.readFileSync(tokenExpiryFilePath(tokenFilePath), "utf8").trim());
|
|
654
654
|
if (Number.isFinite(recorded))
|
|
655
655
|
return recorded;
|
|
656
656
|
} catch {
|
|
657
657
|
}
|
|
658
658
|
try {
|
|
659
|
-
return
|
|
659
|
+
return fs9.statSync(tokenFilePath).mtimeMs + exports.EVENT_TOKEN_TTL_MS;
|
|
660
660
|
} catch {
|
|
661
661
|
return void 0;
|
|
662
662
|
}
|
|
663
663
|
}
|
|
664
664
|
function listPersistedToolInstallationIds2(toolType) {
|
|
665
665
|
const prefix = `${sanitizeFilePart(toolType)}_`;
|
|
666
|
-
const dir =
|
|
666
|
+
const dir = path8.join(ascendaHome7(), "tokens");
|
|
667
667
|
let names;
|
|
668
668
|
try {
|
|
669
|
-
names =
|
|
669
|
+
names = fs9.readdirSync(dir);
|
|
670
670
|
} catch {
|
|
671
671
|
return [];
|
|
672
672
|
}
|
|
@@ -674,9 +674,9 @@ var require_tokenStore = __commonJS({
|
|
|
674
674
|
for (const name of names.sort()) {
|
|
675
675
|
if (!name.startsWith(prefix) || name.length === prefix.length)
|
|
676
676
|
continue;
|
|
677
|
-
const file =
|
|
677
|
+
const file = path8.join(dir, name);
|
|
678
678
|
try {
|
|
679
|
-
if (!
|
|
679
|
+
if (!fs9.statSync(file).isFile())
|
|
680
680
|
continue;
|
|
681
681
|
} catch {
|
|
682
682
|
continue;
|
|
@@ -689,9 +689,9 @@ var require_tokenStore = __commonJS({
|
|
|
689
689
|
}
|
|
690
690
|
function readTokenFile3(tokenFilePath) {
|
|
691
691
|
try {
|
|
692
|
-
if (!
|
|
692
|
+
if (!fs9.existsSync(tokenFilePath))
|
|
693
693
|
return void 0;
|
|
694
|
-
const value =
|
|
694
|
+
const value = fs9.readFileSync(tokenFilePath, "utf8").trim();
|
|
695
695
|
return value || void 0;
|
|
696
696
|
} catch {
|
|
697
697
|
return void 0;
|
|
@@ -750,22 +750,22 @@ var require_modelState = __commonJS({
|
|
|
750
750
|
exports.clearSentModelId = clearSentModelId2;
|
|
751
751
|
exports.modelFieldsFor = modelFieldsFor2;
|
|
752
752
|
exports.withModelOnChange = withModelOnChange2;
|
|
753
|
-
var
|
|
754
|
-
var
|
|
753
|
+
var fs9 = __importStar(__require("fs"));
|
|
754
|
+
var path8 = __importStar(__require("path"));
|
|
755
755
|
var tokenStore_1 = require_tokenStore();
|
|
756
756
|
var modelClassifier_1 = require_modelClassifier();
|
|
757
|
-
var
|
|
757
|
+
var stateDir2 = () => process.env.ASCENDA_STATE_DIR ?? path8.join((0, tokenStore_1.ascendaHome)(), "state");
|
|
758
758
|
function modelFile(agent, sessionId) {
|
|
759
|
-
return
|
|
759
|
+
return path8.join(stateDir2(), `${sanitize2(agent)}-model-${sanitize2(sessionId)}`);
|
|
760
760
|
}
|
|
761
|
-
function
|
|
761
|
+
function sanitize2(value) {
|
|
762
762
|
return value.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
763
763
|
}
|
|
764
764
|
function readSentModelId2(agent, sessionId) {
|
|
765
765
|
if (!sessionId)
|
|
766
766
|
return void 0;
|
|
767
767
|
try {
|
|
768
|
-
const id =
|
|
768
|
+
const id = fs9.readFileSync(modelFile(agent, sessionId), "utf8").trim();
|
|
769
769
|
return id || void 0;
|
|
770
770
|
} catch {
|
|
771
771
|
return void 0;
|
|
@@ -775,8 +775,8 @@ var require_modelState = __commonJS({
|
|
|
775
775
|
if (!sessionId || !modelId)
|
|
776
776
|
return;
|
|
777
777
|
try {
|
|
778
|
-
|
|
779
|
-
|
|
778
|
+
fs9.mkdirSync(stateDir2(), { recursive: true });
|
|
779
|
+
fs9.writeFileSync(modelFile(agent, sessionId), modelId, { encoding: "utf8", mode: 384 });
|
|
780
780
|
} catch {
|
|
781
781
|
}
|
|
782
782
|
}
|
|
@@ -784,7 +784,7 @@ var require_modelState = __commonJS({
|
|
|
784
784
|
if (!sessionId)
|
|
785
785
|
return;
|
|
786
786
|
try {
|
|
787
|
-
|
|
787
|
+
fs9.rmSync(modelFile(agent, sessionId), { force: true });
|
|
788
788
|
} catch {
|
|
789
789
|
}
|
|
790
790
|
}
|
|
@@ -963,6 +963,12 @@ var require_metricKeys = __commonJS({
|
|
|
963
963
|
backendAliases: ["gitAction", "git_action"],
|
|
964
964
|
note: "The live hooks set it on a shell event; the git extractor sets it to commit on each commit event it emits."
|
|
965
965
|
},
|
|
966
|
+
accountKey: {
|
|
967
|
+
family: "session",
|
|
968
|
+
readBy: ["backend"],
|
|
969
|
+
backendAliases: ["accountKey", "account_key"],
|
|
970
|
+
note: "Machine-salted digest of the Claude config folder plus the plan tier, from deriveAccountKey. Same value the live hooks send, so two profiles on one machine stay apart. Never a token, email or account id. Absent when no salt is readable."
|
|
971
|
+
},
|
|
966
972
|
repoKey: {
|
|
967
973
|
family: "repo",
|
|
968
974
|
readBy: ["backend"],
|
|
@@ -1298,6 +1304,21 @@ var require_metricKeys = __commonJS({
|
|
|
1298
1304
|
readBy: ["diagnostic"],
|
|
1299
1305
|
note: "Claude Code only: advisor calls (a second model consulted inside one API message). Their tokens and models are already folded into the session totals and model mix, and this is the receipt for how much of that they are."
|
|
1300
1306
|
},
|
|
1307
|
+
apiErrorMessageCount: {
|
|
1308
|
+
family: "outcome",
|
|
1309
|
+
readBy: ["diagnostic"],
|
|
1310
|
+
note: "Claude Code only: assistant lines the runtime flagged isApiErrorMessage, the error text shown where a reply should be. Counted apart from apiErrorCount, which reads the api_error system lines, so the two can be compared. Absent when there are none."
|
|
1311
|
+
},
|
|
1312
|
+
compactSummaryCount: {
|
|
1313
|
+
family: "context",
|
|
1314
|
+
readBy: ["diagnostic"],
|
|
1315
|
+
note: "Claude Code only: user lines flagged isCompactSummary, the summary a compaction leaves as the next turn's opening. A cross-check on compactionCount, which reads compact_boundary lines. Absent when there are none."
|
|
1316
|
+
},
|
|
1317
|
+
nestedSubagentCount: {
|
|
1318
|
+
family: "counts",
|
|
1319
|
+
readBy: ["diagnostic"],
|
|
1320
|
+
note: "Claude Code only: subagents launched by another subagent, linked by the agent id in the launching subagent's own tool results. Absent when there are none."
|
|
1321
|
+
},
|
|
1301
1322
|
advisorTokensTotal: {
|
|
1302
1323
|
family: "context",
|
|
1303
1324
|
readBy: ["diagnostic"],
|
|
@@ -1528,6 +1549,7 @@ var require_out = __commonJS({
|
|
|
1528
1549
|
gitAction: "git",
|
|
1529
1550
|
milestoneKind: "git",
|
|
1530
1551
|
branchHash: "repo",
|
|
1552
|
+
accountKey: "session",
|
|
1531
1553
|
repoKey: "forge",
|
|
1532
1554
|
headRepoKey: "forge",
|
|
1533
1555
|
prCreatedAt: "git",
|
|
@@ -1557,6 +1579,9 @@ var require_out = __commonJS({
|
|
|
1557
1579
|
// One constant word, from the agent itself. The session sentence names it.
|
|
1558
1580
|
sessionEndReason: "session",
|
|
1559
1581
|
interruptionKind: "waiting",
|
|
1582
|
+
waitMs: "waiting",
|
|
1583
|
+
waitEndedBy: "waiting",
|
|
1584
|
+
waitConfidence: "waiting",
|
|
1560
1585
|
// Claude Code's own opaque id for one subagent, and the class it belongs
|
|
1561
1586
|
// to. Never the agent's name or anything it was asked.
|
|
1562
1587
|
subagentId: "subagents",
|
|
@@ -1599,6 +1624,7 @@ var require_out = __commonJS({
|
|
|
1599
1624
|
"gitAction",
|
|
1600
1625
|
"milestoneKind",
|
|
1601
1626
|
"branchHash",
|
|
1627
|
+
"accountKey",
|
|
1602
1628
|
"repoKey",
|
|
1603
1629
|
"headRepoKey",
|
|
1604
1630
|
"prCreatedAt",
|
|
@@ -1626,6 +1652,9 @@ var require_out = __commonJS({
|
|
|
1626
1652
|
"runtime",
|
|
1627
1653
|
"sessionEndReason",
|
|
1628
1654
|
"interruptionKind",
|
|
1655
|
+
"waitMs",
|
|
1656
|
+
"waitEndedBy",
|
|
1657
|
+
"waitConfidence",
|
|
1629
1658
|
"subagentId",
|
|
1630
1659
|
"subagentClass",
|
|
1631
1660
|
"simulated",
|
|
@@ -1715,6 +1744,10 @@ var require_out = __commonJS({
|
|
|
1715
1744
|
// step toward an interruption count becoming a score, a streak, or something
|
|
1716
1745
|
// that fires on a miss. It must never become any of those.
|
|
1717
1746
|
supervision_interruption: "supervision",
|
|
1747
|
+
// How long that wait lasted, inferred from the next hook that could only
|
|
1748
|
+
// have fired after an answer. Same leg, same rule: overhead to be counted,
|
|
1749
|
+
// never a score.
|
|
1750
|
+
supervision_wait_ended: "supervision",
|
|
1718
1751
|
// The agent asked to run a tool, and the auto-mode classifier refused one.
|
|
1719
1752
|
// Claude Code's `PermissionRequest` and `PermissionDenied` hooks. Neutral,
|
|
1720
1753
|
// because the Notification for the same prompt is already counted above as
|
|
@@ -1790,9 +1823,9 @@ var require_payload = __commonJS({
|
|
|
1790
1823
|
}
|
|
1791
1824
|
return void 0;
|
|
1792
1825
|
}
|
|
1793
|
-
function getNested2(input,
|
|
1826
|
+
function getNested2(input, path8) {
|
|
1794
1827
|
let current = input;
|
|
1795
|
-
for (const segment of
|
|
1828
|
+
for (const segment of path8) {
|
|
1796
1829
|
if (!current || typeof current !== "object")
|
|
1797
1830
|
return void 0;
|
|
1798
1831
|
current = current[segment];
|
|
@@ -1800,16 +1833,16 @@ var require_payload = __commonJS({
|
|
|
1800
1833
|
return current;
|
|
1801
1834
|
}
|
|
1802
1835
|
function getNestedString3(input, paths) {
|
|
1803
|
-
for (const
|
|
1804
|
-
const value = getNested2(input,
|
|
1836
|
+
for (const path8 of paths) {
|
|
1837
|
+
const value = getNested2(input, path8);
|
|
1805
1838
|
if (typeof value === "string" && value.trim())
|
|
1806
1839
|
return value;
|
|
1807
1840
|
}
|
|
1808
1841
|
return void 0;
|
|
1809
1842
|
}
|
|
1810
1843
|
function getNestedNumber2(input, paths) {
|
|
1811
|
-
for (const
|
|
1812
|
-
const value = getNested2(input,
|
|
1844
|
+
for (const path8 of paths) {
|
|
1845
|
+
const value = getNested2(input, path8);
|
|
1813
1846
|
if (typeof value === "number" && Number.isFinite(value))
|
|
1814
1847
|
return value;
|
|
1815
1848
|
}
|
|
@@ -1925,7 +1958,7 @@ var require_collectorVersion = __commonJS({
|
|
|
1925
1958
|
exports.COLLECTOR_VERSION = exports.UNRELEASED_COLLECTOR_VERSION = void 0;
|
|
1926
1959
|
exports.describeCollectorVersion = describeCollectorVersion2;
|
|
1927
1960
|
exports.UNRELEASED_COLLECTOR_VERSION = "unreleased";
|
|
1928
|
-
exports.COLLECTOR_VERSION = "0.1.
|
|
1961
|
+
exports.COLLECTOR_VERSION = "0.1.45" ? "0.1.45" : exports.UNRELEASED_COLLECTOR_VERSION;
|
|
1929
1962
|
function describeCollectorVersion2(version = exports.COLLECTOR_VERSION) {
|
|
1930
1963
|
return version === exports.UNRELEASED_COLLECTOR_VERSION ? `${version} (built from a checkout, not a release)` : version;
|
|
1931
1964
|
}
|
|
@@ -1982,13 +2015,13 @@ var require_stateStore = __commonJS({
|
|
|
1982
2015
|
exports.recordOutboxDiscard = recordOutboxDiscard;
|
|
1983
2016
|
exports.shouldAnnounceFailure = shouldAnnounceFailure2;
|
|
1984
2017
|
exports.markFailureNotified = markFailureNotified2;
|
|
1985
|
-
var
|
|
1986
|
-
var
|
|
2018
|
+
var fs9 = __importStar(__require("fs"));
|
|
2019
|
+
var path8 = __importStar(__require("path"));
|
|
1987
2020
|
var tokenStore_1 = require_tokenStore();
|
|
1988
2021
|
function defaultStateFilePath2(toolInstallationId) {
|
|
1989
2022
|
const dir = process.env.ASCENDA_STATE_DIR?.trim();
|
|
1990
|
-
const base = dir ? dir :
|
|
1991
|
-
return
|
|
2023
|
+
const base = dir ? dir : path8.join((0, tokenStore_1.ascendaHome)(), "state");
|
|
2024
|
+
return path8.join(base, `${(0, tokenStore_1.sanitizeFilePart)(toolInstallationId)}.json`);
|
|
1992
2025
|
}
|
|
1993
2026
|
function unresolvedToolInstallationId2(toolType) {
|
|
1994
2027
|
return `${toolType}:unresolved`;
|
|
@@ -1998,9 +2031,9 @@ var require_stateStore = __commonJS({
|
|
|
1998
2031
|
}
|
|
1999
2032
|
function readCollectorState2(stateFilePath) {
|
|
2000
2033
|
try {
|
|
2001
|
-
if (!
|
|
2034
|
+
if (!fs9.existsSync(stateFilePath))
|
|
2002
2035
|
return void 0;
|
|
2003
|
-
const raw =
|
|
2036
|
+
const raw = fs9.readFileSync(stateFilePath, "utf8").trim();
|
|
2004
2037
|
if (!raw)
|
|
2005
2038
|
return void 0;
|
|
2006
2039
|
const parsed = JSON.parse(raw);
|
|
@@ -2067,17 +2100,17 @@ var require_stateStore = __commonJS({
|
|
|
2067
2100
|
function writeStateFile(stateFilePath, state) {
|
|
2068
2101
|
const temporaryPath = `${stateFilePath}.${process.pid}.tmp`;
|
|
2069
2102
|
try {
|
|
2070
|
-
const dir =
|
|
2071
|
-
|
|
2072
|
-
|
|
2103
|
+
const dir = path8.dirname(stateFilePath);
|
|
2104
|
+
fs9.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
2105
|
+
fs9.writeFileSync(temporaryPath, `${JSON.stringify(state, null, 2)}
|
|
2073
2106
|
`, { encoding: "utf8", mode: 384 });
|
|
2074
|
-
|
|
2107
|
+
fs9.renameSync(temporaryPath, stateFilePath);
|
|
2075
2108
|
if (process.platform !== "win32")
|
|
2076
|
-
|
|
2109
|
+
fs9.chmodSync(stateFilePath, 384);
|
|
2077
2110
|
} catch {
|
|
2078
2111
|
try {
|
|
2079
|
-
if (
|
|
2080
|
-
|
|
2112
|
+
if (fs9.existsSync(temporaryPath))
|
|
2113
|
+
fs9.unlinkSync(temporaryPath);
|
|
2081
2114
|
} catch {
|
|
2082
2115
|
}
|
|
2083
2116
|
}
|
|
@@ -2138,8 +2171,8 @@ var require_outbox = __commonJS({
|
|
|
2138
2171
|
exports.readOutboxSummary = readOutboxSummary2;
|
|
2139
2172
|
exports.claimOutbox = claimOutbox;
|
|
2140
2173
|
exports.enforceOutboxBounds = enforceOutboxBounds;
|
|
2141
|
-
var
|
|
2142
|
-
var
|
|
2174
|
+
var fs9 = __importStar(__require("fs"));
|
|
2175
|
+
var path8 = __importStar(__require("path"));
|
|
2143
2176
|
var stateStore_1 = require_stateStore();
|
|
2144
2177
|
var tokenStore_1 = require_tokenStore();
|
|
2145
2178
|
exports.OUTBOX_DRAIN_ENV_VAR = "ASCENDA_OUTBOX_DRAIN";
|
|
@@ -2155,25 +2188,25 @@ var require_outbox = __commonJS({
|
|
|
2155
2188
|
return !(value === "0" || value === "false" || value === "no" || value === "off");
|
|
2156
2189
|
}
|
|
2157
2190
|
function defaultOutboxFilePath2(toolInstallationId) {
|
|
2158
|
-
const dir =
|
|
2159
|
-
return
|
|
2191
|
+
const dir = path8.dirname((0, stateStore_1.defaultStateFilePath)(toolInstallationId));
|
|
2192
|
+
return path8.join(dir, `${(0, tokenStore_1.sanitizeFilePart)(toolInstallationId)}.outbox.jsonl`);
|
|
2160
2193
|
}
|
|
2161
2194
|
function appendToOutbox(outboxFilePath, payload, now = /* @__PURE__ */ new Date()) {
|
|
2162
2195
|
try {
|
|
2163
|
-
const dir =
|
|
2164
|
-
|
|
2196
|
+
const dir = path8.dirname(outboxFilePath);
|
|
2197
|
+
fs9.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
2165
2198
|
const entry = { queuedAt: now.toISOString(), payload };
|
|
2166
|
-
|
|
2199
|
+
fs9.appendFileSync(outboxFilePath, `${JSON.stringify(entry)}
|
|
2167
2200
|
`, { encoding: "utf8", mode: 384 });
|
|
2168
2201
|
if (process.platform !== "win32")
|
|
2169
|
-
|
|
2202
|
+
fs9.chmodSync(outboxFilePath, 384);
|
|
2170
2203
|
return true;
|
|
2171
2204
|
} catch {
|
|
2172
2205
|
return false;
|
|
2173
2206
|
}
|
|
2174
2207
|
}
|
|
2175
2208
|
function readOutboxSummary2(outboxFilePath) {
|
|
2176
|
-
const files = [outboxFilePath, ...listClaimFiles(outboxFilePath)].filter((file) =>
|
|
2209
|
+
const files = [outboxFilePath, ...listClaimFiles(outboxFilePath)].filter((file) => fs9.existsSync(file));
|
|
2177
2210
|
if (files.length === 0)
|
|
2178
2211
|
return void 0;
|
|
2179
2212
|
let depth = 0;
|
|
@@ -2194,7 +2227,7 @@ var require_outbox = __commonJS({
|
|
|
2194
2227
|
const claimPath = `${outboxFilePath}.${process.pid}${CLAIM_SUFFIX}`;
|
|
2195
2228
|
const claimed = [];
|
|
2196
2229
|
try {
|
|
2197
|
-
|
|
2230
|
+
fs9.renameSync(outboxFilePath, claimPath);
|
|
2198
2231
|
claimed.push(claimPath);
|
|
2199
2232
|
} catch {
|
|
2200
2233
|
}
|
|
@@ -2203,10 +2236,10 @@ var require_outbox = __commonJS({
|
|
|
2203
2236
|
if (claimed.includes(orphan))
|
|
2204
2237
|
continue;
|
|
2205
2238
|
try {
|
|
2206
|
-
if (now -
|
|
2239
|
+
if (now - fs9.statSync(orphan).mtimeMs < ORPHANED_CLAIM_AGE_MS)
|
|
2207
2240
|
continue;
|
|
2208
2241
|
const mine = `${claimPath}.${orphanIndex++}`;
|
|
2209
|
-
|
|
2242
|
+
fs9.renameSync(orphan, mine);
|
|
2210
2243
|
claimed.push(mine);
|
|
2211
2244
|
} catch {
|
|
2212
2245
|
}
|
|
@@ -2231,18 +2264,18 @@ var require_outbox = __commonJS({
|
|
|
2231
2264
|
released = true;
|
|
2232
2265
|
if (remainder.length > 0) {
|
|
2233
2266
|
try {
|
|
2234
|
-
|
|
2235
|
-
|
|
2267
|
+
fs9.mkdirSync(path8.dirname(outboxFilePath), { recursive: true, mode: 448 });
|
|
2268
|
+
fs9.appendFileSync(outboxFilePath, remainder.map((entry) => `${JSON.stringify(entry)}
|
|
2236
2269
|
`).join(""), { encoding: "utf8", mode: 384 });
|
|
2237
2270
|
if (process.platform !== "win32")
|
|
2238
|
-
|
|
2271
|
+
fs9.chmodSync(outboxFilePath, 384);
|
|
2239
2272
|
} catch {
|
|
2240
2273
|
return;
|
|
2241
2274
|
}
|
|
2242
2275
|
}
|
|
2243
2276
|
for (const file of claimed) {
|
|
2244
2277
|
try {
|
|
2245
|
-
|
|
2278
|
+
fs9.unlinkSync(file);
|
|
2246
2279
|
} catch {
|
|
2247
2280
|
}
|
|
2248
2281
|
}
|
|
@@ -2275,10 +2308,10 @@ var require_outbox = __commonJS({
|
|
|
2275
2308
|
return { kept, discarded: { count, reasons, ...oldestQueuedAt !== void 0 ? { oldestQueuedAt } : {} } };
|
|
2276
2309
|
}
|
|
2277
2310
|
function listClaimFiles(outboxFilePath) {
|
|
2278
|
-
const dir =
|
|
2279
|
-
const prefix = `${
|
|
2311
|
+
const dir = path8.dirname(outboxFilePath);
|
|
2312
|
+
const prefix = `${path8.basename(outboxFilePath)}.`;
|
|
2280
2313
|
try {
|
|
2281
|
-
return
|
|
2314
|
+
return fs9.readdirSync(dir).filter((name) => name.startsWith(prefix) && name.includes(CLAIM_SUFFIX)).map((name) => path8.join(dir, name)).sort();
|
|
2282
2315
|
} catch {
|
|
2283
2316
|
return [];
|
|
2284
2317
|
}
|
|
@@ -2286,7 +2319,7 @@ var require_outbox = __commonJS({
|
|
|
2286
2319
|
function readEntries(file) {
|
|
2287
2320
|
let raw;
|
|
2288
2321
|
try {
|
|
2289
|
-
raw =
|
|
2322
|
+
raw = fs9.readFileSync(file, "utf8");
|
|
2290
2323
|
} catch {
|
|
2291
2324
|
return { entries: [], unreadable: 0 };
|
|
2292
2325
|
}
|
|
@@ -2359,7 +2392,7 @@ var require_hookRunner = __commonJS({
|
|
|
2359
2392
|
exports.installHookRunner = installHookRunner2;
|
|
2360
2393
|
exports.removeHookRunner = removeHookRunner;
|
|
2361
2394
|
exports.hookRunnerCommand = hookRunnerCommand2;
|
|
2362
|
-
exports.writeAtomically =
|
|
2395
|
+
exports.writeAtomically = writeAtomically3;
|
|
2363
2396
|
exports.lastHookPath = lastHookPath;
|
|
2364
2397
|
exports.stampLastHook = stampLastHook2;
|
|
2365
2398
|
exports.readLastHook = readLastHook2;
|
|
@@ -2367,12 +2400,12 @@ var require_hookRunner = __commonJS({
|
|
|
2367
2400
|
exports.resolveHookNode = resolveHookNode2;
|
|
2368
2401
|
exports.tidyHomePath = tidyHomePath;
|
|
2369
2402
|
var child_process_1 = __require("child_process");
|
|
2370
|
-
var
|
|
2371
|
-
var
|
|
2403
|
+
var fs9 = __importStar(__require("fs"));
|
|
2404
|
+
var path8 = __importStar(__require("path"));
|
|
2372
2405
|
var collectorVersion_1 = require_collectorVersion();
|
|
2373
2406
|
var tokenStore_1 = require_tokenStore();
|
|
2374
2407
|
function hookRunnerPaths(binaryName) {
|
|
2375
|
-
const launcher =
|
|
2408
|
+
const launcher = path8.join((0, tokenStore_1.ascendaHome)(), "bin", binaryName);
|
|
2376
2409
|
return { launcher, bundle: `${launcher}.mjs`, record: `${launcher}.node`, noNode: `${launcher}.no-node`, version: `${launcher}.version` };
|
|
2377
2410
|
}
|
|
2378
2411
|
var LAUNCHER_MANAGEMENT_COMMANDS = ["setup", "install", "status", "uninstall", "doctor", "pair", "join", "object", "-h", "--help"];
|
|
@@ -2484,7 +2517,7 @@ var require_hookRunner = __commonJS({
|
|
|
2484
2517
|
}
|
|
2485
2518
|
function readInstalledVersion(file) {
|
|
2486
2519
|
try {
|
|
2487
|
-
return
|
|
2520
|
+
return fs9.readFileSync(file, "utf8").trim() || void 0;
|
|
2488
2521
|
} catch {
|
|
2489
2522
|
return void 0;
|
|
2490
2523
|
}
|
|
@@ -2493,41 +2526,41 @@ var require_hookRunner = __commonJS({
|
|
|
2493
2526
|
const paths = hookRunnerPaths(options.binaryName);
|
|
2494
2527
|
if (options.dryRun)
|
|
2495
2528
|
return paths.launcher;
|
|
2496
|
-
const source =
|
|
2529
|
+
const source = path8.resolve(options.source ?? process.argv[1]);
|
|
2497
2530
|
const incoming = options.version ?? collectorVersion_1.COLLECTOR_VERSION;
|
|
2498
2531
|
const installed = readInstalledVersion(paths.version);
|
|
2499
2532
|
const installedFile = process.platform === "win32" ? paths.launcher : paths.bundle;
|
|
2500
|
-
if (installed &&
|
|
2533
|
+
if (installed && fs9.existsSync(installedFile) && isDowngrade(installed, incoming)) {
|
|
2501
2534
|
options.onKeptNewer?.(installed, incoming);
|
|
2502
|
-
if (process.platform !== "win32" && !
|
|
2503
|
-
|
|
2535
|
+
if (process.platform !== "win32" && !fs9.existsSync(paths.launcher))
|
|
2536
|
+
writeAtomically3(paths.launcher, hookLauncherScript2(options), 493);
|
|
2504
2537
|
return paths.launcher;
|
|
2505
2538
|
}
|
|
2506
|
-
|
|
2539
|
+
fs9.mkdirSync(path8.dirname(paths.launcher), { recursive: true });
|
|
2507
2540
|
if (process.platform === "win32") {
|
|
2508
|
-
if (source !==
|
|
2509
|
-
|
|
2510
|
-
|
|
2541
|
+
if (source !== path8.resolve(paths.launcher))
|
|
2542
|
+
fs9.copyFileSync(source, paths.launcher);
|
|
2543
|
+
writeAtomically3(paths.version, `${incoming}
|
|
2511
2544
|
`, 420);
|
|
2512
2545
|
return paths.launcher;
|
|
2513
2546
|
}
|
|
2514
|
-
if (source !==
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2547
|
+
if (source !== path8.resolve(paths.bundle))
|
|
2548
|
+
writeAtomically3(paths.bundle, fs9.readFileSync(source), 493);
|
|
2549
|
+
writeAtomically3(paths.launcher, hookLauncherScript2(options), 493);
|
|
2550
|
+
writeAtomically3(paths.record, `${process.execPath}
|
|
2518
2551
|
`, 420);
|
|
2519
|
-
if (source !==
|
|
2520
|
-
|
|
2552
|
+
if (source !== path8.resolve(paths.bundle))
|
|
2553
|
+
writeAtomically3(paths.version, `${incoming}
|
|
2521
2554
|
`, 420);
|
|
2522
|
-
|
|
2555
|
+
fs9.rmSync(paths.noNode, { force: true });
|
|
2523
2556
|
return paths.launcher;
|
|
2524
2557
|
}
|
|
2525
2558
|
function removeHookRunner(binaryName) {
|
|
2526
2559
|
const removed = [];
|
|
2527
2560
|
for (const file of Object.values(hookRunnerPaths(binaryName))) {
|
|
2528
|
-
if (!
|
|
2561
|
+
if (!fs9.existsSync(file))
|
|
2529
2562
|
continue;
|
|
2530
|
-
|
|
2563
|
+
fs9.rmSync(file, { force: true });
|
|
2531
2564
|
removed.push(file);
|
|
2532
2565
|
}
|
|
2533
2566
|
return removed;
|
|
@@ -2535,30 +2568,30 @@ var require_hookRunner = __commonJS({
|
|
|
2535
2568
|
function hookRunnerCommand2(launcher, platform = process.platform) {
|
|
2536
2569
|
return platform === "win32" ? `"${process.execPath}" "${launcher}"` : `"${launcher}"`;
|
|
2537
2570
|
}
|
|
2538
|
-
function
|
|
2571
|
+
function writeAtomically3(target, contents, mode) {
|
|
2539
2572
|
const tmp = `${target}.${process.pid}.tmp`;
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2573
|
+
fs9.writeFileSync(tmp, contents, { mode });
|
|
2574
|
+
fs9.chmodSync(tmp, mode);
|
|
2575
|
+
fs9.renameSync(tmp, target);
|
|
2543
2576
|
}
|
|
2544
|
-
var
|
|
2577
|
+
var stateDir2 = () => process.env.ASCENDA_STATE_DIR ?? path8.join((0, tokenStore_1.ascendaHome)(), "state");
|
|
2545
2578
|
function lastHookPath(tool) {
|
|
2546
|
-
return
|
|
2579
|
+
return path8.join(stateDir2(), `${tool}-last-hook.json`);
|
|
2547
2580
|
}
|
|
2548
2581
|
function stampLastHook2(tool, event, now = /* @__PURE__ */ new Date()) {
|
|
2549
2582
|
try {
|
|
2550
|
-
|
|
2583
|
+
fs9.mkdirSync(stateDir2(), { recursive: true });
|
|
2551
2584
|
const file = lastHookPath(tool);
|
|
2552
2585
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
2553
|
-
|
|
2586
|
+
fs9.writeFileSync(tmp, `${JSON.stringify({ event, at: now.toISOString() })}
|
|
2554
2587
|
`, { mode: 384 });
|
|
2555
|
-
|
|
2588
|
+
fs9.renameSync(tmp, file);
|
|
2556
2589
|
} catch {
|
|
2557
2590
|
}
|
|
2558
2591
|
}
|
|
2559
2592
|
function readLastHook2(tool) {
|
|
2560
2593
|
try {
|
|
2561
|
-
const parsed = JSON.parse(
|
|
2594
|
+
const parsed = JSON.parse(fs9.readFileSync(lastHookPath(tool), "utf8"));
|
|
2562
2595
|
if (typeof parsed.event !== "string" || typeof parsed.at !== "string")
|
|
2563
2596
|
return void 0;
|
|
2564
2597
|
return { event: parsed.event, at: parsed.at };
|
|
@@ -2581,7 +2614,7 @@ var require_hookRunner = __commonJS({
|
|
|
2581
2614
|
return `${Math.round(hours / 24)} days ago`;
|
|
2582
2615
|
}
|
|
2583
2616
|
function resolveHookNode2(launcher) {
|
|
2584
|
-
if (!
|
|
2617
|
+
if (!fs9.existsSync(launcher))
|
|
2585
2618
|
return { problem: "the hook launcher is not installed" };
|
|
2586
2619
|
const probe = (0, child_process_1.spawnSync)("/bin/sh", [launcher], {
|
|
2587
2620
|
encoding: "utf8",
|
|
@@ -2656,8 +2689,8 @@ var require_releaseCheck = __commonJS({
|
|
|
2656
2689
|
exports.pendingReleaseNotice = pendingReleaseNotice2;
|
|
2657
2690
|
exports.describeReleaseCheck = describeReleaseCheck2;
|
|
2658
2691
|
exports.installedBundleVersion = installedBundleVersion2;
|
|
2659
|
-
var
|
|
2660
|
-
var
|
|
2692
|
+
var fs9 = __importStar(__require("fs"));
|
|
2693
|
+
var path8 = __importStar(__require("path"));
|
|
2661
2694
|
var collectorVersion_1 = require_collectorVersion();
|
|
2662
2695
|
var hookRunner_1 = require_hookRunner();
|
|
2663
2696
|
var tokenStore_1 = require_tokenStore();
|
|
@@ -2671,11 +2704,11 @@ var require_releaseCheck = __commonJS({
|
|
|
2671
2704
|
return env[exports.RELEASE_CHECK_ENV_VAR]?.trim().toLowerCase() === "true";
|
|
2672
2705
|
}
|
|
2673
2706
|
function releaseCheckPath() {
|
|
2674
|
-
return
|
|
2707
|
+
return path8.join((0, tokenStore_1.ascendaHome)(), "state", "release-check.json");
|
|
2675
2708
|
}
|
|
2676
2709
|
function readReleaseCheck(file = releaseCheckPath()) {
|
|
2677
2710
|
try {
|
|
2678
|
-
const parsed = JSON.parse(
|
|
2711
|
+
const parsed = JSON.parse(fs9.readFileSync(file, "utf8"));
|
|
2679
2712
|
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
2680
2713
|
} catch {
|
|
2681
2714
|
return void 0;
|
|
@@ -2683,7 +2716,7 @@ var require_releaseCheck = __commonJS({
|
|
|
2683
2716
|
}
|
|
2684
2717
|
function writeReleaseCheck(file, check) {
|
|
2685
2718
|
try {
|
|
2686
|
-
|
|
2719
|
+
fs9.mkdirSync(path8.dirname(file), { recursive: true, mode: 448 });
|
|
2687
2720
|
(0, hookRunner_1.writeAtomically)(file, `${JSON.stringify(check, null, 2)}
|
|
2688
2721
|
`, 384);
|
|
2689
2722
|
} catch {
|
|
@@ -2774,7 +2807,7 @@ var require_releaseCheck = __commonJS({
|
|
|
2774
2807
|
function runsFromInstalledBundle2(script = process.argv[1]) {
|
|
2775
2808
|
if (!script)
|
|
2776
2809
|
return false;
|
|
2777
|
-
return
|
|
2810
|
+
return path8.dirname(path8.resolve(script)) === path8.join((0, tokenStore_1.ascendaHome)(), "bin");
|
|
2778
2811
|
}
|
|
2779
2812
|
function pendingReleaseNotice2(options) {
|
|
2780
2813
|
if (releaseCheckDisabled(options.env))
|
|
@@ -2823,7 +2856,7 @@ var require_releaseCheck = __commonJS({
|
|
|
2823
2856
|
}
|
|
2824
2857
|
function installedBundleVersion2(versionFile) {
|
|
2825
2858
|
try {
|
|
2826
|
-
return
|
|
2859
|
+
return fs9.readFileSync(versionFile, "utf8").trim() || void 0;
|
|
2827
2860
|
} catch {
|
|
2828
2861
|
return void 0;
|
|
2829
2862
|
}
|
|
@@ -2878,7 +2911,7 @@ var require_backgroundDelivery = __commonJS({
|
|
|
2878
2911
|
exports.flushLockPath = flushLockPath;
|
|
2879
2912
|
exports.startBackgroundFlush = startBackgroundFlush2;
|
|
2880
2913
|
exports.runOutboxFlush = runOutboxFlush3;
|
|
2881
|
-
var
|
|
2914
|
+
var fs9 = __importStar(__require("fs"));
|
|
2882
2915
|
var child_process_1 = __require("child_process");
|
|
2883
2916
|
var outbox_1 = require_outbox();
|
|
2884
2917
|
var releaseCheck_1 = require_releaseCheck();
|
|
@@ -2895,27 +2928,27 @@ var require_backgroundDelivery = __commonJS({
|
|
|
2895
2928
|
}
|
|
2896
2929
|
function lockIsFresh(lockPath, now) {
|
|
2897
2930
|
try {
|
|
2898
|
-
return now -
|
|
2931
|
+
return now - fs9.statSync(lockPath).mtimeMs < exports.FLUSH_LOCK_FRESH_MS;
|
|
2899
2932
|
} catch {
|
|
2900
2933
|
return false;
|
|
2901
2934
|
}
|
|
2902
2935
|
}
|
|
2903
2936
|
function touchLock(lockPath) {
|
|
2904
2937
|
try {
|
|
2905
|
-
|
|
2938
|
+
fs9.writeFileSync(lockPath, `${process.pid}
|
|
2906
2939
|
`, { encoding: "utf8", mode: 384 });
|
|
2907
2940
|
} catch {
|
|
2908
2941
|
}
|
|
2909
2942
|
}
|
|
2910
2943
|
function removeLock(lockPath) {
|
|
2911
2944
|
try {
|
|
2912
|
-
|
|
2945
|
+
fs9.unlinkSync(lockPath);
|
|
2913
2946
|
} catch {
|
|
2914
2947
|
}
|
|
2915
2948
|
}
|
|
2916
2949
|
function outboxHasEntries(outboxFilePath) {
|
|
2917
2950
|
try {
|
|
2918
|
-
return
|
|
2951
|
+
return fs9.statSync(outboxFilePath).size > 0;
|
|
2919
2952
|
} catch {
|
|
2920
2953
|
return false;
|
|
2921
2954
|
}
|
|
@@ -3188,15 +3221,15 @@ var require_credentials = __commonJS({
|
|
|
3188
3221
|
exports.readHostCredentials = readHostCredentials;
|
|
3189
3222
|
exports.writeHostCredentials = writeHostCredentials;
|
|
3190
3223
|
exports.removeHostCredentials = removeHostCredentials;
|
|
3191
|
-
var
|
|
3192
|
-
var
|
|
3224
|
+
var fs9 = __importStar(__require("fs"));
|
|
3225
|
+
var path8 = __importStar(__require("path"));
|
|
3193
3226
|
var tokenStore_1 = require_tokenStore();
|
|
3194
3227
|
function credentialsFilePath2() {
|
|
3195
|
-
return
|
|
3228
|
+
return path8.join((0, tokenStore_1.ascendaHome)(), "credentials.json");
|
|
3196
3229
|
}
|
|
3197
3230
|
function readMachineCredentials2() {
|
|
3198
3231
|
try {
|
|
3199
|
-
const raw =
|
|
3232
|
+
const raw = fs9.readFileSync(credentialsFilePath2(), "utf8").trim();
|
|
3200
3233
|
if (!raw)
|
|
3201
3234
|
return void 0;
|
|
3202
3235
|
const parsed = JSON.parse(raw);
|
|
@@ -3209,12 +3242,12 @@ var require_credentials = __commonJS({
|
|
|
3209
3242
|
}
|
|
3210
3243
|
function writeMachineCredentials2(credentials) {
|
|
3211
3244
|
const file = credentialsFilePath2();
|
|
3212
|
-
|
|
3213
|
-
|
|
3245
|
+
fs9.mkdirSync(path8.dirname(file), { recursive: true, mode: 448 });
|
|
3246
|
+
fs9.writeFileSync(file, `${JSON.stringify(credentials, null, 2)}
|
|
3214
3247
|
`, { encoding: "utf8", mode: 384 });
|
|
3215
3248
|
if (process.platform !== "win32") {
|
|
3216
|
-
|
|
3217
|
-
|
|
3249
|
+
fs9.chmodSync(path8.dirname(file), 448);
|
|
3250
|
+
fs9.chmodSync(file, 384);
|
|
3218
3251
|
}
|
|
3219
3252
|
}
|
|
3220
3253
|
function writeTopLevelCredentials2(credentials) {
|
|
@@ -3321,9 +3354,9 @@ var require_eventLog = __commonJS({
|
|
|
3321
3354
|
exports.describeEventLog = describeEventLog3;
|
|
3322
3355
|
exports.parseEventLogFlag = parseEventLogFlag2;
|
|
3323
3356
|
exports.appendEventLog = appendEventLog2;
|
|
3324
|
-
var
|
|
3357
|
+
var fs9 = __importStar(__require("fs"));
|
|
3325
3358
|
var os4 = __importStar(__require("os"));
|
|
3326
|
-
var
|
|
3359
|
+
var path8 = __importStar(__require("path"));
|
|
3327
3360
|
var agentEvent_1 = require_agentEvent();
|
|
3328
3361
|
var credentials_1 = require_credentials();
|
|
3329
3362
|
var tokenStore_1 = require_tokenStore();
|
|
@@ -3337,11 +3370,11 @@ var require_eventLog = __commonJS({
|
|
|
3337
3370
|
if (value === "~")
|
|
3338
3371
|
return os4.homedir();
|
|
3339
3372
|
if (value.startsWith("~/"))
|
|
3340
|
-
return
|
|
3341
|
-
return
|
|
3373
|
+
return path8.join(os4.homedir(), value.slice(2));
|
|
3374
|
+
return path8.resolve(value);
|
|
3342
3375
|
}
|
|
3343
3376
|
function defaultEventLogPath() {
|
|
3344
|
-
return
|
|
3377
|
+
return path8.join((0, tokenStore_1.ascendaHome)(), "events.jsonl");
|
|
3345
3378
|
}
|
|
3346
3379
|
function resolveEventLog3(options = {}) {
|
|
3347
3380
|
for (const [source, raw] of [
|
|
@@ -3385,21 +3418,21 @@ var require_eventLog = __commonJS({
|
|
|
3385
3418
|
function appendEventLog2(logFilePath, entry) {
|
|
3386
3419
|
try {
|
|
3387
3420
|
rotateIfLarge(logFilePath);
|
|
3388
|
-
const dir =
|
|
3389
|
-
|
|
3421
|
+
const dir = path8.dirname(logFilePath);
|
|
3422
|
+
fs9.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
3390
3423
|
const line = { ...entry, event: entry.event ?? (0, agentEvent_1.toAgentEvent)(entry.payload) };
|
|
3391
|
-
|
|
3424
|
+
fs9.appendFileSync(logFilePath, `${JSON.stringify(line)}
|
|
3392
3425
|
`, { encoding: "utf8", mode: 384 });
|
|
3393
3426
|
if (process.platform !== "win32")
|
|
3394
|
-
|
|
3427
|
+
fs9.chmodSync(logFilePath, 384);
|
|
3395
3428
|
} catch {
|
|
3396
3429
|
}
|
|
3397
3430
|
}
|
|
3398
3431
|
function rotateIfLarge(logFilePath) {
|
|
3399
3432
|
try {
|
|
3400
|
-
if (
|
|
3433
|
+
if (fs9.statSync(logFilePath).size < MAX_BYTES)
|
|
3401
3434
|
return;
|
|
3402
|
-
|
|
3435
|
+
fs9.renameSync(logFilePath, `${logFilePath}.1`);
|
|
3403
3436
|
} catch {
|
|
3404
3437
|
}
|
|
3405
3438
|
}
|
|
@@ -4215,16 +4248,16 @@ var require_contextRegistry = __commonJS({
|
|
|
4215
4248
|
exports.readWorkContextRegistry = readWorkContextRegistry;
|
|
4216
4249
|
exports.recordWorkContext = recordWorkContext2;
|
|
4217
4250
|
exports.recordWorkContextAlias = recordWorkContextAlias;
|
|
4218
|
-
var
|
|
4251
|
+
var fs9 = __importStar(__require("fs"));
|
|
4219
4252
|
var os4 = __importStar(__require("os"));
|
|
4220
|
-
var
|
|
4253
|
+
var path8 = __importStar(__require("path"));
|
|
4221
4254
|
var MAX_PATHS_PER_ENTRY = 8;
|
|
4222
4255
|
function workContextRegistryFilePath() {
|
|
4223
|
-
return
|
|
4256
|
+
return path8.join(os4.homedir(), ".ascenda", "work-contexts.json");
|
|
4224
4257
|
}
|
|
4225
4258
|
function readWorkContextRegistry(registryFilePath = workContextRegistryFilePath()) {
|
|
4226
4259
|
try {
|
|
4227
|
-
const parsed = JSON.parse(
|
|
4260
|
+
const parsed = JSON.parse(fs9.readFileSync(registryFilePath, "utf8"));
|
|
4228
4261
|
if (parsed && parsed.version === 1 && parsed.contexts && typeof parsed.contexts === "object") {
|
|
4229
4262
|
return parsed;
|
|
4230
4263
|
}
|
|
@@ -4300,14 +4333,14 @@ var require_contextRegistry = __commonJS({
|
|
|
4300
4333
|
return iso.slice(0, 10);
|
|
4301
4334
|
}
|
|
4302
4335
|
function writeRegistry(registryFilePath, registry) {
|
|
4303
|
-
const dir =
|
|
4304
|
-
|
|
4336
|
+
const dir = path8.dirname(registryFilePath);
|
|
4337
|
+
fs9.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
4305
4338
|
const tmp = `${registryFilePath}.${process.pid}.tmp`;
|
|
4306
|
-
|
|
4339
|
+
fs9.writeFileSync(tmp, `${JSON.stringify(registry, null, 2)}
|
|
4307
4340
|
`, { encoding: "utf8", mode: 384 });
|
|
4308
|
-
|
|
4341
|
+
fs9.renameSync(tmp, registryFilePath);
|
|
4309
4342
|
if (process.platform !== "win32") {
|
|
4310
|
-
|
|
4343
|
+
fs9.chmodSync(registryFilePath, 384);
|
|
4311
4344
|
}
|
|
4312
4345
|
}
|
|
4313
4346
|
}
|
|
@@ -4362,8 +4395,8 @@ var require_forgeProject = __commonJS({
|
|
|
4362
4395
|
exports.readForgeFullName = readForgeFullName;
|
|
4363
4396
|
exports.forgeFullNameFromConfig = forgeFullNameFromConfig;
|
|
4364
4397
|
exports.recordForgeProjectAlias = recordForgeProjectAlias2;
|
|
4365
|
-
var
|
|
4366
|
-
var
|
|
4398
|
+
var fs9 = __importStar(__require("fs"));
|
|
4399
|
+
var path8 = __importStar(__require("path"));
|
|
4367
4400
|
var contextRegistry_1 = require_contextRegistry();
|
|
4368
4401
|
function forgeProjectHash(value) {
|
|
4369
4402
|
let h = 2166136261;
|
|
@@ -4422,7 +4455,7 @@ ${branch}`;
|
|
|
4422
4455
|
return null;
|
|
4423
4456
|
let config;
|
|
4424
4457
|
try {
|
|
4425
|
-
config =
|
|
4458
|
+
config = fs9.readFileSync(path8.join(repositoryRoot, ".git", "config"), "utf8");
|
|
4426
4459
|
} catch {
|
|
4427
4460
|
return null;
|
|
4428
4461
|
}
|
|
@@ -4529,31 +4562,31 @@ var require_salt = __commonJS({
|
|
|
4529
4562
|
exports.readOrCreateMachineSalt = readOrCreateMachineSalt;
|
|
4530
4563
|
exports.hashWithMachineSalt = hashWithMachineSalt;
|
|
4531
4564
|
var crypto2 = __importStar(__require("crypto"));
|
|
4532
|
-
var
|
|
4533
|
-
var
|
|
4565
|
+
var fs9 = __importStar(__require("fs"));
|
|
4566
|
+
var path8 = __importStar(__require("path"));
|
|
4534
4567
|
var tokenStore_1 = require_tokenStore();
|
|
4535
4568
|
function machineSaltFilePath() {
|
|
4536
|
-
return
|
|
4569
|
+
return path8.join((0, tokenStore_1.ascendaHome)(), "salt");
|
|
4537
4570
|
}
|
|
4538
4571
|
var cache = /* @__PURE__ */ new Map();
|
|
4539
4572
|
function readOrCreateMachineSalt(saltFilePath = machineSaltFilePath()) {
|
|
4540
4573
|
const hit = cache.get(saltFilePath);
|
|
4541
4574
|
if (hit)
|
|
4542
4575
|
return hit;
|
|
4543
|
-
const dir =
|
|
4544
|
-
|
|
4576
|
+
const dir = path8.dirname(saltFilePath);
|
|
4577
|
+
fs9.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
4545
4578
|
let salt;
|
|
4546
4579
|
try {
|
|
4547
4580
|
salt = crypto2.randomBytes(32).toString("hex");
|
|
4548
|
-
|
|
4581
|
+
fs9.writeFileSync(saltFilePath, salt, { encoding: "utf8", mode: 384, flag: "wx" });
|
|
4549
4582
|
} catch (error) {
|
|
4550
4583
|
if (error.code !== "EEXIST")
|
|
4551
4584
|
throw error;
|
|
4552
|
-
salt =
|
|
4585
|
+
salt = fs9.readFileSync(saltFilePath, "utf8").trim();
|
|
4553
4586
|
}
|
|
4554
4587
|
if (process.platform !== "win32") {
|
|
4555
|
-
|
|
4556
|
-
|
|
4588
|
+
fs9.chmodSync(dir, 448);
|
|
4589
|
+
fs9.chmodSync(saltFilePath, 384);
|
|
4557
4590
|
}
|
|
4558
4591
|
cache.set(saltFilePath, salt);
|
|
4559
4592
|
return salt;
|
|
@@ -4613,8 +4646,8 @@ var require_workContext = __commonJS({
|
|
|
4613
4646
|
exports.deriveBranchHash = deriveBranchHash;
|
|
4614
4647
|
exports.readBranchName = readBranchName;
|
|
4615
4648
|
exports.deriveBranchHashForCwd = deriveBranchHashForCwd2;
|
|
4616
|
-
var
|
|
4617
|
-
var
|
|
4649
|
+
var fs9 = __importStar(__require("fs"));
|
|
4650
|
+
var path8 = __importStar(__require("path"));
|
|
4618
4651
|
var salt_1 = require_salt();
|
|
4619
4652
|
var MAX_WALK_DEPTH = 64;
|
|
4620
4653
|
function deriveWorkContext2(cwd, saltFilePath) {
|
|
@@ -4645,14 +4678,14 @@ var require_workContext = __commonJS({
|
|
|
4645
4678
|
};
|
|
4646
4679
|
}
|
|
4647
4680
|
function resolveRepositoryRoots(startDir) {
|
|
4648
|
-
if (!
|
|
4681
|
+
if (!fs9.existsSync(startDir))
|
|
4649
4682
|
return null;
|
|
4650
4683
|
let dir = startDir;
|
|
4651
4684
|
for (let depth = 0; depth < MAX_WALK_DEPTH; depth++) {
|
|
4652
|
-
const dotGit =
|
|
4685
|
+
const dotGit = path8.join(dir, ".git");
|
|
4653
4686
|
let stat = null;
|
|
4654
4687
|
try {
|
|
4655
|
-
stat =
|
|
4688
|
+
stat = fs9.statSync(dotGit);
|
|
4656
4689
|
} catch {
|
|
4657
4690
|
stat = null;
|
|
4658
4691
|
}
|
|
@@ -4663,7 +4696,7 @@ var require_workContext = __commonJS({
|
|
|
4663
4696
|
const canonicalRoot = (gitDir ? worktreeParentRoot(gitDir) : null) ?? dir;
|
|
4664
4697
|
return { checkoutRoot: dir, canonicalRoot, gitDir };
|
|
4665
4698
|
}
|
|
4666
|
-
const parent =
|
|
4699
|
+
const parent = path8.dirname(dir);
|
|
4667
4700
|
if (parent === dir)
|
|
4668
4701
|
return null;
|
|
4669
4702
|
dir = parent;
|
|
@@ -4672,16 +4705,16 @@ var require_workContext = __commonJS({
|
|
|
4672
4705
|
}
|
|
4673
4706
|
function readGitdirPointer(dotGitFile, containingDir) {
|
|
4674
4707
|
try {
|
|
4675
|
-
const match = /^gitdir:\s*(.+)\s*$/m.exec(
|
|
4708
|
+
const match = /^gitdir:\s*(.+)\s*$/m.exec(fs9.readFileSync(dotGitFile, "utf8"));
|
|
4676
4709
|
if (!match)
|
|
4677
4710
|
return null;
|
|
4678
|
-
return
|
|
4711
|
+
return path8.resolve(containingDir, match[1].trim());
|
|
4679
4712
|
} catch {
|
|
4680
4713
|
return null;
|
|
4681
4714
|
}
|
|
4682
4715
|
}
|
|
4683
4716
|
function worktreeParentRoot(resolvedGitDir) {
|
|
4684
|
-
const marker = `${
|
|
4717
|
+
const marker = `${path8.sep}.git${path8.sep}worktrees${path8.sep}`;
|
|
4685
4718
|
const idx = resolvedGitDir.indexOf(marker);
|
|
4686
4719
|
if (idx === -1)
|
|
4687
4720
|
return null;
|
|
@@ -4691,12 +4724,12 @@ var require_workContext = __commonJS({
|
|
|
4691
4724
|
const sep = startPath.includes("\\") && !startPath.includes("/") ? "\\" : "/";
|
|
4692
4725
|
const leading = /^[\\/]/.test(startPath) ? sep : "";
|
|
4693
4726
|
const segments = startPath.split(/[\\/]/).filter(Boolean);
|
|
4694
|
-
const
|
|
4727
|
+
const join8 = (count) => leading + segments.slice(0, count).join(sep);
|
|
4695
4728
|
for (let i = 0; i + 2 < segments.length; i++) {
|
|
4696
4729
|
if (segments[i] === ".claude" && segments[i + 1] === "worktrees") {
|
|
4697
4730
|
if (i === 0)
|
|
4698
4731
|
return null;
|
|
4699
|
-
return { checkoutRoot:
|
|
4732
|
+
return { checkoutRoot: join8(i + 3), canonicalRoot: join8(i), gitDir: null };
|
|
4700
4733
|
}
|
|
4701
4734
|
}
|
|
4702
4735
|
for (let i = 0; i + 1 < segments.length; i++) {
|
|
@@ -4706,7 +4739,7 @@ var require_workContext = __commonJS({
|
|
|
4706
4739
|
continue;
|
|
4707
4740
|
const repoName = folder.slice(0, -suffix.length);
|
|
4708
4741
|
const canonicalRoot = leading + [...segments.slice(0, i), repoName].join(sep);
|
|
4709
|
-
return { checkoutRoot:
|
|
4742
|
+
return { checkoutRoot: join8(i + 2), canonicalRoot, gitDir: null };
|
|
4710
4743
|
}
|
|
4711
4744
|
return null;
|
|
4712
4745
|
}
|
|
@@ -4754,7 +4787,7 @@ var require_workContext = __commonJS({
|
|
|
4754
4787
|
return null;
|
|
4755
4788
|
let head;
|
|
4756
4789
|
try {
|
|
4757
|
-
head =
|
|
4790
|
+
head = fs9.readFileSync(path8.join(gitDir, "HEAD"), "utf8").trim();
|
|
4758
4791
|
} catch {
|
|
4759
4792
|
return null;
|
|
4760
4793
|
}
|
|
@@ -4817,8 +4850,8 @@ var require_forgeKeys = __commonJS({
|
|
|
4817
4850
|
exports.REPO_KEYS_ENV_VAR = void 0;
|
|
4818
4851
|
exports.repoKeysEnabled = repoKeysEnabled;
|
|
4819
4852
|
exports.deriveForgeKeysForCwd = deriveForgeKeysForCwd2;
|
|
4820
|
-
var
|
|
4821
|
-
var
|
|
4853
|
+
var fs9 = __importStar(__require("fs"));
|
|
4854
|
+
var path8 = __importStar(__require("path"));
|
|
4822
4855
|
var credentials_1 = require_credentials();
|
|
4823
4856
|
var forgeProject_1 = require_forgeProject();
|
|
4824
4857
|
var workContext_1 = require_workContext();
|
|
@@ -4833,7 +4866,7 @@ var require_forgeKeys = __commonJS({
|
|
|
4833
4866
|
}
|
|
4834
4867
|
function readDefaultBranch(repositoryRoot) {
|
|
4835
4868
|
try {
|
|
4836
|
-
const head =
|
|
4869
|
+
const head = fs9.readFileSync(path8.join(repositoryRoot, ".git", "refs", "remotes", "origin", "HEAD"), "utf8").trim();
|
|
4837
4870
|
const match = /^ref:\s*refs\/remotes\/origin\/(.+)$/.exec(head);
|
|
4838
4871
|
return match ? (0, workContext_1.normalizeBranchName)(match[1]) : null;
|
|
4839
4872
|
} catch {
|
|
@@ -5452,7 +5485,7 @@ var require_pairingStudyJoin = __commonJS({
|
|
|
5452
5485
|
exports.settleStudyJoin = settleStudyJoin2;
|
|
5453
5486
|
exports.writePairingJoinOutcome = writePairingJoinOutcome2;
|
|
5454
5487
|
exports.pairingJoinOutcome = pairingJoinOutcome2;
|
|
5455
|
-
var
|
|
5488
|
+
var fs9 = __importStar(__require("node:fs"));
|
|
5456
5489
|
var confirmLinks_1 = require_confirmLinks();
|
|
5457
5490
|
var studyJoin_1 = require_studyJoin();
|
|
5458
5491
|
var http_1 = require_http();
|
|
@@ -5481,12 +5514,12 @@ var require_pairingStudyJoin = __commonJS({
|
|
|
5481
5514
|
}
|
|
5482
5515
|
function pairingAttemptLines2(attempt) {
|
|
5483
5516
|
const { session } = attempt;
|
|
5484
|
-
const
|
|
5485
|
-
if (!
|
|
5517
|
+
const join8 = attempt.carriesJoin ? session.studyJoin : void 0;
|
|
5518
|
+
if (!join8)
|
|
5486
5519
|
return (0, confirmLinks_1.pairingConfirmLines)(session.qrUrl, session.code);
|
|
5487
|
-
const gitOffer = (0, studyJoin_1.gitOfferLine)(
|
|
5520
|
+
const gitOffer = (0, studyJoin_1.gitOfferLine)(join8.optionalImportStores);
|
|
5488
5521
|
return [
|
|
5489
|
-
`This also joins ${
|
|
5522
|
+
`This also joins ${join8.organisationName} (${(0, studyJoin_1.formatWindow)(join8.windowStartUtc, join8.windowEndUtc)}). The page shows what you'd share before you confirm.`,
|
|
5490
5523
|
...gitOffer ? [gitOffer] : [],
|
|
5491
5524
|
`Open this link to confirm: ${session.qrUrl}`
|
|
5492
5525
|
];
|
|
@@ -5511,7 +5544,7 @@ var require_pairingStudyJoin = __commonJS({
|
|
|
5511
5544
|
if (!file)
|
|
5512
5545
|
return;
|
|
5513
5546
|
try {
|
|
5514
|
-
|
|
5547
|
+
fs9.writeFileSync(file, `${JSON.stringify(outcome)}
|
|
5515
5548
|
`, { mode: 384 });
|
|
5516
5549
|
} catch {
|
|
5517
5550
|
}
|
|
@@ -5799,19 +5832,19 @@ var require_settingsFile = __commonJS({
|
|
|
5799
5832
|
}();
|
|
5800
5833
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5801
5834
|
exports.replaceSettingsFile = replaceSettingsFile2;
|
|
5802
|
-
var
|
|
5803
|
-
var
|
|
5835
|
+
var fs9 = __importStar(__require("fs"));
|
|
5836
|
+
var path8 = __importStar(__require("path"));
|
|
5804
5837
|
var hookRunner_1 = require_hookRunner();
|
|
5805
5838
|
function replaceSettingsFile2(settingsFile, contents) {
|
|
5806
|
-
const exists =
|
|
5807
|
-
const target = exists ?
|
|
5839
|
+
const exists = fs9.existsSync(settingsFile);
|
|
5840
|
+
const target = exists ? fs9.realpathSync(settingsFile) : settingsFile;
|
|
5808
5841
|
if (exists) {
|
|
5809
5842
|
const backup = `${settingsFile}.ascenda-backup`;
|
|
5810
|
-
if (!
|
|
5811
|
-
|
|
5843
|
+
if (!fs9.existsSync(backup))
|
|
5844
|
+
fs9.copyFileSync(target, backup);
|
|
5812
5845
|
}
|
|
5813
|
-
|
|
5814
|
-
const mode = exists ?
|
|
5846
|
+
fs9.mkdirSync(path8.dirname(target), { recursive: true });
|
|
5847
|
+
const mode = exists ? fs9.statSync(target).mode & 511 : 420;
|
|
5815
5848
|
(0, hookRunner_1.writeAtomically)(target, contents, mode);
|
|
5816
5849
|
}
|
|
5817
5850
|
}
|
|
@@ -5836,7 +5869,7 @@ var require_setupDisclosure = __commonJS({
|
|
|
5836
5869
|
git: "that a commit, push or revert happened, and when a pull request opened or merged",
|
|
5837
5870
|
edits: "roughly how much a file changed, as a bucket, and whether you edited it after the agent wrote it",
|
|
5838
5871
|
context: "how full the context window got",
|
|
5839
|
-
waiting: "that your agent stopped and waited for you, as one word: permission_request, input_request, idle_prompt, or other, and that it asked permission for a tool or had one refused in auto mode, with the tool's name",
|
|
5872
|
+
waiting: "that your agent stopped and waited for you, as one word: permission_request, input_request, idle_prompt, or other, how many milliseconds the wait lasted as worked out on your machine, and that it asked permission for a tool or had one refused in auto mode, with the tool's name",
|
|
5840
5873
|
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",
|
|
5841
5874
|
forge: "for a GitHub repository, one digest of owner/repo and one of the branch, which anyone who guesses the names can reproduce, so a pull request can be matched to your session (turn off with setup --no-repo-keys)",
|
|
5842
5875
|
turns: "an opaque id your agent gives each prompt, so one turn's events group together",
|
|
@@ -5916,22 +5949,22 @@ var require_saverHandoff = __commonJS({
|
|
|
5916
5949
|
exports.heldForSaver = heldForSaver;
|
|
5917
5950
|
exports.readSaverStatuses = readSaverStatuses;
|
|
5918
5951
|
exports.probeSocket = probeSocket;
|
|
5919
|
-
var
|
|
5952
|
+
var fs9 = __importStar(__require("fs"));
|
|
5920
5953
|
var net = __importStar(__require("net"));
|
|
5921
5954
|
var os4 = __importStar(__require("os"));
|
|
5922
|
-
var
|
|
5955
|
+
var path8 = __importStar(__require("path"));
|
|
5923
5956
|
var SAVER_HOST_BUNDLE_ID = "com.apple.ScreenSaver.Engine.legacyScreenSaver";
|
|
5924
5957
|
function saverContainerDir() {
|
|
5925
|
-
return process.env.ASCENDA_SAVER_CONTAINER ??
|
|
5958
|
+
return process.env.ASCENDA_SAVER_CONTAINER ?? path8.join(os4.homedir(), "Library", "Containers", SAVER_HOST_BUNDLE_ID, "Data");
|
|
5926
5959
|
}
|
|
5927
5960
|
function saverSupportDir() {
|
|
5928
|
-
return
|
|
5961
|
+
return path8.join(saverContainerDir(), "Library", "Application Support", "AscendaWaterlineSaver");
|
|
5929
5962
|
}
|
|
5930
5963
|
function saverReplayPath() {
|
|
5931
|
-
return
|
|
5964
|
+
return path8.join(saverContainerDir(), "l.replay.json");
|
|
5932
5965
|
}
|
|
5933
5966
|
function saverStatusDir() {
|
|
5934
|
-
return
|
|
5967
|
+
return path8.join(saverSupportDir(), "status");
|
|
5935
5968
|
}
|
|
5936
5969
|
exports.SAVER_REPLAY_WINDOW_MS = 30 * 60 * 1e3;
|
|
5937
5970
|
var SAVER_REPLAY_MAX = 32;
|
|
@@ -5940,7 +5973,7 @@ var require_saverHandoff = __commonJS({
|
|
|
5940
5973
|
try {
|
|
5941
5974
|
if (process.env.ASCENDA_LIVE_BUS_SOCKET && !process.env.ASCENDA_SAVER_CONTAINER)
|
|
5942
5975
|
return;
|
|
5943
|
-
if (!
|
|
5976
|
+
if (!fs9.existsSync(saverSupportDir()))
|
|
5944
5977
|
return;
|
|
5945
5978
|
const wire = signal;
|
|
5946
5979
|
const tool = wire.tool;
|
|
@@ -5954,15 +5987,15 @@ var require_saverHandoff = __commonJS({
|
|
|
5954
5987
|
kept.sort((a, b) => a.at - b.at);
|
|
5955
5988
|
const body = JSON.stringify({ schema: exports.SAVER_REPLAY_SCHEMA, signals: kept.slice(-SAVER_REPLAY_MAX) });
|
|
5956
5989
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
5957
|
-
|
|
5990
|
+
fs9.writeFileSync(tmp, `${body}
|
|
5958
5991
|
`, { mode: 384 });
|
|
5959
|
-
|
|
5992
|
+
fs9.renameSync(tmp, file);
|
|
5960
5993
|
} catch {
|
|
5961
5994
|
}
|
|
5962
5995
|
}
|
|
5963
5996
|
function readHeld(file) {
|
|
5964
5997
|
try {
|
|
5965
|
-
const parsed = JSON.parse(
|
|
5998
|
+
const parsed = JSON.parse(fs9.readFileSync(file, "utf8"));
|
|
5966
5999
|
if (parsed.schema !== exports.SAVER_REPLAY_SCHEMA || !Array.isArray(parsed.signals))
|
|
5967
6000
|
return [];
|
|
5968
6001
|
return parsed.signals.filter((held) => typeof held === "object" && held !== null && typeof held.tool === "string" && typeof held.session === "string" && typeof held.event === "string" && typeof held.at === "number");
|
|
@@ -5979,14 +6012,14 @@ var require_saverHandoff = __commonJS({
|
|
|
5979
6012
|
function readSaverStatuses(now = Date.now()) {
|
|
5980
6013
|
let names;
|
|
5981
6014
|
try {
|
|
5982
|
-
names =
|
|
6015
|
+
names = fs9.readdirSync(saverStatusDir()).filter((name) => name.endsWith(".json"));
|
|
5983
6016
|
} catch {
|
|
5984
6017
|
return [];
|
|
5985
6018
|
}
|
|
5986
6019
|
const readings = [];
|
|
5987
6020
|
for (const name of names) {
|
|
5988
6021
|
try {
|
|
5989
|
-
const status = JSON.parse(
|
|
6022
|
+
const status = JSON.parse(fs9.readFileSync(path8.join(saverStatusDir(), name), "utf8"));
|
|
5990
6023
|
if (typeof status.pid !== "number" || typeof status.updatedAt !== "string")
|
|
5991
6024
|
continue;
|
|
5992
6025
|
readings.push({ ...status, alive: processAlive(status.pid), ageMs: now - Date.parse(status.updatedAt) });
|
|
@@ -6006,7 +6039,7 @@ var require_saverHandoff = __commonJS({
|
|
|
6006
6039
|
function probeSocket(socketPath, timeoutMs = 300) {
|
|
6007
6040
|
return new Promise((resolve3) => {
|
|
6008
6041
|
try {
|
|
6009
|
-
if (!
|
|
6042
|
+
if (!fs9.statSync(socketPath).isSocket()) {
|
|
6010
6043
|
resolve3("absent");
|
|
6011
6044
|
return;
|
|
6012
6045
|
}
|
|
@@ -6082,10 +6115,10 @@ var require_liveBus = __commonJS({
|
|
|
6082
6115
|
exports.promptSizeMetadata = promptSizeMetadata2;
|
|
6083
6116
|
exports.emitLiveSignal = emitLiveSignal2;
|
|
6084
6117
|
exports.deliverLine = deliverLine;
|
|
6085
|
-
var
|
|
6118
|
+
var fs9 = __importStar(__require("fs"));
|
|
6086
6119
|
var net = __importStar(__require("net"));
|
|
6087
6120
|
var os4 = __importStar(__require("os"));
|
|
6088
|
-
var
|
|
6121
|
+
var path8 = __importStar(__require("path"));
|
|
6089
6122
|
var hookSet_1 = require_hookSet();
|
|
6090
6123
|
var saverHandoff_1 = require_saverHandoff();
|
|
6091
6124
|
var WRITE_TIMEOUT_MS = 50;
|
|
@@ -6098,9 +6131,9 @@ var require_liveBus = __commonJS({
|
|
|
6098
6131
|
return [override];
|
|
6099
6132
|
const home = os4.homedir();
|
|
6100
6133
|
return [
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6134
|
+
path8.join(home, ".ascenda", "live.sock"),
|
|
6135
|
+
path8.join(home, "Library", "Containers", APP_BUNDLE_ID, "Data", ".ascenda", "live.sock"),
|
|
6136
|
+
path8.join(home, "Library", "Containers", exports.SAVER_HOST_BUNDLE_ID, "Data", "l.sock")
|
|
6104
6137
|
];
|
|
6105
6138
|
}
|
|
6106
6139
|
function existingSocketCandidates() {
|
|
@@ -6109,7 +6142,7 @@ var require_liveBus = __commonJS({
|
|
|
6109
6142
|
return candidates;
|
|
6110
6143
|
return candidates.filter((candidate) => {
|
|
6111
6144
|
try {
|
|
6112
|
-
return
|
|
6145
|
+
return fs9.statSync(candidate).isSocket();
|
|
6113
6146
|
} catch {
|
|
6114
6147
|
return false;
|
|
6115
6148
|
}
|
|
@@ -6639,9 +6672,9 @@ var require_cliAgentSetup = __commonJS({
|
|
|
6639
6672
|
exports.findStaleHookCommands = findStaleHookCommands2;
|
|
6640
6673
|
exports.cliAgentRegistrations = cliAgentRegistrations;
|
|
6641
6674
|
var crypto2 = __importStar(__require("crypto"));
|
|
6642
|
-
var
|
|
6675
|
+
var fs9 = __importStar(__require("fs"));
|
|
6643
6676
|
var os4 = __importStar(__require("os"));
|
|
6644
|
-
var
|
|
6677
|
+
var path8 = __importStar(__require("path"));
|
|
6645
6678
|
var collectorVersion_1 = require_collectorVersion();
|
|
6646
6679
|
var releaseCheck_1 = require_releaseCheck();
|
|
6647
6680
|
var credentials_1 = require_credentials();
|
|
@@ -6823,7 +6856,7 @@ ${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName:
|
|
|
6823
6856
|
return 0;
|
|
6824
6857
|
}
|
|
6825
6858
|
function isHomeProject2(options) {
|
|
6826
|
-
return options.scope === "project" &&
|
|
6859
|
+
return options.scope === "project" && path8.resolve(options.projectDir) === path8.resolve(os4.homedir());
|
|
6827
6860
|
}
|
|
6828
6861
|
function parseArgs2(argv, spec) {
|
|
6829
6862
|
const options = {
|
|
@@ -6878,7 +6911,7 @@ ${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName:
|
|
|
6878
6911
|
break;
|
|
6879
6912
|
}
|
|
6880
6913
|
case "--project-dir":
|
|
6881
|
-
options.projectDir =
|
|
6914
|
+
options.projectDir = path8.resolve(next());
|
|
6882
6915
|
break;
|
|
6883
6916
|
case "--dry-run":
|
|
6884
6917
|
options.dryRun = true;
|
|
@@ -7041,9 +7074,9 @@ Pairing ${status.status}. Run setup again.`);
|
|
|
7041
7074
|
}
|
|
7042
7075
|
function writeHookSettings(settingsFile, binary, spec, dryRun) {
|
|
7043
7076
|
let settings = { ...spec.settings.scaffold ?? {} };
|
|
7044
|
-
const exists =
|
|
7077
|
+
const exists = fs9.existsSync(settingsFile);
|
|
7045
7078
|
if (exists && !spec.settings.owned) {
|
|
7046
|
-
const raw =
|
|
7079
|
+
const raw = fs9.readFileSync(settingsFile, "utf8").trim();
|
|
7047
7080
|
if (raw) {
|
|
7048
7081
|
try {
|
|
7049
7082
|
settings = JSON.parse(raw);
|
|
@@ -7062,7 +7095,7 @@ ${settingsFile} is not valid JSON. Fix or move it, then run setup again.`);
|
|
|
7062
7095
|
const updated = { ...settings, hooks };
|
|
7063
7096
|
const serialised = `${JSON.stringify(updated, null, 2)}
|
|
7064
7097
|
`;
|
|
7065
|
-
if (exists &&
|
|
7098
|
+
if (exists && fs9.readFileSync(settingsFile, "utf8") === serialised)
|
|
7066
7099
|
return false;
|
|
7067
7100
|
if (dryRun) {
|
|
7068
7101
|
console.log(`
|
|
@@ -7071,7 +7104,7 @@ ${serialised}`);
|
|
|
7071
7104
|
return true;
|
|
7072
7105
|
}
|
|
7073
7106
|
if (spec.settings.owned) {
|
|
7074
|
-
|
|
7107
|
+
fs9.mkdirSync(path8.dirname(settingsFile), { recursive: true });
|
|
7075
7108
|
(0, hookRunner_1.writeAtomically)(settingsFile, serialised, 420);
|
|
7076
7109
|
return true;
|
|
7077
7110
|
}
|
|
@@ -7215,7 +7248,7 @@ ${serialised}`);
|
|
|
7215
7248
|
}
|
|
7216
7249
|
function readSettings(settingsFile) {
|
|
7217
7250
|
try {
|
|
7218
|
-
return JSON.parse(
|
|
7251
|
+
return JSON.parse(fs9.readFileSync(settingsFile, "utf8"));
|
|
7219
7252
|
} catch {
|
|
7220
7253
|
return {};
|
|
7221
7254
|
}
|
|
@@ -7234,7 +7267,7 @@ ${serialised}`);
|
|
|
7234
7267
|
console.log(`pairing ${credentials?.toolInstallationId ?? "\u2014 not paired"}${localOnly ? " (installed, not paired \u2014 local features active, telemetry inactive)" : ""}`);
|
|
7235
7268
|
console.log(`token ${localOnly ? "\u2014 none needed until this install is paired" : tokenFile && (0, tokenStore_1.readTokenFile)(tokenFile) ? "present" : "\u2014 missing"}`);
|
|
7236
7269
|
console.log(`event log ${(0, eventLog_1.describeEventLog)((0, eventLog_1.resolveEventLog)({ localOnly }), `npx ${spec.packageName} setup`)}`);
|
|
7237
|
-
console.log(`hook binary ${
|
|
7270
|
+
console.log(`hook binary ${fs9.existsSync(binary) ? binary : "\u2014 not installed"}`);
|
|
7238
7271
|
console.log(`latest ${(0, releaseCheck_1.describeReleaseCheck)({
|
|
7239
7272
|
installed: (0, releaseCheck_1.installedBundleVersion)((0, hookRunner_1.hookRunnerPaths)(spec.binaryName).version) ?? collectorVersion_1.COLLECTOR_VERSION,
|
|
7240
7273
|
setupCommand: `npx -y ${spec.packageName} setup`,
|
|
@@ -7286,7 +7319,7 @@ ${serialised}`);
|
|
|
7286
7319
|
await notices.markShown();
|
|
7287
7320
|
const paired = localOnly || credentials?.toolInstallationId !== void 0;
|
|
7288
7321
|
const wired = registered === spec.hookEvents.length || options.scope === "project" && elsewhere === spec.hookEvents.length;
|
|
7289
|
-
const healthy = paired && wired &&
|
|
7322
|
+
const healthy = paired && wired && fs9.existsSync(binary) && !stale.length && !node?.problem && trustLines.length === 0;
|
|
7290
7323
|
return healthy ? 0 : 1;
|
|
7291
7324
|
}
|
|
7292
7325
|
function countRegistered2(settings, spec) {
|
|
@@ -7307,7 +7340,7 @@ ${serialised}`);
|
|
|
7307
7340
|
file: (0, hookRunner_1.tidyHomePath)(file, home),
|
|
7308
7341
|
registered,
|
|
7309
7342
|
scope,
|
|
7310
|
-
homeProject: scope === "project" &&
|
|
7343
|
+
homeProject: scope === "project" && path8.resolve(projectDir) === path8.resolve(home)
|
|
7311
7344
|
});
|
|
7312
7345
|
}
|
|
7313
7346
|
return found;
|
|
@@ -7396,14 +7429,14 @@ ${serialised}`);
|
|
|
7396
7429
|
];
|
|
7397
7430
|
}
|
|
7398
7431
|
function removeOurHookEntries(settingsFile, spec) {
|
|
7399
|
-
if (!
|
|
7432
|
+
if (!fs9.existsSync(settingsFile))
|
|
7400
7433
|
return true;
|
|
7401
7434
|
if (spec.settings.owned) {
|
|
7402
|
-
|
|
7435
|
+
fs9.rmSync(settingsFile, { force: true });
|
|
7403
7436
|
return true;
|
|
7404
7437
|
}
|
|
7405
7438
|
try {
|
|
7406
|
-
const settings = JSON.parse(
|
|
7439
|
+
const settings = JSON.parse(fs9.readFileSync(settingsFile, "utf8"));
|
|
7407
7440
|
const hooks = { ...settings.hooks ?? {} };
|
|
7408
7441
|
for (const event of Object.keys(hooks)) {
|
|
7409
7442
|
const kept = withoutOurEntries2(hooks[event], spec);
|
|
@@ -7424,7 +7457,7 @@ ${serialised}`);
|
|
|
7424
7457
|
}
|
|
7425
7458
|
function uninstall2(options, spec) {
|
|
7426
7459
|
const settingsFile = spec.settings.settingsPath(options.scope, options.projectDir);
|
|
7427
|
-
if (
|
|
7460
|
+
if (fs9.existsSync(settingsFile)) {
|
|
7428
7461
|
if (!removeOurHookEntries(settingsFile, spec)) {
|
|
7429
7462
|
console.error(`could not parse ${settingsFile} \u2014 remove the ascenda hook entries by hand`);
|
|
7430
7463
|
return 1;
|
|
@@ -7439,7 +7472,7 @@ ${serialised}`);
|
|
|
7439
7472
|
(0, credentials_1.removeHostCredentials)(spec.host);
|
|
7440
7473
|
console.log(`removed tools.${spec.host} from ${(0, credentials_1.credentialsFilePath)()}`);
|
|
7441
7474
|
}
|
|
7442
|
-
console.log(`tokens left in ${
|
|
7475
|
+
console.log(`tokens left in ${path8.join((0, tokenStore_1.ascendaHome)(), "tokens")} \u2014 revoke in the Ascenda app to invalidate them`);
|
|
7443
7476
|
return 0;
|
|
7444
7477
|
}
|
|
7445
7478
|
}
|
|
@@ -7491,14 +7524,14 @@ var require_turnState = __commonJS({
|
|
|
7491
7524
|
exports.readTurnPromptId = readTurnPromptId;
|
|
7492
7525
|
exports.consumeTurnDurationMs = consumeTurnDurationMs;
|
|
7493
7526
|
var crypto_1 = __require("crypto");
|
|
7494
|
-
var
|
|
7495
|
-
var
|
|
7527
|
+
var fs9 = __importStar(__require("fs"));
|
|
7528
|
+
var path8 = __importStar(__require("path"));
|
|
7496
7529
|
var tokenStore_1 = require_tokenStore();
|
|
7497
|
-
var
|
|
7530
|
+
var stateDir2 = () => process.env.ASCENDA_STATE_DIR ?? path8.join((0, tokenStore_1.ascendaHome)(), "state");
|
|
7498
7531
|
function turnFile(agent, sessionId) {
|
|
7499
|
-
return
|
|
7532
|
+
return path8.join(stateDir2(), `${sanitize2(agent)}-turn-${sanitize2(sessionId)}`);
|
|
7500
7533
|
}
|
|
7501
|
-
function
|
|
7534
|
+
function sanitize2(value) {
|
|
7502
7535
|
return value.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
7503
7536
|
}
|
|
7504
7537
|
function recordTurnStart(agent, sessionId, now = Date.now()) {
|
|
@@ -7506,8 +7539,8 @@ var require_turnState = __commonJS({
|
|
|
7506
7539
|
return void 0;
|
|
7507
7540
|
try {
|
|
7508
7541
|
const promptId = (0, crypto_1.randomUUID)();
|
|
7509
|
-
|
|
7510
|
-
|
|
7542
|
+
fs9.mkdirSync(stateDir2(), { recursive: true });
|
|
7543
|
+
fs9.writeFileSync(turnFile(agent, sessionId), `${now} ${promptId}`, { encoding: "utf8", mode: 384 });
|
|
7511
7544
|
return promptId;
|
|
7512
7545
|
} catch {
|
|
7513
7546
|
return void 0;
|
|
@@ -7517,7 +7550,7 @@ var require_turnState = __commonJS({
|
|
|
7517
7550
|
if (!sessionId)
|
|
7518
7551
|
return void 0;
|
|
7519
7552
|
try {
|
|
7520
|
-
const id =
|
|
7553
|
+
const id = fs9.readFileSync(turnFile(agent, sessionId), "utf8").trim().split(/\s+/)[1];
|
|
7521
7554
|
return id && /^[A-Za-z0-9_-]{1,128}$/.test(id) ? id : void 0;
|
|
7522
7555
|
} catch {
|
|
7523
7556
|
return void 0;
|
|
@@ -7528,8 +7561,8 @@ var require_turnState = __commonJS({
|
|
|
7528
7561
|
return void 0;
|
|
7529
7562
|
const file = turnFile(agent, sessionId);
|
|
7530
7563
|
try {
|
|
7531
|
-
const started = Number(
|
|
7532
|
-
|
|
7564
|
+
const started = Number(fs9.readFileSync(file, "utf8").trim().split(/\s+/)[0]);
|
|
7565
|
+
fs9.rmSync(file, { force: true });
|
|
7533
7566
|
if (!Number.isFinite(started) || started <= 0 || started > now)
|
|
7534
7567
|
return void 0;
|
|
7535
7568
|
return now - started;
|
|
@@ -7585,21 +7618,21 @@ var require_effortState = __commonJS({
|
|
|
7585
7618
|
exports.readSentEffortLevel = readSentEffortLevel2;
|
|
7586
7619
|
exports.recordSentEffortLevel = recordSentEffortLevel2;
|
|
7587
7620
|
exports.clearSentEffortLevel = clearSentEffortLevel2;
|
|
7588
|
-
var
|
|
7589
|
-
var
|
|
7621
|
+
var fs9 = __importStar(__require("fs"));
|
|
7622
|
+
var path8 = __importStar(__require("path"));
|
|
7590
7623
|
var tokenStore_1 = require_tokenStore();
|
|
7591
|
-
var
|
|
7624
|
+
var stateDir2 = () => process.env.ASCENDA_STATE_DIR ?? path8.join((0, tokenStore_1.ascendaHome)(), "state");
|
|
7592
7625
|
function effortFile(agent, sessionId) {
|
|
7593
|
-
return
|
|
7626
|
+
return path8.join(stateDir2(), `${sanitize2(agent)}-effort-${sanitize2(sessionId)}`);
|
|
7594
7627
|
}
|
|
7595
|
-
function
|
|
7628
|
+
function sanitize2(value) {
|
|
7596
7629
|
return value.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
7597
7630
|
}
|
|
7598
7631
|
function readSentEffortLevel2(agent, sessionId) {
|
|
7599
7632
|
if (!sessionId)
|
|
7600
7633
|
return void 0;
|
|
7601
7634
|
try {
|
|
7602
|
-
const level =
|
|
7635
|
+
const level = fs9.readFileSync(effortFile(agent, sessionId), "utf8").trim();
|
|
7603
7636
|
return level || void 0;
|
|
7604
7637
|
} catch {
|
|
7605
7638
|
return void 0;
|
|
@@ -7609,8 +7642,8 @@ var require_effortState = __commonJS({
|
|
|
7609
7642
|
if (!sessionId || !level)
|
|
7610
7643
|
return;
|
|
7611
7644
|
try {
|
|
7612
|
-
|
|
7613
|
-
|
|
7645
|
+
fs9.mkdirSync(stateDir2(), { recursive: true });
|
|
7646
|
+
fs9.writeFileSync(effortFile(agent, sessionId), level, { encoding: "utf8", mode: 384 });
|
|
7614
7647
|
} catch {
|
|
7615
7648
|
}
|
|
7616
7649
|
}
|
|
@@ -7618,9 +7651,105 @@ var require_effortState = __commonJS({
|
|
|
7618
7651
|
if (!sessionId)
|
|
7619
7652
|
return;
|
|
7620
7653
|
try {
|
|
7621
|
-
|
|
7654
|
+
fs9.rmSync(effortFile(agent, sessionId), { force: true });
|
|
7655
|
+
} catch {
|
|
7656
|
+
}
|
|
7657
|
+
}
|
|
7658
|
+
}
|
|
7659
|
+
});
|
|
7660
|
+
|
|
7661
|
+
// ../packages/tool-kit/out/accountKey.js
|
|
7662
|
+
var require_accountKey = __commonJS({
|
|
7663
|
+
"../packages/tool-kit/out/accountKey.js"(exports) {
|
|
7664
|
+
"use strict";
|
|
7665
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
7666
|
+
if (k2 === void 0) k2 = k;
|
|
7667
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7668
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7669
|
+
desc = { enumerable: true, get: function() {
|
|
7670
|
+
return m[k];
|
|
7671
|
+
} };
|
|
7672
|
+
}
|
|
7673
|
+
Object.defineProperty(o, k2, desc);
|
|
7674
|
+
} : function(o, m, k, k2) {
|
|
7675
|
+
if (k2 === void 0) k2 = k;
|
|
7676
|
+
o[k2] = m[k];
|
|
7677
|
+
});
|
|
7678
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
7679
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
7680
|
+
} : function(o, v) {
|
|
7681
|
+
o["default"] = v;
|
|
7682
|
+
});
|
|
7683
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
7684
|
+
var ownKeys = function(o) {
|
|
7685
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
7686
|
+
var ar = [];
|
|
7687
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
7688
|
+
return ar;
|
|
7689
|
+
};
|
|
7690
|
+
return ownKeys(o);
|
|
7691
|
+
};
|
|
7692
|
+
return function(mod) {
|
|
7693
|
+
if (mod && mod.__esModule) return mod;
|
|
7694
|
+
var result = {};
|
|
7695
|
+
if (mod != null) {
|
|
7696
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
7697
|
+
}
|
|
7698
|
+
__setModuleDefault(result, mod);
|
|
7699
|
+
return result;
|
|
7700
|
+
};
|
|
7701
|
+
}();
|
|
7702
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7703
|
+
exports.ACCOUNT_KEY_VERSION = void 0;
|
|
7704
|
+
exports.readPlanTier = readPlanTier;
|
|
7705
|
+
exports.deriveAccountKey = deriveAccountKey2;
|
|
7706
|
+
exports.extraClaudeProfileDirs = extraClaudeProfileDirs2;
|
|
7707
|
+
var fs9 = __importStar(__require("fs"));
|
|
7708
|
+
var os4 = __importStar(__require("os"));
|
|
7709
|
+
var path8 = __importStar(__require("path"));
|
|
7710
|
+
var salt_1 = require_salt();
|
|
7711
|
+
exports.ACCOUNT_KEY_VERSION = "account-v1";
|
|
7712
|
+
function readPlanTier(configDir, home = os4.homedir(), env = process.env) {
|
|
7713
|
+
const isDefault = path8.resolve(configDir) === path8.join(home, ".claude") && !env.CLAUDE_CONFIG_DIR?.trim();
|
|
7714
|
+
const candidates = isDefault ? [path8.join(home, ".claude.json"), path8.join(configDir, ".claude.json")] : [path8.join(configDir, ".claude.json")];
|
|
7715
|
+
for (const file of candidates) {
|
|
7716
|
+
try {
|
|
7717
|
+
const parsed = JSON.parse(fs9.readFileSync(file, "utf8"));
|
|
7718
|
+
const account = parsed?.oauthAccount;
|
|
7719
|
+
const tier = account?.organizationRateLimitTier;
|
|
7720
|
+
if (typeof tier === "string" && tier.length <= 64)
|
|
7721
|
+
return tier.trim();
|
|
7722
|
+
} catch {
|
|
7723
|
+
}
|
|
7724
|
+
}
|
|
7725
|
+
return "";
|
|
7726
|
+
}
|
|
7727
|
+
function deriveAccountKey2(configDir, home = os4.homedir(), env = process.env, saltFilePath) {
|
|
7728
|
+
const first = env.CLAUDE_CONFIG_DIR?.split(",")[0]?.trim();
|
|
7729
|
+
const dir = path8.resolve(configDir ?? (first ? first : path8.join(home, ".claude")));
|
|
7730
|
+
const tier = readPlanTier(dir, home, env);
|
|
7731
|
+
try {
|
|
7732
|
+
return (0, salt_1.hashWithMachineSalt)(`${exports.ACCOUNT_KEY_VERSION}
|
|
7733
|
+
${dir}
|
|
7734
|
+
${tier}`, saltFilePath) ?? void 0;
|
|
7735
|
+
} catch {
|
|
7736
|
+
return void 0;
|
|
7737
|
+
}
|
|
7738
|
+
}
|
|
7739
|
+
function extraClaudeProfileDirs2(home = os4.homedir()) {
|
|
7740
|
+
let names;
|
|
7741
|
+
try {
|
|
7742
|
+
names = fs9.readdirSync(home, { withFileTypes: true }).filter((e) => (e.isDirectory() || e.isSymbolicLink()) && e.name.startsWith(".claude-")).map((e) => e.name).sort();
|
|
7622
7743
|
} catch {
|
|
7744
|
+
return [];
|
|
7623
7745
|
}
|
|
7746
|
+
return names.map((name) => path8.join(home, name)).filter((dir) => {
|
|
7747
|
+
try {
|
|
7748
|
+
return fs9.statSync(path8.join(dir, "projects")).isDirectory();
|
|
7749
|
+
} catch {
|
|
7750
|
+
return false;
|
|
7751
|
+
}
|
|
7752
|
+
});
|
|
7624
7753
|
}
|
|
7625
7754
|
}
|
|
7626
7755
|
});
|
|
@@ -8059,30 +8188,30 @@ var require_pluginBundle = __commonJS({
|
|
|
8059
8188
|
exports.pluginBundlePaths = pluginBundlePaths2;
|
|
8060
8189
|
exports.installPluginBundle = installPluginBundle2;
|
|
8061
8190
|
exports.describePluginBundleOutcome = describePluginBundleOutcome2;
|
|
8062
|
-
var
|
|
8063
|
-
var
|
|
8191
|
+
var fs9 = __importStar(__require("fs"));
|
|
8192
|
+
var path8 = __importStar(__require("path"));
|
|
8064
8193
|
var collectorVersion_1 = require_collectorVersion();
|
|
8065
8194
|
var hookRunner_1 = require_hookRunner();
|
|
8066
8195
|
var tokenStore_1 = require_tokenStore();
|
|
8067
8196
|
function pluginBundlePaths2(name) {
|
|
8068
|
-
const base =
|
|
8197
|
+
const base = path8.join((0, tokenStore_1.ascendaHome)(), "plugin", name);
|
|
8069
8198
|
return { bundle: `${base}.mjs`, version: `${base}.version`, checked: `${base}.checked` };
|
|
8070
8199
|
}
|
|
8071
8200
|
function installPluginBundle2(options) {
|
|
8072
8201
|
const paths = pluginBundlePaths2(options.name);
|
|
8073
|
-
const source =
|
|
8202
|
+
const source = path8.resolve(options.source ?? process.argv[1]);
|
|
8074
8203
|
const incoming = options.version ?? collectorVersion_1.COLLECTOR_VERSION;
|
|
8075
8204
|
const installed = readVersion(paths.version);
|
|
8076
|
-
const present =
|
|
8077
|
-
if (source ===
|
|
8205
|
+
const present = fs9.existsSync(paths.bundle);
|
|
8206
|
+
if (source === path8.resolve(paths.bundle))
|
|
8078
8207
|
return { kind: "current", version: installed ?? incoming };
|
|
8079
8208
|
if (present && installed && (0, hookRunner_1.isDowngrade)(installed, incoming))
|
|
8080
8209
|
return { kind: "kept-newer", installed, incoming };
|
|
8081
|
-
const contents =
|
|
8082
|
-
if (present && installed === incoming && contents.equals(
|
|
8210
|
+
const contents = fs9.readFileSync(source);
|
|
8211
|
+
if (present && installed === incoming && contents.equals(fs9.readFileSync(paths.bundle))) {
|
|
8083
8212
|
return { kind: "current", version: incoming };
|
|
8084
8213
|
}
|
|
8085
|
-
|
|
8214
|
+
fs9.mkdirSync(path8.dirname(paths.bundle), { recursive: true });
|
|
8086
8215
|
(0, hookRunner_1.writeAtomically)(paths.bundle, contents, 420);
|
|
8087
8216
|
(0, hookRunner_1.writeAtomically)(paths.version, `${incoming}
|
|
8088
8217
|
`, 420);
|
|
@@ -8100,7 +8229,7 @@ var require_pluginBundle = __commonJS({
|
|
|
8100
8229
|
}
|
|
8101
8230
|
function readVersion(file) {
|
|
8102
8231
|
try {
|
|
8103
|
-
return
|
|
8232
|
+
return fs9.readFileSync(file, "utf8").trim() || void 0;
|
|
8104
8233
|
} catch {
|
|
8105
8234
|
return void 0;
|
|
8106
8235
|
}
|
|
@@ -8150,20 +8279,21 @@ var require_agentProcess = __commonJS({
|
|
|
8150
8279
|
};
|
|
8151
8280
|
}();
|
|
8152
8281
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8153
|
-
exports.psArgsLookup = exports.psLookup = exports.AGENT_PROCESS = void 0;
|
|
8282
|
+
exports.psStartLookup = exports.psArgsLookup = exports.psLookup = exports.AGENT_PROCESS = void 0;
|
|
8154
8283
|
exports.scriptMarkerIn = scriptMarkerIn;
|
|
8284
|
+
exports.probeProcess = probeProcess;
|
|
8155
8285
|
exports.findAgentProcess = findAgentProcess2;
|
|
8156
8286
|
exports.findAgentPid = findAgentPid;
|
|
8157
8287
|
exports.livePidFields = livePidFields2;
|
|
8158
8288
|
var child_process_1 = __require("child_process");
|
|
8159
|
-
var
|
|
8289
|
+
var path8 = __importStar(__require("path"));
|
|
8160
8290
|
exports.AGENT_PROCESS = {
|
|
8161
8291
|
claude_code: {
|
|
8162
|
-
executable: (command) =>
|
|
8292
|
+
executable: (command) => path8.basename(command) === "claude" || /\/claude\/versions\/[^/]+$/.test(command) || /\/@anthropic-ai\/claude-code\/bin\/claude\.exe$/.test(command),
|
|
8163
8293
|
scriptMarkers: ["@anthropic-ai/claude-code"]
|
|
8164
8294
|
},
|
|
8165
8295
|
codex: {
|
|
8166
|
-
executable: (command) => /^codex(-(aarch64|x86_64)-apple-darwin)?$/.test(
|
|
8296
|
+
executable: (command) => /^codex(-(aarch64|x86_64)-apple-darwin)?$/.test(path8.basename(command)),
|
|
8167
8297
|
args: (args) => !/\s(app-server|mcp-server)(\s|$)/.test(args)
|
|
8168
8298
|
},
|
|
8169
8299
|
gemini_cli: {
|
|
@@ -8200,6 +8330,39 @@ var require_agentProcess = __commonJS({
|
|
|
8200
8330
|
exports.psLookup = psLookup;
|
|
8201
8331
|
var psArgsLookup = (pid) => ps("args=", pid);
|
|
8202
8332
|
exports.psArgsLookup = psArgsLookup;
|
|
8333
|
+
var psStartLookup = (pid) => {
|
|
8334
|
+
if (process.platform === "win32")
|
|
8335
|
+
return void 0;
|
|
8336
|
+
const line = ps("lstart=", pid);
|
|
8337
|
+
const ms = line ? Date.parse(line) : NaN;
|
|
8338
|
+
return Number.isFinite(ms) ? ms : void 0;
|
|
8339
|
+
};
|
|
8340
|
+
exports.psStartLookup = psStartLookup;
|
|
8341
|
+
var START_TOLERANCE_MS = 2e3;
|
|
8342
|
+
function probeProcess(pid, startedAt, options = {}) {
|
|
8343
|
+
if ((options.platform ?? process.platform) === "win32")
|
|
8344
|
+
return "unknown";
|
|
8345
|
+
if (!Number.isInteger(pid) || pid <= 1)
|
|
8346
|
+
return "unknown";
|
|
8347
|
+
const kill = options.kill ?? ((p, sig) => {
|
|
8348
|
+
process.kill(p, sig);
|
|
8349
|
+
});
|
|
8350
|
+
try {
|
|
8351
|
+
kill(pid, 0);
|
|
8352
|
+
} catch (error) {
|
|
8353
|
+
const code = error?.code;
|
|
8354
|
+
if (code === "ESRCH")
|
|
8355
|
+
return "dead";
|
|
8356
|
+
if (code !== "EPERM")
|
|
8357
|
+
return "unknown";
|
|
8358
|
+
}
|
|
8359
|
+
if (startedAt === void 0)
|
|
8360
|
+
return "unknown";
|
|
8361
|
+
const now = (options.startLookup ?? exports.psStartLookup)(pid);
|
|
8362
|
+
if (now === void 0)
|
|
8363
|
+
return "unknown";
|
|
8364
|
+
return Math.abs(now - startedAt) > START_TOLERANCE_MS ? "dead" : "alive";
|
|
8365
|
+
}
|
|
8203
8366
|
function findAgentProcess2(rule, options = {}) {
|
|
8204
8367
|
if (!rule)
|
|
8205
8368
|
return void 0;
|
|
@@ -8215,13 +8378,13 @@ var require_agentProcess = __commonJS({
|
|
|
8215
8378
|
return void 0;
|
|
8216
8379
|
if (pid !== process.pid) {
|
|
8217
8380
|
if (rule.executable(info.command)) {
|
|
8218
|
-
return accepts(rule, rule.args ? argsLookup(pid) : "") ? { pid, match: "executable" } : void 0;
|
|
8381
|
+
return accepts(rule, rule.args ? argsLookup(pid) : "") ? { pid, match: "executable", ...startField(pid, options) } : void 0;
|
|
8219
8382
|
}
|
|
8220
|
-
if (markers.length > 0 && SCRIPT_RUNTIME.test(
|
|
8383
|
+
if (markers.length > 0 && SCRIPT_RUNTIME.test(path8.basename(info.command))) {
|
|
8221
8384
|
const args = argsLookup(pid);
|
|
8222
8385
|
const marker = args === void 0 ? void 0 : scriptMarkerIn(args, markers);
|
|
8223
8386
|
if (marker !== void 0) {
|
|
8224
|
-
return accepts(rule, args) ? { pid, match: "path", marker } : void 0;
|
|
8387
|
+
return accepts(rule, args) ? { pid, match: "path", marker, ...startField(pid, options) } : void 0;
|
|
8225
8388
|
}
|
|
8226
8389
|
}
|
|
8227
8390
|
}
|
|
@@ -8229,6 +8392,10 @@ var require_agentProcess = __commonJS({
|
|
|
8229
8392
|
}
|
|
8230
8393
|
return void 0;
|
|
8231
8394
|
}
|
|
8395
|
+
function startField(pid, options) {
|
|
8396
|
+
const startedAt = (options.startLookup ?? exports.psStartLookup)(pid);
|
|
8397
|
+
return startedAt === void 0 ? {} : { startedAt };
|
|
8398
|
+
}
|
|
8232
8399
|
function accepts(rule, args) {
|
|
8233
8400
|
if (!rule.args)
|
|
8234
8401
|
return true;
|
|
@@ -8240,9 +8407,10 @@ var require_agentProcess = __commonJS({
|
|
|
8240
8407
|
function livePidFields2(match) {
|
|
8241
8408
|
if (!match)
|
|
8242
8409
|
return {};
|
|
8410
|
+
const start = match.startedAt === void 0 ? {} : { pidStartedAt: match.startedAt };
|
|
8243
8411
|
if (match.match === "executable")
|
|
8244
|
-
return { pid: match.pid };
|
|
8245
|
-
return { pid: match.pid, pidMatch: "path", pidMarker: match.marker };
|
|
8412
|
+
return { pid: match.pid, ...start };
|
|
8413
|
+
return { pid: match.pid, pidMatch: "path", pidMarker: match.marker, ...start };
|
|
8246
8414
|
}
|
|
8247
8415
|
}
|
|
8248
8416
|
});
|
|
@@ -8255,9 +8423,9 @@ var require_out3 = __commonJS({
|
|
|
8255
8423
|
exports.RELEASE_CHECK_ENV_VAR = exports.startBackgroundFlush = exports.runOutboxFlush = exports.hookDeliveryInline = exports.flushLockPath = exports.OUTBOX_FLUSH_COMMAND = exports.HOOK_DELIVERY_ENV_VAR = exports.FLUSH_LOCK_FRESH_MS = exports.describeCollectorVersion = exports.UNRELEASED_COLLECTOR_VERSION = exports.COLLECTOR_VERSION = exports.detectCollectorPlatform = exports.COLLECTOR_PLATFORM = 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.withModelOnChange = exports.modelFieldsFor = exports.clearSentModelId = exports.recordSentModelId = exports.readSentModelId = exports.claudeCodeModelRoute = exports.modelRouteFromCodexProvider = exports.modelRouteFromSlug = exports.classifyEffortClass = exports.isPremiumModelClass = exports.PREMIUM_MODEL_CLASSES = exports.classifyModelClass = exports.autonomyBand = exports.shellCommandFacts = exports.invitesDebrief = exports.classifyMcpWorkMilestone = exports.classifyWorkMilestone = exports.isReworkGitAction = exports.classifyGitAction = exports.isVerificationCommand = exports.classifyCommand = void 0;
|
|
8256
8424
|
exports.readHostCredentials = exports.isLocalOnlyHostInstall = exports.credentialsFilePath = exports.renderSetupDisclosure = exports.REFUSALS = exports.FREE_TEXT_KEYS = exports.FAMILY_SENTENCES = exports.ALWAYS_SENT = exports.writeHookSettings = exports.trustProblemLines = exports.runCliAgentSetup = exports.registeredHookSets = exports.ourHookPositions = exports.isCliAgentManagementCommand = exports.findStaleHookCommands = exports.cliAgentHookBinPath = exports.resolveContextHashes = exports.resolveCliAgentInstallationId = exports.withPromptId = exports.withForgeKeys = exports.loadCliAgentConfig = exports.flushHookOutbox = exports.deliverHookEvents = exports.MissingInstallationIdError = exports.DEFAULT_API_BASE_URL = exports.resolveEventLogPath = exports.resolveEventLog = exports.parseEventLogFlag = exports.expandUserPath = exports.describeEventLog = exports.defaultEventLogPath = exports.appendEventLog = exports.EVENT_LOG_OFF = exports.EVENT_LOG_ENV_VAR = exports.toAgentEvent = exports.buildEventPayload = exports.buildEventBody = exports.TOKEN_RENEW_LEAD_MS = exports.AscendaSemanticEventError = exports.AscendaEventSender = exports.runsFromInstalledBundle = exports.releaseStanding = exports.releaseCheckPath = exports.refreshReleaseCheck = exports.readReleaseCheck = exports.pendingReleaseNotice = exports.installedBundleVersion = exports.describeReleaseCheck = exports.compareReleases = exports.RELEASE_MANIFEST_URL = void 0;
|
|
8257
8425
|
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.recordSentEffortLevel = exports.readSentEffortLevel = exports.clearSentEffortLevel = exports.recordTurnStart = exports.readTurnPromptId = exports.consumeTurnDurationMs = exports.writeTopLevelCredentials = exports.writeMachineCredentials = exports.writeRepoKeysSetting = exports.writeEventLogSetting = exports.writeHostCredentials = exports.removeHostCredentials = exports.readMachineCredentials = void 0;
|
|
8258
|
-
exports.
|
|
8259
|
-
exports.
|
|
8260
|
-
exports.writePairingJoinOutcome = exports.settleStudyJoin = exports.pairingJoinOutcome = exports.pairingAttemptLines = exports.createPairingAttempt = exports.PAIR_ORG_JOIN_CODE_ENV = exports.PAIR_JOIN_OUTCOME_FILE_ENV = exports.studyJoinConfirmUrl = exports.pairingConfirmUrl = exports.pairingConfirmLines = exports.WEEKLY_POSTER_CONNECT_URL = exports.runStudyJoin = exports.gitOfferLine = exports.formatWindow = exports.describeStudyGrant = exports.describeStudyKind = void 0;
|
|
8426
|
+
exports.hookRunnerPaths = exports.hookRunnerCommand = exports.hookLauncherScript = exports.describeAge = exports.terminalStyle = exports.colourEnabled = exports.SAVER_REPLAY_WINDOW_MS = exports.saverSupportDir = exports.saverStatusDir = exports.saverReplayPath = exports.saverContainerDir = exports.readSaverStatuses = exports.probeSocket = exports.heldForSaver = exports.holdForSaver = exports.LIVE_BUS_BACKGROUND_TRUST_MS = exports.liveBusSocketCandidates = exports.liveBusSocketPath = exports.promptSizeMetadata = exports.bucketPromptSize = exports.deliverLine = exports.emitLiveSignal = exports.startSquadronJoin = exports.previewJoinCode = exports.SQUADRON_COLOURS = exports.SQUADRON_AIRCRAFT = exports.describeSquadronRefusal = exports.describeGate = exports.callsignProblem = exports.normaliseBookingReference = exports.generateCallsign = exports.leaseEnd = exports.runSquadronJoin = exports.repoKeysEnabled = exports.deriveForgeKeysForCwd = exports.REPO_KEYS_ENV_VAR = exports.ACCOUNT_KEY_VERSION = exports.readPlanTier = exports.extraClaudeProfileDirs = exports.deriveAccountKey = exports.recordForgeProjectAlias = exports.forgeFullNameFromConfig = exports.readForgeFullName = exports.parseForgeFullName = exports.forgeBranchKey = exports.forgeRepoKey = exports.forgeProjectHash = exports.workContextRegistryFilePath = exports.readWorkContextRegistry = exports.recordWorkContextAlias = void 0;
|
|
8427
|
+
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.psStartLookup = exports.psLookup = exports.psArgsLookup = exports.probeProcess = 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.liveSignalDoctorLines = exports.doctorRow = exports.DOCTOR_VALUE_COLUMN = exports.pluginBundlePaths = exports.installPluginBundle = exports.describePluginBundleOutcome = exports.replaceSettingsFile = exports.writeAtomically = exports.tidyHomePath = exports.stampLastHook = exports.resolveHookNode = exports.removeHookRunner = exports.readLastHook = exports.lastHookPath = exports.isDowngrade = exports.installHookRunner = void 0;
|
|
8428
|
+
exports.writePairingJoinOutcome = exports.settleStudyJoin = exports.pairingJoinOutcome = exports.pairingAttemptLines = exports.createPairingAttempt = exports.PAIR_ORG_JOIN_CODE_ENV = exports.PAIR_JOIN_OUTCOME_FILE_ENV = exports.studyJoinConfirmUrl = exports.pairingConfirmUrl = exports.pairingConfirmLines = exports.WEEKLY_POSTER_CONNECT_URL = exports.runStudyJoin = exports.gitOfferLine = exports.formatWindow = exports.describeStudyGrant = exports.describeStudyKind = exports.describeStudyJoinRefusal = exports.studyNoticeStatus = exports.runStudyObjection = exports.renderStudyNotices = exports.NOTICED_PURPOSES = exports.renderInitiatives = void 0;
|
|
8261
8429
|
var commandClassifier_1 = require_commandClassifier();
|
|
8262
8430
|
Object.defineProperty(exports, "classifyCommand", { enumerable: true, get: function() {
|
|
8263
8431
|
return commandClassifier_1.classifyCommand;
|
|
@@ -8771,6 +8939,19 @@ var require_out3 = __commonJS({
|
|
|
8771
8939
|
Object.defineProperty(exports, "recordForgeProjectAlias", { enumerable: true, get: function() {
|
|
8772
8940
|
return forgeProject_1.recordForgeProjectAlias;
|
|
8773
8941
|
} });
|
|
8942
|
+
var accountKey_1 = require_accountKey();
|
|
8943
|
+
Object.defineProperty(exports, "deriveAccountKey", { enumerable: true, get: function() {
|
|
8944
|
+
return accountKey_1.deriveAccountKey;
|
|
8945
|
+
} });
|
|
8946
|
+
Object.defineProperty(exports, "extraClaudeProfileDirs", { enumerable: true, get: function() {
|
|
8947
|
+
return accountKey_1.extraClaudeProfileDirs;
|
|
8948
|
+
} });
|
|
8949
|
+
Object.defineProperty(exports, "readPlanTier", { enumerable: true, get: function() {
|
|
8950
|
+
return accountKey_1.readPlanTier;
|
|
8951
|
+
} });
|
|
8952
|
+
Object.defineProperty(exports, "ACCOUNT_KEY_VERSION", { enumerable: true, get: function() {
|
|
8953
|
+
return accountKey_1.ACCOUNT_KEY_VERSION;
|
|
8954
|
+
} });
|
|
8774
8955
|
var forgeKeys_1 = require_forgeKeys();
|
|
8775
8956
|
Object.defineProperty(exports, "REPO_KEYS_ENV_VAR", { enumerable: true, get: function() {
|
|
8776
8957
|
return forgeKeys_1.REPO_KEYS_ENV_VAR;
|
|
@@ -8978,12 +9159,18 @@ var require_out3 = __commonJS({
|
|
|
8978
9159
|
Object.defineProperty(exports, "livePidFields", { enumerable: true, get: function() {
|
|
8979
9160
|
return agentProcess_1.livePidFields;
|
|
8980
9161
|
} });
|
|
9162
|
+
Object.defineProperty(exports, "probeProcess", { enumerable: true, get: function() {
|
|
9163
|
+
return agentProcess_1.probeProcess;
|
|
9164
|
+
} });
|
|
8981
9165
|
Object.defineProperty(exports, "psArgsLookup", { enumerable: true, get: function() {
|
|
8982
9166
|
return agentProcess_1.psArgsLookup;
|
|
8983
9167
|
} });
|
|
8984
9168
|
Object.defineProperty(exports, "psLookup", { enumerable: true, get: function() {
|
|
8985
9169
|
return agentProcess_1.psLookup;
|
|
8986
9170
|
} });
|
|
9171
|
+
Object.defineProperty(exports, "psStartLookup", { enumerable: true, get: function() {
|
|
9172
|
+
return agentProcess_1.psStartLookup;
|
|
9173
|
+
} });
|
|
8987
9174
|
Object.defineProperty(exports, "scriptMarkerIn", { enumerable: true, get: function() {
|
|
8988
9175
|
return agentProcess_1.scriptMarkerIn;
|
|
8989
9176
|
} });
|
|
@@ -9146,42 +9333,42 @@ var init_types = __esm({
|
|
|
9146
9333
|
});
|
|
9147
9334
|
|
|
9148
9335
|
// src/paths.ts
|
|
9149
|
-
import * as
|
|
9336
|
+
import * as fs2 from "fs";
|
|
9150
9337
|
import * as os from "os";
|
|
9151
|
-
import * as
|
|
9338
|
+
import * as path2 from "path";
|
|
9152
9339
|
function claudeConfigDir() {
|
|
9153
9340
|
const configured = process.env.CLAUDE_CONFIG_DIR?.trim();
|
|
9154
|
-
return configured ?
|
|
9341
|
+
return configured ? path2.resolve(configured) : path2.join(os.homedir(), ".claude");
|
|
9155
9342
|
}
|
|
9156
9343
|
function hookBinPath() {
|
|
9157
|
-
return
|
|
9344
|
+
return path2.join((0, import_tool_kit6.ascendaHome)(), "bin", "ascenda-claude-hook");
|
|
9158
9345
|
}
|
|
9159
9346
|
function hookBundlePath() {
|
|
9160
|
-
return
|
|
9347
|
+
return path2.join((0, import_tool_kit6.ascendaHome)(), "bin", "ascenda-claude-hook.mjs");
|
|
9161
9348
|
}
|
|
9162
9349
|
function hookNodeRecordPath() {
|
|
9163
|
-
return
|
|
9350
|
+
return path2.join((0, import_tool_kit6.ascendaHome)(), "bin", "ascenda-claude-hook.node");
|
|
9164
9351
|
}
|
|
9165
9352
|
function hookNoNodePath() {
|
|
9166
|
-
return
|
|
9353
|
+
return path2.join((0, import_tool_kit6.ascendaHome)(), "bin", "ascenda-claude-hook.no-node");
|
|
9167
9354
|
}
|
|
9168
9355
|
function readCredentials() {
|
|
9169
|
-
const credentials = (0,
|
|
9356
|
+
const credentials = (0, import_tool_kit6.readMachineCredentials)();
|
|
9170
9357
|
if (!credentials) return void 0;
|
|
9171
9358
|
const { tools: _tools, ...topLevel } = credentials;
|
|
9172
9359
|
return topLevel;
|
|
9173
9360
|
}
|
|
9174
9361
|
function writeCredentials(credentials) {
|
|
9175
|
-
(0,
|
|
9362
|
+
(0, import_tool_kit6.writeTopLevelCredentials)(credentials);
|
|
9176
9363
|
}
|
|
9177
9364
|
function removeCredentials() {
|
|
9178
|
-
const credentials = (0,
|
|
9365
|
+
const credentials = (0, import_tool_kit6.readMachineCredentials)();
|
|
9179
9366
|
if (!credentials) return;
|
|
9180
9367
|
if (credentials.tools && Object.keys(credentials.tools).length > 0) {
|
|
9181
|
-
(0,
|
|
9368
|
+
(0, import_tool_kit6.writeMachineCredentials)({ tools: credentials.tools });
|
|
9182
9369
|
return;
|
|
9183
9370
|
}
|
|
9184
|
-
|
|
9371
|
+
fs2.rmSync((0, import_tool_kit6.credentialsFilePath)(), { force: true });
|
|
9185
9372
|
}
|
|
9186
9373
|
function selfCommand() {
|
|
9187
9374
|
if (process.platform === "win32") return "npx @ascenda-one/claude-code-hooks";
|
|
@@ -9189,34 +9376,252 @@ function selfCommand() {
|
|
|
9189
9376
|
const bin = hookBinPath();
|
|
9190
9377
|
return bin.startsWith(`${home}/`) ? `~${bin.slice(home.length)}` : bin;
|
|
9191
9378
|
}
|
|
9192
|
-
var
|
|
9379
|
+
var import_tool_kit6, import_tool_kit7;
|
|
9193
9380
|
var init_paths = __esm({
|
|
9194
9381
|
"src/paths.ts"() {
|
|
9195
9382
|
"use strict";
|
|
9196
|
-
import_tool_kit5 = __toESM(require_out3(), 1);
|
|
9197
9383
|
import_tool_kit6 = __toESM(require_out3(), 1);
|
|
9384
|
+
import_tool_kit7 = __toESM(require_out3(), 1);
|
|
9385
|
+
}
|
|
9386
|
+
});
|
|
9387
|
+
|
|
9388
|
+
// src/usageLimitReset.ts
|
|
9389
|
+
import * as fs3 from "node:fs";
|
|
9390
|
+
import * as path3 from "node:path";
|
|
9391
|
+
function parseUsageLimitReset(text, now, localZone) {
|
|
9392
|
+
const piped = PIPE_EPOCH.exec(text);
|
|
9393
|
+
if (piped) {
|
|
9394
|
+
const raw = Number(piped[1]);
|
|
9395
|
+
return piped[1].length > 10 ? raw : raw * 1e3;
|
|
9396
|
+
}
|
|
9397
|
+
const match = RESET_CLAUSE.exec(text);
|
|
9398
|
+
if (!match) return void 0;
|
|
9399
|
+
const [, monthWord, dayText, hourText, minuteText, meridiem, zoneText] = match;
|
|
9400
|
+
const hour = to24Hour(Number(hourText), meridiem, minuteText !== void 0);
|
|
9401
|
+
if (hour === void 0) return void 0;
|
|
9402
|
+
const minute = minuteText === void 0 ? 0 : Number(minuteText);
|
|
9403
|
+
if (minute > 59) return void 0;
|
|
9404
|
+
const zone = zoneText?.trim() || localZone || Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
9405
|
+
const today = wallDate(now, zone);
|
|
9406
|
+
if (!today) return void 0;
|
|
9407
|
+
if (monthWord !== void 0) {
|
|
9408
|
+
const month = MONTHS.indexOf(monthWord.slice(0, 3).toLowerCase());
|
|
9409
|
+
if (month < 0 || !matchesMonthName(monthWord, month)) return void 0;
|
|
9410
|
+
const day = Number(dayText);
|
|
9411
|
+
if (day < 1 || day > 31) return void 0;
|
|
9412
|
+
let at = zonedToEpoch({ year: today.year, month: month + 1, day, hour, minute }, zone);
|
|
9413
|
+
if (at !== void 0 && at <= now.getTime()) {
|
|
9414
|
+
at = zonedToEpoch({ year: today.year + 1, month: month + 1, day, hour, minute }, zone);
|
|
9415
|
+
}
|
|
9416
|
+
return at;
|
|
9417
|
+
}
|
|
9418
|
+
const sameDay = zonedToEpoch({ ...today, hour, minute }, zone);
|
|
9419
|
+
if (sameDay === void 0) return void 0;
|
|
9420
|
+
if (sameDay > now.getTime()) return sameDay;
|
|
9421
|
+
return zonedToEpoch({ ...nextDay(today), hour, minute }, zone);
|
|
9422
|
+
}
|
|
9423
|
+
function resumesAtFor(text, now, localZone) {
|
|
9424
|
+
if (!text) return void 0;
|
|
9425
|
+
const at = parseUsageLimitReset(text, now, localZone);
|
|
9426
|
+
if (at === void 0) return void 0;
|
|
9427
|
+
const ahead = at - now.getTime();
|
|
9428
|
+
if (ahead <= 0 || ahead > MAX_RESUME_AHEAD_MS) return void 0;
|
|
9429
|
+
return Math.round(at / 6e4) * 60;
|
|
9430
|
+
}
|
|
9431
|
+
function to24Hour(hour, meridiem, hasMinutes) {
|
|
9432
|
+
if (meridiem === void 0) {
|
|
9433
|
+
if (!hasMinutes || hour > 23) return void 0;
|
|
9434
|
+
return hour;
|
|
9435
|
+
}
|
|
9436
|
+
if (hour < 1 || hour > 12) return void 0;
|
|
9437
|
+
const pm = meridiem.toLowerCase().startsWith("p");
|
|
9438
|
+
if (hour === 12) return pm ? 12 : 0;
|
|
9439
|
+
return pm ? hour + 12 : hour;
|
|
9440
|
+
}
|
|
9441
|
+
function matchesMonthName(word, month) {
|
|
9442
|
+
const full = new Date(Date.UTC(2e3, month, 1)).toLocaleString("en-US", { month: "long", timeZone: "UTC" }).toLowerCase();
|
|
9443
|
+
return full.startsWith(word.toLowerCase());
|
|
9444
|
+
}
|
|
9445
|
+
function wallDate(instant, zone) {
|
|
9446
|
+
const parts = wallParts(instant.getTime(), zone);
|
|
9447
|
+
return parts && { year: parts.year, month: parts.month, day: parts.day };
|
|
9448
|
+
}
|
|
9449
|
+
function nextDay(date) {
|
|
9450
|
+
const next = new Date(Date.UTC(date.year, date.month - 1, date.day + 1));
|
|
9451
|
+
return { year: next.getUTCFullYear(), month: next.getUTCMonth() + 1, day: next.getUTCDate() };
|
|
9452
|
+
}
|
|
9453
|
+
function wallParts(epochMs, zone) {
|
|
9454
|
+
let format;
|
|
9455
|
+
try {
|
|
9456
|
+
format = new Intl.DateTimeFormat("en-US", {
|
|
9457
|
+
timeZone: zone,
|
|
9458
|
+
hourCycle: "h23",
|
|
9459
|
+
year: "numeric",
|
|
9460
|
+
month: "numeric",
|
|
9461
|
+
day: "numeric",
|
|
9462
|
+
hour: "numeric",
|
|
9463
|
+
minute: "numeric"
|
|
9464
|
+
});
|
|
9465
|
+
} catch {
|
|
9466
|
+
return void 0;
|
|
9467
|
+
}
|
|
9468
|
+
const value = (type) => Number(format.formatToParts(epochMs).find((part) => part.type === type)?.value);
|
|
9469
|
+
return { year: value("year"), month: value("month"), day: value("day"), hour: value("hour"), minute: value("minute") };
|
|
9470
|
+
}
|
|
9471
|
+
function zonedToEpoch(time, zone) {
|
|
9472
|
+
const asUtc = Date.UTC(time.year, time.month - 1, time.day, time.hour, time.minute);
|
|
9473
|
+
const check = new Date(asUtc);
|
|
9474
|
+
if (check.getUTCDate() !== time.day) return void 0;
|
|
9475
|
+
let guess = asUtc;
|
|
9476
|
+
for (let pass = 0; pass < 2; pass += 1) {
|
|
9477
|
+
const seen = wallParts(guess, zone);
|
|
9478
|
+
if (!seen) return void 0;
|
|
9479
|
+
const seenUtc = Date.UTC(seen.year, seen.month - 1, seen.day, seen.hour, seen.minute);
|
|
9480
|
+
guess += asUtc - seenUtc;
|
|
9481
|
+
}
|
|
9482
|
+
return guess;
|
|
9483
|
+
}
|
|
9484
|
+
function managedSettingsPath() {
|
|
9485
|
+
if (process.env.ASCENDA_CLAUDE_MANAGED_SETTINGS) return process.env.ASCENDA_CLAUDE_MANAGED_SETTINGS;
|
|
9486
|
+
if (process.platform === "darwin") return "/Library/Application Support/ClaudeCode/managed-settings.json";
|
|
9487
|
+
if (process.platform === "win32") return "C:\\Program Files\\ClaudeCode\\managed-settings.json";
|
|
9488
|
+
return "/etc/claude-code/managed-settings.json";
|
|
9489
|
+
}
|
|
9490
|
+
function autoContinueEnabled(sources = {}) {
|
|
9491
|
+
const files = [
|
|
9492
|
+
sources.managedPath ?? managedSettingsPath(),
|
|
9493
|
+
...sources.projectDir ? [path3.join(sources.projectDir, ".claude", "settings.local.json"), path3.join(sources.projectDir, ".claude", "settings.json")] : [],
|
|
9494
|
+
path3.join(sources.configDir ?? claudeConfigDir(), "settings.json")
|
|
9495
|
+
];
|
|
9496
|
+
for (const file of files) {
|
|
9497
|
+
const value = readSetting(file, "autoContinueAtUsageLimit");
|
|
9498
|
+
if (value !== void 0) return value === true;
|
|
9499
|
+
}
|
|
9500
|
+
return false;
|
|
9501
|
+
}
|
|
9502
|
+
function readSetting(file, key) {
|
|
9503
|
+
try {
|
|
9504
|
+
const parsed = JSON.parse(fs3.readFileSync(file, "utf8"));
|
|
9505
|
+
if (parsed && typeof parsed === "object" && key in parsed) return parsed[key];
|
|
9506
|
+
} catch {
|
|
9507
|
+
}
|
|
9508
|
+
return void 0;
|
|
9509
|
+
}
|
|
9510
|
+
var MAX_RESUME_AHEAD_MS, MONTHS, RESET_CLAUSE, PIPE_EPOCH;
|
|
9511
|
+
var init_usageLimitReset = __esm({
|
|
9512
|
+
"src/usageLimitReset.ts"() {
|
|
9513
|
+
"use strict";
|
|
9514
|
+
init_paths();
|
|
9515
|
+
MAX_RESUME_AHEAD_MS = 6 * 60 * 60 * 1e3;
|
|
9516
|
+
MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
9517
|
+
RESET_CLAUSE = new RegExp(
|
|
9518
|
+
"\\bresets?(?:\\s+at)?\\s+(?:([a-z]{3,9})\\.?\\s+(\\d{1,2})(?:st|nd|rd|th)?,?\\s+(?:at\\s+)?)?(\\d{1,2})(?::(\\d{2}))?\\s*(am|pm|a\\.m\\.|p\\.m\\.)?(?:\\s*\\(([^)]+)\\))?",
|
|
9519
|
+
"i"
|
|
9520
|
+
);
|
|
9521
|
+
PIPE_EPOCH = /usage limit reached\|(\d{10,13})\b/i;
|
|
9522
|
+
}
|
|
9523
|
+
});
|
|
9524
|
+
|
|
9525
|
+
// src/quotaSnapshot.ts
|
|
9526
|
+
import * as fs4 from "node:fs";
|
|
9527
|
+
import * as path4 from "node:path";
|
|
9528
|
+
function quotaSnapshotPath() {
|
|
9529
|
+
return path4.join((0, import_tool_kit8.ascendaHome)(), "claude-quota.json");
|
|
9530
|
+
}
|
|
9531
|
+
function quotaFromStatusline(input, now = /* @__PURE__ */ new Date()) {
|
|
9532
|
+
const limits = field(input, "rate_limits");
|
|
9533
|
+
if (!limits) return void 0;
|
|
9534
|
+
const fiveHour = windowFrom(field(limits, "five_hour"));
|
|
9535
|
+
const sevenDay = windowFrom(field(limits, "seven_day"));
|
|
9536
|
+
if (!fiveHour && !sevenDay) return void 0;
|
|
9537
|
+
return {
|
|
9538
|
+
capturedAt: Math.floor(now.getTime() / 1e3),
|
|
9539
|
+
...fiveHour ? { fiveHour } : {},
|
|
9540
|
+
...sevenDay ? { sevenDay } : {}
|
|
9541
|
+
};
|
|
9542
|
+
}
|
|
9543
|
+
function field(value, key) {
|
|
9544
|
+
if (!value || typeof value !== "object") return void 0;
|
|
9545
|
+
const found = value[key];
|
|
9546
|
+
return found && typeof found === "object" ? found : void 0;
|
|
9547
|
+
}
|
|
9548
|
+
function windowFrom(raw) {
|
|
9549
|
+
if (!raw) return void 0;
|
|
9550
|
+
const used = raw.used_percentage;
|
|
9551
|
+
const resets = raw.resets_at;
|
|
9552
|
+
if (typeof used !== "number" || !Number.isFinite(used) || used < 0) return void 0;
|
|
9553
|
+
if (typeof resets !== "number" || !Number.isFinite(resets) || resets <= 0) return void 0;
|
|
9554
|
+
return { usedPercentage: used, resetsAt: Math.floor(resets) };
|
|
9555
|
+
}
|
|
9556
|
+
function recordQuota(snapshot, file = quotaSnapshotPath()) {
|
|
9557
|
+
try {
|
|
9558
|
+
const previous = readQuota(file);
|
|
9559
|
+
const unchanged = previous && sameWindow(previous.fiveHour, snapshot.fiveHour) && sameWindow(previous.sevenDay, snapshot.sevenDay);
|
|
9560
|
+
if (unchanged && snapshot.capturedAt - previous.capturedAt < REFRESH_SECONDS) return false;
|
|
9561
|
+
fs4.mkdirSync(path4.dirname(file), { recursive: true });
|
|
9562
|
+
(0, import_tool_kit8.writeAtomically)(file, `${JSON.stringify(snapshot)}
|
|
9563
|
+
`, 384);
|
|
9564
|
+
return true;
|
|
9565
|
+
} catch {
|
|
9566
|
+
return false;
|
|
9567
|
+
}
|
|
9568
|
+
}
|
|
9569
|
+
function sameWindow(a, b) {
|
|
9570
|
+
return a?.usedPercentage === b?.usedPercentage && a?.resetsAt === b?.resetsAt;
|
|
9571
|
+
}
|
|
9572
|
+
function readQuota(file = quotaSnapshotPath()) {
|
|
9573
|
+
try {
|
|
9574
|
+
const parsed = JSON.parse(fs4.readFileSync(file, "utf8"));
|
|
9575
|
+
if (!parsed || typeof parsed.capturedAt !== "number") return void 0;
|
|
9576
|
+
const fiveHour = storedWindow(parsed.fiveHour);
|
|
9577
|
+
const sevenDay = storedWindow(parsed.sevenDay);
|
|
9578
|
+
return { capturedAt: parsed.capturedAt, ...fiveHour ? { fiveHour } : {}, ...sevenDay ? { sevenDay } : {} };
|
|
9579
|
+
} catch {
|
|
9580
|
+
return void 0;
|
|
9581
|
+
}
|
|
9582
|
+
}
|
|
9583
|
+
function storedWindow(raw) {
|
|
9584
|
+
if (!raw || typeof raw !== "object") return void 0;
|
|
9585
|
+
const { usedPercentage, resetsAt } = raw;
|
|
9586
|
+
return windowFrom({ used_percentage: usedPercentage, resets_at: resetsAt });
|
|
9587
|
+
}
|
|
9588
|
+
function resumesAtFromQuota(snapshot, now) {
|
|
9589
|
+
if (!snapshot) return void 0;
|
|
9590
|
+
const nowSeconds = now.getTime() / 1e3;
|
|
9591
|
+
const exhausted = [snapshot.fiveHour, snapshot.sevenDay].filter((window) => window !== void 0 && window.usedPercentage >= 100 && window.resetsAt > nowSeconds);
|
|
9592
|
+
if (!exhausted.length) return void 0;
|
|
9593
|
+
const at = Math.max(...exhausted.map((window) => window.resetsAt));
|
|
9594
|
+
return at * 1e3 - now.getTime() <= MAX_RESUME_AHEAD_MS ? at : void 0;
|
|
9595
|
+
}
|
|
9596
|
+
var import_tool_kit8, REFRESH_SECONDS;
|
|
9597
|
+
var init_quotaSnapshot = __esm({
|
|
9598
|
+
"src/quotaSnapshot.ts"() {
|
|
9599
|
+
"use strict";
|
|
9600
|
+
import_tool_kit8 = __toESM(require_out3(), 1);
|
|
9601
|
+
init_usageLimitReset();
|
|
9602
|
+
REFRESH_SECONDS = 60;
|
|
9198
9603
|
}
|
|
9199
9604
|
});
|
|
9200
9605
|
|
|
9201
9606
|
// src/config.ts
|
|
9202
9607
|
function resolveOutboxFilePath(toolInstallationId) {
|
|
9203
|
-
return process.env.ASCENDA_OUTBOX_FILE ?? (0,
|
|
9608
|
+
return process.env.ASCENDA_OUTBOX_FILE ?? (0, import_tool_kit9.defaultOutboxFilePath)(toolInstallationId);
|
|
9204
9609
|
}
|
|
9205
9610
|
function resolveStateFilePath(toolInstallationId) {
|
|
9206
|
-
return process.env.ASCENDA_STATE_FILE ?? (toolInstallationId ? (0,
|
|
9611
|
+
return process.env.ASCENDA_STATE_FILE ?? (toolInstallationId ? (0, import_tool_kit9.defaultStateFilePath)(toolInstallationId) : (0, import_tool_kit9.unresolvedStateFilePath)(ASCENDA_TOOL_TYPE));
|
|
9207
9612
|
}
|
|
9208
9613
|
function localOnlyInstall(credentials = readCredentials()) {
|
|
9209
9614
|
if (!credentials?.localOnly) return false;
|
|
9210
9615
|
if (envOverride("ASCENDA_EVENT_WRITE_TOKEN")) return false;
|
|
9211
|
-
const tokenFilePath = process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (credentials.toolInstallationId ? (0,
|
|
9212
|
-
return !(tokenFilePath && (0,
|
|
9616
|
+
const tokenFilePath = process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (credentials.toolInstallationId ? (0, import_tool_kit9.defaultTokenFilePath)(credentials.toolInstallationId) : void 0);
|
|
9617
|
+
return !(tokenFilePath && (0, import_tool_kit9.readTokenFile)(tokenFilePath));
|
|
9213
9618
|
}
|
|
9214
9619
|
function resolveToolInstallationId(credentials = readCredentials()) {
|
|
9215
9620
|
const fromEnv = process.env.ASCENDA_TOOL_INSTALLATION_ID?.trim();
|
|
9216
9621
|
if (fromEnv) return { toolInstallationId: normalizeToolInstallationId(fromEnv), source: "env" };
|
|
9217
9622
|
const fromCredentials = credentials?.toolInstallationId?.trim();
|
|
9218
9623
|
if (fromCredentials) return { toolInstallationId: normalizeToolInstallationId(fromCredentials), source: "credentials" };
|
|
9219
|
-
const candidates = (0,
|
|
9624
|
+
const candidates = (0, import_tool_kit9.listPersistedToolInstallationIds)(ASCENDA_TOOL_TYPE);
|
|
9220
9625
|
if (candidates.length === 1) return { toolInstallationId: candidates[0], source: "disk" };
|
|
9221
9626
|
throw new MissingInstallationIdError(candidates);
|
|
9222
9627
|
}
|
|
@@ -9224,11 +9629,11 @@ function loadConfigFromEnv() {
|
|
|
9224
9629
|
const credentials = readCredentials();
|
|
9225
9630
|
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? credentials?.apiBaseUrl ?? DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
9226
9631
|
const { toolInstallationId } = resolveToolInstallationId(credentials);
|
|
9227
|
-
const tokenFilePath = process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0,
|
|
9228
|
-
const fileToken = (0,
|
|
9632
|
+
const tokenFilePath = process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0, import_tool_kit9.defaultTokenFilePath)(toolInstallationId);
|
|
9633
|
+
const fileToken = (0, import_tool_kit9.readTokenFile)(tokenFilePath);
|
|
9229
9634
|
const eventWriteToken = fileToken ?? process.env.ASCENDA_EVENT_WRITE_TOKEN;
|
|
9230
9635
|
if (!eventWriteToken) throw new Error("Missing ASCENDA_EVENT_WRITE_TOKEN (or token file)");
|
|
9231
|
-
if (!fileToken) (0,
|
|
9636
|
+
if (!fileToken) (0, import_tool_kit9.persistEventWriteToken)(tokenFilePath, eventWriteToken);
|
|
9232
9637
|
return {
|
|
9233
9638
|
apiBaseUrl,
|
|
9234
9639
|
toolInstallationId,
|
|
@@ -9266,11 +9671,11 @@ function normalizeToolInstallationId(value) {
|
|
|
9266
9671
|
if (trimmed.startsWith("claude_tool_")) return `${ASCENDA_TOOL_TYPE}:${trimmed.slice("claude_tool_".length)}`;
|
|
9267
9672
|
return `${ASCENDA_TOOL_TYPE}:${trimmed}`;
|
|
9268
9673
|
}
|
|
9269
|
-
var
|
|
9674
|
+
var import_tool_kit9, DEFAULT_API_BASE_URL, MissingInstallationIdError;
|
|
9270
9675
|
var init_config = __esm({
|
|
9271
9676
|
"src/config.ts"() {
|
|
9272
9677
|
"use strict";
|
|
9273
|
-
|
|
9678
|
+
import_tool_kit9 = __toESM(require_out3(), 1);
|
|
9274
9679
|
init_paths();
|
|
9275
9680
|
init_types();
|
|
9276
9681
|
DEFAULT_API_BASE_URL = "https://api.ascenda.one";
|
|
@@ -9290,37 +9695,94 @@ var init_config = __esm({
|
|
|
9290
9695
|
|
|
9291
9696
|
// src/hookHealth.ts
|
|
9292
9697
|
function stampLastHook(event, now = /* @__PURE__ */ new Date()) {
|
|
9293
|
-
(0,
|
|
9698
|
+
(0, import_tool_kit10.stampLastHook)(TOOL, event, now);
|
|
9294
9699
|
}
|
|
9295
9700
|
function readLastHook() {
|
|
9296
|
-
return (0,
|
|
9701
|
+
return (0, import_tool_kit10.readLastHook)(TOOL);
|
|
9297
9702
|
}
|
|
9298
9703
|
function resolveHookNode() {
|
|
9299
|
-
return (0,
|
|
9704
|
+
return (0, import_tool_kit10.resolveHookNode)(hookBinPath());
|
|
9300
9705
|
}
|
|
9301
|
-
var
|
|
9706
|
+
var import_tool_kit10, import_tool_kit11, TOOL;
|
|
9302
9707
|
var init_hookHealth = __esm({
|
|
9303
9708
|
"src/hookHealth.ts"() {
|
|
9304
9709
|
"use strict";
|
|
9305
|
-
|
|
9710
|
+
import_tool_kit10 = __toESM(require_out3(), 1);
|
|
9306
9711
|
init_paths();
|
|
9307
|
-
|
|
9712
|
+
import_tool_kit11 = __toESM(require_out3(), 1);
|
|
9308
9713
|
TOOL = "claude_code";
|
|
9309
9714
|
}
|
|
9310
9715
|
});
|
|
9311
9716
|
|
|
9312
9717
|
// src/launcher.ts
|
|
9313
|
-
var
|
|
9718
|
+
var import_tool_kit13, LAUNCHER_OPTIONS, LAUNCHER_SCRIPT;
|
|
9314
9719
|
var init_launcher = __esm({
|
|
9315
9720
|
"src/launcher.ts"() {
|
|
9316
9721
|
"use strict";
|
|
9317
|
-
|
|
9722
|
+
import_tool_kit13 = __toESM(require_out3(), 1);
|
|
9318
9723
|
LAUNCHER_OPTIONS = {
|
|
9319
9724
|
binaryName: "ascenda-claude-hook",
|
|
9320
9725
|
setupCommand: "npx @ascenda-one/claude-code-hooks setup",
|
|
9321
9726
|
loudEvent: "SessionStart"
|
|
9322
9727
|
};
|
|
9323
|
-
LAUNCHER_SCRIPT = (0,
|
|
9728
|
+
LAUNCHER_SCRIPT = (0, import_tool_kit13.hookLauncherScript)(LAUNCHER_OPTIONS);
|
|
9729
|
+
}
|
|
9730
|
+
});
|
|
9731
|
+
|
|
9732
|
+
// src/statusline.ts
|
|
9733
|
+
var statusline_exports = {};
|
|
9734
|
+
__export(statusline_exports, {
|
|
9735
|
+
readChain: () => readChain,
|
|
9736
|
+
runStatusline: () => runStatusline,
|
|
9737
|
+
statuslineChainPath: () => statuslineChainPath
|
|
9738
|
+
});
|
|
9739
|
+
import { spawn } from "node:child_process";
|
|
9740
|
+
import * as fs6 from "node:fs";
|
|
9741
|
+
import * as path6 from "node:path";
|
|
9742
|
+
function statuslineChainPath() {
|
|
9743
|
+
return path6.join((0, import_tool_kit14.ascendaHome)(), "claude-statusline-chain.json");
|
|
9744
|
+
}
|
|
9745
|
+
function readChain(file = statuslineChainPath()) {
|
|
9746
|
+
try {
|
|
9747
|
+
const parsed = JSON.parse(fs6.readFileSync(file, "utf8"));
|
|
9748
|
+
if (parsed && typeof parsed === "object" && typeof parsed.command === "string") {
|
|
9749
|
+
return parsed;
|
|
9750
|
+
}
|
|
9751
|
+
} catch {
|
|
9752
|
+
}
|
|
9753
|
+
return void 0;
|
|
9754
|
+
}
|
|
9755
|
+
async function runStatusline() {
|
|
9756
|
+
const raw = await readStdin();
|
|
9757
|
+
try {
|
|
9758
|
+
const quota = quotaFromStatusline(JSON.parse(raw));
|
|
9759
|
+
if (quota) recordQuota(quota);
|
|
9760
|
+
} catch {
|
|
9761
|
+
}
|
|
9762
|
+
const chain = readChain();
|
|
9763
|
+
if (!chain?.command) return 0;
|
|
9764
|
+
return await new Promise((resolve3) => {
|
|
9765
|
+
const child = spawn(chain.command, { shell: true, stdio: ["pipe", "inherit", "inherit"] });
|
|
9766
|
+
child.on("error", () => resolve3(0));
|
|
9767
|
+
child.on("close", (code) => resolve3(code ?? 0));
|
|
9768
|
+
child.stdin.on("error", () => void 0);
|
|
9769
|
+
child.stdin.end(raw);
|
|
9770
|
+
});
|
|
9771
|
+
}
|
|
9772
|
+
function readStdin() {
|
|
9773
|
+
return new Promise((resolve3) => {
|
|
9774
|
+
const chunks = [];
|
|
9775
|
+
process.stdin.on("data", (chunk) => chunks.push(chunk));
|
|
9776
|
+
process.stdin.on("end", () => resolve3(Buffer.concat(chunks).toString("utf8")));
|
|
9777
|
+
process.stdin.on("error", () => resolve3(Buffer.concat(chunks).toString("utf8")));
|
|
9778
|
+
});
|
|
9779
|
+
}
|
|
9780
|
+
var import_tool_kit14;
|
|
9781
|
+
var init_statusline = __esm({
|
|
9782
|
+
"src/statusline.ts"() {
|
|
9783
|
+
"use strict";
|
|
9784
|
+
import_tool_kit14 = __toESM(require_out3(), 1);
|
|
9785
|
+
init_quotaSnapshot();
|
|
9324
9786
|
}
|
|
9325
9787
|
});
|
|
9326
9788
|
|
|
@@ -9334,12 +9796,14 @@ __export(setup_exports, {
|
|
|
9334
9796
|
ourHookSets: () => ourHookSets,
|
|
9335
9797
|
registrationSummary: () => registrationSummary,
|
|
9336
9798
|
runSetup: () => runSetup,
|
|
9799
|
+
unwrapStatusLine: () => unwrapStatusLine,
|
|
9800
|
+
wrapStatusLine: () => wrapStatusLine,
|
|
9337
9801
|
writeSettings: () => writeSettings
|
|
9338
9802
|
});
|
|
9339
9803
|
import * as crypto from "crypto";
|
|
9340
|
-
import * as
|
|
9804
|
+
import * as fs7 from "fs";
|
|
9341
9805
|
import * as os2 from "os";
|
|
9342
|
-
import * as
|
|
9806
|
+
import * as path7 from "path";
|
|
9343
9807
|
async function runSetup(argv) {
|
|
9344
9808
|
let options;
|
|
9345
9809
|
try {
|
|
@@ -9355,12 +9819,12 @@ async function runSetup(argv) {
|
|
|
9355
9819
|
if (options.action === "status") return await printStatus(options);
|
|
9356
9820
|
if (options.action === "uninstall") return uninstall(options);
|
|
9357
9821
|
const apiBaseUrl = (options.apiBaseUrl ?? readCredentials()?.apiBaseUrl ?? DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
9358
|
-
const ui = (0,
|
|
9822
|
+
const ui = (0, import_tool_kit15.terminalStyle)();
|
|
9359
9823
|
const row = (tone, label, value) => console.log(` ${ui.mark(tone)} ${label.padEnd(12)} ${value}`);
|
|
9360
9824
|
const detail = (label, value) => console.log(ui.dim(` ${label.padEnd(12)} ${value}`));
|
|
9361
9825
|
console.log(`${ui.bold("Ascenda setup")} ${ui.dim(`\xB7 Claude Code \xB7 ${apiBaseUrl}`)}`);
|
|
9362
9826
|
if (options.pair) console.log(`
|
|
9363
|
-
${(0,
|
|
9827
|
+
${(0, import_tool_kit15.renderSetupDisclosure)({ sends: SENDS, displayName: "Claude Code" })}
|
|
9364
9828
|
`);
|
|
9365
9829
|
else console.log("");
|
|
9366
9830
|
const identity = await resolveIdentity(apiBaseUrl, options);
|
|
@@ -9380,8 +9844,8 @@ ${(0, import_tool_kit12.renderSetupDisclosure)({ sends: SENDS, displayName: "Cla
|
|
|
9380
9844
|
// picks up.
|
|
9381
9845
|
...unpaired ? { localOnly: true, installedAt: now } : { pairedAt: now }
|
|
9382
9846
|
});
|
|
9383
|
-
if (options.eventLog !== void 0) (0,
|
|
9384
|
-
if (options.repoKeys !== void 0) (0,
|
|
9847
|
+
if (options.eventLog !== void 0) (0, import_tool_kit15.writeEventLogSetting)(options.eventLog);
|
|
9848
|
+
if (options.repoKeys !== void 0) (0, import_tool_kit15.writeRepoKeysSetting)(options.repoKeys);
|
|
9385
9849
|
}
|
|
9386
9850
|
if (isHomeProject(options)) {
|
|
9387
9851
|
detail("scope", "user (a project install in the home folder only loads when Claude Code starts there)");
|
|
@@ -9393,8 +9857,29 @@ ${(0, import_tool_kit12.renderSetupDisclosure)({ sends: SENDS, displayName: "Cla
|
|
|
9393
9857
|
if (written === null) return 1;
|
|
9394
9858
|
const reach = options.scope === "user" ? "every project" : "this project only";
|
|
9395
9859
|
row("ok", "hooks", `${tidyHome(settingsFile)} ${ui.dim(`(${HOOK_EVENTS.length} events, ${reach}${written ? "" : ", already current"})`)}`);
|
|
9396
|
-
|
|
9860
|
+
if (options.captureQuota !== void 0) {
|
|
9861
|
+
if (options.scope !== "user") {
|
|
9862
|
+
row("warn", "quota", "needs user scope; the status line is left alone");
|
|
9863
|
+
} else {
|
|
9864
|
+
const outcome = options.captureQuota ? wrapStatusLine(settingsFile, binary, options.dryRun) : unwrapStatusLine(settingsFile, options.dryRun);
|
|
9865
|
+
if (outcome === null) return 1;
|
|
9866
|
+
row("ok", "quota", `${outcome}${options.dryRun ? ui.dim(" (dry run)") : ""}`);
|
|
9867
|
+
}
|
|
9868
|
+
}
|
|
9869
|
+
const changes = (0, import_tool_kit15.describeHookSetChanges)((0, import_tool_kit15.hookSetChanges)(before, HOOK_EVENTS), HOOK_SET);
|
|
9397
9870
|
if (changes) detail("", changes);
|
|
9871
|
+
if (options.scope === "user") {
|
|
9872
|
+
for (const profileDir of (0, import_tool_kit15.extraClaudeProfileDirs)()) {
|
|
9873
|
+
const profileSettings = path7.join(profileDir, "settings.json");
|
|
9874
|
+
if (path7.resolve(profileSettings) === path7.resolve(settingsFile)) continue;
|
|
9875
|
+
const profileWritten = writeSettings(profileSettings, binary, options.dryRun);
|
|
9876
|
+
if (profileWritten === null) {
|
|
9877
|
+
row("warn", "hooks", `${tidyHome(profileSettings)} could not be updated`);
|
|
9878
|
+
continue;
|
|
9879
|
+
}
|
|
9880
|
+
row("ok", "hooks", `${tidyHome(profileSettings)} ${ui.dim(`(extra profile${profileWritten ? "" : ", already current"})`)}`);
|
|
9881
|
+
}
|
|
9882
|
+
}
|
|
9398
9883
|
const otherFiles = /* @__PURE__ */ new Set([
|
|
9399
9884
|
settingsPath({ ...options, scope: options.scope === "user" ? "project" : "user" }),
|
|
9400
9885
|
// The home folder's project file, where a project-scope setup run from
|
|
@@ -9422,8 +9907,8 @@ ${(0, import_tool_kit12.renderSetupDisclosure)({ sends: SENDS, displayName: "Cla
|
|
|
9422
9907
|
row("ok", "pairing", `${identity.toolInstallationId}${ui.dim(identity.pairing === "new" ? " (new)" : " (existing)")}`);
|
|
9423
9908
|
}
|
|
9424
9909
|
if (unpaired) detail("installation", `${identity.toolInstallationId} (kept, so pairing later attaches to it)`);
|
|
9425
|
-
detail("credentials", tidyHome((0,
|
|
9426
|
-
const eventLog = (0,
|
|
9910
|
+
detail("credentials", tidyHome((0, import_tool_kit7.credentialsFilePath)()));
|
|
9911
|
+
const eventLog = (0, import_tool_kit15.resolveEventLog)({ localOnly: unpaired });
|
|
9427
9912
|
if (eventLog.path) row("ok", "events", `${tidyHome(eventLog.path)} ${ui.dim("(on this machine only)")}`);
|
|
9428
9913
|
else if (options.eventLog !== void 0) row("info", "events", "off");
|
|
9429
9914
|
if (options.dryRun) {
|
|
@@ -9453,7 +9938,7 @@ ${(0, import_tool_kit12.renderSetupDisclosure)({ sends: SENDS, displayName: "Cla
|
|
|
9453
9938
|
console.log(ui.dim(" confirm the code with, in Ascenda Flow or at me.ascendaflow.com."));
|
|
9454
9939
|
console.log(ui.dim(" Until you pair, nothing leaves this machine."));
|
|
9455
9940
|
console.log("");
|
|
9456
|
-
console.log(ui.dim((0,
|
|
9941
|
+
console.log(ui.dim((0, import_tool_kit15.renderSetupDisclosure)({ sends: SENDS, displayName: "Claude Code" }).split("\n").map((line) => ` ${line}`).join("\n")));
|
|
9457
9942
|
}
|
|
9458
9943
|
return 0;
|
|
9459
9944
|
}
|
|
@@ -9505,10 +9990,10 @@ function parseArgs(argv) {
|
|
|
9505
9990
|
break;
|
|
9506
9991
|
}
|
|
9507
9992
|
case "--project-dir":
|
|
9508
|
-
options.projectDir =
|
|
9993
|
+
options.projectDir = path7.resolve(next());
|
|
9509
9994
|
break;
|
|
9510
9995
|
case "--event-log": {
|
|
9511
|
-
const { value, consumed } = (0,
|
|
9996
|
+
const { value, consumed } = (0, import_tool_kit15.parseEventLogFlag)(argv, i);
|
|
9512
9997
|
options.eventLog = value;
|
|
9513
9998
|
i += consumed;
|
|
9514
9999
|
break;
|
|
@@ -9519,6 +10004,12 @@ function parseArgs(argv) {
|
|
|
9519
10004
|
case "--no-repo-keys":
|
|
9520
10005
|
options.repoKeys = false;
|
|
9521
10006
|
break;
|
|
10007
|
+
case "--capture-quota":
|
|
10008
|
+
options.captureQuota = true;
|
|
10009
|
+
break;
|
|
10010
|
+
case "--no-capture-quota":
|
|
10011
|
+
options.captureQuota = false;
|
|
10012
|
+
break;
|
|
9522
10013
|
case "--no-pair":
|
|
9523
10014
|
// `--no-pairing` is the spelling the CLI agents' setup landed under
|
|
9524
10015
|
// first, and the one their README still showed for a day. Both parse
|
|
@@ -9543,15 +10034,15 @@ ${USAGE}`);
|
|
|
9543
10034
|
return options;
|
|
9544
10035
|
}
|
|
9545
10036
|
function isHomeProject(options) {
|
|
9546
|
-
return options.scope === "project" &&
|
|
10037
|
+
return options.scope === "project" && path7.resolve(options.projectDir) === path7.resolve(os2.homedir());
|
|
9547
10038
|
}
|
|
9548
10039
|
async function resolveIdentity(apiBaseUrl, options) {
|
|
9549
10040
|
const existingId = options.toolInstallationId ?? readCredentials()?.toolInstallationId;
|
|
9550
10041
|
if (existingId && options.token) {
|
|
9551
|
-
if (!options.dryRun) (0,
|
|
10042
|
+
if (!options.dryRun) (0, import_tool_kit15.persistEventWriteToken)((0, import_tool_kit15.defaultTokenFilePath)(existingId), options.token);
|
|
9552
10043
|
return { toolInstallationId: existingId, pairing: "existing" };
|
|
9553
10044
|
}
|
|
9554
|
-
if (existingId && (0,
|
|
10045
|
+
if (existingId && (0, import_tool_kit15.readTokenFile)((0, import_tool_kit15.defaultTokenFilePath)(existingId))) {
|
|
9555
10046
|
return { toolInstallationId: existingId, pairing: "existing" };
|
|
9556
10047
|
}
|
|
9557
10048
|
const toolInstallationId = existingId ?? (options.dryRun ? `${ASCENDA_TOOL_TYPE}:<minted at run time>` : `${ASCENDA_TOOL_TYPE}:${crypto.randomUUID()}`);
|
|
@@ -9563,7 +10054,7 @@ async function resolveIdentity(apiBaseUrl, options) {
|
|
|
9563
10054
|
}
|
|
9564
10055
|
let attempt;
|
|
9565
10056
|
try {
|
|
9566
|
-
attempt = await (0,
|
|
10057
|
+
attempt = await (0, import_tool_kit15.createPairingAttempt)(apiBaseUrl, toolInstallationId, ASCENDA_TOOL_TYPE, "Claude Code");
|
|
9567
10058
|
} catch (error) {
|
|
9568
10059
|
return {
|
|
9569
10060
|
toolInstallationId,
|
|
@@ -9576,7 +10067,7 @@ async function resolveIdentity(apiBaseUrl, options) {
|
|
|
9576
10067
|
${attempt.refusal} Pairing without the study.`);
|
|
9577
10068
|
const outcome = await pollForToken(apiBaseUrl, attempt);
|
|
9578
10069
|
if ("reason" in outcome) return { toolInstallationId, pairing: "local-only", reason: outcome.reason };
|
|
9579
|
-
(0,
|
|
10070
|
+
(0, import_tool_kit15.persistEventWriteToken)((0, import_tool_kit15.defaultTokenFilePath)(toolInstallationId), outcome.token);
|
|
9580
10071
|
return { toolInstallationId, pairing: "new" };
|
|
9581
10072
|
}
|
|
9582
10073
|
async function pollForToken(apiBaseUrl, attempt) {
|
|
@@ -9584,14 +10075,14 @@ async function pollForToken(apiBaseUrl, attempt) {
|
|
|
9584
10075
|
const deadline = Math.min(Date.parse(session.expiresAt) || Date.now() + 3e5, Date.now() + 3e5);
|
|
9585
10076
|
let failures = 0;
|
|
9586
10077
|
let studyJoin;
|
|
9587
|
-
const finish = (pairing) => (0,
|
|
10078
|
+
const finish = (pairing) => (0, import_tool_kit15.writePairingJoinOutcome)((0, import_tool_kit15.pairingJoinOutcome)(attempt, pairing, studyJoin));
|
|
9588
10079
|
console.log("");
|
|
9589
|
-
for (const line of (0,
|
|
10080
|
+
for (const line of (0, import_tool_kit15.pairingAttemptLines)(attempt)) console.log(` ${line}`);
|
|
9590
10081
|
console.log(" Waiting...");
|
|
9591
10082
|
while (Date.now() < deadline) {
|
|
9592
10083
|
let status;
|
|
9593
10084
|
try {
|
|
9594
|
-
status = await (0,
|
|
10085
|
+
status = await (0, import_tool_kit15.getPairingStatus)(apiBaseUrl, session.pairingSessionId);
|
|
9595
10086
|
failures = 0;
|
|
9596
10087
|
} catch (error) {
|
|
9597
10088
|
if (++failures >= POLL_ERROR_TOLERANCE) {
|
|
@@ -9603,7 +10094,7 @@ async function pollForToken(apiBaseUrl, attempt) {
|
|
|
9603
10094
|
}
|
|
9604
10095
|
studyJoin = status.studyJoin ?? studyJoin;
|
|
9605
10096
|
if (status.status === "paired" && status.eventWriteToken) {
|
|
9606
|
-
studyJoin = await (0,
|
|
10097
|
+
studyJoin = await (0, import_tool_kit15.settleStudyJoin)(apiBaseUrl, session.pairingSessionId, studyJoin);
|
|
9607
10098
|
finish("paired");
|
|
9608
10099
|
return { token: status.eventWriteToken };
|
|
9609
10100
|
}
|
|
@@ -9624,23 +10115,23 @@ function restartLine(options) {
|
|
|
9624
10115
|
return options.scope === "user" ? "Restart Claude Code to load the hooks." : "Restart Claude Code in this project to load the hooks.";
|
|
9625
10116
|
}
|
|
9626
10117
|
function installBinary(dryRun) {
|
|
9627
|
-
return (0,
|
|
10118
|
+
return (0, import_tool_kit15.installHookRunner)({
|
|
9628
10119
|
...LAUNCHER_OPTIONS,
|
|
9629
10120
|
dryRun,
|
|
9630
10121
|
onKeptNewer: (installed, incoming) => console.log(`Kept the installed hook bundle (${installed}) rather than replace it with this older ${incoming}. Run setup from the newer version to change it.`)
|
|
9631
10122
|
});
|
|
9632
10123
|
}
|
|
9633
10124
|
function settingsPath(options) {
|
|
9634
|
-
return options.scope === "user" ?
|
|
10125
|
+
return options.scope === "user" ? path7.join(claudeConfigDir(), "settings.json") : path7.join(options.projectDir, ".claude", "settings.local.json");
|
|
9635
10126
|
}
|
|
9636
10127
|
function homeProjectSettingsPath() {
|
|
9637
|
-
return
|
|
10128
|
+
return path7.join(os2.homedir(), ".claude", "settings.local.json");
|
|
9638
10129
|
}
|
|
9639
10130
|
function writeSettings(settingsFile, binary, dryRun) {
|
|
9640
10131
|
let settings = {};
|
|
9641
|
-
const exists =
|
|
10132
|
+
const exists = fs7.existsSync(settingsFile);
|
|
9642
10133
|
if (exists) {
|
|
9643
|
-
const raw =
|
|
10134
|
+
const raw = fs7.readFileSync(settingsFile, "utf8").trim();
|
|
9644
10135
|
if (raw) {
|
|
9645
10136
|
try {
|
|
9646
10137
|
settings = JSON.parse(raw);
|
|
@@ -9654,27 +10145,27 @@ ${settingsFile} is not valid JSON. Fix or move it, then run setup again.`);
|
|
|
9654
10145
|
const command = hookCommand(binary);
|
|
9655
10146
|
const hooks = { ...settings.hooks ?? {} };
|
|
9656
10147
|
for (const event of HOOK_EVENTS) {
|
|
9657
|
-
hooks[event] = placeOurEntry(hooks[event] ?? [], { type: "command", command: `${command} ${event}${(0,
|
|
10148
|
+
hooks[event] = placeOurEntry(hooks[event] ?? [], { type: "command", command: `${command} ${event}${(0, import_tool_kit15.hookSetArgument)(HOOK_SET)}`, timeout: HOOK_TIMEOUT_SECONDS });
|
|
9658
10149
|
}
|
|
9659
10150
|
const updated = { ...settings, hooks };
|
|
9660
10151
|
const serialised = `${JSON.stringify(updated, null, 2)}
|
|
9661
10152
|
`;
|
|
9662
|
-
if (exists &&
|
|
10153
|
+
if (exists && fs7.readFileSync(settingsFile, "utf8") === serialised) return false;
|
|
9663
10154
|
if (dryRun) {
|
|
9664
10155
|
console.log(`
|
|
9665
10156
|
--- ${settingsFile} (dry run) ---
|
|
9666
10157
|
${serialised}`);
|
|
9667
10158
|
return true;
|
|
9668
10159
|
}
|
|
9669
|
-
(0,
|
|
10160
|
+
(0, import_tool_kit15.replaceSettingsFile)(settingsFile, serialised);
|
|
9670
10161
|
return true;
|
|
9671
10162
|
}
|
|
9672
10163
|
function hookCommand(binary) {
|
|
9673
|
-
return (0,
|
|
10164
|
+
return (0, import_tool_kit15.hookRunnerCommand)(binary);
|
|
9674
10165
|
}
|
|
9675
10166
|
function removeOurHooks(settingsFile) {
|
|
9676
10167
|
try {
|
|
9677
|
-
const settings = JSON.parse(
|
|
10168
|
+
const settings = JSON.parse(fs7.readFileSync(settingsFile, "utf8"));
|
|
9678
10169
|
const hooks = { ...settings.hooks ?? {} };
|
|
9679
10170
|
for (const event of Object.keys(hooks)) {
|
|
9680
10171
|
const kept = withoutOurEntries(hooks[event]);
|
|
@@ -9683,7 +10174,7 @@ function removeOurHooks(settingsFile) {
|
|
|
9683
10174
|
}
|
|
9684
10175
|
const updated = { ...settings, hooks };
|
|
9685
10176
|
if (!Object.keys(hooks).length) delete updated.hooks;
|
|
9686
|
-
(0,
|
|
10177
|
+
(0, import_tool_kit15.replaceSettingsFile)(settingsFile, `${JSON.stringify(updated, null, 2)}
|
|
9687
10178
|
`);
|
|
9688
10179
|
return true;
|
|
9689
10180
|
} catch {
|
|
@@ -9745,7 +10236,7 @@ function findStaleHookCommands(settings, binary) {
|
|
|
9745
10236
|
}
|
|
9746
10237
|
function readSettingsFile(settingsFile) {
|
|
9747
10238
|
try {
|
|
9748
|
-
return JSON.parse(
|
|
10239
|
+
return JSON.parse(fs7.readFileSync(settingsFile, "utf8"));
|
|
9749
10240
|
} catch {
|
|
9750
10241
|
return {};
|
|
9751
10242
|
}
|
|
@@ -9756,7 +10247,7 @@ function ourHookSets(settings) {
|
|
|
9756
10247
|
for (const group of groups ?? []) {
|
|
9757
10248
|
for (const entry of group.hooks ?? []) {
|
|
9758
10249
|
if (!isOurEntry(entry)) continue;
|
|
9759
|
-
const set = (0,
|
|
10250
|
+
const set = (0, import_tool_kit15.hookSetOfCommand)(entry.command);
|
|
9760
10251
|
sets.set(event, Math.min(set, sets.get(event) ?? set));
|
|
9761
10252
|
}
|
|
9762
10253
|
}
|
|
@@ -9778,7 +10269,7 @@ function registrationSummary(projectDir) {
|
|
|
9778
10269
|
for (const [file, scope] of files) {
|
|
9779
10270
|
const { registered } = countRegistered(file, binary);
|
|
9780
10271
|
if (registered === 0) continue;
|
|
9781
|
-
found.push({ file, scope, registered, homeProject:
|
|
10272
|
+
found.push({ file, scope, registered, homeProject: path7.resolve(file) === path7.resolve(homeProjectSettingsPath()) });
|
|
9782
10273
|
}
|
|
9783
10274
|
return found;
|
|
9784
10275
|
}
|
|
@@ -9786,7 +10277,7 @@ async function printStatus(options) {
|
|
|
9786
10277
|
const credentials = readCredentials();
|
|
9787
10278
|
const settingsFile = settingsPath(options);
|
|
9788
10279
|
const binary = hookBinPath();
|
|
9789
|
-
const tokenFile = credentials?.toolInstallationId ? (0,
|
|
10280
|
+
const tokenFile = credentials?.toolInstallationId ? (0, import_tool_kit15.defaultTokenFilePath)(credentials.toolInstallationId) : void 0;
|
|
9790
10281
|
const unpaired = localOnlyInstall(credentials);
|
|
9791
10282
|
const here = countRegistered(settingsFile, binary);
|
|
9792
10283
|
const settings = here.settings;
|
|
@@ -9795,18 +10286,18 @@ async function printStatus(options) {
|
|
|
9795
10286
|
const otherFile = settingsPath(otherScope);
|
|
9796
10287
|
const elsewhere = registered === 0 && otherFile !== settingsFile ? countRegistered(otherFile, binary) : void 0;
|
|
9797
10288
|
const stale = findStaleHookCommands(settings, binary);
|
|
9798
|
-
console.log(`version ${(0,
|
|
10289
|
+
console.log(`version ${(0, import_tool_kit15.describeCollectorVersion)()}`);
|
|
9799
10290
|
console.log(`api base url ${credentials?.apiBaseUrl ?? "\u2014 not configured"}`);
|
|
9800
10291
|
console.log(`pairing ${describePairing(credentials, unpaired)}`);
|
|
9801
|
-
const fileToken = Boolean(tokenFile && (0,
|
|
10292
|
+
const fileToken = Boolean(tokenFile && (0, import_tool_kit15.readTokenFile)(tokenFile));
|
|
9802
10293
|
const token = fileToken || Boolean(envOverride("ASCENDA_EVENT_WRITE_TOKEN"));
|
|
9803
10294
|
console.log(`token ${fileToken ? "present" : token ? "from ASCENDA_EVENT_WRITE_TOKEN (no file)" : unpaired ? "\u2014 none until this install is paired" : "\u2014 missing"}`);
|
|
9804
10295
|
console.log(`delivery ${token ? "active" : unpaired ? "inactive \u2014 nothing is sent, and nothing is queued for later" : "\u2014 no token for this pairing, so nothing can be sent"}`);
|
|
9805
10296
|
console.log("local features active \u2014 the session prompts and the live socket signal need no pairing");
|
|
9806
|
-
console.log(`event log ${(0,
|
|
9807
|
-
console.log(`hook binary ${
|
|
9808
|
-
console.log(`latest ${(0,
|
|
9809
|
-
installed: (0,
|
|
10297
|
+
console.log(`event log ${(0, import_tool_kit15.describeEventLog)((0, import_tool_kit15.resolveEventLog)({ localOnly: unpaired }), "npx @ascenda-one/claude-code-hooks setup")}`);
|
|
10298
|
+
console.log(`hook binary ${fs7.existsSync(binary) ? binary : "\u2014 not installed"}`);
|
|
10299
|
+
console.log(`latest ${(0, import_tool_kit15.describeReleaseCheck)({
|
|
10300
|
+
installed: (0, import_tool_kit15.installedBundleVersion)(`${binary}.version`) ?? import_tool_kit15.COLLECTOR_VERSION,
|
|
9810
10301
|
setupCommand: "npx -y @ascenda-one/claude-code-hooks setup",
|
|
9811
10302
|
localOnly: unpaired
|
|
9812
10303
|
})}`);
|
|
@@ -9815,7 +10306,7 @@ async function printStatus(options) {
|
|
|
9815
10306
|
console.log(node.problem ? `node \u2014 ${node.problem}. Install Node 20 or newer, then run setup again` : `node ${node.node} (${node.version}, ${node.how === "recorded" ? "recorded at setup" : "found by the launcher"})`);
|
|
9816
10307
|
}
|
|
9817
10308
|
const last = readLastHook();
|
|
9818
|
-
console.log(last ? `last hook ${last.event}, ${(0,
|
|
10309
|
+
console.log(last ? `last hook ${last.event}, ${(0, import_tool_kit11.describeAge)(Date.now() - Date.parse(last.at))}` : "last hook \u2014 none has run yet. Start Claude Code (restart it if it was open during setup), then check /hooks");
|
|
9819
10310
|
console.log(`hooks ${registered}/${HOOK_EVENTS.length} registered in ${settingsFile}`);
|
|
9820
10311
|
if (elsewhere && elsewhere.registered > 0) {
|
|
9821
10312
|
console.log(` ${elsewhere.registered}/${HOOK_EVENTS.length} found in ${otherFile} (--scope ${otherScope.scope})`);
|
|
@@ -9830,11 +10321,11 @@ async function printStatus(options) {
|
|
|
9830
10321
|
for (const command of stale) console.log(` ${command}`);
|
|
9831
10322
|
console.log(` Remove them from ${settingsFile} by hand; setup cannot tell them from a hook you wrote.`);
|
|
9832
10323
|
}
|
|
9833
|
-
const tokenValue = unpaired ? void 0 : (tokenFile ? (0,
|
|
10324
|
+
const tokenValue = unpaired ? void 0 : (tokenFile ? (0, import_tool_kit15.readTokenFile)(tokenFile) : void 0) ?? envOverride("ASCENDA_EVENT_WRITE_TOKEN") ?? void 0;
|
|
9834
10325
|
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? credentials?.apiBaseUrl ?? DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
9835
10326
|
const [initiativeLines, notices] = await Promise.all([
|
|
9836
|
-
(0,
|
|
9837
|
-
(0,
|
|
10327
|
+
(0, import_tool_kit15.initiativesStatusLines)({ apiBaseUrl, eventWriteToken: tokenValue, pairCommand: `${selfCommand()} pair` }),
|
|
10328
|
+
(0, import_tool_kit15.studyNoticeStatus)({ apiBaseUrl, eventWriteToken: tokenValue, commandPrefix: "npx @ascenda-one/claude-code-hooks" })
|
|
9838
10329
|
]);
|
|
9839
10330
|
console.log("");
|
|
9840
10331
|
for (const line of initiativeLines) console.log(line);
|
|
@@ -9845,7 +10336,7 @@ async function printStatus(options) {
|
|
|
9845
10336
|
console.log(`To send your sessions to Ascenda's servers, so they appear in the app: ${selfCommand()} pair`);
|
|
9846
10337
|
}
|
|
9847
10338
|
const wired = registered === HOOK_EVENTS.length || options.scope === "project" && elsewhere?.registered === HOOK_EVENTS.length;
|
|
9848
|
-
const healthy = credentials?.toolInstallationId && wired &&
|
|
10339
|
+
const healthy = credentials?.toolInstallationId && wired && fs7.existsSync(binary) && !stale.length && !node?.problem;
|
|
9849
10340
|
return healthy ? 0 : 1;
|
|
9850
10341
|
}
|
|
9851
10342
|
function describePairing(credentials, unpaired) {
|
|
@@ -9857,36 +10348,102 @@ function describePairing(credentials, unpaired) {
|
|
|
9857
10348
|
function uninstall(options) {
|
|
9858
10349
|
const unpaired = localOnlyInstall();
|
|
9859
10350
|
const settingsFile = settingsPath(options);
|
|
9860
|
-
if (
|
|
10351
|
+
if (fs7.existsSync(settingsFile)) {
|
|
9861
10352
|
if (!removeOurHooks(settingsFile)) {
|
|
9862
10353
|
console.error(`could not parse ${settingsFile} \u2014 remove the ascenda hook entries by hand`);
|
|
9863
10354
|
return 1;
|
|
9864
10355
|
}
|
|
9865
10356
|
console.log(`hooks removed from ${settingsFile}`);
|
|
10357
|
+
if (unwrapStatusLine(settingsFile, false) === null) console.error(`could not restore your status line in ${settingsFile}`);
|
|
10358
|
+
}
|
|
10359
|
+
for (const file of [quotaSnapshotPath(), statuslineChainPath()]) fs7.rmSync(file, { force: true });
|
|
10360
|
+
if (options.scope === "user") {
|
|
10361
|
+
for (const profileDir of (0, import_tool_kit15.extraClaudeProfileDirs)()) {
|
|
10362
|
+
const profileSettings = path7.join(profileDir, "settings.json");
|
|
10363
|
+
if (path7.resolve(profileSettings) === path7.resolve(settingsFile) || !fs7.existsSync(profileSettings)) continue;
|
|
10364
|
+
if (removeOurHooks(profileSettings)) console.log(`hooks removed from ${profileSettings}`);
|
|
10365
|
+
}
|
|
9866
10366
|
}
|
|
9867
10367
|
for (const file of [hookBinPath(), hookBundlePath(), hookNodeRecordPath(), hookNoNodePath(), `${hookBinPath()}.version`]) {
|
|
9868
|
-
if (!
|
|
9869
|
-
|
|
10368
|
+
if (!fs7.existsSync(file)) continue;
|
|
10369
|
+
fs7.rmSync(file);
|
|
9870
10370
|
if (file === hookBinPath() || file === hookBundlePath()) console.log(`removed ${file}`);
|
|
9871
10371
|
}
|
|
9872
|
-
const credentialsFile2 = (0,
|
|
9873
|
-
if (
|
|
10372
|
+
const credentialsFile2 = (0, import_tool_kit7.credentialsFilePath)();
|
|
10373
|
+
if (fs7.existsSync(credentialsFile2)) {
|
|
9874
10374
|
removeCredentials();
|
|
9875
|
-
console.log(
|
|
10375
|
+
console.log(fs7.existsSync(credentialsFile2) ? `cleared the Claude Code pairing from ${credentialsFile2} (other tools' pairings kept)` : `removed ${credentialsFile2}`);
|
|
9876
10376
|
}
|
|
9877
|
-
console.log(unpaired ? "this install was never paired, so there is no token here and nothing to revoke" : `tokens left in ${
|
|
10377
|
+
console.log(unpaired ? "this install was never paired, so there is no token here and nothing to revoke" : `tokens left in ${path7.join((0, import_tool_kit15.ascendaHome)(), "tokens")} \u2014 revoke in the Ascenda app to invalidate them`);
|
|
9878
10378
|
return 0;
|
|
9879
10379
|
}
|
|
9880
|
-
|
|
10380
|
+
function statuslineCommand(binary) {
|
|
10381
|
+
return `${hookCommand(binary)} statusline`;
|
|
10382
|
+
}
|
|
10383
|
+
function isOurStatusLine(setting) {
|
|
10384
|
+
return typeof setting?.command === "string" && setting.command.includes(HOOK_MARKER) && / statusline$/.test(setting.command);
|
|
10385
|
+
}
|
|
10386
|
+
function readStatusLineSettings(settingsFile) {
|
|
10387
|
+
if (!fs7.existsSync(settingsFile)) return {};
|
|
10388
|
+
const raw = fs7.readFileSync(settingsFile, "utf8").trim();
|
|
10389
|
+
if (!raw) return {};
|
|
10390
|
+
try {
|
|
10391
|
+
return JSON.parse(raw);
|
|
10392
|
+
} catch {
|
|
10393
|
+
console.error(`
|
|
10394
|
+
${settingsFile} is not valid JSON. Fix or move it, then run setup again.`);
|
|
10395
|
+
return null;
|
|
10396
|
+
}
|
|
10397
|
+
}
|
|
10398
|
+
function wrapStatusLine(settingsFile, binary, dryRun) {
|
|
10399
|
+
const settings = readStatusLineSettings(settingsFile);
|
|
10400
|
+
if (settings === null) return null;
|
|
10401
|
+
const current = settings.statusLine && typeof settings.statusLine === "object" ? settings.statusLine : void 0;
|
|
10402
|
+
if (isOurStatusLine(current)) return "status line already wrapped";
|
|
10403
|
+
const wrapped = { ...current ?? {}, type: "command", command: statuslineCommand(binary) };
|
|
10404
|
+
const had = typeof current?.command === "string";
|
|
10405
|
+
if (!dryRun) {
|
|
10406
|
+
if (had) {
|
|
10407
|
+
fs7.mkdirSync(path7.dirname(statuslineChainPath()), { recursive: true });
|
|
10408
|
+
fs7.writeFileSync(statuslineChainPath(), `${JSON.stringify(current)}
|
|
10409
|
+
`, { mode: 384 });
|
|
10410
|
+
} else {
|
|
10411
|
+
fs7.rmSync(statuslineChainPath(), { force: true });
|
|
10412
|
+
}
|
|
10413
|
+
(0, import_tool_kit15.replaceSettingsFile)(settingsFile, `${JSON.stringify({ ...settings, statusLine: wrapped }, null, 2)}
|
|
10414
|
+
`);
|
|
10415
|
+
}
|
|
10416
|
+
return had ? `wrapped your status line, its output is passed through (backup ${tidyHome(`${settingsFile}.ascenda-backup`)})` : "added a status line that keeps the usage numbers and prints nothing";
|
|
10417
|
+
}
|
|
10418
|
+
function unwrapStatusLine(settingsFile, dryRun) {
|
|
10419
|
+
if (!fs7.existsSync(settingsFile)) return "no status line wrapper to remove";
|
|
10420
|
+
const settings = readStatusLineSettings(settingsFile);
|
|
10421
|
+
if (settings === null) return null;
|
|
10422
|
+
const current = settings.statusLine && typeof settings.statusLine === "object" ? settings.statusLine : void 0;
|
|
10423
|
+
if (!isOurStatusLine(current)) return "no status line wrapper to remove";
|
|
10424
|
+
const original = readChain();
|
|
10425
|
+
const updated = { ...settings };
|
|
10426
|
+
if (original) updated.statusLine = original;
|
|
10427
|
+
else delete updated.statusLine;
|
|
10428
|
+
if (!dryRun) {
|
|
10429
|
+
(0, import_tool_kit15.replaceSettingsFile)(settingsFile, `${JSON.stringify(updated, null, 2)}
|
|
10430
|
+
`);
|
|
10431
|
+
fs7.rmSync(statuslineChainPath(), { force: true });
|
|
10432
|
+
}
|
|
10433
|
+
return original ? "put your own status line back" : "removed the wrapper, you had no status line";
|
|
10434
|
+
}
|
|
10435
|
+
var import_tool_kit15, HOOK_EVENTS, HOOK_SET, HOOK_TIMEOUT_SECONDS, HOOK_MARKER, SENDS, USAGE, POLL_ERROR_TOLERANCE, REGISTERED_EVENT_COUNT;
|
|
9881
10436
|
var init_setup = __esm({
|
|
9882
10437
|
"src/setup.ts"() {
|
|
9883
10438
|
"use strict";
|
|
9884
|
-
|
|
10439
|
+
import_tool_kit15 = __toESM(require_out3(), 1);
|
|
9885
10440
|
init_config();
|
|
9886
10441
|
init_hookHealth();
|
|
9887
10442
|
init_launcher();
|
|
9888
10443
|
init_paths();
|
|
9889
10444
|
init_types();
|
|
10445
|
+
init_quotaSnapshot();
|
|
10446
|
+
init_statusline();
|
|
9890
10447
|
HOOK_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PostToolUseFailure", "PreCompact", "PostCompact", "Stop", "StopFailure", "Notification", "SessionEnd", "SubagentStart", "SubagentStop", "PermissionRequest", "PermissionDenied"];
|
|
9891
10448
|
HOOK_SET = 4;
|
|
9892
10449
|
HOOK_TIMEOUT_SECONDS = 5;
|
|
@@ -9921,6 +10478,9 @@ Options
|
|
|
9921
10478
|
names can reproduce. Machine-wide. --repo-keys turns them back on
|
|
9922
10479
|
--scope user|project where hooks are registered (default user: every project)
|
|
9923
10480
|
--project-dir <path> project root for --scope project (default cwd)
|
|
10481
|
+
--capture-quota keep Claude Code's 5-hour and 7-day usage numbers on this machine, so a usage-limit
|
|
10482
|
+
hold uses the real reset time. Wraps your status line, and keeps its output
|
|
10483
|
+
unchanged. User scope only. --no-capture-quota puts your own status line back
|
|
9924
10484
|
--dry-run print what would change, write nothing
|
|
9925
10485
|
-h, --help
|
|
9926
10486
|
`;
|
|
@@ -9930,13 +10490,13 @@ Options
|
|
|
9930
10490
|
});
|
|
9931
10491
|
|
|
9932
10492
|
// src/cli.ts
|
|
9933
|
-
var import_tool_kit15 = __toESM(require_out3(), 1);
|
|
9934
|
-
var import_tool_kit16 = __toESM(require_out3(), 1);
|
|
9935
|
-
var import_tool_kit17 = __toESM(require_out3(), 1);
|
|
9936
10493
|
var import_tool_kit18 = __toESM(require_out3(), 1);
|
|
9937
10494
|
var import_tool_kit19 = __toESM(require_out3(), 1);
|
|
10495
|
+
var import_tool_kit20 = __toESM(require_out3(), 1);
|
|
10496
|
+
var import_tool_kit21 = __toESM(require_out3(), 1);
|
|
10497
|
+
var import_tool_kit22 = __toESM(require_out3(), 1);
|
|
9938
10498
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
9939
|
-
import * as
|
|
10499
|
+
import * as fs8 from "node:fs";
|
|
9940
10500
|
|
|
9941
10501
|
// src/ascendaClient.ts
|
|
9942
10502
|
var import_tool_kit = __toESM(require_out3(), 1);
|
|
@@ -9995,12 +10555,13 @@ function mapClaudeEvent(hookName, input, options = {}) {
|
|
|
9995
10555
|
const cwd = (0, import_tool_kit3.getString)(input, ["cwd"]) ?? process.cwd();
|
|
9996
10556
|
const branchHash = (0, import_tool_kit4.deriveBranchHashForCwd)(cwd);
|
|
9997
10557
|
const { repoKey, branchKey } = (0, import_tool_kit4.deriveForgeKeysForCwd)(cwd);
|
|
10558
|
+
const accountKey = (0, import_tool_kit4.deriveAccountKey)();
|
|
9998
10559
|
const promptId = readPromptId(input);
|
|
9999
10560
|
const runtime = claudeRuntime();
|
|
10000
10561
|
const subagentId = readSubagentId(input);
|
|
10001
10562
|
return events.map((event) => ({
|
|
10002
10563
|
...event,
|
|
10003
|
-
metadata: { host: CLAUDE_HOST, runtime, ...branchHash ? { branchHash } : {}, ...repoKey ? { repoKey } : {}, ...branchKey ? { branchKey } : {}, ...promptId ? { promptId } : {}, ...subagentId ? { subagentId } : {}, ...event.metadata }
|
|
10564
|
+
metadata: { host: CLAUDE_HOST, runtime, ...branchHash ? { branchHash } : {}, ...accountKey ? { accountKey } : {}, ...repoKey ? { repoKey } : {}, ...branchKey ? { branchKey } : {}, ...promptId ? { promptId } : {}, ...subagentId ? { subagentId } : {}, ...event.metadata }
|
|
10004
10565
|
}));
|
|
10005
10566
|
}
|
|
10006
10567
|
function withModel(hookName, input, events, options) {
|
|
@@ -10418,154 +10979,174 @@ function notificationLiveEvent(input) {
|
|
|
10418
10979
|
return Object.hasOwn(NOTIFICATION_KIND_EVENTS, label) ? NOTIFICATION_KIND_EVENTS[label] : void 0;
|
|
10419
10980
|
}
|
|
10420
10981
|
|
|
10421
|
-
// src/
|
|
10422
|
-
|
|
10423
|
-
import * as
|
|
10424
|
-
import * as
|
|
10425
|
-
var
|
|
10426
|
-
var
|
|
10427
|
-
var
|
|
10428
|
-
|
|
10429
|
-
|
|
10430
|
-
)
|
|
10431
|
-
|
|
10432
|
-
|
|
10433
|
-
const
|
|
10434
|
-
|
|
10435
|
-
|
|
10436
|
-
|
|
10437
|
-
|
|
10438
|
-
|
|
10439
|
-
|
|
10440
|
-
|
|
10441
|
-
|
|
10442
|
-
|
|
10443
|
-
|
|
10444
|
-
|
|
10445
|
-
const zone = zoneText?.trim() || localZone || Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
10446
|
-
const today = wallDate(now, zone);
|
|
10447
|
-
if (!today) return void 0;
|
|
10448
|
-
if (monthWord !== void 0) {
|
|
10449
|
-
const month = MONTHS.indexOf(monthWord.slice(0, 3).toLowerCase());
|
|
10450
|
-
if (month < 0 || !matchesMonthName(monthWord, month)) return void 0;
|
|
10451
|
-
const day = Number(dayText);
|
|
10452
|
-
if (day < 1 || day > 31) return void 0;
|
|
10453
|
-
let at = zonedToEpoch({ year: today.year, month: month + 1, day, hour, minute }, zone);
|
|
10454
|
-
if (at !== void 0 && at <= now.getTime()) {
|
|
10455
|
-
at = zonedToEpoch({ year: today.year + 1, month: month + 1, day, hour, minute }, zone);
|
|
10982
|
+
// src/waitTracker.ts
|
|
10983
|
+
var import_tool_kit5 = __toESM(require_out3(), 1);
|
|
10984
|
+
import * as fs from "fs";
|
|
10985
|
+
import * as path from "path";
|
|
10986
|
+
var SETTLE_MS = 1500;
|
|
10987
|
+
var IDLE_COOLDOWN_MS = 6e4;
|
|
10988
|
+
var STALE_MS = 24 * 60 * 60 * 1e3;
|
|
10989
|
+
var emptyWaitState = () => ({ waits: {}, lastStart: {} });
|
|
10990
|
+
var ANSWERABLE = ["permission_request", "input_request"];
|
|
10991
|
+
function startKind(hookName, input) {
|
|
10992
|
+
if (hookName === "PermissionRequest") return "permission_request";
|
|
10993
|
+
if (hookName !== "Notification") return void 0;
|
|
10994
|
+
const kind = notificationKind((0, import_tool_kit3.getString)(input, ["message"]), (0, import_tool_kit3.getString)(input, ["notification_type", "notificationType"]));
|
|
10995
|
+
return kind === "other" ? void 0 : kind;
|
|
10996
|
+
}
|
|
10997
|
+
function waitEvent(kind, wait, now, endedBy, confidence) {
|
|
10998
|
+
return {
|
|
10999
|
+
eventType: "supervision_wait_ended",
|
|
11000
|
+
severity: "low",
|
|
11001
|
+
metadata: {
|
|
11002
|
+
interruptionKind: kind,
|
|
11003
|
+
waitMs: Math.max(0, Math.round(now - wait.startedAt)),
|
|
11004
|
+
waitEndedBy: endedBy,
|
|
11005
|
+
waitConfidence: wait.maxRequests > 1 && confidence === "inferred" ? "lower_bound" : confidence
|
|
10456
11006
|
}
|
|
10457
|
-
|
|
10458
|
-
}
|
|
10459
|
-
const sameDay = zonedToEpoch({ ...today, hour, minute }, zone);
|
|
10460
|
-
if (sameDay === void 0) return void 0;
|
|
10461
|
-
if (sameDay > now.getTime()) return sameDay;
|
|
10462
|
-
return zonedToEpoch({ ...nextDay(today), hour, minute }, zone);
|
|
10463
|
-
}
|
|
10464
|
-
function resumesAtFor(text, now, localZone) {
|
|
10465
|
-
if (!text) return void 0;
|
|
10466
|
-
const at = parseUsageLimitReset(text, now, localZone);
|
|
10467
|
-
if (at === void 0) return void 0;
|
|
10468
|
-
const ahead = at - now.getTime();
|
|
10469
|
-
if (ahead <= 0 || ahead > MAX_RESUME_AHEAD_MS) return void 0;
|
|
10470
|
-
return Math.round(at / 6e4) * 60;
|
|
11007
|
+
};
|
|
10471
11008
|
}
|
|
10472
|
-
function
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
|
|
11009
|
+
function advanceWait(previous, hookName, input, now) {
|
|
11010
|
+
const state = { waits: { ...previous.waits }, lastStart: { ...previous.lastStart } };
|
|
11011
|
+
const events = [];
|
|
11012
|
+
let suppressInterruption = false;
|
|
11013
|
+
for (const kind of Object.keys(state.waits)) {
|
|
11014
|
+
const wait = state.waits[kind];
|
|
11015
|
+
if (wait && now - wait.startedAt > STALE_MS) delete state.waits[kind];
|
|
11016
|
+
}
|
|
11017
|
+
const opening = startKind(hookName, input);
|
|
11018
|
+
if (opening) {
|
|
11019
|
+
const open = state.waits[opening];
|
|
11020
|
+
const last = state.lastStart[opening];
|
|
11021
|
+
if (open) {
|
|
11022
|
+
if (hookName === "PermissionRequest") {
|
|
11023
|
+
open.requests += 1;
|
|
11024
|
+
open.maxRequests = Math.max(open.maxRequests, open.requests);
|
|
11025
|
+
open.toolName ??= getToolName(input);
|
|
11026
|
+
}
|
|
11027
|
+
if (opening === "idle_prompt") suppressInterruption = true;
|
|
11028
|
+
} else if (opening === "idle_prompt" && last !== void 0 && now - last < IDLE_COOLDOWN_MS) {
|
|
11029
|
+
suppressInterruption = true;
|
|
11030
|
+
} else if (opening !== "idle_prompt" && hookName === "Notification" && last !== void 0 && now - last < SETTLE_MS) {
|
|
11031
|
+
} else {
|
|
11032
|
+
const isRequest = hookName === "PermissionRequest";
|
|
11033
|
+
state.waits[opening] = { startedAt: now, requests: isRequest ? 1 : 0, maxRequests: isRequest ? 1 : 0, ...isRequest && getToolName(input) ? { toolName: getToolName(input) } : {} };
|
|
11034
|
+
state.lastStart[opening] = now;
|
|
11035
|
+
}
|
|
11036
|
+
return { state, events, suppressInterruption };
|
|
10476
11037
|
}
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
|
|
10481
|
-
|
|
10482
|
-
|
|
10483
|
-
|
|
10484
|
-
|
|
10485
|
-
|
|
10486
|
-
|
|
10487
|
-
|
|
10488
|
-
|
|
11038
|
+
const close = (kind, endedBy, confidence) => {
|
|
11039
|
+
const wait = state.waits[kind];
|
|
11040
|
+
if (!wait) return;
|
|
11041
|
+
events.push(waitEvent(kind, wait, now, endedBy, confidence));
|
|
11042
|
+
delete state.waits[kind];
|
|
11043
|
+
};
|
|
11044
|
+
switch (hookName) {
|
|
11045
|
+
case "PreToolUse":
|
|
11046
|
+
case "PermissionDenied": {
|
|
11047
|
+
for (const kind of ANSWERABLE) {
|
|
11048
|
+
const wait = state.waits[kind];
|
|
11049
|
+
if (!wait) continue;
|
|
11050
|
+
if (hookName === "PreToolUse" && now - wait.startedAt < SETTLE_MS) continue;
|
|
11051
|
+
const tool = getToolName(input);
|
|
11052
|
+
if (wait.toolName !== void 0 && tool !== void 0 && tool !== wait.toolName) continue;
|
|
11053
|
+
const outstanding = Math.max(1, wait.requests) - 1;
|
|
11054
|
+
if (outstanding > 0) {
|
|
11055
|
+
wait.requests = outstanding;
|
|
11056
|
+
} else {
|
|
11057
|
+
close(kind, hookName === "PreToolUse" ? "tool_started" : "permission_denied", "inferred");
|
|
11058
|
+
}
|
|
11059
|
+
}
|
|
11060
|
+
break;
|
|
11061
|
+
}
|
|
11062
|
+
case "PostToolUse":
|
|
11063
|
+
case "PostToolUseFailure": {
|
|
11064
|
+
for (const kind of ANSWERABLE) {
|
|
11065
|
+
const wait = state.waits[kind];
|
|
11066
|
+
if (!wait || now - wait.startedAt < SETTLE_MS || wait.requests > 1) continue;
|
|
11067
|
+
close(kind, "tool_finished", "lower_bound");
|
|
11068
|
+
}
|
|
11069
|
+
break;
|
|
11070
|
+
}
|
|
11071
|
+
case "UserPromptSubmit": {
|
|
11072
|
+
for (const kind of ANSWERABLE) close(kind, "prompt_submitted", "upper_bound");
|
|
11073
|
+
close("idle_prompt", "prompt_submitted", "inferred");
|
|
11074
|
+
break;
|
|
11075
|
+
}
|
|
11076
|
+
case "Stop":
|
|
11077
|
+
case "StopFailure": {
|
|
11078
|
+
for (const kind of ANSWERABLE) delete state.waits[kind];
|
|
11079
|
+
break;
|
|
11080
|
+
}
|
|
11081
|
+
case "SessionEnd":
|
|
11082
|
+
state.waits = {};
|
|
11083
|
+
break;
|
|
11084
|
+
default:
|
|
11085
|
+
break;
|
|
11086
|
+
}
|
|
11087
|
+
return { state, events, suppressInterruption };
|
|
10489
11088
|
}
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
|
|
11089
|
+
var stateDir = () => process.env.ASCENDA_STATE_DIR ?? path.join((0, import_tool_kit5.ascendaHome)(), "state");
|
|
11090
|
+
var sanitize = (value) => value.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
11091
|
+
function waitFile(sessionId, agentId) {
|
|
11092
|
+
return path.join(stateDir(), `claude-wait-${sanitize(sessionId)}${agentId ? `-${sanitize(agentId)}` : ""}.json`);
|
|
10493
11093
|
}
|
|
10494
|
-
function
|
|
10495
|
-
let format;
|
|
11094
|
+
function readWaitState(sessionId, agentId) {
|
|
10496
11095
|
try {
|
|
10497
|
-
|
|
10498
|
-
|
|
10499
|
-
hourCycle: "h23",
|
|
10500
|
-
year: "numeric",
|
|
10501
|
-
month: "numeric",
|
|
10502
|
-
day: "numeric",
|
|
10503
|
-
hour: "numeric",
|
|
10504
|
-
minute: "numeric"
|
|
10505
|
-
});
|
|
11096
|
+
const parsed = JSON.parse(fs.readFileSync(waitFile(sessionId, agentId), "utf8"));
|
|
11097
|
+
return { waits: parsed.waits ?? {}, lastStart: parsed.lastStart ?? {} };
|
|
10506
11098
|
} catch {
|
|
10507
|
-
return
|
|
10508
|
-
}
|
|
10509
|
-
const value = (type) => Number(format.formatToParts(epochMs).find((part) => part.type === type)?.value);
|
|
10510
|
-
return { year: value("year"), month: value("month"), day: value("day"), hour: value("hour"), minute: value("minute") };
|
|
10511
|
-
}
|
|
10512
|
-
function zonedToEpoch(time, zone) {
|
|
10513
|
-
const asUtc = Date.UTC(time.year, time.month - 1, time.day, time.hour, time.minute);
|
|
10514
|
-
const check = new Date(asUtc);
|
|
10515
|
-
if (check.getUTCDate() !== time.day) return void 0;
|
|
10516
|
-
let guess = asUtc;
|
|
10517
|
-
for (let pass = 0; pass < 2; pass += 1) {
|
|
10518
|
-
const seen = wallParts(guess, zone);
|
|
10519
|
-
if (!seen) return void 0;
|
|
10520
|
-
const seenUtc = Date.UTC(seen.year, seen.month - 1, seen.day, seen.hour, seen.minute);
|
|
10521
|
-
guess += asUtc - seenUtc;
|
|
11099
|
+
return emptyWaitState();
|
|
10522
11100
|
}
|
|
10523
|
-
return guess;
|
|
10524
11101
|
}
|
|
10525
|
-
function
|
|
10526
|
-
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
|
|
10530
|
-
|
|
10531
|
-
|
|
10532
|
-
|
|
10533
|
-
|
|
10534
|
-
|
|
10535
|
-
path2.join(sources.configDir ?? claudeConfigDir(), "settings.json")
|
|
10536
|
-
];
|
|
10537
|
-
for (const file of files) {
|
|
10538
|
-
const value = readSetting(file, "autoContinueAtUsageLimit");
|
|
10539
|
-
if (value !== void 0) return value === true;
|
|
11102
|
+
function writeWaitState(sessionId, agentId, state) {
|
|
11103
|
+
try {
|
|
11104
|
+
const file = waitFile(sessionId, agentId);
|
|
11105
|
+
if (Object.keys(state.waits).length === 0 && Object.keys(state.lastStart).length === 0) {
|
|
11106
|
+
fs.rmSync(file, { force: true });
|
|
11107
|
+
return;
|
|
11108
|
+
}
|
|
11109
|
+
fs.mkdirSync(stateDir(), { recursive: true });
|
|
11110
|
+
fs.writeFileSync(file, JSON.stringify(state), { encoding: "utf8", mode: 384 });
|
|
11111
|
+
} catch {
|
|
10540
11112
|
}
|
|
10541
|
-
return false;
|
|
10542
11113
|
}
|
|
10543
|
-
function
|
|
11114
|
+
function trackWait(hookName, input, now = Date.now()) {
|
|
11115
|
+
const sessionId = (0, import_tool_kit3.getString)(input, ["session_id", "sessionId"]);
|
|
11116
|
+
if (!sessionId) return { state: emptyWaitState(), events: [], suppressInterruption: false };
|
|
10544
11117
|
try {
|
|
10545
|
-
const
|
|
10546
|
-
|
|
11118
|
+
const agentId = readSubagentId(input);
|
|
11119
|
+
const advance = advanceWait(readWaitState(sessionId, agentId), hookName, input, now);
|
|
11120
|
+
if (hookName === "SessionEnd") {
|
|
11121
|
+
fs.rmSync(waitFile(sessionId, agentId), { force: true });
|
|
11122
|
+
} else {
|
|
11123
|
+
writeWaitState(sessionId, agentId, advance.state);
|
|
11124
|
+
}
|
|
11125
|
+
return advance;
|
|
10547
11126
|
} catch {
|
|
11127
|
+
return { state: emptyWaitState(), events: [], suppressInterruption: false };
|
|
10548
11128
|
}
|
|
10549
|
-
return void 0;
|
|
10550
11129
|
}
|
|
10551
11130
|
|
|
10552
11131
|
// src/cli.ts
|
|
11132
|
+
init_usageLimitReset();
|
|
11133
|
+
init_quotaSnapshot();
|
|
10553
11134
|
init_config();
|
|
10554
11135
|
init_paths();
|
|
10555
11136
|
init_types();
|
|
10556
11137
|
init_hookHealth();
|
|
10557
11138
|
|
|
10558
11139
|
// src/pluginHookSet.ts
|
|
10559
|
-
var
|
|
10560
|
-
import * as
|
|
10561
|
-
import * as
|
|
11140
|
+
var import_tool_kit12 = __toESM(require_out3(), 1);
|
|
11141
|
+
import * as fs5 from "node:fs";
|
|
11142
|
+
import * as path5 from "node:path";
|
|
10562
11143
|
function pluginHookSetStatePath() {
|
|
10563
|
-
return
|
|
11144
|
+
return path5.join((0, import_tool_kit12.ascendaHome)(), "state", "plugin-hook-set.json");
|
|
10564
11145
|
}
|
|
10565
11146
|
function pendingPluginHookSetNotice(options) {
|
|
10566
11147
|
const env = options.env ?? process.env;
|
|
10567
|
-
if (!(0,
|
|
10568
|
-
const registered = (0,
|
|
11148
|
+
if (!(0, import_tool_kit12.readViaPlugin)(env) || env[import_tool_kit12.RELEASE_CHECK_ENV_VAR]?.trim().toLowerCase() === "true") return void 0;
|
|
11149
|
+
const registered = (0, import_tool_kit12.readHookSet)(options.argv ?? process.argv);
|
|
10569
11150
|
if (registered === void 0 || registered >= options.currentSet) return void 0;
|
|
10570
11151
|
const file = options.file ?? pluginHookSetStatePath();
|
|
10571
11152
|
const key = `${registered}->${options.currentSet}`;
|
|
@@ -10574,8 +11155,8 @@ function pendingPluginHookSetNotice(options) {
|
|
|
10574
11155
|
text: `Ascenda note: the Ascenda plugin registers hook set ${registered}, and the code it runs expects set ${options.currentSet}, so some Claude Code events aren't reaching Ascenda. Run \`claude plugin update ascenda@ascenda-one\`, then restart Claude Code. This note appears once.`,
|
|
10575
11156
|
markShown: () => {
|
|
10576
11157
|
try {
|
|
10577
|
-
|
|
10578
|
-
(0,
|
|
11158
|
+
fs5.mkdirSync(path5.dirname(file), { recursive: true, mode: 448 });
|
|
11159
|
+
(0, import_tool_kit12.writeAtomically)(file, `${JSON.stringify({ shown: key })}
|
|
10579
11160
|
`, 384);
|
|
10580
11161
|
} catch {
|
|
10581
11162
|
}
|
|
@@ -10584,7 +11165,7 @@ function pendingPluginHookSetNotice(options) {
|
|
|
10584
11165
|
}
|
|
10585
11166
|
function readShown(file) {
|
|
10586
11167
|
try {
|
|
10587
|
-
const parsed = JSON.parse(
|
|
11168
|
+
const parsed = JSON.parse(fs5.readFileSync(file, "utf8"));
|
|
10588
11169
|
return typeof parsed.shown === "string" ? parsed.shown : void 0;
|
|
10589
11170
|
} catch {
|
|
10590
11171
|
return void 0;
|
|
@@ -10592,13 +11173,13 @@ function readShown(file) {
|
|
|
10592
11173
|
}
|
|
10593
11174
|
|
|
10594
11175
|
// src/liveDoctor.ts
|
|
10595
|
-
var
|
|
11176
|
+
var import_tool_kit16 = __toESM(require_out3(), 1);
|
|
10596
11177
|
init_paths();
|
|
10597
|
-
var
|
|
11178
|
+
var import_tool_kit17 = __toESM(require_out3(), 1);
|
|
10598
11179
|
import * as os3 from "os";
|
|
10599
11180
|
async function localSignalLines(projectDir = process.cwd()) {
|
|
10600
11181
|
const { registrationSummary: registrationSummary2, REGISTERED_EVENT_COUNT: REGISTERED_EVENT_COUNT2 } = await Promise.resolve().then(() => (init_setup(), setup_exports));
|
|
10601
|
-
return (0,
|
|
11182
|
+
return (0, import_tool_kit16.liveSignalDoctorLines)({
|
|
10602
11183
|
displayName: "Claude Code",
|
|
10603
11184
|
tool: "claude_code",
|
|
10604
11185
|
launcher: process.platform === "win32" ? void 0 : hookBinPath(),
|
|
@@ -10631,12 +11212,12 @@ async function runPair() {
|
|
|
10631
11212
|
const { SENDS: SENDS2 } = isClaudeCode ? await Promise.resolve().then(() => (init_setup(), setup_exports)) : { SENDS: [] };
|
|
10632
11213
|
await writeStdout(
|
|
10633
11214
|
`
|
|
10634
|
-
${(0,
|
|
11215
|
+
${(0, import_tool_kit18.renderSetupDisclosure)({ sends: SENDS2, displayName: isClaudeCode ? "Claude Code" : toolType })}
|
|
10635
11216
|
`
|
|
10636
11217
|
);
|
|
10637
|
-
const session = await (0,
|
|
11218
|
+
const session = await (0, import_tool_kit18.createPairingSession)(apiBaseUrl, toolInstallationId, toolType, toolType === ASCENDA_TOOL_TYPE ? "Claude Code" : toolType);
|
|
10638
11219
|
const code = session.deviceCode ?? session.code;
|
|
10639
|
-
const instructions = `${(0,
|
|
11220
|
+
const instructions = `${(0, import_tool_kit18.pairingConfirmLines)(session.qrUrl, code).join("\n")}
|
|
10640
11221
|
`;
|
|
10641
11222
|
await writeStdout(`
|
|
10642
11223
|
${instructions}Waiting for confirmation (expires ${session.expiresAt})...
|
|
@@ -10645,7 +11226,7 @@ ${instructions}Waiting for confirmation (expires ${session.expiresAt})...
|
|
|
10645
11226
|
const deadline = Date.now() + 11 * 60 * 1e3;
|
|
10646
11227
|
while (Date.now() < deadline) {
|
|
10647
11228
|
await new Promise((resolve3) => setTimeout(resolve3, 3e3));
|
|
10648
|
-
const status = await (0,
|
|
11229
|
+
const status = await (0, import_tool_kit18.getPairingStatus)(apiBaseUrl, session.pairingSessionId);
|
|
10649
11230
|
if (status.status === "pending") continue;
|
|
10650
11231
|
if (status.status !== "paired") {
|
|
10651
11232
|
process.stderr.write(`Pairing ${status.status}. Run the command again for a fresh code.
|
|
@@ -10661,12 +11242,12 @@ ${instructions}Waiting for confirmation (expires ${session.expiresAt})...
|
|
|
10661
11242
|
process.exitCode = 1;
|
|
10662
11243
|
return;
|
|
10663
11244
|
}
|
|
10664
|
-
const tokenFilePath = (0,
|
|
10665
|
-
(0,
|
|
11245
|
+
const tokenFilePath = (0, import_tool_kit18.defaultTokenFilePath)(pairedId);
|
|
11246
|
+
(0, import_tool_kit18.persistEventWriteToken)(tokenFilePath, status.eventWriteToken);
|
|
10666
11247
|
writeCredentials({ apiBaseUrl, toolInstallationId: pairedId, pairedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
10667
11248
|
await writeStdout(
|
|
10668
11249
|
`Paired. Write token saved to ${tokenFilePath}
|
|
10669
|
-
Pairing saved to ${(0,
|
|
11250
|
+
Pairing saved to ${(0, import_tool_kit7.credentialsFilePath)()}
|
|
10670
11251
|
|
|
10671
11252
|
Restart Claude Code and events flow. Nothing to add to your shell profile.
|
|
10672
11253
|
|
|
@@ -10692,7 +11273,7 @@ async function runJoin(argv) {
|
|
|
10692
11273
|
`);
|
|
10693
11274
|
return 1;
|
|
10694
11275
|
}
|
|
10695
|
-
return (0,
|
|
11276
|
+
return (0, import_tool_kit18.runStudyJoin)({ apiBaseUrl, eventWriteToken, displayName: "Claude Code", joinCode });
|
|
10696
11277
|
}
|
|
10697
11278
|
async function runSquadron(argv) {
|
|
10698
11279
|
const reference = argv[0];
|
|
@@ -10723,7 +11304,7 @@ async function runSquadron(argv) {
|
|
|
10723
11304
|
return 1;
|
|
10724
11305
|
}
|
|
10725
11306
|
}
|
|
10726
|
-
return (0,
|
|
11307
|
+
return (0, import_tool_kit18.runSquadronJoin)({
|
|
10727
11308
|
apiBaseUrl: config.apiBaseUrl,
|
|
10728
11309
|
eventWriteToken: config.eventWriteToken,
|
|
10729
11310
|
displayName: "Claude Code",
|
|
@@ -10743,7 +11324,7 @@ async function runObject(argv) {
|
|
|
10743
11324
|
`);
|
|
10744
11325
|
return 1;
|
|
10745
11326
|
}
|
|
10746
|
-
return (0,
|
|
11327
|
+
return (0, import_tool_kit18.runStudyObjection)({
|
|
10747
11328
|
apiBaseUrl,
|
|
10748
11329
|
eventWriteToken,
|
|
10749
11330
|
commandPrefix: "npx @ascenda-one/claude-code-hooks",
|
|
@@ -10779,7 +11360,7 @@ async function main() {
|
|
|
10779
11360
|
await runDoctor();
|
|
10780
11361
|
return;
|
|
10781
11362
|
}
|
|
10782
|
-
if (command ===
|
|
11363
|
+
if (command === import_tool_kit19.OUTBOX_FLUSH_COMMAND) {
|
|
10783
11364
|
await runFlush();
|
|
10784
11365
|
return;
|
|
10785
11366
|
}
|
|
@@ -10787,6 +11368,11 @@ async function main() {
|
|
|
10787
11368
|
setupExitCode = runPluginSync();
|
|
10788
11369
|
return;
|
|
10789
11370
|
}
|
|
11371
|
+
if (command === "statusline") {
|
|
11372
|
+
const { runStatusline: runStatusline2 } = await Promise.resolve().then(() => (init_statusline(), statusline_exports));
|
|
11373
|
+
setupExitCode = await runStatusline2();
|
|
11374
|
+
return;
|
|
11375
|
+
}
|
|
10790
11376
|
if (MANAGEMENT_COMMANDS.has(command)) {
|
|
10791
11377
|
const { runSetup: runSetup2 } = await Promise.resolve().then(() => (init_setup(), setup_exports));
|
|
10792
11378
|
setupExitCode = await runSetup2(process.argv.slice(2));
|
|
@@ -10815,28 +11401,33 @@ async function main() {
|
|
|
10815
11401
|
await writeStdout(JSON.stringify({
|
|
10816
11402
|
hookSpecificOutput: { hookEventName: hookName, additionalContext: contextParts.join("\n\n") }
|
|
10817
11403
|
}));
|
|
10818
|
-
if (pending) (0,
|
|
11404
|
+
if (pending) (0, import_tool_kit18.markFailureNotified)(pending.stateFilePath, pending.state);
|
|
10819
11405
|
release?.markShown();
|
|
10820
11406
|
}
|
|
10821
11407
|
await emitLive(hookName, input);
|
|
10822
|
-
const effortSessionId = (0,
|
|
11408
|
+
const effortSessionId = (0, import_tool_kit18.getString)(input, ["session_id", "sessionId"]);
|
|
10823
11409
|
const mappedEvents = mapClaudeEvent(hookName, input, {
|
|
10824
|
-
lastSentEffortLevel: (0,
|
|
10825
|
-
lastSentModelId: (0,
|
|
11410
|
+
lastSentEffortLevel: (0, import_tool_kit21.readSentEffortLevel)(CLAUDE_EFFORT_STATE_AGENT, effortSessionId),
|
|
11411
|
+
lastSentModelId: (0, import_tool_kit22.readSentModelId)(CLAUDE_EFFORT_STATE_AGENT, effortSessionId)
|
|
10826
11412
|
});
|
|
11413
|
+
const wait = trackWait(hookName, input);
|
|
11414
|
+
if (wait.suppressInterruption) {
|
|
11415
|
+
for (let i = mappedEvents.length - 1; i >= 0; i--) if (mappedEvents[i].eventType === "supervision_interruption") mappedEvents.splice(i, 1);
|
|
11416
|
+
}
|
|
11417
|
+
mappedEvents.push(...wait.events);
|
|
10827
11418
|
const effortSent = sentEffortLevel(mappedEvents);
|
|
10828
|
-
if (effortSent) (0,
|
|
11419
|
+
if (effortSent) (0, import_tool_kit21.recordSentEffortLevel)(CLAUDE_EFFORT_STATE_AGENT, effortSessionId, effortSent);
|
|
10829
11420
|
const modelSent = sentModelId(mappedEvents);
|
|
10830
|
-
if (modelSent) (0,
|
|
11421
|
+
if (modelSent) (0, import_tool_kit22.recordSentModelId)(CLAUDE_EFFORT_STATE_AGENT, effortSessionId, modelSent);
|
|
10831
11422
|
if (hookName === "SessionEnd") {
|
|
10832
|
-
(0,
|
|
10833
|
-
(0,
|
|
11423
|
+
(0, import_tool_kit21.clearSentEffortLevel)(CLAUDE_EFFORT_STATE_AGENT, effortSessionId);
|
|
11424
|
+
(0, import_tool_kit22.clearSentModelId)(CLAUDE_EFFORT_STATE_AGENT, effortSessionId);
|
|
10834
11425
|
}
|
|
10835
11426
|
if (!mappedEvents.length) return;
|
|
10836
|
-
const workContext = (0,
|
|
11427
|
+
const workContext = (0, import_tool_kit18.deriveWorkContext)((0, import_tool_kit18.getString)(input, ["cwd"]) ?? process.cwd());
|
|
10837
11428
|
if (workContext) {
|
|
10838
|
-
(0,
|
|
10839
|
-
(0,
|
|
11429
|
+
(0, import_tool_kit18.recordWorkContext)(workContext);
|
|
11430
|
+
(0, import_tool_kit18.recordForgeProjectAlias)(workContext);
|
|
10840
11431
|
}
|
|
10841
11432
|
let config;
|
|
10842
11433
|
try {
|
|
@@ -10844,20 +11435,20 @@ async function main() {
|
|
|
10844
11435
|
} catch (error) {
|
|
10845
11436
|
const unpaired = localOnlyInstall();
|
|
10846
11437
|
if (!unpaired && error instanceof MissingInstallationIdError) journalSkippedSend(error);
|
|
10847
|
-
const logFile = (0,
|
|
11438
|
+
const logFile = (0, import_tool_kit18.resolveEventLogPath)({ localOnly: unpaired });
|
|
10848
11439
|
if (!logFile) {
|
|
10849
11440
|
if (unpaired) return;
|
|
10850
11441
|
throw error;
|
|
10851
11442
|
}
|
|
10852
11443
|
for (const event of mappedEvents) {
|
|
10853
|
-
logUnsent(logFile, event, workContext, (0,
|
|
11444
|
+
logUnsent(logFile, event, workContext, (0, import_tool_kit18.getString)(input, ["session_id", "sessionId"]) ?? null);
|
|
10854
11445
|
}
|
|
10855
11446
|
if (!unpaired && !(error instanceof MissingInstallationIdError)) throw error;
|
|
10856
11447
|
return;
|
|
10857
11448
|
}
|
|
10858
11449
|
config.workspaceHash ??= workContext?.workspaceHash ?? null;
|
|
10859
11450
|
config.projectHash ??= workContext?.projectHash ?? null;
|
|
10860
|
-
config.sessionId ??= (0,
|
|
11451
|
+
config.sessionId ??= (0, import_tool_kit18.getString)(input, ["session_id", "sessionId"]) ?? null;
|
|
10861
11452
|
const client = new AscendaClient(config);
|
|
10862
11453
|
if (hookName === "SessionEnd") {
|
|
10863
11454
|
for (const event of mappedEvents) {
|
|
@@ -10865,11 +11456,11 @@ async function main() {
|
|
|
10865
11456
|
}
|
|
10866
11457
|
return;
|
|
10867
11458
|
}
|
|
10868
|
-
if (!(0,
|
|
11459
|
+
if (!(0, import_tool_kit19.hookDeliveryInline)() && claudeRuntime() !== "cloud") {
|
|
10869
11460
|
for (const event of mappedEvents) {
|
|
10870
11461
|
if (!client.queue(event)) console.error("Ascenda telemetry not kept: the event could not be written to the outbox.");
|
|
10871
11462
|
}
|
|
10872
|
-
(0,
|
|
11463
|
+
(0, import_tool_kit19.startBackgroundFlush)({ outboxFilePath: client.outboxFilePath() });
|
|
10873
11464
|
return;
|
|
10874
11465
|
}
|
|
10875
11466
|
for (const event of mappedEvents) {
|
|
@@ -10882,8 +11473,8 @@ async function main() {
|
|
|
10882
11473
|
var PLUGIN_SYNC_COMMAND = "plugin-sync";
|
|
10883
11474
|
function runPluginSync() {
|
|
10884
11475
|
try {
|
|
10885
|
-
const outcome = (0,
|
|
10886
|
-
console.log((0,
|
|
11476
|
+
const outcome = (0, import_tool_kit20.installPluginBundle)({ name: "claude-code-hooks" });
|
|
11477
|
+
console.log((0, import_tool_kit20.describePluginBundleOutcome)(outcome, (0, import_tool_kit20.pluginBundlePaths)("claude-code-hooks").bundle));
|
|
10887
11478
|
return 0;
|
|
10888
11479
|
} catch (error) {
|
|
10889
11480
|
console.error(`plugin-sync: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -10900,7 +11491,7 @@ async function runFlush() {
|
|
|
10900
11491
|
await new AscendaClient(config).flushOutbox();
|
|
10901
11492
|
}
|
|
10902
11493
|
function journalSkippedSend(error) {
|
|
10903
|
-
(0,
|
|
11494
|
+
(0, import_tool_kit18.recordSendOutcome)(resolveStateFilePath(), (0, import_tool_kit18.unresolvedToolInstallationId)(ASCENDA_TOOL_TYPE), "skipped_no_installation_id", {
|
|
10904
11495
|
detail: error.candidates.length === 0 ? "no ASCENDA_TOOL_INSTALLATION_ID, no credentials.json pairing, no claude_code token file" : `no ASCENDA_TOOL_INSTALLATION_ID, no credentials.json pairing, ${error.candidates.length} claude_code token files (${error.candidates.join(", ")})`
|
|
10905
11496
|
});
|
|
10906
11497
|
}
|
|
@@ -10919,25 +11510,25 @@ async function emitLive(hookName, input) {
|
|
|
10919
11510
|
}
|
|
10920
11511
|
if (!event) return;
|
|
10921
11512
|
try {
|
|
10922
|
-
const prompt = event === "prompt_submitted" ? (0,
|
|
10923
|
-
const promptSource = event === "prompt_submitted" ? (0,
|
|
11513
|
+
const prompt = event === "prompt_submitted" ? (0, import_tool_kit18.getString)(input, ["prompt", "userPrompt", "message"]) ?? (0, import_tool_kit18.getNestedString)(input, [["payload", "prompt"], ["payload", "message"]]) : void 0;
|
|
11514
|
+
const promptSource = event === "prompt_submitted" ? (0, import_tool_kit18.getString)(input, ["promptSource", "prompt_source"]) : void 0;
|
|
10924
11515
|
const queued = promptSource === void 0 ? void 0 : promptSource === "queued";
|
|
10925
11516
|
const backgroundTasks = event === "stop" ? countBackgroundTasks(input) : void 0;
|
|
10926
|
-
const errorKind = hookName === "StopFailure" && event === "halted" ? (0,
|
|
11517
|
+
const errorKind = hookName === "StopFailure" && event === "halted" ? (0, import_tool_kit18.getString)(input, ["error"]) === "rate_limit" ? "rate_limit" : "error" : void 0;
|
|
10927
11518
|
const resumesAt = errorKind === "rate_limit" ? usageLimitResumesAt(input) : void 0;
|
|
10928
|
-
const agent = (0,
|
|
10929
|
-
const hookSet = (0,
|
|
10930
|
-
const viaPlugin = (0,
|
|
10931
|
-
await (0,
|
|
11519
|
+
const agent = (0, import_tool_kit18.findAgentProcess)(import_tool_kit18.AGENT_PROCESS.claude_code);
|
|
11520
|
+
const hookSet = (0, import_tool_kit18.readHookSet)(process.argv);
|
|
11521
|
+
const viaPlugin = (0, import_tool_kit18.readViaPlugin)(process.env);
|
|
11522
|
+
await (0, import_tool_kit18.emitLiveSignal)({
|
|
10932
11523
|
tool: process.env.ASCENDA_TOOL_TYPE ?? "claude_code",
|
|
10933
11524
|
// Concurrent sessions must count as separate streams for the X gauge.
|
|
10934
11525
|
// Without a session id every window collapses into one, so fall back to
|
|
10935
11526
|
// this process's parent — still per-session in practice, since Claude
|
|
10936
11527
|
// Code spawns hooks from the session process.
|
|
10937
|
-
session: (0,
|
|
10938
|
-
...(0,
|
|
11528
|
+
session: (0, import_tool_kit18.getString)(input, ["session_id", "sessionId"]) ?? process.env.ASCENDA_SESSION_ID ?? `ppid-${process.ppid}`,
|
|
11529
|
+
...(0, import_tool_kit18.livePidFields)(agent),
|
|
10939
11530
|
event,
|
|
10940
|
-
...prompt !== void 0 ? { sizeBucket: (0,
|
|
11531
|
+
...prompt !== void 0 ? { sizeBucket: (0, import_tool_kit18.bucketPromptSize)(prompt) } : {},
|
|
10941
11532
|
...queued !== void 0 ? { queued } : {},
|
|
10942
11533
|
...backgroundTasks !== void 0 ? { backgroundTasks } : {},
|
|
10943
11534
|
...hookSet !== void 0 ? { hookSet } : {},
|
|
@@ -10949,13 +11540,15 @@ async function emitLive(hookName, input) {
|
|
|
10949
11540
|
}
|
|
10950
11541
|
}
|
|
10951
11542
|
function usageLimitResumesAt(input) {
|
|
10952
|
-
const projectDir = process.env.CLAUDE_PROJECT_DIR ?? (0,
|
|
11543
|
+
const projectDir = process.env.CLAUDE_PROJECT_DIR ?? (0, import_tool_kit18.getString)(input, ["cwd"]);
|
|
10953
11544
|
if (!autoContinueEnabled({ projectDir })) return void 0;
|
|
10954
11545
|
const now = /* @__PURE__ */ new Date();
|
|
11546
|
+
const reported = resumesAtFromQuota(readQuota(), now);
|
|
11547
|
+
if (reported !== void 0) return reported;
|
|
10955
11548
|
const texts = [
|
|
10956
|
-
(0,
|
|
10957
|
-
(0,
|
|
10958
|
-
(0,
|
|
11549
|
+
(0, import_tool_kit18.getString)(input, ["error_details"]),
|
|
11550
|
+
(0, import_tool_kit18.getNestedString)(input, [["error_details", "message"]]),
|
|
11551
|
+
(0, import_tool_kit18.getString)(input, ["last_assistant_message"])
|
|
10959
11552
|
];
|
|
10960
11553
|
for (const text of texts) {
|
|
10961
11554
|
const at = resumesAtFor(text, now);
|
|
@@ -10982,8 +11575,8 @@ function pendingFailureNotice(hookName) {
|
|
|
10982
11575
|
return void 0;
|
|
10983
11576
|
}
|
|
10984
11577
|
const stateFilePath = resolveStateFilePath(toolInstallationId);
|
|
10985
|
-
const state = (0,
|
|
10986
|
-
if (!(0,
|
|
11578
|
+
const state = (0, import_tool_kit18.readCollectorState)(stateFilePath);
|
|
11579
|
+
if (!(0, import_tool_kit18.shouldAnnounceFailure)(state) || !state) return void 0;
|
|
10987
11580
|
const since = state.lastSuccessAt ? `since ${state.lastSuccessAt}` : "and has never succeeded on this machine";
|
|
10988
11581
|
return {
|
|
10989
11582
|
text: `Ascenda note: work telemetry has not been reaching Ascenda ${since} (${describeOutcome(state)}). Your work is unaffected and nothing was lost from this session. Run \`npx @ascenda-one/claude-code-hooks doctor\` for details, or \`npx @ascenda-one/claude-code-hooks pair\` to reconnect. This note appears once.`,
|
|
@@ -10994,8 +11587,8 @@ function pendingFailureNotice(hookName) {
|
|
|
10994
11587
|
function pendingUpdateNotice(hookName, input) {
|
|
10995
11588
|
if (hookName !== "SessionStart" || !isNewSessionStart(input)) return void 0;
|
|
10996
11589
|
try {
|
|
10997
|
-
if (!(0,
|
|
10998
|
-
return (0,
|
|
11590
|
+
if (!(0, import_tool_kit19.runsFromInstalledBundle)() || localOnlyInstall()) return void 0;
|
|
11591
|
+
return (0, import_tool_kit19.pendingReleaseNotice)({ setupCommand: "npx -y @ascenda-one/claude-code-hooks setup", agentName: "Claude Code" });
|
|
10999
11592
|
} catch {
|
|
11000
11593
|
return void 0;
|
|
11001
11594
|
}
|
|
@@ -11032,7 +11625,7 @@ function writeStdout(text) {
|
|
|
11032
11625
|
});
|
|
11033
11626
|
}
|
|
11034
11627
|
async function runDoctor() {
|
|
11035
|
-
const ui = (0,
|
|
11628
|
+
const ui = (0, import_tool_kit19.terminalStyle)();
|
|
11036
11629
|
const lines = [ui.bold("Ascenda doctor"), ""];
|
|
11037
11630
|
try {
|
|
11038
11631
|
lines.push(...await localSignalLines(process.env.CLAUDE_PROJECT_DIR ?? process.cwd()), "");
|
|
@@ -11040,7 +11633,7 @@ async function runDoctor() {
|
|
|
11040
11633
|
lines.push(` Live signal (could not be checked: ${error instanceof Error ? error.message : String(error)})`, "");
|
|
11041
11634
|
}
|
|
11042
11635
|
const unpaired = localOnlyInstall();
|
|
11043
|
-
lines.push(` ${ui.bold("Local events")} ${(0,
|
|
11636
|
+
lines.push(` ${ui.bold("Local events")} ${(0, import_tool_kit18.describeEventLog)((0, import_tool_kit18.resolveEventLog)({ localOnly: unpaired }), "npx @ascenda-one/claude-code-hooks setup")}`, "");
|
|
11044
11637
|
lines.push(unpaired ? ` ${ui.bold("Account sync")} ${ui.dim("(optional; this install isn't paired)")}` : ` ${ui.bold("Account sync")} ${ui.dim("(Telemetry)")}`);
|
|
11045
11638
|
const telemetryStart = lines.length;
|
|
11046
11639
|
const finish = async () => {
|
|
@@ -11067,14 +11660,14 @@ async function runDoctor() {
|
|
|
11067
11660
|
const { toolInstallationId } = resolved;
|
|
11068
11661
|
lines.push(` Installation id ${toolInstallationId}`);
|
|
11069
11662
|
lines.push(` Id source ${describeIdSource(resolved)}`);
|
|
11070
|
-
const tokenFilePath = process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0,
|
|
11663
|
+
const tokenFilePath = process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0, import_tool_kit18.defaultTokenFilePath)(toolInstallationId);
|
|
11071
11664
|
lines.push(` Token file ${tokenFilePath}`);
|
|
11072
11665
|
lines.push(` Token ${describeToken(tokenFilePath, unpaired)}`);
|
|
11073
|
-
const hasToken =
|
|
11666
|
+
const hasToken = fs8.existsSync(tokenFilePath) || Boolean(process.env.ASCENDA_EVENT_WRITE_TOKEN);
|
|
11074
11667
|
lines.push(` Mode ${unpaired ? "not paired. The live signal works; nothing is sent to Ascenda's servers" : hasToken ? "paired \u2014 local features and telemetry active" : "paired, but no token on this machine \u2014 local features active, nothing can be sent"}`);
|
|
11075
11668
|
const stateFilePath = resolveStateFilePath(toolInstallationId);
|
|
11076
11669
|
lines.push(` Journal ${stateFilePath}`);
|
|
11077
|
-
const state = (0,
|
|
11670
|
+
const state = (0, import_tool_kit18.readCollectorState)(stateFilePath);
|
|
11078
11671
|
if (!state) {
|
|
11079
11672
|
lines.push(unpaired ? " Last outcome (none \u2014 nothing is sent from an install with no pairing)" : " Last outcome (no journal yet \u2014 no send attempted since this version was installed)");
|
|
11080
11673
|
} else {
|
|
@@ -11111,7 +11704,7 @@ function markTelemetryLine(ui, line, unpaired) {
|
|
|
11111
11704
|
const label = line.slice(2, 24).trim();
|
|
11112
11705
|
const value = line.slice(24);
|
|
11113
11706
|
const failed = /FAILED|missing|no token for|rejected/.test(value);
|
|
11114
|
-
const row = (0,
|
|
11707
|
+
const row = (0, import_tool_kit17.doctorRow)(ui, failed ? "bad" : /^(paired —|OK)/.test(value) ? "ok" : "info", label, value);
|
|
11115
11708
|
return unpaired ? ui.dim(row) : row;
|
|
11116
11709
|
}
|
|
11117
11710
|
async function liveRoundTrip() {
|
|
@@ -11132,13 +11725,13 @@ function describeIdSource(resolved) {
|
|
|
11132
11725
|
case "credentials":
|
|
11133
11726
|
return "credentials file (~/.ascenda/credentials.json)";
|
|
11134
11727
|
case "disk":
|
|
11135
|
-
return `disk (token file ${(0,
|
|
11728
|
+
return `disk (token file ${(0, import_tool_kit18.defaultTokenFilePath)(resolved.toolInstallationId)})`;
|
|
11136
11729
|
}
|
|
11137
11730
|
}
|
|
11138
11731
|
function skippedSendLines(alreadyShown) {
|
|
11139
11732
|
const stateFilePath = resolveStateFilePath();
|
|
11140
11733
|
if (stateFilePath === alreadyShown) return [];
|
|
11141
|
-
const state = (0,
|
|
11734
|
+
const state = (0, import_tool_kit18.readCollectorState)(stateFilePath);
|
|
11142
11735
|
if (!state) return [];
|
|
11143
11736
|
const since = state.failingSince ? ` since ${state.failingSince}` : "";
|
|
11144
11737
|
return [
|
|
@@ -11150,7 +11743,7 @@ function skippedSendLines(alreadyShown) {
|
|
|
11150
11743
|
function outboxLines(toolInstallationId, state) {
|
|
11151
11744
|
const outboxFilePath = resolveOutboxFilePath(toolInstallationId);
|
|
11152
11745
|
const lines = [` Outbox ${outboxFilePath}`];
|
|
11153
|
-
const summary = (0,
|
|
11746
|
+
const summary = (0, import_tool_kit18.readOutboxSummary)(outboxFilePath);
|
|
11154
11747
|
if (!summary || summary.depth === 0) {
|
|
11155
11748
|
lines.push(" Outbox depth 0 (nothing waiting)");
|
|
11156
11749
|
} else {
|
|
@@ -11160,8 +11753,8 @@ function outboxLines(toolInstallationId, state) {
|
|
|
11160
11753
|
if (summary && summary.unreadableLines > 0) {
|
|
11161
11754
|
lines.push(` Outbox unreadable ${summary.unreadableLines} line(s) did not parse \u2014 discarded and journaled on the next hook`);
|
|
11162
11755
|
}
|
|
11163
|
-
lines.push(` Outbox drain ${(0,
|
|
11164
|
-
lines.push(` Delivery ${claudeRuntime() === "cloud" ? "inline (hosted session)" : (0,
|
|
11756
|
+
lines.push(` Outbox drain ${(0, import_tool_kit18.outboxDrainEnabled)() ? "on (queued events are replayed, oldest first)" : "off \u2014 queued events are kept and bounded, not sent"} \u2014 ${import_tool_kit18.OUTBOX_DRAIN_ENV_VAR}`);
|
|
11757
|
+
lines.push(` Delivery ${claudeRuntime() === "cloud" ? "inline (hosted session)" : (0, import_tool_kit19.hookDeliveryInline)() ? `inline \u2014 ${import_tool_kit19.HOOK_DELIVERY_ENV_VAR} or ${import_tool_kit18.OUTBOX_DRAIN_ENV_VAR}` : "background sender (the hook queues and returns)"}`);
|
|
11165
11758
|
const discarded = state?.outboxDiscarded;
|
|
11166
11759
|
if (discarded) {
|
|
11167
11760
|
const reasons = Object.entries(discarded.lastReasons).map(([reason, count]) => `${count} ${reason}`).join(", ");
|
|
@@ -11181,11 +11774,11 @@ function describeAge2(isoTimestamp) {
|
|
|
11181
11774
|
}
|
|
11182
11775
|
function describeToken(tokenFilePath, unpaired) {
|
|
11183
11776
|
try {
|
|
11184
|
-
if (!
|
|
11777
|
+
if (!fs8.existsSync(tokenFilePath)) {
|
|
11185
11778
|
if (process.env.ASCENDA_EVENT_WRITE_TOKEN) return "from ASCENDA_EVENT_WRITE_TOKEN (no file)";
|
|
11186
11779
|
return unpaired ? "none \u2014 this install has no pairing" : "MISSING \u2014 run `pair`";
|
|
11187
11780
|
}
|
|
11188
|
-
const stat =
|
|
11781
|
+
const stat = fs8.statSync(tokenFilePath);
|
|
11189
11782
|
const ageDays = Math.floor((Date.now() - stat.mtimeMs) / 864e5);
|
|
11190
11783
|
return `present, last written ${stat.mtime.toISOString()} (${ageDays}d ago)`;
|
|
11191
11784
|
} catch (error) {
|
|
@@ -11193,7 +11786,7 @@ function describeToken(tokenFilePath, unpaired) {
|
|
|
11193
11786
|
}
|
|
11194
11787
|
}
|
|
11195
11788
|
function logUnsent(logFile, event, workContext, sessionId) {
|
|
11196
|
-
const payload = (0,
|
|
11789
|
+
const payload = (0, import_tool_kit18.buildEventPayload)({
|
|
11197
11790
|
toolInstallationId: `${ASCENDA_TOOL_TYPE}:unpaired`,
|
|
11198
11791
|
source: "claude_code",
|
|
11199
11792
|
// The payload's session, same as a delivered row — this log exists so
|
|
@@ -11204,7 +11797,7 @@ function logUnsent(logFile, event, workContext, sessionId) {
|
|
|
11204
11797
|
workspaceHash: envOverride("ASCENDA_WORKSPACE_HASH") ?? workContext?.workspaceHash ?? null,
|
|
11205
11798
|
projectHash: envOverride("ASCENDA_PROJECT_HASH") ?? workContext?.projectHash ?? null
|
|
11206
11799
|
}, event);
|
|
11207
|
-
(0,
|
|
11800
|
+
(0, import_tool_kit18.appendEventLog)(logFile, { loggedAt: (/* @__PURE__ */ new Date()).toISOString(), delivery: "not_sent", payload });
|
|
11208
11801
|
}
|
|
11209
11802
|
async function readJsonFromStdin() {
|
|
11210
11803
|
const chunks = [];
|