@topogram/cli 0.3.62 → 0.3.64

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 (121) hide show
  1. package/package.json +1 -1
  2. package/src/adoption/plan.d.ts +6 -0
  3. package/src/adoption/reporting.d.ts +10 -0
  4. package/src/adoption/review-groups.d.ts +6 -0
  5. package/src/agent-brief.d.ts +3 -0
  6. package/src/agent-brief.js +495 -0
  7. package/src/agent-ops/query-builders.d.ts +26 -0
  8. package/src/archive/archive.d.ts +2 -0
  9. package/src/archive/compact.d.ts +1 -0
  10. package/src/archive/unarchive.d.ts +1 -0
  11. package/src/catalog.d.ts +10 -0
  12. package/src/catalog.js +62 -66
  13. package/src/cli/catalog-alias.d.ts +1 -0
  14. package/src/cli/command-parser.js +38 -0
  15. package/src/cli/command-parsers/core.js +102 -0
  16. package/src/cli/command-parsers/generator.js +39 -0
  17. package/src/cli/command-parsers/import.js +44 -0
  18. package/src/cli/command-parsers/legacy-workflow.js +21 -0
  19. package/src/cli/command-parsers/project.js +47 -0
  20. package/src/cli/command-parsers/sdlc.js +47 -0
  21. package/src/cli/command-parsers/shared.js +51 -0
  22. package/src/cli/command-parsers/template.js +48 -0
  23. package/src/cli/commands/agent.js +47 -0
  24. package/src/cli/commands/catalog.js +617 -0
  25. package/src/cli/commands/check.js +268 -0
  26. package/src/cli/commands/doctor.js +268 -0
  27. package/src/cli/commands/emit.js +149 -0
  28. package/src/cli/commands/generate.js +96 -0
  29. package/src/cli/commands/generator-policy.js +785 -0
  30. package/src/cli/commands/generator.js +443 -0
  31. package/src/cli/commands/import-runner.js +157 -0
  32. package/src/cli/commands/import.js +1734 -0
  33. package/src/cli/commands/inspect.js +55 -0
  34. package/src/cli/commands/new.js +94 -0
  35. package/src/cli/commands/package.js +815 -0
  36. package/src/cli/commands/query.js +1302 -0
  37. package/src/cli/commands/release-rollout.js +257 -0
  38. package/src/cli/commands/release-shared.js +528 -0
  39. package/src/cli/commands/release-status.js +429 -0
  40. package/src/cli/commands/release.js +107 -0
  41. package/src/cli/commands/sdlc.js +168 -0
  42. package/src/cli/commands/setup.js +76 -0
  43. package/src/cli/commands/source.js +291 -0
  44. package/src/cli/commands/template-runner.js +198 -0
  45. package/src/cli/commands/template.js +2145 -0
  46. package/src/cli/commands/trust.js +219 -0
  47. package/src/cli/commands/version.js +40 -0
  48. package/src/cli/commands/widget.js +168 -0
  49. package/src/cli/commands/workflow.js +63 -0
  50. package/src/cli/dispatcher.js +392 -0
  51. package/src/cli/help-dispatch.js +188 -0
  52. package/src/cli/help.js +296 -0
  53. package/src/cli/migration-guidance.js +59 -0
  54. package/src/cli/options.js +96 -0
  55. package/src/cli/output-safety.js +107 -0
  56. package/src/cli/path-normalization.js +29 -0
  57. package/src/cli.js +47 -11711
  58. package/src/example-implementation.d.ts +2 -0
  59. package/src/format.d.ts +1 -0
  60. package/src/generator/check.d.ts +1 -0
  61. package/src/generator/context/bundle.d.ts +1 -0
  62. package/src/generator/context/shared.d.ts +2 -0
  63. package/src/generator/native/parity-bundle.js +2 -1
  64. package/src/generator/surfaces/web/html-escape.js +22 -0
  65. package/src/generator/surfaces/web/react.js +10 -8
  66. package/src/generator/surfaces/web/sveltekit.js +7 -5
  67. package/src/generator/surfaces/web/vanilla.js +8 -4
  68. package/src/generator.d.ts +2 -0
  69. package/src/github-client.js +520 -0
  70. package/src/import/core/shared.js +20 -62
  71. package/src/import/extractors/api/flutter-dio.js +4 -8
  72. package/src/import/extractors/api/react-native-repository.js +4 -8
  73. package/src/import/index.d.ts +4 -0
  74. package/src/import/provenance.d.ts +4 -0
  75. package/src/new-project.js +100 -11
  76. package/src/npm-safety.js +79 -0
  77. package/src/parser.d.ts +1 -0
  78. package/src/path-helpers.d.ts +1 -0
  79. package/src/path-helpers.js +20 -0
  80. package/src/project-config.js +1 -0
  81. package/src/reconcile/docs.d.ts +8 -0
  82. package/src/reconcile/journeys.d.ts +1 -0
  83. package/src/resolver.d.ts +1 -0
  84. package/src/runtime-support.js +29 -0
  85. package/src/sdlc/adopt.d.ts +1 -0
  86. package/src/sdlc/check.d.ts +1 -0
  87. package/src/sdlc/explain.d.ts +1 -0
  88. package/src/sdlc/release.d.ts +1 -0
  89. package/src/sdlc/scaffold.d.ts +1 -0
  90. package/src/sdlc/transition.d.ts +1 -0
  91. package/src/text-helpers.d.ts +6 -0
  92. package/src/text-helpers.js +245 -0
  93. package/src/topogram-config.js +306 -0
  94. package/src/validator.d.ts +2 -0
  95. package/src/workflows/adoption/index.js +26 -0
  96. package/src/workflows/docs-generate.js +262 -0
  97. package/src/workflows/docs-scan.js +703 -0
  98. package/src/workflows/docs.js +15 -0
  99. package/src/workflows/import-app/api.js +799 -0
  100. package/src/workflows/import-app/db.js +538 -0
  101. package/src/workflows/import-app/index.js +30 -0
  102. package/src/workflows/import-app/shared.js +218 -0
  103. package/src/workflows/import-app/ui.js +443 -0
  104. package/src/workflows/import-app/workflow.js +159 -0
  105. package/src/workflows/reconcile/adoption-plan.js +742 -0
  106. package/src/workflows/reconcile/auth.js +692 -0
  107. package/src/workflows/reconcile/bundle-core.js +600 -0
  108. package/src/workflows/reconcile/bundle-shared.js +75 -0
  109. package/src/workflows/reconcile/candidate-model.js +477 -0
  110. package/src/workflows/reconcile/canonical-surface.js +264 -0
  111. package/src/workflows/reconcile/gap-report.js +333 -0
  112. package/src/workflows/reconcile/ids.js +6 -0
  113. package/src/workflows/reconcile/impacts.js +625 -0
  114. package/src/workflows/reconcile/index.js +7 -0
  115. package/src/workflows/reconcile/renderers.js +461 -0
  116. package/src/workflows/reconcile/summary.js +90 -0
  117. package/src/workflows/reconcile/workflow.js +309 -0
  118. package/src/workflows/shared.js +189 -0
  119. package/src/workflows/types.d.ts +93 -0
  120. package/src/workflows.d.ts +1 -0
  121. package/src/workflows.js +10 -7652
