@codyswann/lisa 2.332.2 → 2.332.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/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +2 -1
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/package.json +1 -1
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-setup-remote-env/scripts/setup-remote-env.mjs +109 -0
- package/plugins/lisa/skills/lisa-setup-remote-env/scripts/setup-remote-env.mjs +109 -0
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-agy/skills/lisa-setup-remote-env/scripts/setup-remote-env.mjs +109 -0
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/skills/lisa-setup-remote-env/scripts/setup-remote-env.mjs +109 -0
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/skills/lisa-setup-remote-env/scripts/setup-remote-env.mjs +109 -0
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/src/base/skills/lisa-setup-remote-env/scripts/setup-remote-env.mjs +109 -0
package/package.json
CHANGED
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"brace-expansion": ">=5.0.9"
|
|
116
116
|
},
|
|
117
117
|
"name": "@codyswann/lisa",
|
|
118
|
-
"version": "2.332.
|
|
118
|
+
"version": "2.332.3",
|
|
119
119
|
"description": "Claude Code governance framework that applies guardrails, guidance, and automated enforcement to projects",
|
|
120
120
|
"main": "dist/index.js",
|
|
121
121
|
"exports": {
|
package/plugins/lisa/.codex-plugin/skills/lisa-setup-remote-env/scripts/setup-remote-env.mjs
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
rmSync,
|
|
39
39
|
writeFileSync,
|
|
40
40
|
} from "node:fs";
|
|
41
|
+
import { homedir } from "node:os";
|
|
41
42
|
import { delimiter, dirname, join, resolve } from "node:path";
|
|
42
43
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
43
44
|
|
|
@@ -583,6 +584,101 @@ export const SETUP_FIELD =
|
|
|
583
584
|
'PWD=$PWD HOME=$HOME" >&2; ls -1 . "$HOME" /workspace 2>&1 | head -40 >&2; exit 1; }; ' +
|
|
584
585
|
'exit "$rc"';
|
|
585
586
|
|
|
587
|
+
/**
|
|
588
|
+
* Register the session-start hook at USER scope, so it fires wherever the
|
|
589
|
+
* session opens.
|
|
590
|
+
*
|
|
591
|
+
* The committed `.claude/settings.json` hook is *project*-scoped: it loads only
|
|
592
|
+
* when Claude Code's project directory is that repository. A cloud session does
|
|
593
|
+
* not reliably start there. With several repositories it starts in the shared
|
|
594
|
+
* parent, which is not a git repository at all; even with one, the checkout sits
|
|
595
|
+
* at `$HOME/<repo>` while the session may open at `$HOME`. In those sessions no
|
|
596
|
+
* project settings load, the hook never registers, and nothing materializes —
|
|
597
|
+
* the failure that `materializeAt: "both"` was introduced to paper over, and
|
|
598
|
+
* which it could not fix, because the setup phase cannot see the bootstrap
|
|
599
|
+
* credential in the first place.
|
|
600
|
+
*
|
|
601
|
+
* A user-scoped hook has neither problem: `~/.claude/settings.json` is read for
|
|
602
|
+
* every session regardless of project directory, and it runs in-session where
|
|
603
|
+
* the vendor's configured variables ARE present.
|
|
604
|
+
*
|
|
605
|
+
* Only ever on a remote surface. This writes machine state in an ephemeral
|
|
606
|
+
* container, which is fine there and would be an intrusion on a developer's
|
|
607
|
+
* laptop, where the project hook already works and the user owns that file.
|
|
608
|
+
*
|
|
609
|
+
* Merged, never clobbered, and idempotent on the exact command — an existing
|
|
610
|
+
* user settings file may carry hooks this knows nothing about.
|
|
611
|
+
* @param {string} repoRoot Absolute path to the checkout.
|
|
612
|
+
* @param {object} options Home directory, dry-run flag, and file seams.
|
|
613
|
+
* @returns {{action: string, path: string, reason?: string}} What was done.
|
|
614
|
+
*/
|
|
615
|
+
export function installUserSessionHook(repoRoot, options = {}) {
|
|
616
|
+
const {
|
|
617
|
+
home = process.env.HOME || homedir(),
|
|
618
|
+
dryRun = false,
|
|
619
|
+
exists = existsSync,
|
|
620
|
+
read = readFileSync,
|
|
621
|
+
write = writeFileSync,
|
|
622
|
+
mkdir = mkdirSync,
|
|
623
|
+
} = options;
|
|
624
|
+
|
|
625
|
+
const script = join(repoRoot, "scripts/lisa-remote-env/session-start.sh");
|
|
626
|
+
if (!exists(script)) {
|
|
627
|
+
return { action: "skipped", path: script, reason: "no session-start.sh" };
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
const dir = join(home, ".claude");
|
|
631
|
+
const settingsPath = join(dir, "settings.json");
|
|
632
|
+
const command = `bash ${script}`;
|
|
633
|
+
|
|
634
|
+
let settings = {};
|
|
635
|
+
if (exists(settingsPath)) {
|
|
636
|
+
try {
|
|
637
|
+
settings = JSON.parse(String(read(settingsPath, "utf8"))) || {};
|
|
638
|
+
} catch {
|
|
639
|
+
// Refuse rather than overwrite. A settings file that does not parse is
|
|
640
|
+
// still someone's configuration, and replacing it would be the careless
|
|
641
|
+
// destruction this whole function is written to avoid.
|
|
642
|
+
return {
|
|
643
|
+
action: "failed",
|
|
644
|
+
path: settingsPath,
|
|
645
|
+
reason: "existing settings.json is not valid JSON; left untouched",
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const hooks = settings.hooks ?? {};
|
|
651
|
+
const sessionStart = Array.isArray(hooks.SessionStart)
|
|
652
|
+
? hooks.SessionStart
|
|
653
|
+
: [];
|
|
654
|
+
const already = sessionStart.some(entry =>
|
|
655
|
+
(entry?.hooks ?? []).some(hook => hook?.command === command)
|
|
656
|
+
);
|
|
657
|
+
if (already) {
|
|
658
|
+
return { action: "present", path: settingsPath };
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
const updated = {
|
|
662
|
+
...settings,
|
|
663
|
+
hooks: {
|
|
664
|
+
...hooks,
|
|
665
|
+
SessionStart: [
|
|
666
|
+
...sessionStart,
|
|
667
|
+
{
|
|
668
|
+
matcher: "startup|resume",
|
|
669
|
+
hooks: [{ type: "command", command }],
|
|
670
|
+
},
|
|
671
|
+
],
|
|
672
|
+
},
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
if (dryRun) return { action: "would-register", path: settingsPath };
|
|
676
|
+
|
|
677
|
+
mkdir(dir, { recursive: true });
|
|
678
|
+
write(settingsPath, `${JSON.stringify(updated, null, 2)}\n`);
|
|
679
|
+
return { action: "registered", path: settingsPath };
|
|
680
|
+
}
|
|
681
|
+
|
|
586
682
|
/**
|
|
587
683
|
* The settings block that wires the session-start hook into a repository.
|
|
588
684
|
*
|
|
@@ -936,6 +1032,19 @@ async function main() {
|
|
|
936
1032
|
// codex-cloud both have no second chance, so a silent pass there would
|
|
937
1033
|
// hand back a session with no credentials and call it ready.
|
|
938
1034
|
const retried = !requested && materializesAtSessionStart(materializeAt);
|
|
1035
|
+
|
|
1036
|
+
// If the hook is what will retry, make sure the hook can actually fire.
|
|
1037
|
+
// Registering it at user scope is what makes the retry real rather than
|
|
1038
|
+
// assumed: the committed project hook does not load when the session opens
|
|
1039
|
+
// above the checkout, which is the norm in a cloud container.
|
|
1040
|
+
// `materializeAt` being set is what "remote surface" means here. The
|
|
1041
|
+
// toolchain phase derives a local `remote` from it, but that binding is
|
|
1042
|
+
// scoped to its own block and is not in scope in this one.
|
|
1043
|
+
if (retried && Boolean(materializeAt)) {
|
|
1044
|
+
const hook = installUserSessionHook(process.cwd(), { dryRun });
|
|
1045
|
+
console.log(` session-start hook: ${hook.action} (${hook.path})`);
|
|
1046
|
+
if (hook.reason) console.log(` ${hook.reason}`);
|
|
1047
|
+
}
|
|
939
1048
|
try {
|
|
940
1049
|
execFileSync(
|
|
941
1050
|
"node",
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
rmSync,
|
|
39
39
|
writeFileSync,
|
|
40
40
|
} from "node:fs";
|
|
41
|
+
import { homedir } from "node:os";
|
|
41
42
|
import { delimiter, dirname, join, resolve } from "node:path";
|
|
42
43
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
43
44
|
|
|
@@ -583,6 +584,101 @@ export const SETUP_FIELD =
|
|
|
583
584
|
'PWD=$PWD HOME=$HOME" >&2; ls -1 . "$HOME" /workspace 2>&1 | head -40 >&2; exit 1; }; ' +
|
|
584
585
|
'exit "$rc"';
|
|
585
586
|
|
|
587
|
+
/**
|
|
588
|
+
* Register the session-start hook at USER scope, so it fires wherever the
|
|
589
|
+
* session opens.
|
|
590
|
+
*
|
|
591
|
+
* The committed `.claude/settings.json` hook is *project*-scoped: it loads only
|
|
592
|
+
* when Claude Code's project directory is that repository. A cloud session does
|
|
593
|
+
* not reliably start there. With several repositories it starts in the shared
|
|
594
|
+
* parent, which is not a git repository at all; even with one, the checkout sits
|
|
595
|
+
* at `$HOME/<repo>` while the session may open at `$HOME`. In those sessions no
|
|
596
|
+
* project settings load, the hook never registers, and nothing materializes —
|
|
597
|
+
* the failure that `materializeAt: "both"` was introduced to paper over, and
|
|
598
|
+
* which it could not fix, because the setup phase cannot see the bootstrap
|
|
599
|
+
* credential in the first place.
|
|
600
|
+
*
|
|
601
|
+
* A user-scoped hook has neither problem: `~/.claude/settings.json` is read for
|
|
602
|
+
* every session regardless of project directory, and it runs in-session where
|
|
603
|
+
* the vendor's configured variables ARE present.
|
|
604
|
+
*
|
|
605
|
+
* Only ever on a remote surface. This writes machine state in an ephemeral
|
|
606
|
+
* container, which is fine there and would be an intrusion on a developer's
|
|
607
|
+
* laptop, where the project hook already works and the user owns that file.
|
|
608
|
+
*
|
|
609
|
+
* Merged, never clobbered, and idempotent on the exact command — an existing
|
|
610
|
+
* user settings file may carry hooks this knows nothing about.
|
|
611
|
+
* @param {string} repoRoot Absolute path to the checkout.
|
|
612
|
+
* @param {object} options Home directory, dry-run flag, and file seams.
|
|
613
|
+
* @returns {{action: string, path: string, reason?: string}} What was done.
|
|
614
|
+
*/
|
|
615
|
+
export function installUserSessionHook(repoRoot, options = {}) {
|
|
616
|
+
const {
|
|
617
|
+
home = process.env.HOME || homedir(),
|
|
618
|
+
dryRun = false,
|
|
619
|
+
exists = existsSync,
|
|
620
|
+
read = readFileSync,
|
|
621
|
+
write = writeFileSync,
|
|
622
|
+
mkdir = mkdirSync,
|
|
623
|
+
} = options;
|
|
624
|
+
|
|
625
|
+
const script = join(repoRoot, "scripts/lisa-remote-env/session-start.sh");
|
|
626
|
+
if (!exists(script)) {
|
|
627
|
+
return { action: "skipped", path: script, reason: "no session-start.sh" };
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
const dir = join(home, ".claude");
|
|
631
|
+
const settingsPath = join(dir, "settings.json");
|
|
632
|
+
const command = `bash ${script}`;
|
|
633
|
+
|
|
634
|
+
let settings = {};
|
|
635
|
+
if (exists(settingsPath)) {
|
|
636
|
+
try {
|
|
637
|
+
settings = JSON.parse(String(read(settingsPath, "utf8"))) || {};
|
|
638
|
+
} catch {
|
|
639
|
+
// Refuse rather than overwrite. A settings file that does not parse is
|
|
640
|
+
// still someone's configuration, and replacing it would be the careless
|
|
641
|
+
// destruction this whole function is written to avoid.
|
|
642
|
+
return {
|
|
643
|
+
action: "failed",
|
|
644
|
+
path: settingsPath,
|
|
645
|
+
reason: "existing settings.json is not valid JSON; left untouched",
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const hooks = settings.hooks ?? {};
|
|
651
|
+
const sessionStart = Array.isArray(hooks.SessionStart)
|
|
652
|
+
? hooks.SessionStart
|
|
653
|
+
: [];
|
|
654
|
+
const already = sessionStart.some(entry =>
|
|
655
|
+
(entry?.hooks ?? []).some(hook => hook?.command === command)
|
|
656
|
+
);
|
|
657
|
+
if (already) {
|
|
658
|
+
return { action: "present", path: settingsPath };
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
const updated = {
|
|
662
|
+
...settings,
|
|
663
|
+
hooks: {
|
|
664
|
+
...hooks,
|
|
665
|
+
SessionStart: [
|
|
666
|
+
...sessionStart,
|
|
667
|
+
{
|
|
668
|
+
matcher: "startup|resume",
|
|
669
|
+
hooks: [{ type: "command", command }],
|
|
670
|
+
},
|
|
671
|
+
],
|
|
672
|
+
},
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
if (dryRun) return { action: "would-register", path: settingsPath };
|
|
676
|
+
|
|
677
|
+
mkdir(dir, { recursive: true });
|
|
678
|
+
write(settingsPath, `${JSON.stringify(updated, null, 2)}\n`);
|
|
679
|
+
return { action: "registered", path: settingsPath };
|
|
680
|
+
}
|
|
681
|
+
|
|
586
682
|
/**
|
|
587
683
|
* The settings block that wires the session-start hook into a repository.
|
|
588
684
|
*
|
|
@@ -936,6 +1032,19 @@ async function main() {
|
|
|
936
1032
|
// codex-cloud both have no second chance, so a silent pass there would
|
|
937
1033
|
// hand back a session with no credentials and call it ready.
|
|
938
1034
|
const retried = !requested && materializesAtSessionStart(materializeAt);
|
|
1035
|
+
|
|
1036
|
+
// If the hook is what will retry, make sure the hook can actually fire.
|
|
1037
|
+
// Registering it at user scope is what makes the retry real rather than
|
|
1038
|
+
// assumed: the committed project hook does not load when the session opens
|
|
1039
|
+
// above the checkout, which is the norm in a cloud container.
|
|
1040
|
+
// `materializeAt` being set is what "remote surface" means here. The
|
|
1041
|
+
// toolchain phase derives a local `remote` from it, but that binding is
|
|
1042
|
+
// scoped to its own block and is not in scope in this one.
|
|
1043
|
+
if (retried && Boolean(materializeAt)) {
|
|
1044
|
+
const hook = installUserSessionHook(process.cwd(), { dryRun });
|
|
1045
|
+
console.log(` session-start hook: ${hook.action} (${hook.path})`);
|
|
1046
|
+
if (hook.reason) console.log(` ${hook.reason}`);
|
|
1047
|
+
}
|
|
939
1048
|
try {
|
|
940
1049
|
execFileSync(
|
|
941
1050
|
"node",
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
rmSync,
|
|
39
39
|
writeFileSync,
|
|
40
40
|
} from "node:fs";
|
|
41
|
+
import { homedir } from "node:os";
|
|
41
42
|
import { delimiter, dirname, join, resolve } from "node:path";
|
|
42
43
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
43
44
|
|
|
@@ -583,6 +584,101 @@ export const SETUP_FIELD =
|
|
|
583
584
|
'PWD=$PWD HOME=$HOME" >&2; ls -1 . "$HOME" /workspace 2>&1 | head -40 >&2; exit 1; }; ' +
|
|
584
585
|
'exit "$rc"';
|
|
585
586
|
|
|
587
|
+
/**
|
|
588
|
+
* Register the session-start hook at USER scope, so it fires wherever the
|
|
589
|
+
* session opens.
|
|
590
|
+
*
|
|
591
|
+
* The committed `.claude/settings.json` hook is *project*-scoped: it loads only
|
|
592
|
+
* when Claude Code's project directory is that repository. A cloud session does
|
|
593
|
+
* not reliably start there. With several repositories it starts in the shared
|
|
594
|
+
* parent, which is not a git repository at all; even with one, the checkout sits
|
|
595
|
+
* at `$HOME/<repo>` while the session may open at `$HOME`. In those sessions no
|
|
596
|
+
* project settings load, the hook never registers, and nothing materializes —
|
|
597
|
+
* the failure that `materializeAt: "both"` was introduced to paper over, and
|
|
598
|
+
* which it could not fix, because the setup phase cannot see the bootstrap
|
|
599
|
+
* credential in the first place.
|
|
600
|
+
*
|
|
601
|
+
* A user-scoped hook has neither problem: `~/.claude/settings.json` is read for
|
|
602
|
+
* every session regardless of project directory, and it runs in-session where
|
|
603
|
+
* the vendor's configured variables ARE present.
|
|
604
|
+
*
|
|
605
|
+
* Only ever on a remote surface. This writes machine state in an ephemeral
|
|
606
|
+
* container, which is fine there and would be an intrusion on a developer's
|
|
607
|
+
* laptop, where the project hook already works and the user owns that file.
|
|
608
|
+
*
|
|
609
|
+
* Merged, never clobbered, and idempotent on the exact command — an existing
|
|
610
|
+
* user settings file may carry hooks this knows nothing about.
|
|
611
|
+
* @param {string} repoRoot Absolute path to the checkout.
|
|
612
|
+
* @param {object} options Home directory, dry-run flag, and file seams.
|
|
613
|
+
* @returns {{action: string, path: string, reason?: string}} What was done.
|
|
614
|
+
*/
|
|
615
|
+
export function installUserSessionHook(repoRoot, options = {}) {
|
|
616
|
+
const {
|
|
617
|
+
home = process.env.HOME || homedir(),
|
|
618
|
+
dryRun = false,
|
|
619
|
+
exists = existsSync,
|
|
620
|
+
read = readFileSync,
|
|
621
|
+
write = writeFileSync,
|
|
622
|
+
mkdir = mkdirSync,
|
|
623
|
+
} = options;
|
|
624
|
+
|
|
625
|
+
const script = join(repoRoot, "scripts/lisa-remote-env/session-start.sh");
|
|
626
|
+
if (!exists(script)) {
|
|
627
|
+
return { action: "skipped", path: script, reason: "no session-start.sh" };
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
const dir = join(home, ".claude");
|
|
631
|
+
const settingsPath = join(dir, "settings.json");
|
|
632
|
+
const command = `bash ${script}`;
|
|
633
|
+
|
|
634
|
+
let settings = {};
|
|
635
|
+
if (exists(settingsPath)) {
|
|
636
|
+
try {
|
|
637
|
+
settings = JSON.parse(String(read(settingsPath, "utf8"))) || {};
|
|
638
|
+
} catch {
|
|
639
|
+
// Refuse rather than overwrite. A settings file that does not parse is
|
|
640
|
+
// still someone's configuration, and replacing it would be the careless
|
|
641
|
+
// destruction this whole function is written to avoid.
|
|
642
|
+
return {
|
|
643
|
+
action: "failed",
|
|
644
|
+
path: settingsPath,
|
|
645
|
+
reason: "existing settings.json is not valid JSON; left untouched",
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const hooks = settings.hooks ?? {};
|
|
651
|
+
const sessionStart = Array.isArray(hooks.SessionStart)
|
|
652
|
+
? hooks.SessionStart
|
|
653
|
+
: [];
|
|
654
|
+
const already = sessionStart.some(entry =>
|
|
655
|
+
(entry?.hooks ?? []).some(hook => hook?.command === command)
|
|
656
|
+
);
|
|
657
|
+
if (already) {
|
|
658
|
+
return { action: "present", path: settingsPath };
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
const updated = {
|
|
662
|
+
...settings,
|
|
663
|
+
hooks: {
|
|
664
|
+
...hooks,
|
|
665
|
+
SessionStart: [
|
|
666
|
+
...sessionStart,
|
|
667
|
+
{
|
|
668
|
+
matcher: "startup|resume",
|
|
669
|
+
hooks: [{ type: "command", command }],
|
|
670
|
+
},
|
|
671
|
+
],
|
|
672
|
+
},
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
if (dryRun) return { action: "would-register", path: settingsPath };
|
|
676
|
+
|
|
677
|
+
mkdir(dir, { recursive: true });
|
|
678
|
+
write(settingsPath, `${JSON.stringify(updated, null, 2)}\n`);
|
|
679
|
+
return { action: "registered", path: settingsPath };
|
|
680
|
+
}
|
|
681
|
+
|
|
586
682
|
/**
|
|
587
683
|
* The settings block that wires the session-start hook into a repository.
|
|
588
684
|
*
|
|
@@ -936,6 +1032,19 @@ async function main() {
|
|
|
936
1032
|
// codex-cloud both have no second chance, so a silent pass there would
|
|
937
1033
|
// hand back a session with no credentials and call it ready.
|
|
938
1034
|
const retried = !requested && materializesAtSessionStart(materializeAt);
|
|
1035
|
+
|
|
1036
|
+
// If the hook is what will retry, make sure the hook can actually fire.
|
|
1037
|
+
// Registering it at user scope is what makes the retry real rather than
|
|
1038
|
+
// assumed: the committed project hook does not load when the session opens
|
|
1039
|
+
// above the checkout, which is the norm in a cloud container.
|
|
1040
|
+
// `materializeAt` being set is what "remote surface" means here. The
|
|
1041
|
+
// toolchain phase derives a local `remote` from it, but that binding is
|
|
1042
|
+
// scoped to its own block and is not in scope in this one.
|
|
1043
|
+
if (retried && Boolean(materializeAt)) {
|
|
1044
|
+
const hook = installUserSessionHook(process.cwd(), { dryRun });
|
|
1045
|
+
console.log(` session-start hook: ${hook.action} (${hook.path})`);
|
|
1046
|
+
if (hook.reason) console.log(` ${hook.reason}`);
|
|
1047
|
+
}
|
|
939
1048
|
try {
|
|
940
1049
|
execFileSync(
|
|
941
1050
|
"node",
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
rmSync,
|
|
39
39
|
writeFileSync,
|
|
40
40
|
} from "node:fs";
|
|
41
|
+
import { homedir } from "node:os";
|
|
41
42
|
import { delimiter, dirname, join, resolve } from "node:path";
|
|
42
43
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
43
44
|
|
|
@@ -583,6 +584,101 @@ export const SETUP_FIELD =
|
|
|
583
584
|
'PWD=$PWD HOME=$HOME" >&2; ls -1 . "$HOME" /workspace 2>&1 | head -40 >&2; exit 1; }; ' +
|
|
584
585
|
'exit "$rc"';
|
|
585
586
|
|
|
587
|
+
/**
|
|
588
|
+
* Register the session-start hook at USER scope, so it fires wherever the
|
|
589
|
+
* session opens.
|
|
590
|
+
*
|
|
591
|
+
* The committed `.claude/settings.json` hook is *project*-scoped: it loads only
|
|
592
|
+
* when Claude Code's project directory is that repository. A cloud session does
|
|
593
|
+
* not reliably start there. With several repositories it starts in the shared
|
|
594
|
+
* parent, which is not a git repository at all; even with one, the checkout sits
|
|
595
|
+
* at `$HOME/<repo>` while the session may open at `$HOME`. In those sessions no
|
|
596
|
+
* project settings load, the hook never registers, and nothing materializes —
|
|
597
|
+
* the failure that `materializeAt: "both"` was introduced to paper over, and
|
|
598
|
+
* which it could not fix, because the setup phase cannot see the bootstrap
|
|
599
|
+
* credential in the first place.
|
|
600
|
+
*
|
|
601
|
+
* A user-scoped hook has neither problem: `~/.claude/settings.json` is read for
|
|
602
|
+
* every session regardless of project directory, and it runs in-session where
|
|
603
|
+
* the vendor's configured variables ARE present.
|
|
604
|
+
*
|
|
605
|
+
* Only ever on a remote surface. This writes machine state in an ephemeral
|
|
606
|
+
* container, which is fine there and would be an intrusion on a developer's
|
|
607
|
+
* laptop, where the project hook already works and the user owns that file.
|
|
608
|
+
*
|
|
609
|
+
* Merged, never clobbered, and idempotent on the exact command — an existing
|
|
610
|
+
* user settings file may carry hooks this knows nothing about.
|
|
611
|
+
* @param {string} repoRoot Absolute path to the checkout.
|
|
612
|
+
* @param {object} options Home directory, dry-run flag, and file seams.
|
|
613
|
+
* @returns {{action: string, path: string, reason?: string}} What was done.
|
|
614
|
+
*/
|
|
615
|
+
export function installUserSessionHook(repoRoot, options = {}) {
|
|
616
|
+
const {
|
|
617
|
+
home = process.env.HOME || homedir(),
|
|
618
|
+
dryRun = false,
|
|
619
|
+
exists = existsSync,
|
|
620
|
+
read = readFileSync,
|
|
621
|
+
write = writeFileSync,
|
|
622
|
+
mkdir = mkdirSync,
|
|
623
|
+
} = options;
|
|
624
|
+
|
|
625
|
+
const script = join(repoRoot, "scripts/lisa-remote-env/session-start.sh");
|
|
626
|
+
if (!exists(script)) {
|
|
627
|
+
return { action: "skipped", path: script, reason: "no session-start.sh" };
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
const dir = join(home, ".claude");
|
|
631
|
+
const settingsPath = join(dir, "settings.json");
|
|
632
|
+
const command = `bash ${script}`;
|
|
633
|
+
|
|
634
|
+
let settings = {};
|
|
635
|
+
if (exists(settingsPath)) {
|
|
636
|
+
try {
|
|
637
|
+
settings = JSON.parse(String(read(settingsPath, "utf8"))) || {};
|
|
638
|
+
} catch {
|
|
639
|
+
// Refuse rather than overwrite. A settings file that does not parse is
|
|
640
|
+
// still someone's configuration, and replacing it would be the careless
|
|
641
|
+
// destruction this whole function is written to avoid.
|
|
642
|
+
return {
|
|
643
|
+
action: "failed",
|
|
644
|
+
path: settingsPath,
|
|
645
|
+
reason: "existing settings.json is not valid JSON; left untouched",
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const hooks = settings.hooks ?? {};
|
|
651
|
+
const sessionStart = Array.isArray(hooks.SessionStart)
|
|
652
|
+
? hooks.SessionStart
|
|
653
|
+
: [];
|
|
654
|
+
const already = sessionStart.some(entry =>
|
|
655
|
+
(entry?.hooks ?? []).some(hook => hook?.command === command)
|
|
656
|
+
);
|
|
657
|
+
if (already) {
|
|
658
|
+
return { action: "present", path: settingsPath };
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
const updated = {
|
|
662
|
+
...settings,
|
|
663
|
+
hooks: {
|
|
664
|
+
...hooks,
|
|
665
|
+
SessionStart: [
|
|
666
|
+
...sessionStart,
|
|
667
|
+
{
|
|
668
|
+
matcher: "startup|resume",
|
|
669
|
+
hooks: [{ type: "command", command }],
|
|
670
|
+
},
|
|
671
|
+
],
|
|
672
|
+
},
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
if (dryRun) return { action: "would-register", path: settingsPath };
|
|
676
|
+
|
|
677
|
+
mkdir(dir, { recursive: true });
|
|
678
|
+
write(settingsPath, `${JSON.stringify(updated, null, 2)}\n`);
|
|
679
|
+
return { action: "registered", path: settingsPath };
|
|
680
|
+
}
|
|
681
|
+
|
|
586
682
|
/**
|
|
587
683
|
* The settings block that wires the session-start hook into a repository.
|
|
588
684
|
*
|
|
@@ -936,6 +1032,19 @@ async function main() {
|
|
|
936
1032
|
// codex-cloud both have no second chance, so a silent pass there would
|
|
937
1033
|
// hand back a session with no credentials and call it ready.
|
|
938
1034
|
const retried = !requested && materializesAtSessionStart(materializeAt);
|
|
1035
|
+
|
|
1036
|
+
// If the hook is what will retry, make sure the hook can actually fire.
|
|
1037
|
+
// Registering it at user scope is what makes the retry real rather than
|
|
1038
|
+
// assumed: the committed project hook does not load when the session opens
|
|
1039
|
+
// above the checkout, which is the norm in a cloud container.
|
|
1040
|
+
// `materializeAt` being set is what "remote surface" means here. The
|
|
1041
|
+
// toolchain phase derives a local `remote` from it, but that binding is
|
|
1042
|
+
// scoped to its own block and is not in scope in this one.
|
|
1043
|
+
if (retried && Boolean(materializeAt)) {
|
|
1044
|
+
const hook = installUserSessionHook(process.cwd(), { dryRun });
|
|
1045
|
+
console.log(` session-start hook: ${hook.action} (${hook.path})`);
|
|
1046
|
+
if (hook.reason) console.log(` ${hook.reason}`);
|
|
1047
|
+
}
|
|
939
1048
|
try {
|
|
940
1049
|
execFileSync(
|
|
941
1050
|
"node",
|