@ectplsm/relic 0.3.1 → 0.3.2

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.
@@ -36,11 +36,12 @@ export class ClaudeShell {
36
36
  console.log("Hook registered to ~/.claude/settings.json");
37
37
  console.log();
38
38
  }
39
- const args = [
40
- "--system-prompt",
41
- prompt,
42
- ...(options?.extraArgs ?? []),
43
- ];
39
+ const args = [];
40
+ // resume 系操作時は injection をスキップ(前回セッションに焼き付き済み)
41
+ if (!options?.skipInjection) {
42
+ args.push("--system-prompt", prompt);
43
+ }
44
+ args.push(...(options?.extraArgs ?? []));
44
45
  const env = {};
45
46
  if (options?.engramId)
46
47
  env.RELIC_ENGRAM_ID = options.engramId;
@@ -38,11 +38,12 @@ export class CodexShell {
38
38
  console.log("Hook registered to ~/.codex/hooks.json");
39
39
  console.log();
40
40
  }
41
- const args = [
42
- "-c", `developer_instructions=${JSON.stringify(wrapWithOverride(prompt))}`,
43
- "-c", "features.codex_hooks=true",
44
- ...(options?.extraArgs ?? []),
45
- ];
41
+ const args = [];
42
+ // resume 系操作時は injection をスキップ(前回セッションに焼き付き済み)
43
+ if (!options?.skipInjection) {
44
+ args.push("-c", `developer_instructions=${JSON.stringify(wrapWithOverride(prompt))}`);
45
+ }
46
+ args.push("-c", "features.codex_hooks=true", ...(options?.extraArgs ?? []));
46
47
  const env = {};
47
48
  if (options?.engramId)
48
49
  env.RELIC_ENGRAM_ID = options.engramId;
@@ -106,6 +106,14 @@ export class GeminiShell {
106
106
  console.log("Hook registered to ~/.gemini/settings.json");
107
107
  console.log();
108
108
  }
109
+ // resume 系操作時は injection をスキップ(前回セッションに焼き付き済み)
110
+ if (options?.skipInjection) {
111
+ const env = {};
112
+ if (options?.engramId)
113
+ env.RELIC_ENGRAM_ID = options.engramId;
114
+ await spawnShell(this.command, [...(options?.extraArgs ?? [])], options?.cwd, Object.keys(env).length > 0 ? env : undefined);
115
+ return;
116
+ }
109
117
  // 2. デフォルトシステムプロンプトをキャッシュから読む、なければキャプチャ
110
118
  let defaultPrompt;
