@scotthamilton77/sidekick 0.0.1-alpha → 0.0.2-alpha
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 +149 -282
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -27684,134 +27684,19 @@ var require_runtime_context = __commonJS({
|
|
|
27684
27684
|
}
|
|
27685
27685
|
});
|
|
27686
27686
|
|
|
27687
|
-
// ../sidekick-core/dist/
|
|
27688
|
-
var
|
|
27689
|
-
"../sidekick-core/dist/
|
|
27687
|
+
// ../sidekick-core/dist/project-root.js
|
|
27688
|
+
var require_project_root = __commonJS({
|
|
27689
|
+
"../sidekick-core/dist/project-root.js"(exports2) {
|
|
27690
27690
|
"use strict";
|
|
27691
27691
|
var __importDefault2 = exports2 && exports2.__importDefault || function(mod) {
|
|
27692
27692
|
return mod && mod.__esModule ? mod : { "default": mod };
|
|
27693
27693
|
};
|
|
27694
27694
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
27695
|
-
exports2.
|
|
27696
|
-
var node_fs_1 = require("node:fs");
|
|
27697
|
-
var node_os_1 = require("node:os");
|
|
27695
|
+
exports2.resolveProjectRoot = resolveProjectRoot;
|
|
27698
27696
|
var node_path_1 = __importDefault2(require("node:path"));
|
|
27699
|
-
|
|
27700
|
-
|
|
27701
|
-
|
|
27702
|
-
return (0, node_fs_1.realpathSync)(hookScriptPath);
|
|
27703
|
-
} catch {
|
|
27704
|
-
return node_path_1.default.resolve(hookScriptPath);
|
|
27705
|
-
}
|
|
27706
|
-
}
|
|
27707
|
-
function deriveProjectRootFromHook(hookScriptPath) {
|
|
27708
|
-
const index = hookScriptPath.lastIndexOf(SIDEKICK_HOOK_SEGMENT);
|
|
27709
|
-
if (index === -1) {
|
|
27710
|
-
return void 0;
|
|
27711
|
-
}
|
|
27712
|
-
return hookScriptPath.slice(0, index);
|
|
27713
|
-
}
|
|
27714
|
-
function findNearestSidekickDir(startDir) {
|
|
27715
|
-
let current = node_path_1.default.resolve(startDir);
|
|
27716
|
-
while (true) {
|
|
27717
|
-
const candidate = node_path_1.default.join(current, ".claude", "hooks", "sidekick");
|
|
27718
|
-
if ((0, node_fs_1.existsSync)(candidate)) {
|
|
27719
|
-
return candidate;
|
|
27720
|
-
}
|
|
27721
|
-
const parent = node_path_1.default.dirname(current);
|
|
27722
|
-
if (parent === current) {
|
|
27723
|
-
return void 0;
|
|
27724
|
-
}
|
|
27725
|
-
current = parent;
|
|
27726
|
-
}
|
|
27727
|
-
}
|
|
27728
|
-
function projectHasSidekickInstall(projectDir) {
|
|
27729
|
-
const targets = [
|
|
27730
|
-
node_path_1.default.join(projectDir, ".claude", "settings.json"),
|
|
27731
|
-
node_path_1.default.join(projectDir, ".claude", "settings.json.local")
|
|
27732
|
-
];
|
|
27733
|
-
return targets.some((filePath) => {
|
|
27734
|
-
if (!(0, node_fs_1.existsSync)(filePath)) {
|
|
27735
|
-
return false;
|
|
27736
|
-
}
|
|
27737
|
-
try {
|
|
27738
|
-
const contents = (0, node_fs_1.readFileSync)(filePath, "utf8");
|
|
27739
|
-
return contents.toLowerCase().includes("sidekick");
|
|
27740
|
-
} catch {
|
|
27741
|
-
return false;
|
|
27742
|
-
}
|
|
27743
|
-
});
|
|
27744
|
-
}
|
|
27745
|
-
function normalizeDir(dir) {
|
|
27746
|
-
try {
|
|
27747
|
-
return (0, node_fs_1.realpathSync)(node_path_1.default.resolve(dir));
|
|
27748
|
-
} catch {
|
|
27749
|
-
return node_path_1.default.resolve(dir);
|
|
27750
|
-
}
|
|
27751
|
-
}
|
|
27752
|
-
function resolveScope(input) {
|
|
27753
|
-
const warnings = [];
|
|
27754
|
-
const cwd = input.cwd ? node_path_1.default.resolve(input.cwd) : process.cwd();
|
|
27755
|
-
const hookScriptPath = input.hookScriptPath ? normalizeHookPath(input.hookScriptPath) : void 0;
|
|
27756
|
-
const providedProjectDir = input.projectDir ? node_path_1.default.resolve(input.projectDir) : void 0;
|
|
27757
|
-
const resolvedHomeDir = input.homeDir ? normalizeDir(input.homeDir) : normalizeDir((0, node_os_1.homedir)());
|
|
27758
|
-
if (input.scopeOverride) {
|
|
27759
|
-
return {
|
|
27760
|
-
scope: input.scopeOverride,
|
|
27761
|
-
source: "override",
|
|
27762
|
-
hookScriptPath,
|
|
27763
|
-
projectRoot: input.scopeOverride === "project" ? providedProjectDir : void 0,
|
|
27764
|
-
warnings,
|
|
27765
|
-
dualInstallDetected: false
|
|
27766
|
-
};
|
|
27767
|
-
}
|
|
27768
|
-
if (hookScriptPath) {
|
|
27769
|
-
if (hookScriptPath.startsWith(node_path_1.default.join(resolvedHomeDir, ".claude", "hooks", "sidekick"))) {
|
|
27770
|
-
const dualInstallDetected2 = Boolean(providedProjectDir && projectHasSidekickInstall(providedProjectDir));
|
|
27771
|
-
return {
|
|
27772
|
-
scope: "user",
|
|
27773
|
-
source: "hook-script-path",
|
|
27774
|
-
hookScriptPath,
|
|
27775
|
-
projectRoot: void 0,
|
|
27776
|
-
warnings,
|
|
27777
|
-
dualInstallDetected: dualInstallDetected2
|
|
27778
|
-
};
|
|
27779
|
-
}
|
|
27780
|
-
const projectRoot = deriveProjectRootFromHook(hookScriptPath);
|
|
27781
|
-
if (projectRoot) {
|
|
27782
|
-
if (providedProjectDir && node_path_1.default.resolve(projectRoot) !== providedProjectDir) {
|
|
27783
|
-
warnings.push("Project directory hint from --project-dir does not match path derived from --hook-script-path. Using hook-script-path.");
|
|
27784
|
-
}
|
|
27785
|
-
return {
|
|
27786
|
-
scope: "project",
|
|
27787
|
-
source: "hook-script-path",
|
|
27788
|
-
hookScriptPath,
|
|
27789
|
-
projectRoot,
|
|
27790
|
-
warnings,
|
|
27791
|
-
dualInstallDetected: false
|
|
27792
|
-
};
|
|
27793
|
-
}
|
|
27794
|
-
}
|
|
27795
|
-
const sidekickDir = findNearestSidekickDir(cwd);
|
|
27796
|
-
if (sidekickDir && !sidekickDir.startsWith(node_path_1.default.join(resolvedHomeDir, ".claude", "hooks", "sidekick"))) {
|
|
27797
|
-
return {
|
|
27798
|
-
scope: "project",
|
|
27799
|
-
source: "cwd-fallback",
|
|
27800
|
-
hookScriptPath,
|
|
27801
|
-
projectRoot: node_path_1.default.resolve(sidekickDir, "..", "..", ".."),
|
|
27802
|
-
warnings,
|
|
27803
|
-
dualInstallDetected: false
|
|
27804
|
-
};
|
|
27805
|
-
}
|
|
27806
|
-
const dualInstallDetected = Boolean(providedProjectDir && projectHasSidekickInstall(providedProjectDir));
|
|
27807
|
-
return {
|
|
27808
|
-
scope: "user",
|
|
27809
|
-
source: "default",
|
|
27810
|
-
hookScriptPath,
|
|
27811
|
-
projectRoot: void 0,
|
|
27812
|
-
warnings,
|
|
27813
|
-
dualInstallDetected
|
|
27814
|
-
};
|
|
27697
|
+
function resolveProjectRoot(input) {
|
|
27698
|
+
const projectRoot = input.projectDir ? node_path_1.default.resolve(input.projectDir) : void 0;
|
|
27699
|
+
return { projectRoot };
|
|
27815
27700
|
}
|
|
27816
27701
|
}
|
|
27817
27702
|
});
|
|
@@ -32460,7 +32345,6 @@ var require_structured_logging = __commonJS({
|
|
|
32460
32345
|
source: "cli",
|
|
32461
32346
|
context: {
|
|
32462
32347
|
sessionId: context.sessionId,
|
|
32463
|
-
scope: context.scope,
|
|
32464
32348
|
correlationId: context.correlationId,
|
|
32465
32349
|
traceId: context.traceId,
|
|
32466
32350
|
hook: context.hook
|
|
@@ -32480,7 +32364,6 @@ var require_structured_logging = __commonJS({
|
|
|
32480
32364
|
source: "cli",
|
|
32481
32365
|
context: {
|
|
32482
32366
|
sessionId: context.sessionId,
|
|
32483
|
-
scope: context.scope,
|
|
32484
32367
|
correlationId: context.correlationId,
|
|
32485
32368
|
traceId: context.traceId,
|
|
32486
32369
|
hook: context.hook
|
|
@@ -32502,7 +32385,6 @@ var require_structured_logging = __commonJS({
|
|
|
32502
32385
|
source: "daemon",
|
|
32503
32386
|
context: {
|
|
32504
32387
|
sessionId: context.sessionId,
|
|
32505
|
-
scope: context.scope,
|
|
32506
32388
|
correlationId: context.correlationId,
|
|
32507
32389
|
traceId: context.traceId,
|
|
32508
32390
|
hook: context.hook,
|
|
@@ -32524,7 +32406,6 @@ var require_structured_logging = __commonJS({
|
|
|
32524
32406
|
source: "daemon",
|
|
32525
32407
|
context: {
|
|
32526
32408
|
sessionId: context.sessionId,
|
|
32527
|
-
scope: context.scope,
|
|
32528
32409
|
correlationId: context.correlationId,
|
|
32529
32410
|
traceId: context.traceId,
|
|
32530
32411
|
hook: context.hook,
|
|
@@ -32546,7 +32427,6 @@ var require_structured_logging = __commonJS({
|
|
|
32546
32427
|
source: "daemon",
|
|
32547
32428
|
context: {
|
|
32548
32429
|
sessionId: context.sessionId,
|
|
32549
|
-
scope: context.scope,
|
|
32550
32430
|
correlationId: context.correlationId,
|
|
32551
32431
|
traceId: context.traceId,
|
|
32552
32432
|
hook: context.hook,
|
|
@@ -32568,8 +32448,7 @@ var require_structured_logging = __commonJS({
|
|
|
32568
32448
|
time: Date.now(),
|
|
32569
32449
|
source: "daemon",
|
|
32570
32450
|
context: {
|
|
32571
|
-
sessionId: ""
|
|
32572
|
-
scope: "project"
|
|
32451
|
+
sessionId: ""
|
|
32573
32452
|
},
|
|
32574
32453
|
payload: {
|
|
32575
32454
|
metadata
|
|
@@ -32585,8 +32464,7 @@ var require_structured_logging = __commonJS({
|
|
|
32585
32464
|
time: Date.now(),
|
|
32586
32465
|
source: "daemon",
|
|
32587
32466
|
context: {
|
|
32588
|
-
sessionId: ""
|
|
32589
|
-
scope: "project"
|
|
32467
|
+
sessionId: ""
|
|
32590
32468
|
},
|
|
32591
32469
|
payload: {
|
|
32592
32470
|
metadata
|
|
@@ -32602,8 +32480,7 @@ var require_structured_logging = __commonJS({
|
|
|
32602
32480
|
time: Date.now(),
|
|
32603
32481
|
source: "daemon",
|
|
32604
32482
|
context: {
|
|
32605
|
-
sessionId: ""
|
|
32606
|
-
scope: "project"
|
|
32483
|
+
sessionId: ""
|
|
32607
32484
|
},
|
|
32608
32485
|
payload: {
|
|
32609
32486
|
metadata
|
|
@@ -32619,8 +32496,7 @@ var require_structured_logging = __commonJS({
|
|
|
32619
32496
|
time: Date.now(),
|
|
32620
32497
|
source: "daemon",
|
|
32621
32498
|
context: {
|
|
32622
|
-
sessionId: ""
|
|
32623
|
-
scope: "project"
|
|
32499
|
+
sessionId: ""
|
|
32624
32500
|
},
|
|
32625
32501
|
payload: {
|
|
32626
32502
|
metadata
|
|
@@ -32636,8 +32512,7 @@ var require_structured_logging = __commonJS({
|
|
|
32636
32512
|
time: Date.now(),
|
|
32637
32513
|
source: "daemon",
|
|
32638
32514
|
context: {
|
|
32639
|
-
sessionId: ""
|
|
32640
|
-
scope: "project"
|
|
32515
|
+
sessionId: ""
|
|
32641
32516
|
},
|
|
32642
32517
|
payload: {
|
|
32643
32518
|
metadata
|
|
@@ -32656,7 +32531,6 @@ var require_structured_logging = __commonJS({
|
|
|
32656
32531
|
source: "cli",
|
|
32657
32532
|
context: {
|
|
32658
32533
|
sessionId: context.sessionId,
|
|
32659
|
-
scope: context.scope,
|
|
32660
32534
|
correlationId: context.correlationId,
|
|
32661
32535
|
traceId: context.traceId,
|
|
32662
32536
|
hook: context.hook,
|
|
@@ -32679,7 +32553,6 @@ var require_structured_logging = __commonJS({
|
|
|
32679
32553
|
source: "cli",
|
|
32680
32554
|
context: {
|
|
32681
32555
|
sessionId: context.sessionId,
|
|
32682
|
-
scope: context.scope,
|
|
32683
32556
|
correlationId: context.correlationId,
|
|
32684
32557
|
traceId: context.traceId,
|
|
32685
32558
|
hook: context.hook,
|
|
@@ -32703,7 +32576,6 @@ var require_structured_logging = __commonJS({
|
|
|
32703
32576
|
source: "daemon",
|
|
32704
32577
|
context: {
|
|
32705
32578
|
sessionId: context.sessionId,
|
|
32706
|
-
scope: context.scope,
|
|
32707
32579
|
correlationId: context.correlationId,
|
|
32708
32580
|
traceId: context.traceId,
|
|
32709
32581
|
hook: context.hook,
|
|
@@ -32726,7 +32598,6 @@ var require_structured_logging = __commonJS({
|
|
|
32726
32598
|
source: "daemon",
|
|
32727
32599
|
context: {
|
|
32728
32600
|
sessionId: context.sessionId,
|
|
32729
|
-
scope: context.scope,
|
|
32730
32601
|
correlationId: context.correlationId,
|
|
32731
32602
|
traceId: context.traceId,
|
|
32732
32603
|
hook: context.hook,
|
|
@@ -32749,7 +32620,6 @@ var require_structured_logging = __commonJS({
|
|
|
32749
32620
|
source: "daemon",
|
|
32750
32621
|
context: {
|
|
32751
32622
|
sessionId: context.sessionId,
|
|
32752
|
-
scope: context.scope,
|
|
32753
32623
|
correlationId: context.correlationId,
|
|
32754
32624
|
traceId: context.traceId,
|
|
32755
32625
|
hook: context.hook,
|
|
@@ -32773,7 +32643,6 @@ var require_structured_logging = __commonJS({
|
|
|
32773
32643
|
source: "transcript",
|
|
32774
32644
|
context: {
|
|
32775
32645
|
sessionId: context.sessionId,
|
|
32776
|
-
scope: context.scope,
|
|
32777
32646
|
correlationId: context.correlationId,
|
|
32778
32647
|
traceId: context.traceId,
|
|
32779
32648
|
hook: context.hook,
|
|
@@ -32796,7 +32665,6 @@ var require_structured_logging = __commonJS({
|
|
|
32796
32665
|
source: "transcript",
|
|
32797
32666
|
context: {
|
|
32798
32667
|
sessionId: context.sessionId,
|
|
32799
|
-
scope: context.scope,
|
|
32800
32668
|
correlationId: context.correlationId,
|
|
32801
32669
|
traceId: context.traceId,
|
|
32802
32670
|
hook: context.hook,
|
|
@@ -33395,7 +33263,6 @@ var require_staging_service = __commonJS({
|
|
|
33395
33263
|
await this.options.stateService.write(reminderPath, data, types_1.StagedReminderSchema);
|
|
33396
33264
|
const event = structured_logging_1.LogEvents.reminderStaged({
|
|
33397
33265
|
sessionId,
|
|
33398
|
-
scope: this.options.scope,
|
|
33399
33266
|
hook: hookName
|
|
33400
33267
|
}, {
|
|
33401
33268
|
reminderName: data.name,
|
|
@@ -33541,10 +33408,9 @@ var require_staging_service = __commonJS({
|
|
|
33541
33408
|
};
|
|
33542
33409
|
exports2.StagingServiceCore = StagingServiceCore;
|
|
33543
33410
|
var SessionScopedStagingService = class {
|
|
33544
|
-
constructor(core, sessionId
|
|
33411
|
+
constructor(core, sessionId) {
|
|
33545
33412
|
this.core = core;
|
|
33546
33413
|
this.sessionId = sessionId;
|
|
33547
|
-
this.scope = scope;
|
|
33548
33414
|
}
|
|
33549
33415
|
// ============================================================================
|
|
33550
33416
|
// StagingService Interface Implementation (delegates to core)
|
|
@@ -33585,12 +33451,6 @@ var require_staging_service = __commonJS({
|
|
|
33585
33451
|
getSessionId() {
|
|
33586
33452
|
return this.sessionId;
|
|
33587
33453
|
}
|
|
33588
|
-
/**
|
|
33589
|
-
* Get the scope (for testing/debugging).
|
|
33590
|
-
*/
|
|
33591
|
-
getScope() {
|
|
33592
|
-
return this.scope;
|
|
33593
|
-
}
|
|
33594
33454
|
};
|
|
33595
33455
|
exports2.SessionScopedStagingService = SessionScopedStagingService;
|
|
33596
33456
|
}
|
|
@@ -33685,8 +33545,7 @@ var require_handler_registry2 = __commonJS({
|
|
|
33685
33545
|
this.handlers = [];
|
|
33686
33546
|
this.context = {
|
|
33687
33547
|
sessionId: options.sessionId,
|
|
33688
|
-
transcriptPath: options.transcriptPath
|
|
33689
|
-
scope: options.scope
|
|
33548
|
+
transcriptPath: options.transcriptPath
|
|
33690
33549
|
};
|
|
33691
33550
|
}
|
|
33692
33551
|
/**
|
|
@@ -33802,7 +33661,7 @@ var require_handler_registry2 = __commonJS({
|
|
|
33802
33661
|
const event = this.buildTranscriptEvent(eventType, entry, lineNumber, isBulkProcessing);
|
|
33803
33662
|
const metrics = this.options.getMetrics?.();
|
|
33804
33663
|
if (metrics) {
|
|
33805
|
-
(0, structured_logging_js_1.logEvent)(this.options.logger, structured_logging_js_1.LogEvents.transcriptEventEmitted({ sessionId: this.options.sessionId
|
|
33664
|
+
(0, structured_logging_js_1.logEvent)(this.options.logger, structured_logging_js_1.LogEvents.transcriptEventEmitted({ sessionId: this.options.sessionId }, {
|
|
33806
33665
|
eventType,
|
|
33807
33666
|
lineNumber,
|
|
33808
33667
|
uuid: entry.uuid,
|
|
@@ -33828,8 +33687,7 @@ var require_handler_registry2 = __commonJS({
|
|
|
33828
33687
|
async invokeTranscriptHandler(handler, event) {
|
|
33829
33688
|
const startTime = Date.now();
|
|
33830
33689
|
const logContext = {
|
|
33831
|
-
sessionId: this.options.sessionId
|
|
33832
|
-
scope: this.options.scope
|
|
33690
|
+
sessionId: this.options.sessionId
|
|
33833
33691
|
};
|
|
33834
33692
|
try {
|
|
33835
33693
|
await handler.handler(event, this.context);
|
|
@@ -33875,8 +33733,7 @@ var require_handler_registry2 = __commonJS({
|
|
|
33875
33733
|
buildTranscriptEvent(eventType, entry, lineNumber, isBulkProcessing = false) {
|
|
33876
33734
|
const context = {
|
|
33877
33735
|
sessionId: this.options.sessionId,
|
|
33878
|
-
timestamp: Date.now()
|
|
33879
|
-
scope: this.options.scope
|
|
33736
|
+
timestamp: Date.now()
|
|
33880
33737
|
};
|
|
33881
33738
|
const metrics = this.options.getMetrics?.() ?? this.createEmptyMetrics();
|
|
33882
33739
|
return {
|
|
@@ -37247,7 +37104,7 @@ var require_transcript_service = __commonJS({
|
|
|
37247
37104
|
await this.persistCompactionHistory();
|
|
37248
37105
|
if (this.sessionId) {
|
|
37249
37106
|
const lineCount = (0, node_fs_1.statSync)(snapshotPath).size > 0 ? this.metrics.lastProcessedLine : 0;
|
|
37250
|
-
(0, structured_logging_js_1.logEvent)(this.options.logger, structured_logging_js_1.LogEvents.preCompactCaptured({ sessionId: this.sessionId
|
|
37107
|
+
(0, structured_logging_js_1.logEvent)(this.options.logger, structured_logging_js_1.LogEvents.preCompactCaptured({ sessionId: this.sessionId }, { snapshotPath, lineCount }, { transcriptPath: this.transcriptPath ?? "", metrics: this.deepCloneMetrics() }));
|
|
37251
37108
|
}
|
|
37252
37109
|
this.options.logger.info("Captured pre-compact state", { sessionId: this.sessionId, snapshotPath });
|
|
37253
37110
|
}
|
|
@@ -37831,7 +37688,6 @@ var require_service_factory2 = __commonJS({
|
|
|
37831
37688
|
this.stagingCore = new staging_service_js_1.StagingServiceCore({
|
|
37832
37689
|
stateDir: options.stateDir,
|
|
37833
37690
|
logger: options.logger,
|
|
37834
|
-
scope: options.scope,
|
|
37835
37691
|
stateService: stagingStateService
|
|
37836
37692
|
});
|
|
37837
37693
|
}
|
|
@@ -37841,7 +37697,7 @@ var require_service_factory2 = __commonJS({
|
|
|
37841
37697
|
*/
|
|
37842
37698
|
getStagingService(sessionId) {
|
|
37843
37699
|
this.touchSession(sessionId);
|
|
37844
|
-
return new staging_service_js_1.SessionScopedStagingService(this.stagingCore, sessionId
|
|
37700
|
+
return new staging_service_js_1.SessionScopedStagingService(this.stagingCore, sessionId);
|
|
37845
37701
|
}
|
|
37846
37702
|
/**
|
|
37847
37703
|
* Prepare a session-scoped TranscriptService without starting event emission.
|
|
@@ -38554,7 +38410,7 @@ var require_dist3 = __commonJS({
|
|
|
38554
38410
|
return logger_1.createConsoleLogger;
|
|
38555
38411
|
} });
|
|
38556
38412
|
__exportStar(require_runtime_context(), exports2);
|
|
38557
|
-
__exportStar(
|
|
38413
|
+
__exportStar(require_project_root(), exports2);
|
|
38558
38414
|
var structured_logging_1 = require_structured_logging();
|
|
38559
38415
|
Object.defineProperty(exports2, "createLogManager", { enumerable: true, get: function() {
|
|
38560
38416
|
return structured_logging_1.createLogManager;
|
|
@@ -38726,9 +38582,9 @@ var require_runtime = __commonJS({
|
|
|
38726
38582
|
var node_crypto_1 = require("node:crypto");
|
|
38727
38583
|
var node_os_1 = require("node:os");
|
|
38728
38584
|
var node_path_1 = require("node:path");
|
|
38729
|
-
function getLogFilePath(
|
|
38730
|
-
if (
|
|
38731
|
-
return (0, node_path_1.join)(
|
|
38585
|
+
function getLogFilePath(projectRoot) {
|
|
38586
|
+
if (projectRoot) {
|
|
38587
|
+
return (0, node_path_1.join)(projectRoot, ".sidekick", "logs", "sidekick.log");
|
|
38732
38588
|
}
|
|
38733
38589
|
return (0, node_path_1.join)((0, node_os_1.homedir)(), ".sidekick", "logs", "sidekick.log");
|
|
38734
38590
|
}
|
|
@@ -38739,17 +38595,17 @@ var require_runtime = __commonJS({
|
|
|
38739
38595
|
bootstrapSink: options.stderrSink ?? process.stderr,
|
|
38740
38596
|
bufferPreUpgrade: true
|
|
38741
38597
|
});
|
|
38742
|
-
const
|
|
38598
|
+
const { projectRoot } = (0, core_1.resolveProjectRoot)(options);
|
|
38743
38599
|
const defaultAssetsDir = options.defaultAssetsDir ?? (0, core_1.getDefaultAssetsDir)();
|
|
38744
38600
|
const assets = (0, core_1.createAssetResolver)({
|
|
38745
38601
|
defaultAssetsDir,
|
|
38746
|
-
projectRoot
|
|
38602
|
+
projectRoot,
|
|
38747
38603
|
homeDir: options.homeDir
|
|
38748
38604
|
});
|
|
38749
38605
|
let config;
|
|
38750
38606
|
try {
|
|
38751
38607
|
config = (0, core_1.createConfigService)({
|
|
38752
|
-
projectRoot
|
|
38608
|
+
projectRoot,
|
|
38753
38609
|
homeDir: options.homeDir,
|
|
38754
38610
|
assets
|
|
38755
38611
|
});
|
|
@@ -38761,15 +38617,14 @@ var require_runtime = __commonJS({
|
|
|
38761
38617
|
}
|
|
38762
38618
|
const effectiveLogLevel = options.logLevel ?? config.core.logging.level;
|
|
38763
38619
|
let logContext = {
|
|
38764
|
-
scope: scope.scope,
|
|
38765
38620
|
correlationId,
|
|
38766
38621
|
command: options.command
|
|
38767
38622
|
};
|
|
38768
|
-
const logFilePath = getLogFilePath(
|
|
38623
|
+
const logFilePath = getLogFilePath(projectRoot);
|
|
38769
38624
|
const isInteractive = options.interactive ?? process.env.SIDEKICK_INTERACTIVE === "1";
|
|
38770
38625
|
const enableFileLogging = options.enableFileLogging ?? true;
|
|
38771
38626
|
const logManager = (0, core_1.createLogManager)({
|
|
38772
|
-
name:
|
|
38627
|
+
name: "sidekick:cli",
|
|
38773
38628
|
level: effectiveLogLevel,
|
|
38774
38629
|
context: logContext,
|
|
38775
38630
|
destinations: {
|
|
@@ -38782,7 +38637,7 @@ var require_runtime = __commonJS({
|
|
|
38782
38637
|
}
|
|
38783
38638
|
});
|
|
38784
38639
|
loggerFacade.upgrade({
|
|
38785
|
-
name:
|
|
38640
|
+
name: "sidekick:cli",
|
|
38786
38641
|
level: effectiveLogLevel,
|
|
38787
38642
|
context: logContext,
|
|
38788
38643
|
destinations: {
|
|
@@ -38810,28 +38665,21 @@ var require_runtime = __commonJS({
|
|
|
38810
38665
|
const telemetry = logManager.getTelemetry();
|
|
38811
38666
|
const cleanupErrorHandlers = (0, core_1.setupGlobalErrorHandlers)(logger);
|
|
38812
38667
|
logger.debug("Runtime bootstrap complete", {
|
|
38813
|
-
|
|
38814
|
-
projectRoot: scope.projectRoot ?? null,
|
|
38815
|
-
source: scope.source,
|
|
38816
|
-
warnings: scope.warnings,
|
|
38668
|
+
projectRoot: projectRoot ?? null,
|
|
38817
38669
|
logFile: enableFileLogging ? logFilePath : null
|
|
38818
38670
|
});
|
|
38819
38671
|
if (config.sources.length > 0) {
|
|
38820
38672
|
logger.debug("Configuration sources loaded", { sources: config.sources });
|
|
38821
38673
|
}
|
|
38822
38674
|
logger.debug("Asset resolver initialized", { cascadeLayers: assets.cascadeLayers });
|
|
38823
|
-
|
|
38824
|
-
logger.warn("Detected project-scope installation while running from user hooks. Deferring to project scope.");
|
|
38825
|
-
telemetry.increment("dual_install_detected", { scope: scope.scope });
|
|
38826
|
-
}
|
|
38827
|
-
const stateRoot = scope.projectRoot ?? (0, node_path_1.join)((0, node_os_1.homedir)(), ".claude");
|
|
38675
|
+
const stateRoot = projectRoot ?? (0, node_path_1.join)((0, node_os_1.homedir)(), ".claude");
|
|
38828
38676
|
const stateService = new core_1.StateService(stateRoot, { logger });
|
|
38829
38677
|
return {
|
|
38830
38678
|
get logger() {
|
|
38831
38679
|
return logger;
|
|
38832
38680
|
},
|
|
38833
38681
|
telemetry,
|
|
38834
|
-
|
|
38682
|
+
projectRoot,
|
|
38835
38683
|
config,
|
|
38836
38684
|
assets,
|
|
38837
38685
|
stateService,
|
|
@@ -38842,7 +38690,7 @@ var require_runtime = __commonJS({
|
|
|
38842
38690
|
bindSessionId: (sessionId) => {
|
|
38843
38691
|
logContext = { ...logContext, sessionId };
|
|
38844
38692
|
const newLogManager = (0, core_1.createLogManager)({
|
|
38845
|
-
name:
|
|
38693
|
+
name: "sidekick:cli",
|
|
38846
38694
|
level: effectiveLogLevel,
|
|
38847
38695
|
context: logContext,
|
|
38848
38696
|
destinations: {
|
|
@@ -47929,7 +47777,6 @@ var require_events2 = __commonJS({
|
|
|
47929
47777
|
source: "cli",
|
|
47930
47778
|
context: {
|
|
47931
47779
|
sessionId: context.sessionId,
|
|
47932
|
-
scope: context.scope,
|
|
47933
47780
|
correlationId: context.correlationId,
|
|
47934
47781
|
traceId: context.traceId,
|
|
47935
47782
|
hook: context.hook,
|
|
@@ -47952,7 +47799,6 @@ var require_events2 = __commonJS({
|
|
|
47952
47799
|
source: "daemon",
|
|
47953
47800
|
context: {
|
|
47954
47801
|
sessionId: context.sessionId,
|
|
47955
|
-
scope: context.scope,
|
|
47956
47802
|
correlationId: context.correlationId,
|
|
47957
47803
|
traceId: context.traceId,
|
|
47958
47804
|
hook: context.hook,
|
|
@@ -48095,7 +47941,6 @@ var require_consumption_handler_factory = __commonJS({
|
|
|
48095
47941
|
}
|
|
48096
47942
|
(0, core_1.logEvent)(cliCtx.logger, events_js_1.ReminderEvents.reminderConsumed({
|
|
48097
47943
|
sessionId,
|
|
48098
|
-
scope: cliCtx.paths.projectDir ? "project" : "user",
|
|
48099
47944
|
hook
|
|
48100
47945
|
}, {
|
|
48101
47946
|
reminderName: reminder.name,
|
|
@@ -48204,7 +48049,7 @@ var require_inject_stop = __commonJS({
|
|
|
48204
48049
|
}
|
|
48205
48050
|
return (0, consumption_handler_factory_js_1.buildDefaultResponse)(reminder, supportsBlocking);
|
|
48206
48051
|
} else {
|
|
48207
|
-
const metrics = reminder.stagedAt ?? { turnCount: 0, toolsThisTurn: 0 };
|
|
48052
|
+
const metrics = reminder.stagedAt ?? { turnCount: 0, toolsThisTurn: 0, toolCount: 0 };
|
|
48208
48053
|
try {
|
|
48209
48054
|
await ipc.send("vc-unverified.set", {
|
|
48210
48055
|
sessionId,
|
|
@@ -48214,7 +48059,8 @@ var require_inject_stop = __commonJS({
|
|
|
48214
48059
|
},
|
|
48215
48060
|
metrics: {
|
|
48216
48061
|
turnCount: metrics.turnCount,
|
|
48217
|
-
toolsThisTurn: metrics.toolsThisTurn
|
|
48062
|
+
toolsThisTurn: metrics.toolsThisTurn,
|
|
48063
|
+
toolCount: metrics.toolCount
|
|
48218
48064
|
}
|
|
48219
48065
|
});
|
|
48220
48066
|
} catch (setErr) {
|
|
@@ -48243,13 +48089,14 @@ var require_inject_stop = __commonJS({
|
|
|
48243
48089
|
if (projectDir) {
|
|
48244
48090
|
const ipc = new core_1.IpcService(projectDir, cliCtx.logger);
|
|
48245
48091
|
try {
|
|
48246
|
-
const metrics = reminder.stagedAt ?? { turnCount: 0, toolsThisTurn: 0 };
|
|
48092
|
+
const metrics = reminder.stagedAt ?? { turnCount: 0, toolsThisTurn: 0, toolCount: 0 };
|
|
48247
48093
|
await ipc.send("reminder.consumed", {
|
|
48248
48094
|
sessionId,
|
|
48249
48095
|
reminderName: reminder.name,
|
|
48250
48096
|
metrics: {
|
|
48251
48097
|
turnCount: metrics.turnCount,
|
|
48252
|
-
toolsThisTurn: metrics.toolsThisTurn
|
|
48098
|
+
toolsThisTurn: metrics.toolsThisTurn,
|
|
48099
|
+
toolCount: metrics.toolCount
|
|
48253
48100
|
}
|
|
48254
48101
|
});
|
|
48255
48102
|
} finally {
|
|
@@ -48702,21 +48549,19 @@ var require_context2 = __commonJS({
|
|
|
48702
48549
|
var feature_reminders_1 = require_dist4();
|
|
48703
48550
|
function buildCLIContext(options) {
|
|
48704
48551
|
const { runtime, sessionId, transcriptPath } = options;
|
|
48705
|
-
if (!runtime.
|
|
48706
|
-
throw new Error("Cannot build CLIContext without project root - reminder consumption requires project
|
|
48552
|
+
if (!runtime.projectRoot) {
|
|
48553
|
+
throw new Error("Cannot build CLIContext without project root - reminder consumption requires project root");
|
|
48707
48554
|
}
|
|
48708
|
-
const projectRoot = runtime.
|
|
48555
|
+
const projectRoot = runtime.projectRoot;
|
|
48709
48556
|
const paths = {
|
|
48710
48557
|
projectDir: projectRoot,
|
|
48711
48558
|
userConfigDir: (0, node_path_1.join)((0, node_os_1.homedir)(), ".sidekick"),
|
|
48712
|
-
projectConfigDir: (0, node_path_1.join)(projectRoot, ".sidekick")
|
|
48713
|
-
hookScriptPath: runtime.scope.hookScriptPath
|
|
48559
|
+
projectConfigDir: (0, node_path_1.join)(projectRoot, ".sidekick")
|
|
48714
48560
|
};
|
|
48715
48561
|
const handlers = new core_1.HandlerRegistryImpl({
|
|
48716
48562
|
logger: runtime.logger,
|
|
48717
48563
|
sessionId,
|
|
48718
|
-
transcriptPath
|
|
48719
|
-
scope: runtime.scope.scope
|
|
48564
|
+
transcriptPath
|
|
48720
48565
|
});
|
|
48721
48566
|
const daemon = new core_1.DaemonClient(projectRoot, runtime.logger);
|
|
48722
48567
|
const context = {
|
|
@@ -48871,11 +48716,10 @@ var require_hook = __commonJS({
|
|
|
48871
48716
|
}
|
|
48872
48717
|
};
|
|
48873
48718
|
}
|
|
48874
|
-
function buildHookEvent(hookName, input, correlationId
|
|
48719
|
+
function buildHookEvent(hookName, input, correlationId) {
|
|
48875
48720
|
const context = {
|
|
48876
48721
|
sessionId: input.sessionId,
|
|
48877
48722
|
timestamp: Date.now(),
|
|
48878
|
-
scope,
|
|
48879
48723
|
correlationId
|
|
48880
48724
|
};
|
|
48881
48725
|
switch (hookName) {
|
|
@@ -48914,16 +48758,15 @@ ${daemonResponse.additionalContext}` : cliResponse.additionalContext;
|
|
|
48914
48758
|
return merged;
|
|
48915
48759
|
}
|
|
48916
48760
|
async function handleHookCommand(hookName, options, logger, stdout) {
|
|
48917
|
-
const { projectRoot, hookInput, correlationId,
|
|
48761
|
+
const { projectRoot, hookInput, correlationId, runtime } = options;
|
|
48918
48762
|
const startTime = Date.now();
|
|
48919
48763
|
const logContext = {
|
|
48920
48764
|
sessionId: hookInput.sessionId,
|
|
48921
|
-
scope,
|
|
48922
48765
|
correlationId,
|
|
48923
48766
|
hook: hookName
|
|
48924
48767
|
};
|
|
48925
48768
|
(0, core_1.logEvent)(logger, core_1.LogEvents.hookReceived(logContext, { cwd: hookInput.cwd, mode: "hook" }));
|
|
48926
|
-
const event = buildHookEvent(hookName, hookInput, correlationId
|
|
48769
|
+
const event = buildHookEvent(hookName, hookInput, correlationId);
|
|
48927
48770
|
logger.debug("Dispatching hook event to daemon", {
|
|
48928
48771
|
hook: hookName,
|
|
48929
48772
|
sessionId: hookInput.sessionId
|
|
@@ -49125,7 +48968,7 @@ var require_hook_command = __commonJS({
|
|
|
49125
48968
|
}
|
|
49126
48969
|
}
|
|
49127
48970
|
async function handleUnifiedHookCommand(hookName, options, logger, stdout) {
|
|
49128
|
-
const { projectRoot, hookInput, correlationId,
|
|
48971
|
+
const { projectRoot, hookInput, correlationId, runtime } = options;
|
|
49129
48972
|
logger.debug("Unified hook command invoked", { hookName, sessionId: hookInput.sessionId });
|
|
49130
48973
|
let internalOutput = "";
|
|
49131
48974
|
const captureStream = {
|
|
@@ -49139,7 +48982,6 @@ var require_hook_command = __commonJS({
|
|
|
49139
48982
|
sessionId: hookInput.sessionId,
|
|
49140
48983
|
hookInput,
|
|
49141
48984
|
correlationId,
|
|
49142
|
-
scope,
|
|
49143
48985
|
runtime
|
|
49144
48986
|
}, logger, captureStream);
|
|
49145
48987
|
const internalResponse = parseInternalResponse(internalOutput.trim(), hookName, logger);
|
|
@@ -49672,7 +49514,6 @@ var require_events3 = __commonJS({
|
|
|
49672
49514
|
source: "daemon",
|
|
49673
49515
|
context: {
|
|
49674
49516
|
sessionId: context.sessionId,
|
|
49675
|
-
scope: context.scope,
|
|
49676
49517
|
correlationId: context.correlationId,
|
|
49677
49518
|
traceId: context.traceId,
|
|
49678
49519
|
hook: context.hook,
|
|
@@ -49696,7 +49537,6 @@ var require_events3 = __commonJS({
|
|
|
49696
49537
|
source: "daemon",
|
|
49697
49538
|
context: {
|
|
49698
49539
|
sessionId: context.sessionId,
|
|
49699
|
-
scope: context.scope,
|
|
49700
49540
|
correlationId: context.correlationId,
|
|
49701
49541
|
traceId: context.traceId,
|
|
49702
49542
|
hook: context.hook,
|
|
@@ -50097,7 +49937,7 @@ var require_update_summary = __commonJS({
|
|
|
50097
49937
|
async function generateResumeMessage(ctx, summaryState, eventContext, summary, transcriptExcerpt, config) {
|
|
50098
49938
|
const { sessionId } = eventContext;
|
|
50099
49939
|
if (summary.session_title_confidence < types_js_1.RESUME_MIN_CONFIDENCE || summary.latest_intent_confidence < types_js_1.RESUME_MIN_CONFIDENCE) {
|
|
50100
|
-
(0, core_1.logEvent)(ctx.logger, core_1.LogEvents.resumeSkipped({ sessionId
|
|
49940
|
+
(0, core_1.logEvent)(ctx.logger, core_1.LogEvents.resumeSkipped({ sessionId }, {
|
|
50101
49941
|
title_confidence: summary.session_title_confidence,
|
|
50102
49942
|
intent_confidence: summary.latest_intent_confidence,
|
|
50103
49943
|
min_confidence: types_js_1.RESUME_MIN_CONFIDENCE
|
|
@@ -50114,7 +49954,7 @@ var require_update_summary = __commonJS({
|
|
|
50114
49954
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
50115
49955
|
};
|
|
50116
49956
|
await summaryState.resumeMessage.write(sessionId, resumeState);
|
|
50117
|
-
(0, core_1.logEvent)(ctx.logger, core_1.LogEvents.resumeUpdated({ sessionId
|
|
49957
|
+
(0, core_1.logEvent)(ctx.logger, core_1.LogEvents.resumeUpdated({ sessionId }, {
|
|
50118
49958
|
snarky_comment: resumeState.snarky_comment,
|
|
50119
49959
|
timestamp: resumeState.timestamp
|
|
50120
49960
|
}));
|
|
@@ -50125,7 +49965,7 @@ var require_update_summary = __commonJS({
|
|
|
50125
49965
|
ctx.logger.warn("Resume message prompt not found", { path: RESUME_PROMPT_FILE });
|
|
50126
49966
|
return;
|
|
50127
49967
|
}
|
|
50128
|
-
(0, core_1.logEvent)(ctx.logger, core_1.LogEvents.resumeGenerating({ sessionId
|
|
49968
|
+
(0, core_1.logEvent)(ctx.logger, core_1.LogEvents.resumeGenerating({ sessionId }, {
|
|
50129
49969
|
title_confidence: summary.session_title_confidence,
|
|
50130
49970
|
intent_confidence: summary.latest_intent_confidence
|
|
50131
49971
|
}));
|
|
@@ -50154,7 +49994,7 @@ var require_update_summary = __commonJS({
|
|
|
50154
49994
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
50155
49995
|
};
|
|
50156
49996
|
await summaryState.resumeMessage.write(sessionId, resumeState);
|
|
50157
|
-
(0, core_1.logEvent)(ctx.logger, core_1.LogEvents.resumeUpdated({ sessionId
|
|
49997
|
+
(0, core_1.logEvent)(ctx.logger, core_1.LogEvents.resumeUpdated({ sessionId }, {
|
|
50158
49998
|
snarky_comment: resumeState.snarky_comment,
|
|
50159
49999
|
timestamp: resumeState.timestamp
|
|
50160
50000
|
}));
|
|
@@ -51855,8 +51695,7 @@ Examples:
|
|
|
51855
51695
|
const sessionId = options.sessionId ?? "current";
|
|
51856
51696
|
const stateService = new core_1.StateService(projectDir);
|
|
51857
51697
|
const eventContext = {
|
|
51858
|
-
sessionId
|
|
51859
|
-
scope: "project"
|
|
51698
|
+
sessionId
|
|
51860
51699
|
};
|
|
51861
51700
|
const cwd = options.hookInput?.cwd ?? process.cwd();
|
|
51862
51701
|
logger.debug("Statusline hookInput received", { hookInput: options.hookInput });
|
|
@@ -52735,6 +52574,38 @@ var require_dev_mode = __commonJS({
|
|
|
52735
52574
|
}
|
|
52736
52575
|
return zombies;
|
|
52737
52576
|
}
|
|
52577
|
+
async function cleanupStalePidFiles(logger) {
|
|
52578
|
+
const daemonsDir = (0, core_1.getUserDaemonsDir)();
|
|
52579
|
+
let cleanedCount = 0;
|
|
52580
|
+
let files;
|
|
52581
|
+
try {
|
|
52582
|
+
files = await (0, promises_12.readdir)(daemonsDir);
|
|
52583
|
+
} catch {
|
|
52584
|
+
return 0;
|
|
52585
|
+
}
|
|
52586
|
+
const pidFiles = files.filter((f) => f.endsWith(".pid"));
|
|
52587
|
+
for (const pidFile of pidFiles) {
|
|
52588
|
+
const pidPath = node_path_1.default.join(daemonsDir, pidFile);
|
|
52589
|
+
try {
|
|
52590
|
+
const content = await (0, promises_12.readFile)(pidPath, "utf-8");
|
|
52591
|
+
const info = JSON.parse(content);
|
|
52592
|
+
try {
|
|
52593
|
+
process.kill(info.pid, 0);
|
|
52594
|
+
} catch {
|
|
52595
|
+
await (0, promises_12.unlink)(pidPath).catch(() => {
|
|
52596
|
+
});
|
|
52597
|
+
logger.debug("Removed stale PID file", { pidFile, pid: info.pid });
|
|
52598
|
+
cleanedCount++;
|
|
52599
|
+
}
|
|
52600
|
+
} catch {
|
|
52601
|
+
await (0, promises_12.unlink)(pidPath).catch(() => {
|
|
52602
|
+
});
|
|
52603
|
+
logger.debug("Removed corrupt PID file", { pidFile });
|
|
52604
|
+
cleanedCount++;
|
|
52605
|
+
}
|
|
52606
|
+
}
|
|
52607
|
+
return cleanedCount;
|
|
52608
|
+
}
|
|
52738
52609
|
function isDevHookCommand(command) {
|
|
52739
52610
|
return command?.includes("dev-hooks") ?? false;
|
|
52740
52611
|
}
|
|
@@ -53007,13 +52878,42 @@ var require_dev_mode = __commonJS({
|
|
|
53007
52878
|
stdout.write("\n");
|
|
53008
52879
|
const shouldKill = force || await promptConfirm("Kill these processes?", stdout, stdin);
|
|
53009
52880
|
if (shouldKill) {
|
|
53010
|
-
|
|
53011
|
-
const
|
|
52881
|
+
let killedCount = 0;
|
|
52882
|
+
for (const zombie of zombies) {
|
|
52883
|
+
const filesToRemove = [
|
|
52884
|
+
(0, core_1.getUserPidPath)(zombie.projectDir),
|
|
52885
|
+
(0, core_1.getPidPath)(zombie.projectDir),
|
|
52886
|
+
(0, core_1.getSocketPath)(zombie.projectDir),
|
|
52887
|
+
(0, core_1.getTokenPath)(zombie.projectDir)
|
|
52888
|
+
];
|
|
52889
|
+
try {
|
|
52890
|
+
process.kill(zombie.pid, "SIGKILL");
|
|
52891
|
+
logger.info("Killed zombie daemon", { pid: zombie.pid, projectDir: zombie.projectDir });
|
|
52892
|
+
killedCount++;
|
|
52893
|
+
} catch (err) {
|
|
52894
|
+
const code = err.code;
|
|
52895
|
+
if (code === "ESRCH") {
|
|
52896
|
+
logger.info("Zombie daemon already exited", { pid: zombie.pid, projectDir: zombie.projectDir });
|
|
52897
|
+
killedCount++;
|
|
52898
|
+
} else {
|
|
52899
|
+
logger.warn("Failed to kill zombie daemon", {
|
|
52900
|
+
pid: zombie.pid,
|
|
52901
|
+
error: err instanceof Error ? err.message : String(err)
|
|
52902
|
+
});
|
|
52903
|
+
}
|
|
52904
|
+
}
|
|
52905
|
+
await Promise.all(filesToRemove.map((f) => (0, promises_12.unlink)(f).catch(() => {
|
|
52906
|
+
})));
|
|
52907
|
+
}
|
|
53012
52908
|
log(stdout, "info", `Killed ${killedCount} zombie daemon(s)`);
|
|
53013
52909
|
} else {
|
|
53014
52910
|
log(stdout, "info", "Skipping zombie cleanup");
|
|
53015
52911
|
}
|
|
53016
52912
|
}
|
|
52913
|
+
const staleCount = await cleanupStalePidFiles(logger);
|
|
52914
|
+
if (staleCount > 0) {
|
|
52915
|
+
log(stdout, "info", `Cleaned up ${staleCount} stale PID file(s)`);
|
|
52916
|
+
}
|
|
53017
52917
|
stdout.write("\n");
|
|
53018
52918
|
log(stdout, "info", "Clean complete. Restart Claude Code with: claude --continue");
|
|
53019
52919
|
return { exitCode: 0 };
|
|
@@ -53171,11 +53071,10 @@ Example: { "command": "pnpm sidekick daemon status", "dangerouslyDisableSandbox"
|
|
|
53171
53071
|
`;
|
|
53172
53072
|
var types_1 = require_dist();
|
|
53173
53073
|
var runtime_1 = require_runtime();
|
|
53174
|
-
var hook_js_1 = require_hook();
|
|
53175
53074
|
function parseArgs(argv) {
|
|
53176
53075
|
const parsed = (0, yargs_parser_1.default)(argv, {
|
|
53177
|
-
boolean: ["
|
|
53178
|
-
string: ["
|
|
53076
|
+
boolean: ["wait", "open", "prefer-project", "help", "kill", "force"],
|
|
53077
|
+
string: ["project-dir", "log-level", "format", "host", "session-id", "type"],
|
|
53179
53078
|
number: ["port", "width"],
|
|
53180
53079
|
alias: {
|
|
53181
53080
|
h: "help"
|
|
@@ -53184,13 +53083,10 @@ Example: { "command": "pnpm sidekick daemon status", "dangerouslyDisableSandbox"
|
|
|
53184
53083
|
"camel-case-expansion": false
|
|
53185
53084
|
}
|
|
53186
53085
|
});
|
|
53187
|
-
const command = parsed._[0]
|
|
53086
|
+
const command = parsed._[0];
|
|
53188
53087
|
return {
|
|
53189
53088
|
command,
|
|
53190
|
-
hookMode: Boolean(parsed.hook),
|
|
53191
|
-
hookScriptPath: parsed["hook-script-path"],
|
|
53192
53089
|
projectDir: parsed["project-dir"],
|
|
53193
|
-
scopeOverride: parsed.scope,
|
|
53194
53090
|
logLevel: parsed["log-level"],
|
|
53195
53091
|
wait: Boolean(parsed.wait),
|
|
53196
53092
|
format: parsed.format,
|
|
@@ -53240,12 +53136,9 @@ Example: { "command": "pnpm sidekick daemon status", "dangerouslyDisableSandbox"
|
|
|
53240
53136
|
const homeDir = options.homeDir ?? options.env?.HOME;
|
|
53241
53137
|
const hookInput = parseHookInput(options.stdinData);
|
|
53242
53138
|
const runtime = (0, runtime_1.bootstrapRuntime)({
|
|
53243
|
-
hookScriptPath: parsed.hookScriptPath,
|
|
53244
53139
|
projectDir: parsed.projectDir,
|
|
53245
|
-
scopeOverride: parsed.scopeOverride,
|
|
53246
53140
|
logLevel: parsed.logLevel,
|
|
53247
53141
|
stderrSink: stderr,
|
|
53248
|
-
cwd: options.cwd,
|
|
53249
53142
|
homeDir,
|
|
53250
53143
|
command: parsed.command,
|
|
53251
53144
|
interactive: options.interactive ?? false,
|
|
@@ -53254,15 +53147,12 @@ Example: { "command": "pnpm sidekick daemon status", "dangerouslyDisableSandbox"
|
|
|
53254
53147
|
if (hookInput) {
|
|
53255
53148
|
runtime.logger.debug("Hook input received", { hookInput: hookInput.raw });
|
|
53256
53149
|
}
|
|
53257
|
-
const shouldExit = runtime.scope.dualInstallDetected && parsed.scopeOverride !== "project";
|
|
53258
|
-
if (shouldExit) {
|
|
53259
|
-
runtime.logger.warn("User-scope hook detected project installation. Exiting to prevent duplicate execution.");
|
|
53260
|
-
}
|
|
53261
53150
|
return {
|
|
53262
53151
|
runtime,
|
|
53263
53152
|
hookInput,
|
|
53264
53153
|
parsed,
|
|
53265
|
-
shouldExit
|
|
53154
|
+
shouldExit: false
|
|
53155
|
+
// No longer needed - Claude Code handles deduplication
|
|
53266
53156
|
};
|
|
53267
53157
|
}
|
|
53268
53158
|
async function initializeSession(options) {
|
|
@@ -53327,36 +53217,10 @@ Examples:
|
|
|
53327
53217
|
return { exitCode: 0, stdout: GLOBAL_HELP_TEXT, stderr: "" };
|
|
53328
53218
|
}
|
|
53329
53219
|
async function routeCommand(context) {
|
|
53330
|
-
const { parsed, runtime, hookInput, stdout
|
|
53220
|
+
const { parsed, runtime, hookInput, stdout } = context;
|
|
53331
53221
|
runtime.logger.debug("Raw hook input", { hookInput });
|
|
53332
|
-
if (parsed.
|
|
53333
|
-
|
|
53334
|
-
if (hookName) {
|
|
53335
|
-
const result = await (0, hook_js_1.handleHookCommand)(hookName, {
|
|
53336
|
-
projectRoot: runtime.scope.projectRoot,
|
|
53337
|
-
sessionId: hookInput.sessionId,
|
|
53338
|
-
hookInput,
|
|
53339
|
-
correlationId: runtime.correlationId,
|
|
53340
|
-
scope: runtime.scope.scope,
|
|
53341
|
-
runtime
|
|
53342
|
-
}, runtime.logger, stdout);
|
|
53343
|
-
return { exitCode: result.exitCode, stdout: result.output, stderr: "" };
|
|
53344
|
-
}
|
|
53345
|
-
}
|
|
53346
|
-
if (!parsed.hookMode) {
|
|
53347
|
-
const isDefaultCommand = parsed.command === "session-start";
|
|
53348
|
-
const isHelpCommand = parsed.command === "help" || parsed.command === "--help" || parsed.command === "-h";
|
|
53349
|
-
if (parsed.help && isDefaultCommand || isHelpCommand) {
|
|
53350
|
-
return showGlobalHelp(stdout);
|
|
53351
|
-
}
|
|
53352
|
-
}
|
|
53353
|
-
if (parsed.hookMode && !hookInput) {
|
|
53354
|
-
runtime.logger.warn("Hook mode invoked without valid hook input, returning empty response", {
|
|
53355
|
-
command: parsed.command,
|
|
53356
|
-
daemonStarted
|
|
53357
|
-
});
|
|
53358
|
-
stdout.write("{}\n");
|
|
53359
|
-
return { exitCode: 0, stdout: "{}", stderr: "" };
|
|
53222
|
+
if (!parsed.command || parsed.command === "help") {
|
|
53223
|
+
return showGlobalHelp(stdout);
|
|
53360
53224
|
}
|
|
53361
53225
|
if (parsed.command === "hook") {
|
|
53362
53226
|
const { parseHookArg, handleUnifiedHookCommand } = await Promise.resolve().then(() => __importStar(require_hook_command()));
|
|
@@ -53384,27 +53248,31 @@ Examples:
|
|
|
53384
53248
|
return { exitCode: 0, stdout: helpText, stderr: "" };
|
|
53385
53249
|
}
|
|
53386
53250
|
if (!hookName) {
|
|
53387
|
-
const
|
|
53251
|
+
const errorMsg2 = `Error: Unknown hook name '${hookArg}'
|
|
53388
53252
|
Run 'sidekick hook --help' for available hooks.
|
|
53389
53253
|
`;
|
|
53390
|
-
stdout.write(
|
|
53391
|
-
return { exitCode: 1, stdout:
|
|
53254
|
+
stdout.write(errorMsg2);
|
|
53255
|
+
return { exitCode: 1, stdout: errorMsg2, stderr: "" };
|
|
53256
|
+
}
|
|
53257
|
+
if (!parsed.projectDir) {
|
|
53258
|
+
const errorMsg2 = "Hook command requires --project-dir to be specified\n";
|
|
53259
|
+
stdout.write(errorMsg2);
|
|
53260
|
+
return { exitCode: 1, stdout: errorMsg2, stderr: "" };
|
|
53392
53261
|
}
|
|
53393
53262
|
if (!hookInput) {
|
|
53394
53263
|
runtime.logger.warn("Hook command invoked without valid hook input", { hookName });
|
|
53395
53264
|
stdout.write("{}\n");
|
|
53396
53265
|
return { exitCode: 0, stdout: "{}", stderr: "" };
|
|
53397
53266
|
}
|
|
53398
|
-
if (!runtime.
|
|
53267
|
+
if (!runtime.projectRoot) {
|
|
53399
53268
|
runtime.logger.warn("Hook command invoked without project root", { hookName });
|
|
53400
53269
|
stdout.write("{}\n");
|
|
53401
53270
|
return { exitCode: 0, stdout: "{}", stderr: "" };
|
|
53402
53271
|
}
|
|
53403
53272
|
const result = await handleUnifiedHookCommand(hookName, {
|
|
53404
|
-
projectRoot: runtime.
|
|
53273
|
+
projectRoot: runtime.projectRoot,
|
|
53405
53274
|
hookInput,
|
|
53406
53275
|
correlationId: runtime.correlationId,
|
|
53407
|
-
scope: runtime.scope.scope,
|
|
53408
53276
|
runtime
|
|
53409
53277
|
}, runtime.logger, stdout);
|
|
53410
53278
|
return { exitCode: result.exitCode, stdout: result.output, stderr: "" };
|
|
@@ -53416,7 +53284,7 @@ Run 'sidekick hook --help' for available hooks.
|
|
|
53416
53284
|
return { exitCode: 1, stdout: SANDBOX_ERROR_MESSAGE, stderr: "" };
|
|
53417
53285
|
}
|
|
53418
53286
|
const { handleDaemonCommand } = await Promise.resolve().then(() => __importStar(require_daemon()));
|
|
53419
|
-
const result = await handleDaemonCommand(subcommand, runtime.
|
|
53287
|
+
const result = await handleDaemonCommand(subcommand, runtime.projectRoot || process.cwd(), runtime.logger, stdout, { wait: parsed.wait });
|
|
53420
53288
|
return { exitCode: result.exitCode, stdout: "", stderr: "" };
|
|
53421
53289
|
}
|
|
53422
53290
|
if (parsed.command === "statusline") {
|
|
@@ -53424,7 +53292,7 @@ Run 'sidekick hook --help' for available hooks.
|
|
|
53424
53292
|
const sessionId = parsed.sessionIdArg ?? hookInput?.sessionId;
|
|
53425
53293
|
const parsedHookInput = hookInput?.raw ? parseStatuslineInput(hookInput.raw) : void 0;
|
|
53426
53294
|
const statuslineFormat = parsed.format === "text" || parsed.format === "json" ? parsed.format : void 0;
|
|
53427
|
-
const result = await handleStatuslineCommand(runtime.
|
|
53295
|
+
const result = await handleStatuslineCommand(runtime.projectRoot || process.cwd(), runtime.logger, stdout, {
|
|
53428
53296
|
format: statuslineFormat,
|
|
53429
53297
|
sessionId,
|
|
53430
53298
|
hookInput: parsedHookInput,
|
|
@@ -53436,7 +53304,7 @@ Run 'sidekick hook --help' for available hooks.
|
|
|
53436
53304
|
}
|
|
53437
53305
|
if (parsed.command === "ui") {
|
|
53438
53306
|
const { handleUiCommand } = await Promise.resolve().then(() => __importStar(require_ui()));
|
|
53439
|
-
const result = await handleUiCommand(runtime.
|
|
53307
|
+
const result = await handleUiCommand(runtime.projectRoot || process.cwd(), runtime.logger, stdout, {
|
|
53440
53308
|
port: parsed.port,
|
|
53441
53309
|
host: parsed.host,
|
|
53442
53310
|
open: parsed.open,
|
|
@@ -53448,7 +53316,7 @@ Run 'sidekick hook --help' for available hooks.
|
|
|
53448
53316
|
const { handlePersonaCommand } = await Promise.resolve().then(() => __importStar(require_persona2()));
|
|
53449
53317
|
const subcommand = parsed.help ? "--help" : parsed._?.[1];
|
|
53450
53318
|
const args = parsed._?.slice(2) ?? [];
|
|
53451
|
-
const result = await handlePersonaCommand(subcommand, args, runtime.
|
|
53319
|
+
const result = await handlePersonaCommand(subcommand, args, runtime.projectRoot || process.cwd(), runtime.logger, stdout, {
|
|
53452
53320
|
sessionId: parsed.sessionIdArg,
|
|
53453
53321
|
format: parsed.format === "json" || parsed.format === "table" ? parsed.format : void 0,
|
|
53454
53322
|
testType: parsed.messageType,
|
|
@@ -53458,7 +53326,7 @@ Run 'sidekick hook --help' for available hooks.
|
|
|
53458
53326
|
}
|
|
53459
53327
|
if (parsed.command === "sessions") {
|
|
53460
53328
|
const { handleSessionsCommand } = await Promise.resolve().then(() => __importStar(require_sessions()));
|
|
53461
|
-
const result = await handleSessionsCommand(runtime.
|
|
53329
|
+
const result = await handleSessionsCommand(runtime.projectRoot || process.cwd(), runtime.logger, stdout, {
|
|
53462
53330
|
format: parsed.format === "json" || parsed.format === "table" ? parsed.format : void 0,
|
|
53463
53331
|
help: parsed.help,
|
|
53464
53332
|
width: parsed.width
|
|
@@ -53468,14 +53336,14 @@ Run 'sidekick hook --help' for available hooks.
|
|
|
53468
53336
|
if (parsed.command === "dev-mode") {
|
|
53469
53337
|
const subcommand = parsed.help ? "--help" : parsed._ && parsed._[1] || "status";
|
|
53470
53338
|
const { handleDevModeCommand } = await Promise.resolve().then(() => __importStar(require_dev_mode()));
|
|
53471
|
-
const result = await handleDevModeCommand(subcommand, runtime.
|
|
53339
|
+
const result = await handleDevModeCommand(subcommand, runtime.projectRoot || process.cwd(), runtime.logger, stdout, { force: Boolean(parsed.force) });
|
|
53472
53340
|
return { exitCode: result.exitCode, stdout: "", stderr: "" };
|
|
53473
53341
|
}
|
|
53474
|
-
|
|
53475
|
-
|
|
53476
|
-
|
|
53477
|
-
|
|
53478
|
-
return
|
|
53342
|
+
const errorMsg = `Unknown command: ${parsed.command}
|
|
53343
|
+
Run 'sidekick help' for available commands.
|
|
53344
|
+
`;
|
|
53345
|
+
stdout.write(errorMsg);
|
|
53346
|
+
return { exitCode: 1, stdout: errorMsg, stderr: "" };
|
|
53479
53347
|
}
|
|
53480
53348
|
async function persistCliLogMetrics(stateService, sessionId, counts, logger) {
|
|
53481
53349
|
const logMetricsPath = stateService.sessionStatePath(sessionId, "cli-log-metrics.json");
|
|
@@ -53512,18 +53380,17 @@ Run 'sidekick hook --help' for available hooks.
|
|
|
53512
53380
|
stateService: runtime.stateService,
|
|
53513
53381
|
logger: runtime.logger
|
|
53514
53382
|
});
|
|
53515
|
-
const isHookExecution = parsed.
|
|
53516
|
-
|
|
53383
|
+
const isHookExecution = parsed.command === "hook" && Boolean(parsed.projectDir);
|
|
53384
|
+
await ensureDaemon({
|
|
53517
53385
|
hookMode: isHookExecution,
|
|
53518
|
-
projectRoot: runtime.
|
|
53386
|
+
projectRoot: runtime.projectRoot,
|
|
53519
53387
|
logger: runtime.logger
|
|
53520
53388
|
});
|
|
53521
53389
|
const result = await routeCommand({
|
|
53522
53390
|
parsed,
|
|
53523
53391
|
runtime,
|
|
53524
53392
|
hookInput,
|
|
53525
|
-
stdout
|
|
53526
|
-
daemonStarted
|
|
53393
|
+
stdout
|
|
53527
53394
|
});
|
|
53528
53395
|
if (sessionId) {
|
|
53529
53396
|
await persistCliLogMetrics(runtime.stateService, sessionId, runtime.getLogCounts(), runtime.logger);
|
package/package.json
CHANGED