@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,264 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runVerify = runVerify;
4
+ const node_child_process_1 = require("node:child_process");
5
+ const config_1 = require("../config");
6
+ const errors_1 = require("../errors");
7
+ const error_catalog_1 = require("../error-catalog");
8
+ const session_state_1 = require("../session-state");
9
+ const server_sync_1 = require("../server-sync");
10
+ const file_fingerprints_1 = require("../file-fingerprints");
11
+ const git_status_1 = require("../git-status");
12
+ const operator_snapshot_1 = require("../operator-snapshot");
13
+ const work_context_resolver_1 = require("../work-context-resolver");
14
+ const verification_conditions_1 = require("../verification-conditions");
15
+ const MAX_EXCERPT_CHARS = 8000;
16
+ function resolveNetworkContext() {
17
+ const cfg = (0, config_1.readConfig)();
18
+ const projectId = process.env.AGENTBRIDGE_PROJECT_ID ?? cfg.projectId;
19
+ const apiKey = process.env.AGENTBRIDGE_API_KEY ?? cfg.apiKey ?? "";
20
+ const apiBaseUrl = process.env.AGENTBRIDGE_BASE_URL ?? cfg.apiBaseUrl ?? "https://agentauth-api-production.up.railway.app";
21
+ if (!projectId || !apiKey) {
22
+ throw (0, errors_1.catalogCliError)("CONFIG_INCOMPLETE");
23
+ }
24
+ return { projectId, apiKey, apiBaseUrl };
25
+ }
26
+ function excerpt(text) {
27
+ if (text.length <= MAX_EXCERPT_CHARS)
28
+ return text;
29
+ return text.slice(-MAX_EXCERPT_CHARS);
30
+ }
31
+ function currentGitHead() {
32
+ try {
33
+ return (0, node_child_process_1.execFileSync)("git", ["rev-parse", "HEAD"], {
34
+ stdio: ["ignore", "pipe", "ignore"],
35
+ encoding: "utf8",
36
+ }).trim();
37
+ }
38
+ catch {
39
+ return "";
40
+ }
41
+ }
42
+ function normalizeChangedFiles(files) {
43
+ return [...new Set(files.map((file) => file.trim()).filter((file) => file.length > 0))].sort();
44
+ }
45
+ function repoDirtySnapshot() {
46
+ return (0, git_status_1.repoDirtySnapshotFromGitStatus)();
47
+ }
48
+ async function preflightSyncLocalChangedFiles(ctx, workSessionId) {
49
+ const state = (0, session_state_1.readSessionState)();
50
+ if (!state)
51
+ return [];
52
+ const changedFiles = normalizeChangedFiles(state.changedFiles ?? []);
53
+ if (changedFiles.length === 0)
54
+ return [];
55
+ const fingerprints = (0, file_fingerprints_1.computeFileFingerprints)(changedFiles);
56
+ const fpMap = new Map(fingerprints.map((fp) => [fp.path, fp.sha256 ?? fp.mtimeMs?.toString() ?? ""]));
57
+ const nextHash = changedFiles.map((f) => `${f}:${fpMap.get(f) ?? ""}`).join("\n");
58
+ if (state.lastSyncedChangedFilesHash !== nextHash) {
59
+ await (0, server_sync_1.postObservedDiff)(ctx, { workSessionId }, {
60
+ activeLaneDomain: state.laneDomain ?? null,
61
+ changedFiles,
62
+ boundaryCrossings: [],
63
+ fileFingerprints: fingerprints,
64
+ });
65
+ state.lastSyncedChangedFilesHash = nextHash;
66
+ (0, session_state_1.writeSessionState)(state);
67
+ }
68
+ return changedFiles;
69
+ }
70
+ async function execute(command) {
71
+ return new Promise((resolve) => {
72
+ const child = (0, node_child_process_1.spawn)(command, {
73
+ shell: true,
74
+ stdio: ["ignore", "pipe", "pipe"],
75
+ env: process.env,
76
+ });
77
+ let stdout = "";
78
+ let stderr = "";
79
+ child.stdout.on("data", (chunk) => {
80
+ stdout += chunk.toString();
81
+ });
82
+ child.stderr.on("data", (chunk) => {
83
+ stderr += chunk.toString();
84
+ });
85
+ child.on("close", (code) => {
86
+ resolve({ exitCode: code ?? 1, stdout, stderr });
87
+ });
88
+ child.on("error", (err) => {
89
+ stderr += `${err instanceof Error ? err.message : String(err)}\n`;
90
+ resolve({ exitCode: 1, stdout, stderr });
91
+ });
92
+ });
93
+ }
94
+ function renderProtocolWarnings(warnings) {
95
+ if (warnings.length === 0)
96
+ return [];
97
+ return [
98
+ "Protocol warnings:",
99
+ ...warnings.map((warning) => `- ${warning.code}: ${warning.message}`),
100
+ ];
101
+ }
102
+ async function runVerify(commandInput, options = {}) {
103
+ process.exitCode = 0;
104
+ const command = commandInput.trim();
105
+ if (!command) {
106
+ throw (0, errors_1.catalogCliError)("VERIFY_COMMAND_REQUIRED");
107
+ }
108
+ const ctx = resolveNetworkContext();
109
+ const resolution = await (0, work_context_resolver_1.resolveWorkContext)(ctx, {
110
+ useConfigActiveChangeRequestId: false,
111
+ includeOtherActiveSessions: true,
112
+ });
113
+ if (resolution.state !== "current_session_resolved" || !resolution.binding) {
114
+ const workContextErr = (0, errors_1.catalogCliError)((0, error_catalog_1.workContextStateToCode)(resolution.state));
115
+ if (options.json) {
116
+ const snapshot = (0, operator_snapshot_1.buildOperatorSnapshot)(resolution);
117
+ process.stdout.write(`${JSON.stringify({
118
+ snapshot,
119
+ verification_recorded: false,
120
+ next_action: [
121
+ 'run agentbridge start --summary "<work>" --scope "<path>"',
122
+ "run agentbridge watch --allow-dirty",
123
+ ],
124
+ }, null, 2)}\n`);
125
+ process.stderr.write(`${(0, errors_1.renderCliError)(workContextErr)}\n`);
126
+ process.exitCode = 1;
127
+ return;
128
+ }
129
+ process.stdout.write(`${[
130
+ ...(0, work_context_resolver_1.renderWorkContextLines)(resolution),
131
+ "",
132
+ "Verification was not recorded.",
133
+ "",
134
+ "Next action:",
135
+ '- run agentbridge start --summary "<work>" --scope "<path>"',
136
+ "- or run agentbridge watch --allow-dirty",
137
+ ].join("\n")}\n`);
138
+ process.stderr.write(`${(0, errors_1.renderCliError)(workContextErr)}\n`);
139
+ process.exitCode = 1;
140
+ return;
141
+ }
142
+ const { workSessionId } = (0, work_context_resolver_1.requireWorkContextBinding)(resolution, "verify");
143
+ const startedAt = new Date().toISOString();
144
+ const run = await execute(command);
145
+ const finishedAt = new Date().toISOString();
146
+ const status = run.exitCode === 0 ? "passed" : "failed";
147
+ let localSessionChangedFiles = [];
148
+ try {
149
+ localSessionChangedFiles = await preflightSyncLocalChangedFiles(ctx, workSessionId);
150
+ }
151
+ catch {
152
+ localSessionChangedFiles = [];
153
+ }
154
+ let acceptanceChangedFiles = [];
155
+ try {
156
+ const report = await (0, server_sync_1.fetchAcceptanceCheck)(ctx, { workSessionId });
157
+ acceptanceChangedFiles = normalizeChangedFiles(report.changed_files ?? []);
158
+ }
159
+ catch {
160
+ acceptanceChangedFiles = [];
161
+ }
162
+ const dirtySnapshot = repoDirtySnapshot();
163
+ const proofScopeFiles = acceptanceChangedFiles.length > 0
164
+ ? acceptanceChangedFiles
165
+ : localSessionChangedFiles.length > 0
166
+ ? localSessionChangedFiles
167
+ : dirtySnapshot;
168
+ const proofScopeSource = acceptanceChangedFiles.length > 0
169
+ ? "acceptance_check"
170
+ : localSessionChangedFiles.length > 0
171
+ ? "local_session"
172
+ : "dirty_snapshot_fallback";
173
+ const proofScopeFingerprints = (0, file_fingerprints_1.computeFileFingerprints)(proofScopeFiles);
174
+ const conditions = (0, verification_conditions_1.analyzeVerificationCommand)({
175
+ command,
176
+ proofScopeFiles,
177
+ proofScopeSource,
178
+ serverBacked: true,
179
+ });
180
+ const confidence = (0, verification_conditions_1.buildVerificationConfidence)({ status, conditions });
181
+ await (0, server_sync_1.postVerificationRun)(ctx, { workSessionId }, {
182
+ command,
183
+ startedAt,
184
+ finishedAt,
185
+ exitCode: run.exitCode,
186
+ stdoutExcerpt: excerpt(run.stdout),
187
+ stderrExcerpt: excerpt(run.stderr),
188
+ gitHead: currentGitHead(),
189
+ changedFilesSnapshot: proofScopeFiles,
190
+ proofScopeFiles,
191
+ proofScopeSource,
192
+ repoDirtySnapshot: dirtySnapshot,
193
+ proofScopeFingerprints,
194
+ status,
195
+ conditions,
196
+ confidence,
197
+ });
198
+ let protocolWarnings = [];
199
+ let latestReport = null;
200
+ try {
201
+ const report = await (0, server_sync_1.fetchAcceptanceCheck)(ctx, { workSessionId });
202
+ latestReport = report;
203
+ protocolWarnings = report.protocol_warnings ?? [];
204
+ const warnings = renderProtocolWarnings(protocolWarnings);
205
+ if (warnings.length > 0) {
206
+ process.stdout.write(`${warnings.join("\n")}\n`);
207
+ }
208
+ }
209
+ catch {
210
+ // Verification recording is authoritative; warning fetch is best-effort.
211
+ }
212
+ if (options.json) {
213
+ const report = latestReport ?? (await (0, server_sync_1.fetchAcceptanceCheck)(ctx, { workSessionId }));
214
+ const snapshot = (0, operator_snapshot_1.buildOperatorSnapshot)({
215
+ ...resolution,
216
+ binding: {
217
+ workSessionId,
218
+ changeRequestId: report.change_request_id ?? null,
219
+ report,
220
+ },
221
+ resolvedServerSessionId: report.work_session_id,
222
+ resolvedChangeRequestId: report.change_request_id ?? null,
223
+ });
224
+ process.stdout.write(`${JSON.stringify({
225
+ snapshot,
226
+ verification: {
227
+ work_session_id: workSessionId,
228
+ command,
229
+ status,
230
+ exit_code: run.exitCode,
231
+ proof_scope_source: proofScopeSource,
232
+ proof_scope_files: proofScopeFiles,
233
+ confidence,
234
+ conditions,
235
+ protocol_warnings: protocolWarnings,
236
+ },
237
+ }, null, 2)}\n`);
238
+ return;
239
+ }
240
+ if (status === "passed") {
241
+ const confidenceLines = (0, verification_conditions_1.renderConfidenceSummary)(confidence);
242
+ const hygieneWarning = (0, verification_conditions_1.renderMockHygieneWarning)(conditions.mock_hygiene);
243
+ process.stdout.write([
244
+ "Verification passed.",
245
+ `Command: ${command}`,
246
+ `Attached to run: ${workSessionId}`,
247
+ ...confidenceLines,
248
+ ...(hygieneWarning ? [hygieneWarning] : []),
249
+ "Run agentbridge check to review the watch result.",
250
+ ].join("\n") + "\n");
251
+ return;
252
+ }
253
+ process.stdout.write([
254
+ "Verification failed.",
255
+ `Command: ${command}`,
256
+ `Exit code: ${run.exitCode}`,
257
+ `Attached to run: ${workSessionId}`,
258
+ "Run agentbridge check to review failed proof.",
259
+ ].join("\n") + "\n");
260
+ process.stderr.write(`${(0, errors_1.renderCliError)((0, errors_1.catalogCliError)("VERIFY_COMMAND_FAILED", {
261
+ what: `Verification command "${command}" failed with exit code ${run.exitCode}.`,
262
+ }))}\n`);
263
+ process.exitCode = 1;
264
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runVersion = runVersion;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ const dist_freshness_1 = require("./dist-freshness");
7
+ function cliRootFromCommandDir() {
8
+ // src/commands/version.ts -> cli/
9
+ return (0, node_path_1.resolve)(__dirname, "..", "..");
10
+ }
11
+ function runVersion(cliRootOverride) {
12
+ const cliRoot = cliRootOverride ?? cliRootFromCommandDir();
13
+ const packageJsonPath = (0, node_path_1.resolve)(cliRoot, "package.json");
14
+ const pkg = JSON.parse((0, node_fs_1.readFileSync)(packageJsonPath, "utf8"));
15
+ const freshness = (0, dist_freshness_1.getDistFreshnessReport)(cliRoot);
16
+ const lines = [];
17
+ lines.push(`agentbridge cli ${pkg?.version ? `v${pkg.version}` : "(version unknown)"}`);
18
+ lines.push(`CLI dist: ${freshness.state}`);
19
+ lines.push(`Build timestamp: ${freshness.builtAt ?? "unknown"}`);
20
+ lines.push(`Git head: ${freshness.gitHead ?? "unknown"}`);
21
+ lines.push(`Source newer than dist: ${freshness.sourceNewerThanDist}`);
22
+ if (freshness.sourceLatestFile || freshness.sourceLatestMtime) {
23
+ lines.push(`Built from source snapshot: ${freshness.sourceLatestFile ?? "unknown"} @ ${freshness.sourceLatestMtime ?? "unknown"}`);
24
+ }
25
+ if (freshness.reason) {
26
+ lines.push(`Reason: ${freshness.reason}`);
27
+ }
28
+ if (freshness.state === "stale") {
29
+ lines.push("CLI dist appears stale. Run: npm run build:cli");
30
+ }
31
+ process.stdout.write(`${lines.join("\n")}\n`);
32
+ }