@saptools/service-flow 0.1.65 → 0.1.67

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 (42) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +67 -11
  3. package/TECHNICAL-NOTE.md +41 -1
  4. package/dist/{chunk-OONNRIDL.js → chunk-ZQABU7MR.js} +3764 -643
  5. package/dist/chunk-ZQABU7MR.js.map +1 -0
  6. package/dist/cli.js +158 -295
  7. package/dist/cli.js.map +1 -1
  8. package/dist/index.d.ts +196 -1
  9. package/dist/index.js +7 -3
  10. package/dist/index.js.map +1 -1
  11. package/package.json +1 -1
  12. package/src/cli/002-doctor-lifecycle.ts +66 -0
  13. package/src/cli/doctor.ts +14 -27
  14. package/src/cli.ts +130 -102
  15. package/src/db/000-call-fact-repository.ts +537 -0
  16. package/src/db/001-fact-lifecycle.ts +111 -0
  17. package/src/db/migrations.ts +16 -1
  18. package/src/db/repositories.ts +1 -315
  19. package/src/db/schema.ts +4 -2
  20. package/src/index.ts +22 -0
  21. package/src/linker/004-event-subscription-handler-linker.ts +300 -0
  22. package/src/linker/cross-repo-linker.ts +23 -2
  23. package/src/output/001-compact-json-output.ts +6 -0
  24. package/src/parsers/imported-wrapper-parser.ts +4 -0
  25. package/src/parsers/outbound-call-parser.ts +11 -1
  26. package/src/parsers/symbol-parser.ts +7 -4
  27. package/src/trace/010-traversal-scope.ts +188 -0
  28. package/src/trace/011-event-subscriber-traversal.ts +366 -0
  29. package/src/trace/012-trace-graph-lookups.ts +74 -0
  30. package/src/trace/013-trace-root-scopes.ts +279 -0
  31. package/src/trace/014-compact-contract.ts +347 -0
  32. package/src/trace/015-trace-edge-recorder.ts +336 -0
  33. package/src/trace/016-compact-projector.ts +697 -0
  34. package/src/trace/017-trace-context.ts +378 -0
  35. package/src/trace/018-compact-trace.ts +87 -0
  36. package/src/trace/019-trace-edge-semantics.ts +328 -0
  37. package/src/trace/020-compact-field-projection.ts +387 -0
  38. package/src/trace/dynamic-branches.ts +35 -13
  39. package/src/trace/trace-engine.ts +271 -245
  40. package/src/types.ts +10 -0
  41. package/src/version.ts +1 -1
  42. package/dist/chunk-OONNRIDL.js.map +0 -1
package/dist/cli.js CHANGED
@@ -1,10 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ ANALYZER_VERSION,
4
+ VERSION,
3
5
  classifyODataPathIntent,
4
6
  classifyOutboundCallsInSource,
5
7
  clearRepoFacts,
8
+ compactTrace,
6
9
  containsSupportedOutboundCall,
7
10
  discoverRepositories,
11
+ factLifecycleDiagnostic,
8
12
  getWorkspace,
9
13
  handlerMethodIsExecutable,
10
14
  implementationHintSuggestions,
@@ -20,6 +24,7 @@ import {
20
24
  listRepositories,
21
25
  loadPackageJsonSnapshot,
22
26
  loadRepositorySourceContext,
27
+ migrate,
23
28
  normalizeODataOperationInvocationPath,
24
29
  normalizePath,
25
30
  parseCdsFile,
@@ -31,15 +36,16 @@ import {
31
36
  parseServiceBindings,
32
37
  parseVars,
33
38
  projectBoundedInOrder,
39
+ redactValue,
34
40
  reposByName,
35
41
  selectorRepoAmbiguousDiagnostic,
36
42
  trace,
37
43
  upsertRepository,
38
44
  upsertWorkspace
39
- } from "./chunk-OONNRIDL.js";
45
+ } from "./chunk-ZQABU7MR.js";
40
46
 
41
47
  // src/cli.ts
42
- import { Command } from "commander";
48
+ import { Command, Option } from "commander";
43
49
 
44
50
  // src/config/defaults.ts
