codiedev 0.9.15 → 0.9.16-beta.0
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/dist/hook.js +28 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +27 -0
- package/package.json +1 -1
package/dist/hook.js
CHANGED
|
@@ -137,6 +137,28 @@ async function runStopFailure(hookInput) {
|
|
|
137
137
|
}
|
|
138
138
|
process.exit(0);
|
|
139
139
|
}
|
|
140
|
+
// SessionStart: the capture-coverage denominator. Record that a session opened
|
|
141
|
+
// so the backend can later compute captured ÷ started. Deliberately tiny — no
|
|
142
|
+
// transcript read, no git — so it never slows session startup. Best-effort +
|
|
143
|
+
// silent (SessionStart hook output is ignored by Claude Code).
|
|
144
|
+
async function runSessionStart(hookInput) {
|
|
145
|
+
const config = (0, utils_1.readConfig)();
|
|
146
|
+
if (!config)
|
|
147
|
+
process.exit(0);
|
|
148
|
+
if (hookInput.session_id) {
|
|
149
|
+
try {
|
|
150
|
+
await postJson(`${config.backendUrl}/api/cli/sessionStart`, {
|
|
151
|
+
sessionId: hookInput.session_id,
|
|
152
|
+
startedAt: Date.now(),
|
|
153
|
+
source: "claude-code",
|
|
154
|
+
}, config.token);
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
/* best-effort — never block session startup */
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
process.exit(0);
|
|
161
|
+
}
|
|
140
162
|
function postJson(url, body, bearerToken) {
|
|
141
163
|
return new Promise((resolve, reject) => {
|
|
142
164
|
const parsed = new URL(url);
|
|
@@ -268,6 +290,11 @@ async function main() {
|
|
|
268
290
|
await runStopFailure(hookInput);
|
|
269
291
|
return;
|
|
270
292
|
}
|
|
293
|
+
// SessionStart: post the capture-coverage denominator ping. Tiny + fast.
|
|
294
|
+
if (process.argv[2] === "session-start") {
|
|
295
|
+
await runSessionStart(hookInput);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
271
298
|
// Self-heal: a user who upgraded the CLI but hasn't re-run `connect` gets the
|
|
272
299
|
// discovery + auto-backup + limit hooks wired on their next SessionEnd, without
|
|
273
300
|
// re-connecting. Cheap (settings.json read, writes only when missing), so it
|
|
@@ -275,6 +302,7 @@ async function main() {
|
|
|
275
302
|
(0, utils_1.ensureDiscoveryHookInstalled)();
|
|
276
303
|
(0, utils_1.ensureBackupHookInstalled)();
|
|
277
304
|
(0, utils_1.ensureLimitHookInstalled)();
|
|
305
|
+
(0, utils_1.ensureSessionStartHookInstalled)();
|
|
278
306
|
const { session_id, transcript_path, cwd, workspace_roots } = hookInput;
|
|
279
307
|
const workspaceRoot = workspace_roots && workspace_roots.length > 0
|
|
280
308
|
? workspace_roots[0]
|
package/dist/utils.d.ts
CHANGED
|
@@ -78,6 +78,7 @@ export declare function installHook(): void;
|
|
|
78
78
|
export declare function ensureDiscoveryHookInstalled(): void;
|
|
79
79
|
export declare function ensureBackupHookInstalled(): void;
|
|
80
80
|
export declare function ensureLimitHookInstalled(): void;
|
|
81
|
+
export declare function ensureSessionStartHookInstalled(): void;
|
|
81
82
|
export declare function installClaudeCodeInstructions(): void;
|
|
82
83
|
export declare function installCodexInstructions(): void;
|
|
83
84
|
export declare function installCursorInstructions(): void;
|
package/dist/utils.js
CHANGED
|
@@ -60,6 +60,7 @@ exports.installHook = installHook;
|
|
|
60
60
|
exports.ensureDiscoveryHookInstalled = ensureDiscoveryHookInstalled;
|
|
61
61
|
exports.ensureBackupHookInstalled = ensureBackupHookInstalled;
|
|
62
62
|
exports.ensureLimitHookInstalled = ensureLimitHookInstalled;
|
|
63
|
+
exports.ensureSessionStartHookInstalled = ensureSessionStartHookInstalled;
|
|
63
64
|
exports.installClaudeCodeInstructions = installClaudeCodeInstructions;
|
|
64
65
|
exports.installCodexInstructions = installCodexInstructions;
|
|
65
66
|
exports.installCursorInstructions = installCursorInstructions;
|
|
@@ -801,6 +802,9 @@ function installHook() {
|
|
|
801
802
|
upsertCodiedevHook(hooks, "Stop", "backup");
|
|
802
803
|
// StopFailure (matcher rate_limit) → limit (post rate-limit event to the team).
|
|
803
804
|
upsertCodiedevHook(hooks, "StopFailure", "limit", "rate_limit");
|
|
805
|
+
// SessionStart → session-start (capture-coverage denominator: record that a
|
|
806
|
+
// session opened, independent of whether it later captures).
|
|
807
|
+
upsertCodiedevHook(hooks, "SessionStart", "session-start");
|
|
804
808
|
if (!fs.existsSync(CLAUDE_DIR)) {
|
|
805
809
|
fs.mkdirSync(CLAUDE_DIR, { recursive: true });
|
|
806
810
|
}
|
|
@@ -879,6 +883,29 @@ function ensureLimitHookInstalled() {
|
|
|
879
883
|
}
|
|
880
884
|
catch { /* best-effort */ }
|
|
881
885
|
}
|
|
886
|
+
// Self-heal: ensure the SessionStart → session-start hook is present without a
|
|
887
|
+
// full `connect` re-run, mirroring ensureLimitHookInstalled. Called from the
|
|
888
|
+
// capture hook so an upgraded-but-not-reconnected user starts emitting the
|
|
889
|
+
// capture-coverage denominator on their next session. Only writes when missing.
|
|
890
|
+
function ensureSessionStartHookInstalled() {
|
|
891
|
+
try {
|
|
892
|
+
if (!fs.existsSync(CLAUDE_SETTINGS_PATH))
|
|
893
|
+
return;
|
|
894
|
+
const settings = JSON.parse(fs.readFileSync(CLAUDE_SETTINGS_PATH, "utf8"));
|
|
895
|
+
const hooks = (settings.hooks ?? {});
|
|
896
|
+
const ss = (hooks.SessionStart ?? []);
|
|
897
|
+
const present = ss.some((h) => {
|
|
898
|
+
const inner = h.hooks;
|
|
899
|
+
return Array.isArray(inner) && inner.some((x) => (0, detection_1.isCodiedevHookCommand)(x.command));
|
|
900
|
+
});
|
|
901
|
+
if (present)
|
|
902
|
+
return;
|
|
903
|
+
settings.hooks = hooks;
|
|
904
|
+
upsertCodiedevHook(hooks, "SessionStart", "session-start");
|
|
905
|
+
fs.writeFileSync(CLAUDE_SETTINGS_PATH, JSON.stringify(settings, null, 2), "utf8");
|
|
906
|
+
}
|
|
907
|
+
catch { /* best-effort */ }
|
|
908
|
+
}
|
|
882
909
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
883
910
|
// MCP server installation — writes the codiedev MCP server config into each
|
|
884
911
|
// agent CLI's expected location so "npx codiedev connect" wires it up once.
|
package/package.json
CHANGED