@@ -0,0 +1,296 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @param {{ all?: boolean }} [options]
5
+ * @returns {void}
6
+ */
7
+ export function printUsage(options = {}) {
8
+ const { all = false } = options;
9
+ console.log("Usage: topogram version [--json]");
10
+ console.log("Usage: topogram doctor [--json] [--catalog <path-or-source>]");
11
+ console.log(" or: topogram doctor --allow-local-npmrc");
12
+ console.log("Usage: topogram setup package-auth|catalog-auth");
13
+ console.log("Usage: topogram release status [--json] [--strict] [--markdown|--write-report <path>]");
14
+ console.log(" or: topogram release roll-consumers <version|--latest> [--json] [--no-push] [--watch]");
15
+ console.log("Usage: topogram check [path] [--json]");
16
+ console.log(" or: topogram widget check [path] [--projection <id>] [--widget <id>] [--json]");
17
+ console.log(" or: topogram widget behavior [path] [--projection <id>] [--widget <id>] [--json]");
18
+ console.log(" or: topogram agent brief [path] [--json]");
19
+ console.log(" or: topogram generate [path] [--out <path>]");
20
+ console.log(" or: topogram emit <target> [path] [--json|--write --out-dir <path>]");
21
+ console.log(" or: topogram query list [--json]");
22
+ console.log(" or: topogram query show <name> [--json]");
23
+ console.log(" or: topogram trust template [path]");
24
+ console.log(" or: topogram trust status [path] [--json]");
25
+ console.log(" or: topogram trust diff [path] [--json]");
26
+ console.log(" or: topogram catalog list [--json] [--catalog <path-or-source>]");
27
+ console.log(" or: topogram catalog show <id> [--json] [--catalog <path-or-source>]");
28
+ console.log(" or: topogram catalog doctor [--json] [--catalog <path-or-source>]");
29
+ console.log(" or: topogram catalog check <path-or-url> [--json]");
30
+ console.log(" or: topogram catalog copy <id> <target> [--version <version>] [--json] [--catalog <path-or-source>]");
31
+ console.log(" or: topogram package update-cli <version|--latest> [--json]");
32
+ console.log(" or: topogram import <app-path> --out <target> [--from <track[,track]>] [--json]");
33
+ console.log(" or: topogram import refresh [path] [--from <app-path>] [--dry-run] [--json]");
34
+ console.log(" or: topogram import diff [path] [--json]");
35
+ console.log(" or: topogram import check [path] [--json]");
36
+ console.log(" or: topogram import plan [path] [--json]");
37
+ console.log(" or: topogram import adopt --list [path] [--json]");
38
+ console.log(" or: topogram import adopt <selector> [path] [--dry-run|--write] [--force --reason <text>] [--json]");
39
+ console.log(" or: topogram import status [path] [--json]");
40
+ console.log(" or: topogram import history [path] [--verify] [--json]");
41
+ console.log(" or: topogram source status [path] [--local|--remote] [--json]");
42
+ console.log(" or: topogram template list [--json]");
43
+ console.log(" or: topogram template explain [path] [--json]");
44
+ console.log(" or: topogram template status [path] [--latest] [--json]");
45
+ console.log(" or: topogram template detach [path] [--dry-run] [--remove-policy] [--json]");
46
+ console.log(" or: topogram template policy init [path] [--json]");
47
+ console.log(" or: topogram template policy check [path] [--json]");
48
+ console.log(" or: topogram template policy explain [path] [--json]");
49
+ console.log(" or: topogram template policy pin [template-id@version] [path] [--json]");
50
+ console.log(" or: topogram template check <template-spec-or-path> [--json]");
51
+ console.log(" or: topogram template update [path] --status|--recommend|--plan|--check|--apply [--template <spec>|--latest] [--json] [--out <path>]");
52
+ console.log(" or: topogram template update [path] --accept-current|--accept-candidate|--delete-current <file> [--template <spec>] [--json]");
53
+ console.log(" or: topogram generator list [--json]");
54
+ console.log(" or: topogram generator show <id-or-package> [--json]");
55
+ console.log(" or: topogram generator check <path-or-package> [--json]");
56
+ console.log(" or: topogram generator policy init [path] [--json]");
57
+ console.log(" or: topogram generator policy status [path] [--json]");
58
+ console.log(" or: topogram generator policy check [path] [--json]");
59
+ console.log(" or: topogram generator policy explain [path] [--json]");
60
+ console.log(" or: topogram generator policy pin [package@version] [path] [--json]");
61
+ console.log(" or: topogram new <path> [--template hello-web|todo|./local-template|@scope/template]");
62
+ console.log(" or: topogram new <path> --template <package> --allow-local-npmrc");
63
+ console.log(" or: topogram new --list-templates [--json] [--catalog <path-or-source>]");
64
+ console.log("");
65
+ console.log("Common commands:");
66
+ console.log(" topogram version");
67
+ console.log(" topogram doctor");
68
+ console.log(" topogram setup package-auth");
69
+ console.log(" topogram release status");
70
+ console.log(" topogram release roll-consumers --latest");
71
+ console.log(" topogram new ./my-app");
72
+ console.log(" topogram new --list-templates");
73
+ console.log(" topogram new ./my-app --template todo");
74
+ console.log(" topogram check");
75
+ console.log(" topogram check --json");
76
+ console.log(" topogram widget check --projection proj_web_surface");
77
+ console.log(" topogram widget behavior --projection proj_web_surface");
78
+ console.log(" topogram agent brief");
79
+ console.log(" topogram agent brief --json");
80
+ console.log(" topogram query list");
81
+ console.log(" topogram query show widget-behavior");
82
+ console.log(" topogram query widget-behavior ./topogram --projection proj_web_surface --json");
83
+ console.log(" topogram emit ui-widget-contract --widget widget_data_grid --json");
84
+ console.log(" topogram emit widget-conformance-report ./topogram --projection proj_web_surface --json");
85
+ console.log(" topogram generator list");
86
+ console.log(" topogram generator show @topogram/generator-react-web");
87
+ console.log(" topogram generator check ./generator-package");
88
+ console.log(" topogram generator policy check");
89
+ console.log(" topogram generate");
90
+ console.log(" topogram import ./existing-app --out ./imported-topogram");
91
+ console.log(" topogram import diff ./imported-topogram");
92
+ console.log(" topogram import refresh ./imported-topogram --from ./existing-app --dry-run");
93
+ console.log(" topogram import check ./imported-topogram");
94
+ console.log(" topogram import plan ./imported-topogram");
95
+ console.log(" topogram import adopt --list ./imported-topogram");
96
+ console.log(" topogram import adopt bundle:task ./imported-topogram --dry-run");
97
+ console.log(" topogram import status ./imported-topogram");
98
+ console.log(" topogram import history ./imported-topogram --verify");
99
+ console.log("");
100
+ console.log("Fresh install:");
101
+ console.log(" npm install --save-dev @topogram/cli");
102
+ console.log(" npx topogram doctor");
103
+ console.log(" npx topogram template list");
104
+ console.log(" npx topogram new ./my-app --template hello-web");
105
+ console.log(" cd ./my-app && npm install && npm run check && npm run generate");
106
+ console.log(" npm --prefix app run compile");
107
+ console.log("");
108
+ console.log("Template and catalog discovery:");
109
+ console.log(" topogram template list");
110
+ console.log(" topogram catalog list");
111
+ console.log(" topogram catalog show todo");
112
+ console.log(" topogram catalog doctor");
113
+ console.log(" topogram catalog check topograms.catalog.json");
114
+ console.log(" topogram catalog copy hello ./hello-topogram");
115
+ console.log(" topogram source status --local");
116
+ console.log(" topogram source status --remote");
117
+ console.log("");
118
+ console.log("Template trust and updates:");
119
+ console.log(" topogram trust template");
120
+ console.log(" topogram trust status");
121
+ console.log(" topogram trust diff");
122
+ console.log(" topogram package update-cli --latest");
123
+ console.log(" topogram template explain");
124
+ console.log(" topogram template status");
125
+ console.log(" topogram template status --latest");
126
+ console.log(" topogram template detach");
127
+ console.log(" topogram template policy init");
128
+ console.log(" topogram template policy check");
129
+ console.log(" topogram template policy explain");
130
+ console.log(" topogram template policy pin @scope/template@0.2.0");
131
+ console.log(" topogram template check ./local-template");
132
+ console.log(" topogram template update --status");
133
+ console.log(" topogram template update --recommend");
134
+ console.log(" topogram template update --recommend --latest");
135
+ console.log(" topogram template update --plan");
136
+ console.log(" topogram template update --check");
137
+ console.log(" topogram template update --apply");
138
+ console.log("");
139
+ console.log("Defaults: check/generate use ./topogram, and generate writes ./app.");
140
+ console.log("Default starter: hello-web from the catalog. Run `topogram template list` for catalog aliases.");
141
+ console.log("Generated app commands are emitted into the output package.json.");
142
+ console.log("Run `topogram help <command>` for command-specific help.");
143
+ console.log("Run `topogram help all` for legacy and agent-facing commands.");
144
+ if (!all) {
145
+ return;
146
+ }
147
+ console.log("");
148
+ console.log("Legacy and internal commands:");
149
+ console.log("Usage: topogram create <path> [--template hello-web|todo|./local-template|@scope/template]");
150
+ console.log(" or: topogram template show <id> [--json] [--catalog <path-or-source>]");
151
+ console.log(" or: topogram import app <path> [--from <track[,track]>] [--write]");
152
+ console.log(" or: topogram validate <path>");
153
+ console.log(" or: node ./src/cli.js query work-packet <path> --mode import-adopt --lane <id>");
154
+ console.log(" or: node ./src/cli.js <path> [--json] [--validate] [--resolve] [--workflow <name>] [--mode <id>] [--from <track[,track]>] [--adopt <selector>] [--refresh-adopted] [--shape <id>] [--capability <id>] [--widget <id>] [--projection <id>] [--entity <id>] [--journey <id>] [--surface <id>] [--task <id>] [--profile <id>] [--from-snapshot <path>] [--from-topogram <path>] [--write] [--out-dir <path>]");
155
+ console.log(" or: node ./src/cli.js emit <target> [path] [--json] [--write] [--out-dir <path>]");
156
+ console.log(" or: node ./src/cli.js import app <path> [--from <track[,track]>] [--write]");
157
+ console.log(" or: node ./src/cli.js import docs <path> [--write]");
158
+ console.log(" or: node ./src/cli.js generate journeys <path> [--write]");
159
+ console.log(" or: node ./src/cli.js report gaps <path> [--write]");
160
+ console.log(" or: node ./src/cli.js query task-mode <path> [--mode <id>] [--capability <id>] [--workflow <id>] [--projection <id>] [--widget <id>] [--entity <id>] [--journey <id>] [--from-topogram <path>]");
161
+ console.log(" or: node ./src/cli.js query adoption-plan <path>");
162
+ console.log(" or: node ./src/cli.js query maintained-boundary <path>");
163
+ console.log(" or: node ./src/cli.js query maintained-conformance <path> [--from-topogram <path>]");
164
+ console.log(" or: node ./src/cli.js query maintained-drift <path> --from-topogram <path>");
165
+ console.log(" or: node ./src/cli.js query seam-check <path> [--seam <id>] [--from-topogram <path>]");
166
+ console.log(" or: node ./src/cli.js query diff <path> --from-topogram <path>");
167
+ console.log(" or: node ./src/cli.js query slice <path> [--capability <id>] [--workflow <id>] [--projection <id>] [--widget <id>] [--entity <id>] [--journey <id>] [--domain <id>]");
168
+ console.log(" or: node ./src/cli.js query domain-list <path>");
169
+ console.log(" or: node ./src/cli.js query domain-coverage <path> --domain <id>");
170
+ console.log(" or: node ./src/cli.js query review-boundary <path> [--capability <id>] [--workflow <id>] [--projection <id>] [--widget <id>] [--entity <id>] [--journey <id>]");
171
+ console.log(" or: node ./src/cli.js query write-scope <path> [--mode <id>] [--capability <id>] [--workflow <id>] [--projection <id>] [--widget <id>] [--entity <id>] [--journey <id>] [--from-topogram <path>]");
172
+ console.log(" or: node ./src/cli.js query verification-targets <path> [--mode <id>] [--capability <id>] [--workflow <id>] [--projection <id>] [--widget <id>] [--entity <id>] [--journey <id>] [--from-topogram <path>]");
173
+ console.log(" or: node ./src/cli.js query widget-behavior <path> [--projection <id>] [--widget <id>] [--json]");
174
+ console.log(" or: node ./src/cli.js query change-plan <path> [--mode <id>] [--capability <id>] [--workflow <id>] [--projection <id>] [--widget <id>] [--entity <id>] [--journey <id>] [--surface <id>] [--from-topogram <path>]");
175
+ console.log(" or: node ./src/cli.js query import-plan <path>");
176
+ console.log(" or: node ./src/cli.js query risk-summary <path> [--mode <id>] [--capability <id>] [--workflow <id>] [--projection <id>] [--widget <id>] [--entity <id>] [--journey <id>] [--surface <id>] [--from-topogram <path>]");
177
+ console.log(" or: node ./src/cli.js query canonical-writes <path> [--mode <id>] [--capability <id>] [--workflow <id>] [--projection <id>] [--widget <id>] [--entity <id>] [--journey <id>] [--surface <id>] [--from-topogram <path>]");
178
+ console.log(" or: node ./src/cli.js query proceed-decision <path> [--mode <id>] [--capability <id>] [--workflow <id>] [--projection <id>] [--widget <id>] [--entity <id>] [--journey <id>] [--surface <id>] [--from-topogram <path>]");
179
+ console.log(" or: node ./src/cli.js query review-packet <path> [--mode <id>] [--capability <id>] [--workflow <id>] [--projection <id>] [--widget <id>] [--entity <id>] [--journey <id>] [--surface <id>] [--from-topogram <path>]");
180
+ console.log(" or: node ./src/cli.js query next-action <path> [--mode <id>] [--capability <id>] [--workflow <id>] [--projection <id>] [--widget <id>] [--entity <id>] [--journey <id>] [--from-topogram <path>]");
181
+ console.log(" or: node ./src/cli.js query single-agent-plan <path> --mode <id> [--capability <id>] [--workflow <id>] [--projection <id>] [--widget <id>] [--entity <id>] [--journey <id>] [--surface <id>] [--from-topogram <path>]");
182
+ console.log(" or: node ./src/cli.js query multi-agent-plan <path> --mode import-adopt");
183
+ console.log(" or: node ./src/cli.js query resolved-workflow-context <path> --mode <id> [--capability <id>] [--workflow <id>] [--projection <id>] [--widget <id>] [--entity <id>] [--journey <id>] [--surface <id>] [--provider <id>] [--preset <id>] [--from-topogram <path>]");
184
+ console.log(" or: node ./src/cli.js query workflow-preset-activation <path> --mode <id> [--provider <id>] [--preset <id>] [--from-topogram <path>]");
185
+ console.log(" or: node ./src/cli.js query workflow-preset-diff <path> --provider <id> [--preset <id>]");
186
+ console.log(" or: node ./src/cli.js query workflow-preset-customization <path> --provider <id> --preset <id>");
187
+ console.log(" or: node ./src/cli.js workflow-preset customize <path> --provider <id> --preset <id> [--out <path>] [--write]");
188
+ console.log(" or: node ./src/cli.js query lane-status <path> --mode import-adopt");
189
+ console.log(" or: node ./src/cli.js query handoff-status <path> --mode import-adopt");
190
+ console.log(" or: node ./src/cli.js query auth-hints <path>");
191
+ console.log(" or: node ./src/cli.js query auth-review-packet <path> --bundle <slug>");
192
+ console.log(" or: node ./src/cli.js reconcile <path> [--write]");
193
+ console.log(" or: node ./src/cli.js reconcile adopt <selector> <path> [--refresh-adopted] [--write]");
194
+ console.log(" or: node ./src/cli.js adoption status <path> [--write]");
195
+ console.log("Targets: json-schema, docs, docs-index, verification-plan, verification-checklist, shape-transform-graph, shape-transform-debug, api-contract-graph, api-contract-debug, ui-contract-graph, ui-contract-debug, ui-widget-contract, widget-conformance-report, widget-behavior-report, ui-surface-contract, ui-surface-debug, sveltekit-app, swiftui-app, db-contract-graph, db-contract-debug, db-schema-snapshot, db-migration-plan, db-lifecycle-plan, db-lifecycle-bundle, environment-plan, environment-bundle, deployment-plan, deployment-bundle, runtime-smoke-plan, runtime-smoke-bundle, runtime-check-plan, runtime-check-bundle, compile-check-plan, compile-check-bundle, app-bundle-plan, app-bundle, native-parity-plan, native-parity-bundle, sql-migration, sql-schema, prisma-schema, drizzle-schema, persistence-scaffold, server-contract, hono-server, openapi, context-digest, context-diff, context-slice, context-bundle, context-report, context-task-mode");
196
+ console.log("Workflows: import-app, scan-docs, reconcile, adoption-status, generate-docs, generate-journeys, refresh-docs, report-gaps");
197
+ console.log("Import tracks: db, api, ui, workflows, verification");
198
+ console.log("Reconcile adopt selectors: from-plan, actors, roles, enums, shapes, entities, capabilities, widgets, docs, journeys, workflows, ui, bundle:<slug>, projection-review:<id>, ui-review:<id>, workflow-review:<id>, bundle-review:<slug>");
199
+ }
200
+
201
+ /**
202
+ * @returns {void}
203
+ */
204
+ export function printNewHelp() {
205
+ console.log("Usage: topogram new <path> [--template <alias|package|path>] [--catalog <path-or-source>]");
206
+ console.log(" or: topogram new --list-templates [--json] [--catalog <path-or-source>]");
207
+ console.log("");
208
+ console.log("Creates a new editable Topogram workspace from a template package or local template path.");
209
+ console.log("");
210
+ console.log("Fresh install flow:");
211
+ console.log(" npm install --save-dev @topogram/cli");
212
+ console.log(" npx topogram template list");
213
+ console.log(" npx topogram new ./my-app --template hello-web");
214
+ console.log(" cd ./my-app && npm install && npm run check && npm run generate");
215
+ console.log(" npm --prefix app run compile");
216
+ console.log("");
217
+ console.log("Examples:");
218
+ console.log(" topogram new ./my-app");
219
+ console.log(" topogram new --list-templates");
220
+ console.log(" topogram new ./my-app --template hello-web");
221
+ console.log(" topogram new ./my-app --template ./local-template");
222
+ console.log(" topogram new ./my-app --template @scope/topogram-template");
223
+ console.log("");
224
+ console.log("Default template: hello-web from the configured catalog.");
225
+ }
226
+
227
+ /**
228
+ * @returns {void}
229
+ */
230
+ export function printGenerateHelp() {
231
+ console.log("Usage: topogram generate [path] [--out <path>]");
232
+ console.log(" or: topogram generate app [path] [--out <path>]");
233
+ console.log("");
234
+ console.log("Defaults: path is ./topogram and app generation writes ./app.");
235
+ console.log("Use `topogram emit <target>` for contracts, reports, snapshots, migration plans, and other artifacts.");
236
+ console.log("");
237
+ console.log("Examples:");
238
+ console.log(" topogram generate");
239
+ console.log(" topogram generate ./topogram --out ./app");
240
+ console.log(" topogram generate app ./topogram --out ./app");
241
+ }
242
+
243
+ /**
244
+ * @returns {void}
245
+ */
246
+ export function printEmitHelp() {
247
+ console.log("Usage: topogram emit <target> [path] [--json]");
248
+ console.log(" or: topogram emit <target> [path] --write [--out-dir <path>]");
249
+ console.log("");
250
+ console.log("Emits named contracts, reports, snapshots, migration plans, and other artifacts.");
251
+ console.log("");
252
+ console.log("Defaults: path is ./topogram. Emit prints to stdout unless --write is passed. --write writes ./artifacts unless --out-dir is supplied.");
253
+ console.log("");
254
+ console.log("Common artifact targets:");
255
+ console.log(" ui-widget-contract");
256
+ console.log(" widget-conformance-report");
257
+ console.log(" widget-behavior-report");
258
+ console.log(" context-slice");
259
+ console.log(" context-diff");
260
+ console.log(" verification-targets");
261
+ console.log("");
262
+ console.log("Selectors:");
263
+ console.log(" --widget <id>");
264
+ console.log(" --capability <id>");
265
+ console.log(" --projection <id>");
266
+ console.log(" --entity <id>");
267
+ console.log(" --journey <id>");
268
+ console.log("");
269
+ console.log("Examples:");
270
+ console.log(" topogram emit ui-widget-contract --widget widget_data_grid --json");
271
+ console.log(" topogram emit widget-conformance-report ./topogram --projection proj_web_surface --json");
272
+ console.log(" topogram emit widget-behavior-report ./topogram --projection proj_web_surface --json");
273
+ console.log(" topogram emit db-schema-snapshot ./topogram --projection proj_db_postgres --json");
274
+ console.log(" topogram emit sql-migration ./topogram --projection proj_db_postgres --from-snapshot ./state/current.json");
275
+ console.log(" topogram emit ui-widget-contract --write --out-dir ./contracts");
276
+ }
277
+
278
+ /**
279
+ * @returns {void}
280
+ */
281
+ export function printWidgetHelp() {
282
+ console.log("Usage: topogram widget check [path] [--projection <id>] [--widget <id>] [--json]");
283
+ console.log(" or: topogram widget behavior [path] [--projection <id>] [--widget <id>] [--json]");
284
+ console.log("");
285
+ console.log("Checks projection widget_bindings usage against reusable widget contracts and behavior realizations.");
286
+ console.log("");
287
+ console.log("Defaults: path is ./topogram.");
288
+ console.log("");
289
+ console.log("Examples:");
290
+ console.log(" topogram widget check");
291
+ console.log(" topogram widget check --projection proj_web_surface");
292
+ console.log(" topogram widget check ./topogram --widget widget_data_grid --json");
293
+ console.log(" topogram widget behavior");
294
+ console.log(" topogram widget behavior --projection proj_web_surface");
295
+ console.log(" topogram widget behavior ./topogram --widget widget_data_grid --json");
296
+ }
@@ -0,0 +1,59 @@
1
+ // @ts-check
2
+
3
+ const RENAMED_CLI_ARGS = new Map([
4
+ ["--component", "--widget"]
5
+ ]);
6
+ const RENAMED_GENERATE_TARGETS = new Map([
7
+ ["ui-component-contract", "ui-widget-contract"],
8
+ ["component-conformance-report", "widget-conformance-report"],
9
+ ["component-behavior-report", "widget-behavior-report"],
10
+ ["ui-web-contract", "ui-surface-contract"],
11
+ ["ui-web-debug", "ui-surface-debug"]
12
+ ]);
13
+
14
+ /**
15
+ * @param {string[]} args
16
+ * @param {number} index
17
+ * @param {string} [fallback]
18
+ * @returns {string}
19
+ */
20
+ function commandPath(args, index, fallback = "./topogram") {
21
+ const value = args[index];
22
+ return value && !value.startsWith("-") ? value : fallback;
23
+ }
24
+
25
+ /**
26
+ * @param {string[]} args
27
+ * @returns {string|null}
28
+ */
29
+ export function cliMigrationError(args) {
30
+ if (args[0] === "component") {
31
+ return "Command 'topogram component' was renamed to 'topogram widget'.";
32
+ }
33
+ for (const [oldArg, newArg] of RENAMED_CLI_ARGS) {
34
+ if (args.includes(oldArg)) {
35
+ return `CLI flag '${oldArg}' was renamed to '${newArg}'.`;
36
+ }
37
+ }
38
+ const removedGenerateIndex = args.indexOf("--generate");
39
+ if (removedGenerateIndex >= 0) {
40
+ const target = args[removedGenerateIndex + 1];
41
+ const input = args[0] === "generate" ? commandPath(args, 1) : commandPath(args, 0);
42
+ const replacement = target && !target.startsWith("-")
43
+ ? `topogram emit ${target} ${input}`
44
+ : "topogram emit <target> <path>";
45
+ return `The artifact flag '--generate' was removed. Use '${replacement}' instead.`;
46
+ }
47
+ return null;
48
+ }
49
+
50
+ /**
51
+ * @param {string|null|undefined} target
52
+ * @returns {string|null}
53
+ */
54
+ export function artifactTargetMigrationError(target) {
55
+ if (!target || !RENAMED_GENERATE_TARGETS.has(target)) {
56
+ return null;
57
+ }
58
+ return `Artifact target '${target}' was renamed to '${RENAMED_GENERATE_TARGETS.get(target)}'.`;
59
+ }
@@ -0,0 +1,96 @@
1
+ // @ts-check
2
+
3
+ import path from "node:path";
4
+
5
+ /**
6
+ * @param {string[]} args
7
+ * @param {string} flag
8
+ * @returns {string|null}
9
+ */
10
+ export function optionValue(args, flag) {
11
+ const index = args.indexOf(flag);
12
+ return index >= 0 ? args[index + 1] || null : null;
13
+ }
14
+
15
+ /**
16
+ * @param {string[]} args
17
+ * @param {string} flag
18
+ * @returns {string|null}
19
+ */
20
+ export function optionValueIfPresent(args, flag) {
21
+ const value = optionValue(args, flag);
22
+ return value && !value.startsWith("-") ? value : null;
23
+ }
24
+
25
+ /**
26
+ * @param {string[]} args
27
+ * @param {string} flag
28
+ * @returns {string|null}
29
+ */
30
+ function resolvedPathOption(args, flag) {
31
+ const value = optionValue(args, flag);
32
+ return value ? path.resolve(value) : null;
33
+ }
34
+
35
+ /**
36
+ * @param {string[]} args
37
+ * @param {Record<string, any>|null|undefined} commandArgs
38
+ * @returns {Record<string, any>}
39
+ */
40
+ export function parseCliOptions(args, commandArgs) {
41
+ const generateTarget = commandArgs?.generateTarget || null;
42
+ const workflowFlagValue = optionValue(args, "--workflow");
43
+ const outDir = optionValue(args, "--out-dir");
44
+ const outPath = optionValue(args, "--out");
45
+ return {
46
+ emitJson: args.includes("--json"),
47
+ shouldForce: Boolean(commandArgs?.force) || args.includes("--force"),
48
+ shouldValidate: Boolean(commandArgs?.validate) || args.includes("--validate"),
49
+ shouldResolve: args.includes("--resolve"),
50
+ generateTarget,
51
+ workflowName: commandArgs?.workflowName || (!generateTarget && workflowFlagValue ? workflowFlagValue : null),
52
+ workflowId: generateTarget ? workflowFlagValue : null,
53
+ fromValue: optionValue(args, "--from"),
54
+ adoptValue: commandArgs?.adoptValue || optionValue(args, "--adopt"),
55
+ reasonValue: optionValueIfPresent(args, "--reason"),
56
+ modeId: optionValue(args, "--mode"),
57
+ profileId: optionValue(args, "--profile"),
58
+ providerId: optionValue(args, "--provider"),
59
+ presetId: optionValue(args, "--preset"),
60
+ templateName: optionValue(args, "--template") || "hello-web",
61
+ catalogSource: optionValueIfPresent(args, "--catalog"),
62
+ requestedVersion: optionValueIfPresent(args, "--version"),
63
+ bundleSlug: optionValue(args, "--bundle"),
64
+ laneId: optionValue(args, "--lane"),
65
+ fromSnapshotPath: resolvedPathOption(args, "--from-snapshot"),
66
+ fromTopogramPath: resolvedPathOption(args, "--from-topogram"),
67
+ shouldWrite: Boolean(commandArgs?.write) || args.includes("--write"),
68
+ refreshAdopted: args.includes("--refresh-adopted"),
69
+ outPath,
70
+ effectiveOutDir: outDir || outPath || commandArgs?.defaultOutDir || null,
71
+ selectors: {
72
+ shapeId: optionValue(args, "--shape"),
73
+ capabilityId: optionValue(args, "--capability"),
74
+ workflowId: generateTarget ? workflowFlagValue : null,
75
+ projectionId: optionValue(args, "--projection"),
76
+ widgetId: optionValue(args, "--widget"),
77
+ componentId: optionValue(args, "--widget"),
78
+ entityId: optionValue(args, "--entity"),
79
+ journeyId: optionValue(args, "--journey"),
80
+ surfaceId: optionValue(args, "--surface"),
81
+ domainId: optionValue(args, "--domain"),
82
+ seamId: optionValue(args, "--seam"),
83
+ taskId: optionValue(args, "--task"),
84
+ pitchId: optionValue(args, "--pitch"),
85
+ requirementId: optionValue(args, "--requirement"),
86
+ acceptanceId: optionValue(args, "--acceptance"),
87
+ bugId: optionValue(args, "--bug"),
88
+ documentId: optionValue(args, "--document"),
89
+ kind: optionValue(args, "--kind"),
90
+ appVersion: optionValue(args, "--app-version"),
91
+ sinceTag: optionValue(args, "--since-tag"),
92
+ includeArchived: args.includes("--include-archived"),
93
+ modeId: optionValue(args, "--mode")
94
+ }
95
+ };
96
+ }
@@ -0,0 +1,107 @@
1
+ // @ts-check
2
+
3
+ import fs from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+
7
+ import { outputOwnershipForPath } from "../project-config.js";
8
+
9
+ export const GENERATED_OUTPUT_SENTINEL = ".topogram-generated.json";
10
+
11
+ const REPO_ROOT = path.resolve(decodeURIComponent(new URL("../../../", import.meta.url).pathname));
12
+
13
+ /**
14
+ * @param {string} parent
15
+ * @param {string} child
16
+ * @returns {boolean}
17
+ */
18
+ function isSameOrInside(parent, child) {
19
+ const relative = path.relative(path.resolve(parent), path.resolve(child));
20
+ return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
21
+ }
22
+
23
+ /**
24
+ * @param {string} message
25
+ * @returns {never}
26
+ */
27
+ function rejectOutputDir(message) {
28
+ throw new Error(`${message} Choose a generated output directory such as ./app.`);
29
+ }
30
+
31
+ /**
32
+ * @param {string} outDir
33
+ * @param {string} topogramRoot
34
+ * @returns {void}
35
+ */
36
+ export function assertSafeGeneratedOutputDir(outDir, topogramRoot) {
37
+ const resolvedOutDir = path.resolve(outDir);
38
+ const resolvedTopogramRoot = path.resolve(topogramRoot);
39
+ const homeDir = path.resolve(os.homedir());
40
+ const cwd = path.resolve(process.cwd());
41
+
42
+ if (resolvedOutDir === cwd) {
43
+ rejectOutputDir("Refusing to replace the current working directory.");
44
+ }
45
+ if (resolvedOutDir === REPO_ROOT) {
46
+ rejectOutputDir("Refusing to replace the repository root.");
47
+ }
48
+ if (resolvedOutDir === homeDir) {
49
+ rejectOutputDir("Refusing to replace the home directory.");
50
+ }
51
+ if (isSameOrInside(resolvedOutDir, resolvedTopogramRoot) || isSameOrInside(resolvedTopogramRoot, resolvedOutDir)) {
52
+ rejectOutputDir("Refusing to replace the Topogram source directory or one of its parents/children.");
53
+ }
54
+
55
+ if (!fs.existsSync(resolvedOutDir)) {
56
+ return;
57
+ }
58
+ const stat = fs.statSync(resolvedOutDir);
59
+ if (!stat.isDirectory()) {
60
+ throw new Error(`Refusing to write generated output over non-directory path: ${resolvedOutDir}`);
61
+ }
62
+ const hasSentinel = fs.existsSync(path.join(resolvedOutDir, GENERATED_OUTPUT_SENTINEL));
63
+ const isEmpty = fs.readdirSync(resolvedOutDir).length === 0;
64
+ if (!isEmpty && !hasSentinel) {
65
+ rejectOutputDir(
66
+ `Refusing to replace non-empty directory without ${GENERATED_OUTPUT_SENTINEL}: ${resolvedOutDir}.`
67
+ );
68
+ }
69
+ }
70
+
71
+ /**
72
+ * @param {{ config: any, configPath: string|null, configDir: string }|null|undefined} configInfo
73
+ * @param {string} outDir
74
+ * @returns {void}
75
+ */
76
+ export function assertProjectOutputAllowsWrite(configInfo, outDir) {
77
+ const ownership = outputOwnershipForPath(configInfo, outDir);
78
+ if (ownership?.ownership === "maintained") {
79
+ throw new Error(
80
+ `Refusing to write generated output to maintained output '${ownership.name}': ${ownership.path}`
81
+ );
82
+ }
83
+ }
84
+
85
+ /**
86
+ * @param {string} target
87
+ * @returns {string}
88
+ */
89
+ export function generatedOutputSentinel(target) {
90
+ return `${JSON.stringify({
91
+ generated_by: "topogram",
92
+ target,
93
+ safe_to_replace: true
94
+ }, null, 2)}\n`;
95
+ }
96
+
97
+ /**
98
+ * @param {string} inputPath
99
+ * @returns {string}
100
+ */
101
+ export function topogramInputPathForGeneration(inputPath) {
102
+ const absolute = path.resolve(inputPath);
103
+ if (isSameOrInside(REPO_ROOT, absolute)) {
104
+ return `./${path.relative(REPO_ROOT, absolute).replace(/\\/g, "/")}`;
105
+ }
106
+ return path.basename(absolute) === "topogram" ? "./topogram" : ".";
107
+ }
@@ -0,0 +1,29 @@
1
+ // @ts-check
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+
6
+ /**
7
+ * @param {string} inputPath
8
+ * @returns {string}
9
+ */
10
+ export function normalizeTopogramPath(inputPath) {
11
+ const absolute = path.resolve(inputPath);
12
+ if (path.basename(absolute) === "topogram") {
13
+ return absolute;
14
+ }
15
+ const candidate = path.join(absolute, "topogram");
16
+ return fs.existsSync(candidate) ? candidate : absolute;
17
+ }
18
+
19
+ /**
20
+ * @param {string} inputPath
21
+ * @returns {string}
22
+ */
23
+ export function normalizeProjectRoot(inputPath) {
24
+ const absolute = path.resolve(inputPath);
25
+ if (path.basename(absolute) === "topogram") {
26
+ return path.dirname(absolute);
27
+ }
28
+ return absolute;
29
+ }