@hua-labs/tap 0.2.0 → 0.2.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.
package/dist/index.d.mts CHANGED
@@ -10,6 +10,8 @@ interface AdapterContext {
10
10
  platform: Platform;
11
11
  /** Instance ID for TAP_AGENT_ID env injection. Set by 'tap add'. */
12
12
  instanceId?: string;
13
+ /** Agent name from state. Injected as TAP_AGENT_NAME in MCP config. */
14
+ agentName?: string;
13
15
  }
14
16
  interface ProbeResult {
15
17
  installed: boolean;
@@ -129,6 +131,10 @@ interface InstanceState {
129
131
  bridge: BridgeState | null;
130
132
  /** Headless mode configuration. null = interactive (default). */
131
133
  headless: HeadlessConfig | null;
134
+ /** Whether bridge manages its own app-server process. Saved for restart mode preservation. */
135
+ manageAppServer?: boolean;
136
+ /** Whether bridge runs without auth gateway. Saved for restart mode preservation. */
137
+ noAuth?: boolean;
132
138
  warnings: string[];
133
139
  }
134
140
  /** @deprecated Use InstanceState. Kept for v1 state migration. */
@@ -164,8 +170,8 @@ interface TapStateV1 {
164
170
  packageVersion: string;
165
171
  runtimes: Partial<Record<RuntimeName, RuntimeState>>;
166
172
  }
167
- type CommandName = "init" | "init-worktree" | "add" | "remove" | "status" | "serve" | "bridge" | "up" | "down" | "dashboard" | "doctor" | "unknown";
168
- type CommandCode = "TAP_INIT_OK" | "TAP_ADD_OK" | "TAP_REMOVE_OK" | "TAP_STATUS_OK" | "TAP_SERVE_OK" | "TAP_NO_OP" | "TAP_ALREADY_INITIALIZED" | "TAP_NOT_INITIALIZED" | "TAP_RUNTIME_UNKNOWN" | "TAP_RUNTIME_NOT_FOUND" | "TAP_CONFIG_INVALID" | "TAP_LOCAL_SERVER_MISSING" | "TAP_INVALID_ARGUMENT" | "TAP_INSTANCE_NOT_FOUND" | "TAP_INSTANCE_AMBIGUOUS" | "TAP_PORT_CONFLICT" | "TAP_PATCH_FAILED" | "TAP_VERIFY_FAILED" | "TAP_ROLLBACK_FAILED" | "TAP_BRIDGE_START_OK" | "TAP_BRIDGE_START_FAILED" | "TAP_BRIDGE_STOP_OK" | "TAP_BRIDGE_STATUS_OK" | "TAP_BRIDGE_NOT_RUNNING" | "TAP_BRIDGE_SCRIPT_MISSING" | "TAP_UP_OK" | "TAP_DOWN_OK" | "TAP_SERVE_NO_SERVER" | "TAP_SERVE_BUN_REQUIRED" | "TAP_REVIEW_START_OK" | "TAP_REVIEW_TERMINATED" | "TAP_INTERNAL_ERROR";
173
+ type CommandName = "init" | "init-worktree" | "add" | "remove" | "status" | "serve" | "bridge" | "up" | "down" | "comms" | "dashboard" | "doctor" | "unknown";
174
+ type CommandCode = "TAP_INIT_OK" | "TAP_ADD_OK" | "TAP_REMOVE_OK" | "TAP_STATUS_OK" | "TAP_SERVE_OK" | "TAP_NO_OP" | "TAP_ALREADY_INITIALIZED" | "TAP_INIT_CLONE_FAILED" | "TAP_NOT_INITIALIZED" | "TAP_RUNTIME_UNKNOWN" | "TAP_RUNTIME_NOT_FOUND" | "TAP_CONFIG_INVALID" | "TAP_LOCAL_SERVER_MISSING" | "TAP_INVALID_ARGUMENT" | "TAP_INSTANCE_NOT_FOUND" | "TAP_INSTANCE_AMBIGUOUS" | "TAP_PORT_CONFLICT" | "TAP_PATCH_FAILED" | "TAP_VERIFY_FAILED" | "TAP_ROLLBACK_FAILED" | "TAP_BRIDGE_START_OK" | "TAP_BRIDGE_START_FAILED" | "TAP_BRIDGE_STOP_OK" | "TAP_BRIDGE_STATUS_OK" | "TAP_BRIDGE_NOT_RUNNING" | "TAP_BRIDGE_SCRIPT_MISSING" | "TAP_UP_OK" | "TAP_DOWN_OK" | "TAP_COMMS_PULL_OK" | "TAP_COMMS_PULL_FAILED" | "TAP_COMMS_PUSH_OK" | "TAP_COMMS_PUSH_FAILED" | "TAP_COMMS_NOT_REPO" | "TAP_SERVE_NO_SERVER" | "TAP_SERVE_BUN_REQUIRED" | "TAP_REVIEW_START_OK" | "TAP_REVIEW_TERMINATED" | "TAP_INTERNAL_ERROR";
169
175
  interface CommandResult<T = Record<string, unknown>> {
170
176
  ok: boolean;
171
177
  command: CommandName;
@@ -197,6 +203,10 @@ interface TapSharedConfig {
197
203
  runtimeCommand?: string;
198
204
  /** App server WebSocket URL for bridge connections. */
199
205
  appServerUrl?: string;
206
+ /** GitHub URL for the comms repository (used by `tap comms pull/push`). */
207
+ commsRepoUrl?: string;
208
+ /** Control tower agent name. Used for auto-notify on new agent join (M111). */
209
+ towerName?: string;
200
210
  }
201
211
  /**
202
212
  * Local config (tap-config.local.json) — gitignored, machine-specific overrides.
@@ -212,6 +222,7 @@ interface TapResolvedConfig {
212
222
  stateDir: string;
213
223
  runtimeCommand: string;
214
224
  appServerUrl: string;
225
+ towerName: string | null;
215
226
  }
216
227
  /** Config resolution source for diagnostics. */
217
228
  type ConfigSource = "cli-flag" | "env" | "local-config" | "shared-config" | "legacy-shell-config" | "auto";
@@ -237,6 +248,46 @@ declare function resolveConfig(overrides?: ConfigOverrides, startDir?: string):
237
248
  declare function saveSharedConfig(repoRoot: string, config: TapSharedConfig): void;
238
249
  declare function saveLocalConfig(repoRoot: string, config: TapLocalConfig): void;
239
250
 
251
+ interface BridgeStartOptions {
252
+ instanceId: InstanceId;
253
+ runtime: RuntimeName;
254
+ stateDir: string;
255
+ commsDir: string;
256
+ bridgeScript: string;
257
+ platform: Platform;
258
+ agentName?: string;
259
+ runtimeCommand?: string;
260
+ appServerUrl?: string;
261
+ repoRoot?: string;
262
+ port?: number;
263
+ /** Headless configuration. Passed as env vars to the bridge process. */
264
+ headless?: HeadlessConfig | null;
265
+ /** Bridge script operational flags (forwarded to codex-app-server-bridge.ts) */
266
+ busyMode?: "steer" | "wait";
267
+ pollSeconds?: number;
268
+ reconnectSeconds?: number;
269
+ messageLookbackMinutes?: number;
270
+ threadId?: string;
271
+ ephemeral?: boolean;
272
+ processExistingMessages?: boolean;
273
+ manageAppServer?: boolean;
274
+ /** Skip auth gateway — app-server listens directly on the public port (localhost only). */
275
+ noAuth?: boolean;
276
+ }
277
+ interface RestartBridgeOptions extends BridgeStartOptions {
278
+ /** Max seconds to wait for active turn to complete before killing. Default: 30 */
279
+ drainTimeoutSeconds?: number;
280
+ }
281
+ /**
282
+ * Graceful bridge restart: wait for active turn → cleanup → stop → start.
283
+ * Prevents message loss during restart by draining active work first
284
+ * and replaying unprocessed messages on the new instance.
285
+ *
286
+ * For headless instances: drain phase cleans up headless dispatch files
287
+ * to prevent the new bridge from re-injecting completed review requests.
288
+ * (별 finding: eager marking + replay collision)
289
+ */
290
+ declare function restartBridge(options: RestartBridgeOptions): Promise<BridgeState>;
240
291
  declare function rotateLog(logPath: string): void;
241
292
  /**
242
293
  * Update the heartbeat timestamp for a running bridge.
@@ -300,7 +351,8 @@ declare function collectDashboardSnapshot(repoRoot?: string, commsDirOverride?:
300
351
  * State/Control API — programmatic access to tap state.
301
352
  * GUI and autopilot consume these functions instead of shelling out to CLI.
302
353
  *
303
- * M105: JSON contract for getDashboardSnapshot, streamEvents.
354
+ * M105 P1: getDashboardSnapshot, streamEvents (read-only)
355
+ * M105 P2: startAgents, stopAgents (write — wraps tap up/down)
304
356
  */
305
357
 
306
358
  interface StateApiOptions {
@@ -327,6 +379,44 @@ interface EventStreamOptions extends StateApiOptions {
327
379
  * Stops when the AbortSignal fires or the consumer breaks out.
328
380
  */
329
381
  declare function streamEvents(options?: EventStreamOptions): AsyncGenerator<DashboardSnapshot>;
382
+ interface AgentControlOptions {
383
+ /** Extra CLI args forwarded to `tap up` (e.g. `["--no-auth"]`) */
384
+ args?: string[];
385
+ }
386
+ interface AgentControlResult {
387
+ ok: boolean;
388
+ message: string;
389
+ snapshot: DashboardSnapshot;
390
+ commandResult: CommandResult;
391
+ }
392
+ /**
393
+ * Start all registered bridge daemons.
394
+ * Equivalent to `tap up [...args]`.
395
+ *
396
+ * Always operates on the cwd-based repo (same as CLI commands).
397
+ * Use read-only APIs (getDashboardSnapshot) for cross-repo queries.
398
+ */
399
+ declare function startAgents(options?: AgentControlOptions): Promise<AgentControlResult>;
400
+ /**
401
+ * Stop all running bridge daemons.
402
+ * Equivalent to `tap down`.
403
+ *
404
+ * Always operates on the cwd-based repo (same as CLI commands).
405
+ */
406
+ declare function stopAgents(): Promise<AgentControlResult>;
407
+ interface HealthReport {
408
+ ok: boolean;
409
+ timestamp: string;
410
+ bridges: DashboardSnapshot["bridges"];
411
+ agents: DashboardSnapshot["agents"];
412
+ warnings: DashboardSnapshot["warnings"];
413
+ headless: Record<string, unknown>[];
414
+ }
415
+ /**
416
+ * Health check that combines dashboard snapshot with headless state.
417
+ * Consumed by monitoring tools (Uptime Kuma, cron, autopilot).
418
+ */
419
+ declare function getHealthReport(options?: StateApiOptions): HealthReport;
330
420
  /**
331
421
  * Resolve tap configuration for API consumers.
332
422
  * Returns paths and settings without requiring CLI args.
@@ -403,4 +493,4 @@ declare function resolveNodeRuntime(configCommand: string, repoRoot: string): Re
403
493
  */
404
494
  declare function buildRuntimeEnv(repoRoot: string, baseEnv?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
405
495
 
406
- export { type AdapterContext, type AgentInfo, type AppServerAuthState, type AppServerState, type ApplyResult, type ArtifactKind, type BridgeInfo, type BridgeMode, type BridgeState, type CommandCode, type CommandName, type CommandResult, type ConfigOverrides, type ConfigResolution, type ConfigSource, type DashboardSnapshot, type DashboardWarning, type EventStreamOptions, type HttpServerOptions, type InstanceId, type InstanceState, LOCAL_CONFIG_FILE, type OwnedArtifact, type PRInfo, type PatchOp, type PatchOpType, type PatchPlan, type Platform, type ProbeResult, type ResolvedRuntime, type RuntimeAdapter, type RuntimeName, type RuntimeSource, type RuntimeState, SHARED_CONFIG_FILE, type StateApiOptions, type TapLocalConfig, type TapResolvedConfig, type TapSharedConfig, type TapState, type TapStateV1, type VerifyCheck, type VerifyResult, buildRuntimeEnv, collectDashboardSnapshot, createInitialState, getConfig, getDashboardSnapshot, getFnmBinDir, getHeartbeatAge, loadLocalConfig, loadSharedConfig, loadState, probeFnmNode, readNodeVersion, resolveConfig, resolveNodeRuntime, rotateLog, saveLocalConfig, saveSharedConfig, saveState, startHttpServer, stateExists, streamEvents, updateBridgeHeartbeat, version };
496
+ export { type AdapterContext, type AgentControlOptions, type AgentControlResult, type AgentInfo, type AppServerAuthState, type AppServerState, type ApplyResult, type ArtifactKind, type BridgeInfo, type BridgeMode, type BridgeState, type CommandCode, type CommandName, type CommandResult, type ConfigOverrides, type ConfigResolution, type ConfigSource, type DashboardSnapshot, type DashboardWarning, type EventStreamOptions, type HealthReport, type HttpServerOptions, type InstanceId, type InstanceState, LOCAL_CONFIG_FILE, type OwnedArtifact, type PRInfo, type PatchOp, type PatchOpType, type PatchPlan, type Platform, type ProbeResult, type ResolvedRuntime, type RuntimeAdapter, type RuntimeName, type RuntimeSource, type RuntimeState, SHARED_CONFIG_FILE, type StateApiOptions, type TapLocalConfig, type TapResolvedConfig, type TapSharedConfig, type TapState, type TapStateV1, type VerifyCheck, type VerifyResult, buildRuntimeEnv, collectDashboardSnapshot, createInitialState, getConfig, getDashboardSnapshot, getFnmBinDir, getHealthReport, getHeartbeatAge, loadLocalConfig, loadSharedConfig, loadState, probeFnmNode, readNodeVersion, resolveConfig, resolveNodeRuntime, restartBridge, rotateLog, saveLocalConfig, saveSharedConfig, saveState, startAgents, startHttpServer, stateExists, stopAgents, streamEvents, updateBridgeHeartbeat, version };