@agfpd/iapeer 0.4.52 → 0.4.53

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli/index.ts +62 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agfpd/iapeer",
3
- "version": "0.4.52",
3
+ "version": "0.4.53",
4
4
  "description": "Run Claude Code and Codex CLI as local background agents that message each other, wake on demand, and share one memory.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "agfpd",
package/src/cli/index.ts CHANGED
@@ -244,12 +244,21 @@ export function stopPeer(personality: string, runtime: string | undefined, opts:
244
244
  const identity = buildProcessAddress(rt, personality)
245
245
  const sock = buildSocketPath(rt, personality, cfg.sockDir)
246
246
  if (isInfraRuntime(rt)) {
247
- // Audit #13: do NOT swallow the launchctl result. (bootout returns non-zero when
248
- // the service was already not loaded — benign for stop — but surface the detail in
249
- // the reason rather than silently claiming success.)
247
+ // Audit #13 + В48: do NOT swallow the launchctl result — but DISCRIMINATE. An
248
+ // already-unloaded job (exit 3 / "No such process", verified live) is BENIGN for
249
+ // stop: the desired state ("not running") already holds, so it carries NO reason
250
+ // and must not fail the verb. Any other non-zero is a REAL error and sets reason
251
+ // (the CLI maps a reasoned bootout to exit 1).
250
252
  const r = spawnSync('launchctl', ['bootout', `gui/${uid()}/${launchdLabel(personality)}`], { encoding: 'utf8' })
251
253
  killSession(sock, identity, env)
252
- out.push({ personality, runtime: rt, action: 'bootout', reason: r.status === 0 ? undefined : `launchctl bootout exited ${r.status}${(r.stderr ?? '').trim() ? `: ${(r.stderr ?? '').trim()}` : ''}` })
254
+ const stderrText = (r.stderr ?? '').trim()
255
+ const benign = r.status === 0 || r.status === 3 || /No such process/i.test(stderrText)
256
+ out.push({
257
+ personality,
258
+ runtime: rt,
259
+ action: 'bootout',
260
+ reason: benign ? undefined : `launchctl bootout exited ${r.status}${stderrText ? `: ${stderrText}` : ''}`,
261
+ })
253
262
  } else {
254
263
  // A deliberate stop is a CLEAN PARK, not a death (stop→start must survive ≥
255
264
  // idle-reap): park-mark BEFORE the kill so the post-`start`
@@ -1131,6 +1140,32 @@ function parseIdentity(identity: string): { personality: string; runtime: Runtim
1131
1140
  // CLI dispatch — `iapeer <verb> …`
1132
1141
  // ─────────────────────────────────────────────────────────────────────────────
1133
1142
 
1143
+ /** В49 — flags that never take a value. Without the schema the look-ahead form ate the
1144
+ * NEXT positional: `iapeer update --force 0.4.31` parsed as flags.force='0.4.31' with NO
1145
+ * positionals → an UNforced full-cascade update instead of a forced version pin (live
1146
+ * incident shape). A boolean flag is always `true`; forcing a value onto one is only
1147
+ * possible via the explicit `--key=value` form (which stays verbatim). */
1148
+ const BOOLEAN_FLAGS: ReadonlySet<string> = new Set([
1149
+ 'accept-risk',
1150
+ 'all',
1151
+ 'check',
1152
+ 'dry-run',
1153
+ 'fix',
1154
+ 'force',
1155
+ 'foundation-only',
1156
+ 'install-plist',
1157
+ 'json',
1158
+ 'no-bootstrap',
1159
+ 'no-memory',
1160
+ 'no-notifier',
1161
+ 'no-setup',
1162
+ 'no-telegram',
1163
+ 'no-voice',
1164
+ 'npx',
1165
+ 'remove-codesign-identity',
1166
+ 'yes',
1167
+ ])
1168
+
1134
1169
  export function parseArgs(argv: string[]): { positionals: string[]; flags: Record<string, string | true> } {
1135
1170
  const positionals: string[] = []
1136
1171
  const flags: Record<string, string | true> = {}
@@ -1145,6 +1180,11 @@ export function parseArgs(argv: string[]): { positionals: string[]; flags: Recor
1145
1180
  continue
1146
1181
  }
1147
1182
  const key = a.slice(2)
1183
+ // В49 — a KNOWN boolean flag never consumes the next token as its value.
1184
+ if (BOOLEAN_FLAGS.has(key)) {
1185
+ flags[key] = true
1186
+ continue
1187
+ }
1148
1188
  const next = argv[i + 1]
1149
1189
  if (next === undefined || next.startsWith('--')) flags[key] = true
1150
1190
  else flags[key] = argv[++i]
@@ -1684,9 +1724,13 @@ export async function runCli(argv: string[], env: NodeJS.ProcessEnv = process.en
1684
1724
  out(
1685
1725
  `initialized "${r.personality}" (default: ${r.runtime}; runtimes: ${allRuntimes.join(', ')}); ` +
1686
1726
  `mcp: ${r.mcpConfigPaths.join(', ') || r.codexMcpConfigPath || 'none'}` +
1687
- `${r.bootstrapped ? `; bootstrap: ${r.bootstrapped.state}` : ''}\n`,
1727
+ `${r.bootstrapped ? `; bootstrap: ${r.bootstrapped.state}` : ''}` +
1728
+ `${r.selfConfig?.state === 'failed' ? '; self-config: FAILED (infra peer NOT started)' : ''}\n`,
1688
1729
  )
1689
- return 0
1730
+ // В47 — a failed runtime self-config means initPeer deliberately did NOT bootstrap:
1731
+ // the always-on peer is not running. Exit 0 here read as success to automation.
1732
+ if (r.selfConfig?.state === 'failed') return 1
1733
+ return r.bootstrapped && (r.bootstrapped.state === 'failed' || r.bootstrapped.state === 'refused-foreign') ? 1 : 0
1690
1734
  }
1691
1735
  case 'create': {
1692
1736
  // cwd-INDEPENDENT: resolve a location (default ~/.iapeer/peers/<p> or --path),
@@ -1753,8 +1797,13 @@ export async function runCli(argv: string[], env: NodeJS.ProcessEnv = process.en
1753
1797
  out(
1754
1798
  `created "${r.personality}" (default: ${r.runtime}; runtimes: ${allRuntimes.join(', ')}) at ${r.location}; ` +
1755
1799
  `mcp: ${r.mcpConfigPaths.join(', ') || r.codexMcpConfigPath || 'none'}` +
1756
- `${r.plistPath ? `; plist: ${r.plistPath}` : ''}${r.bootstrapped ? `; bootstrap: ${r.bootstrapped.state}` : ''}\n`,
1800
+ `${r.plistPath ? `; plist: ${r.plistPath}` : ''}${r.bootstrapped ? `; bootstrap: ${r.bootstrapped.state}` : ''}` +
1801
+ `${r.selfConfig?.state === 'failed' ? '; self-config: FAILED (infra peer NOT started)' : ''}\n`,
1757
1802
  )
1803
+ // В47 — selfConfig 'failed' deliberately skips the bootstrap (initPeer), so the
1804
+ // always-on peer is NOT running; `create x --runtime telegram` with a broken hook
1805
+ // exited 0 and automation read a dead telegram router as provisioned.
1806
+ if (r.selfConfig?.state === 'failed') return 1
1758
1807
  return r.bootstrapped && (r.bootstrapped.state === 'failed' || r.bootstrapped.state === 'refused-foreign') ? 1 : 0
1759
1808
  }
1760
1809
  case 'list': {
@@ -1865,7 +1914,9 @@ export async function runCli(argv: string[], env: NodeJS.ProcessEnv = process.en
1865
1914
  if (!peers) return argErr(errOut, 'stop needs a peer or --all — usage: iapeer stop <peer> [runtime] | --all')
1866
1915
  const outcomes = peers.flatMap(p => stopPeer(p, flags.all === true ? undefined : positionals[1], { env }))
1867
1916
  for (const o of outcomes) out(`${o.personality} (${o.runtime}): ${o.action}${o.reason ? ` — ${o.reason}` : ''}\n`)
1868
- return outcomes.some(o => o.action === 'refused-foreign-launchd') ? 1 : 0
1917
+ // В48 — a REAL bootout error (reason set; benign already-unloaded carries none) is exit 1:
1918
+ // automation must see that an always-on peer may still be running.
1919
+ return outcomes.some(o => o.action === 'refused-foreign-launchd' || (o.action === 'bootout' && o.reason !== undefined)) ? 1 : 0
1869
1920
  }
1870
1921
  case 'add-runtime': {
1871
1922
  // Fleet-switch enabler (codex-parity audit): add an agentic runtime to
@@ -1917,7 +1968,9 @@ export async function runCli(argv: string[], env: NodeJS.ProcessEnv = process.en
1917
1968
  if (!peers) return argErr(errOut, 'start needs a peer or --all — usage: iapeer start <peer> [runtime] | --all')
1918
1969
  const outcomes = peers.flatMap(p => startPeer(p, flags.all === true ? undefined : positionals[1], { env }))
1919
1970
  for (const o of outcomes) out(`${o.personality} (${o.runtime}): ${o.action}${o.reason ? ` — ${o.reason}` : ''}\n`)
1920
- return outcomes.some(o => o.action === 'refused-foreign-launchd') ? 1 : 0
1971
+ // В48 — a failed launchctl bootstrap (reason set) means the always-on peer is NOT
1972
+ // started; exit 0 here let automation read a dead telegram/notifier as running.
1973
+ return outcomes.some(o => o.action === 'refused-foreign-launchd' || (o.action === 'bootstrap' && o.reason !== undefined)) ? 1 : 0
1921
1974
  }
1922
1975
  case 'refresh': {
1923
1976
  // LAZY soft-reload (fleet doctrine refresh): arm `.fresh-next` so each agentic peer comes up FRESH