@ascenda-one/claude-code-hooks 0.1.33 → 0.1.34
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 +38 -26
- package/dist/cli.js +1412 -420
- package/dist/cli.js.map +1 -1
- package/dist/hookHealth.js +21 -0
- package/dist/hookHealth.js.map +1 -0
- package/dist/launcher.js +14 -0
- package/dist/launcher.js.map +1 -0
- package/dist/liveDoctor.js +27 -0
- package/dist/liveDoctor.js.map +1 -0
- package/dist/liveEvent.js +8 -0
- package/dist/liveEvent.js.map +1 -1
- package/dist/paths.js +30 -1
- package/dist/paths.js.map +1 -1
- package/dist/setup.js +222 -90
- package/dist/setup.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -968,7 +968,7 @@ var require_collectorVersion = __commonJS({
|
|
|
968
968
|
exports.COLLECTOR_VERSION = exports.UNRELEASED_COLLECTOR_VERSION = void 0;
|
|
969
969
|
exports.describeCollectorVersion = describeCollectorVersion2;
|
|
970
970
|
exports.UNRELEASED_COLLECTOR_VERSION = "unreleased";
|
|
971
|
-
exports.COLLECTOR_VERSION = "0.1.
|
|
971
|
+
exports.COLLECTOR_VERSION = "0.1.34" ? "0.1.34" : exports.UNRELEASED_COLLECTOR_VERSION;
|
|
972
972
|
function describeCollectorVersion2(version = exports.COLLECTOR_VERSION) {
|
|
973
973
|
return version === exports.UNRELEASED_COLLECTOR_VERSION ? `${version} (built from a checkout, not a release)` : version;
|
|
974
974
|
}
|
|
@@ -1022,7 +1022,7 @@ var require_eventLog = __commonJS({
|
|
|
1022
1022
|
exports.resolveEventLogPath = resolveEventLogPath2;
|
|
1023
1023
|
exports.appendEventLog = appendEventLog2;
|
|
1024
1024
|
var fs5 = __importStar(__require("fs"));
|
|
1025
|
-
var
|
|
1025
|
+
var os5 = __importStar(__require("os"));
|
|
1026
1026
|
var path4 = __importStar(__require("path"));
|
|
1027
1027
|
exports.EVENT_LOG_ENV_VAR = "ASCENDA_EVENT_LOG_FILE";
|
|
1028
1028
|
var MAX_BYTES = 5 * 1024 * 1024;
|
|
@@ -1031,9 +1031,9 @@ var require_eventLog = __commonJS({
|
|
|
1031
1031
|
if (!value)
|
|
1032
1032
|
return void 0;
|
|
1033
1033
|
if (value === "~")
|
|
1034
|
-
return
|
|
1034
|
+
return os5.homedir();
|
|
1035
1035
|
if (value.startsWith("~/"))
|
|
1036
|
-
return path4.join(
|
|
1036
|
+
return path4.join(os5.homedir(), value.slice(2));
|
|
1037
1037
|
return path4.resolve(value);
|
|
1038
1038
|
}
|
|
1039
1039
|
function resolveEventLogPath2() {
|
|
@@ -1366,9 +1366,9 @@ var require_tokenStore = __commonJS({
|
|
|
1366
1366
|
exports.readTokenFile = readTokenFile3;
|
|
1367
1367
|
exports.sanitizeFilePart = sanitizeFilePart;
|
|
1368
1368
|
var fs5 = __importStar(__require("fs"));
|
|
1369
|
-
var
|
|
1369
|
+
var os5 = __importStar(__require("os"));
|
|
1370
1370
|
var path4 = __importStar(__require("path"));
|
|
1371
|
-
function ascendaHome3(home =
|
|
1371
|
+
function ascendaHome3(home = os5.homedir()) {
|
|
1372
1372
|
return process.env.ASCENDA_HOME ?? path4.join(home, ".ascenda");
|
|
1373
1373
|
}
|
|
1374
1374
|
function defaultTokenFilePath4(toolInstallationId) {
|
|
@@ -2336,11 +2336,11 @@ var require_contextRegistry = __commonJS({
|
|
|
2336
2336
|
exports.recordWorkContext = recordWorkContext2;
|
|
2337
2337
|
exports.recordWorkContextAlias = recordWorkContextAlias;
|
|
2338
2338
|
var fs5 = __importStar(__require("fs"));
|
|
2339
|
-
var
|
|
2339
|
+
var os5 = __importStar(__require("os"));
|
|
2340
2340
|
var path4 = __importStar(__require("path"));
|
|
2341
2341
|
var MAX_PATHS_PER_ENTRY = 8;
|
|
2342
2342
|
function workContextRegistryFilePath() {
|
|
2343
|
-
return path4.join(
|
|
2343
|
+
return path4.join(os5.homedir(), ".ascenda", "work-contexts.json");
|
|
2344
2344
|
}
|
|
2345
2345
|
function readWorkContextRegistry(registryFilePath = workContextRegistryFilePath()) {
|
|
2346
2346
|
try {
|
|
@@ -3677,6 +3677,771 @@ var require_setupDisclosure = __commonJS({
|
|
|
3677
3677
|
}
|
|
3678
3678
|
});
|
|
3679
3679
|
|
|
3680
|
+
// ../packages/tool-kit/out/hookRunner.js
|
|
3681
|
+
var require_hookRunner = __commonJS({
|
|
3682
|
+
"../packages/tool-kit/out/hookRunner.js"(exports) {
|
|
3683
|
+
"use strict";
|
|
3684
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
3685
|
+
if (k2 === void 0) k2 = k;
|
|
3686
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
3687
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
3688
|
+
desc = { enumerable: true, get: function() {
|
|
3689
|
+
return m[k];
|
|
3690
|
+
} };
|
|
3691
|
+
}
|
|
3692
|
+
Object.defineProperty(o, k2, desc);
|
|
3693
|
+
} : function(o, m, k, k2) {
|
|
3694
|
+
if (k2 === void 0) k2 = k;
|
|
3695
|
+
o[k2] = m[k];
|
|
3696
|
+
});
|
|
3697
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
3698
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
3699
|
+
} : function(o, v) {
|
|
3700
|
+
o["default"] = v;
|
|
3701
|
+
});
|
|
3702
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
3703
|
+
var ownKeys = function(o) {
|
|
3704
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
3705
|
+
var ar = [];
|
|
3706
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
3707
|
+
return ar;
|
|
3708
|
+
};
|
|
3709
|
+
return ownKeys(o);
|
|
3710
|
+
};
|
|
3711
|
+
return function(mod) {
|
|
3712
|
+
if (mod && mod.__esModule) return mod;
|
|
3713
|
+
var result = {};
|
|
3714
|
+
if (mod != null) {
|
|
3715
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
3716
|
+
}
|
|
3717
|
+
__setModuleDefault(result, mod);
|
|
3718
|
+
return result;
|
|
3719
|
+
};
|
|
3720
|
+
}();
|
|
3721
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3722
|
+
exports.hookRunnerPaths = hookRunnerPaths;
|
|
3723
|
+
exports.hookLauncherScript = hookLauncherScript2;
|
|
3724
|
+
exports.installHookRunner = installHookRunner2;
|
|
3725
|
+
exports.removeHookRunner = removeHookRunner;
|
|
3726
|
+
exports.hookRunnerCommand = hookRunnerCommand2;
|
|
3727
|
+
exports.lastHookPath = lastHookPath;
|
|
3728
|
+
exports.stampLastHook = stampLastHook2;
|
|
3729
|
+
exports.readLastHook = readLastHook2;
|
|
3730
|
+
exports.describeAge = describeAge3;
|
|
3731
|
+
exports.resolveHookNode = resolveHookNode2;
|
|
3732
|
+
exports.tidyHomePath = tidyHomePath;
|
|
3733
|
+
var child_process_1 = __require("child_process");
|
|
3734
|
+
var fs5 = __importStar(__require("fs"));
|
|
3735
|
+
var path4 = __importStar(__require("path"));
|
|
3736
|
+
var tokenStore_1 = require_tokenStore();
|
|
3737
|
+
function hookRunnerPaths(binaryName) {
|
|
3738
|
+
const launcher = path4.join((0, tokenStore_1.ascendaHome)(), "bin", binaryName);
|
|
3739
|
+
return { launcher, bundle: `${launcher}.mjs`, record: `${launcher}.node`, noNode: `${launcher}.no-node` };
|
|
3740
|
+
}
|
|
3741
|
+
var LAUNCHER_MANAGEMENT_COMMANDS = ["setup", "install", "status", "uninstall", "doctor", "pair", "join", "object", "-h", "--help"];
|
|
3742
|
+
function hookLauncherScript2(options) {
|
|
3743
|
+
const { binaryName, setupCommand, loudEvent } = options;
|
|
3744
|
+
return [
|
|
3745
|
+
"#!/bin/sh",
|
|
3746
|
+
`# Ascenda hook launcher (${binaryName}). Written by \`setup\`, replaced by the`,
|
|
3747
|
+
"# next one; edits here are lost. Finds a Node to run the hook bundle beside it.",
|
|
3748
|
+
"",
|
|
3749
|
+
'dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) || exit 0',
|
|
3750
|
+
`bundle="$dir/${binaryName}.mjs"`,
|
|
3751
|
+
`record="$dir/${binaryName}.node"`,
|
|
3752
|
+
`missing="$dir/${binaryName}.no-node"`,
|
|
3753
|
+
"",
|
|
3754
|
+
'runs() { [ -n "$1" ] && [ -f "$1" ] && [ -x "$1" ]; }',
|
|
3755
|
+
"",
|
|
3756
|
+
"# The hook bundle needs Node 20 or newer. Checked only while searching, so",
|
|
3757
|
+
"# the recorded path costs nothing to reuse.",
|
|
3758
|
+
"recent() {",
|
|
3759
|
+
` runs "$1" && "$1" -e 'process.exit(parseInt(process.versions.node, 10) >= 20 ? 0 : 1)' >/dev/null 2>&1`,
|
|
3760
|
+
"}",
|
|
3761
|
+
"",
|
|
3762
|
+
"newest_nvm() {",
|
|
3763
|
+
' [ -d "$HOME/.nvm/versions/node" ] || return 0',
|
|
3764
|
+
` ls "$HOME/.nvm/versions/node" 2>/dev/null | sed 's/^v//' | sort -t. -k1,1n -k2,2n -k3,3n | tail -n 1 | sed 's/^/v/'`,
|
|
3765
|
+
"}",
|
|
3766
|
+
"",
|
|
3767
|
+
'node=""',
|
|
3768
|
+
"how=recorded",
|
|
3769
|
+
'[ -r "$record" ] && IFS= read -r node < "$record"',
|
|
3770
|
+
"",
|
|
3771
|
+
'if ! runs "$node"; then',
|
|
3772
|
+
' node=""',
|
|
3773
|
+
" how=found",
|
|
3774
|
+
' nvm_default=""',
|
|
3775
|
+
' if [ -r "$HOME/.nvm/alias/default" ]; then',
|
|
3776
|
+
' IFS= read -r wanted < "$HOME/.nvm/alias/default"',
|
|
3777
|
+
" wanted=${wanted#v}",
|
|
3778
|
+
' for candidate in "$HOME/.nvm/versions/node/v$wanted"*; do',
|
|
3779
|
+
' [ -x "$candidate/bin/node" ] && nvm_default="$candidate/bin/node"',
|
|
3780
|
+
" done",
|
|
3781
|
+
" fi",
|
|
3782
|
+
" nvm_newest=$(newest_nvm)",
|
|
3783
|
+
" for candidate in \\",
|
|
3784
|
+
' "$(command -v node 2>/dev/null)" \\',
|
|
3785
|
+
" /opt/homebrew/bin/node \\",
|
|
3786
|
+
" /usr/local/bin/node \\",
|
|
3787
|
+
' "$HOME/.volta/bin/node" \\',
|
|
3788
|
+
' "$nvm_default" \\',
|
|
3789
|
+
' "$HOME/.local/share/fnm/aliases/default/bin/node" \\',
|
|
3790
|
+
' "$HOME/Library/Application Support/fnm/aliases/default/bin/node" \\',
|
|
3791
|
+
' "$HOME/.asdf/shims/node" \\',
|
|
3792
|
+
' "$HOME/.local/share/mise/shims/node" \\',
|
|
3793
|
+
' "$HOME/.nvm/versions/node/$nvm_newest/bin/node"',
|
|
3794
|
+
" do",
|
|
3795
|
+
' if recent "$candidate"; then node=$candidate; break; fi',
|
|
3796
|
+
" done",
|
|
3797
|
+
' if [ -n "$node" ]; then',
|
|
3798
|
+
` printf '%s\\n' "$node" > "$record.$$" 2>/dev/null && mv -f "$record.$$" "$record" 2>/dev/null`,
|
|
3799
|
+
' rm -f "$missing" 2>/dev/null',
|
|
3800
|
+
" fi",
|
|
3801
|
+
"fi",
|
|
3802
|
+
"",
|
|
3803
|
+
'if [ -n "$ASCENDA_HOOK_LAUNCHER_PROBE" ]; then',
|
|
3804
|
+
' [ -n "$node" ] || { echo "no Node 20 or newer found on PATH or in the usual install locations" >&2; exit 1; }',
|
|
3805
|
+
` printf '%s\\t%s\\n' "$node" "$how"`,
|
|
3806
|
+
" exit 0",
|
|
3807
|
+
"fi",
|
|
3808
|
+
"",
|
|
3809
|
+
'if [ -z "$node" ]; then',
|
|
3810
|
+
' date -u +%Y-%m-%dT%H:%M:%SZ > "$missing" 2>/dev/null',
|
|
3811
|
+
' case "$1" in',
|
|
3812
|
+
...loudEvent ? [
|
|
3813
|
+
` ${loudEvent})`,
|
|
3814
|
+
" cat >/dev/null 2>&1",
|
|
3815
|
+
` echo "Ascenda hooks cannot find Node 20 or newer, so none of them are running. Install Node, then run: ${setupCommand}" >&2`,
|
|
3816
|
+
" exit 1 ;;"
|
|
3817
|
+
] : [],
|
|
3818
|
+
` ${LAUNCHER_MANAGEMENT_COMMANDS.join("|")})`,
|
|
3819
|
+
` echo "${binaryName}: no Node 20 or newer found on PATH or in the usual install locations." >&2`,
|
|
3820
|
+
" exit 1 ;;",
|
|
3821
|
+
" *)",
|
|
3822
|
+
" # A hook: say nothing per tool call. status and doctor read the",
|
|
3823
|
+
" # file written above.",
|
|
3824
|
+
" cat >/dev/null 2>&1",
|
|
3825
|
+
" exit 0 ;;",
|
|
3826
|
+
" esac",
|
|
3827
|
+
"fi",
|
|
3828
|
+
"",
|
|
3829
|
+
'exec "$node" "$bundle" "$@"',
|
|
3830
|
+
""
|
|
3831
|
+
].join("\n");
|
|
3832
|
+
}
|
|
3833
|
+
function installHookRunner2(options) {
|
|
3834
|
+
const paths = hookRunnerPaths(options.binaryName);
|
|
3835
|
+
if (options.dryRun)
|
|
3836
|
+
return paths.launcher;
|
|
3837
|
+
const source = path4.resolve(options.source ?? process.argv[1]);
|
|
3838
|
+
fs5.mkdirSync(path4.dirname(paths.launcher), { recursive: true });
|
|
3839
|
+
if (process.platform === "win32") {
|
|
3840
|
+
if (source !== path4.resolve(paths.launcher))
|
|
3841
|
+
fs5.copyFileSync(source, paths.launcher);
|
|
3842
|
+
return paths.launcher;
|
|
3843
|
+
}
|
|
3844
|
+
if (source !== path4.resolve(paths.bundle))
|
|
3845
|
+
writeAtomically(paths.bundle, fs5.readFileSync(source), 493);
|
|
3846
|
+
writeAtomically(paths.launcher, hookLauncherScript2(options), 493);
|
|
3847
|
+
writeAtomically(paths.record, `${process.execPath}
|
|
3848
|
+
`, 420);
|
|
3849
|
+
fs5.rmSync(paths.noNode, { force: true });
|
|
3850
|
+
return paths.launcher;
|
|
3851
|
+
}
|
|
3852
|
+
function removeHookRunner(binaryName) {
|
|
3853
|
+
const removed = [];
|
|
3854
|
+
for (const file of Object.values(hookRunnerPaths(binaryName))) {
|
|
3855
|
+
if (!fs5.existsSync(file))
|
|
3856
|
+
continue;
|
|
3857
|
+
fs5.rmSync(file, { force: true });
|
|
3858
|
+
removed.push(file);
|
|
3859
|
+
}
|
|
3860
|
+
return removed;
|
|
3861
|
+
}
|
|
3862
|
+
function hookRunnerCommand2(launcher) {
|
|
3863
|
+
return process.platform === "win32" ? `"${process.execPath}" "${launcher}"` : `"${launcher}"`;
|
|
3864
|
+
}
|
|
3865
|
+
function writeAtomically(target, contents, mode) {
|
|
3866
|
+
const tmp = `${target}.${process.pid}.tmp`;
|
|
3867
|
+
fs5.writeFileSync(tmp, contents, { mode });
|
|
3868
|
+
fs5.chmodSync(tmp, mode);
|
|
3869
|
+
fs5.renameSync(tmp, target);
|
|
3870
|
+
}
|
|
3871
|
+
var stateDir = () => process.env.ASCENDA_STATE_DIR ?? path4.join((0, tokenStore_1.ascendaHome)(), "state");
|
|
3872
|
+
function lastHookPath(tool) {
|
|
3873
|
+
return path4.join(stateDir(), `${tool}-last-hook.json`);
|
|
3874
|
+
}
|
|
3875
|
+
function stampLastHook2(tool, event, now = /* @__PURE__ */ new Date()) {
|
|
3876
|
+
try {
|
|
3877
|
+
fs5.mkdirSync(stateDir(), { recursive: true });
|
|
3878
|
+
const file = lastHookPath(tool);
|
|
3879
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
3880
|
+
fs5.writeFileSync(tmp, `${JSON.stringify({ event, at: now.toISOString() })}
|
|
3881
|
+
`, { mode: 384 });
|
|
3882
|
+
fs5.renameSync(tmp, file);
|
|
3883
|
+
} catch {
|
|
3884
|
+
}
|
|
3885
|
+
}
|
|
3886
|
+
function readLastHook2(tool) {
|
|
3887
|
+
try {
|
|
3888
|
+
const parsed = JSON.parse(fs5.readFileSync(lastHookPath(tool), "utf8"));
|
|
3889
|
+
if (typeof parsed.event !== "string" || typeof parsed.at !== "string")
|
|
3890
|
+
return void 0;
|
|
3891
|
+
return { event: parsed.event, at: parsed.at };
|
|
3892
|
+
} catch {
|
|
3893
|
+
return void 0;
|
|
3894
|
+
}
|
|
3895
|
+
}
|
|
3896
|
+
function describeAge3(ms) {
|
|
3897
|
+
if (!Number.isFinite(ms) || ms < 0)
|
|
3898
|
+
return "just now";
|
|
3899
|
+
const seconds = Math.round(ms / 1e3);
|
|
3900
|
+
if (seconds < 60)
|
|
3901
|
+
return `${seconds} s ago`;
|
|
3902
|
+
const minutes = Math.round(seconds / 60);
|
|
3903
|
+
if (minutes < 60)
|
|
3904
|
+
return `${minutes} min ago`;
|
|
3905
|
+
const hours = Math.round(minutes / 60);
|
|
3906
|
+
if (hours < 48)
|
|
3907
|
+
return `${hours} h ago`;
|
|
3908
|
+
return `${Math.round(hours / 24)} days ago`;
|
|
3909
|
+
}
|
|
3910
|
+
function resolveHookNode2(launcher) {
|
|
3911
|
+
if (!fs5.existsSync(launcher))
|
|
3912
|
+
return { problem: "the hook launcher is not installed" };
|
|
3913
|
+
const probe = (0, child_process_1.spawnSync)("/bin/sh", [launcher], {
|
|
3914
|
+
encoding: "utf8",
|
|
3915
|
+
timeout: 5e3,
|
|
3916
|
+
env: { HOME: process.env.HOME ?? "", PATH: "/usr/bin:/bin:/usr/sbin:/sbin", ASCENDA_HOOK_LAUNCHER_PROBE: "1" }
|
|
3917
|
+
});
|
|
3918
|
+
const [node, how] = (probe.stdout ?? "").trim().split(" ");
|
|
3919
|
+
if (probe.status !== 0 || !node) {
|
|
3920
|
+
return { problem: (probe.stderr ?? "").trim() || "the launcher found no Node it can run" };
|
|
3921
|
+
}
|
|
3922
|
+
const version = (0, child_process_1.spawnSync)(node, ["--version"], { encoding: "utf8", timeout: 5e3 });
|
|
3923
|
+
if (version.status !== 0)
|
|
3924
|
+
return { node, how, problem: `${node} did not run` };
|
|
3925
|
+
return { node, how, version: version.stdout.trim() };
|
|
3926
|
+
}
|
|
3927
|
+
function tidyHomePath(file, home = process.env.HOME ?? "") {
|
|
3928
|
+
return home && file.startsWith(`${home}/`) ? `~${file.slice(home.length)}` : file;
|
|
3929
|
+
}
|
|
3930
|
+
}
|
|
3931
|
+
});
|
|
3932
|
+
|
|
3933
|
+
// ../packages/tool-kit/out/saverHandoff.js
|
|
3934
|
+
var require_saverHandoff = __commonJS({
|
|
3935
|
+
"../packages/tool-kit/out/saverHandoff.js"(exports) {
|
|
3936
|
+
"use strict";
|
|
3937
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
3938
|
+
if (k2 === void 0) k2 = k;
|
|
3939
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
3940
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
3941
|
+
desc = { enumerable: true, get: function() {
|
|
3942
|
+
return m[k];
|
|
3943
|
+
} };
|
|
3944
|
+
}
|
|
3945
|
+
Object.defineProperty(o, k2, desc);
|
|
3946
|
+
} : function(o, m, k, k2) {
|
|
3947
|
+
if (k2 === void 0) k2 = k;
|
|
3948
|
+
o[k2] = m[k];
|
|
3949
|
+
});
|
|
3950
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
3951
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
3952
|
+
} : function(o, v) {
|
|
3953
|
+
o["default"] = v;
|
|
3954
|
+
});
|
|
3955
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
3956
|
+
var ownKeys = function(o) {
|
|
3957
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
3958
|
+
var ar = [];
|
|
3959
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
3960
|
+
return ar;
|
|
3961
|
+
};
|
|
3962
|
+
return ownKeys(o);
|
|
3963
|
+
};
|
|
3964
|
+
return function(mod) {
|
|
3965
|
+
if (mod && mod.__esModule) return mod;
|
|
3966
|
+
var result = {};
|
|
3967
|
+
if (mod != null) {
|
|
3968
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
3969
|
+
}
|
|
3970
|
+
__setModuleDefault(result, mod);
|
|
3971
|
+
return result;
|
|
3972
|
+
};
|
|
3973
|
+
}();
|
|
3974
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3975
|
+
exports.SAVER_REPLAY_SCHEMA = exports.SAVER_REPLAY_WINDOW_MS = void 0;
|
|
3976
|
+
exports.saverContainerDir = saverContainerDir;
|
|
3977
|
+
exports.saverSupportDir = saverSupportDir;
|
|
3978
|
+
exports.saverReplayPath = saverReplayPath;
|
|
3979
|
+
exports.saverStatusDir = saverStatusDir;
|
|
3980
|
+
exports.holdForSaver = holdForSaver;
|
|
3981
|
+
exports.heldForSaver = heldForSaver;
|
|
3982
|
+
exports.readSaverStatuses = readSaverStatuses;
|
|
3983
|
+
exports.probeSocket = probeSocket;
|
|
3984
|
+
var fs5 = __importStar(__require("fs"));
|
|
3985
|
+
var net = __importStar(__require("net"));
|
|
3986
|
+
var os5 = __importStar(__require("os"));
|
|
3987
|
+
var path4 = __importStar(__require("path"));
|
|
3988
|
+
var SAVER_HOST_BUNDLE_ID = "com.apple.ScreenSaver.Engine.legacyScreenSaver";
|
|
3989
|
+
function saverContainerDir() {
|
|
3990
|
+
return process.env.ASCENDA_SAVER_CONTAINER ?? path4.join(os5.homedir(), "Library", "Containers", SAVER_HOST_BUNDLE_ID, "Data");
|
|
3991
|
+
}
|
|
3992
|
+
function saverSupportDir() {
|
|
3993
|
+
return path4.join(saverContainerDir(), "Library", "Application Support", "AscendaWaterlineSaver");
|
|
3994
|
+
}
|
|
3995
|
+
function saverReplayPath() {
|
|
3996
|
+
return path4.join(saverContainerDir(), "l.replay.json");
|
|
3997
|
+
}
|
|
3998
|
+
function saverStatusDir() {
|
|
3999
|
+
return path4.join(saverSupportDir(), "status");
|
|
4000
|
+
}
|
|
4001
|
+
exports.SAVER_REPLAY_WINDOW_MS = 30 * 60 * 1e3;
|
|
4002
|
+
var SAVER_REPLAY_MAX = 32;
|
|
4003
|
+
exports.SAVER_REPLAY_SCHEMA = 1;
|
|
4004
|
+
function holdForSaver(signal, now = Date.now()) {
|
|
4005
|
+
try {
|
|
4006
|
+
if (process.env.ASCENDA_LIVE_BUS_SOCKET && !process.env.ASCENDA_SAVER_CONTAINER)
|
|
4007
|
+
return;
|
|
4008
|
+
if (!fs5.existsSync(saverSupportDir()))
|
|
4009
|
+
return;
|
|
4010
|
+
const wire = signal;
|
|
4011
|
+
const tool = wire.tool;
|
|
4012
|
+
const session = wire.session;
|
|
4013
|
+
const event = wire.event;
|
|
4014
|
+
if (typeof tool !== "string" || typeof session !== "string" || typeof event !== "string")
|
|
4015
|
+
return;
|
|
4016
|
+
const file = saverReplayPath();
|
|
4017
|
+
const kept = readHeld(file).filter((held) => now - held.at <= exports.SAVER_REPLAY_WINDOW_MS && !(held.tool === tool && held.session === session));
|
|
4018
|
+
kept.push({ ...wire, tool, session, event, at: now });
|
|
4019
|
+
kept.sort((a, b) => a.at - b.at);
|
|
4020
|
+
const body = JSON.stringify({ schema: exports.SAVER_REPLAY_SCHEMA, signals: kept.slice(-SAVER_REPLAY_MAX) });
|
|
4021
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
4022
|
+
fs5.writeFileSync(tmp, `${body}
|
|
4023
|
+
`, { mode: 384 });
|
|
4024
|
+
fs5.renameSync(tmp, file);
|
|
4025
|
+
} catch {
|
|
4026
|
+
}
|
|
4027
|
+
}
|
|
4028
|
+
function readHeld(file) {
|
|
4029
|
+
try {
|
|
4030
|
+
const parsed = JSON.parse(fs5.readFileSync(file, "utf8"));
|
|
4031
|
+
if (parsed.schema !== exports.SAVER_REPLAY_SCHEMA || !Array.isArray(parsed.signals))
|
|
4032
|
+
return [];
|
|
4033
|
+
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");
|
|
4034
|
+
} catch {
|
|
4035
|
+
return [];
|
|
4036
|
+
}
|
|
4037
|
+
}
|
|
4038
|
+
function heldForSaver(now = Date.now()) {
|
|
4039
|
+
const held = readHeld(saverReplayPath()).filter((entry) => now - entry.at <= exports.SAVER_REPLAY_WINDOW_MS);
|
|
4040
|
+
if (held.length === 0)
|
|
4041
|
+
return { count: 0 };
|
|
4042
|
+
return { count: held.length, newestAgeMs: now - Math.max(...held.map((entry) => entry.at)) };
|
|
4043
|
+
}
|
|
4044
|
+
function readSaverStatuses(now = Date.now()) {
|
|
4045
|
+
let names;
|
|
4046
|
+
try {
|
|
4047
|
+
names = fs5.readdirSync(saverStatusDir()).filter((name) => name.endsWith(".json"));
|
|
4048
|
+
} catch {
|
|
4049
|
+
return [];
|
|
4050
|
+
}
|
|
4051
|
+
const readings = [];
|
|
4052
|
+
for (const name of names) {
|
|
4053
|
+
try {
|
|
4054
|
+
const status = JSON.parse(fs5.readFileSync(path4.join(saverStatusDir(), name), "utf8"));
|
|
4055
|
+
if (typeof status.pid !== "number" || typeof status.updatedAt !== "string")
|
|
4056
|
+
continue;
|
|
4057
|
+
readings.push({ ...status, alive: processAlive(status.pid), ageMs: now - Date.parse(status.updatedAt) });
|
|
4058
|
+
} catch {
|
|
4059
|
+
}
|
|
4060
|
+
}
|
|
4061
|
+
return readings.sort((a, b) => a.ageMs - b.ageMs);
|
|
4062
|
+
}
|
|
4063
|
+
function processAlive(pid) {
|
|
4064
|
+
try {
|
|
4065
|
+
process.kill(pid, 0);
|
|
4066
|
+
return true;
|
|
4067
|
+
} catch (error) {
|
|
4068
|
+
return error.code === "EPERM";
|
|
4069
|
+
}
|
|
4070
|
+
}
|
|
4071
|
+
function probeSocket(socketPath, timeoutMs = 300) {
|
|
4072
|
+
return new Promise((resolve2) => {
|
|
4073
|
+
try {
|
|
4074
|
+
if (!fs5.statSync(socketPath).isSocket()) {
|
|
4075
|
+
resolve2("absent");
|
|
4076
|
+
return;
|
|
4077
|
+
}
|
|
4078
|
+
} catch {
|
|
4079
|
+
resolve2("absent");
|
|
4080
|
+
return;
|
|
4081
|
+
}
|
|
4082
|
+
let settled = false;
|
|
4083
|
+
const finish = (state) => {
|
|
4084
|
+
if (settled)
|
|
4085
|
+
return;
|
|
4086
|
+
settled = true;
|
|
4087
|
+
clearTimeout(timer);
|
|
4088
|
+
socket.destroy();
|
|
4089
|
+
resolve2(state);
|
|
4090
|
+
};
|
|
4091
|
+
const socket = net.createConnection(socketPath);
|
|
4092
|
+
const timer = setTimeout(() => finish("unreachable"), timeoutMs);
|
|
4093
|
+
socket.on("connect", () => finish("listening"));
|
|
4094
|
+
socket.on("error", (error) => finish(error.code === "ECONNREFUSED" || error.code === "ENOENT" ? "stale" : "unreachable"));
|
|
4095
|
+
});
|
|
4096
|
+
}
|
|
4097
|
+
}
|
|
4098
|
+
});
|
|
4099
|
+
|
|
4100
|
+
// ../packages/tool-kit/out/liveBus.js
|
|
4101
|
+
var require_liveBus = __commonJS({
|
|
4102
|
+
"../packages/tool-kit/out/liveBus.js"(exports) {
|
|
4103
|
+
"use strict";
|
|
4104
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4105
|
+
if (k2 === void 0) k2 = k;
|
|
4106
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4107
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
4108
|
+
desc = { enumerable: true, get: function() {
|
|
4109
|
+
return m[k];
|
|
4110
|
+
} };
|
|
4111
|
+
}
|
|
4112
|
+
Object.defineProperty(o, k2, desc);
|
|
4113
|
+
} : function(o, m, k, k2) {
|
|
4114
|
+
if (k2 === void 0) k2 = k;
|
|
4115
|
+
o[k2] = m[k];
|
|
4116
|
+
});
|
|
4117
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
4118
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
4119
|
+
} : function(o, v) {
|
|
4120
|
+
o["default"] = v;
|
|
4121
|
+
});
|
|
4122
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
4123
|
+
var ownKeys = function(o) {
|
|
4124
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
4125
|
+
var ar = [];
|
|
4126
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
4127
|
+
return ar;
|
|
4128
|
+
};
|
|
4129
|
+
return ownKeys(o);
|
|
4130
|
+
};
|
|
4131
|
+
return function(mod) {
|
|
4132
|
+
if (mod && mod.__esModule) return mod;
|
|
4133
|
+
var result = {};
|
|
4134
|
+
if (mod != null) {
|
|
4135
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
4136
|
+
}
|
|
4137
|
+
__setModuleDefault(result, mod);
|
|
4138
|
+
return result;
|
|
4139
|
+
};
|
|
4140
|
+
}();
|
|
4141
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4142
|
+
exports.SAVER_HOST_BUNDLE_ID = exports.LIVE_BUS_BACKGROUND_TRUST_MS = void 0;
|
|
4143
|
+
exports.liveBusSocketCandidates = liveBusSocketCandidates;
|
|
4144
|
+
exports.existingSocketCandidates = existingSocketCandidates;
|
|
4145
|
+
exports.liveBusSocketPath = liveBusSocketPath;
|
|
4146
|
+
exports.bucketPromptSize = bucketPromptSize2;
|
|
4147
|
+
exports.emitLiveSignal = emitLiveSignal2;
|
|
4148
|
+
exports.deliverLine = deliverLine;
|
|
4149
|
+
var fs5 = __importStar(__require("fs"));
|
|
4150
|
+
var net = __importStar(__require("net"));
|
|
4151
|
+
var os5 = __importStar(__require("os"));
|
|
4152
|
+
var path4 = __importStar(__require("path"));
|
|
4153
|
+
var hookSet_1 = require_hookSet();
|
|
4154
|
+
var saverHandoff_1 = require_saverHandoff();
|
|
4155
|
+
var WRITE_TIMEOUT_MS = 50;
|
|
4156
|
+
exports.LIVE_BUS_BACKGROUND_TRUST_MS = 60 * 60 * 1e3;
|
|
4157
|
+
var APP_BUNDLE_ID = "one.ascenda.ascendaMissionControl";
|
|
4158
|
+
exports.SAVER_HOST_BUNDLE_ID = "com.apple.ScreenSaver.Engine.legacyScreenSaver";
|
|
4159
|
+
function liveBusSocketCandidates() {
|
|
4160
|
+
const override = process.env.ASCENDA_LIVE_BUS_SOCKET;
|
|
4161
|
+
if (override)
|
|
4162
|
+
return [override];
|
|
4163
|
+
const home = os5.homedir();
|
|
4164
|
+
return [
|
|
4165
|
+
path4.join(home, ".ascenda", "live.sock"),
|
|
4166
|
+
path4.join(home, "Library", "Containers", APP_BUNDLE_ID, "Data", ".ascenda", "live.sock"),
|
|
4167
|
+
path4.join(home, "Library", "Containers", exports.SAVER_HOST_BUNDLE_ID, "Data", "l.sock")
|
|
4168
|
+
];
|
|
4169
|
+
}
|
|
4170
|
+
function existingSocketCandidates() {
|
|
4171
|
+
const candidates = liveBusSocketCandidates();
|
|
4172
|
+
if (process.env.ASCENDA_LIVE_BUS_SOCKET)
|
|
4173
|
+
return candidates;
|
|
4174
|
+
return candidates.filter((candidate) => {
|
|
4175
|
+
try {
|
|
4176
|
+
return fs5.statSync(candidate).isSocket();
|
|
4177
|
+
} catch {
|
|
4178
|
+
return false;
|
|
4179
|
+
}
|
|
4180
|
+
});
|
|
4181
|
+
}
|
|
4182
|
+
function liveBusSocketPath() {
|
|
4183
|
+
return existingSocketCandidates()[0] ?? liveBusSocketCandidates()[0];
|
|
4184
|
+
}
|
|
4185
|
+
function bucketPromptSize2(text) {
|
|
4186
|
+
const length = typeof text === "string" ? text.length : 0;
|
|
4187
|
+
if (length <= 280)
|
|
4188
|
+
return "s";
|
|
4189
|
+
if (length <= 2e3)
|
|
4190
|
+
return "m";
|
|
4191
|
+
if (length <= 8e3)
|
|
4192
|
+
return "l";
|
|
4193
|
+
return "xl";
|
|
4194
|
+
}
|
|
4195
|
+
var NOBODY_LISTENING = /* @__PURE__ */ new Set(["ECONNREFUSED", "ENOENT"]);
|
|
4196
|
+
function onTheWire(signal) {
|
|
4197
|
+
const out = { ...signal };
|
|
4198
|
+
if ("hookSet" in out && !(0, hookSet_1.isHookSet)(out.hookSet))
|
|
4199
|
+
delete out.hookSet;
|
|
4200
|
+
if ("viaPlugin" in out && out.viaPlugin !== true)
|
|
4201
|
+
delete out.viaPlugin;
|
|
4202
|
+
return out;
|
|
4203
|
+
}
|
|
4204
|
+
function emitLiveSignal2(signal) {
|
|
4205
|
+
const wire = onTheWire(signal);
|
|
4206
|
+
return deliverLine(`${JSON.stringify(wire)}
|
|
4207
|
+
`).then((delivered) => {
|
|
4208
|
+
if (!delivered)
|
|
4209
|
+
(0, saverHandoff_1.holdForSaver)(wire);
|
|
4210
|
+
});
|
|
4211
|
+
}
|
|
4212
|
+
function deliverLine(line) {
|
|
4213
|
+
return new Promise((resolve2) => {
|
|
4214
|
+
const candidates = existingSocketCandidates();
|
|
4215
|
+
if (candidates.length === 0) {
|
|
4216
|
+
resolve2(void 0);
|
|
4217
|
+
return;
|
|
4218
|
+
}
|
|
4219
|
+
let settled = false;
|
|
4220
|
+
let accepted;
|
|
4221
|
+
let socket;
|
|
4222
|
+
const drop = () => {
|
|
4223
|
+
try {
|
|
4224
|
+
socket?.destroy();
|
|
4225
|
+
} catch {
|
|
4226
|
+
}
|
|
4227
|
+
socket = void 0;
|
|
4228
|
+
};
|
|
4229
|
+
const done = () => {
|
|
4230
|
+
if (settled)
|
|
4231
|
+
return;
|
|
4232
|
+
settled = true;
|
|
4233
|
+
clearTimeout(timer);
|
|
4234
|
+
drop();
|
|
4235
|
+
resolve2(accepted);
|
|
4236
|
+
};
|
|
4237
|
+
const timer = setTimeout(done, WRITE_TIMEOUT_MS);
|
|
4238
|
+
const tryFrom = (index) => {
|
|
4239
|
+
if (settled)
|
|
4240
|
+
return;
|
|
4241
|
+
if (index >= candidates.length) {
|
|
4242
|
+
done();
|
|
4243
|
+
return;
|
|
4244
|
+
}
|
|
4245
|
+
let attempt;
|
|
4246
|
+
try {
|
|
4247
|
+
attempt = net.createConnection(candidates[index]);
|
|
4248
|
+
} catch {
|
|
4249
|
+
tryFrom(index + 1);
|
|
4250
|
+
return;
|
|
4251
|
+
}
|
|
4252
|
+
socket = attempt;
|
|
4253
|
+
if (typeof attempt.unref === "function")
|
|
4254
|
+
attempt.unref();
|
|
4255
|
+
let connected = false;
|
|
4256
|
+
attempt.on("error", (error) => {
|
|
4257
|
+
if (settled || socket !== attempt)
|
|
4258
|
+
return;
|
|
4259
|
+
if (!connected && error.code && NOBODY_LISTENING.has(error.code)) {
|
|
4260
|
+
drop();
|
|
4261
|
+
tryFrom(index + 1);
|
|
4262
|
+
return;
|
|
4263
|
+
}
|
|
4264
|
+
done();
|
|
4265
|
+
});
|
|
4266
|
+
attempt.on("connect", () => {
|
|
4267
|
+
if (settled || socket !== attempt)
|
|
4268
|
+
return;
|
|
4269
|
+
connected = true;
|
|
4270
|
+
accepted = candidates[index];
|
|
4271
|
+
try {
|
|
4272
|
+
attempt.write(line, done);
|
|
4273
|
+
} catch {
|
|
4274
|
+
done();
|
|
4275
|
+
}
|
|
4276
|
+
});
|
|
4277
|
+
};
|
|
4278
|
+
tryFrom(0);
|
|
4279
|
+
});
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
});
|
|
4283
|
+
|
|
4284
|
+
// ../packages/tool-kit/out/terminalStyle.js
|
|
4285
|
+
var require_terminalStyle = __commonJS({
|
|
4286
|
+
"../packages/tool-kit/out/terminalStyle.js"(exports) {
|
|
4287
|
+
"use strict";
|
|
4288
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4289
|
+
exports.colourEnabled = colourEnabled;
|
|
4290
|
+
exports.terminalStyle = terminalStyle3;
|
|
4291
|
+
function colourEnabled(stream = process.stdout, env = process.env) {
|
|
4292
|
+
if (env.NO_COLOR !== void 0 && env.NO_COLOR !== "")
|
|
4293
|
+
return false;
|
|
4294
|
+
if (env.FORCE_COLOR !== void 0)
|
|
4295
|
+
return env.FORCE_COLOR !== "0";
|
|
4296
|
+
if (env.TERM === "dumb")
|
|
4297
|
+
return false;
|
|
4298
|
+
return Boolean(stream.isTTY);
|
|
4299
|
+
}
|
|
4300
|
+
function terminalStyle3(enabled = colourEnabled()) {
|
|
4301
|
+
const wrap = (open, close) => (text) => enabled ? `\x1B[${open}m${text}\x1B[${close}m` : text;
|
|
4302
|
+
const bold = wrap(1, 22);
|
|
4303
|
+
const dim = wrap(2, 22);
|
|
4304
|
+
const green = wrap(32, 39);
|
|
4305
|
+
const yellow = wrap(33, 39);
|
|
4306
|
+
const red = wrap(31, 39);
|
|
4307
|
+
const cyan = wrap(36, 39);
|
|
4308
|
+
const colour = { ok: green, warn: yellow, bad: red, info: dim };
|
|
4309
|
+
const marks = { ok: "\u2713", warn: "!", bad: "\u2717", info: "\xB7" };
|
|
4310
|
+
return {
|
|
4311
|
+
enabled,
|
|
4312
|
+
bold,
|
|
4313
|
+
dim,
|
|
4314
|
+
green,
|
|
4315
|
+
yellow,
|
|
4316
|
+
red,
|
|
4317
|
+
cyan,
|
|
4318
|
+
mark: (tone) => colour[tone](marks[tone]),
|
|
4319
|
+
tone: (tone, text) => colour[tone](text)
|
|
4320
|
+
};
|
|
4321
|
+
}
|
|
4322
|
+
}
|
|
4323
|
+
});
|
|
4324
|
+
|
|
4325
|
+
// ../packages/tool-kit/out/liveSignalDoctor.js
|
|
4326
|
+
var require_liveSignalDoctor = __commonJS({
|
|
4327
|
+
"../packages/tool-kit/out/liveSignalDoctor.js"(exports) {
|
|
4328
|
+
"use strict";
|
|
4329
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4330
|
+
exports.DOCTOR_VALUE_COLUMN = void 0;
|
|
4331
|
+
exports.doctorRow = doctorRow2;
|
|
4332
|
+
exports.liveSignalDoctorLines = liveSignalDoctorLines2;
|
|
4333
|
+
var hookRunner_1 = require_hookRunner();
|
|
4334
|
+
var liveBus_1 = require_liveBus();
|
|
4335
|
+
var saverHandoff_1 = require_saverHandoff();
|
|
4336
|
+
var terminalStyle_1 = require_terminalStyle();
|
|
4337
|
+
exports.DOCTOR_VALUE_COLUMN = 25;
|
|
4338
|
+
function doctorRow2(ui, tone, label, value) {
|
|
4339
|
+
return ` ${ui.mark(tone)} ${label.padEnd(exports.DOCTOR_VALUE_COLUMN - 5)} ${value}`;
|
|
4340
|
+
}
|
|
4341
|
+
async function liveSignalDoctorLines2(options) {
|
|
4342
|
+
const ui = options.ui ?? (0, terminalStyle_1.terminalStyle)();
|
|
4343
|
+
const lines = [` ${ui.bold("Live signal")} ${ui.dim("(this machine; needs no pairing)")}`];
|
|
4344
|
+
const now = Date.now();
|
|
4345
|
+
let problems = 0;
|
|
4346
|
+
const row = (tone, label, value) => {
|
|
4347
|
+
if (tone === "bad" || tone === "warn")
|
|
4348
|
+
problems += 1;
|
|
4349
|
+
lines.push(doctorRow2(ui, tone, label, tone === "bad" ? ui.red(value) : value));
|
|
4350
|
+
};
|
|
4351
|
+
const more = (value) => lines.push(`${" ".repeat(exports.DOCTOR_VALUE_COLUMN)}${value}`);
|
|
4352
|
+
if (options.launcher && process.platform !== "win32") {
|
|
4353
|
+
const node = (0, hookRunner_1.resolveHookNode)(options.launcher);
|
|
4354
|
+
if (node.problem)
|
|
4355
|
+
row("bad", "Node", `${node.problem}. Install Node 20 or newer, then run setup again`);
|
|
4356
|
+
else
|
|
4357
|
+
row("ok", "Node", `${node.node} ${ui.dim(`(${node.version}, ${node.how === "recorded" ? "recorded at setup" : "found by the launcher"})`)}`);
|
|
4358
|
+
}
|
|
4359
|
+
if (options.registrations.length === 0)
|
|
4360
|
+
row("bad", "Hooks", `not registered. Run: ${options.setupCommand}`);
|
|
4361
|
+
for (const entry of options.registrations) {
|
|
4362
|
+
const where = entry.homeProject ? `loads only when ${options.displayName} starts in the home folder. Run setup again to move it to every project` : entry.scope === "user" ? "every project" : "this project only";
|
|
4363
|
+
const complete = entry.registered === options.eventCount;
|
|
4364
|
+
row(entry.homeProject || !complete ? "warn" : entry.scope === "user" ? "ok" : "info", "Hooks", `${entry.registered}/${options.eventCount} in ${entry.file} ${ui.dim(`(${where})`)}`);
|
|
4365
|
+
}
|
|
4366
|
+
if (options.registrations.length > 1) {
|
|
4367
|
+
problems += 1;
|
|
4368
|
+
more(ui.yellow("Registered in more than one file, so each event runs more than once. Run setup again to fix."));
|
|
4369
|
+
}
|
|
4370
|
+
const last = (0, hookRunner_1.readLastHook)(options.tool);
|
|
4371
|
+
if (last)
|
|
4372
|
+
row("ok", "Last hook", `${last.event}, ${(0, hookRunner_1.describeAge)(now - Date.parse(last.at))}`);
|
|
4373
|
+
else
|
|
4374
|
+
row("info", "Last hook", `none yet. Start ${options.displayName} (restart it if it was open during setup)${options.lookHint ? `, then ${options.lookHint}` : ""}`);
|
|
4375
|
+
const [appSocket, appContainerSocket, saverSocket] = (0, liveBus_1.liveBusSocketCandidates)();
|
|
4376
|
+
const appState = await (0, saverHandoff_1.probeSocket)(appSocket);
|
|
4377
|
+
const legacyState = appContainerSocket ? await (0, saverHandoff_1.probeSocket)(appContainerSocket) : "absent";
|
|
4378
|
+
if (appState === "listening" || legacyState === "listening")
|
|
4379
|
+
row("ok", "Desktop app", "listening. It takes every signal, and the saver mirrors it");
|
|
4380
|
+
else
|
|
4381
|
+
row("info", "Desktop app", "not listening");
|
|
4382
|
+
const saverState = saverSocket ? await (0, saverHandoff_1.probeSocket)(saverSocket) : "absent";
|
|
4383
|
+
const live = (0, saverHandoff_1.readSaverStatuses)(now).filter((status) => status.alive);
|
|
4384
|
+
const holder = live.find((status) => status.ownsBus);
|
|
4385
|
+
const saver = describeSaver(saverState, holder, live);
|
|
4386
|
+
row(saver.tone, "Screen saver", saver.text);
|
|
4387
|
+
for (const status of live)
|
|
4388
|
+
more(ui.dim(describeProcess(status, now)));
|
|
4389
|
+
const held = (0, saverHandoff_1.heldForSaver)(now);
|
|
4390
|
+
if (held.count > 0) {
|
|
4391
|
+
row("info", "Held for the saver", `${held.count} session${held.count === 1 ? "" : "s"}, newest ${(0, hookRunner_1.describeAge)(held.newestAgeMs ?? 0)}. Replayed when the saver starts`);
|
|
4392
|
+
}
|
|
4393
|
+
const trip = await pingRoundTrip(saverSocket, options.selfCommand);
|
|
4394
|
+
row(trip.tone, "Round trip", trip.text);
|
|
4395
|
+
lines.push("");
|
|
4396
|
+
lines.push(problems === 0 ? ` ${ui.mark("ok")} ${ui.bold("Ready.")} The hooks can run, and the screen saver hears them while it's on screen.` : ` ${ui.mark("bad")} ${ui.bold(`${problems} problem${problems === 1 ? "" : "s"} above.`)} Each line says how to fix it.`);
|
|
4397
|
+
return lines;
|
|
4398
|
+
}
|
|
4399
|
+
function describeSaver(state, holder, live) {
|
|
4400
|
+
if (state === "listening") {
|
|
4401
|
+
if (!holder)
|
|
4402
|
+
return { tone: "warn", text: "listening, from a process that isn't reporting. Restart it: killall legacyScreenSaver" };
|
|
4403
|
+
if (holder.saverViews === 0) {
|
|
4404
|
+
return { tone: "bad", text: `pid ${holder.pid} holds the socket but isn't drawing the saver, so signals go nowhere you can see. Fix: killall legacyScreenSaver` };
|
|
4405
|
+
}
|
|
4406
|
+
return { tone: "ok", text: `listening, pid ${holder.pid}, on screen` };
|
|
4407
|
+
}
|
|
4408
|
+
if (state === "stale")
|
|
4409
|
+
return { tone: "info", text: "not running (a socket file was left behind, which is harmless)" };
|
|
4410
|
+
if (live.some((status) => status.previewViews > 0)) {
|
|
4411
|
+
return { tone: "info", text: "not running. The System Settings preview never listens, so it stays still; the water goes live once the saver itself runs" };
|
|
4412
|
+
}
|
|
4413
|
+
return { tone: "info", text: "not running. That's normal: it listens only while it's on screen" };
|
|
4414
|
+
}
|
|
4415
|
+
function describeProcess(status, now) {
|
|
4416
|
+
const what = [
|
|
4417
|
+
status.saverViews > 0 ? `saver on ${status.saverViews} display${status.saverViews === 1 ? "" : "s"}` : void 0,
|
|
4418
|
+
status.previewViews > 0 ? "preview" : void 0
|
|
4419
|
+
].filter(Boolean).join(" + ") || "not drawing";
|
|
4420
|
+
const heard = status.lastSignalAt ? `last signal ${status.lastSignalEvent ?? ""} ${(0, hookRunner_1.describeAge)(now - Date.parse(status.lastSignalAt))}`.replace(/\s+/g, " ") : "no signal yet";
|
|
4421
|
+
const replay = status.replayed > 0 ? `, replayed ${status.replayed} since this process started` : "";
|
|
4422
|
+
const beat = status.ageMs > 1e4 ? `, heartbeat ${(0, hookRunner_1.describeAge)(status.ageMs)} (not animating)` : "";
|
|
4423
|
+
return `pid ${status.pid} ${status.version ?? ""}: ${what}, ${status.mode ?? "?"}${status.ownsBus ? ", owns the socket" : ""}, ${heard}${replay}${beat}`.replace(/\s+:/, ":");
|
|
4424
|
+
}
|
|
4425
|
+
async function pingRoundTrip(saverSocket, selfCommand2) {
|
|
4426
|
+
const session = `doctor-${process.pid}-${Date.now()}`;
|
|
4427
|
+
const accepted = await (0, liveBus_1.deliverLine)(`${JSON.stringify({ tool: "doctor", session, event: "ping" })}
|
|
4428
|
+
`);
|
|
4429
|
+
if (!accepted) {
|
|
4430
|
+
return { tone: "info", text: `nobody is listening right now, so there is nothing to test. To test the saver: open -a ScreenSaverEngine; sleep 5; ${selfCommand2} doctor` };
|
|
4431
|
+
}
|
|
4432
|
+
if (accepted !== saverSocket)
|
|
4433
|
+
return { tone: "ok", text: `the desktop app took it (${accepted})` };
|
|
4434
|
+
for (let waited = 0; waited < 2e3; waited += 100) {
|
|
4435
|
+
await new Promise((resolve2) => setTimeout(resolve2, 100));
|
|
4436
|
+
const answered = (0, saverHandoff_1.readSaverStatuses)().find((status) => status.lastPingSession === session);
|
|
4437
|
+
if (answered)
|
|
4438
|
+
return { tone: "ok", text: `OK. The screen saver (pid ${answered.pid}) received it` };
|
|
4439
|
+
}
|
|
4440
|
+
return { tone: "bad", text: "the saver's socket took the ping but no saver reported it. It may be a version from before 0.8.1, or stuck. Fix: killall legacyScreenSaver" };
|
|
4441
|
+
}
|
|
4442
|
+
}
|
|
4443
|
+
});
|
|
4444
|
+
|
|
3680
4445
|
// ../packages/tool-kit/out/studyNotices.js
|
|
3681
4446
|
var require_studyNotices = __commonJS({
|
|
3682
4447
|
"../packages/tool-kit/out/studyNotices.js"(exports) {
|
|
@@ -3926,13 +4691,15 @@ var require_cliAgentSetup = __commonJS({
|
|
|
3926
4691
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3927
4692
|
exports.isCliAgentManagementCommand = isCliAgentManagementCommand;
|
|
3928
4693
|
exports.cliAgentHookBinPath = cliAgentHookBinPath;
|
|
4694
|
+
exports.cliAgentSelfCommand = cliAgentSelfCommand;
|
|
3929
4695
|
exports.runCliAgentSetup = runCliAgentSetup;
|
|
3930
4696
|
exports.writeHookSettings = writeHookSettings;
|
|
3931
4697
|
exports.registeredHookSets = registeredHookSets;
|
|
3932
4698
|
exports.findStaleHookCommands = findStaleHookCommands2;
|
|
4699
|
+
exports.cliAgentRegistrations = cliAgentRegistrations;
|
|
3933
4700
|
var crypto2 = __importStar(__require("crypto"));
|
|
3934
4701
|
var fs5 = __importStar(__require("fs"));
|
|
3935
|
-
var
|
|
4702
|
+
var os5 = __importStar(__require("os"));
|
|
3936
4703
|
var path4 = __importStar(__require("path"));
|
|
3937
4704
|
var collectorVersion_1 = require_collectorVersion();
|
|
3938
4705
|
var credentials_1 = require_credentials();
|
|
@@ -3941,22 +4708,29 @@ var require_cliAgentSetup = __commonJS({
|
|
|
3941
4708
|
var hookSet_1 = require_hookSet();
|
|
3942
4709
|
var initiatives_1 = require_initiatives();
|
|
3943
4710
|
var setupDisclosure_1 = require_setupDisclosure();
|
|
4711
|
+
var hookRunner_1 = require_hookRunner();
|
|
4712
|
+
var liveSignalDoctor_1 = require_liveSignalDoctor();
|
|
3944
4713
|
var stateStore_1 = require_stateStore();
|
|
3945
4714
|
var studyJoin_1 = require_studyJoin();
|
|
3946
4715
|
var studyNotices_1 = require_studyNotices();
|
|
4716
|
+
var terminalStyle_1 = require_terminalStyle();
|
|
3947
4717
|
var tokenStore_1 = require_tokenStore();
|
|
3948
|
-
var MANAGEMENT_COMMANDS2 = /* @__PURE__ */ new Set(["setup", "install", "status", "uninstall", "join", "object", "-h", "--help"]);
|
|
4718
|
+
var MANAGEMENT_COMMANDS2 = /* @__PURE__ */ new Set(["setup", "install", "status", "uninstall", "doctor", "join", "object", "-h", "--help"]);
|
|
3949
4719
|
function isCliAgentManagementCommand(argument) {
|
|
3950
4720
|
return argument !== void 0 && MANAGEMENT_COMMANDS2.has(argument);
|
|
3951
4721
|
}
|
|
3952
4722
|
function cliAgentHookBinPath(binaryName) {
|
|
3953
|
-
return
|
|
4723
|
+
return (0, hookRunner_1.hookRunnerPaths)(binaryName).launcher;
|
|
4724
|
+
}
|
|
4725
|
+
function cliAgentSelfCommand(spec) {
|
|
4726
|
+
return process.platform === "win32" ? `npx ${spec.packageName}` : (0, hookRunner_1.tidyHomePath)(cliAgentHookBinPath(spec.binaryName), os5.homedir());
|
|
3954
4727
|
}
|
|
3955
4728
|
function usage(spec) {
|
|
3956
4729
|
return `${spec.binaryName} setup \u2014 wire ${spec.displayName} to Ascenda telemetry
|
|
3957
4730
|
|
|
3958
4731
|
npx ${spec.packageName} setup [options]
|
|
3959
4732
|
npx ${spec.packageName} status
|
|
4733
|
+
npx ${spec.packageName} doctor
|
|
3960
4734
|
npx ${spec.packageName} uninstall
|
|
3961
4735
|
npx ${spec.packageName} join <code>
|
|
3962
4736
|
npx ${spec.packageName} object <purpose> [--undo]
|
|
@@ -3967,7 +4741,7 @@ Options
|
|
|
3967
4741
|
--tool-installation-id <id> reuse an existing pairing instead of creating one
|
|
3968
4742
|
--token <eventWriteToken> reuse an existing token (stored 0600, never printed)
|
|
3969
4743
|
--no-pair install without pairing: local features on, nothing sent
|
|
3970
|
-
--scope project
|
|
4744
|
+
--scope user|project where hooks are registered (default user: every project)
|
|
3971
4745
|
--project-dir <path> project root for --scope project (default cwd)
|
|
3972
4746
|
--dry-run print what would change, write nothing
|
|
3973
4747
|
-h, --help
|
|
@@ -3993,29 +4767,26 @@ Options
|
|
|
3993
4767
|
return await printStatus2(options, spec);
|
|
3994
4768
|
if (options.action === "uninstall")
|
|
3995
4769
|
return uninstall2(options, spec);
|
|
4770
|
+
if (options.action === "doctor")
|
|
4771
|
+
return await runDoctor2(options, spec);
|
|
3996
4772
|
const apiBaseUrl = (options.apiBaseUrl ?? (0, credentials_1.readHostCredentials)(spec.host)?.apiBaseUrl ?? hookAdapter_1.DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
3997
|
-
|
|
3998
|
-
console.log(`
|
|
3999
|
-
|
|
4000
|
-
`);
|
|
4773
|
+
const ui = (0, terminalStyle_1.terminalStyle)();
|
|
4774
|
+
const row = (tone, label, value) => console.log(` ${ui.mark(tone)} ${label.padEnd(12)} ${value}`);
|
|
4775
|
+
const detail = (label, value) => console.log(ui.dim(` ${label.padEnd(12)} ${value}`));
|
|
4776
|
+
console.log(`${ui.bold("Ascenda setup")} ${ui.dim(`\xB7 ${spec.displayName} \xB7 ${apiBaseUrl}`)}`);
|
|
4777
|
+
if (!options.skipPairing)
|
|
4778
|
+
console.log(`
|
|
4779
|
+
${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName: spec.displayName })}`);
|
|
4780
|
+
console.log("");
|
|
4001
4781
|
let identity;
|
|
4002
|
-
|
|
4003
|
-
if (options.skipPairing) {
|
|
4004
|
-
unpairedReason = "asked not to pair (--no-pair)";
|
|
4005
|
-
} else {
|
|
4782
|
+
if (!options.skipPairing)
|
|
4006
4783
|
identity = await resolveIdentity2(apiBaseUrl, options, spec);
|
|
4007
|
-
if (identity) {
|
|
4008
|
-
console.log(` pairing ${identity.toolInstallationId}${identity.paired ? " (new)" : " (existing)"}`);
|
|
4009
|
-
} else {
|
|
4010
|
-
unpairedReason = "pairing did not finish \u2014 installing the local half anyway";
|
|
4011
|
-
}
|
|
4012
|
-
}
|
|
4013
|
-
if (unpairedReason) {
|
|
4014
|
-
console.log(` pairing none: ${unpairedReason}`);
|
|
4015
|
-
console.log(" local features on, nothing is sent");
|
|
4016
|
-
}
|
|
4017
4784
|
const binary = installBinary2(spec, options.dryRun);
|
|
4018
|
-
|
|
4785
|
+
const node = options.dryRun || process.platform === "win32" ? void 0 : (0, hookRunner_1.resolveHookNode)(binary);
|
|
4786
|
+
if (node?.problem)
|
|
4787
|
+
row("bad", "hook binary", `${(0, hookRunner_1.tidyHomePath)(binary, os5.homedir())}, but ${node.problem}. Install Node 20 or newer, then run setup again`);
|
|
4788
|
+
else
|
|
4789
|
+
row("ok", "hook binary", `${(0, hookRunner_1.tidyHomePath)(binary, os5.homedir())}${node?.version ? ui.dim(` (Node ${node.version})`) : ""}`);
|
|
4019
4790
|
if (!options.dryRun) {
|
|
4020
4791
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
4021
4792
|
const toolInstallationId = identity?.toolInstallationId ?? options.toolInstallationId ?? (0, credentials_1.readHostCredentials)(spec.host)?.toolInstallationId ?? `${spec.toolType}:${crypto2.randomUUID()}`;
|
|
@@ -4025,31 +4796,76 @@ ${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName:
|
|
|
4025
4796
|
...identity ? { pairedAt: now } : { localOnly: true, installedAt: now }
|
|
4026
4797
|
});
|
|
4027
4798
|
}
|
|
4028
|
-
|
|
4799
|
+
if (isHomeProject2(options)) {
|
|
4800
|
+
detail("scope", "user (a project install in the home folder only loads when the agent starts there)");
|
|
4801
|
+
options.scope = "user";
|
|
4802
|
+
}
|
|
4029
4803
|
const settingsFile = spec.settings.settingsPath(options.scope, options.projectDir);
|
|
4030
4804
|
const before = registeredHookSets(readSettings(settingsFile), spec);
|
|
4031
4805
|
const written = writeHookSettings(settingsFile, binary, spec, options.dryRun);
|
|
4032
4806
|
if (written === null)
|
|
4033
4807
|
return 1;
|
|
4034
|
-
|
|
4808
|
+
const reach = options.scope === "user" ? "every project" : "this project only";
|
|
4809
|
+
row("ok", "hooks", `${(0, hookRunner_1.tidyHomePath)(settingsFile, os5.homedir())} ${ui.dim(`(${spec.hookEvents.length} events, ${reach}${written ? "" : ", already current"})`)}`);
|
|
4035
4810
|
const changes = spec.hookSet === void 0 ? void 0 : (0, hookSet_1.describeHookSetChanges)((0, hookSet_1.hookSetChanges)(before, spec.hookEvents), spec.hookSet);
|
|
4036
4811
|
if (changes)
|
|
4037
|
-
|
|
4812
|
+
detail("", changes);
|
|
4813
|
+
const otherFile = spec.settings.settingsPath(options.scope === "user" ? "project" : "user", options.projectDir);
|
|
4814
|
+
if (otherFile !== settingsFile && registeredHookSets(readSettings(otherFile), spec).size > 0) {
|
|
4815
|
+
if (options.dryRun) {
|
|
4816
|
+
row("info", "moved", `would remove the copy in ${(0, hookRunner_1.tidyHomePath)(otherFile, os5.homedir())}, so each event runs once`);
|
|
4817
|
+
} else if (removeOurHookEntries(otherFile, spec)) {
|
|
4818
|
+
row("ok", "moved", `removed the copy in ${(0, hookRunner_1.tidyHomePath)(otherFile, os5.homedir())}, so each event runs once ${ui.dim("(backup beside it)")}`);
|
|
4819
|
+
} else {
|
|
4820
|
+
row("warn", "note", `${(0, hookRunner_1.tidyHomePath)(otherFile, os5.homedir())} registers these hooks too, so each event runs twice.`);
|
|
4821
|
+
detail("", `Remove the ${spec.binaryName} entries from one of the two files.`);
|
|
4822
|
+
}
|
|
4823
|
+
}
|
|
4824
|
+
const chosenLocal = options.skipPairing;
|
|
4825
|
+
if (identity)
|
|
4826
|
+
row("ok", "pairing", `${identity.toolInstallationId}${ui.dim(identity.paired ? " (new)" : " (existing)")}`);
|
|
4827
|
+
else if (chosenLocal)
|
|
4828
|
+
row("info", "pairing", `none, as asked ${ui.dim("(--no-pair)")}`);
|
|
4829
|
+
else
|
|
4830
|
+
row("warn", "pairing", "not paired: pairing did not finish");
|
|
4831
|
+
detail("credentials", `${(0, hookRunner_1.tidyHomePath)((0, credentials_1.credentialsFilePath)(), os5.homedir())} (tools.${spec.host})`);
|
|
4038
4832
|
if (options.dryRun) {
|
|
4039
|
-
console.log("\nDry run
|
|
4833
|
+
console.log("\nDry run. Nothing was written.");
|
|
4040
4834
|
return 0;
|
|
4041
4835
|
}
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4836
|
+
const self = cliAgentSelfCommand(spec);
|
|
4837
|
+
const next = (label, value) => console.log(` ${ui.bold(label.padEnd(6))} ${value}`);
|
|
4838
|
+
console.log("");
|
|
4839
|
+
if (chosenLocal) {
|
|
4840
|
+
console.log(`${ui.mark("ok")} ${ui.bold("Ready.")} The screen saver and the Ascenda app's live view work now.`);
|
|
4841
|
+
console.log(" They run on this machine and need no account or pairing.");
|
|
4842
|
+
} else if (!identity) {
|
|
4843
|
+
console.log(`${ui.mark("warn")} ${ui.bold("Installed, not paired.")} The screen saver and the live view work now.`);
|
|
4844
|
+
console.log(" Your sessions won't reach Ascenda's servers until pairing completes.");
|
|
4845
|
+
} else {
|
|
4846
|
+
console.log(`${ui.mark("ok")} ${ui.bold("Done.")} Paired, and the hooks are installed.`);
|
|
4847
|
+
}
|
|
4848
|
+
console.log("");
|
|
4849
|
+
next("Next", spec.restartHint);
|
|
4850
|
+
next("Check", ui.cyan(`${self} doctor`));
|
|
4851
|
+
if (!identity)
|
|
4852
|
+
next(chosenLocal ? "Pair" : "Retry", `${ui.cyan(`${self} setup`)}${chosenLocal ? ui.dim(" (optional)") : ""}`);
|
|
4853
|
+
if (chosenLocal) {
|
|
4854
|
+
console.log("");
|
|
4855
|
+
console.log(ui.dim(" Pairing sends the details below to Ascenda's servers, under the account the"));
|
|
4856
|
+
console.log(ui.dim(" Ascenda app is signed in to when you confirm the code, so your sessions appear"));
|
|
4857
|
+
console.log(ui.dim(" in the app. Until you pair, nothing leaves this machine."));
|
|
4858
|
+
console.log("");
|
|
4859
|
+
console.log(ui.dim((0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName: spec.displayName }).split("\n").map((line) => ` ${line}`).join("\n")));
|
|
4046
4860
|
}
|
|
4047
|
-
console.log(`Check anytime: npx ${spec.packageName} status`);
|
|
4048
4861
|
return 0;
|
|
4049
4862
|
}
|
|
4863
|
+
function isHomeProject2(options) {
|
|
4864
|
+
return options.scope === "project" && path4.resolve(options.projectDir) === path4.resolve(os5.homedir());
|
|
4865
|
+
}
|
|
4050
4866
|
function parseArgs2(argv, spec) {
|
|
4051
4867
|
const options = {
|
|
4052
|
-
scope: "
|
|
4868
|
+
scope: "user",
|
|
4053
4869
|
projectDir: process.cwd(),
|
|
4054
4870
|
dryRun: false,
|
|
4055
4871
|
skipPairing: false,
|
|
@@ -4074,6 +4890,9 @@ Done. ${spec.restartHint}`);
|
|
|
4074
4890
|
case "uninstall":
|
|
4075
4891
|
options.action = "uninstall";
|
|
4076
4892
|
break;
|
|
4893
|
+
case "doctor":
|
|
4894
|
+
options.action = "doctor";
|
|
4895
|
+
break;
|
|
4077
4896
|
case "--api-base-url":
|
|
4078
4897
|
options.apiBaseUrl = next();
|
|
4079
4898
|
break;
|
|
@@ -4182,7 +5001,7 @@ ${usage(spec)}`);
|
|
|
4182
5001
|
const toolInstallationId = existingId ?? `${spec.toolType}:${crypto2.randomUUID()}`;
|
|
4183
5002
|
let session;
|
|
4184
5003
|
try {
|
|
4185
|
-
session = await (0, http_1.createPairingSession)(apiBaseUrl, toolInstallationId, spec.toolType, `${spec.displayName} on ${
|
|
5004
|
+
session = await (0, http_1.createPairingSession)(apiBaseUrl, toolInstallationId, spec.toolType, `${spec.displayName} on ${os5.hostname()}`);
|
|
4186
5005
|
} catch (error) {
|
|
4187
5006
|
console.error(`
|
|
4188
5007
|
Could not reach ${apiBaseUrl} to pair: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -4231,17 +5050,7 @@ Pairing ${status.status}. Run setup again.`);
|
|
|
4231
5050
|
return void 0;
|
|
4232
5051
|
}
|
|
4233
5052
|
function installBinary2(spec, dryRun) {
|
|
4234
|
-
|
|
4235
|
-
if (dryRun)
|
|
4236
|
-
return target;
|
|
4237
|
-
const source = process.argv[1];
|
|
4238
|
-
fs5.mkdirSync(path4.dirname(target), { recursive: true });
|
|
4239
|
-
if (path4.resolve(source) !== path4.resolve(target)) {
|
|
4240
|
-
fs5.copyFileSync(source, target);
|
|
4241
|
-
}
|
|
4242
|
-
if (process.platform !== "win32")
|
|
4243
|
-
fs5.chmodSync(target, 493);
|
|
4244
|
-
return target;
|
|
5053
|
+
return (0, hookRunner_1.installHookRunner)({ binaryName: spec.binaryName, setupCommand: `npx ${spec.packageName} setup`, dryRun });
|
|
4245
5054
|
}
|
|
4246
5055
|
function writeHookSettings(settingsFile, binary, spec, dryRun) {
|
|
4247
5056
|
let settings = { ...spec.settings.scaffold ?? {} };
|
|
@@ -4282,7 +5091,7 @@ ${serialised}`);
|
|
|
4282
5091
|
return true;
|
|
4283
5092
|
}
|
|
4284
5093
|
function hookCommand2(binary, spec) {
|
|
4285
|
-
return
|
|
5094
|
+
return `${(0, hookRunner_1.hookRunnerCommand)(binary)}${(0, hookSet_1.hookSetArgument)(spec.hookSet)}`;
|
|
4286
5095
|
}
|
|
4287
5096
|
function registeredHookSets(settings, spec) {
|
|
4288
5097
|
const sets = /* @__PURE__ */ new Map();
|
|
@@ -4335,7 +5144,18 @@ ${serialised}`);
|
|
|
4335
5144
|
console.log(`pairing ${credentials?.toolInstallationId ?? "\u2014 not paired"}${localOnly ? " (installed, not paired \u2014 local features active, telemetry inactive)" : ""}`);
|
|
4336
5145
|
console.log(`token ${localOnly ? "\u2014 none needed until this install is paired" : tokenFile && (0, tokenStore_1.readTokenFile)(tokenFile) ? "present" : "\u2014 missing"}`);
|
|
4337
5146
|
console.log(`hook binary ${fs5.existsSync(binary) ? binary : "\u2014 not installed"}`);
|
|
5147
|
+
const node = process.platform === "win32" ? void 0 : (0, hookRunner_1.resolveHookNode)(binary);
|
|
5148
|
+
if (node) {
|
|
5149
|
+
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"})`);
|
|
5150
|
+
}
|
|
5151
|
+
const last = (0, hookRunner_1.readLastHook)(spec.host);
|
|
5152
|
+
console.log(last ? `last hook ${last.event}, ${(0, hookRunner_1.describeAge)(Date.now() - Date.parse(last.at))}` : `last hook \u2014 none has run yet. Start ${spec.displayName} (restart it if it was open during setup)`);
|
|
4338
5153
|
console.log(`hooks ${registered}/${spec.hookEvents.length} registered in ${settingsFile}`);
|
|
5154
|
+
const otherScope = options.scope === "user" ? "project" : "user";
|
|
5155
|
+
const otherFile = spec.settings.settingsPath(otherScope, options.projectDir);
|
|
5156
|
+
const elsewhere = registered === 0 && otherFile !== settingsFile ? countRegistered2(readSettings(otherFile), spec) : 0;
|
|
5157
|
+
if (elsewhere > 0)
|
|
5158
|
+
console.log(` ${elsewhere}/${spec.hookEvents.length} found in ${otherFile} (--scope ${otherScope})`);
|
|
4339
5159
|
if (spec.hookSet !== void 0 && registered > 0) {
|
|
4340
5160
|
const sets = [...registeredHookSets(settings, spec).values()];
|
|
4341
5161
|
const oldest = Math.min(...sets);
|
|
@@ -4361,132 +5181,130 @@ ${serialised}`);
|
|
|
4361
5181
|
if (process.stdout.isTTY)
|
|
4362
5182
|
await notices.markShown();
|
|
4363
5183
|
const paired = localOnly || credentials?.toolInstallationId !== void 0;
|
|
4364
|
-
const
|
|
5184
|
+
const wired = registered === spec.hookEvents.length || options.scope === "project" && elsewhere === spec.hookEvents.length;
|
|
5185
|
+
const healthy = paired && wired && fs5.existsSync(binary) && !stale.length && !node?.problem;
|
|
4365
5186
|
return healthy ? 0 : 1;
|
|
4366
5187
|
}
|
|
4367
|
-
function
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
} catch {
|
|
4388
|
-
console.error(`could not parse ${settingsFile} \u2014 remove the ascenda hook entries by hand`);
|
|
4389
|
-
return 1;
|
|
4390
|
-
}
|
|
4391
|
-
}
|
|
4392
|
-
const binary = cliAgentHookBinPath(spec.binaryName);
|
|
4393
|
-
if (fs5.existsSync(binary)) {
|
|
4394
|
-
fs5.rmSync(binary);
|
|
4395
|
-
console.log(`removed ${binary}`);
|
|
5188
|
+
function countRegistered2(settings, spec) {
|
|
5189
|
+
return spec.hookEvents.filter((event) => (settings.hooks?.[event] ?? []).some((entry) => isOurs2(entry, spec))).length;
|
|
5190
|
+
}
|
|
5191
|
+
function cliAgentRegistrations(spec, projectDir = process.cwd()) {
|
|
5192
|
+
const home = os5.homedir();
|
|
5193
|
+
const userFile = spec.settings.settingsPath("user", projectDir);
|
|
5194
|
+
const projectFile = spec.settings.settingsPath("project", projectDir);
|
|
5195
|
+
const found = [];
|
|
5196
|
+
for (const [scope, file] of [["user", userFile], ["project", projectFile]]) {
|
|
5197
|
+
if (scope === "project" && file === userFile)
|
|
5198
|
+
continue;
|
|
5199
|
+
const registered = countRegistered2(readSettings(file), spec);
|
|
5200
|
+
if (registered === 0)
|
|
5201
|
+
continue;
|
|
5202
|
+
found.push({
|
|
5203
|
+
file: (0, hookRunner_1.tidyHomePath)(file, home),
|
|
5204
|
+
registered,
|
|
5205
|
+
scope,
|
|
5206
|
+
homeProject: scope === "project" && path4.resolve(projectDir) === path4.resolve(home)
|
|
5207
|
+
});
|
|
4396
5208
|
}
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
5209
|
+
return found;
|
|
5210
|
+
}
|
|
5211
|
+
async function runDoctor2(options, spec) {
|
|
5212
|
+
const ui = (0, terminalStyle_1.terminalStyle)();
|
|
5213
|
+
const lines = [`${ui.bold("Ascenda doctor")} ${ui.dim(`\xB7 ${spec.displayName}`)}`, ""];
|
|
5214
|
+
try {
|
|
5215
|
+
lines.push(...await (0, liveSignalDoctor_1.liveSignalDoctorLines)({
|
|
5216
|
+
displayName: spec.displayName,
|
|
5217
|
+
tool: spec.host,
|
|
5218
|
+
launcher: process.platform === "win32" ? void 0 : cliAgentHookBinPath(spec.binaryName),
|
|
5219
|
+
registrations: cliAgentRegistrations(spec, options.projectDir),
|
|
5220
|
+
eventCount: spec.hookEvents.length,
|
|
5221
|
+
selfCommand: cliAgentSelfCommand(spec),
|
|
5222
|
+
setupCommand: `npx ${spec.packageName} setup`,
|
|
5223
|
+
ui
|
|
5224
|
+
}));
|
|
5225
|
+
} catch (error) {
|
|
5226
|
+
lines.push(` Live signal (could not be checked: ${error instanceof Error ? error.message : String(error)})`);
|
|
4400
5227
|
}
|
|
4401
|
-
|
|
5228
|
+
lines.push("", ...accountLines(ui, spec));
|
|
5229
|
+
console.log(lines.join("\n"));
|
|
4402
5230
|
return 0;
|
|
4403
5231
|
}
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
5232
|
+
function accountLines(ui, spec) {
|
|
5233
|
+
const credentials = (0, credentials_1.readHostCredentials)(spec.host);
|
|
5234
|
+
const id = credentials?.toolInstallationId;
|
|
5235
|
+
const localOnly = (0, credentials_1.isLocalOnlyHostInstall)(spec.host, (installationId) => (0, tokenStore_1.readTokenFile)((0, tokenStore_1.defaultTokenFilePath)(installationId)) !== void 0);
|
|
5236
|
+
const row = (tone, label, value) => ` ${ui.mark(tone)} ${label.padEnd(20)} ${value}`;
|
|
5237
|
+
if (!id || localOnly) {
|
|
5238
|
+
return [
|
|
5239
|
+
` ${ui.bold("Account sync")} ${ui.dim("(optional; this install isn't paired)")}`,
|
|
5240
|
+
...id ? [ui.dim(row("info", "Installation id", id))] : [],
|
|
5241
|
+
"",
|
|
5242
|
+
" Not paired, which is fine: the screen saver and the live view above work",
|
|
5243
|
+
" without it. Nothing leaves this machine and nothing is queued. To send your",
|
|
5244
|
+
" sessions to Ascenda's servers, so they appear in the app:",
|
|
5245
|
+
` ${ui.cyan(`${cliAgentSelfCommand(spec)} setup`)}`
|
|
5246
|
+
];
|
|
4418
5247
|
}
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
});
|
|
4429
|
-
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
4430
|
-
var ownKeys = function(o) {
|
|
4431
|
-
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
4432
|
-
var ar = [];
|
|
4433
|
-
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
4434
|
-
return ar;
|
|
4435
|
-
};
|
|
4436
|
-
return ownKeys(o);
|
|
4437
|
-
};
|
|
4438
|
-
return function(mod) {
|
|
4439
|
-
if (mod && mod.__esModule) return mod;
|
|
4440
|
-
var result = {};
|
|
4441
|
-
if (mod != null) {
|
|
4442
|
-
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
4443
|
-
}
|
|
4444
|
-
__setModuleDefault(result, mod);
|
|
4445
|
-
return result;
|
|
4446
|
-
};
|
|
4447
|
-
}();
|
|
4448
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4449
|
-
exports.recordTurnStart = recordTurnStart;
|
|
4450
|
-
exports.consumeTurnDurationMs = consumeTurnDurationMs;
|
|
4451
|
-
var fs5 = __importStar(__require("fs"));
|
|
4452
|
-
var path4 = __importStar(__require("path"));
|
|
4453
|
-
var tokenStore_1 = require_tokenStore();
|
|
4454
|
-
var stateDir = () => process.env.ASCENDA_STATE_DIR ?? path4.join((0, tokenStore_1.ascendaHome)(), "state");
|
|
4455
|
-
function turnFile(agent, sessionId) {
|
|
4456
|
-
return path4.join(stateDir(), `${sanitize(agent)}-turn-${sanitize(sessionId)}`);
|
|
4457
|
-
}
|
|
4458
|
-
function sanitize(value) {
|
|
4459
|
-
return value.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
5248
|
+
const token = (0, tokenStore_1.readTokenFile)((0, tokenStore_1.defaultTokenFilePath)(id)) ?? process.env.ASCENDA_EVENT_WRITE_TOKEN?.trim();
|
|
5249
|
+
const state = (0, stateStore_1.readCollectorState)((0, stateStore_1.defaultStateFilePath)(id));
|
|
5250
|
+
const outcome = state?.lastOutcome;
|
|
5251
|
+
return [
|
|
5252
|
+
` ${ui.bold("Account sync")}`,
|
|
5253
|
+
row("info", "Installation id", id),
|
|
5254
|
+
token ? row("ok", "Token", "present") : row("bad", "Token", ui.red(`missing, so nothing can be sent. Run: npx ${spec.packageName} setup`)),
|
|
5255
|
+
outcome ? row(outcome === "accepted" ? "ok" : "warn", "Last send", `${outcome}${state?.lastAttemptAt ? ui.dim(` (${state.lastAttemptAt})`) : ""}`) : row("info", "Last send", "none yet")
|
|
5256
|
+
];
|
|
4460
5257
|
}
|
|
4461
|
-
function
|
|
4462
|
-
if (!
|
|
4463
|
-
return;
|
|
5258
|
+
function removeOurHookEntries(settingsFile, spec) {
|
|
5259
|
+
if (!fs5.existsSync(settingsFile))
|
|
5260
|
+
return true;
|
|
4464
5261
|
try {
|
|
4465
|
-
fs5.
|
|
4466
|
-
|
|
5262
|
+
const settings = JSON.parse(fs5.readFileSync(settingsFile, "utf8"));
|
|
5263
|
+
const hooks = { ...settings.hooks ?? {} };
|
|
5264
|
+
for (const event of Object.keys(hooks)) {
|
|
5265
|
+
const kept = hooks[event].filter((entry) => !isOurs2(entry, spec));
|
|
5266
|
+
if (kept.length)
|
|
5267
|
+
hooks[event] = kept;
|
|
5268
|
+
else
|
|
5269
|
+
delete hooks[event];
|
|
5270
|
+
}
|
|
5271
|
+
const updated = { ...settings, hooks };
|
|
5272
|
+
if (!Object.keys(hooks).length)
|
|
5273
|
+
delete updated.hooks;
|
|
5274
|
+
fs5.copyFileSync(settingsFile, `${settingsFile}.ascenda-backup`);
|
|
5275
|
+
fs5.writeFileSync(settingsFile, `${JSON.stringify(updated, null, 2)}
|
|
5276
|
+
`, "utf8");
|
|
5277
|
+
return true;
|
|
4467
5278
|
} catch {
|
|
5279
|
+
return false;
|
|
4468
5280
|
}
|
|
4469
5281
|
}
|
|
4470
|
-
function
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
5282
|
+
function uninstall2(options, spec) {
|
|
5283
|
+
const settingsFile = spec.settings.settingsPath(options.scope, options.projectDir);
|
|
5284
|
+
if (fs5.existsSync(settingsFile)) {
|
|
5285
|
+
if (!removeOurHookEntries(settingsFile, spec)) {
|
|
5286
|
+
console.error(`could not parse ${settingsFile} \u2014 remove the ascenda hook entries by hand`);
|
|
5287
|
+
return 1;
|
|
5288
|
+
}
|
|
5289
|
+
console.log(`hooks removed from ${settingsFile}`);
|
|
5290
|
+
}
|
|
5291
|
+
for (const file of (0, hookRunner_1.removeHookRunner)(spec.binaryName)) {
|
|
5292
|
+
if (!file.endsWith(".node") && !file.endsWith(".no-node"))
|
|
5293
|
+
console.log(`removed ${file}`);
|
|
5294
|
+
}
|
|
5295
|
+
if ((0, credentials_1.readHostCredentials)(spec.host)) {
|
|
5296
|
+
(0, credentials_1.removeHostCredentials)(spec.host);
|
|
5297
|
+
console.log(`removed tools.${spec.host} from ${(0, credentials_1.credentialsFilePath)()}`);
|
|
4482
5298
|
}
|
|
5299
|
+
console.log(`tokens left in ${path4.join((0, tokenStore_1.ascendaHome)(), "tokens")} \u2014 revoke in the Ascenda app to invalidate them`);
|
|
5300
|
+
return 0;
|
|
4483
5301
|
}
|
|
4484
5302
|
}
|
|
4485
5303
|
});
|
|
4486
5304
|
|
|
4487
|
-
// ../packages/tool-kit/out/
|
|
4488
|
-
var
|
|
4489
|
-
"../packages/tool-kit/out/
|
|
5305
|
+
// ../packages/tool-kit/out/turnState.js
|
|
5306
|
+
var require_turnState = __commonJS({
|
|
5307
|
+
"../packages/tool-kit/out/turnState.js"(exports) {
|
|
4490
5308
|
"use strict";
|
|
4491
5309
|
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4492
5310
|
if (k2 === void 0) k2 = k;
|
|
@@ -4526,134 +5344,40 @@ var require_liveBus = __commonJS({
|
|
|
4526
5344
|
};
|
|
4527
5345
|
}();
|
|
4528
5346
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4529
|
-
exports.
|
|
4530
|
-
exports.
|
|
4531
|
-
exports.liveBusSocketPath = liveBusSocketPath;
|
|
4532
|
-
exports.bucketPromptSize = bucketPromptSize2;
|
|
4533
|
-
exports.emitLiveSignal = emitLiveSignal2;
|
|
5347
|
+
exports.recordTurnStart = recordTurnStart;
|
|
5348
|
+
exports.consumeTurnDurationMs = consumeTurnDurationMs;
|
|
4534
5349
|
var fs5 = __importStar(__require("fs"));
|
|
4535
|
-
var net = __importStar(__require("net"));
|
|
4536
|
-
var os3 = __importStar(__require("os"));
|
|
4537
5350
|
var path4 = __importStar(__require("path"));
|
|
4538
|
-
var
|
|
4539
|
-
var
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
var SAVER_HOST_BUNDLE_ID = "com.apple.ScreenSaver.Engine.legacyScreenSaver";
|
|
4543
|
-
function liveBusSocketCandidates() {
|
|
4544
|
-
const override = process.env.ASCENDA_LIVE_BUS_SOCKET;
|
|
4545
|
-
if (override)
|
|
4546
|
-
return [override];
|
|
4547
|
-
const home = os3.homedir();
|
|
4548
|
-
return [
|
|
4549
|
-
path4.join(home, ".ascenda", "live.sock"),
|
|
4550
|
-
path4.join(home, "Library", "Containers", APP_BUNDLE_ID, "Data", ".ascenda", "live.sock"),
|
|
4551
|
-
path4.join(home, "Library", "Containers", SAVER_HOST_BUNDLE_ID, "Data", "l.sock")
|
|
4552
|
-
];
|
|
4553
|
-
}
|
|
4554
|
-
function existingSocketCandidates() {
|
|
4555
|
-
const candidates = liveBusSocketCandidates();
|
|
4556
|
-
if (process.env.ASCENDA_LIVE_BUS_SOCKET)
|
|
4557
|
-
return candidates;
|
|
4558
|
-
return candidates.filter((candidate) => {
|
|
4559
|
-
try {
|
|
4560
|
-
return fs5.statSync(candidate).isSocket();
|
|
4561
|
-
} catch {
|
|
4562
|
-
return false;
|
|
4563
|
-
}
|
|
4564
|
-
});
|
|
4565
|
-
}
|
|
4566
|
-
function liveBusSocketPath() {
|
|
4567
|
-
return existingSocketCandidates()[0] ?? liveBusSocketCandidates()[0];
|
|
5351
|
+
var tokenStore_1 = require_tokenStore();
|
|
5352
|
+
var stateDir = () => process.env.ASCENDA_STATE_DIR ?? path4.join((0, tokenStore_1.ascendaHome)(), "state");
|
|
5353
|
+
function turnFile(agent, sessionId) {
|
|
5354
|
+
return path4.join(stateDir(), `${sanitize(agent)}-turn-${sanitize(sessionId)}`);
|
|
4568
5355
|
}
|
|
4569
|
-
function
|
|
4570
|
-
|
|
4571
|
-
if (length <= 280)
|
|
4572
|
-
return "s";
|
|
4573
|
-
if (length <= 2e3)
|
|
4574
|
-
return "m";
|
|
4575
|
-
if (length <= 8e3)
|
|
4576
|
-
return "l";
|
|
4577
|
-
return "xl";
|
|
5356
|
+
function sanitize(value) {
|
|
5357
|
+
return value.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
4578
5358
|
}
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
5359
|
+
function recordTurnStart(agent, sessionId, now = Date.now()) {
|
|
5360
|
+
if (!sessionId)
|
|
5361
|
+
return;
|
|
5362
|
+
try {
|
|
5363
|
+
fs5.mkdirSync(stateDir(), { recursive: true });
|
|
5364
|
+
fs5.writeFileSync(turnFile(agent, sessionId), String(now), { encoding: "utf8", mode: 384 });
|
|
5365
|
+
} catch {
|
|
5366
|
+
}
|
|
4587
5367
|
}
|
|
4588
|
-
function
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
}
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
}
|
|
4602
|
-
socket = void 0;
|
|
4603
|
-
};
|
|
4604
|
-
const done = () => {
|
|
4605
|
-
if (settled)
|
|
4606
|
-
return;
|
|
4607
|
-
settled = true;
|
|
4608
|
-
clearTimeout(timer);
|
|
4609
|
-
drop();
|
|
4610
|
-
resolve2();
|
|
4611
|
-
};
|
|
4612
|
-
const timer = setTimeout(done, WRITE_TIMEOUT_MS);
|
|
4613
|
-
if (typeof timer.unref === "function")
|
|
4614
|
-
timer.unref();
|
|
4615
|
-
const tryFrom = (index) => {
|
|
4616
|
-
if (settled)
|
|
4617
|
-
return;
|
|
4618
|
-
if (index >= candidates.length) {
|
|
4619
|
-
done();
|
|
4620
|
-
return;
|
|
4621
|
-
}
|
|
4622
|
-
let attempt;
|
|
4623
|
-
try {
|
|
4624
|
-
attempt = net.createConnection(candidates[index]);
|
|
4625
|
-
} catch {
|
|
4626
|
-
tryFrom(index + 1);
|
|
4627
|
-
return;
|
|
4628
|
-
}
|
|
4629
|
-
socket = attempt;
|
|
4630
|
-
if (typeof attempt.unref === "function")
|
|
4631
|
-
attempt.unref();
|
|
4632
|
-
let connected = false;
|
|
4633
|
-
attempt.on("error", (error) => {
|
|
4634
|
-
if (settled || socket !== attempt)
|
|
4635
|
-
return;
|
|
4636
|
-
if (!connected && error.code && NOBODY_LISTENING.has(error.code)) {
|
|
4637
|
-
drop();
|
|
4638
|
-
tryFrom(index + 1);
|
|
4639
|
-
return;
|
|
4640
|
-
}
|
|
4641
|
-
done();
|
|
4642
|
-
});
|
|
4643
|
-
attempt.on("connect", () => {
|
|
4644
|
-
if (settled || socket !== attempt)
|
|
4645
|
-
return;
|
|
4646
|
-
connected = true;
|
|
4647
|
-
try {
|
|
4648
|
-
attempt.write(`${JSON.stringify(onTheWire(signal))}
|
|
4649
|
-
`, done);
|
|
4650
|
-
} catch {
|
|
4651
|
-
done();
|
|
4652
|
-
}
|
|
4653
|
-
});
|
|
4654
|
-
};
|
|
4655
|
-
tryFrom(0);
|
|
4656
|
-
});
|
|
5368
|
+
function consumeTurnDurationMs(agent, sessionId, now = Date.now()) {
|
|
5369
|
+
if (!sessionId)
|
|
5370
|
+
return void 0;
|
|
5371
|
+
const file = turnFile(agent, sessionId);
|
|
5372
|
+
try {
|
|
5373
|
+
const started = Number(fs5.readFileSync(file, "utf8").trim());
|
|
5374
|
+
fs5.rmSync(file, { force: true });
|
|
5375
|
+
if (!Number.isFinite(started) || started <= 0 || started > now)
|
|
5376
|
+
return void 0;
|
|
5377
|
+
return now - started;
|
|
5378
|
+
} catch {
|
|
5379
|
+
return void 0;
|
|
5380
|
+
}
|
|
4657
5381
|
}
|
|
4658
5382
|
}
|
|
4659
5383
|
});
|
|
@@ -4804,7 +5528,8 @@ var require_out2 = __commonJS({
|
|
|
4804
5528
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4805
5529
|
exports.FREE_TEXT_KEYS = exports.FAMILY_SENTENCES = exports.ALWAYS_SENT = exports.writeHookSettings = exports.runCliAgentSetup = exports.registeredHookSets = exports.isCliAgentManagementCommand = exports.findStaleHookCommands = exports.cliAgentHookBinPath = exports.resolveContextHashes = exports.resolveCliAgentInstallationId = exports.loadCliAgentConfig = exports.deliverHookEvents = exports.MissingInstallationIdError = exports.DEFAULT_API_BASE_URL = exports.resolveEventLogPath = exports.expandUserPath = exports.appendEventLog = exports.EVENT_LOG_ENV_VAR = exports.buildEventPayload = exports.TOKEN_RENEW_LEAD_MS = exports.AscendaSemanticEventError = exports.AscendaEventSender = exports.describeCollectorVersion = exports.UNRELEASED_COLLECTOR_VERSION = exports.COLLECTOR_VERSION = exports.mintIdempotencyKey = exports.looksLikeCorrection = exports.outcomeForHook = exports.inferOutcome = exports.getNestedNumber = exports.getNestedString = exports.getNested = exports.getNumber = exports.getString = exports.localHourAt = exports.utcOffsetMinutesAt = exports.BUSINESS_DAY = exports.isOutsideBusinessHours = exports.isAfterHours = exports.bucketDurationMs = exports.bucketLinesChanged = exports.classifyModelClass = exports.autonomyBand = exports.invitesDebrief = exports.classifyWorkMilestone = exports.isReworkGitAction = exports.classifyGitAction = exports.isVerificationCommand = exports.classifyCommand = void 0;
|
|
4806
5530
|
exports.recordWorkContextAlias = exports.recordWorkContext = exports.readBranchName = exports.normalizeBranchName = exports.deriveBranchHashForCwd = exports.deriveBranchHash = exports.deriveWorkContext = exports.hashWithMachineSalt = exports.readOrCreateMachineSalt = exports.machineSaltFilePath = exports.fixedTimeProvider = exports.systemTimeProvider = exports.enforceOutboxBounds = exports.claimOutbox = exports.readOutboxSummary = exports.appendToOutbox = exports.defaultOutboxFilePath = exports.outboxDrainEnabled = exports.DEFAULT_OUTBOX_DRAIN_BATCH_SIZE = exports.DEFAULT_OUTBOX_MAX_AGE_MS = exports.DEFAULT_OUTBOX_MAX_ENTRIES = exports.OUTBOX_DRAIN_ENV_VAR = exports.recordOutboxDiscard = exports.unresolvedToolInstallationId = exports.unresolvedStateFilePath = exports.markFailureNotified = exports.shouldAnnounceFailure = exports.recordSendOutcome = exports.readCollectorState = exports.defaultStateFilePath = exports.tokenExpiryFilePath = exports.readTokenFile = exports.readTokenExpiry = exports.persistEventWriteToken = exports.listPersistedToolInstallationIds = exports.defaultTokenFilePath = exports.ascendaHome = exports.EVENT_TOKEN_TTL_MS = exports.recordTurnStart = exports.consumeTurnDurationMs = exports.writeTopLevelCredentials = exports.writeMachineCredentials = exports.writeHostCredentials = exports.removeHostCredentials = exports.readMachineCredentials = exports.readHostCredentials = exports.isLocalOnlyHostInstall = exports.credentialsFilePath = exports.renderSetupDisclosure = exports.REFUSALS = void 0;
|
|
4807
|
-
exports.
|
|
5531
|
+
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.tidyHomePath = exports.stampLastHook = exports.resolveHookNode = exports.removeHookRunner = exports.readLastHook = exports.lastHookPath = exports.installHookRunner = 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.bucketPromptSize = exports.deliverLine = exports.emitLiveSignal = exports.recordForgeProjectAlias = exports.forgeFullNameFromConfig = exports.readForgeFullName = exports.parseForgeFullName = exports.forgeProjectHash = exports.workContextRegistryFilePath = exports.readWorkContextRegistry = void 0;
|
|
5532
|
+
exports.runStudyJoin = exports.studyNoticeStatus = exports.runStudyObjection = exports.renderStudyNotices = exports.NOTICED_PURPOSES = exports.renderInitiatives = exports.initiativesStatusLines = exports.INITIATIVE_COPY = exports.startStudyJoin = exports.setStudyObjection = exports.markStudyNoticeShown = exports.readStudyNotices = exports.readInitiatives = exports.isRetryableStatus = exports.parseIngestResponse = exports.postToolEventsBatch = exports.postToolEvent = exports.renewToolToken = exports.getStudyJoinStatus = exports.getPairingStatus = exports.createPairingSession = exports.AscendaApiError = exports.scriptMarkerIn = exports.psLookup = exports.psArgsLookup = exports.livePidFields = void 0;
|
|
4808
5533
|
var commandClassifier_1 = require_commandClassifier();
|
|
4809
5534
|
Object.defineProperty(exports, "classifyCommand", { enumerable: true, get: function() {
|
|
4810
5535
|
return commandClassifier_1.classifyCommand;
|
|
@@ -5154,6 +5879,9 @@ var require_out2 = __commonJS({
|
|
|
5154
5879
|
Object.defineProperty(exports, "emitLiveSignal", { enumerable: true, get: function() {
|
|
5155
5880
|
return liveBus_1.emitLiveSignal;
|
|
5156
5881
|
} });
|
|
5882
|
+
Object.defineProperty(exports, "deliverLine", { enumerable: true, get: function() {
|
|
5883
|
+
return liveBus_1.deliverLine;
|
|
5884
|
+
} });
|
|
5157
5885
|
Object.defineProperty(exports, "bucketPromptSize", { enumerable: true, get: function() {
|
|
5158
5886
|
return liveBus_1.bucketPromptSize;
|
|
5159
5887
|
} });
|
|
@@ -5166,6 +5894,85 @@ var require_out2 = __commonJS({
|
|
|
5166
5894
|
Object.defineProperty(exports, "LIVE_BUS_BACKGROUND_TRUST_MS", { enumerable: true, get: function() {
|
|
5167
5895
|
return liveBus_1.LIVE_BUS_BACKGROUND_TRUST_MS;
|
|
5168
5896
|
} });
|
|
5897
|
+
var saverHandoff_1 = require_saverHandoff();
|
|
5898
|
+
Object.defineProperty(exports, "holdForSaver", { enumerable: true, get: function() {
|
|
5899
|
+
return saverHandoff_1.holdForSaver;
|
|
5900
|
+
} });
|
|
5901
|
+
Object.defineProperty(exports, "heldForSaver", { enumerable: true, get: function() {
|
|
5902
|
+
return saverHandoff_1.heldForSaver;
|
|
5903
|
+
} });
|
|
5904
|
+
Object.defineProperty(exports, "probeSocket", { enumerable: true, get: function() {
|
|
5905
|
+
return saverHandoff_1.probeSocket;
|
|
5906
|
+
} });
|
|
5907
|
+
Object.defineProperty(exports, "readSaverStatuses", { enumerable: true, get: function() {
|
|
5908
|
+
return saverHandoff_1.readSaverStatuses;
|
|
5909
|
+
} });
|
|
5910
|
+
Object.defineProperty(exports, "saverContainerDir", { enumerable: true, get: function() {
|
|
5911
|
+
return saverHandoff_1.saverContainerDir;
|
|
5912
|
+
} });
|
|
5913
|
+
Object.defineProperty(exports, "saverReplayPath", { enumerable: true, get: function() {
|
|
5914
|
+
return saverHandoff_1.saverReplayPath;
|
|
5915
|
+
} });
|
|
5916
|
+
Object.defineProperty(exports, "saverStatusDir", { enumerable: true, get: function() {
|
|
5917
|
+
return saverHandoff_1.saverStatusDir;
|
|
5918
|
+
} });
|
|
5919
|
+
Object.defineProperty(exports, "saverSupportDir", { enumerable: true, get: function() {
|
|
5920
|
+
return saverHandoff_1.saverSupportDir;
|
|
5921
|
+
} });
|
|
5922
|
+
Object.defineProperty(exports, "SAVER_REPLAY_WINDOW_MS", { enumerable: true, get: function() {
|
|
5923
|
+
return saverHandoff_1.SAVER_REPLAY_WINDOW_MS;
|
|
5924
|
+
} });
|
|
5925
|
+
var terminalStyle_1 = require_terminalStyle();
|
|
5926
|
+
Object.defineProperty(exports, "colourEnabled", { enumerable: true, get: function() {
|
|
5927
|
+
return terminalStyle_1.colourEnabled;
|
|
5928
|
+
} });
|
|
5929
|
+
Object.defineProperty(exports, "terminalStyle", { enumerable: true, get: function() {
|
|
5930
|
+
return terminalStyle_1.terminalStyle;
|
|
5931
|
+
} });
|
|
5932
|
+
var hookRunner_1 = require_hookRunner();
|
|
5933
|
+
Object.defineProperty(exports, "describeAge", { enumerable: true, get: function() {
|
|
5934
|
+
return hookRunner_1.describeAge;
|
|
5935
|
+
} });
|
|
5936
|
+
Object.defineProperty(exports, "hookLauncherScript", { enumerable: true, get: function() {
|
|
5937
|
+
return hookRunner_1.hookLauncherScript;
|
|
5938
|
+
} });
|
|
5939
|
+
Object.defineProperty(exports, "hookRunnerCommand", { enumerable: true, get: function() {
|
|
5940
|
+
return hookRunner_1.hookRunnerCommand;
|
|
5941
|
+
} });
|
|
5942
|
+
Object.defineProperty(exports, "hookRunnerPaths", { enumerable: true, get: function() {
|
|
5943
|
+
return hookRunner_1.hookRunnerPaths;
|
|
5944
|
+
} });
|
|
5945
|
+
Object.defineProperty(exports, "installHookRunner", { enumerable: true, get: function() {
|
|
5946
|
+
return hookRunner_1.installHookRunner;
|
|
5947
|
+
} });
|
|
5948
|
+
Object.defineProperty(exports, "lastHookPath", { enumerable: true, get: function() {
|
|
5949
|
+
return hookRunner_1.lastHookPath;
|
|
5950
|
+
} });
|
|
5951
|
+
Object.defineProperty(exports, "readLastHook", { enumerable: true, get: function() {
|
|
5952
|
+
return hookRunner_1.readLastHook;
|
|
5953
|
+
} });
|
|
5954
|
+
Object.defineProperty(exports, "removeHookRunner", { enumerable: true, get: function() {
|
|
5955
|
+
return hookRunner_1.removeHookRunner;
|
|
5956
|
+
} });
|
|
5957
|
+
Object.defineProperty(exports, "resolveHookNode", { enumerable: true, get: function() {
|
|
5958
|
+
return hookRunner_1.resolveHookNode;
|
|
5959
|
+
} });
|
|
5960
|
+
Object.defineProperty(exports, "stampLastHook", { enumerable: true, get: function() {
|
|
5961
|
+
return hookRunner_1.stampLastHook;
|
|
5962
|
+
} });
|
|
5963
|
+
Object.defineProperty(exports, "tidyHomePath", { enumerable: true, get: function() {
|
|
5964
|
+
return hookRunner_1.tidyHomePath;
|
|
5965
|
+
} });
|
|
5966
|
+
var liveSignalDoctor_1 = require_liveSignalDoctor();
|
|
5967
|
+
Object.defineProperty(exports, "DOCTOR_VALUE_COLUMN", { enumerable: true, get: function() {
|
|
5968
|
+
return liveSignalDoctor_1.DOCTOR_VALUE_COLUMN;
|
|
5969
|
+
} });
|
|
5970
|
+
Object.defineProperty(exports, "doctorRow", { enumerable: true, get: function() {
|
|
5971
|
+
return liveSignalDoctor_1.doctorRow;
|
|
5972
|
+
} });
|
|
5973
|
+
Object.defineProperty(exports, "liveSignalDoctorLines", { enumerable: true, get: function() {
|
|
5974
|
+
return liveSignalDoctor_1.liveSignalDoctorLines;
|
|
5975
|
+
} });
|
|
5169
5976
|
var hookSet_1 = require_hookSet();
|
|
5170
5977
|
Object.defineProperty(exports, "HOOK_SET_FLAG", { enumerable: true, get: function() {
|
|
5171
5978
|
return hookSet_1.HOOK_SET_FLAG;
|
|
@@ -5324,10 +6131,20 @@ var init_types = __esm({
|
|
|
5324
6131
|
|
|
5325
6132
|
// src/paths.ts
|
|
5326
6133
|
import * as fs2 from "fs";
|
|
6134
|
+
import * as os2 from "os";
|
|
5327
6135
|
import * as path2 from "path";
|
|
5328
6136
|
function hookBinPath() {
|
|
5329
6137
|
return path2.join((0, import_tool_kit5.ascendaHome)(), "bin", "ascenda-claude-hook");
|
|
5330
6138
|
}
|
|
6139
|
+
function hookBundlePath() {
|
|
6140
|
+
return path2.join((0, import_tool_kit5.ascendaHome)(), "bin", "ascenda-claude-hook.mjs");
|
|
6141
|
+
}
|
|
6142
|
+
function hookNodeRecordPath() {
|
|
6143
|
+
return path2.join((0, import_tool_kit5.ascendaHome)(), "bin", "ascenda-claude-hook.node");
|
|
6144
|
+
}
|
|
6145
|
+
function hookNoNodePath() {
|
|
6146
|
+
return path2.join((0, import_tool_kit5.ascendaHome)(), "bin", "ascenda-claude-hook.no-node");
|
|
6147
|
+
}
|
|
5331
6148
|
function readCredentials() {
|
|
5332
6149
|
const credentials = (0, import_tool_kit5.readMachineCredentials)();
|
|
5333
6150
|
if (!credentials) return void 0;
|
|
@@ -5346,6 +6163,12 @@ function removeCredentials() {
|
|
|
5346
6163
|
}
|
|
5347
6164
|
fs2.rmSync((0, import_tool_kit5.credentialsFilePath)(), { force: true });
|
|
5348
6165
|
}
|
|
6166
|
+
function selfCommand() {
|
|
6167
|
+
if (process.platform === "win32") return "npx @ascenda-one/claude-code-hooks";
|
|
6168
|
+
const home = os2.homedir();
|
|
6169
|
+
const bin = hookBinPath();
|
|
6170
|
+
return bin.startsWith(`${home}/`) ? `~${bin.slice(home.length)}` : bin;
|
|
6171
|
+
}
|
|
5349
6172
|
var import_tool_kit5, import_tool_kit6;
|
|
5350
6173
|
var init_paths = __esm({
|
|
5351
6174
|
"src/paths.ts"() {
|
|
@@ -5445,19 +6268,57 @@ var init_config = __esm({
|
|
|
5445
6268
|
}
|
|
5446
6269
|
});
|
|
5447
6270
|
|
|
6271
|
+
// src/hookHealth.ts
|
|
6272
|
+
function stampLastHook(event, now = /* @__PURE__ */ new Date()) {
|
|
6273
|
+
(0, import_tool_kit8.stampLastHook)(TOOL, event, now);
|
|
6274
|
+
}
|
|
6275
|
+
function readLastHook() {
|
|
6276
|
+
return (0, import_tool_kit8.readLastHook)(TOOL);
|
|
6277
|
+
}
|
|
6278
|
+
function resolveHookNode() {
|
|
6279
|
+
return (0, import_tool_kit8.resolveHookNode)(hookBinPath());
|
|
6280
|
+
}
|
|
6281
|
+
var import_tool_kit8, import_tool_kit9, TOOL;
|
|
6282
|
+
var init_hookHealth = __esm({
|
|
6283
|
+
"src/hookHealth.ts"() {
|
|
6284
|
+
"use strict";
|
|
6285
|
+
import_tool_kit8 = __toESM(require_out2(), 1);
|
|
6286
|
+
init_paths();
|
|
6287
|
+
import_tool_kit9 = __toESM(require_out2(), 1);
|
|
6288
|
+
TOOL = "claude_code";
|
|
6289
|
+
}
|
|
6290
|
+
});
|
|
6291
|
+
|
|
6292
|
+
// src/launcher.ts
|
|
6293
|
+
var import_tool_kit10, LAUNCHER_OPTIONS, LAUNCHER_SCRIPT;
|
|
6294
|
+
var init_launcher = __esm({
|
|
6295
|
+
"src/launcher.ts"() {
|
|
6296
|
+
"use strict";
|
|
6297
|
+
import_tool_kit10 = __toESM(require_out2(), 1);
|
|
6298
|
+
LAUNCHER_OPTIONS = {
|
|
6299
|
+
binaryName: "ascenda-claude-hook",
|
|
6300
|
+
setupCommand: "npx @ascenda-one/claude-code-hooks setup",
|
|
6301
|
+
loudEvent: "SessionStart"
|
|
6302
|
+
};
|
|
6303
|
+
LAUNCHER_SCRIPT = (0, import_tool_kit10.hookLauncherScript)(LAUNCHER_OPTIONS);
|
|
6304
|
+
}
|
|
6305
|
+
});
|
|
6306
|
+
|
|
5448
6307
|
// src/setup.ts
|
|
5449
6308
|
var setup_exports = {};
|
|
5450
6309
|
__export(setup_exports, {
|
|
5451
6310
|
HOOK_SET: () => HOOK_SET,
|
|
6311
|
+
REGISTERED_EVENT_COUNT: () => REGISTERED_EVENT_COUNT,
|
|
5452
6312
|
SENDS: () => SENDS,
|
|
5453
6313
|
findStaleHookCommands: () => findStaleHookCommands,
|
|
5454
6314
|
ourHookSets: () => ourHookSets,
|
|
6315
|
+
registrationSummary: () => registrationSummary,
|
|
5455
6316
|
runSetup: () => runSetup,
|
|
5456
6317
|
writeSettings: () => writeSettings
|
|
5457
6318
|
});
|
|
5458
6319
|
import * as crypto from "crypto";
|
|
5459
6320
|
import * as fs3 from "fs";
|
|
5460
|
-
import * as
|
|
6321
|
+
import * as os3 from "os";
|
|
5461
6322
|
import * as path3 from "path";
|
|
5462
6323
|
async function runSetup(argv) {
|
|
5463
6324
|
let options;
|
|
@@ -5474,17 +6335,21 @@ async function runSetup(argv) {
|
|
|
5474
6335
|
if (options.action === "status") return await printStatus(options);
|
|
5475
6336
|
if (options.action === "uninstall") return uninstall(options);
|
|
5476
6337
|
const apiBaseUrl = (options.apiBaseUrl ?? readCredentials()?.apiBaseUrl ?? DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
console.log(`
|
|
5480
|
-
|
|
6338
|
+
const ui = (0, import_tool_kit11.terminalStyle)();
|
|
6339
|
+
const row = (tone, label, value) => console.log(` ${ui.mark(tone)} ${label.padEnd(12)} ${value}`);
|
|
6340
|
+
const detail = (label, value) => console.log(ui.dim(` ${label.padEnd(12)} ${value}`));
|
|
6341
|
+
console.log(`${ui.bold("Ascenda setup")} ${ui.dim(`\xB7 Claude Code \xB7 ${apiBaseUrl}`)}`);
|
|
6342
|
+
if (options.pair) console.log(`
|
|
6343
|
+
${(0, import_tool_kit11.renderSetupDisclosure)({ sends: SENDS, displayName: "Claude Code" })}
|
|
5481
6344
|
`);
|
|
6345
|
+
else console.log("");
|
|
5482
6346
|
const identity = await resolveIdentity(apiBaseUrl, options);
|
|
5483
6347
|
const unpaired = identity.pairing === "local-only";
|
|
5484
|
-
|
|
5485
|
-
if (unpaired) console.log(` installation ${identity.toolInstallationId} (recorded, so a later pair attaches to it)`);
|
|
6348
|
+
const chosenLocal = unpaired && !options.pair;
|
|
5486
6349
|
const binary = installBinary(options.dryRun);
|
|
5487
|
-
|
|
6350
|
+
const node = options.dryRun || process.platform === "win32" ? void 0 : resolveHookNode();
|
|
6351
|
+
if (node?.problem) row("bad", "hook binary", `${tidyHome(binary)}, but ${node.problem}. Install Node 20 or newer, then run setup again`);
|
|
6352
|
+
else row("ok", "hook binary", `${tidyHome(binary)}${node?.version ? ui.dim(` (Node ${node.version})`) : ""}`);
|
|
5488
6353
|
if (!options.dryRun) {
|
|
5489
6354
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
5490
6355
|
writeCredentials({
|
|
@@ -5496,39 +6361,79 @@ ${(0, import_tool_kit8.renderSetupDisclosure)({ sends: SENDS, displayName: "Clau
|
|
|
5496
6361
|
...unpaired ? { localOnly: true, installedAt: now } : { pairedAt: now }
|
|
5497
6362
|
});
|
|
5498
6363
|
}
|
|
5499
|
-
|
|
6364
|
+
if (isHomeProject(options)) {
|
|
6365
|
+
detail("scope", "user (a project install in the home folder only loads when Claude Code starts there)");
|
|
6366
|
+
options.scope = "user";
|
|
6367
|
+
}
|
|
5500
6368
|
const settingsFile = settingsPath(options);
|
|
5501
6369
|
const before = ourHookSets(readSettingsFile(settingsFile));
|
|
5502
6370
|
const written = writeSettings(settingsFile, binary, options.dryRun);
|
|
5503
6371
|
if (written === null) return 1;
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
6372
|
+
const reach = options.scope === "user" ? "every project" : "this project only";
|
|
6373
|
+
row("ok", "hooks", `${tidyHome(settingsFile)} ${ui.dim(`(${HOOK_EVENTS.length} events, ${reach}${written ? "" : ", already current"})`)}`);
|
|
6374
|
+
const changes = (0, import_tool_kit11.describeHookSetChanges)((0, import_tool_kit11.hookSetChanges)(before, HOOK_EVENTS), HOOK_SET);
|
|
6375
|
+
if (changes) detail("", changes);
|
|
6376
|
+
const otherFiles = /* @__PURE__ */ new Set([
|
|
6377
|
+
settingsPath({ ...options, scope: options.scope === "user" ? "project" : "user" }),
|
|
6378
|
+
// The home folder's project file, where a project-scope setup run from
|
|
6379
|
+
// `~` used to put them.
|
|
6380
|
+
path3.join(os3.homedir(), ".claude", "settings.local.json")
|
|
6381
|
+
]);
|
|
6382
|
+
otherFiles.delete(settingsFile);
|
|
6383
|
+
for (const otherFile of otherFiles) {
|
|
6384
|
+
if (ourHookSets(readSettingsFile(otherFile)).size === 0) continue;
|
|
6385
|
+
if (options.dryRun) {
|
|
6386
|
+
row("info", "moved", `would remove the copy in ${tidyHome(otherFile)}, so each event runs once`);
|
|
6387
|
+
} else if (removeOurHooks(otherFile)) {
|
|
6388
|
+
row("ok", "moved", `removed the copy in ${tidyHome(otherFile)}, so each event runs once ${ui.dim("(backup beside it)")}`);
|
|
6389
|
+
} else {
|
|
6390
|
+
row("warn", "note", `${tidyHome(otherFile)} registers these hooks too, so each event runs twice.`);
|
|
6391
|
+
detail("", "Remove the ascenda-claude-hook entries from one of the two files.");
|
|
6392
|
+
}
|
|
6393
|
+
}
|
|
6394
|
+
if (chosenLocal) {
|
|
6395
|
+
row("info", "pairing", `none, as asked ${ui.dim("(--no-pair)")}`);
|
|
6396
|
+
} else if (unpaired) {
|
|
6397
|
+
row("warn", "pairing", `not paired: ${identity.reason}`);
|
|
6398
|
+
if (identity.hint) detail("", identity.hint);
|
|
6399
|
+
} else {
|
|
6400
|
+
row("ok", "pairing", `${identity.toolInstallationId}${ui.dim(identity.pairing === "new" ? " (new)" : " (existing)")}`);
|
|
5511
6401
|
}
|
|
6402
|
+
if (unpaired) detail("installation", `${identity.toolInstallationId} (kept, so pairing later attaches to it)`);
|
|
6403
|
+
detail("credentials", tidyHome((0, import_tool_kit6.credentialsFilePath)()));
|
|
5512
6404
|
if (options.dryRun) {
|
|
5513
|
-
console.log("\nDry run
|
|
6405
|
+
console.log("\nDry run. Nothing was written.");
|
|
5514
6406
|
return 0;
|
|
5515
6407
|
}
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
console.log("
|
|
5522
|
-
|
|
6408
|
+
const self = selfCommand();
|
|
6409
|
+
const next = (label, value) => console.log(` ${ui.bold(label.padEnd(6))} ${value}`);
|
|
6410
|
+
console.log("");
|
|
6411
|
+
if (chosenLocal) {
|
|
6412
|
+
console.log(`${ui.mark("ok")} ${ui.bold("Ready.")} The screen saver and the Ascenda app's live view work now.`);
|
|
6413
|
+
console.log(" They run on this machine and need no account or pairing.");
|
|
6414
|
+
} else if (unpaired) {
|
|
6415
|
+
console.log(`${ui.mark("warn")} ${ui.bold("Installed, not paired.")} The screen saver and the live view work now.`);
|
|
6416
|
+
console.log(` Your sessions won't reach Ascenda's servers until pairing completes.`);
|
|
5523
6417
|
} else {
|
|
5524
|
-
console.log("
|
|
6418
|
+
console.log(`${ui.mark("ok")} ${ui.bold("Done.")} Paired, and the hooks are installed.`);
|
|
6419
|
+
}
|
|
6420
|
+
console.log("");
|
|
6421
|
+
next("Next", `${restartLine(options)} Then type ${ui.cyan("/hooks")}: Ascenda's are under ${options.scope === "user" ? "User" : "Local"}.`);
|
|
6422
|
+
next("Check", ui.cyan(`${self} doctor`));
|
|
6423
|
+
if (unpaired) next(chosenLocal ? "Pair" : "Retry", `${ui.cyan(`${self} pair`)}${chosenLocal ? ui.dim(" (optional)") : ""}`);
|
|
6424
|
+
if (chosenLocal) {
|
|
6425
|
+
console.log("");
|
|
6426
|
+
console.log(ui.dim(" Pairing sends the details below to Ascenda's servers, under the account the"));
|
|
6427
|
+
console.log(ui.dim(" Ascenda app is signed in to when you confirm the code, so your sessions appear"));
|
|
6428
|
+
console.log(ui.dim(" in the app. Until you pair, nothing leaves this machine."));
|
|
6429
|
+
console.log("");
|
|
6430
|
+
console.log(ui.dim((0, import_tool_kit11.renderSetupDisclosure)({ sends: SENDS, displayName: "Claude Code" }).split("\n").map((line) => ` ${line}`).join("\n")));
|
|
5525
6431
|
}
|
|
5526
|
-
console.log(`Check anytime: npx @ascenda-one/claude-code-hooks status`);
|
|
5527
6432
|
return 0;
|
|
5528
6433
|
}
|
|
5529
6434
|
function parseArgs(argv) {
|
|
5530
6435
|
const options = {
|
|
5531
|
-
scope: "
|
|
6436
|
+
scope: "user",
|
|
5532
6437
|
projectDir: process.env.CLAUDE_PROJECT_DIR ?? process.cwd(),
|
|
5533
6438
|
dryRun: false,
|
|
5534
6439
|
pair: true,
|
|
@@ -5599,13 +6504,16 @@ ${USAGE}`);
|
|
|
5599
6504
|
}
|
|
5600
6505
|
return options;
|
|
5601
6506
|
}
|
|
6507
|
+
function isHomeProject(options) {
|
|
6508
|
+
return options.scope === "project" && path3.resolve(options.projectDir) === path3.resolve(os3.homedir());
|
|
6509
|
+
}
|
|
5602
6510
|
async function resolveIdentity(apiBaseUrl, options) {
|
|
5603
6511
|
const existingId = options.toolInstallationId ?? readCredentials()?.toolInstallationId;
|
|
5604
6512
|
if (existingId && options.token) {
|
|
5605
|
-
if (!options.dryRun) (0,
|
|
6513
|
+
if (!options.dryRun) (0, import_tool_kit11.persistEventWriteToken)((0, import_tool_kit11.defaultTokenFilePath)(existingId), options.token);
|
|
5606
6514
|
return { toolInstallationId: existingId, pairing: "existing" };
|
|
5607
6515
|
}
|
|
5608
|
-
if (existingId && (0,
|
|
6516
|
+
if (existingId && (0, import_tool_kit11.readTokenFile)((0, import_tool_kit11.defaultTokenFilePath)(existingId))) {
|
|
5609
6517
|
return { toolInstallationId: existingId, pairing: "existing" };
|
|
5610
6518
|
}
|
|
5611
6519
|
const toolInstallationId = existingId ?? (options.dryRun ? `${ASCENDA_TOOL_TYPE}:<minted at run time>` : `${ASCENDA_TOOL_TYPE}:${crypto.randomUUID()}`);
|
|
@@ -5617,7 +6525,7 @@ async function resolveIdentity(apiBaseUrl, options) {
|
|
|
5617
6525
|
}
|
|
5618
6526
|
let session;
|
|
5619
6527
|
try {
|
|
5620
|
-
session = await (0,
|
|
6528
|
+
session = await (0, import_tool_kit11.createPairingSession)(apiBaseUrl, toolInstallationId, ASCENDA_TOOL_TYPE, `Claude Code on ${os3.hostname()}`);
|
|
5621
6529
|
} catch (error) {
|
|
5622
6530
|
return {
|
|
5623
6531
|
toolInstallationId,
|
|
@@ -5628,7 +6536,7 @@ async function resolveIdentity(apiBaseUrl, options) {
|
|
|
5628
6536
|
}
|
|
5629
6537
|
const outcome = await pollForToken(apiBaseUrl, session.pairingSessionId, session.code, session.expiresAt);
|
|
5630
6538
|
if ("reason" in outcome) return { toolInstallationId, pairing: "local-only", reason: outcome.reason };
|
|
5631
|
-
(0,
|
|
6539
|
+
(0, import_tool_kit11.persistEventWriteToken)((0, import_tool_kit11.defaultTokenFilePath)(toolInstallationId), outcome.token);
|
|
5632
6540
|
return { toolInstallationId, pairing: "new" };
|
|
5633
6541
|
}
|
|
5634
6542
|
async function pollForToken(apiBaseUrl, pairingSessionId, code, expiresAt) {
|
|
@@ -5638,7 +6546,7 @@ async function pollForToken(apiBaseUrl, pairingSessionId, code, expiresAt) {
|
|
|
5638
6546
|
while (Date.now() < deadline) {
|
|
5639
6547
|
let status;
|
|
5640
6548
|
try {
|
|
5641
|
-
status = await (0,
|
|
6549
|
+
status = await (0, import_tool_kit11.getPairingStatus)(apiBaseUrl, pairingSessionId);
|
|
5642
6550
|
failures = 0;
|
|
5643
6551
|
} catch (error) {
|
|
5644
6552
|
if (++failures >= POLL_ERROR_TOLERANCE) {
|
|
@@ -5659,19 +6567,18 @@ async function pollForToken(apiBaseUrl, pairingSessionId, code, expiresAt) {
|
|
|
5659
6567
|
}
|
|
5660
6568
|
return { reason: "no confirmation within 5 minutes" };
|
|
5661
6569
|
}
|
|
6570
|
+
function tidyHome(file) {
|
|
6571
|
+
const home = os3.homedir();
|
|
6572
|
+
return file.startsWith(`${home}/`) ? `~${file.slice(home.length)}` : file;
|
|
6573
|
+
}
|
|
6574
|
+
function restartLine(options) {
|
|
6575
|
+
return options.scope === "user" ? "Restart Claude Code to load the hooks." : "Restart Claude Code in this project to load the hooks.";
|
|
6576
|
+
}
|
|
5662
6577
|
function installBinary(dryRun) {
|
|
5663
|
-
|
|
5664
|
-
if (dryRun) return target;
|
|
5665
|
-
const source = process.argv[1];
|
|
5666
|
-
fs3.mkdirSync(path3.dirname(target), { recursive: true });
|
|
5667
|
-
if (path3.resolve(source) !== path3.resolve(target)) {
|
|
5668
|
-
fs3.copyFileSync(source, target);
|
|
5669
|
-
}
|
|
5670
|
-
if (process.platform !== "win32") fs3.chmodSync(target, 493);
|
|
5671
|
-
return target;
|
|
6578
|
+
return (0, import_tool_kit11.installHookRunner)({ ...LAUNCHER_OPTIONS, dryRun });
|
|
5672
6579
|
}
|
|
5673
6580
|
function settingsPath(options) {
|
|
5674
|
-
return options.scope === "user" ? path3.join(
|
|
6581
|
+
return options.scope === "user" ? path3.join(os3.homedir(), ".claude", "settings.json") : path3.join(options.projectDir, ".claude", "settings.local.json");
|
|
5675
6582
|
}
|
|
5676
6583
|
function writeSettings(settingsFile, binary, dryRun) {
|
|
5677
6584
|
let settings = {};
|
|
@@ -5692,7 +6599,7 @@ ${settingsFile} is not valid JSON. Fix or move it, then run setup again.`);
|
|
|
5692
6599
|
const hooks = { ...settings.hooks ?? {} };
|
|
5693
6600
|
for (const event of HOOK_EVENTS) {
|
|
5694
6601
|
const kept = (hooks[event] ?? []).filter((group) => !isOurs(group));
|
|
5695
|
-
hooks[event] = [...kept, { hooks: [{ type: "command", command: `${command} ${event}${(0,
|
|
6602
|
+
hooks[event] = [...kept, { hooks: [{ type: "command", command: `${command} ${event}${(0, import_tool_kit11.hookSetArgument)(HOOK_SET)}`, timeout: HOOK_TIMEOUT_SECONDS }] }];
|
|
5696
6603
|
}
|
|
5697
6604
|
const updated = { ...settings, hooks };
|
|
5698
6605
|
const serialised = `${JSON.stringify(updated, null, 2)}
|
|
@@ -5710,7 +6617,26 @@ ${serialised}`);
|
|
|
5710
6617
|
return true;
|
|
5711
6618
|
}
|
|
5712
6619
|
function hookCommand(binary) {
|
|
5713
|
-
return
|
|
6620
|
+
return (0, import_tool_kit11.hookRunnerCommand)(binary);
|
|
6621
|
+
}
|
|
6622
|
+
function removeOurHooks(settingsFile) {
|
|
6623
|
+
try {
|
|
6624
|
+
const settings = JSON.parse(fs3.readFileSync(settingsFile, "utf8"));
|
|
6625
|
+
const hooks = { ...settings.hooks ?? {} };
|
|
6626
|
+
for (const event of Object.keys(hooks)) {
|
|
6627
|
+
const kept = hooks[event].filter((group) => !isOurs(group));
|
|
6628
|
+
if (kept.length) hooks[event] = kept;
|
|
6629
|
+
else delete hooks[event];
|
|
6630
|
+
}
|
|
6631
|
+
const updated = { ...settings, hooks };
|
|
6632
|
+
if (!Object.keys(hooks).length) delete updated.hooks;
|
|
6633
|
+
fs3.copyFileSync(settingsFile, `${settingsFile}.ascenda-backup`);
|
|
6634
|
+
fs3.writeFileSync(settingsFile, `${JSON.stringify(updated, null, 2)}
|
|
6635
|
+
`, "utf8");
|
|
6636
|
+
return true;
|
|
6637
|
+
} catch {
|
|
6638
|
+
return false;
|
|
6639
|
+
}
|
|
5714
6640
|
}
|
|
5715
6641
|
function isOurs(group) {
|
|
5716
6642
|
return (group.hooks ?? []).some((entry) => typeof entry.command === "string" && entry.command.includes(HOOK_MARKER));
|
|
@@ -5743,7 +6669,7 @@ function ourHookSets(settings) {
|
|
|
5743
6669
|
if (!isOurs(group)) continue;
|
|
5744
6670
|
for (const entry of group.hooks ?? []) {
|
|
5745
6671
|
if (typeof entry?.command !== "string") continue;
|
|
5746
|
-
const set = (0,
|
|
6672
|
+
const set = (0, import_tool_kit11.hookSetOfCommand)(entry.command);
|
|
5747
6673
|
sets.set(event, Math.min(set, sets.get(event) ?? set));
|
|
5748
6674
|
}
|
|
5749
6675
|
}
|
|
@@ -5754,11 +6680,26 @@ function countRegistered(settingsFile, binary) {
|
|
|
5754
6680
|
const settings = readSettingsFile(settingsFile);
|
|
5755
6681
|
return { settings, registered: HOOK_EVENTS.filter((event) => (settings.hooks?.[event] ?? []).some(isOurs)).length };
|
|
5756
6682
|
}
|
|
6683
|
+
function registrationSummary(projectDir) {
|
|
6684
|
+
const binary = hookBinPath();
|
|
6685
|
+
const files = /* @__PURE__ */ new Map([
|
|
6686
|
+
[settingsPath({ scope: "user", projectDir }), "user"],
|
|
6687
|
+
[settingsPath({ scope: "project", projectDir }), "project"],
|
|
6688
|
+
[path3.join(os3.homedir(), ".claude", "settings.local.json"), "project"]
|
|
6689
|
+
]);
|
|
6690
|
+
const found = [];
|
|
6691
|
+
for (const [file, scope] of files) {
|
|
6692
|
+
const { registered } = countRegistered(file, binary);
|
|
6693
|
+
if (registered === 0) continue;
|
|
6694
|
+
found.push({ file, scope, registered, homeProject: path3.resolve(file) === path3.resolve(os3.homedir(), ".claude", "settings.local.json") });
|
|
6695
|
+
}
|
|
6696
|
+
return found;
|
|
6697
|
+
}
|
|
5757
6698
|
async function printStatus(options) {
|
|
5758
6699
|
const credentials = readCredentials();
|
|
5759
6700
|
const settingsFile = settingsPath(options);
|
|
5760
6701
|
const binary = hookBinPath();
|
|
5761
|
-
const tokenFile = credentials?.toolInstallationId ? (0,
|
|
6702
|
+
const tokenFile = credentials?.toolInstallationId ? (0, import_tool_kit11.defaultTokenFilePath)(credentials.toolInstallationId) : void 0;
|
|
5762
6703
|
const unpaired = localOnlyInstall(credentials);
|
|
5763
6704
|
const here = countRegistered(settingsFile, binary);
|
|
5764
6705
|
const settings = here.settings;
|
|
@@ -5767,15 +6708,21 @@ async function printStatus(options) {
|
|
|
5767
6708
|
const otherFile = settingsPath(otherScope);
|
|
5768
6709
|
const elsewhere = registered === 0 && otherFile !== settingsFile ? countRegistered(otherFile, binary) : void 0;
|
|
5769
6710
|
const stale = findStaleHookCommands(settings, binary);
|
|
5770
|
-
console.log(`version ${(0,
|
|
6711
|
+
console.log(`version ${(0, import_tool_kit11.describeCollectorVersion)()}`);
|
|
5771
6712
|
console.log(`api base url ${credentials?.apiBaseUrl ?? "\u2014 not configured"}`);
|
|
5772
6713
|
console.log(`pairing ${describePairing(credentials, unpaired)}`);
|
|
5773
|
-
const fileToken = Boolean(tokenFile && (0,
|
|
6714
|
+
const fileToken = Boolean(tokenFile && (0, import_tool_kit11.readTokenFile)(tokenFile));
|
|
5774
6715
|
const token = fileToken || Boolean(envOverride("ASCENDA_EVENT_WRITE_TOKEN"));
|
|
5775
6716
|
console.log(`token ${fileToken ? "present" : token ? "from ASCENDA_EVENT_WRITE_TOKEN (no file)" : unpaired ? "\u2014 none until this install is paired" : "\u2014 missing"}`);
|
|
5776
6717
|
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"}`);
|
|
5777
6718
|
console.log("local features active \u2014 the session prompts and the live socket signal need no pairing");
|
|
5778
6719
|
console.log(`hook binary ${fs3.existsSync(binary) ? binary : "\u2014 not installed"}`);
|
|
6720
|
+
const node = process.platform === "win32" ? void 0 : resolveHookNode();
|
|
6721
|
+
if (node) {
|
|
6722
|
+
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"})`);
|
|
6723
|
+
}
|
|
6724
|
+
const last = readLastHook();
|
|
6725
|
+
console.log(last ? `last hook ${last.event}, ${(0, import_tool_kit9.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");
|
|
5779
6726
|
console.log(`hooks ${registered}/${HOOK_EVENTS.length} registered in ${settingsFile}`);
|
|
5780
6727
|
if (elsewhere && elsewhere.registered > 0) {
|
|
5781
6728
|
console.log(` ${elsewhere.registered}/${HOOK_EVENTS.length} found in ${otherFile} (--scope ${otherScope.scope})`);
|
|
@@ -5790,22 +6737,22 @@ async function printStatus(options) {
|
|
|
5790
6737
|
for (const command of stale) console.log(` ${command}`);
|
|
5791
6738
|
console.log(` Remove them from ${settingsFile} by hand; setup cannot tell them from a hook you wrote.`);
|
|
5792
6739
|
}
|
|
5793
|
-
const tokenValue = unpaired ? void 0 : (tokenFile ? (0,
|
|
6740
|
+
const tokenValue = unpaired ? void 0 : (tokenFile ? (0, import_tool_kit11.readTokenFile)(tokenFile) : void 0) ?? envOverride("ASCENDA_EVENT_WRITE_TOKEN") ?? void 0;
|
|
5794
6741
|
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? credentials?.apiBaseUrl ?? DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
5795
6742
|
const [initiativeLines, notices] = await Promise.all([
|
|
5796
|
-
(0,
|
|
5797
|
-
(0,
|
|
6743
|
+
(0, import_tool_kit11.initiativesStatusLines)({ apiBaseUrl, eventWriteToken: tokenValue, pairCommand: `${selfCommand()} pair` }),
|
|
6744
|
+
(0, import_tool_kit11.studyNoticeStatus)({ apiBaseUrl, eventWriteToken: tokenValue, commandPrefix: "npx @ascenda-one/claude-code-hooks" })
|
|
5798
6745
|
]);
|
|
5799
6746
|
console.log("");
|
|
5800
6747
|
for (const line of initiativeLines) console.log(line);
|
|
5801
6748
|
for (const line of notices.lines) console.log(line);
|
|
5802
6749
|
if (process.stdout.isTTY) await notices.markShown();
|
|
5803
6750
|
if (unpaired) {
|
|
5804
|
-
console.log("\
|
|
5805
|
-
console.log(
|
|
6751
|
+
console.log("\nNot paired, which the screen saver and the live view don't need.");
|
|
6752
|
+
console.log(`To send your sessions to Ascenda's servers, so they appear in the app: ${selfCommand()} pair`);
|
|
5806
6753
|
}
|
|
5807
6754
|
const wired = registered === HOOK_EVENTS.length || options.scope === "project" && elsewhere?.registered === HOOK_EVENTS.length;
|
|
5808
|
-
const healthy = credentials?.toolInstallationId && wired && fs3.existsSync(binary) && !stale.length;
|
|
6755
|
+
const healthy = credentials?.toolInstallationId && wired && fs3.existsSync(binary) && !stale.length && !node?.problem;
|
|
5809
6756
|
return healthy ? 0 : 1;
|
|
5810
6757
|
}
|
|
5811
6758
|
function describePairing(credentials, unpaired) {
|
|
@@ -5818,44 +6765,33 @@ function uninstall(options) {
|
|
|
5818
6765
|
const unpaired = localOnlyInstall();
|
|
5819
6766
|
const settingsFile = settingsPath(options);
|
|
5820
6767
|
if (fs3.existsSync(settingsFile)) {
|
|
5821
|
-
|
|
5822
|
-
const settings = JSON.parse(fs3.readFileSync(settingsFile, "utf8"));
|
|
5823
|
-
const hooks = { ...settings.hooks ?? {} };
|
|
5824
|
-
for (const event of Object.keys(hooks)) {
|
|
5825
|
-
const kept = hooks[event].filter((group) => !isOurs(group));
|
|
5826
|
-
if (kept.length) hooks[event] = kept;
|
|
5827
|
-
else delete hooks[event];
|
|
5828
|
-
}
|
|
5829
|
-
const updated = { ...settings, hooks };
|
|
5830
|
-
if (!Object.keys(hooks).length) delete updated.hooks;
|
|
5831
|
-
fs3.copyFileSync(settingsFile, `${settingsFile}.ascenda-backup`);
|
|
5832
|
-
fs3.writeFileSync(settingsFile, `${JSON.stringify(updated, null, 2)}
|
|
5833
|
-
`, "utf8");
|
|
5834
|
-
console.log(`hooks removed from ${settingsFile}`);
|
|
5835
|
-
} catch {
|
|
6768
|
+
if (!removeOurHooks(settingsFile)) {
|
|
5836
6769
|
console.error(`could not parse ${settingsFile} \u2014 remove the ascenda hook entries by hand`);
|
|
5837
6770
|
return 1;
|
|
5838
6771
|
}
|
|
6772
|
+
console.log(`hooks removed from ${settingsFile}`);
|
|
5839
6773
|
}
|
|
5840
|
-
const
|
|
5841
|
-
|
|
5842
|
-
fs3.rmSync(
|
|
5843
|
-
console.log(`removed ${
|
|
6774
|
+
for (const file of [hookBinPath(), hookBundlePath(), hookNodeRecordPath(), hookNoNodePath()]) {
|
|
6775
|
+
if (!fs3.existsSync(file)) continue;
|
|
6776
|
+
fs3.rmSync(file);
|
|
6777
|
+
if (file === hookBinPath() || file === hookBundlePath()) console.log(`removed ${file}`);
|
|
5844
6778
|
}
|
|
5845
6779
|
const credentialsFile2 = (0, import_tool_kit6.credentialsFilePath)();
|
|
5846
6780
|
if (fs3.existsSync(credentialsFile2)) {
|
|
5847
6781
|
removeCredentials();
|
|
5848
6782
|
console.log(fs3.existsSync(credentialsFile2) ? `cleared the Claude Code pairing from ${credentialsFile2} (other tools' pairings kept)` : `removed ${credentialsFile2}`);
|
|
5849
6783
|
}
|
|
5850
|
-
console.log(unpaired ? "this install was never paired, so there is no token here and nothing to revoke" : `tokens left in ${path3.join((0,
|
|
6784
|
+
console.log(unpaired ? "this install was never paired, so there is no token here and nothing to revoke" : `tokens left in ${path3.join((0, import_tool_kit11.ascendaHome)(), "tokens")} \u2014 revoke in the Ascenda app to invalidate them`);
|
|
5851
6785
|
return 0;
|
|
5852
6786
|
}
|
|
5853
|
-
var
|
|
6787
|
+
var import_tool_kit11, HOOK_EVENTS, HOOK_SET, HOOK_TIMEOUT_SECONDS, HOOK_MARKER, SENDS, USAGE, POLL_ERROR_TOLERANCE, REGISTERED_EVENT_COUNT;
|
|
5854
6788
|
var init_setup = __esm({
|
|
5855
6789
|
"src/setup.ts"() {
|
|
5856
6790
|
"use strict";
|
|
5857
|
-
|
|
6791
|
+
import_tool_kit11 = __toESM(require_out2(), 1);
|
|
5858
6792
|
init_config();
|
|
6793
|
+
init_hookHealth();
|
|
6794
|
+
init_launcher();
|
|
5859
6795
|
init_paths();
|
|
5860
6796
|
init_types();
|
|
5861
6797
|
HOOK_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PostToolUseFailure", "PreCompact", "PostCompact", "Stop", "StopFailure", "Notification", "SessionEnd", "SubagentStart", "SubagentStop"];
|
|
@@ -5884,17 +6820,19 @@ Options
|
|
|
5884
6820
|
--token <eventWriteToken> reuse an existing token (stored 0600, never printed)
|
|
5885
6821
|
--no-pair install without pairing: local features on, nothing sent
|
|
5886
6822
|
(--no-pairing is accepted too)
|
|
5887
|
-
--scope project
|
|
6823
|
+
--scope user|project where hooks are registered (default user: every project)
|
|
5888
6824
|
--project-dir <path> project root for --scope project (default cwd)
|
|
5889
6825
|
--dry-run print what would change, write nothing
|
|
5890
6826
|
-h, --help
|
|
5891
6827
|
`;
|
|
5892
6828
|
POLL_ERROR_TOLERANCE = 3;
|
|
6829
|
+
REGISTERED_EVENT_COUNT = HOOK_EVENTS.length;
|
|
5893
6830
|
}
|
|
5894
6831
|
});
|
|
5895
6832
|
|
|
5896
6833
|
// src/cli.ts
|
|
5897
|
-
var
|
|
6834
|
+
var import_tool_kit14 = __toESM(require_out2(), 1);
|
|
6835
|
+
var import_tool_kit15 = __toESM(require_out2(), 1);
|
|
5898
6836
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
5899
6837
|
import * as fs4 from "node:fs";
|
|
5900
6838
|
|
|
@@ -6267,6 +7205,8 @@ function liveEventFor(hookName, input) {
|
|
|
6267
7205
|
return "stop";
|
|
6268
7206
|
case "StopFailure":
|
|
6269
7207
|
return "halted";
|
|
7208
|
+
case "SessionEnd":
|
|
7209
|
+
return "halted";
|
|
6270
7210
|
case "Notification":
|
|
6271
7211
|
return notificationLiveEvent(input);
|
|
6272
7212
|
default:
|
|
@@ -6426,6 +7366,32 @@ function readSetting(file, key) {
|
|
|
6426
7366
|
init_config();
|
|
6427
7367
|
init_paths();
|
|
6428
7368
|
init_types();
|
|
7369
|
+
init_hookHealth();
|
|
7370
|
+
|
|
7371
|
+
// src/liveDoctor.ts
|
|
7372
|
+
var import_tool_kit12 = __toESM(require_out2(), 1);
|
|
7373
|
+
init_paths();
|
|
7374
|
+
var import_tool_kit13 = __toESM(require_out2(), 1);
|
|
7375
|
+
import * as os4 from "os";
|
|
7376
|
+
async function localSignalLines(projectDir = process.cwd()) {
|
|
7377
|
+
const { registrationSummary: registrationSummary2, REGISTERED_EVENT_COUNT: REGISTERED_EVENT_COUNT2 } = await Promise.resolve().then(() => (init_setup(), setup_exports));
|
|
7378
|
+
return (0, import_tool_kit12.liveSignalDoctorLines)({
|
|
7379
|
+
displayName: "Claude Code",
|
|
7380
|
+
tool: "claude_code",
|
|
7381
|
+
launcher: process.platform === "win32" ? void 0 : hookBinPath(),
|
|
7382
|
+
registrations: registrationSummary2(projectDir).map((entry) => ({ ...entry, file: tidy(entry.file) })),
|
|
7383
|
+
eventCount: REGISTERED_EVENT_COUNT2,
|
|
7384
|
+
selfCommand: selfCommand(),
|
|
7385
|
+
setupCommand: "npx @ascenda-one/claude-code-hooks setup",
|
|
7386
|
+
lookHint: "type /hooks"
|
|
7387
|
+
});
|
|
7388
|
+
}
|
|
7389
|
+
function tidy(file) {
|
|
7390
|
+
const home = os4.homedir();
|
|
7391
|
+
return file.startsWith(`${home}/`) ? `~${file.slice(home.length)}` : file;
|
|
7392
|
+
}
|
|
7393
|
+
|
|
7394
|
+
// src/cli.ts
|
|
6429
7395
|
var INTENTION_INVITE = "Ascenda tip: if it's natural, you can ask what would make this session count before diving in \u2014 one line is enough. Not a required step, and skip it entirely if the user is already mid-task.";
|
|
6430
7396
|
var MILESTONE_DEBRIEF_INVITE = "Ascenda tip: that finished a piece of work. If the moment suits, it's worth a short debrief \u2014 what moved, what's still unresolved, and what you'd do differently next time. One or two lines. Skip it if they're already onto the next thing.";
|
|
6431
7397
|
async function runPair() {
|
|
@@ -6441,10 +7407,10 @@ async function runPair() {
|
|
|
6441
7407
|
const { SENDS: SENDS2 } = isClaudeCode ? await Promise.resolve().then(() => (init_setup(), setup_exports)) : { SENDS: [] };
|
|
6442
7408
|
await writeStdout(
|
|
6443
7409
|
`
|
|
6444
|
-
${(0,
|
|
7410
|
+
${(0, import_tool_kit14.renderSetupDisclosure)({ sends: SENDS2, displayName: isClaudeCode ? "Claude Code" : toolType })}
|
|
6445
7411
|
`
|
|
6446
7412
|
);
|
|
6447
|
-
const session = await (0,
|
|
7413
|
+
const session = await (0, import_tool_kit14.createPairingSession)(apiBaseUrl, toolInstallationId, toolType, toolType === ASCENDA_TOOL_TYPE ? "Claude Code" : toolType);
|
|
6448
7414
|
const code = session.deviceCode ?? session.code;
|
|
6449
7415
|
await writeStdout(
|
|
6450
7416
|
`
|
|
@@ -6458,7 +7424,7 @@ Waiting for confirmation (expires ${session.expiresAt})...
|
|
|
6458
7424
|
const deadline = Date.now() + 11 * 60 * 1e3;
|
|
6459
7425
|
while (Date.now() < deadline) {
|
|
6460
7426
|
await new Promise((resolve2) => setTimeout(resolve2, 3e3));
|
|
6461
|
-
const status = await (0,
|
|
7427
|
+
const status = await (0, import_tool_kit14.getPairingStatus)(apiBaseUrl, session.pairingSessionId);
|
|
6462
7428
|
if (status.status === "pending") continue;
|
|
6463
7429
|
if (status.status !== "paired") {
|
|
6464
7430
|
process.stderr.write(`Pairing ${status.status}. Run the command again for a fresh code.
|
|
@@ -6474,8 +7440,8 @@ Waiting for confirmation (expires ${session.expiresAt})...
|
|
|
6474
7440
|
process.exitCode = 1;
|
|
6475
7441
|
return;
|
|
6476
7442
|
}
|
|
6477
|
-
const tokenFilePath = (0,
|
|
6478
|
-
(0,
|
|
7443
|
+
const tokenFilePath = (0, import_tool_kit14.defaultTokenFilePath)(pairedId);
|
|
7444
|
+
(0, import_tool_kit14.persistEventWriteToken)(tokenFilePath, status.eventWriteToken);
|
|
6479
7445
|
writeCredentials({ apiBaseUrl, toolInstallationId: pairedId, pairedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
6480
7446
|
await writeStdout(
|
|
6481
7447
|
`Paired. Write token saved to ${tokenFilePath}
|
|
@@ -6505,7 +7471,7 @@ async function runJoin(argv) {
|
|
|
6505
7471
|
`);
|
|
6506
7472
|
return 1;
|
|
6507
7473
|
}
|
|
6508
|
-
return (0,
|
|
7474
|
+
return (0, import_tool_kit14.runStudyJoin)({ apiBaseUrl, eventWriteToken, displayName: "Claude Code", joinCode });
|
|
6509
7475
|
}
|
|
6510
7476
|
async function runObject(argv) {
|
|
6511
7477
|
let apiBaseUrl;
|
|
@@ -6517,7 +7483,7 @@ async function runObject(argv) {
|
|
|
6517
7483
|
`);
|
|
6518
7484
|
return 1;
|
|
6519
7485
|
}
|
|
6520
|
-
return (0,
|
|
7486
|
+
return (0, import_tool_kit14.runStudyObjection)({
|
|
6521
7487
|
apiBaseUrl,
|
|
6522
7488
|
eventWriteToken,
|
|
6523
7489
|
commandPrefix: "npx @ascenda-one/claude-code-hooks",
|
|
@@ -6560,6 +7526,7 @@ async function main() {
|
|
|
6560
7526
|
);
|
|
6561
7527
|
}
|
|
6562
7528
|
const hookName = command;
|
|
7529
|
+
stampLastHook(hookName);
|
|
6563
7530
|
const input = await readJsonFromStdin();
|
|
6564
7531
|
const contextParts = [];
|
|
6565
7532
|
if (hookName === "SessionStart" && isNewSessionStart(input) && process.env.ASCENDA_DISABLE_INTENTION_INVITE !== "true") {
|
|
@@ -6574,15 +7541,15 @@ async function main() {
|
|
|
6574
7541
|
await writeStdout(JSON.stringify({
|
|
6575
7542
|
hookSpecificOutput: { hookEventName: hookName, additionalContext: contextParts.join("\n\n") }
|
|
6576
7543
|
}));
|
|
6577
|
-
if (pending) (0,
|
|
7544
|
+
if (pending) (0, import_tool_kit14.markFailureNotified)(pending.stateFilePath, pending.state);
|
|
6578
7545
|
}
|
|
6579
7546
|
await emitLive(hookName, input);
|
|
6580
7547
|
const mappedEvents = mapClaudeEvent(hookName, input);
|
|
6581
7548
|
if (!mappedEvents.length) return;
|
|
6582
|
-
const workContext = (0,
|
|
7549
|
+
const workContext = (0, import_tool_kit14.deriveWorkContext)((0, import_tool_kit14.getString)(input, ["cwd"]) ?? process.cwd());
|
|
6583
7550
|
if (workContext) {
|
|
6584
|
-
(0,
|
|
6585
|
-
(0,
|
|
7551
|
+
(0, import_tool_kit14.recordWorkContext)(workContext);
|
|
7552
|
+
(0, import_tool_kit14.recordForgeProjectAlias)(workContext);
|
|
6586
7553
|
}
|
|
6587
7554
|
let config;
|
|
6588
7555
|
try {
|
|
@@ -6590,19 +7557,19 @@ async function main() {
|
|
|
6590
7557
|
} catch (error) {
|
|
6591
7558
|
const unpaired = localOnlyInstall();
|
|
6592
7559
|
if (!unpaired && error instanceof MissingInstallationIdError) journalSkippedSend(error);
|
|
6593
|
-
const logFile = (0,
|
|
7560
|
+
const logFile = (0, import_tool_kit14.resolveEventLogPath)();
|
|
6594
7561
|
if (!logFile) {
|
|
6595
7562
|
if (unpaired) return;
|
|
6596
7563
|
throw error;
|
|
6597
7564
|
}
|
|
6598
7565
|
for (const event of mappedEvents) {
|
|
6599
|
-
logUnsent(logFile, event, workContext, (0,
|
|
7566
|
+
logUnsent(logFile, event, workContext, (0, import_tool_kit14.getString)(input, ["session_id", "sessionId"]) ?? null);
|
|
6600
7567
|
}
|
|
6601
7568
|
return;
|
|
6602
7569
|
}
|
|
6603
7570
|
config.workspaceHash ??= workContext?.workspaceHash ?? null;
|
|
6604
7571
|
config.projectHash ??= workContext?.projectHash ?? null;
|
|
6605
|
-
config.sessionId ??= (0,
|
|
7572
|
+
config.sessionId ??= (0, import_tool_kit14.getString)(input, ["session_id", "sessionId"]) ?? null;
|
|
6606
7573
|
const client = new AscendaClient(config);
|
|
6607
7574
|
if (hookName === "SessionEnd") {
|
|
6608
7575
|
for (const event of mappedEvents) {
|
|
@@ -6618,7 +7585,7 @@ async function main() {
|
|
|
6618
7585
|
}
|
|
6619
7586
|
}
|
|
6620
7587
|
function journalSkippedSend(error) {
|
|
6621
|
-
(0,
|
|
7588
|
+
(0, import_tool_kit14.recordSendOutcome)(resolveStateFilePath(), (0, import_tool_kit14.unresolvedToolInstallationId)(ASCENDA_TOOL_TYPE), "skipped_no_installation_id", {
|
|
6622
7589
|
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(", ")})`
|
|
6623
7590
|
});
|
|
6624
7591
|
}
|
|
@@ -6637,25 +7604,25 @@ async function emitLive(hookName, input) {
|
|
|
6637
7604
|
}
|
|
6638
7605
|
if (!event) return;
|
|
6639
7606
|
try {
|
|
6640
|
-
const prompt = event === "prompt_submitted" ? (0,
|
|
6641
|
-
const promptSource = event === "prompt_submitted" ? (0,
|
|
7607
|
+
const prompt = event === "prompt_submitted" ? (0, import_tool_kit14.getString)(input, ["prompt", "userPrompt", "message"]) ?? (0, import_tool_kit14.getNestedString)(input, [["payload", "prompt"], ["payload", "message"]]) : void 0;
|
|
7608
|
+
const promptSource = event === "prompt_submitted" ? (0, import_tool_kit14.getString)(input, ["promptSource", "prompt_source"]) : void 0;
|
|
6642
7609
|
const queued = promptSource === void 0 ? void 0 : promptSource === "queued";
|
|
6643
7610
|
const backgroundTasks = event === "stop" ? countBackgroundTasks(input) : void 0;
|
|
6644
|
-
const errorKind = hookName === "StopFailure" && event === "halted" ? (0,
|
|
7611
|
+
const errorKind = hookName === "StopFailure" && event === "halted" ? (0, import_tool_kit14.getString)(input, ["error"]) === "rate_limit" ? "rate_limit" : "error" : void 0;
|
|
6645
7612
|
const resumesAt = errorKind === "rate_limit" ? usageLimitResumesAt(input) : void 0;
|
|
6646
|
-
const agent = (0,
|
|
6647
|
-
const hookSet = (0,
|
|
6648
|
-
const viaPlugin = (0,
|
|
6649
|
-
await (0,
|
|
7613
|
+
const agent = (0, import_tool_kit14.findAgentProcess)(import_tool_kit14.AGENT_PROCESS.claude_code);
|
|
7614
|
+
const hookSet = (0, import_tool_kit14.readHookSet)(process.argv);
|
|
7615
|
+
const viaPlugin = (0, import_tool_kit14.readViaPlugin)(process.env);
|
|
7616
|
+
await (0, import_tool_kit14.emitLiveSignal)({
|
|
6650
7617
|
tool: process.env.ASCENDA_TOOL_TYPE ?? "claude_code",
|
|
6651
7618
|
// Concurrent sessions must count as separate streams for the X gauge.
|
|
6652
7619
|
// Without a session id every window collapses into one, so fall back to
|
|
6653
7620
|
// this process's parent — still per-session in practice, since Claude
|
|
6654
7621
|
// Code spawns hooks from the session process.
|
|
6655
|
-
session: (0,
|
|
6656
|
-
...(0,
|
|
7622
|
+
session: (0, import_tool_kit14.getString)(input, ["session_id", "sessionId"]) ?? process.env.ASCENDA_SESSION_ID ?? `ppid-${process.ppid}`,
|
|
7623
|
+
...(0, import_tool_kit14.livePidFields)(agent),
|
|
6657
7624
|
event,
|
|
6658
|
-
...prompt !== void 0 ? { sizeBucket: (0,
|
|
7625
|
+
...prompt !== void 0 ? { sizeBucket: (0, import_tool_kit14.bucketPromptSize)(prompt) } : {},
|
|
6659
7626
|
...queued !== void 0 ? { queued } : {},
|
|
6660
7627
|
...backgroundTasks !== void 0 ? { backgroundTasks } : {},
|
|
6661
7628
|
...hookSet !== void 0 ? { hookSet } : {},
|
|
@@ -6667,13 +7634,13 @@ async function emitLive(hookName, input) {
|
|
|
6667
7634
|
}
|
|
6668
7635
|
}
|
|
6669
7636
|
function usageLimitResumesAt(input) {
|
|
6670
|
-
const projectDir = process.env.CLAUDE_PROJECT_DIR ?? (0,
|
|
7637
|
+
const projectDir = process.env.CLAUDE_PROJECT_DIR ?? (0, import_tool_kit14.getString)(input, ["cwd"]);
|
|
6671
7638
|
if (!autoContinueEnabled({ projectDir })) return void 0;
|
|
6672
7639
|
const now = /* @__PURE__ */ new Date();
|
|
6673
7640
|
const texts = [
|
|
6674
|
-
(0,
|
|
6675
|
-
(0,
|
|
6676
|
-
(0,
|
|
7641
|
+
(0, import_tool_kit14.getString)(input, ["error_details"]),
|
|
7642
|
+
(0, import_tool_kit14.getNestedString)(input, [["error_details", "message"]]),
|
|
7643
|
+
(0, import_tool_kit14.getString)(input, ["last_assistant_message"])
|
|
6677
7644
|
];
|
|
6678
7645
|
for (const text of texts) {
|
|
6679
7646
|
const at = resumesAtFor(text, now);
|
|
@@ -6700,8 +7667,8 @@ function pendingFailureNotice(hookName) {
|
|
|
6700
7667
|
return void 0;
|
|
6701
7668
|
}
|
|
6702
7669
|
const stateFilePath = resolveStateFilePath(toolInstallationId);
|
|
6703
|
-
const state = (0,
|
|
6704
|
-
if (!(0,
|
|
7670
|
+
const state = (0, import_tool_kit14.readCollectorState)(stateFilePath);
|
|
7671
|
+
if (!(0, import_tool_kit14.shouldAnnounceFailure)(state) || !state) return void 0;
|
|
6705
7672
|
const since = state.lastSuccessAt ? `since ${state.lastSuccessAt}` : "and has never succeeded on this machine";
|
|
6706
7673
|
return {
|
|
6707
7674
|
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.`,
|
|
@@ -6732,9 +7699,26 @@ function writeStdout(text) {
|
|
|
6732
7699
|
});
|
|
6733
7700
|
}
|
|
6734
7701
|
async function runDoctor() {
|
|
6735
|
-
const
|
|
6736
|
-
const
|
|
7702
|
+
const ui = (0, import_tool_kit15.terminalStyle)();
|
|
7703
|
+
const lines = [ui.bold("Ascenda doctor"), ""];
|
|
7704
|
+
try {
|
|
7705
|
+
lines.push(...await localSignalLines(process.env.CLAUDE_PROJECT_DIR ?? process.cwd()), "");
|
|
7706
|
+
} catch (error) {
|
|
7707
|
+
lines.push(` Live signal (could not be checked: ${error instanceof Error ? error.message : String(error)})`, "");
|
|
7708
|
+
}
|
|
6737
7709
|
const unpaired = localOnlyInstall();
|
|
7710
|
+
lines.push(unpaired ? ` ${ui.bold("Account sync")} ${ui.dim("(optional; this install isn't paired)")}` : ` ${ui.bold("Account sync")} ${ui.dim("(Telemetry)")}`);
|
|
7711
|
+
const telemetryStart = lines.length;
|
|
7712
|
+
const finish = async () => {
|
|
7713
|
+
if (unpaired) {
|
|
7714
|
+
const kept = lines.slice(telemetryStart).filter((line) => !isTelemetryRow(line) || /^ (Installation id|Mode) /.test(line));
|
|
7715
|
+
lines.splice(telemetryStart, lines.length - telemetryStart, ...kept);
|
|
7716
|
+
}
|
|
7717
|
+
for (let i = telemetryStart; i < lines.length; i++) lines[i] = markTelemetryLine(ui, lines[i], unpaired);
|
|
7718
|
+
await writeStdout(`${lines.join("\n")}
|
|
7719
|
+
`);
|
|
7720
|
+
};
|
|
7721
|
+
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? "https://api.ascenda.one").replace(/\/$/, "");
|
|
6738
7722
|
lines.push(` API base URL ${apiBaseUrl}`);
|
|
6739
7723
|
let resolved;
|
|
6740
7724
|
try {
|
|
@@ -6742,22 +7726,21 @@ async function runDoctor() {
|
|
|
6742
7726
|
} catch (error) {
|
|
6743
7727
|
lines.push(` Installation id (unresolved \u2014 ${error instanceof Error ? error.message : String(error)})`);
|
|
6744
7728
|
lines.push(...skippedSendLines(void 0));
|
|
6745
|
-
lines.push("", " Not paired on this machine. Run:",
|
|
6746
|
-
await
|
|
6747
|
-
`);
|
|
7729
|
+
lines.push("", " Not paired on this machine. Run:", ` ${selfCommand()} pair`);
|
|
7730
|
+
await finish();
|
|
6748
7731
|
return;
|
|
6749
7732
|
}
|
|
6750
7733
|
const { toolInstallationId } = resolved;
|
|
6751
7734
|
lines.push(` Installation id ${toolInstallationId}`);
|
|
6752
7735
|
lines.push(` Id source ${describeIdSource(resolved)}`);
|
|
6753
|
-
const tokenFilePath = process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0,
|
|
7736
|
+
const tokenFilePath = process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0, import_tool_kit14.defaultTokenFilePath)(toolInstallationId);
|
|
6754
7737
|
lines.push(` Token file ${tokenFilePath}`);
|
|
6755
7738
|
lines.push(` Token ${describeToken(tokenFilePath, unpaired)}`);
|
|
6756
7739
|
const hasToken = fs4.existsSync(tokenFilePath) || Boolean(process.env.ASCENDA_EVENT_WRITE_TOKEN);
|
|
6757
|
-
lines.push(` Mode ${unpaired ? "
|
|
7740
|
+
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"}`);
|
|
6758
7741
|
const stateFilePath = resolveStateFilePath(toolInstallationId);
|
|
6759
7742
|
lines.push(` Journal ${stateFilePath}`);
|
|
6760
|
-
const state = (0,
|
|
7743
|
+
const state = (0, import_tool_kit14.readCollectorState)(stateFilePath);
|
|
6761
7744
|
if (!state) {
|
|
6762
7745
|
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)");
|
|
6763
7746
|
} else {
|
|
@@ -6774,19 +7757,28 @@ async function runDoctor() {
|
|
|
6774
7757
|
if (unpaired) {
|
|
6775
7758
|
lines.push(
|
|
6776
7759
|
"",
|
|
6777
|
-
"
|
|
6778
|
-
"
|
|
6779
|
-
"
|
|
6780
|
-
|
|
7760
|
+
" Not paired, which is fine: the screen saver and the live view above work",
|
|
7761
|
+
" without it. Nothing leaves this machine and nothing is queued. To send your",
|
|
7762
|
+
" sessions to Ascenda's servers, so they appear in the app:",
|
|
7763
|
+
` ${ui.cyan(`${selfCommand()} pair`)}`
|
|
6781
7764
|
);
|
|
6782
|
-
await
|
|
6783
|
-
`);
|
|
7765
|
+
await finish();
|
|
6784
7766
|
return;
|
|
6785
7767
|
}
|
|
6786
7768
|
lines.push("", " Live round trip...");
|
|
6787
7769
|
lines.push(` ${await liveRoundTrip()}`);
|
|
6788
|
-
await
|
|
6789
|
-
|
|
7770
|
+
await finish();
|
|
7771
|
+
}
|
|
7772
|
+
function isTelemetryRow(line) {
|
|
7773
|
+
return line.length > 24 && line.startsWith(" ") && line[2] !== " " && line[22] === " " && line[23] === " " && line[24] !== " ";
|
|
7774
|
+
}
|
|
7775
|
+
function markTelemetryLine(ui, line, unpaired) {
|
|
7776
|
+
if (!isTelemetryRow(line)) return unpaired ? ui.dim(line) : line;
|
|
7777
|
+
const label = line.slice(2, 24).trim();
|
|
7778
|
+
const value = line.slice(24);
|
|
7779
|
+
const failed = /FAILED|missing|no token for|rejected/.test(value);
|
|
7780
|
+
const row = (0, import_tool_kit13.doctorRow)(ui, failed ? "bad" : /^(paired —|OK)/.test(value) ? "ok" : "info", label, value);
|
|
7781
|
+
return unpaired ? ui.dim(row) : row;
|
|
6790
7782
|
}
|
|
6791
7783
|
async function liveRoundTrip() {
|
|
6792
7784
|
let config;
|
|
@@ -6806,13 +7798,13 @@ function describeIdSource(resolved) {
|
|
|
6806
7798
|
case "credentials":
|
|
6807
7799
|
return "credentials file (~/.ascenda/credentials.json)";
|
|
6808
7800
|
case "disk":
|
|
6809
|
-
return `disk (token file ${(0,
|
|
7801
|
+
return `disk (token file ${(0, import_tool_kit14.defaultTokenFilePath)(resolved.toolInstallationId)})`;
|
|
6810
7802
|
}
|
|
6811
7803
|
}
|
|
6812
7804
|
function skippedSendLines(alreadyShown) {
|
|
6813
7805
|
const stateFilePath = resolveStateFilePath();
|
|
6814
7806
|
if (stateFilePath === alreadyShown) return [];
|
|
6815
|
-
const state = (0,
|
|
7807
|
+
const state = (0, import_tool_kit14.readCollectorState)(stateFilePath);
|
|
6816
7808
|
if (!state) return [];
|
|
6817
7809
|
const since = state.failingSince ? ` since ${state.failingSince}` : "";
|
|
6818
7810
|
return [
|
|
@@ -6824,17 +7816,17 @@ function skippedSendLines(alreadyShown) {
|
|
|
6824
7816
|
function outboxLines(toolInstallationId, state) {
|
|
6825
7817
|
const outboxFilePath = resolveOutboxFilePath(toolInstallationId);
|
|
6826
7818
|
const lines = [` Outbox ${outboxFilePath}`];
|
|
6827
|
-
const summary = (0,
|
|
7819
|
+
const summary = (0, import_tool_kit14.readOutboxSummary)(outboxFilePath);
|
|
6828
7820
|
if (!summary || summary.depth === 0) {
|
|
6829
7821
|
lines.push(" Outbox depth 0 (nothing waiting)");
|
|
6830
7822
|
} else {
|
|
6831
|
-
const oldest = summary.oldestQueuedAt ? ` \u2014 oldest queued ${summary.oldestQueuedAt} (${
|
|
7823
|
+
const oldest = summary.oldestQueuedAt ? ` \u2014 oldest queued ${summary.oldestQueuedAt} (${describeAge2(summary.oldestQueuedAt)} ago)` : "";
|
|
6832
7824
|
lines.push(` Outbox depth ${summary.depth} waiting${oldest}`);
|
|
6833
7825
|
}
|
|
6834
7826
|
if (summary && summary.unreadableLines > 0) {
|
|
6835
7827
|
lines.push(` Outbox unreadable ${summary.unreadableLines} line(s) did not parse \u2014 discarded and journaled on the next hook`);
|
|
6836
7828
|
}
|
|
6837
|
-
lines.push(` Outbox drain ${(0,
|
|
7829
|
+
lines.push(` Outbox drain ${(0, import_tool_kit14.outboxDrainEnabled)() ? "on (queued events are replayed, oldest first)" : "off \u2014 queued events are kept and bounded, not sent"} \u2014 ${import_tool_kit14.OUTBOX_DRAIN_ENV_VAR}`);
|
|
6838
7830
|
const discarded = state?.outboxDiscarded;
|
|
6839
7831
|
if (discarded) {
|
|
6840
7832
|
const reasons = Object.entries(discarded.lastReasons).map(([reason, count]) => `${count} ${reason}`).join(", ");
|
|
@@ -6843,7 +7835,7 @@ function outboxLines(toolInstallationId, state) {
|
|
|
6843
7835
|
}
|
|
6844
7836
|
return lines;
|
|
6845
7837
|
}
|
|
6846
|
-
function
|
|
7838
|
+
function describeAge2(isoTimestamp) {
|
|
6847
7839
|
const ms = Date.now() - Date.parse(isoTimestamp);
|
|
6848
7840
|
if (!Number.isFinite(ms) || ms < 0) return "0m";
|
|
6849
7841
|
const minutes = Math.floor(ms / 6e4);
|
|
@@ -6866,7 +7858,7 @@ function describeToken(tokenFilePath, unpaired) {
|
|
|
6866
7858
|
}
|
|
6867
7859
|
}
|
|
6868
7860
|
function logUnsent(logFile, event, workContext, sessionId) {
|
|
6869
|
-
const payload = (0,
|
|
7861
|
+
const payload = (0, import_tool_kit14.buildEventPayload)({
|
|
6870
7862
|
toolInstallationId: `${ASCENDA_TOOL_TYPE}:unpaired`,
|
|
6871
7863
|
source: "claude_code",
|
|
6872
7864
|
// The payload's session, same as a delivered row — this log exists so
|
|
@@ -6877,7 +7869,7 @@ function logUnsent(logFile, event, workContext, sessionId) {
|
|
|
6877
7869
|
workspaceHash: envOverride("ASCENDA_WORKSPACE_HASH") ?? workContext?.workspaceHash ?? null,
|
|
6878
7870
|
projectHash: envOverride("ASCENDA_PROJECT_HASH") ?? workContext?.projectHash ?? null
|
|
6879
7871
|
}, event);
|
|
6880
|
-
(0,
|
|
7872
|
+
(0, import_tool_kit14.appendEventLog)(logFile, { loggedAt: (/* @__PURE__ */ new Date()).toISOString(), delivery: "not_sent", payload });
|
|
6881
7873
|
}
|
|
6882
7874
|
async function readJsonFromStdin() {
|
|
6883
7875
|
const chunks = [];
|