@link-assistant/hive-mind 1.75.0 → 1.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @link-assistant/hive-mind
2
2
 
3
+ ## 1.76.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 80c56fa: Add experimental `--use-handoff` HANDOFF.md continuity **Agent Skill** (issue
8
+ #1877). When enabled, Hive Mind deploys a real `SKILL.md` (the Agent Skills open
9
+ standard created by Anthropic) into the session working directory for both tools
10
+ natively — `.claude/skills/handoff/SKILL.md` for `--tool claude` and
11
+ `.agents/skills/handoff/SKILL.md` for `--tool codex` — so the very same skill
12
+ teaches each tool to read `HANDOFF.md` (repository root) first when present and
13
+ keep it updated with task, current state, decisions, next steps, gotchas, and
14
+ critical files. A minimal activation nudge in the system prompt ensures the
15
+ read-at-session-start behavior fires reliably. Because each Hive Mind working
16
+ session runs in an ephemeral working directory cloned from the PR branch, the
17
+ handoff file is committed to the branch — making it the shared cross-session,
18
+ cross-tool memory so Claude and Codex can continue each other's work in a single
19
+ pull request. The deployed `SKILL.md` is tooling (re-deployed every session) and
20
+ is kept out of the target repository via `.git/info/exclude`, so it never appears
21
+ in the PR. Disabled by default; auto-forwarded by `hive`. Includes a case study
22
+ in `docs/case-studies/issue-1877/` and tests in `tests/handoff-prompt.test.mjs`.
23
+
3
24
  ## 1.75.0
4
25
 
5
26
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@link-assistant/hive-mind",
3
- "version": "1.75.0",
3
+ "version": "1.76.0",
4
4
  "description": "AI-powered issue solver and hive mind for collaborative problem solving",
5
5
  "main": "src/hive.mjs",
6
6
  "type": "module",
@@ -28,6 +28,7 @@ import { fetchModelInfo } from './model-info.lib.mjs';
28
28
  import { classifyRetryableError, maybeSwitchToFallbackModel, waitWithCountdown } from './tool-retry.lib.mjs';
29
29
  import { resolveSubSessionSize } from './sub-session-size.lib.mjs'; // Issue #1706
30
30
  import { withAgentsMdAsClaudeMd } from './agents-md-claude-support.lib.mjs';
31
+ import { deployHandoffSkill } from './handoff-skill.lib.mjs'; // Issue #1877
31
32
  import { createThinkingBlockRecovery } from './claude.thinking-block-recovery.lib.mjs'; // Issue #1834 (PR #1835 feedback)
32
33
  export { availableModels, fetchModelInfo }; // Re-export for backward compatibility