45
51
  var DEFAULT_IGNORES = [
@@ -109,212 +115,6 @@ function createWorkspaceConfig(rootPath, dbPath, ignore = [...DEFAULT_IGNORES])
109
115
  // src/db/connection.ts
110
116
  import fs2 from "fs";
111
117
  import path2 from "path";
112
-
113
- // src/db/schema.ts
114
- var schemaTablesSql = `
115
- CREATE TABLE IF NOT EXISTS workspaces (id INTEGER PRIMARY KEY, root_path TEXT UNIQUE NOT NULL, db_path TEXT NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL);
116
- CREATE TABLE IF NOT EXISTS repositories (id INTEGER PRIMARY KEY, workspace_id INTEGER NOT NULL, name TEXT NOT NULL, absolute_path TEXT NOT NULL, relative_path TEXT NOT NULL, package_name TEXT, package_version TEXT, dependencies_json TEXT DEFAULT '{}', kind TEXT NOT NULL, is_git_repo INTEGER NOT NULL, last_indexed_at TEXT, index_status TEXT DEFAULT 'pending', error_count INTEGER DEFAULT 0, fingerprint TEXT, fact_generation INTEGER NOT NULL DEFAULT 0, graph_generation INTEGER NOT NULL DEFAULT 0, graph_stale_reason TEXT, graph_stale_at TEXT, fact_analyzer_version TEXT, UNIQUE(workspace_id, absolute_path), FOREIGN KEY(workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE);
117
- CREATE TABLE IF NOT EXISTS files (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, relative_path TEXT NOT NULL, extension TEXT NOT NULL, sha256 TEXT NOT NULL, size_bytes INTEGER NOT NULL, last_indexed_at TEXT NOT NULL, UNIQUE(repo_id, relative_path), FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE);
118
- CREATE TABLE IF NOT EXISTS cds_requires (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, alias TEXT NOT NULL, kind TEXT, model TEXT, destination TEXT, service_path TEXT, request_timeout INTEGER, raw_json TEXT NOT NULL, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE);
119
- CREATE TABLE IF NOT EXISTS cds_services (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, namespace TEXT, service_name TEXT NOT NULL, qualified_name TEXT NOT NULL, service_path TEXT NOT NULL, is_extend INTEGER NOT NULL, source_file TEXT NOT NULL, source_line INTEGER NOT NULL, extension_local_ref TEXT, extension_imported_symbol TEXT, extension_local_alias TEXT, extension_module_specifier TEXT, extension_import_kind TEXT, extension_base_service_id INTEGER, extension_base_status TEXT, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(extension_base_service_id) REFERENCES cds_services(id) ON DELETE SET NULL);
120
- CREATE TABLE IF NOT EXISTS cds_operations (id INTEGER PRIMARY KEY, service_id INTEGER NOT NULL, operation_type TEXT NOT NULL, operation_name TEXT NOT NULL, operation_path TEXT NOT NULL, params_json TEXT NOT NULL, return_type TEXT, source_file TEXT NOT NULL, source_line INTEGER NOT NULL, provenance TEXT NOT NULL DEFAULT 'direct', base_operation_id INTEGER, FOREIGN KEY(service_id) REFERENCES cds_services(id) ON DELETE CASCADE, FOREIGN KEY(base_operation_id) REFERENCES cds_operations(id) ON DELETE SET NULL);
121
- CREATE TABLE IF NOT EXISTS symbols (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, file_id INTEGER, kind TEXT NOT NULL, name TEXT NOT NULL, qualified_name TEXT NOT NULL, exported INTEGER NOT NULL, start_line INTEGER NOT NULL, end_line INTEGER NOT NULL, start_offset INTEGER, end_offset INTEGER, source_file TEXT, exported_name TEXT, evidence_json TEXT, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(file_id) REFERENCES files(id) ON DELETE CASCADE);
122
- CREATE TABLE IF NOT EXISTS handler_classes (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, symbol_id INTEGER, class_name TEXT NOT NULL, source_file TEXT NOT NULL, source_line INTEGER NOT NULL, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(symbol_id) REFERENCES symbols(id) ON DELETE SET NULL);
123
- CREATE TABLE IF NOT EXISTS handler_methods (id INTEGER PRIMARY KEY, handler_class_id INTEGER NOT NULL, method_name TEXT NOT NULL, decorator_kind TEXT NOT NULL, decorator_value TEXT, decorator_raw_expression TEXT NOT NULL, decorator_resolution_json TEXT NOT NULL DEFAULT '{}', source_file TEXT NOT NULL, source_line INTEGER NOT NULL, FOREIGN KEY(handler_class_id) REFERENCES handler_classes(id) ON DELETE CASCADE);
124
- CREATE TABLE IF NOT EXISTS handler_registrations (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, handler_class_id INTEGER, class_name TEXT, import_source TEXT, registration_file TEXT NOT NULL, registration_line INTEGER NOT NULL, registration_kind TEXT NOT NULL, confidence REAL NOT NULL, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(handler_class_id) REFERENCES handler_classes(id) ON DELETE SET NULL);
125
- CREATE TABLE IF NOT EXISTS service_bindings (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, symbol_id INTEGER, variable_name TEXT NOT NULL, alias TEXT, alias_expr TEXT, destination_expr TEXT, service_path_expr TEXT, is_dynamic INTEGER NOT NULL, placeholders_json TEXT NOT NULL, source_file TEXT NOT NULL, source_line INTEGER NOT NULL, helper_chain_json TEXT, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(symbol_id) REFERENCES symbols(id) ON DELETE SET NULL);
126
- CREATE TABLE IF NOT EXISTS outbound_calls (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, source_symbol_id INTEGER, call_type TEXT NOT NULL, service_binding_id INTEGER, method TEXT, operation_path_expr TEXT, query_entity TEXT, event_name_expr TEXT, payload_summary TEXT, source_file TEXT NOT NULL, source_line INTEGER NOT NULL, confidence REAL NOT NULL, unresolved_reason TEXT, local_service_name TEXT, local_service_lookup TEXT, alias_chain_json TEXT, evidence_json TEXT, external_target_kind TEXT, external_target_id TEXT, external_target_label TEXT, external_target_dynamic INTEGER NOT NULL DEFAULT 0, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(source_symbol_id) REFERENCES symbols(id) ON DELETE SET NULL, FOREIGN KEY(service_binding_id) REFERENCES service_bindings(id) ON DELETE SET NULL);
127
- CREATE TABLE IF NOT EXISTS symbol_calls (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, caller_symbol_id INTEGER NOT NULL, callee_symbol_id INTEGER, callee_expression TEXT NOT NULL, import_source TEXT, source_file TEXT NOT NULL, source_line INTEGER NOT NULL, status TEXT NOT NULL, confidence REAL NOT NULL, evidence_json TEXT NOT NULL, unresolved_reason TEXT, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(caller_symbol_id) REFERENCES symbols(id) ON DELETE CASCADE, FOREIGN KEY(callee_symbol_id) REFERENCES symbols(id) ON DELETE SET NULL);
128
- CREATE TABLE IF NOT EXISTS graph_edges (id INTEGER PRIMARY KEY, workspace_id INTEGER NOT NULL, edge_type TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'unresolved', from_kind TEXT NOT NULL, from_id TEXT NOT NULL, to_kind TEXT NOT NULL, to_id TEXT NOT NULL, confidence REAL NOT NULL, evidence_json TEXT NOT NULL, is_dynamic INTEGER NOT NULL, unresolved_reason TEXT, generation INTEGER NOT NULL DEFAULT 0, FOREIGN KEY(workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE);
129
- CREATE TABLE IF NOT EXISTS index_runs (id INTEGER PRIMARY KEY, workspace_id INTEGER NOT NULL, started_at TEXT NOT NULL, finished_at TEXT, status TEXT NOT NULL, repo_count INTEGER NOT NULL, file_count INTEGER NOT NULL, diagnostic_count INTEGER NOT NULL, error_message TEXT, owner_pid INTEGER, FOREIGN KEY(workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE);
130
- CREATE TABLE IF NOT EXISTS diagnostics (id INTEGER PRIMARY KEY, repo_id INTEGER, file_id INTEGER, severity TEXT NOT NULL, code TEXT NOT NULL, message TEXT NOT NULL, source_file TEXT, source_line INTEGER, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(file_id) REFERENCES files(id) ON DELETE SET NULL);
131
- `;
132
- var schemaIndexesSql = `
133
- CREATE INDEX IF NOT EXISTS idx_repo_name ON repositories(name);
134
- CREATE INDEX IF NOT EXISTS idx_service_path ON cds_services(service_path);
135
- CREATE INDEX IF NOT EXISTS idx_extension_import ON cds_services(extension_module_specifier, extension_imported_symbol, is_extend);
136
- CREATE INDEX IF NOT EXISTS idx_operation_name ON cds_operations(operation_name, operation_path);
137
- CREATE INDEX IF NOT EXISTS idx_operation_base ON cds_operations(base_operation_id);
138
- CREATE INDEX IF NOT EXISTS idx_calls_repo ON outbound_calls(repo_id, call_type);
139
- CREATE INDEX IF NOT EXISTS idx_symbol_calls_caller ON symbol_calls(repo_id, caller_symbol_id);
140
- CREATE VIRTUAL TABLE IF NOT EXISTS search_index USING fts5(kind, name, path, repo);
141
- `;
142
- var schemaSql = `${schemaTablesSql}
143
- ${schemaIndexesSql}`;
144
-
145
- // src/db/migrations.ts
146
- var CURRENT_SCHEMA_VERSION = 11;
147
- var columns = {
148
- handler_methods: [
149
- { name: "decorator_resolution_json", ddl: "ALTER TABLE handler_methods ADD COLUMN decorator_resolution_json TEXT NOT NULL DEFAULT '{}'" }
150
- ],
151
- service_bindings: [
152
- { name: "helper_chain_json", ddl: "ALTER TABLE service_bindings ADD COLUMN helper_chain_json TEXT" },
153
- { name: "alias_expr", ddl: "ALTER TABLE service_bindings ADD COLUMN alias_expr TEXT" }
154
- ],
155
- repositories: [
156
- { name: "fingerprint", ddl: "ALTER TABLE repositories ADD COLUMN fingerprint TEXT" },
157
- { name: "fact_generation", ddl: "ALTER TABLE repositories ADD COLUMN fact_generation INTEGER NOT NULL DEFAULT 0" },
158
- { name: "graph_generation", ddl: "ALTER TABLE repositories ADD COLUMN graph_generation INTEGER NOT NULL DEFAULT 0" },
159
- { name: "graph_stale_reason", ddl: "ALTER TABLE repositories ADD COLUMN graph_stale_reason TEXT" },
160
- { name: "graph_stale_at", ddl: "ALTER TABLE repositories ADD COLUMN graph_stale_at TEXT" },
161
- { name: "fact_analyzer_version", ddl: "ALTER TABLE repositories ADD COLUMN fact_analyzer_version TEXT DEFAULT 'legacy'" }
162
- ],
163
- graph_edges: [
164
- { name: "status", ddl: "ALTER TABLE graph_edges ADD COLUMN status TEXT NOT NULL DEFAULT 'unresolved'" },
165
- { name: "generation", ddl: "ALTER TABLE graph_edges ADD COLUMN generation INTEGER NOT NULL DEFAULT 0" }
166
- ],
167
- handler_registrations: [
168
- { name: "class_name", ddl: "ALTER TABLE handler_registrations ADD COLUMN class_name TEXT" },
169
- { name: "import_source", ddl: "ALTER TABLE handler_registrations ADD COLUMN import_source TEXT" }
170
- ],
171
- symbols: [
172
- { name: "start_offset", ddl: "ALTER TABLE symbols ADD COLUMN start_offset INTEGER" },
173
- { name: "end_offset", ddl: "ALTER TABLE symbols ADD COLUMN end_offset INTEGER" },
174
- { name: "source_file", ddl: "ALTER TABLE symbols ADD COLUMN source_file TEXT" },
175
- { name: "exported_name", ddl: "ALTER TABLE symbols ADD COLUMN exported_name TEXT" },
176
- { name: "evidence_json", ddl: "ALTER TABLE symbols ADD COLUMN evidence_json TEXT" }
177
- ],
178
- cds_services: [
179
- { name: "extension_local_ref", ddl: "ALTER TABLE cds_services ADD COLUMN extension_local_ref TEXT" },
180
- { name: "extension_imported_symbol", ddl: "ALTER TABLE cds_services ADD COLUMN extension_imported_symbol TEXT" },
181
- { name: "extension_local_alias", ddl: "ALTER TABLE cds_services ADD COLUMN extension_local_alias TEXT" },
182
- { name: "extension_module_specifier", ddl: "ALTER TABLE cds_services ADD COLUMN extension_module_specifier TEXT" },
183
- { name: "extension_import_kind", ddl: "ALTER TABLE cds_services ADD COLUMN extension_import_kind TEXT" },
184
- { name: "extension_base_service_id", ddl: "ALTER TABLE cds_services ADD COLUMN extension_base_service_id INTEGER" },
185
- { name: "extension_base_status", ddl: "ALTER TABLE cds_services ADD COLUMN extension_base_status TEXT" }
186
- ],
187
- cds_operations: [
188
- { name: "provenance", ddl: "ALTER TABLE cds_operations ADD COLUMN provenance TEXT NOT NULL DEFAULT 'direct'" },
189
- { name: "base_operation_id", ddl: "ALTER TABLE cds_operations ADD COLUMN base_operation_id INTEGER" }
190
- ],
191
- outbound_calls: [
192
- { name: "local_service_name", ddl: "ALTER TABLE outbound_calls ADD COLUMN local_service_name TEXT" },
193
- { name: "local_service_lookup", ddl: "ALTER TABLE outbound_calls ADD COLUMN local_service_lookup TEXT" },
194
- { name: "alias_chain_json", ddl: "ALTER TABLE outbound_calls ADD COLUMN alias_chain_json TEXT" },
195
- { name: "evidence_json", ddl: "ALTER TABLE outbound_calls ADD COLUMN evidence_json TEXT" },
196
- { name: "external_target_kind", ddl: "ALTER TABLE outbound_calls ADD COLUMN external_target_kind TEXT" },
197
- { name: "external_target_id", ddl: "ALTER TABLE outbound_calls ADD COLUMN external_target_id TEXT" },
198
- { name: "external_target_label", ddl: "ALTER TABLE outbound_calls ADD COLUMN external_target_label TEXT" },
199
- { name: "external_target_dynamic", ddl: "ALTER TABLE outbound_calls ADD COLUMN external_target_dynamic INTEGER NOT NULL DEFAULT 0" }
200
- ],
201
- index_runs: [
202
- { name: "error_message", ddl: "ALTER TABLE index_runs ADD COLUMN error_message TEXT" },
203
- { name: "owner_pid", ddl: "ALTER TABLE index_runs ADD COLUMN owner_pid INTEGER" }
204
- ]
205
- };
206
- function hasColumn(db, table, column) {
207
- return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
208
- }
209
- function userVersion(db) {
210
- const row = db.pragma("user_version")[0];
211
- return Number(row?.user_version ?? 0);
212
- }
213
- function addMissingColumns(db) {
214
- for (const [table, tableColumns] of Object.entries(columns)) {
215
- for (const column of tableColumns) {
216
- if (!hasColumn(db, table, column.name)) db.prepare(column.ddl).run();
217
- }
218
- }
219
- }
220
- function normalizeLegacyStatus(db) {
221
- db.prepare("UPDATE graph_edges SET status=CASE WHEN edge_type='REMOTE_CALL_RESOLVES_TO_OPERATION' THEN 'resolved' WHEN edge_type IN ('HANDLER_RUNS_DB_QUERY','HANDLER_CALLS_EXTERNAL_HTTP','HANDLER_EMITS_EVENT','EVENT_CONSUMED_BY_HANDLER') THEN 'terminal' WHEN edge_type='DYNAMIC_EDGE_CANDIDATE' THEN 'dynamic' WHEN status='ambiguous' THEN 'ambiguous' ELSE status END").run();
222
- db.prepare("UPDATE repositories SET graph_stale_reason='schema_migration_requires_relink', graph_stale_at=COALESCE(graph_stale_at, datetime('now')) WHERE EXISTS (SELECT 1 FROM graph_edges WHERE graph_edges.workspace_id=repositories.workspace_id) AND graph_generation=0").run();
223
- }
224
- function migrate(db) {
225
- db.transaction(() => {
226
- const version = userVersion(db);
227
- if (version > CURRENT_SCHEMA_VERSION) throw new Error(`Unsupported future service-flow schema version ${version}`);
228
- db.exec(schemaTablesSql);
229
- addMissingColumns(db);
230
- db.exec(schemaIndexesSql);
231
- normalizeLegacyStatus(db);
232
- const violations = db.pragma("foreign_key_check");
233
- if (violations.length > 0) throw new Error("SQLite foreign_key_check failed during migration");
234
- db.pragma(`user_version = ${CURRENT_SCHEMA_VERSION}`);
235
- });
236
- }
237
-
238
- // package.json
239
- var package_default = {
240
- name: "@saptools/service-flow",
241
- version: "0.1.65",
242
- description: "Trace SAP CAP service-to-service flows across multi-repository workspaces with runtime-aware graph resolution",
243
- type: "module",
244
- publishConfig: {
245
- access: "public",
246
- registry: "https://registry.npmjs.org/"
247
- },
248
- bin: {
249
- "service-flow": "dist/cli.js"
250
- },
251
- main: "./dist/index.js",
252
- types: "./dist/index.d.ts",
253
- exports: {
254
- ".": {
255
- types: "./dist/index.d.ts",
256
- import: "./dist/index.js"
257
- }
258
- },
259
- files: [
260
- "CHANGELOG.md",
261
- "README.md",
262
- "TECHNICAL-NOTE.md",
263
- "dist",
264
- "src"
265
- ],
266
- engines: {
267
- node: ">=24.0.0"
268
- },
269
- scripts: {
270
- build: "tsup",
271
- typecheck: "tsc --noEmit",
272
- lint: "eslint src tests",
273
- test: "vitest run tests/unit",
274
- "test:unit": "vitest run tests/unit",
275
- "test:e2e": "vitest run tests/e2e",
276
- "test:e2e:fake": "vitest run tests/e2e"
277
- },
278
- keywords: [
279
- "sap",
280
- "cap",
281
- "cds",
282
- "btp",
283
- "cli",
284
- "service-graph",
285
- "call-graph",
286
- "sqlite",
287
- "saptools"
288
- ],
289
- author: "Dong Tran",
290
- license: "MIT",
291
- repository: {
292
- type: "git",
293
- url: "git+https://github.com/dongitran/saptools.git",
294
- directory: "packages/service-flow"
295
- },
296
- homepage: "https://github.com/dongitran/saptools/tree/main/packages/service-flow#readme",
297
- bugs: {
298
- url: "https://github.com/dongitran/saptools/issues"
299
- },
300
- dependencies: {
301
- commander: "13.1.0",
302
- picocolors: "1.1.1",
303
- typescript: "5.9.3",
304
- zod: "4.4.3"
305
- },
306
- devDependencies: {
307
- "@vitest/coverage-v8": "3.2.4",
308
- tsup: "8.5.1",
309
- vitest: "3.2.4"
310
- }
311
- };
312
-
313
- // src/version.ts
314
- var VERSION = package_default.version;
315
- var ANALYZER_VERSION = package_default.version;
316
-
317
- // src/db/connection.ts
318
118
  var sqliteWarningFilterInstalled = false;
319
119
  function installSqliteWarningFilter() {
320
120
  if (sqliteWarningFilterInstalled) return;
@@ -703,7 +503,7 @@ async function parseExecutableSymbols(repoPath, filePath, context) {
703
503
  const imports = /* @__PURE__ */ new Map();
704
504
  const namespaceImports = /* @__PURE__ */ new Set();
705
505
  const eventSubscriptionOffsets = new Set(
706
- classifyOutboundCallsInSource(source, sourceFile).filter((call) => call.fact.callType === "async_subscribe").map((call) => call.node.getStart(source))
506
+ classifyOutboundCallsInSource(source, sourceFile).filter((call) => call.fact.callType === "async_subscribe").map((call) => `${call.node.getStart(source)}:${call.node.getEnd()}`)
707
507
  );
708
508
  const exportNames = exportDeclarations(source);
709
509
  const objectExports = /* @__PURE__ */ new Set();
@@ -821,7 +621,7 @@ async function parseExecutableSymbols(repoPath, filePath, context) {
821
621
  const name = `event:${eventName}:${startLine}`;
822
622
  symbols.push({ kind: "event_registration", localName: name, qualifiedName: `module:${sourceFile}#${name}`, sourceFile, startLine, endLine: lineOf(source, node.getEnd()), startOffset: node.getStart(source), endOffset: node.getEnd(), exported: false, importExportEvidence: { source: "synthetic_event_registration", eventName: eventArg.text, registrationLine: startLine, receiver } });
823
623
  }
824
- if (eventSubscriptionOffsets.has(node.getStart(source))) {
624
+ if (eventSubscriptionOffsets.has(`${node.getStart(source)}:${node.getEnd()}`)) {
825
625
  const startLine = lineOf(source, node.getStart(source));
826
626
  const handlerArgument = node.arguments[1];
827
627
  const target = handlerArgument ? handlerReferenceTarget(
@@ -838,12 +638,15 @@ async function parseExecutableSymbols(repoPath, filePath, context) {
838
638
  importSource: target.importSource,
839
639
  sourceFile,
840
640
  sourceLine: startLine,
641
+ callSiteStartOffset: node.getStart(source),
642
+ callSiteEndOffset: node.getEnd(),
643
+ callRole: "event_subscribe_handler",
841
644
  evidence: {
842
645
  relation: target.relation,
843
646
  caller: anchor.qualifiedName,
844
647
  targetName: target.calleeLocalName,
845
648
  ...target.wrapperFunction ? { wrapperFunction: target.wrapperFunction } : {},
846
- candidateStrategy: "event_subscribe_handler_reference"
649
+ factOrigin: "event_subscribe_handler_reference"
847
650
  }
848
651
  });
849
652
  }
@@ -901,7 +704,7 @@ async function parseExecutableSymbols(repoPath, filePath, context) {
901
704
  const ignored = loggerLike || terminalMember || ignoredFrameworkCall(callee);
902
705
  const resolvedTarget = provenThisMethod ? thisTarget : targetName;
903
706
  const keep = Boolean(resolvedTarget) && !ignored && (provenLocal || provenThisMethod || provenRelativeImport || provenClassInstance || provenPackageImport);
904
- if (keep) calls.push({ callerQualifiedName: caller.qualifiedName, calleeExpression: callee.expression, calleeLocalName: resolvedTarget, receiverLocalName: callee.member ? callee.local ?? callee.receiver : void 0, importSource, sourceFile, sourceLine: line, evidence: { relation: instance ? "class_instance_method" : proxy ? "relative_import_proxy_member" : packageImport ? "package_import" : namespaceMember ? "relative_import_namespace_member" : importSource ? "relative_import" : provenThisMethod ? "indexed_this_method" : "indexed_local_symbol", caller: caller.qualifiedName, targetName: resolvedTarget, instanceVariable: instance ? instance.propertyName ?? callee.local : void 0, className: instance?.className, methodName: instance ? callee.member : void 0, classImportSource: instance?.importSource, callArguments: argumentEvidence(node.arguments, source), proxyVariableName: proxy?.variableName, factory: proxy?.factory, factoryExpression: proxy?.factory, factoryImportSource: proxy?.importSource, candidateStrategy: instance ? instance.importSource ? "relative_import_class_instance_method" : "same_file_class_instance_method" : proxy ? "proxy_member_exact_export_or_unique_member" : void 0 } });
707
+ if (keep) calls.push({ callerQualifiedName: caller.qualifiedName, calleeExpression: callee.expression, calleeLocalName: resolvedTarget, receiverLocalName: callee.member ? callee.local ?? callee.receiver : void 0, importSource, sourceFile, sourceLine: line, callSiteStartOffset: node.getStart(source), callSiteEndOffset: node.getEnd(), callRole: "ordinary_call", evidence: { relation: instance ? "class_instance_method" : proxy ? "relative_import_proxy_member" : packageImport ? "package_import" : namespaceMember ? "relative_import_namespace_member" : importSource ? "relative_import" : provenThisMethod ? "indexed_this_method" : "indexed_local_symbol", caller: caller.qualifiedName, targetName: resolvedTarget, instanceVariable: instance ? instance.propertyName ?? callee.local : void 0, className: instance?.className, methodName: instance ? callee.member : void 0, classImportSource: instance?.importSource, callArguments: argumentEvidence(node.arguments, source), proxyVariableName: proxy?.variableName, factory: proxy?.factory, factoryExpression: proxy?.factory, factoryImportSource: proxy?.importSource, candidateStrategy: instance ? instance.importSource ? "relative_import_class_instance_method" : "same_file_class_instance_method" : proxy ? "proxy_member_exact_export_or_unique_member" : void 0 } });
905
708
  }
906
709
  }
907
710
  ts.forEachChild(node, visitCalls);
@@ -1334,19 +1137,74 @@ function upperFirst(value) {
1334
1137
  return value ? `${value[0]?.toUpperCase() ?? ""}${value.slice(1)}` : value;
1335
1138
  }
1336
1139
 
1337
- // src/cli/doctor.ts
1338
- function linkUpgradeWarnings(db) {
1339
- return [...schemaDriftDiagnostics(db, true), ...analyzerVersionDiagnostics(db, true)].filter((item) => ["schema_legacy_columns_present", "external_target_columns_missing_data", "reindex_required_after_upgrade", "reindex_required_after_analyzer_upgrade"].includes(String(item.code)));
1140
+ // src/cli/002-doctor-lifecycle.ts
1141
+ function linkUpgradeWarnings(db, workspaceId) {
1142
+ const lifecycle = factLifecycleDiagnostic(db, workspaceId);
1143
+ if (lifecycle) return [lifecycle];
1144
+ return [
1145
+ ...schemaDriftDiagnostics(db, true, workspaceId),
1146
+ ...analyzerVersionDiagnostics(db, true, workspaceId)
1147
+ ].filter((item) => [
1148
+ "schema_legacy_columns_present",
1149
+ "external_target_columns_missing_data",
1150
+ "reindex_required_after_upgrade",
1151
+ "reindex_required_after_analyzer_upgrade"
1152
+ ].includes(String(item.code)));
1153
+ }
1154
+ function schemaDriftDiagnostics(db, strict, workspaceId) {
1155
+ if (!strict) return [];
1156
+ const columns = db.prepare("PRAGMA table_info(symbols)").all();
1157
+ const legacy = columns.filter((row) => [
1158
+ "external_target_kind",
1159
+ "external_target_id",
1160
+ "external_target_label",
1161
+ "external_target_dynamic"
1162
+ ].includes(String(row.name))).map((row) => row.name);
1163
+ const missing = db.prepare(`SELECT c.id id,c.source_file sourceFile,
1164
+ c.source_line sourceLine FROM outbound_calls c
1165
+ JOIN repositories r ON r.id=c.repo_id
1166
+ WHERE c.call_type='external_http'
1167
+ AND (? IS NULL OR r.workspace_id=?)
1168
+ AND (c.external_target_id IS NULL OR c.external_target_label IS NULL
1169
+ OR c.external_target_kind IS NULL) LIMIT 20`).all(
1170
+ workspaceId,
1171
+ workspaceId
1172
+ );
1173
+ const out = [];
1174
+ if (legacy.length > 0) out.push({ severity: "warning", code: "schema_legacy_columns_present", message: "Legacy external-target columns are present on symbols; run service-flow clean --db-only, then init/index/link to rebuild with the current schema.", scope: "workspace", affectedColumns: legacy, remediation: "service-flow clean --db-only && service-flow init <workspace> && service-flow index && service-flow link" });
1175
+ if (missing.length > 0) out.push({ severity: "warning", code: "external_target_columns_missing_data", message: "External HTTP calls are missing queryable external target metadata; reindex is required after upgrade.", scope: "workspace", affectedRows: missing, remediation: "service-flow index --force && service-flow link" });
1176
+ if (legacy.length > 0 || missing.length > 0) out.push({ severity: "warning", code: "reindex_required_after_upgrade", message: "This database cannot be made equivalent to a fresh index by relink alone.", scope: "workspace", remediation: "Rebuild or force reindex the workspace, then run service-flow doctor --strict." });
1177
+ return out;
1340
1178
  }
1179
+ function analyzerVersionDiagnostics(db, strict, workspaceId) {
1180
+ if (!strict) return [];
1181
+ const rows = db.prepare(`SELECT name,
1182
+ COALESCE(fact_analyzer_version,'legacy') factAnalyzerVersion
1183
+ FROM repositories WHERE index_status='indexed'
1184
+ AND (? IS NULL OR workspace_id=?)
1185
+ AND COALESCE(fact_analyzer_version,'legacy')<>?`).all(
1186
+ workspaceId,
1187
+ workspaceId,
1188
+ ANALYZER_VERSION
1189
+ );
1190
+ if (rows.length === 0) return [];
1191
+ return [{ severity: "warning", code: "reindex_required_after_analyzer_upgrade", message: "Repository facts were produced by an older or unknown analyzer; run service-flow index --force before relink to apply current parser semantics.", scope: "workspace", affectedRepositoryCount: rows.length, currentAnalyzerVersion: ANALYZER_VERSION, repositories: rows, remediation: "service-flow index --force && service-flow link" }];
1192
+ }
1193
+
1194
+ // src/cli/doctor.ts
1341
1195
  function doctorDiagnostics(db, strict, options = {}) {
1196
+ const lifecycle = factLifecycleDiagnostic(db, options.workspaceId);
1197
+ if (lifecycle?.code === "schema_upgrade_required" || lifecycle?.code === "unsupported_future_schema")
1198
+ return boundDoctorDiagnostics([lifecycle]);
1342
1199
  const diagnostics = db.prepare("SELECT severity,code,message,source_file sourceFile,source_line sourceLine FROM diagnostics ORDER BY id").all();
1343
1200
  return boundDoctorDiagnostics([
1201
+ ...lifecycle ? [lifecycle] : [],
1344
1202
  ...diagnostics,
1345
1203
  ...healthDiagnostics(db, strict),
1346
1204
  ...remoteTargetWithoutImplementationDiagnostics(db, strict, Boolean(options.detail)),
1347
1205
  ...localServiceDiagnostics(db, strict),
1348
- ...schemaDriftDiagnostics(db, strict),
1349
- ...analyzerVersionDiagnostics(db, strict),
1206
+ ...schemaDriftDiagnostics(db, strict, options.workspaceId),
1207
+ ...analyzerVersionDiagnostics(db, strict, options.workspaceId),
1350
1208
  ...parserQualityDiagnostics(db, strict, options)
1351
1209
  ]);
1352
1210
  }
@@ -1424,23 +1282,6 @@ function remoteTargetWithoutImplementationExamples(db, servicePath, operationPat
1424
1282
  AND NOT EXISTS (SELECT 1 FROM graph_edges impl WHERE impl.edge_type='OPERATION_IMPLEMENTED_BY_HANDLER' AND impl.from_kind='operation' AND impl.from_id=remote.to_id)
1425
1283
  ORDER BY r.name,c.source_file,c.source_line`).all(servicePath, operationPath);
1426
1284
  }
1427
- function schemaDriftDiagnostics(db, strict) {
1428
- if (!strict) return [];
1429
- const columns2 = db.prepare("PRAGMA table_info(symbols)").all();
1430
- const legacy = columns2.filter((row) => ["external_target_kind", "external_target_id", "external_target_label", "external_target_dynamic"].includes(String(row.name))).map((row) => row.name);
1431
- const missing = db.prepare("SELECT id id,source_file sourceFile,source_line sourceLine FROM outbound_calls WHERE call_type='external_http' AND (external_target_id IS NULL OR external_target_label IS NULL OR external_target_kind IS NULL) LIMIT 20").all();
1432
- const out = [];
1433
- if (legacy.length > 0) out.push({ severity: "warning", code: "schema_legacy_columns_present", message: "Legacy external-target columns are present on symbols; run service-flow clean --db-only, then init/index/link to rebuild with the current schema.", scope: "workspace", affectedColumns: legacy, remediation: "service-flow clean --db-only && service-flow init <workspace> && service-flow index && service-flow link" });
1434
- if (missing.length > 0) out.push({ severity: "warning", code: "external_target_columns_missing_data", message: "External HTTP calls are missing queryable external target metadata; reindex is required after upgrade.", scope: "workspace", affectedRows: missing, remediation: "service-flow index --force && service-flow link" });
1435
- if (legacy.length > 0 || missing.length > 0) out.push({ severity: "warning", code: "reindex_required_after_upgrade", message: "This database cannot be made equivalent to a fresh index by relink alone.", scope: "workspace", remediation: "Rebuild or force reindex the workspace, then run service-flow doctor --strict." });
1436
- return out;
1437
- }
1438
- function analyzerVersionDiagnostics(db, strict) {
1439
- if (!strict) return [];
1440
- const rows = db.prepare("SELECT name,COALESCE(fact_analyzer_version,'legacy') factAnalyzerVersion FROM repositories WHERE index_status='indexed' AND COALESCE(fact_analyzer_version,'legacy')<>?").all(ANALYZER_VERSION);
1441
- if (rows.length === 0) return [];
1442
- return [{ severity: "warning", code: "reindex_required_after_analyzer_upgrade", message: "Repository facts were produced by an older or unknown analyzer; run service-flow index --force before relink to apply current parser semantics.", scope: "workspace", affectedRepositoryCount: rows.length, currentAnalyzerVersion: ANALYZER_VERSION, repositories: rows, remediation: "service-flow index --force && service-flow link" }];
1443
- }
1444
1285
  function localServiceDiagnostics(db, strict) {
1445
1286
  const rows = db.prepare("SELECT e.status status,e.unresolved_reason reason,e.evidence_json evidenceJson FROM graph_edges e JOIN outbound_calls c ON e.from_kind='call' AND c.id=CAST(e.from_id AS INTEGER) WHERE c.call_type='local_service_call'").all();
1446
1287
  const implementationContext = rows.filter((row) => row.status === "resolved" && String(row.evidenceJson ?? "").includes("implementation_context_caller_ownership")).length;
@@ -2190,6 +2031,12 @@ function createStdoutWriter(stream, onUnexpectedError) {
2190
2031
  return writer;
2191
2032
  }
2192
2033
 
2034
+ // src/output/001-compact-json-output.ts
2035
+ function renderCompactJson(value) {
2036
+ return `${JSON.stringify(redactValue(value))}
2037
+ `;
2038
+ }
2039
+
2193
2040
  // src/cli/000-clean.ts
2194
2041
  import fs6 from "fs/promises";
2195
2042
  import path6 from "path";
@@ -2251,6 +2098,8 @@ async function markCleanClaimFailed(dbPath, runId, error) {
2251
2098
 
2252
2099
  // src/cli.ts
2253
2100
  var stdout = createStdoutWriter(process.stdout, fail);
2101
+ var TRACE_FORMATS = ["table", "json", "mermaid", "compact-json"];
2102
+ var GRAPH_FORMATS = ["mermaid", "json", "compact-json"];
2254
2103
  function writeStdout(value) {
2255
2104
  stdout.write(value);
2256
2105
  }
@@ -2328,6 +2177,72 @@ function selectRepository(db, selector, workspaceId) {
2328
2177
  )
2329
2178
  };
2330
2179
  }
2180
+ function traceFormatOption() {
2181
+ return new Option("--format <format>", TRACE_FORMATS.join("|")).choices([...TRACE_FORMATS]).default("table");
2182
+ }
2183
+ function graphFormatOption() {
2184
+ return new Option("--format <format>", GRAPH_FORMATS.join("|")).choices([...GRAPH_FORMATS]).default("mermaid");
2185
+ }
2186
+ function writeTraceOutput(db, start, options, format) {
2187
+ if (format === "compact-json") {
2188
+ writeStdout(renderCompactJson(compactTrace(db, start, options)));
2189
+ return;
2190
+ }
2191
+ const result = trace(db, start, options);
2192
+ writeStdout(renderDetailedTrace(result, format));
2193
+ }
2194
+ function renderDetailedTrace(result, format) {
2195
+ if (format === "json") return renderTraceJson(result);
2196
+ if (format === "mermaid") return renderMermaid(result);
2197
+ return renderTraceTable(result);
2198
+ }
2199
+ function runTraceCommand(opts) {
2200
+ return withReadOnlyWorkspace(opts.workspace, (db, workspaceId) => {
2201
+ const start = {
2202
+ repo: opts.repo,
2203
+ servicePath: opts.service,
2204
+ operation: opts.operation,
2205
+ operationPath: opts.path,
2206
+ handler: opts.handler
2207
+ };
2208
+ const options = {
2209
+ depth: Number(opts.depth),
2210
+ workspaceId,
2211
+ vars: parseVars(opts.var),
2212
+ includeExternal: Boolean(opts.includeExternal),
2213
+ includeDb: Boolean(opts.includeDb),
2214
+ includeAsync: Boolean(opts.includeAsync),
2215
+ implementationRepo: opts.implementationRepo,
2216
+ implementationHints: opts.implementationHint.map(parseImplementationHint),
2217
+ dynamicMode: parseDynamicMode(opts.dynamicMode),
2218
+ maxDynamicCandidates: parsePositiveInteger(opts.maxDynamicCandidates, 5)
2219
+ };
2220
+ writeTraceOutput(db, start, options, opts.format);
2221
+ });
2222
+ }
2223
+ function runGraphCommand(opts) {
2224
+ return withReadOnlyWorkspace(opts.workspace, (db, workspaceId) => {
2225
+ const start = {
2226
+ repo: opts.repo,
2227
+ operation: opts.operation,
2228
+ servicePath: opts.service,
2229
+ operationPath: opts.path
2230
+ };
2231
+ const options = {
2232
+ depth: 100,
2233
+ workspaceId,
2234
+ includeAsync: true,
2235
+ includeDb: true,
2236
+ includeExternal: true,
2237
+ vars: parseVars(opts.var),
2238
+ implementationRepo: opts.implementationRepo,
2239
+ implementationHints: opts.implementationHint.map(parseImplementationHint),
2240
+ dynamicMode: parseDynamicMode(opts.dynamicMode),
2241
+ maxDynamicCandidates: parsePositiveInteger(opts.maxDynamicCandidates, 5)
2242
+ };
2243
+ writeTraceOutput(db, start, options, opts.format);
2244
+ });
2245
+ }
2331
2246
  function createProgram() {
2332
2247
  const program = new Command();
2333
2248
  program.name("service-flow").description(
@@ -2351,43 +2266,15 @@ function createProgram() {
2351
2266
  program.command("link").option("--workspace <path>").option("--force").action(
2352
2267
  (opts) => void withWorkspace(opts.workspace, (db, workspaceId) => {
2353
2268
  const r = linkWorkspace(db, workspaceId);
2354
- const upgradeWarnings = linkUpgradeWarnings(db);
2269
+ const upgradeWarnings = linkUpgradeWarnings(db, workspaceId);
2355
2270
  writeStdout(
2356
2271
  `${upgradeWarnings.length ? `Warnings: ${upgradeWarnings.map((item) => String(item.code)).join(", ")}. Run service-flow doctor --strict for remediation.
2357
- ` : ""}Linked ${r.edgeCount} edges: ${r.remoteResolvedCount} remote operation calls resolved, ${r.localResolvedCount} local operation calls resolved, ${r.unresolvedCount} unresolved operation calls, ${r.ambiguousCount} ambiguous operation calls, ${r.dynamicCount} dynamic operation calls, ${r.terminalCount} terminal call edges, ${r.dependencyResolvedCount} dependency resolved, ${r.dependencyAmbiguousCount} dependency ambiguous, ${r.implementationResolvedCount} implementation resolved, ${r.implementationAmbiguousCount} implementation ambiguous, ${r.implementationUnresolvedCount} implementation unresolved
2272
+ ` : ""}Linked ${r.edgeCount} edges: ${r.remoteResolvedCount} remote operation calls resolved, ${r.localResolvedCount} local operation calls resolved, ${r.unresolvedCount} unresolved operation calls, ${r.ambiguousCount} ambiguous operation calls, ${r.dynamicCount} dynamic operation calls, ${r.terminalCount} terminal call edges, ${r.dependencyResolvedCount} dependency resolved, ${r.dependencyAmbiguousCount} dependency ambiguous, ${r.implementationResolvedCount} implementation resolved, ${r.implementationAmbiguousCount} implementation ambiguous, ${r.implementationUnresolvedCount} implementation unresolved, ${r.subscriptionHandlerResolvedCount} subscription handlers resolved, ${r.subscriptionHandlerAmbiguousCount} subscription handlers ambiguous, ${r.subscriptionHandlerUnresolvedCount} subscription handlers unresolved, ${r.subscriptionHandlerMissingAssociationCount} subscription handler associations missing
2358
2273
  `
2359
2274
  );
2360
2275
  }).catch(fail)
2361
2276
  );
2362
- program.command("trace").option("--workspace <path>").option("--repo <name>").option("--operation <name>").option("--service <path>").option("--path <operationPath>").option("--handler <name>").option("--depth <n>", "trace depth", "25").option("--format <format>", "table|json|mermaid", "table").option("--include-external").option("--include-db").option("--include-async").option("--implementation-repo <name>").option("--implementation-hint <scope>", "scoped implementation hint", collect, []).option("--var <key=value>", "dynamic variable", collect, []).option("--dynamic-mode <mode>", "strict|candidates|infer", "strict").option("--max-dynamic-candidates <n>", "maximum dynamic candidates to show", "5").action(
2363
- (opts) => void withReadOnlyWorkspace(opts.workspace, (db, workspaceId) => {
2364
- const result = trace(
2365
- db,
2366
- {
2367
- repo: opts.repo,
2368
- servicePath: opts.service,
2369
- operation: opts.operation,
2370
- operationPath: opts.path,
2371
- handler: opts.handler
2372
- },
2373
- {
2374
- depth: Number(opts.depth),
2375
- workspaceId,
2376
- vars: parseVars(opts.var),
2377
- includeExternal: Boolean(opts.includeExternal),
2378
- includeDb: Boolean(opts.includeDb),
2379
- includeAsync: Boolean(opts.includeAsync),
2380
- implementationRepo: opts.implementationRepo,
2381
- implementationHints: opts.implementationHint.map(parseImplementationHint),
2382
- dynamicMode: parseDynamicMode(opts.dynamicMode),
2383
- maxDynamicCandidates: parsePositiveInteger(opts.maxDynamicCandidates, 5)
2384
- }
2385
- );
2386
- writeStdout(
2387
- opts.format === "json" ? renderTraceJson(result) : opts.format === "mermaid" ? renderMermaid(result) : renderTraceTable(result)
2388
- );
2389
- }).catch(fail)
2390
- );
2277
+ program.command("trace").option("--workspace <path>").option("--repo <name>").option("--operation <name>").option("--service <path>").option("--path <operationPath>").option("--handler <name>").option("--depth <n>", "trace depth", "25").addOption(traceFormatOption()).option("--include-external").option("--include-db").option("--include-async").option("--implementation-repo <name>").option("--implementation-hint <scope>", "scoped implementation hint", collect, []).option("--var <key=value>", "dynamic variable", collect, []).option("--dynamic-mode <mode>", "strict|candidates|infer", "strict").option("--max-dynamic-candidates <n>", "maximum dynamic candidates to show", "5").action((opts) => void runTraceCommand(opts).catch(fail));
2391
2278
  const list = program.command("list");
2392
2279
  list.command("repos").option("--workspace <path>").action(
2393
2280
  (opts) => void withReadOnlyWorkspace(
@@ -2453,34 +2340,7 @@ function createProgram() {
2453
2340
  writeStdout(renderJson(rows));
2454
2341
  }).catch(fail)
2455
2342
  );
2456
- program.command("graph").option("--workspace <path>").option("--repo <name>").option("--operation <name>").option("--service <path>").option("--path <operationPath>").option("--format <format>", "mermaid|json", "mermaid").option("--implementation-repo <name>").option("--implementation-hint <scope>", "scoped implementation hint", collect, []).option("--var <key=value>", "dynamic variable", collect, []).option("--dynamic-mode <mode>", "strict|candidates|infer", "strict").option("--max-dynamic-candidates <n>", "maximum dynamic candidates to show", "5").action(
2457
- (opts) => void withReadOnlyWorkspace(opts.workspace, (db, workspaceId) => {
2458
- const result = trace(
2459
- db,
2460
- {
2461
- repo: opts.repo,
2462
- operation: opts.operation,
2463
- servicePath: opts.service,
2464
- operationPath: opts.path
2465
- },
2466
- {
2467
- depth: 100,
2468
- workspaceId,
2469
- includeAsync: true,
2470
- includeDb: true,
2471
- includeExternal: true,
2472
- vars: parseVars(opts.var),
2473
- implementationRepo: opts.implementationRepo,
2474
- implementationHints: opts.implementationHint.map(parseImplementationHint),
2475
- dynamicMode: parseDynamicMode(opts.dynamicMode),
2476
- maxDynamicCandidates: parsePositiveInteger(opts.maxDynamicCandidates, 5)
2477
- }
2478
- );
2479
- writeStdout(
2480
- opts.format === "json" ? renderTraceJson(result) : renderMermaid(result)
2481
- );
2482
- }).catch(fail)
2483
- );
2343
+ program.command("graph").option("--workspace <path>").option("--repo <name>").option("--operation <name>").option("--service <path>").option("--path <operationPath>").addOption(graphFormatOption()).option("--implementation-repo <name>").option("--implementation-hint <scope>", "scoped implementation hint", collect, []).option("--var <key=value>", "dynamic variable", collect, []).option("--dynamic-mode <mode>", "strict|candidates|infer", "strict").option("--max-dynamic-candidates <n>", "maximum dynamic candidates to show", "5").action((opts) => void runGraphCommand(opts).catch(fail));
2484
2344
  const inspect = program.command("inspect");
2485
2345
  inspect.command("repo").argument("<name>").option("--workspace <path>").action(
2486
2346
  (name, opts) => void withReadOnlyWorkspace(opts.workspace, (db, workspaceId) => {
@@ -2499,8 +2359,11 @@ function createProgram() {
2499
2359
  }).catch(fail)
2500
2360
  );
2501
2361
  program.command("doctor").option("--workspace <path>").option("--strict").option("--detail").option("--format <format>", "json|table").action(
2502
- (opts) => void withReadOnlyWorkspace(opts.workspace, (db) => {
2503
- const allDiagnostics = doctorDiagnostics(db, Boolean(opts.strict), { detail: Boolean(opts.detail) });
2362
+ (opts) => void withReadOnlyWorkspace(opts.workspace, (db, workspaceId) => {
2363
+ const allDiagnostics = doctorDiagnostics(db, Boolean(opts.strict), {
2364
+ detail: Boolean(opts.detail),
2365
+ workspaceId
2366
+ });
2504
2367
  writeStdout(renderDoctorDiagnostics(allDiagnostics, opts.format));
2505
2368
  }).catch(fail)
2506
2369
  );