111
119
  if (existsSync(GEMINI_DEFAULT_CACHE)) {
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Resume Detection — Shell の extraArgs から resume 系操作を検出する
3
+ *
4
+ * resume 時は Engram injection をスキップし、Shell をそのまま起動する。
5
+ * 各 CLI の resume 引数仕様:
6
+ * - Claude: --resume, -r, --continue, -c, --from-pr (options)
7
+ * - Codex: resume, fork (subcommands)
8
+ * - Gemini: --resume, -r (options)
9
+ *
10
+ * 注意: Claude の -c は --continue の短縮。Codex の -c は --config の短縮。
11
+ */
12
+ /**
13
+ * extraArgs が resume 系の操作を含むかを判定する。
14
+ *
15
+ * @param shellName - Shell の表示名 ("Claude Code", "Codex CLI", "Gemini CLI")
16
+ * @param extraArgs - Shell に渡される追加引数
17
+ * @returns resume 系操作が検出された場合 true
18
+ */
19
+ export declare function isResumeArgs(shellName: string, extraArgs: string[]): boolean;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Resume Detection — Shell の extraArgs から resume 系操作を検出する
3
+ *
4
+ * resume 時は Engram injection をスキップし、Shell をそのまま起動する。
5
+ * 各 CLI の resume 引数仕様:
6
+ * - Claude: --resume, -r, --continue, -c, --from-pr (options)
7
+ * - Codex: resume, fork (subcommands)
8
+ * - Gemini: --resume, -r (options)
9
+ *
10
+ * 注意: Claude の -c は --continue の短縮。Codex の -c は --config の短縮。
11
+ */
12
+ /** Claude Code の resume 系オプション */
13
+ const CLAUDE_RESUME_FLAGS = new Set([
14
+ "--resume",
15
+ "-r",
16
+ "--continue",
17
+ "-c",
18
+ "--from-pr",
19
+ ]);
20
+ /** Gemini CLI の resume 系オプション */
21
+ const GEMINI_RESUME_FLAGS = new Set([
22
+ "--resume",
23
+ "-r",
24
+ ]);
25
+ /** Codex CLI の resume 系サブコマンド */
26
+ const CODEX_RESUME_SUBCOMMANDS = new Set([
27
+ "resume",
28
+ "fork",
29
+ ]);
30
+ /**
31
+ * extraArgs が resume 系の操作を含むかを判定する。
32
+ *
33
+ * @param shellName - Shell の表示名 ("Claude Code", "Codex CLI", "Gemini CLI")
34
+ * @param extraArgs - Shell に渡される追加引数
35
+ * @returns resume 系操作が検出された場合 true
36
+ */
37
+ export function isResumeArgs(shellName, extraArgs) {
38
+ if (extraArgs.length === 0)
39
+ return false;
40
+ switch (shellName) {
41
+ case "Claude Code":
42
+ return extraArgs.some((arg) => CLAUDE_RESUME_FLAGS.has(arg));
43
+ case "Codex CLI":
44
+ // Codex は resume/fork がサブコマンド(先頭引数)
45
+ return CODEX_RESUME_SUBCOMMANDS.has(extraArgs[0]);
46
+ case "Gemini CLI":
47
+ return extraArgs.some((arg) => GEMINI_RESUME_FLAGS.has(arg));
48
+ default:
49
+ return false;
50
+ }
51
+ }
@@ -17,6 +17,12 @@ export interface ShellLaunchOptions {
17
17
  cwd?: string;
18
18
  /** 注入するEngram ID(Shell固有のセットアップに使用) */
19
19
  engramId?: string;
20
+ /**
21
+ * true の場合、Engram prompt の injection をスキップする。
22
+ * resume 系操作では前回セッションに injection 済みのため再注入は不要。
23
+ * hook セットアップと RELIC_ENGRAM_ID は skipInjection 時も維持される。
24
+ */
25
+ skipInjection?: boolean;
20
26
  }
21
27
  /**
22
28
  * ShellLauncher — AI CLIにEngramを注入して起動する抽象ポート
@@ -5,6 +5,7 @@ import { resolveEngramsPath, resolveDefaultEngram, resolveMemoryWindowSize, reso
5
5
  import { ClaudeShell } from "../../../adapters/shells/claude-shell.js";
6
6
  import { GeminiShell } from "../../../adapters/shells/gemini-shell.js";
7
7
  import { CodexShell } from "../../../adapters/shells/codex-shell.js";
8
+ import { isResumeArgs } from "../../../adapters/shells/resume-detect.js";
8
9
  const SHELLS = [
9
10
  {
10
11
  name: "claude",
@@ -31,6 +32,7 @@ export function registerShellCommands(program) {
31
32
  .option("-p, --path <dir>", "Override engrams directory path")
32
33
  .option("--cwd <dir>", "Working directory for the Shell (default: current directory)")
33
34
  .allowUnknownOption(true)
35
+ .allowExcessArguments(true)
34
36
  .action(async (opts, cmd) => {
35
37
  const launcher = shell.create();
36
38
  // Shell利用可能チェック
@@ -56,12 +58,24 @@ export function registerShellCommands(program) {
56
58
  memoryWindowSize,
57
59
  distillationBatchSize,
58
60
  });
59
- console.log(`Summoning "${result.engramName}" into ${launcher.name}...`);
60
- console.log();
61
61
  // --engram, --path, --cwd 以外の引数をShellにパススルー
62
62
  const extraArgs = cmd.args;
63
63
  const cwd = opts.cwd ? resolve(opts.cwd) : process.cwd();
64
- await launcher.launch(result.prompt, { extraArgs, cwd, engramId });
64
+ // resume 系操作の検出
65
+ const skipInjection = isResumeArgs(launcher.name, extraArgs);
66
+ if (skipInjection) {
67
+ console.log(`Resuming ${launcher.name} session (${result.engramName})...`);
68
+ }
69
+ else {
70
+ console.log(`Summoning "${result.engramName}" into ${launcher.name}...`);
71
+ }
72
+ console.log();
73
+ await launcher.launch(result.prompt, {
74
+ extraArgs,
75
+ cwd,
76
+ engramId,
77
+ skipInjection,
78
+ });
65
79
  }
66
80
  catch (err) {
67
81
  if (err instanceof EngramNotFoundError) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ectplsm/relic",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "PROJECT RELIC — Engram injection system for AI constructs",
5
5
  "license": "MIT",
6
6
  "repository": {