@event4u/agent-config 9.15.0 → 9.17.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/.claude-plugin/marketplace.json +1 -1
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +74 -0
- package/README.md +1 -1
- package/dist/agent-src/commands/agent-handoff.md +100 -48
- package/dist/agent-src/commands/commit.md +1 -1
- package/dist/agent-src/commands/condense.md +19 -64
- package/dist/agent-src/commands/evals/agent-handoff.json +13 -1
- package/dist/agent-src/commands/memory/promote.md +14 -1
- package/dist/agent-src/commands/mode.md +9 -5
- package/dist/agent-src/commands/optimize/deep.md +72 -11
- package/dist/agent-src/contexts/authority/commit-mechanics.md +5 -5
- package/dist/agent-src/contexts/communication/rules-auto/guidelines-mechanics.md +1 -0
- package/dist/agent-src/contexts/communication/rules-auto/skill-quality-mechanics.md +1 -1
- package/dist/agent-src/contexts/communication/rules-auto/think-before-action-mechanics.md +6 -1
- package/dist/agent-src/contexts/communication/rules-auto/token-efficiency-mechanics.md +4 -1
- package/dist/agent-src/contexts/execution/autonomy-mechanics.md +27 -1
- package/dist/agent-src/contexts/execution/roadmap-process-loop.md +5 -2
- package/dist/agent-src/profiles/agency.yml +3 -3
- package/dist/agent-src/profiles/content_creator.yml +2 -2
- package/dist/agent-src/profiles/developer.yml +2 -2
- package/dist/agent-src/profiles/finance.yml +1 -1
- package/dist/agent-src/profiles/founder.yml +2 -2
- package/dist/agent-src/profiles/ops.yml +2 -2
- package/dist/agent-src/rules/architecture.md +2 -2
- package/dist/agent-src/rules/autonomous-execution.md +1 -1
- package/dist/agent-src/rules/context-hygiene.md +3 -2
- package/dist/agent-src/rules/domain-safety-pii.md +1 -1
- package/dist/agent-src/rules/output-discipline.md +9 -2
- package/dist/agent-src/rules/token-budget-discipline.md +2 -2
- package/dist/agent-src/rules/user-interaction.md +3 -4
- package/dist/agent-src/skills/build-buy-partner/SKILL.md +1 -1
- package/dist/agent-src/skills/copilot-agents-optimization/SKILL.md +4 -4
- package/dist/agent-src/skills/copilot-config/SKILL.md +1 -1
- package/dist/agent-src/skills/deep-reading-analyst/SKILL.md +7 -4
- package/dist/agent-src/skills/description-assist/SKILL.md +1 -1
- package/dist/agent-src/skills/fe-design/SKILL.md +1 -1
- package/dist/agent-src/skills/market-entry-analysis/SKILL.md +1 -1
- package/dist/agent-src/skills/persona-writing/SKILL.md +2 -2
- package/dist/agent-src/skills/readme-reviewer/SKILL.md +2 -1
- package/dist/agent-src/skills/rule-writing/SKILL.md +4 -2
- package/dist/agent-src/skills/skill-reviewer/SKILL.md +1 -1
- package/dist/agent-src/skills/skill-writing/SKILL.md +2 -2
- package/dist/agent-src/skills/tailwind-engineer/SKILL.md +3 -1
- package/dist/agent-src/skills/token-optimizer/SKILL.md +2 -2
- package/dist/agent-src/skills/ui-component-architect/SKILL.md +6 -3
- package/dist/agent-src/templates/agent-settings.md +13 -15
- package/dist/agent-src/templates/agents/agent-project-settings.example.yml +6 -2
- package/dist/agent-src/templates/persona.md +2 -2
- package/dist/agent-src/templates/roadmaps.md +1 -1
- package/dist/agent-src/templates/rule.md +1 -1
- package/dist/agent-src/templates/skill.md +1 -1
- package/dist/cli/mcp/content.js +1 -1
- package/dist/cli/mcp/content.js.map +1 -1
- package/dist/cli/registry.js +1 -0
- package/dist/cli/registry.js.map +1 -1
- package/dist/cli-delegate/{chunk-ZXXJLL5K.js → chunk-BSLUHV2F.js} +127 -1487
- package/dist/cli-delegate/{chunk-H574KOUH.js → chunk-IMSXPRVH.js} +24 -1
- package/dist/cli-delegate/chunk-VSYT7OHO.js +1382 -0
- package/dist/cli-delegate/chunk-XGA2NTU4.js +3727 -0
- package/dist/cli-delegate/cmd_conformance.js +4 -3
- package/dist/cli-delegate/cmd_converge.js +3 -3
- package/dist/cli-delegate/cmd_doctor.js +3 -2
- package/dist/cli-delegate/cmd_export.js +4 -4
- package/dist/cli-delegate/cmd_handoff.js +3194 -0
- package/dist/cli-delegate/cmd_memory_get.js +35 -3754
- package/dist/cli-delegate/cmd_migrate.js +2 -2
- package/dist/cli-delegate/cmd_prune.js +4 -4
- package/dist/cli-delegate/cmd_settings_migrate.js +4 -4
- package/dist/cli-delegate/cmd_sync.js +4 -4
- package/dist/cli-delegate/cmd_uninstall.js +4 -4
- package/dist/cli-delegate/cmd_update.js +3 -3
- package/dist/cli-delegate/cmd_upgrade.js +3 -3
- package/dist/cli-delegate/cmd_validate.js +4 -4
- package/dist/cli-delegate/cmd_versions.js +3 -3
- package/dist/discovery/deprecation-report.md +1 -1
- package/dist/discovery/discovery-manifest.json +31 -31
- package/dist/discovery/discovery-manifest.json.sha256 +1 -1
- package/dist/discovery/discovery-manifest.summary.md +1 -1
- package/dist/discovery/orphan-report.md +1 -1
- package/dist/discovery/packs.json +2 -2
- package/dist/discovery/trust-report.md +1 -1
- package/dist/discovery/workspaces.json +2 -2
- package/dist/hooks/dispatch.js +602 -507
- package/dist/install/install.mjs +23 -0
- package/dist/mcp/awesome-mcp-servers.row.md +1 -1
- package/dist/mcp/mcp-cloudflare-catalogue.json +2 -2
- package/dist/mcp/registry-manifest.json +4 -4
- package/dist/mcp/server.json +2 -2
- package/dist/mcp/server.mjs +25 -3
- package/dist/scripts/_lib/agent_src.js +39 -6
- package/dist/scripts/_lib/agent_src.js.map +1 -1
- package/dist/server/routes/workspace.js +1 -1
- package/dist/server/routes/workspace.js.map +1 -1
- package/dist/server/schemas/settings.js +13 -0
- package/dist/server/schemas/settings.js.map +1 -1
- package/dist/shared/userMd/utils.js +1 -1
- package/dist/shared/userMd/utils.js.map +1 -1
- package/dist/ui/assets/index-DmR0mbk4.js +26 -0
- package/dist/ui/assets/index-DmR0mbk4.js.map +1 -0
- package/dist/ui/index.html +1 -1
- package/docs/guidelines/abstraction-thresholds.md +53 -0
- package/docs/guidelines/agent-infra/agent-interaction-and-decision-quality.md +1 -1
- package/docs/guidelines/agent-infra/asking-and-brevity-examples.md +7 -0
- package/docs/guidelines/agent-infra/context-hygiene-mechanics.md +2 -2
- package/docs/guidelines/agent-infra/minimal-safe-diff-mechanics.md +5 -3
- package/docs/guidelines/agent-infra/size-and-scope.md +8 -2
- package/docs/guidelines/component-oriented-and-oop-development.md +11 -6
- package/docs/guidelines/docs/readme-size-and-splitting.md +5 -2
- package/llms.txt +1 -0
- package/package.json +4 -4
- package/src/config/agent-settings.template.yml +25 -1
- package/src/config/budget-routing.json +7 -0
- package/src/config/evaluator-budgets.json +8 -11
- package/src/config/gate-coverage.yml +30 -0
- package/src/scripts/_cli/cmd_handoff.ts +405 -0
- package/src/scripts/_cli/handoff_generate.ts +453 -0
- package/src/scripts/_cli/handoff_sessions.ts +435 -0
- package/src/scripts/_dispatch.bash +9 -0
- package/src/scripts/_lib/agent_src.ts +36 -6
- package/src/scripts/_lib/release_material.ts +156 -0
- package/src/scripts/_lib/tier_budget_routing.ts +154 -28
- package/src/scripts/anchor_scoring_run.ts +1 -1
- package/src/scripts/bench_persona_placebo.ts +1 -1
- package/src/scripts/bench_quality_run.ts +1 -1
- package/src/scripts/check_cli_registry_budget_sync.ts +168 -0
- package/src/scripts/check_condensation.ts +2 -1
- package/src/scripts/check_finding_dispositions.ts +278 -0
- package/src/scripts/check_gate_coverage.ts +1 -1
- package/src/scripts/check_pack_size.ts +4 -3
- package/src/scripts/check_references.ts +1 -0
- package/src/scripts/check_release_highlights.ts +300 -0
- package/src/scripts/check_release_pr_shape.ts +4 -0
- package/src/scripts/check_release_surface_equality.ts +132 -0
- package/src/scripts/check_reply_consistency.ts +187 -138
- package/src/scripts/check_token_quality_golden.ts +1 -1
- package/src/scripts/cost/budget.mjs +18 -4
- package/src/scripts/handoff_context_hook.ts +148 -0
- package/src/scripts/hook_manifest.yaml +17 -7
- package/src/scripts/hooks/concern_registry.ts +2 -0
- package/src/scripts/lint_abstraction_thresholds.ts +325 -0
- package/src/scripts/lint_framework_leakage_allowlist.json +2 -2
- package/src/scripts/lint_profile_personas.ts +153 -0
- package/src/scripts/lint_token_budget_discipline.ts +148 -0
- package/src/scripts/release.ts +264 -37
- package/src/scripts/release_drill.ts +491 -0
- package/src/scripts/routing_doctor.ts +76 -1
- package/src/scripts/schemas/command.schema.json +33 -0
- package/src/scripts/self_review_gate.ts +41 -3
- package/src/scripts/skill_linter.ts +3 -1
- package/src/scripts/smoke/router.sh +1 -1
- package/src/scripts/update_counts.ts +60 -12
- package/src/server/schemas/settings.ts +23 -0
- package/src/shared/userMd/utils.ts +1 -1
- package/dist/ui/assets/index-DJY_vQVn.js +0 -40
- package/dist/ui/assets/index-DJY_vQVn.js.map +0 -1
- package/dist/cli-delegate/{chunk-XX6TOPD7.js → chunk-WR6GTRHJ.js} +3 -3
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `agent-config handoff` — pick a recent session, generate a handoff,
|
|
4
|
+
* seed a fresh session (road-to-agent-handoff-resume Phase 4).
|
|
5
|
+
*
|
|
6
|
+
* Default TTY flow: numbered picker over the unified session list
|
|
7
|
+
* (chat-history primary; Claude-transcript + Codex-session adapters),
|
|
8
|
+
* then the Phase-2 deterministic generator writes
|
|
9
|
+
* `agents/runtime/state/handoff-context.md`, which the Phase-3
|
|
10
|
+
* session_start hook injects into the NEXT session exactly once.
|
|
11
|
+
*
|
|
12
|
+
* Flags:
|
|
13
|
+
* --list print the sessions and exit
|
|
14
|
+
* --json with --list: machine-readable output
|
|
15
|
+
* --session <id> skip the picker (exact id or unique prefix)
|
|
16
|
+
* --print emit the handoff to stdout instead of the state
|
|
17
|
+
* file (legacy copy-paste mode)
|
|
18
|
+
* --launch <host> spawn a fresh interactive host session after
|
|
19
|
+
* generating (claude: hook-seeded; codex: handoff as
|
|
20
|
+
* initial prompt — no hook surface there)
|
|
21
|
+
* --llm narrative-polish seam; v1: clear not-implemented error
|
|
22
|
+
* --root <path> repo root override (default: cwd)
|
|
23
|
+
*
|
|
24
|
+
* Exit codes: 0 ok · 1 no sessions / session not found · 2 invocation error
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { spawnSync } from 'node:child_process';
|
|
28
|
+
import * as fs from 'node:fs';
|
|
29
|
+
import process from 'node:process';
|
|
30
|
+
import * as path from 'node:path';
|
|
31
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
32
|
+
|
|
33
|
+
import {
|
|
34
|
+
build_handoff,
|
|
35
|
+
handoff_target_path,
|
|
36
|
+
LlmPolishNotImplementedError,
|
|
37
|
+
write_handoff,
|
|
38
|
+
} from './handoff_generate.js';
|
|
39
|
+
import { list_handoff_sessions } from './handoff_sessions.js';
|
|
40
|
+
import type { HandoffSession } from './handoff_sessions.js';
|
|
41
|
+
|
|
42
|
+
const PROG = 'agent-config handoff';
|
|
43
|
+
const USAGE = `usage: ${PROG} [--list] [--json] [--session <id>] [--print] [--launch <host>] [--llm] [--root <path>]`;
|
|
44
|
+
|
|
45
|
+
const _HELP = `${USAGE}
|
|
46
|
+
|
|
47
|
+
Pick a recent session, generate a deterministic handoff, and seed a fresh
|
|
48
|
+
session with it. Without flags (in a TTY): numbered picker, then the handoff
|
|
49
|
+
lands in agents/runtime/state/handoff-context.md and auto-injects into the
|
|
50
|
+
next session on hook-capable hosts.
|
|
51
|
+
|
|
52
|
+
options:
|
|
53
|
+
--list print the recent sessions and exit
|
|
54
|
+
--json with --list: JSON output
|
|
55
|
+
--session <id> generate for this session id (exact or unique prefix)
|
|
56
|
+
--print print the handoff to stdout (no state file)
|
|
57
|
+
--launch <host> start a fresh interactive session (claude | codex)
|
|
58
|
+
--llm optional LLM polish — not implemented in v1
|
|
59
|
+
--root <path> repo root (default: current directory)
|
|
60
|
+
-h, --help show this help
|
|
61
|
+
|
|
62
|
+
exit codes:
|
|
63
|
+
0 handoff generated (or list printed)
|
|
64
|
+
1 no sessions found / session id not found
|
|
65
|
+
2 invocation error (bad flag, non-TTY without --session, unsupported host)
|
|
66
|
+
`;
|
|
67
|
+
|
|
68
|
+
class ArgparseExit extends Error {
|
|
69
|
+
constructor(public readonly code: number) {
|
|
70
|
+
super(`exit ${code}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ---------------------------------------------------------------------
|
|
75
|
+
// launch adapter table (v1: claude + codex live, gemini stubbed)
|
|
76
|
+
// ---------------------------------------------------------------------
|
|
77
|
+
|
|
78
|
+
export interface LaunchAdapter {
|
|
79
|
+
supports_launch: boolean;
|
|
80
|
+
/** 'hook' = state file + session_start injection; 'initial-prompt' = argv. */
|
|
81
|
+
seeding: 'hook' | 'initial-prompt';
|
|
82
|
+
build_argv: (handoffText: string) => string[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const LAUNCH_ADAPTERS: Record<string, LaunchAdapter> = {
|
|
86
|
+
claude: {
|
|
87
|
+
supports_launch: true,
|
|
88
|
+
seeding: 'hook',
|
|
89
|
+
build_argv: () => ['claude'],
|
|
90
|
+
},
|
|
91
|
+
codex: {
|
|
92
|
+
// Codex is a bundle host without hooks — seed via the initial prompt.
|
|
93
|
+
supports_launch: true,
|
|
94
|
+
seeding: 'initial-prompt',
|
|
95
|
+
build_argv: (handoffText: string) => ['codex', handoffText],
|
|
96
|
+
},
|
|
97
|
+
gemini: {
|
|
98
|
+
supports_launch: false,
|
|
99
|
+
seeding: 'hook',
|
|
100
|
+
build_argv: () => ['gemini'],
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// ---------------------------------------------------------------------
|
|
105
|
+
// options + seams
|
|
106
|
+
// ---------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
export interface Opts {
|
|
109
|
+
list: boolean;
|
|
110
|
+
json: boolean;
|
|
111
|
+
session: string | null;
|
|
112
|
+
print: boolean;
|
|
113
|
+
launch: string | null;
|
|
114
|
+
llm: boolean;
|
|
115
|
+
root: string | null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
type Runner = (cmd: string[]) => number;
|
|
119
|
+
|
|
120
|
+
export interface MainOptions {
|
|
121
|
+
out?: (text: string) => void;
|
|
122
|
+
err?: (text: string) => void;
|
|
123
|
+
/** TTY availability override (default: stdin AND stdout are TTYs). */
|
|
124
|
+
isTTY?: boolean;
|
|
125
|
+
/** Picker input; returns the raw line or null on read failure. */
|
|
126
|
+
readLine?: (prompt: string) => string | null;
|
|
127
|
+
/** Interactive child spawn (default: spawnSync stdio-inherit). */
|
|
128
|
+
runner?: Runner;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function _default_runner(cmd: string[]): number {
|
|
132
|
+
const r = spawnSync(cmd[0] as string, cmd.slice(1), { stdio: 'inherit' });
|
|
133
|
+
if (r.error) {
|
|
134
|
+
process.stderr.write(`${PROG}: cannot run ${cmd[0]}: ${String(r.error)}\n`);
|
|
135
|
+
return 127;
|
|
136
|
+
}
|
|
137
|
+
return r.status ?? 1;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Synchronous /dev/tty line read (never fd 0 — EAGAIN under go-task
|
|
142
|
+
* `interactive: true` silently auto-aborts a fd-0 prompt).
|
|
143
|
+
*/
|
|
144
|
+
function _tty_read_line(prompt: string): string | null {
|
|
145
|
+
try {
|
|
146
|
+
process.stdout.write(prompt);
|
|
147
|
+
const fd = fs.openSync('/dev/tty', 'rs');
|
|
148
|
+
try {
|
|
149
|
+
const buf = Buffer.alloc(1);
|
|
150
|
+
let line = '';
|
|
151
|
+
for (;;) {
|
|
152
|
+
let n = 0;
|
|
153
|
+
try {
|
|
154
|
+
n = fs.readSync(fd, buf, 0, 1, null);
|
|
155
|
+
} catch (exc) {
|
|
156
|
+
const code = (exc as NodeJS.ErrnoException).code;
|
|
157
|
+
if (code === 'EAGAIN' || code === 'EINTR') continue;
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
if (n === 0) break;
|
|
161
|
+
const ch = buf.toString('utf-8');
|
|
162
|
+
if (ch === '\n') break;
|
|
163
|
+
line += ch;
|
|
164
|
+
}
|
|
165
|
+
return line;
|
|
166
|
+
} finally {
|
|
167
|
+
fs.closeSync(fd);
|
|
168
|
+
}
|
|
169
|
+
} catch {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ---------------------------------------------------------------------
|
|
175
|
+
// arg parsing (hand-rolled, house style — no commander in _cli/)
|
|
176
|
+
// ---------------------------------------------------------------------
|
|
177
|
+
|
|
178
|
+
function _argError(err: (t: string) => void, message: string): never {
|
|
179
|
+
err(`${USAGE}\n${PROG}: error: ${message}\n`);
|
|
180
|
+
throw new ArgparseExit(2);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function _parse(argv: string[], err: (t: string) => void): Opts {
|
|
184
|
+
const opts: Opts = {
|
|
185
|
+
list: false,
|
|
186
|
+
json: false,
|
|
187
|
+
session: null,
|
|
188
|
+
print: false,
|
|
189
|
+
launch: null,
|
|
190
|
+
llm: false,
|
|
191
|
+
root: null,
|
|
192
|
+
};
|
|
193
|
+
let i = 0;
|
|
194
|
+
const takeValue = (flag: string): string => {
|
|
195
|
+
const arg = argv[i] as string;
|
|
196
|
+
const eq = arg.indexOf('=');
|
|
197
|
+
if (eq >= 0) return arg.slice(eq + 1);
|
|
198
|
+
i += 1;
|
|
199
|
+
const value = argv[i];
|
|
200
|
+
if (value === undefined) _argError(err, `argument ${flag}: expected one argument`);
|
|
201
|
+
return value;
|
|
202
|
+
};
|
|
203
|
+
while (i < argv.length) {
|
|
204
|
+
const arg = argv[i] as string;
|
|
205
|
+
const flag = arg.includes('=') ? arg.slice(0, arg.indexOf('=')) : arg;
|
|
206
|
+
switch (flag) {
|
|
207
|
+
case '-h':
|
|
208
|
+
case '--help':
|
|
209
|
+
process.stdout.write(_HELP);
|
|
210
|
+
throw new ArgparseExit(0);
|
|
211
|
+
case '--list':
|
|
212
|
+
opts.list = true;
|
|
213
|
+
break;
|
|
214
|
+
case '--json':
|
|
215
|
+
opts.json = true;
|
|
216
|
+
break;
|
|
217
|
+
case '--print':
|
|
218
|
+
opts.print = true;
|
|
219
|
+
break;
|
|
220
|
+
case '--llm':
|
|
221
|
+
opts.llm = true;
|
|
222
|
+
break;
|
|
223
|
+
case '--session':
|
|
224
|
+
opts.session = takeValue('--session');
|
|
225
|
+
break;
|
|
226
|
+
case '--launch':
|
|
227
|
+
opts.launch = takeValue('--launch');
|
|
228
|
+
break;
|
|
229
|
+
case '--root':
|
|
230
|
+
opts.root = takeValue('--root');
|
|
231
|
+
break;
|
|
232
|
+
default:
|
|
233
|
+
_argError(err, `unrecognized arguments: ${arg}`);
|
|
234
|
+
}
|
|
235
|
+
i += 1;
|
|
236
|
+
}
|
|
237
|
+
return opts;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// ---------------------------------------------------------------------
|
|
241
|
+
// rendering
|
|
242
|
+
// ---------------------------------------------------------------------
|
|
243
|
+
|
|
244
|
+
function _fmt_date(iso: string | null): string {
|
|
245
|
+
if (!iso) return 'unknown-date';
|
|
246
|
+
return iso.slice(0, 16).replace('T', ' ');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function render_session_line(s: HandoffSession, index: number): string {
|
|
250
|
+
const branch = s.branch ? ` · ${s.branch}` : '';
|
|
251
|
+
return `${String(index + 1).padStart(2)}. ${_fmt_date(s.endedAt ?? s.startedAt)} · ${s.source}${branch} · ${s.summary}`;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function _render_list(sessions: HandoffSession[], json: boolean): string {
|
|
255
|
+
if (json) return JSON.stringify(sessions, null, 2) + '\n';
|
|
256
|
+
return sessions.map((s, i) => render_session_line(s, i)).join('\n') + '\n';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// ---------------------------------------------------------------------
|
|
260
|
+
// main
|
|
261
|
+
// ---------------------------------------------------------------------
|
|
262
|
+
|
|
263
|
+
export function main(argv: string[] | null = null, options: MainOptions = {}): number {
|
|
264
|
+
const out = options.out ?? ((t: string): void => void process.stdout.write(t));
|
|
265
|
+
const err = options.err ?? ((t: string): void => void process.stderr.write(t));
|
|
266
|
+
const isTTY = options.isTTY ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
267
|
+
const readLine = options.readLine ?? _tty_read_line;
|
|
268
|
+
const runner = options.runner ?? _default_runner;
|
|
269
|
+
|
|
270
|
+
let opts: Opts;
|
|
271
|
+
try {
|
|
272
|
+
opts = _parse(argv ?? process.argv.slice(2), err);
|
|
273
|
+
} catch (exc) {
|
|
274
|
+
if (exc instanceof ArgparseExit) return exc.code;
|
|
275
|
+
throw exc;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// The bash dispatcher strips a global `--root` and exports it as
|
|
279
|
+
// AGENT_CONFIG_PROJECT_ROOT instead — honor both channels.
|
|
280
|
+
const envRoot =
|
|
281
|
+
process.env.AGENT_CONFIG_ROOT_OVERRIDE === '1'
|
|
282
|
+
? process.env.AGENT_CONFIG_PROJECT_ROOT || null
|
|
283
|
+
: null;
|
|
284
|
+
const root = path.resolve(opts.root ?? envRoot ?? process.cwd());
|
|
285
|
+
const sessions = list_handoff_sessions({ cwd: root });
|
|
286
|
+
|
|
287
|
+
if (opts.list) {
|
|
288
|
+
if (sessions.length === 0) {
|
|
289
|
+
out('no recent sessions found for this repo\n');
|
|
290
|
+
return 1;
|
|
291
|
+
}
|
|
292
|
+
out(_render_list(sessions, opts.json));
|
|
293
|
+
return 0;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (sessions.length === 0) {
|
|
297
|
+
err(`${PROG}: no recent sessions found for this repo\n`);
|
|
298
|
+
return 1;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (opts.launch && !(opts.launch in LAUNCH_ADAPTERS)) {
|
|
302
|
+
err(`${USAGE}\n${PROG}: error: unknown --launch host '${opts.launch}' (claude | codex)\n`);
|
|
303
|
+
return 2;
|
|
304
|
+
}
|
|
305
|
+
const adapter = opts.launch ? (LAUNCH_ADAPTERS[opts.launch] as LaunchAdapter) : null;
|
|
306
|
+
if (opts.launch && adapter && !adapter.supports_launch) {
|
|
307
|
+
err(`${PROG}: --launch ${opts.launch} is not supported yet (hook injection already works there)\n`);
|
|
308
|
+
return 2;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// resolve the session — flag, or picker in a TTY
|
|
312
|
+
let picked: HandoffSession | undefined;
|
|
313
|
+
if (opts.session) {
|
|
314
|
+
const matches = sessions.filter((s) => s.id === opts.session || s.id.startsWith(opts.session as string));
|
|
315
|
+
if (matches.length === 0) {
|
|
316
|
+
err(`${PROG}: session '${opts.session}' not found — run --list\n`);
|
|
317
|
+
return 1;
|
|
318
|
+
}
|
|
319
|
+
if (matches.length > 1) {
|
|
320
|
+
err(`${PROG}: session prefix '${opts.session}' is ambiguous (${matches.length} matches)\n`);
|
|
321
|
+
return 2;
|
|
322
|
+
}
|
|
323
|
+
picked = matches[0];
|
|
324
|
+
} else if (isTTY) {
|
|
325
|
+
out('Recent sessions:\n');
|
|
326
|
+
out(_render_list(sessions, false));
|
|
327
|
+
const raw = readLine(`Pick a session [1-${sessions.length}]: `);
|
|
328
|
+
const n = Number((raw ?? '').trim());
|
|
329
|
+
if (!Number.isInteger(n) || n < 1 || n > sessions.length) {
|
|
330
|
+
err(`${PROG}: invalid selection\n`);
|
|
331
|
+
return 2;
|
|
332
|
+
}
|
|
333
|
+
picked = sessions[n - 1];
|
|
334
|
+
} else {
|
|
335
|
+
out(_render_list(sessions, false));
|
|
336
|
+
err(`${PROG}: non-interactive invocation needs --session <id> (list above)\n`);
|
|
337
|
+
return 2;
|
|
338
|
+
}
|
|
339
|
+
if (!picked) return 2;
|
|
340
|
+
|
|
341
|
+
let text: string;
|
|
342
|
+
try {
|
|
343
|
+
text = build_handoff(picked, { cwd: root, llm: opts.llm });
|
|
344
|
+
} catch (exc) {
|
|
345
|
+
if (exc instanceof LlmPolishNotImplementedError) {
|
|
346
|
+
err(`${PROG}: ${exc.message}\n`);
|
|
347
|
+
return 2;
|
|
348
|
+
}
|
|
349
|
+
throw exc;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (opts.print) {
|
|
353
|
+
out(text);
|
|
354
|
+
return 0;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (adapter && adapter.seeding === 'initial-prompt') {
|
|
358
|
+
// no state file on this path — nothing would consume it
|
|
359
|
+
out(`launching ${opts.launch} with the handoff as initial prompt…\n`);
|
|
360
|
+
return runner(adapter.build_argv(text));
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Only the most recent handoff persists — a second `handoff` run before
|
|
364
|
+
// the next session start replaces the unconsumed file (by design; the
|
|
365
|
+
// hook consumes exactly one).
|
|
366
|
+
const existed = fs.existsSync(handoff_target_path(root));
|
|
367
|
+
const target = write_handoff(text, { cwd: root });
|
|
368
|
+
if (existed) out('note: replaced an unconsumed handoff — only the most recent one persists.\n');
|
|
369
|
+
out(`handoff written: ${target}\n`);
|
|
370
|
+
out('start a new session — the handoff will be injected automatically (hook-capable hosts).\n');
|
|
371
|
+
|
|
372
|
+
if (adapter) {
|
|
373
|
+
out(`launching ${opts.launch}…\n`);
|
|
374
|
+
return runner(adapter.build_argv(text));
|
|
375
|
+
}
|
|
376
|
+
return 0;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// ---------------------------------------------------------------------
|
|
380
|
+
// entry guard (symlink-safe; same shape as cmd_analyze_session.ts —
|
|
381
|
+
// under the cli-delegate bundle the argv-URL compare matches the bundle)
|
|
382
|
+
// ---------------------------------------------------------------------
|
|
383
|
+
|
|
384
|
+
function _isCliEntry(): boolean {
|
|
385
|
+
if (process.argv[1] === undefined) {
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
const argvUrl = pathToFileURL(path.resolve(process.argv[1])).href;
|
|
389
|
+
if (import.meta.url === argvUrl) {
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
// Symlinked invocation (installed projection, /var → /private/var):
|
|
393
|
+
// compare realpaths so the entry guard still fires.
|
|
394
|
+
try {
|
|
395
|
+
const here = fs.realpathSync(fileURLToPath(import.meta.url));
|
|
396
|
+
const argv = fs.realpathSync(path.resolve(process.argv[1]));
|
|
397
|
+
return here === argv;
|
|
398
|
+
} catch {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (_isCliEntry()) {
|
|
404
|
+
process.exitCode = main();
|
|
405
|
+
}
|