@hua-labs/tap 0.1.1 → 0.2.1

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
@@ -8,6 +8,8 @@ interface AdapterContext {
8
8
  repoRoot: string;
9
9
  stateDir: string;
10
10
  platform: Platform;
11
+ /** Instance ID for TAP_AGENT_ID env injection. Set by 'tap add'. */
12
+ instanceId?: string;
11
13
  }
12
14
  interface ProbeResult {
13
15
  installed: boolean;
@@ -83,10 +85,32 @@ interface HeadlessConfig {
83
85
  /** Severity floor for quality-threshold strategy. Default: "high" */
84
86
  qualitySeverityFloor: "critical" | "high" | "medium";
85
87
  }
88
+ interface AppServerAuthState {
89
+ mode: "query-token";
90
+ protectedUrl: string;
91
+ upstreamUrl: string;
92
+ tokenPath: string;
93
+ gatewayPid: number | null;
94
+ gatewayLogPath: string | null;
95
+ }
96
+ interface AppServerState {
97
+ url: string;
98
+ pid: number | null;
99
+ managed: boolean;
100
+ healthy: boolean;
101
+ lastCheckedAt: string;
102
+ lastHealthyAt: string | null;
103
+ logPath: string | null;
104
+ manualCommand: string;
105
+ auth?: AppServerAuthState | null;
106
+ }
86
107
  interface BridgeState {
87
108
  pid: number;
88
109
  statePath: string;
89
110
  lastHeartbeat: string;
111
+ appServer?: AppServerState | null;
112
+ /** Instance-specific daemon state dir (thread/heartbeat/processed markers). */
113
+ runtimeStateDir?: string | null;
90
114
  }
91
115
  /** Runtime instance state. Supports multiple instances per runtime (e.g. codex-reviewer, codex-builder). */
92
116
  interface InstanceState {
@@ -140,8 +164,8 @@ interface TapStateV1 {
140
164
  packageVersion: string;
141
165
  runtimes: Partial<Record<RuntimeName, RuntimeState>>;
142
166
  }
143
- type CommandName = "init" | "init-worktree" | "add" | "remove" | "status" | "serve" | "bridge" | "dashboard" | "unknown";
144
- 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_SERVE_NO_SERVER" | "TAP_SERVE_BUN_REQUIRED" | "TAP_REVIEW_START_OK" | "TAP_REVIEW_TERMINATED" | "TAP_INTERNAL_ERROR";
167
+ type CommandName = "init" | "init-worktree" | "add" | "remove" | "status" | "serve" | "bridge" | "up" | "down" | "comms" | "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_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";
145
169
  interface CommandResult<T = Record<string, unknown>> {
146
170
  ok: boolean;
147
171
  command: CommandName;
@@ -158,7 +182,7 @@ declare function loadState(repoRoot: string): TapState | null;
158
182
  declare function saveState(repoRoot: string, state: TapState): void;
159
183
  declare function createInitialState(commsDir: string, repoRoot: string, packageVersion: string): TapState;
160
184
 
161
- declare const version = "0.1.0";
185
+ declare const version: string;
162
186
 
163
187
  /**
164
188
  * Shared config (tap-config.json) — git tracked, repo-level defaults.
@@ -173,6 +197,8 @@ interface TapSharedConfig {
173
197
  runtimeCommand?: string;
174
198
  /** App server WebSocket URL for bridge connections. */
175
199
  appServerUrl?: string;
200
+ /** GitHub URL for the comms repository (used by `tap comms pull/push`). */
201
+ commsRepoUrl?: string;
176
202
  }
177
203
  /**
178
204
  * Local config (tap-config.local.json) — gitignored, machine-specific overrides.
@@ -190,7 +216,7 @@ interface TapResolvedConfig {
190
216
  appServerUrl: string;
191
217
  }
192
218
  /** Config resolution source for diagnostics. */
193
- type ConfigSource = "cli-flag" | "env" | "local-config" | "shared-config" | "auto";
219
+ type ConfigSource = "cli-flag" | "env" | "local-config" | "shared-config" | "legacy-shell-config" | "auto";
194
220
  interface ConfigResolution {
195
221
  config: TapResolvedConfig;
196
222
  sources: Record<keyof TapResolvedConfig, ConfigSource>;
@@ -228,6 +254,142 @@ declare function updateBridgeHeartbeat(stateDir: string, instanceId: InstanceId)
228
254
  */
229
255
  declare function getHeartbeatAge(stateDir: string, instanceId: InstanceId): number | null;
230
256
 
257
+ /**
258
+ * Dashboard data collection engine.
259
+ * Aggregates: agents (comms presence), bridges (state + PID), PRs (gh CLI).
260
+ *
261
+ * Ref: tap public repo tap-ops-dashboard.ps1 (single-agent view)
262
+ * M74 extends to control-tower view (all agents, all bridges, all PRs).
263
+ */
264
+ interface AgentInfo {
265
+ name: string;
266
+ status: string | null;
267
+ lastActivity: string | null;
268
+ joinedAt: string | null;
269
+ }
270
+ interface BridgeInfo {
271
+ instanceId: string;
272
+ runtime: string;
273
+ status: "running" | "stopped" | "stale";
274
+ pid: number | null;
275
+ port: number | null;
276
+ heartbeatAge: number | null;
277
+ headless: boolean;
278
+ }
279
+ interface PRInfo {
280
+ number: number;
281
+ title: string;
282
+ author: string;
283
+ state: string;
284
+ url: string;
285
+ }
286
+ interface DashboardWarning {
287
+ level: "warn" | "error";
288
+ message: string;
289
+ }
290
+ interface DashboardSnapshot {
291
+ generatedAt: string;
292
+ repoRoot: string;
293
+ commsDir: string;
294
+ agents: AgentInfo[];
295
+ bridges: BridgeInfo[];
296
+ prs: PRInfo[];
297
+ warnings: DashboardWarning[];
298
+ }
299
+ declare function collectDashboardSnapshot(repoRoot?: string, commsDirOverride?: string): DashboardSnapshot;
300
+
301
+ /**
302
+ * State/Control API — programmatic access to tap state.
303
+ * GUI and autopilot consume these functions instead of shelling out to CLI.
304
+ *
305
+ * M105 P1: getDashboardSnapshot, streamEvents (read-only)
306
+ * M105 P2: startAgents, stopAgents (write — wraps tap up/down)
307
+ */
308
+
309
+ interface StateApiOptions {
310
+ repoRoot?: string;
311
+ commsDir?: string;
312
+ }
313
+ /**
314
+ * Get a point-in-time snapshot of all tap state:
315
+ * agents, bridges, PRs, and warnings.
316
+ *
317
+ * This is the read-only entry point for GUI dashboards and autopilot.
318
+ */
319
+ declare function getDashboardSnapshot(options?: StateApiOptions): DashboardSnapshot;
320
+ interface EventStreamOptions extends StateApiOptions {
321
+ /** Poll interval in milliseconds (default: 2000) */
322
+ intervalMs?: number;
323
+ /** AbortSignal to stop the stream */
324
+ signal?: AbortSignal;
325
+ }
326
+ /**
327
+ * Async generator that yields dashboard snapshots at regular intervals.
328
+ * Useful for SSE or WebSocket push to GUI clients.
329
+ *
330
+ * Stops when the AbortSignal fires or the consumer breaks out.
331
+ */
332
+ declare function streamEvents(options?: EventStreamOptions): AsyncGenerator<DashboardSnapshot>;
333
+ interface AgentControlOptions {
334
+ /** Extra CLI args forwarded to `tap up` (e.g. `["--no-auth"]`) */
335
+ args?: string[];
336
+ }
337
+ interface AgentControlResult {
338
+ ok: boolean;
339
+ message: string;
340
+ snapshot: DashboardSnapshot;
341
+ commandResult: CommandResult;
342
+ }
343
+ /**
344
+ * Start all registered bridge daemons.
345
+ * Equivalent to `tap up [...args]`.
346
+ *
347
+ * Always operates on the cwd-based repo (same as CLI commands).
348
+ * Use read-only APIs (getDashboardSnapshot) for cross-repo queries.
349
+ */
350
+ declare function startAgents(options?: AgentControlOptions): Promise<AgentControlResult>;
351
+ /**
352
+ * Stop all running bridge daemons.
353
+ * Equivalent to `tap down`.
354
+ *
355
+ * Always operates on the cwd-based repo (same as CLI commands).
356
+ */
357
+ declare function stopAgents(): Promise<AgentControlResult>;
358
+ /**
359
+ * Resolve tap configuration for API consumers.
360
+ * Returns paths and settings without requiring CLI args.
361
+ */
362
+ declare function getConfig(options?: StateApiOptions): {
363
+ repoRoot: string;
364
+ commsDir: string;
365
+ stateDir: string;
366
+ appServerUrl: string;
367
+ };
368
+
369
+ /**
370
+ * Minimal HTTP transport for tap State API.
371
+ * localhost-only, no external dependencies (uses node:http).
372
+ *
373
+ * Endpoints:
374
+ * GET /api/snapshot — DashboardSnapshot JSON
375
+ * GET /api/events — SSE stream of snapshots
376
+ * GET /api/config — Resolved tap configuration
377
+ * GET /health — Health check
378
+ */
379
+
380
+ interface HttpServerOptions extends StateApiOptions {
381
+ /** Port to listen on (default: 4580) */
382
+ port?: number;
383
+ }
384
+ /**
385
+ * Start a localhost-only HTTP server for the tap State API.
386
+ * Resolves after the server is listening. Rejects on bind failure (e.g. EADDRINUSE).
387
+ */
388
+ declare function startHttpServer(options?: HttpServerOptions): Promise<{
389
+ port: number;
390
+ close: () => Promise<void>;
391
+ }>;
392
+
231
393
  /**
232
394
  * Common Node.js runtime resolver for all tap-comms child processes.
233
395
  *
@@ -269,4 +431,4 @@ declare function resolveNodeRuntime(configCommand: string, repoRoot: string): Re
269
431
  */
270
432
  declare function buildRuntimeEnv(repoRoot: string, baseEnv?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
271
433
 
272
- export { type AdapterContext, type ApplyResult, type ArtifactKind, type BridgeMode, type BridgeState, type CommandCode, type CommandName, type CommandResult, type ConfigOverrides, type ConfigResolution, type ConfigSource, type InstanceId, type InstanceState, LOCAL_CONFIG_FILE, type OwnedArtifact, type PatchOp, type PatchOpType, type PatchPlan, type Platform, type ProbeResult, type ResolvedRuntime, type RuntimeAdapter, type RuntimeName, type RuntimeSource, type RuntimeState, SHARED_CONFIG_FILE, type TapLocalConfig, type TapResolvedConfig, type TapSharedConfig, type TapState, type TapStateV1, type VerifyCheck, type VerifyResult, buildRuntimeEnv, createInitialState, getFnmBinDir, getHeartbeatAge, loadLocalConfig, loadSharedConfig, loadState, probeFnmNode, readNodeVersion, resolveConfig, resolveNodeRuntime, rotateLog, saveLocalConfig, saveSharedConfig, saveState, stateExists, updateBridgeHeartbeat, version };
434
+ 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 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, startAgents, startHttpServer, stateExists, stopAgents, streamEvents, updateBridgeHeartbeat, version };