@agentbridge1/cli 0.0.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.
Files changed (69) hide show
  1. package/bin/agentbridge.js +11 -0
  2. package/dist/acceptance-block.js +21 -0
  3. package/dist/acceptance-preflight.js +91 -0
  4. package/dist/api-client.js +6 -0
  5. package/dist/authority-request.js +25 -0
  6. package/dist/briefing.js +26 -0
  7. package/dist/bug-registry.js +350 -0
  8. package/dist/build-info.json +6 -0
  9. package/dist/canonical-state.js +11 -0
  10. package/dist/claimed-paths.js +42 -0
  11. package/dist/cli-failure-log.js +34 -0
  12. package/dist/commands/accept.js +241 -0
  13. package/dist/commands/attention.js +85 -0
  14. package/dist/commands/autopilot.js +93 -0
  15. package/dist/commands/bug.js +106 -0
  16. package/dist/commands/check.js +283 -0
  17. package/dist/commands/connect.js +159 -0
  18. package/dist/commands/dist-freshness.js +105 -0
  19. package/dist/commands/doctor.js +300 -0
  20. package/dist/commands/done.js +292 -0
  21. package/dist/commands/handoff.js +189 -0
  22. package/dist/commands/handshake.js +78 -0
  23. package/dist/commands/health.js +154 -0
  24. package/dist/commands/identity.js +57 -0
  25. package/dist/commands/init.js +5 -0
  26. package/dist/commands/memory.js +400 -0
  27. package/dist/commands/next.js +21 -0
  28. package/dist/commands/precommit-check.js +17 -0
  29. package/dist/commands/recover.js +116 -0
  30. package/dist/commands/session.js +229 -0
  31. package/dist/commands/setup-mcp.js +56 -0
  32. package/dist/commands/start.js +626 -0
  33. package/dist/commands/status.js +486 -0
  34. package/dist/commands/use.js +13 -0
  35. package/dist/commands/verify.js +264 -0
  36. package/dist/commands/version.js +32 -0
  37. package/dist/commands/watch.js +1718 -0
  38. package/dist/config.js +55 -0
  39. package/dist/domain-resolution.js +63 -0
  40. package/dist/error-catalog.js +494 -0
  41. package/dist/errors.js +276 -0
  42. package/dist/file-fingerprints.js +45 -0
  43. package/dist/gates.js +200 -0
  44. package/dist/git-evidence.js +285 -0
  45. package/dist/git-status.js +81 -0
  46. package/dist/http.js +151 -0
  47. package/dist/index.js +622 -0
  48. package/dist/init.js +458 -0
  49. package/dist/memory-context-render.js +51 -0
  50. package/dist/operator-snapshot.js +99 -0
  51. package/dist/precommit.js +72 -0
  52. package/dist/preflight-changed-files.js +109 -0
  53. package/dist/proof-guidance.js +110 -0
  54. package/dist/redact-secrets.js +15 -0
  55. package/dist/revert-crossing.js +73 -0
  56. package/dist/server-sync.js +433 -0
  57. package/dist/session-state.js +138 -0
  58. package/dist/session.js +89 -0
  59. package/dist/supervision.js +212 -0
  60. package/dist/terminal-ui.js +18 -0
  61. package/dist/test-runner.js +62 -0
  62. package/dist/types.js +2 -0
  63. package/dist/verification-conditions.js +185 -0
  64. package/dist/watch-core.js +208 -0
  65. package/dist/watch-packet-handshake.js +71 -0
  66. package/dist/watcher.js +62 -0
  67. package/dist/work-context-resolver.js +412 -0
  68. package/dist/work-contract.js +110 -0
  69. package/package.json +44 -0
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runSessionList = runSessionList;
4
+ exports.runSessionCleanupStale = runSessionCleanupStale;
5
+ exports.runSessionInspect = runSessionInspect;
6
+ exports.runSessionAbandon = runSessionAbandon;
7
+ const config_1 = require("../config");
8
+ const errors_1 = require("../errors");
9
+ const http_1 = require("../http");
10
+ const session_state_1 = require("../session-state");
11
+ const server_sync_1 = require("../server-sync");
12
+ const work_context_resolver_1 = require("../work-context-resolver");
13
+ function resolveNetworkContext() {
14
+ const cfg = (0, config_1.readConfig)();
15
+ const projectId = process.env.AGENTBRIDGE_PROJECT_ID ?? cfg.projectId;
16
+ const apiKey = process.env.AGENTBRIDGE_API_KEY ?? cfg.apiKey ?? "";
17
+ const apiBaseUrl = process.env.AGENTBRIDGE_BASE_URL ?? cfg.apiBaseUrl ?? "https://agentauth-api-production.up.railway.app";
18
+ if (!projectId || !apiKey) {
19
+ throw (0, errors_1.catalogCliError)("CONFIG_INCOMPLETE");
20
+ }
21
+ return { projectId, apiKey, apiBaseUrl };
22
+ }
23
+ async function fetchWorkSessionOrThrow(ctx, sessionId) {
24
+ try {
25
+ return await (0, server_sync_1.getWorkSession)(ctx, sessionId);
26
+ }
27
+ catch (err) {
28
+ if (err instanceof http_1.CliHttpError && err.status === 404) {
29
+ throw (0, errors_1.catalogCliError)("SESSION_SERVER_MISSING");
30
+ }
31
+ throw err;
32
+ }
33
+ }
34
+ function formatSessionRow(s) {
35
+ const cr = s.change_request_id?.trim() ?? "no CR";
36
+ const agent = s.work_identity_id?.trim() ?? "no identity";
37
+ return `${s.id} status=${s.status} CR=${cr} identity=${agent}`;
38
+ }
39
+ function toRelativeTime(timestamp) {
40
+ if (!timestamp)
41
+ return "unknown";
42
+ const when = Date.parse(timestamp);
43
+ if (!Number.isFinite(when))
44
+ return "unknown";
45
+ const deltaMs = Date.now() - when;
46
+ if (deltaMs < 0)
47
+ return "just now";
48
+ const minutes = Math.floor(deltaMs / 60_000);
49
+ if (minutes < 1)
50
+ return "just now";
51
+ if (minutes < 60)
52
+ return `${minutes}m ago`;
53
+ const hours = Math.floor(minutes / 60);
54
+ if (hours < 48)
55
+ return `${hours}h ago`;
56
+ const days = Math.floor(hours / 24);
57
+ return `${days}d ago`;
58
+ }
59
+ async function runSessionList(options) {
60
+ const ctx = resolveNetworkContext();
61
+ const cfg = (0, config_1.readConfig)();
62
+ const allSessions = await (0, server_sync_1.listWorkSessions)(ctx, { status: "all", crId: options.crId });
63
+ const activeSessions = allSessions.filter((s) => (0, work_context_resolver_1.isNonTerminalSessionStatus)(s.status));
64
+ const resolution = await (0, work_context_resolver_1.resolveWorkContext)(ctx, {
65
+ includeOtherActiveSessions: true,
66
+ useConfigActiveChangeRequestId: false,
67
+ changeRequestId: options.crId ?? undefined,
68
+ });
69
+ const currentSessionId = resolution.binding?.workSessionId ?? null;
70
+ const currentSession = currentSessionId
71
+ ? activeSessions.find((session) => session.id === currentSessionId) ?? null
72
+ : null;
73
+ const visibleOtherActive = resolution.otherActiveSessions.filter((session) => session.id !== currentSessionId);
74
+ if (options.json) {
75
+ process.stdout.write(`${JSON.stringify({
76
+ current_session: currentSession
77
+ ? {
78
+ id: currentSession.id,
79
+ change_request_id: resolution.binding?.changeRequestId ?? null,
80
+ status: currentSession.status,
81
+ updated_at: currentSession.updated_at,
82
+ }
83
+ : null,
84
+ other_active_sessions: visibleOtherActive,
85
+ last_accepted_session_id: cfg.lastAcceptedSessionId ?? null,
86
+ }, null, 2)}\n`);
87
+ return;
88
+ }
89
+ if (options.activeOnly && !currentSession && visibleOtherActive.length === 0) {
90
+ process.stdout.write("No active work sessions found.\n");
91
+ return;
92
+ }
93
+ const lines = [];
94
+ lines.push("Current session:");
95
+ if (!currentSessionId) {
96
+ lines.push("none");
97
+ }
98
+ else {
99
+ lines.push(`- ${currentSessionId} / ${resolution.binding?.changeRequestId ?? "no CR"} / ${currentSession?.status ?? "active"} / last seen ${toRelativeTime(currentSession?.updated_at)}`);
100
+ }
101
+ lines.push("");
102
+ lines.push("Other active sessions:");
103
+ if (visibleOtherActive.length === 0) {
104
+ lines.push("- none");
105
+ }
106
+ else {
107
+ for (const session of visibleOtherActive) {
108
+ lines.push(`- ${session.id} / ${session.change_request_id ?? "no CR"} / ${session.status} / last seen ${toRelativeTime(session.updated_at)}`);
109
+ }
110
+ }
111
+ lines.push("");
112
+ lines.push("Last accepted:");
113
+ lines.push(`- ${cfg.lastAcceptedSessionId ?? "none"}`);
114
+ process.stdout.write(`${lines.join("\n")}\n`);
115
+ }
116
+ async function runSessionCleanupStale(options) {
117
+ const ctx = resolveNetworkContext();
118
+ const cfg = (0, config_1.readConfig)();
119
+ const resolution = await (0, work_context_resolver_1.resolveWorkContext)(ctx, {
120
+ includeOtherActiveSessions: true,
121
+ useConfigActiveChangeRequestId: false,
122
+ });
123
+ const currentSessionId = resolution.binding?.workSessionId ?? null;
124
+ const staleCandidates = resolution.otherActiveSessions.filter((session) => session.id !== currentSessionId);
125
+ if (options.json) {
126
+ process.stdout.write(`${JSON.stringify({
127
+ dry_run: options.dryRun !== false,
128
+ current_session_id: currentSessionId,
129
+ stale_candidates: staleCandidates,
130
+ last_accepted_session_id: cfg.lastAcceptedSessionId ?? null,
131
+ }, null, 2)}\n`);
132
+ return;
133
+ }
134
+ const lines = [];
135
+ lines.push(options.dryRun === false ? "Session cleanup (live):" : "Session cleanup (dry-run):");
136
+ lines.push(`Current session: ${currentSessionId ?? "none"}`);
137
+ lines.push("");
138
+ lines.push("Other active sessions (candidates for manual close):");
139
+ if (staleCandidates.length === 0) {
140
+ lines.push("- none");
141
+ }
142
+ else {
143
+ for (const session of staleCandidates) {
144
+ lines.push(`- ${session.id} / ${session.change_request_id ?? "no CR"} / ${session.status} / last seen ${toRelativeTime(session.updated_at)}`);
145
+ }
146
+ }
147
+ lines.push("");
148
+ lines.push("To close a stale session:");
149
+ lines.push('- agentbridge session abandon --session <id> --reason "orphan cleanup from dry-run"');
150
+ process.stdout.write(`${lines.join("\n")}\n`);
151
+ }
152
+ async function runSessionInspect(sessionId, options) {
153
+ const id = sessionId.trim();
154
+ if (!id) {
155
+ throw (0, errors_1.catalogCliError)("SESSION_ID_REQUIRED");
156
+ }
157
+ const ctx = resolveNetworkContext();
158
+ const session = await fetchWorkSessionOrThrow(ctx, id);
159
+ const local = (0, session_state_1.readSessionState)();
160
+ if (options?.json) {
161
+ process.stdout.write(`${JSON.stringify({
162
+ session: {
163
+ id: session.id,
164
+ status: session.status,
165
+ change_request_id: session.change_request_id ?? null,
166
+ work_identity_id: session.work_identity_id ?? null,
167
+ execution_surface_id: session.execution_surface_id ?? null,
168
+ intent: session.intent ?? null,
169
+ created_at: session.created_at ?? null,
170
+ updated_at: session.updated_at ?? null,
171
+ },
172
+ local: {
173
+ linked: local?.serverSessionId === id,
174
+ server_session_id: local?.serverSessionId ?? null,
175
+ },
176
+ }, null, 2)}\n`);
177
+ return;
178
+ }
179
+ const lines = [
180
+ "WORK SESSION",
181
+ "----------------------------------------",
182
+ formatSessionRow(session),
183
+ `intent: ${session.intent ?? "(none)"}`,
184
+ `created: ${session.created_at ?? "(unknown)"}`,
185
+ `updated: ${session.updated_at ?? "(unknown)"}`,
186
+ `local linked: ${local?.serverSessionId === id ? "yes" : "no"}`,
187
+ ];
188
+ process.stdout.write(`${lines.join("\n")}\n`);
189
+ }
190
+ async function runSessionAbandon(args) {
191
+ const reason = args.reason.trim();
192
+ if (reason.length < 8) {
193
+ throw (0, errors_1.catalogCliError)("SESSION_ABANDON_REASON_REQUIRED");
194
+ }
195
+ const ctx = resolveNetworkContext();
196
+ const local = (0, session_state_1.readSessionState)();
197
+ const targetId = (args.sessionId?.trim() || local?.serverSessionId?.trim() || "").trim();
198
+ if (!targetId) {
199
+ throw (0, errors_1.catalogCliError)("SESSION_NO_TARGET");
200
+ }
201
+ const result = await (0, server_sync_1.cancelWorkSession)(ctx, targetId, reason);
202
+ const shouldClearLocal = args.clearLocal !== false && local?.serverSessionId === targetId;
203
+ const localUnchangedDifferentSession = Boolean(local?.serverSessionId && local.serverSessionId !== targetId);
204
+ if (args.json) {
205
+ process.stdout.write(`${JSON.stringify({
206
+ cancelled_session: {
207
+ id: result.id,
208
+ status: result.status,
209
+ },
210
+ local_state: shouldClearLocal
211
+ ? { action: "cleared", server_session_id: null }
212
+ : localUnchangedDifferentSession
213
+ ? { action: "unchanged", server_session_id: local?.serverSessionId ?? null }
214
+ : { action: "none", server_session_id: local?.serverSessionId ?? null },
215
+ }, null, 2)}\n`);
216
+ if (shouldClearLocal) {
217
+ (0, session_state_1.clearSessionState)();
218
+ }
219
+ return;
220
+ }
221
+ process.stdout.write(`Cancelled work session ${result.id} (status: ${result.status}).\n`);
222
+ if (shouldClearLocal) {
223
+ (0, session_state_1.clearSessionState)();
224
+ process.stdout.write("Cleared local session state.\n");
225
+ }
226
+ else if (localUnchangedDifferentSession) {
227
+ process.stdout.write(`Local session still points at ${local?.serverSessionId ?? "unknown"} (unchanged).\n`);
228
+ }
229
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runSetupMcp = runSetupMcp;
4
+ const config_1 = require("../config");
5
+ const MCP_SERVER_NAME = "agentbridge";
6
+ function standardSnippet(projectId, apiKey, apiBaseUrl) {
7
+ const serverConfig = {
8
+ command: "agentbridge",
9
+ args: ["mcp"],
10
+ env: {
11
+ AGENTBRIDGE_PROJECT_ID: projectId,
12
+ AGENTBRIDGE_API_KEY: apiKey,
13
+ AGENTBRIDGE_BASE_URL: apiBaseUrl,
14
+ },
15
+ };
16
+ return JSON.stringify({ [MCP_SERVER_NAME]: serverConfig }, null, 2);
17
+ }
18
+ async function runSetupMcp(options = {}) {
19
+ const cfg = (0, config_1.readConfig)();
20
+ const projectId = process.env.AGENTBRIDGE_PROJECT_ID ?? cfg.projectId ?? "<your-project-id>";
21
+ const apiKey = process.env.AGENTBRIDGE_API_KEY ?? cfg.apiKey ?? "<your-api-key>";
22
+ const apiBaseUrl = process.env.AGENTBRIDGE_BASE_URL ??
23
+ cfg.apiBaseUrl ??
24
+ "https://agentauth-api-production.up.railway.app";
25
+ const editor = options.editor ?? "cursor";
26
+ process.stdout.write("\nAgentBridge MCP Setup\n");
27
+ process.stdout.write("─────────────────────────────────────────\n\n");
28
+ if (editor === "cursor") {
29
+ process.stdout.write("Add this to your ~/.cursor/mcp.json (or project-level .cursor/mcp.json):\n\n");
30
+ }
31
+ else if (editor === "windsurf") {
32
+ process.stdout.write("Add this to your ~/.codeium/windsurf/mcp_config.json:\n\n");
33
+ }
34
+ else if (editor === "vscode") {
35
+ process.stdout.write("Add this to your .vscode/mcp.json:\n\n");
36
+ }
37
+ else {
38
+ process.stdout.write(`Add this to your ${editor} MCP config:\n\n`);
39
+ }
40
+ process.stdout.write("Recommended config:\n\n");
41
+ process.stdout.write(JSON.stringify({
42
+ mcpServers: JSON.parse(standardSnippet(projectId, apiKey, apiBaseUrl)),
43
+ }, null, 2) + "\n");
44
+ if (projectId === "<your-project-id>" || apiKey === "<your-api-key>") {
45
+ process.stdout.write("\n⚠ Credentials not found. Run `agentbridge connect` first to save your project ID and API key.\n");
46
+ }
47
+ else {
48
+ process.stdout.write("\n✓ Credentials filled from .agentbridge/config.json\n");
49
+ }
50
+ process.stdout.write([
51
+ "",
52
+ "After saving the config, restart your editor to activate the MCP server.",
53
+ "The MCP server lets your AI assistant call tools like agent_hello, check AgentBridge status, and trigger approvals.",
54
+ "",
55
+ ].join("\n"));
56
+ }