33
34
  const showResumeCommand = async (sessionId, tempDir, claudePath, model, log, argv = null) => {
@@ -353,6 +354,10 @@ export const executeClaude = async params => {
353
354
  const escapedPrompt = prompt.replace(/"/g, '\\"').replace(/\$/g, '\\$');
354
355
  const escapedSystemPrompt = systemPrompt.replace(/"/g, '\\"').replace(/\$/g, '\\$');
355
356
 
357
+ // Issue #1877: deploy the experimental HANDOFF.md Agent Skill so Claude loads
358
+ // it natively from .claude/skills/handoff/SKILL.md (no-op unless --use-handoff).
359
+ await deployHandoffSkill({ tempDir, argv, log, $ });
360
+
356
361
  return await withAgentsMdAsClaudeMd({ tempDir, branchName, argv, prompt, fs, path, $, log, formatAligned }, () =>
357
362
  executeClaudeCommand({
358
363
  tempDir,
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import { getArchitectureCareSubPrompt } from './architecture-care.prompts.lib.mjs';
7
+ import { getHandoffSubPrompt } from './handoff.prompts.lib.mjs';
7
8
  import { getExperimentsExamplesSubPrompt } from './experiments-examples.prompts.lib.mjs';
8
9
  import { primaryModelNames } from './models/index.mjs';
9
10
  import { getThinkingPromptInstruction } from './thinking-prompt.lib.mjs';
@@ -338,7 +339,7 @@ Visual UI work and screenshots.
338
339
  - When the fix is visual, include side-by-side or sequential comparison of before/after states in the PR description.
339
340
  - When possible, create automated visual regression tests to prevent the UI bug from recurring.`
340
341
  : ''
341
- }${ciExamples}${getArchitectureCareSubPrompt(argv)}${buildWorkLanguageDirective()}`;
342
+ }${ciExamples}${getArchitectureCareSubPrompt(argv)}${getHandoffSubPrompt(argv)}${buildWorkLanguageDirective()}`;
342
343
  };
343
344
 
344
345
  // Export all functions as default object too
package/src/codex.lib.mjs CHANGED
@@ -29,6 +29,7 @@ import { defaultModels } from './models/index.mjs';
29
29
  import { classifyRetryableError, getRetryDelayMs, maybeSwitchToFallbackModel, waitWithCountdown } from './tool-retry.lib.mjs';
30
30
  import { parseSubSessionSize, buildCodexSubSessionSizeConfigArgs, buildCodexDisable1mContextConfigArgs } from './sub-session-size.lib.mjs'; // Issue #1706
31
31
  import { getCumulativeContextInputTokens } from './context-fill.lib.mjs';
32
+ import { deployHandoffSkill } from './handoff-skill.lib.mjs'; // Issue #1877
32
33
  import Decimal from 'decimal.js-light';
33
34
 
34
35
  const CODEX_USAGE_FIELD_NAMES = ['input_tokens', 'cached_input_tokens', 'output_tokens', 'cache_write_tokens', 'cache_creation_input_tokens', 'reasoning_tokens', 'input_tokens_details.cached_tokens', 'input_tokens_details.cache_read_tokens', 'input_tokens_details.cache_write_tokens', 'input_tokens_details.cache_creation_tokens', 'input_tokens_details.cache_creation_input_tokens', 'output_tokens_details.reasoning_tokens'];
@@ -661,6 +662,10 @@ export const executeCodex = async params => {
661
662
  }
662
663
  }
663
664
 
665
+ // Issue #1877: deploy the experimental HANDOFF.md Agent Skill so Codex loads
666
+ // it natively from .agents/skills/handoff/SKILL.md (no-op unless --use-handoff).
667
+ await deployHandoffSkill({ tempDir, argv, log, $ });
668
+
664
669
  // Execute the Codex command
665
670
  return await executeCodexCommand({
666
671
  tempDir,
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import { getArchitectureCareSubPrompt } from './architecture-care.prompts.lib.mjs';
7
+ import { getHandoffSubPrompt } from './handoff.prompts.lib.mjs';
7
8
  import { getExperimentsExamplesSubPrompt } from './experiments-examples.prompts.lib.mjs';
8
9
  import { getThinkingPromptInstruction } from './thinking-prompt.lib.mjs';
9
10
  import { buildWorkLanguageDirective } from './work-language.prompts.lib.mjs';
@@ -306,7 +307,7 @@ Visual UI work and screenshots.
306
307
  - When the fix is visual, include side-by-side or sequential comparison of before/after states in the PR description.
307
308
  - When possible, create automated visual regression tests to prevent the UI bug from recurring.`
308
309
  : ''
309
- }${ciExamples}${getArchitectureCareSubPrompt(argv)}${buildWorkLanguageDirective()}`;
310
+ }${ciExamples}${getArchitectureCareSubPrompt(argv)}${getHandoffSubPrompt(argv)}${buildWorkLanguageDirective()}`;
310
311
  };
311
312
 
312
313
  // Export all functions as default object too
@@ -0,0 +1,256 @@
1
+ /**
2
+ * HANDOFF.md Agent Skill deployment (issue #1877)
3
+ *
4
+ * Writes the canonical handoff `SKILL.md` (built by handoff.prompts.lib.mjs)
5
+ * into the session working directory so the AI tool loads it natively as an
6
+ * Agent Skill, instead of relying on an injected prompt.
7
+ *
8
+ * Both supported tools read the Agent Skills standard, but from different
9
+ * hardcoded project directories (neither tool exposes a setting or env var to
10
+ * point at a custom/shared folder):
11
+ * - Claude Code: .claude/skills/<name>/SKILL.md
12
+ * - Codex: .agents/skills/<name>/SKILL.md
13
+ *
14
+ * To answer "can both CLIs use the SAME folder?": there is no native shared
15
+ * location, so we make one ourselves. The SKILL.md is written exactly ONCE into
16
+ * a single real directory (the Claude path, `.claude/skills/handoff/`), and the
17
+ * Codex path (`.agents/skills/handoff`) is a relative **symlink** pointing at
18
+ * that one real directory. Both tools therefore read byte-for-byte the same
19
+ * file from a single source of truth on disk — not two copies that could drift.
20
+ * If the filesystem cannot create a symlink (e.g. Windows without privilege),
21
+ * we fall back to writing a real second copy so the feature still works.
22
+ *
23
+ * The deployed skill is tool configuration, not project state, so it is:
24
+ * - re-deployed every session by hive-mind (each session clones fresh), and
25
+ * - excluded from git via `.git/info/exclude` (a local, never-committed
26
+ * ignore) so it never pollutes the pull request or the "uncommitted
27
+ * changes" checks. Only the HANDOFF.md the tool produces is committed.
28
+ */
29
+
30
+ // Fetch use-m if not available (matches the rest of src/*.lib.mjs).
31
+ if (typeof globalThis.use === 'undefined') {
32
+ globalThis.use = (await eval(await (await fetch('https://unpkg.com/use-m/use.js')).text())).use;
33
+ }
34
+ const fs = (await use('fs')).promises;
35
+ const path = (await use('path')).default;
36
+
37
+ import { buildHandoffSkillFile, HANDOFF_SKILL_NAME } from './handoff.prompts.lib.mjs';
38
+
39
+ const noopLog = async () => {};
40
+
41
+ const SKILL_FILE = 'SKILL.md';
42
+
43
+ /**
44
+ * The single real skill directory the SKILL.md is written into. Claude Code
45
+ * reads it directly; Codex reaches the same files through a symlink (below).
46
+ * @type {string}
47
+ */
48
+ export const HANDOFF_PRIMARY_SKILL_DIR = path.join('.claude', 'skills', HANDOFF_SKILL_NAME);
49
+
50
+ /**
51
+ * Additional skill directories that should resolve to the same SKILL.md. Each
52
+ * is created as a symlink to HANDOFF_PRIMARY_SKILL_DIR (one source of truth),
53
+ * falling back to a real copy only if symlinking is unsupported.
54
+ * @type {string[]}
55
+ */
56
+ export const HANDOFF_LINKED_SKILL_DIRS = Object.freeze([
57
+ path.join('.agents', 'skills', HANDOFF_SKILL_NAME), // Codex
58
+ ]);
59
+
60
+ /**
61
+ * All skill directories the deployment touches (primary + links). Kept for the
62
+ * git-exclude bookkeeping and for callers/tests that enumerate every location.
63
+ * @type {string[]}
64
+ */
65
+ export const HANDOFF_SKILL_DIRS = Object.freeze([HANDOFF_PRIMARY_SKILL_DIR, ...HANDOFF_LINKED_SKILL_DIRS]);
66
+
67
+ /**
68
+ * Determine whether a path is already tracked by git in the working dir. We
69
+ * never clobber a file/dir the target repository tracks itself.
70
+ */
71
+ const isTracked = async ({ $, tempDir, relPath }) => {
72
+ if (!$) return false;
73
+ try {
74
+ const result = await $({ cwd: tempDir })`git ls-files --error-unmatch ${relPath} 2>/dev/null`;
75
+ return result.code === 0;
76
+ } catch {
77
+ return false;
78
+ }
79
+ };
80
+
81
+ /**
82
+ * Resolve the local git exclude file (`.git/info/exclude`), honoring worktrees
83
+ * via `git rev-parse --git-path`. Falls back to the conventional location.
84
+ */
85
+ const resolveExcludePath = async ({ $, tempDir }) => {
86
+ if ($) {
87
+ try {
88
+ const result = await $({ cwd: tempDir })`git rev-parse --git-path info/exclude 2>/dev/null`;
89
+ const rel = (result.stdout || '').toString().trim();
90
+ if (result.code === 0 && rel) {
91
+ return path.isAbsolute(rel) ? rel : path.join(tempDir, rel);
92
+ }
93
+ } catch {
94
+ // fall through to default
95
+ }
96
+ }
97
+ return path.join(tempDir, '.git', 'info', 'exclude');
98
+ };
99
+
100
+ /**
101
+ * Append the skill directories to `.git/info/exclude` (idempotent) so the
102
+ * deployed SKILL.md files (real dir and symlink alike) stay invisible to git.
103
+ * Entries are written WITHOUT a trailing slash so they match both a real
104
+ * directory and a directory symlink (git would not match a symlink against a
105
+ * `dir/` pattern).
106
+ */
107
+ const updateGitExclude = async ({ $, tempDir, log }) => {
108
+ const excludePath = await resolveExcludePath({ $, tempDir });
109
+ // Only touch the exclude file if its parent (.git/info) exists — i.e. this is
110
+ // a real git working dir. Avoid creating a stray `.git/` in non-git dirs.
111
+ try {
112
+ await fs.access(path.dirname(excludePath));
113
+ } catch {
114
+ await log(' Handoff skill: no .git/info directory; skipping git-exclude update', { verbose: true });
115
+ return false;
116
+ }
117
+
118
+ let existing = '';
119
+ try {
120
+ existing = await fs.readFile(excludePath, 'utf8');
121
+ } catch {
122
+ existing = '';
123
+ }
124
+
125
+ const entries = HANDOFF_SKILL_DIRS.map(dir => `/${dir.split(path.sep).join('/')}`);
126
+ const existingLines = existing.split(/\r?\n/);
127
+ const missing = entries.filter(entry => !existingLines.includes(entry));
128
+ if (missing.length === 0) return true;
129
+
130
+ const header = '# hive-mind --use-handoff: experimental HANDOFF.md Agent Skill (issue #1877)';
131
+ const prefix = existing.length > 0 && !existing.endsWith('\n') ? '\n' : '';
132
+ const block = `${prefix}${existing.includes(header) ? '' : header + '\n'}${missing.join('\n')}\n`;
133
+ await fs.writeFile(excludePath, existing + block, 'utf8');
134
+ return true;
135
+ };
136
+
137
+ /**
138
+ * Write the real SKILL.md into the primary skill directory.
139
+ */
140
+ const writeRealSkill = async ({ tempDir, content }) => {
141
+ const absDir = path.join(tempDir, HANDOFF_PRIMARY_SKILL_DIR);
142
+ await fs.mkdir(absDir, { recursive: true });
143
+ await fs.writeFile(path.join(absDir, SKILL_FILE), content, 'utf8');
144
+ return absDir;
145
+ };
146
+
147
+ /**
148
+ * Make `relLinkDir` resolve to the same files as the primary skill directory.
149
+ * Prefers a relative symlink (single source of truth); if symlinking is not
150
+ * supported, falls back to writing a real copy of the SKILL.md.
151
+ *
152
+ * @returns {Promise<'symlink'|'copy'>}
153
+ */
154
+ const linkOrCopySkill = async ({ tempDir, relLinkDir, primaryAbsDir, content }) => {
155
+ const absLinkDir = path.join(tempDir, relLinkDir);
156
+ const parent = path.dirname(absLinkDir);
157
+ await fs.mkdir(parent, { recursive: true });
158
+ const relTarget = path.relative(parent, primaryAbsDir);
159
+
160
+ // Reconcile any pre-existing entry (e.g. from a prior session re-deploy).
161
+ try {
162
+ const st = await fs.lstat(absLinkDir);
163
+ if (st.isSymbolicLink()) {
164
+ const current = await fs.readlink(absLinkDir);
165
+ if (current === relTarget) return 'symlink'; // already correct
166
+ await fs.rm(absLinkDir, { recursive: true, force: true });
167
+ } else if (st.isDirectory()) {
168
+ // A real directory is already there (prior copy fallback). Refresh the
169
+ // copy in place rather than replacing the directory.
170
+ await fs.writeFile(path.join(absLinkDir, SKILL_FILE), content, 'utf8');
171
+ return 'copy';
172
+ } else {
173
+ await fs.rm(absLinkDir, { force: true });
174
+ }
175
+ } catch {
176
+ // Nothing there yet — fall through and create it.
177
+ }
178
+
179
+ try {
180
+ await fs.symlink(relTarget, absLinkDir, 'dir');
181
+ return 'symlink';
182
+ } catch {
183
+ await fs.mkdir(absLinkDir, { recursive: true });
184
+ await fs.writeFile(path.join(absLinkDir, SKILL_FILE), content, 'utf8');
185
+ return 'copy';
186
+ }
187
+ };
188
+
189
+ /**
190
+ * Deploy the handoff SKILL.md into the session working directory.
191
+ *
192
+ * @param {Object} params
193
+ * @param {string} params.tempDir - The repo working directory.
194
+ * @param {Object} params.argv - Parsed CLI args (uses argv.useHandoff).
195
+ * @param {Function} [params.log] - Logger.
196
+ * @param {Function} [params.$] - Command runner (for git checks); optional.
197
+ * @returns {Promise<{deployed: boolean, reason?: string, paths: string[], shared: boolean}>}
198
+ */
199
+ export const deployHandoffSkill = async ({ tempDir, argv, log = noopLog, $ = null } = {}) => {
200
+ if (!argv || !argv.useHandoff) {
201
+ return { deployed: false, reason: 'disabled', paths: [], shared: false };
202
+ }
203
+ if (!tempDir) {
204
+ return { deployed: false, reason: 'no-temp-dir', paths: [], shared: false };
205
+ }
206
+
207
+ const content = buildHandoffSkillFile();
208
+ const written = [];
209
+ let allShared = true;
210
+
211
+ // 1. Write the single real SKILL.md (unless the repo tracks it itself).
212
+ const primaryRelFile = path.join(HANDOFF_PRIMARY_SKILL_DIR, SKILL_FILE);
213
+ let primaryAbsDir = path.join(tempDir, HANDOFF_PRIMARY_SKILL_DIR);
214
+ if (await isTracked({ $, tempDir, relPath: primaryRelFile })) {
215
+ await log(` Handoff skill: ${primaryRelFile} is tracked by the repo; leaving it untouched`, { verbose: true });
216
+ } else {
217
+ try {
218
+ primaryAbsDir = await writeRealSkill({ tempDir, content });
219
+ written.push(primaryRelFile);
220
+ } catch (error) {
221
+ await log(` Handoff skill: failed to deploy ${primaryRelFile}: ${error.message}`, { verbose: true });
222
+ return { deployed: false, reason: 'write-failed', paths: [], shared: false };
223
+ }
224
+ }
225
+
226
+ // 2. Point every other tool's skill dir at that same real directory.
227
+ for (const relLinkDir of HANDOFF_LINKED_SKILL_DIRS) {
228
+ const relFile = path.join(relLinkDir, SKILL_FILE);
229
+ if (await isTracked({ $, tempDir, relPath: relFile })) {
230
+ await log(` Handoff skill: ${relFile} is tracked by the repo; leaving it untouched`, { verbose: true });
231
+ continue;
232
+ }
233
+ try {
234
+ const mode = await linkOrCopySkill({ tempDir, relLinkDir, primaryAbsDir, content });
235
+ if (mode !== 'symlink') allShared = false;
236
+ written.push(relFile);
237
+ } catch (error) {
238
+ await log(` Handoff skill: failed to link ${relFile}: ${error.message}`, { verbose: true });
239
+ }
240
+ }
241
+
242
+ if (written.length > 0) {
243
+ await updateGitExclude({ $, tempDir, log });
244
+ const how = allShared ? 'one shared folder via symlink' : 'copied (symlink unsupported)';
245
+ await log(` Handoff skill deployed (--use-handoff, ${how}): ${written.join(', ')}`, { verbose: true });
246
+ }
247
+
248
+ return { deployed: written.length > 0, paths: written, shared: allShared };
249
+ };
250
+
251
+ export default {
252
+ HANDOFF_PRIMARY_SKILL_DIR,
253
+ HANDOFF_LINKED_SKILL_DIRS,
254
+ HANDOFF_SKILL_DIRS,
255
+ deployHandoffSkill,
256
+ };
@@ -0,0 +1,158 @@
1
+ /**
2
+ * HANDOFF.md support — Agent Skill (issue #1877)
3
+ *
4
+ * Instead of injecting a bespoke sub-prompt, this module ships a real
5
+ * **Agent Skill** (https://agentskills.io) — a `SKILL.md` document with YAML
6
+ * frontmatter — that teaches the AI tool to read and maintain a HANDOFF.md file
7
+ * in the repository root. The Agent Skills format is an open standard (created
8
+ * by Anthropic) that BOTH supported tools load natively:
9
+ * - Claude Code discovers project skills from `.claude/skills/<name>/SKILL.md`.
10
+ * - Codex discovers project skills from `.agents/skills/<name>/SKILL.md`.
11
+ * The exact same `SKILL.md` works for both, so "same skill, same way" is
12
+ * satisfied by a single canonical file rather than a tool-specific prompt.
13
+ * Because neither tool lets you redirect its skills folder, the deployment
14
+ * writes that file ONCE and symlinks the second tool's path to it, so both
15
+ * tools literally read the same folder (see handoff-skill.lib.mjs).
16
+ *
17
+ * The skill is deployed into the session working directory by
18
+ * `handoff-skill.lib.mjs` (gated behind the experimental --use-handoff flag).
19
+ * This module only builds the canonical text; the deployment module writes it.
20
+ *
21
+ * Goal: cross-session AND cross-tool continuity — a session driven by one tool
22
+ * (e.g. Claude) can be continued by another tool (e.g. Codex) inside the same
23
+ * pull request, because the HANDOFF.md state travels with the branch.
24
+ *
25
+ * Design rationale specific to hive-mind:
26
+ * - Each working session runs in an ephemeral temp working directory that is
27
+ * cloned fresh from the pull request branch. The ONLY state that persists
28
+ * between sessions (and between different tools) is what is committed to the
29
+ * branch. Therefore, unlike the general "disposable temp-dir handoff"
30
+ * convention, the handoff file here MUST be committed to the PR branch so
31
+ * the next session/tool can read it. We keep a single active HANDOFF.md per
32
+ * branch to avoid ambiguity.
33
+ * - The skill file itself (SKILL.md) is tool configuration, not project state,
34
+ * so it is re-deployed each session by hive-mind and is NOT committed to the
35
+ * target repository (see handoff-skill.lib.mjs).
36
+ */
37
+
38
+ /**
39
+ * The default handoff file name (repository root, relative path).
40
+ * @type {string}
41
+ */
42
+ export const HANDOFF_FILE_NAME = 'HANDOFF.md';
43
+
44
+ /**
45
+ * The skill directory / invocation name (Agent Skills standard).
46
+ * @type {string}
47
+ */
48
+ export const HANDOFF_SKILL_NAME = 'handoff';
49
+
50
+ /**
51
+ * The skill description used in the SKILL.md frontmatter. Front-loads the key
52
+ * use case and trigger words so the tool can match the skill implicitly.
53
+ * @type {string}
54
+ */
55
+ export const HANDOFF_SKILL_DESCRIPTION = "Maintain a HANDOFF.md continuity document in the repository root so any session can continue a previous session's work — even across different AI tools (Claude and Codex) in the same pull request. Use when starting, resuming, or finishing work on a long-running task, issue, or pull request.";
56
+
57
+ /**
58
+ * Build the canonical handoff skill instructions (the markdown body that follows
59
+ * the YAML frontmatter in SKILL.md). This is tool-agnostic and identical for
60
+ * Claude and Codex.
61
+ *
62
+ * @param {Object} [options]
63
+ * @param {string} [options.fileName=HANDOFF_FILE_NAME] - Handoff file name.
64
+ * @returns {string} The markdown instructions body.
65
+ */
66
+ export const buildHandoffSkillBody = ({ fileName = HANDOFF_FILE_NAME } = {}) => {
67
+ return `# HANDOFF.md continuity skill
68
+
69
+ ${fileName} is a single shared handoff document in the repository root that lets any session continue the work of any previous session, even when a different AI tool (for example Claude and Codex) is used. It travels with the pull request branch, so it is the cross-tool, cross-session memory for this PR.
70
+
71
+ ## When to use this skill
72
+
73
+ - When you start a working session, read ${fileName} first if it exists. Treat its "Next steps" section as your immediate starting point and honor the decisions and constraints it records before exploring anything else.
74
+ - When ${fileName} does not exist yet and the task is non-trivial, create it early so an interrupted session can always be resumed.
75
+ - When you make meaningful progress, update ${fileName} so it always reflects the current truth. Keep exactly one active ${fileName} per pull request branch (do not create per-session copies).
76
+ - When all requirements are fully met and the work is complete, record that completion at the top of ${fileName} (or delete the file) so the next session knows there is nothing left to continue.
77
+
78
+ ## How to write ${fileName}
79
+
80
+ - Keep it concise and tool-agnostic: describe state by referencing file paths, function names, branch, and commit SHAs rather than tool-specific commands, so the next tool (Claude or Codex) can act on it directly. Prefer pointers to existing artifacts over duplicating their content.
81
+ - Include these sections:
82
+ 1. **Task** — the issue/PR being solved and the goal.
83
+ 2. **Current state** — what is done and verified.
84
+ 3. **Decisions** — key choices made and why (so they are not re-litigated).
85
+ 4. **Next steps** — the concrete, ordered actions the next session should take.
86
+ 5. **Gotchas** — known pitfalls, failing checks, or constraints.
87
+ 6. **Critical files** — the important paths and what each is for.
88
+ - When you record next steps, make them specific and actionable (a path, a function, a command to run) instead of vague goals, and remove items as they are completed.
89
+
90
+ ## Committing and safety
91
+
92
+ - When you finish a step that changes the state, commit ${fileName} together with the related code changes so the handoff stays in sync with the branch and is never lost if the session is interrupted.
93
+ - Never include secrets, tokens, API keys, passwords, or personal data in ${fileName} — it is committed to the repository.`;
94
+ };
95
+
96
+ /**
97
+ * Build a complete SKILL.md document (Agent Skills standard): YAML frontmatter
98
+ * with `name` and `description`, followed by the instructions body. This exact
99
+ * file is deployed verbatim for both Claude (.claude/skills/handoff/SKILL.md)
100
+ * and Codex (.agents/skills/handoff/SKILL.md).
101
+ *
102
+ * @param {Object} [options]
103
+ * @param {string} [options.fileName=HANDOFF_FILE_NAME] - Handoff file name.
104
+ * @param {string} [options.name=HANDOFF_SKILL_NAME] - Skill name (frontmatter).
105
+ * @param {string} [options.description=HANDOFF_SKILL_DESCRIPTION] - Skill description.
106
+ * @returns {string} The full SKILL.md content.
107
+ */
108
+ export const buildHandoffSkillFile = ({ fileName = HANDOFF_FILE_NAME, name = HANDOFF_SKILL_NAME, description = HANDOFF_SKILL_DESCRIPTION } = {}) => {
109
+ return `---
110
+ name: ${name}
111
+ description: ${description}
112
+ ---
113
+
114
+ ${buildHandoffSkillBody({ fileName })}
115
+ `;
116
+ };
117
+
118
+ /**
119
+ * Build a minimal activation nudge for the system prompt. The full procedure
120
+ * lives in the deployed SKILL.md (loaded natively by the tool); this short
121
+ * pointer only ensures the read-at-session-start behavior reliably fires, since
122
+ * that is triggered by session lifecycle rather than by a task description.
123
+ *
124
+ * @param {Object} [options]
125
+ * @param {string} [options.fileName=HANDOFF_FILE_NAME] - Handoff file name.
126
+ * @param {string} [options.name=HANDOFF_SKILL_NAME] - Skill name.
127
+ * @returns {string} The activation nudge.
128
+ */
129
+ export const buildHandoffSubPrompt = ({ fileName = HANDOFF_FILE_NAME, name = HANDOFF_SKILL_NAME } = {}) => {
130
+ return `
131
+ HANDOFF.md continuity skill (experimental, --use-handoff).
132
+ - A reusable "${name}" Agent Skill is installed in this workspace (.claude/skills/${name}/ for Claude, .agents/skills/${name}/ for Codex). It defines how to read and maintain ${fileName} so any session can continue the work of a previous one — even across tools (Claude and Codex) in the same pull request.
133
+ - At the start of this session, use the ${name} skill: if ${fileName} exists in the repository root, read it first and continue from its "Next steps". Create or update ${fileName} as you make progress and commit it to the pull request branch.`;
134
+ };
135
+
136
+ /**
137
+ * Get the handoff skill activation nudge if enabled.
138
+ *
139
+ * @param {Object} argv - Parsed command line arguments.
140
+ * @returns {string} The sub-prompt content, or an empty string when disabled.
141
+ */
142
+ export const getHandoffSubPrompt = argv => {
143
+ if (argv && argv.useHandoff) {
144
+ return buildHandoffSubPrompt();
145
+ }
146
+ return '';
147
+ };
148
+
149
+ // Export all functions as default object too (mirrors architecture-care module)
150
+ export default {
151
+ HANDOFF_FILE_NAME,
152
+ HANDOFF_SKILL_NAME,
153
+ HANDOFF_SKILL_DESCRIPTION,
154
+ buildHandoffSkillBody,
155
+ buildHandoffSkillFile,
156
+ buildHandoffSubPrompt,
157
+ getHandoffSubPrompt,
158
+ };
@@ -189,6 +189,7 @@ const KNOWN_OPTION_NAMES = [
189
189
  'prompt-issue-reporting',
190
190
  'prompt-architecture-care',
191
191
  'prompt-case-studies',
192
+ 'use-handoff',
192
193
  'prompt-playwright-mcp',
193
194
  'prompt-check-sibling-pull-requests',
194
195
  'enable-workspaces',
@@ -480,6 +480,11 @@ export const SOLVE_OPTION_DEFINITIONS = {
480
480
  description: 'Create comprehensive case study documentation for the issue including logs, analysis, timeline, root cause investigation, and proposed solutions. Organizes findings into ./docs/case-studies/issue-{id}/ directory. Supported for --tool claude and --tool codex.',
481
481
  default: false,
482
482
  },
483
+ 'use-handoff': {
484
+ type: 'boolean',
485
+ description: '[EXPERIMENTAL] Enable the HANDOFF.md continuity Agent Skill so a session can continue the work of a previous session — even when a different AI tool is used (e.g. Claude and Codex continuing each other in the same pull request). A real SKILL.md (the open Agent Skills standard) is deployed into the working directory so each tool loads it natively (.claude/skills/handoff/ for Claude, .agents/skills/handoff/ for Codex). The AI reads HANDOFF.md (repository root) first when present and keeps it updated with task, current state, decisions, next steps, gotchas, and critical files. HANDOFF.md is committed to the PR branch so it persists across the ephemeral per-session working directories; the SKILL.md itself is re-deployed each session and git-excluded so it never pollutes the PR. The same skill file is used identically for --tool claude and --tool codex. Disabled by default (issue #1877).',
486
+ default: false,
487
+ },
483
488
  'prompt-playwright-mcp': {
484
489
  type: 'boolean',
485
490
  description: 'Enable Playwright MCP browser automation hints in system prompt (enabled by default, only takes effect if Playwright MCP is installed). Use --no-prompt-playwright-mcp to disable. Supported for --tool claude, --tool codex, --tool opencode, --tool agent, --tool qwen, and --tool gemini.',