@scotthamilton77/sidekick 0.1.2 → 0.1.3
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/bin.js +1 -1
- package/dist/daemon.js +39 -95
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -82184,7 +82184,7 @@ var require_cli = __commonJS({
|
|
|
82184
82184
|
var promises_12 = require("node:fs/promises");
|
|
82185
82185
|
var node_stream_1 = require("node:stream");
|
|
82186
82186
|
var yargs_parser_1 = __importDefault2(require_build());
|
|
82187
|
-
var VERSION = true ? "0.1.
|
|
82187
|
+
var VERSION = true ? "0.1.3" : "dev";
|
|
82188
82188
|
var SANDBOX_ERROR_MESSAGE = `Error: Daemon commands cannot run in sandbox mode.
|
|
82189
82189
|
|
|
82190
82190
|
Claude Code's sandbox blocks Unix socket operations required for daemon IPC.
|
package/dist/daemon.js
CHANGED
|
@@ -74790,7 +74790,6 @@ var require_context_metrics_service = __commonJS({
|
|
|
74790
74790
|
var fs = __importStar(require("node:fs/promises"));
|
|
74791
74791
|
var path = __importStar(require("node:path"));
|
|
74792
74792
|
var node_crypto_1 = require("node:crypto");
|
|
74793
|
-
var node_os_1 = require("node:os");
|
|
74794
74793
|
var core_1 = require_dist4();
|
|
74795
74794
|
var shared_providers_1 = require_dist3();
|
|
74796
74795
|
var types_js_1 = require_types4();
|
|
@@ -74913,9 +74912,8 @@ var require_context_metrics_service = __commonJS({
|
|
|
74913
74912
|
* Capture base metrics by running `claude -p "/context"`.
|
|
74914
74913
|
* This is an expensive operation that spawns a new Claude session.
|
|
74915
74914
|
*
|
|
74916
|
-
*
|
|
74917
|
-
*
|
|
74918
|
-
* We must read the transcript file after the CLI exits to get the /context output.
|
|
74915
|
+
* Parses /context output directly from CLI stdout, wrapping it in
|
|
74916
|
+
* <local-command-stdout> tags so the existing parser pipeline works.
|
|
74919
74917
|
*/
|
|
74920
74918
|
async captureBaseMetrics() {
|
|
74921
74919
|
const sessionId = (0, node_crypto_1.randomUUID)();
|
|
@@ -74934,7 +74932,6 @@ var require_context_metrics_service = __commonJS({
|
|
|
74934
74932
|
cwd: tempDir,
|
|
74935
74933
|
timeout: CLI_CAPTURE_TIMEOUT_MS,
|
|
74936
74934
|
maxRetries: 1,
|
|
74937
|
-
// Limited retries for capture (not critical path)
|
|
74938
74935
|
logger: this.logger,
|
|
74939
74936
|
providerId: "context-metrics"
|
|
74940
74937
|
});
|
|
@@ -74943,58 +74940,50 @@ var require_context_metrics_service = __commonJS({
|
|
|
74943
74940
|
stdoutLength: result.stdout.length,
|
|
74944
74941
|
stderrLength: result.stderr.length
|
|
74945
74942
|
});
|
|
74946
|
-
const
|
|
74947
|
-
if (!
|
|
74948
|
-
const errorMessage = "
|
|
74949
|
-
this.logger.warn(errorMessage, { sessionId
|
|
74943
|
+
const stdout = result.stdout.trim();
|
|
74944
|
+
if (!stdout) {
|
|
74945
|
+
const errorMessage = "CLI stdout was empty \u2014 /context produced no output";
|
|
74946
|
+
this.logger.warn(errorMessage, { sessionId });
|
|
74950
74947
|
await this.recordCaptureError(errorMessage);
|
|
74951
74948
|
return;
|
|
74952
74949
|
}
|
|
74953
|
-
|
|
74954
|
-
|
|
74955
|
-
|
|
74956
|
-
});
|
|
74957
|
-
if ((0, transcript_parser_js_1.isContextCommandOutput)(output)) {
|
|
74958
|
-
const parsed = (0, transcript_parser_js_1.parseContextTable)(output);
|
|
74959
|
-
if (parsed) {
|
|
74960
|
-
const metrics = {
|
|
74961
|
-
systemPromptTokens: parsed.systemPrompt,
|
|
74962
|
-
systemToolsTokens: parsed.systemTools,
|
|
74963
|
-
autocompactBufferTokens: parsed.autocompactBuffer,
|
|
74964
|
-
capturedAt: Date.now(),
|
|
74965
|
-
capturedFrom: "context_command",
|
|
74966
|
-
sessionId,
|
|
74967
|
-
// Clear error state on success
|
|
74968
|
-
lastErrorAt: null,
|
|
74969
|
-
lastErrorMessage: null
|
|
74970
|
-
};
|
|
74971
|
-
await this.writeBaseMetrics(metrics);
|
|
74972
|
-
this.logger.info("Base metrics captured successfully", {
|
|
74973
|
-
systemPromptTokens: metrics.systemPromptTokens,
|
|
74974
|
-
systemToolsTokens: metrics.systemToolsTokens,
|
|
74975
|
-
autocompactBufferTokens: metrics.autocompactBufferTokens,
|
|
74976
|
-
sessionId
|
|
74977
|
-
});
|
|
74978
|
-
return;
|
|
74979
|
-
} else {
|
|
74980
|
-
const errorMessage = "Failed to parse /context table output";
|
|
74981
|
-
this.logger.warn(errorMessage, {
|
|
74982
|
-
outputLength: output.length,
|
|
74983
|
-
outputPreview: output.slice(0, 500)
|
|
74984
|
-
});
|
|
74985
|
-
await this.recordCaptureError(errorMessage);
|
|
74986
|
-
}
|
|
74987
|
-
} else {
|
|
74988
|
-
const errorMessage = "Transcript content does not appear to be /context output";
|
|
74950
|
+
const wrappedOutput = `<local-command-stdout>${stdout}</local-command-stdout>`;
|
|
74951
|
+
if (!(0, transcript_parser_js_1.isContextCommandOutput)(wrappedOutput)) {
|
|
74952
|
+
const errorMessage = "CLI stdout does not appear to be /context output";
|
|
74989
74953
|
this.logger.warn(errorMessage, {
|
|
74990
|
-
|
|
74991
|
-
|
|
74992
|
-
hasLocalCommandTag: output.includes("<local-command-stdout>"),
|
|
74993
|
-
hasSystemPrompt: output.includes("System prompt"),
|
|
74994
|
-
hasSystemTools: output.includes("System tools")
|
|
74954
|
+
stdoutLength: stdout.length,
|
|
74955
|
+
stdoutPreview: stdout.slice(0, 500)
|
|
74995
74956
|
});
|
|
74996
74957
|
await this.recordCaptureError(errorMessage);
|
|
74958
|
+
return;
|
|
74997
74959
|
}
|
|
74960
|
+
const parsed = (0, transcript_parser_js_1.parseContextTable)(wrappedOutput);
|
|
74961
|
+
if (!parsed) {
|
|
74962
|
+
const errorMessage = "Failed to parse /context table from CLI stdout";
|
|
74963
|
+
this.logger.warn(errorMessage, {
|
|
74964
|
+
stdoutLength: stdout.length,
|
|
74965
|
+
stdoutPreview: stdout.slice(0, 500)
|
|
74966
|
+
});
|
|
74967
|
+
await this.recordCaptureError(errorMessage);
|
|
74968
|
+
return;
|
|
74969
|
+
}
|
|
74970
|
+
const metrics = {
|
|
74971
|
+
systemPromptTokens: parsed.systemPrompt,
|
|
74972
|
+
systemToolsTokens: parsed.systemTools,
|
|
74973
|
+
autocompactBufferTokens: parsed.autocompactBuffer,
|
|
74974
|
+
capturedAt: Date.now(),
|
|
74975
|
+
capturedFrom: "context_command",
|
|
74976
|
+
sessionId,
|
|
74977
|
+
lastErrorAt: null,
|
|
74978
|
+
lastErrorMessage: null
|
|
74979
|
+
};
|
|
74980
|
+
await this.writeBaseMetrics(metrics);
|
|
74981
|
+
this.logger.info("Base metrics captured successfully", {
|
|
74982
|
+
systemPromptTokens: metrics.systemPromptTokens,
|
|
74983
|
+
systemToolsTokens: metrics.systemToolsTokens,
|
|
74984
|
+
autocompactBufferTokens: metrics.autocompactBufferTokens,
|
|
74985
|
+
sessionId
|
|
74986
|
+
});
|
|
74998
74987
|
} catch (err) {
|
|
74999
74988
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
75000
74989
|
this.logger.warn("CLI capture failed", {
|
|
@@ -75004,51 +74993,6 @@ var require_context_metrics_service = __commonJS({
|
|
|
75004
74993
|
await this.recordCaptureError(errorMessage);
|
|
75005
74994
|
}
|
|
75006
74995
|
}
|
|
75007
|
-
/**
|
|
75008
|
-
* Read the /context output from the transcript file.
|
|
75009
|
-
*
|
|
75010
|
-
* Claude CLI writes output to: ~/.claude/projects/{encoded-cwd}/{session-id}.jsonl
|
|
75011
|
-
* where encoded-cwd replaces / with - (e.g., /tmp/foo → -tmp-foo)
|
|
75012
|
-
*
|
|
75013
|
-
* @returns The content containing <local-command-stdout>, or null if not found
|
|
75014
|
-
*/
|
|
75015
|
-
async readContextOutputFromTranscript(cwd, sessionId) {
|
|
75016
|
-
try {
|
|
75017
|
-
const resolvedCwd = await fs.realpath(cwd);
|
|
75018
|
-
const encodedPath = resolvedCwd.replace(/\//g, "-").replace(/^-/, "-");
|
|
75019
|
-
const transcriptPath = path.join((0, node_os_1.homedir)(), ".claude", "projects", encodedPath, `${sessionId}.jsonl`);
|
|
75020
|
-
this.logger.debug("Reading transcript file", { transcriptPath });
|
|
75021
|
-
await new Promise((resolve3) => setTimeout(resolve3, 100));
|
|
75022
|
-
try {
|
|
75023
|
-
await fs.access(transcriptPath);
|
|
75024
|
-
} catch {
|
|
75025
|
-
this.logger.warn("Transcript file not found", { transcriptPath });
|
|
75026
|
-
return null;
|
|
75027
|
-
}
|
|
75028
|
-
const content = await fs.readFile(transcriptPath, "utf-8");
|
|
75029
|
-
const lines = content.trim().split("\n").filter(Boolean);
|
|
75030
|
-
for (const line of lines) {
|
|
75031
|
-
try {
|
|
75032
|
-
const entry = JSON.parse(line);
|
|
75033
|
-
const messageContent = entry.message?.content;
|
|
75034
|
-
if (typeof messageContent === "string" && messageContent.includes("<local-command-stdout>")) {
|
|
75035
|
-
return messageContent;
|
|
75036
|
-
}
|
|
75037
|
-
} catch {
|
|
75038
|
-
}
|
|
75039
|
-
}
|
|
75040
|
-
this.logger.warn("No /context output found in transcript", {
|
|
75041
|
-
transcriptPath,
|
|
75042
|
-
lineCount: lines.length
|
|
75043
|
-
});
|
|
75044
|
-
return null;
|
|
75045
|
-
} catch (err) {
|
|
75046
|
-
this.logger.warn("Failed to read transcript file", {
|
|
75047
|
-
error: err instanceof Error ? err.message : String(err)
|
|
75048
|
-
});
|
|
75049
|
-
return null;
|
|
75050
|
-
}
|
|
75051
|
-
}
|
|
75052
74996
|
// ==========================================================================
|
|
75053
74997
|
// Project Metrics - Project-level state via projectStateService
|
|
75054
74998
|
// ==========================================================================
|