nexarch 0.12.6 → 0.12.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ import { appliedPolicies } from "./commands/applied-policies.js";
26
26
  import { governanceSummary } from "./commands/governance-summary.js";
27
27
  import { proposalsStart } from "./commands/proposals-start.js";
28
28
  import { registerRuntime } from "./commands/register-runtime.js";
29
+ import { ingestInfra } from "./commands/ingest-infra.js";
29
30
  const [, , command, ...args] = process.argv;
30
31
  const commands = {
31
32
  login,
@@ -37,6 +38,7 @@ const commands = {
37
38
  "init-agent": initAgent,
38
39
  "agent-identify": agentIdentify,
39
40
  "init-project": initProject,
41
+ "ingest-infra": ingestInfra,
40
42
  "update-project": (args) => initProject(["--refresh", ...args]),
41
43
  "update-entity": updateEntity,
42
44
  "add-relationship": addRelationship,
@@ -73,198 +75,206 @@ async function main() {
73
75
  }
74
76
  const handler = commands[command ?? ""];
75
77
  if (!handler) {
76
- console.log(`
77
- nexarch — Your architecture workspace for AI delivery.
78
-
79
- Usage:
80
- nexarch login Authenticate in browser and store company-scoped credentials
81
- Option: --company <id>
82
- nexarch logout Remove stored credentials
83
- nexarch status Check connection and show architecture summary
84
- nexarch setup One-step onboarding: login (if needed) + MCP config + register agent
85
- nexarch mcp-config Print MCP server config block for manual setup
86
- Client list is registry-managed (see 'nexarch mcp-config --client <code>')
87
- nexarch mcp-proxy Run as stdio MCP proxy (used by MCP clients)
88
- nexarch init-agent Run handshake + mandatory agent registration in graph (advanced/manual)
89
- Options: --agent-id <id> --bind-to-external-key <key>
90
- --bind-relationship-type <code> --redact-hostname
91
- --json --strict
92
- nexarch agent identify
93
- Capture richer coding-agent identity metadata
94
- Options: --agent-id <id> --provider <provider> --model <model>
95
- --client <name> [--framework <name>] [--session-id <id>]
96
- [--tool-version <v>] [--capabilities <csv>]
97
- [--notes <text>] [--json]
98
- nexarch agent-identify
99
- Alias of 'nexarch agent identify'
100
- nexarch init-project
101
- Scan a project directory, resolve detected packages/env vars/
102
- config files against the reference library, write entities and
103
- relationships to the architecture graph, and log unresolved
104
- names as reference candidates.
105
- Monorepos register a project entity plus one proposed
106
- application per deployable package (sourced_from the project).
107
- Single-package repos register the repo's one application; when
108
- similar applications exist they are listed, and the new
109
- application is created as proposed for review at activation.
110
- Options: --dir <path> (default: cwd)
111
- --name <name> override project name
112
- --entity-type <code> (default: application)
113
- --application-ref <entityRef> force mapping target
114
- --create-application force new application entity
115
- --auto-map-application auto-map only when high confidence
116
- --non-interactive deprecated (mapping no longer prompts)
117
- --batch-size <n> upsert batch size (default: 10)
118
- --profile include timing/profile data in JSON output
119
- --dry-run preview without writing
120
- --json
121
- nexarch update-project
122
- Re-scan a previously registered project directory, refresh
123
- entities and relationships in the graph, and diff the new scan
124
- against the current graph state to surface stale relationships
125
- and removed sub-packages for the calling agent to review.
126
- Accepts all the same options as init-project plus:
127
- --application-ref <entityRef> target project key (recommended)
128
- --auto-map-application auto-select best-match application
129
- Output includes enrichmentRequired.diff with:
130
- newRelationships — detected but not yet in graph
131
- staleRelationships — in graph but absent from manifests
132
- removedSubPackages — previously registered, no longer on disk
133
- --json
134
- nexarch update-entity
135
- Update the name and/or description of an existing graph entity.
136
- Use this after init-project to enrich the entity with meaningful
137
- content from the project README or docs.
138
- Options: --key <externalKey> (required)
139
- --name <name>
140
- --description <text>
141
- --entity-type <code> (default: application)
142
- --subtype <code>
143
- --icon <lucide-name> (convenience; sets attributes.application_icon)
144
- --attributes-json '<json object>'
145
- --attributes-file <path.json>
146
- --json
147
- nexarch add-relationship
148
- Add relationships between existing graph entities (single or batch).
149
- Single options: --from <externalKey>
150
- --to <externalKey>
151
- --type <code> (e.g. part_of, depends_on)
152
- Batch options: --relationships-json '<json array>'
153
- --relationships-file <path.json>
154
- --json
155
- nexarch register-alias
156
- Register a company-scoped alias for an entity so future
157
- scans resolve it instead of logging it as a candidate.
158
- Use after enriching internal monorepo packages.
159
- Options: --alias <value> (required, e.g. @scope/name)
160
- --key <externalKey> (required)
161
- --name <name> (required)
162
- --entity-type <code> (required)
163
- --subtype <code>
164
- --description <text>
165
- --json
166
- nexarch resolve-names
167
- Look up one or more raw names (package names, platform
168
- names) against the global reference library and return
169
- their canonical external keys. Useful for gap-check
170
- results before calling add-relationship.
171
- Options: --names <csv> (required, e.g. "vercel,neon")
172
- --json
173
- nexarch list-entities
174
- List entities from the workspace graph.
175
- Options: --type <entityTypeCode>
176
- --status <status>
177
- --query <text>
178
- --limit <1-500>
179
- --json
180
- nexarch list-relationships
181
- List relationships from the workspace graph.
182
- Options: --type <relationshipTypeCode>
183
- --status <status>
184
- --from <fromExternalKey>
185
- --to <toExternalKey>
186
- --limit <1-500>
187
- --json
188
- nexarch register-runtime
189
- Register or refresh runtime + optional application context
190
- without performing check-in.
191
- Options: --application-ref <entityRef>
192
- --client <name>
193
- --version <semver>
194
- --json
195
- nexarch check-in Preview pending application-target commands (no auto-claim)
196
- and report draft/proposed applications needing review so the
197
- agent can prompt the user to explore and instantiate them.
198
- Use command-claim to explicitly claim a specific command.
199
- Scope is resolved server-side from active company context.
200
- Options: --agent-key <key> override stored agent key
201
- --application-ref <entityRef> narrow preview scope
202
- --json JSON output includes draftApplications[] and proposedApplications[]
203
- nexarch proposals start
204
- Start a new application workspace from a proposed NexArch app.
205
- Lists proposed apps, shows policy review gates, writes a starter
206
- project scaffold, and activates the proposal to active once
207
- required policy controls are acknowledged.
208
- Options: --id <applicationId>
209
- --dir <path>
210
- --reason <text>
211
- --repo <url>
212
- --skip-activate
213
- --activate
214
- --force
215
- --non-interactive
216
- --json
217
- nexarch command-claim
218
- Explicitly claim a pending command by ID.
219
- Options: --id <commandId> (required)
220
- --agent-key <key> override stored agent key
221
- --application-ref <entityRef> required for application-target commands
222
- --json
223
- nexarch command-done
224
- Mark a claimed command as completed.
225
- Options: --id <commandId> (required)
226
- --summary <text> short summary of what was done
227
- --summary-file <path.md|txt>
228
- --json
229
- nexarch command-fail
230
- Mark a claimed command as failed.
231
- Options: --id <commandId> (required)
232
- --error <message> (required)
233
- --json
234
- nexarch policy-controls
235
- Fetch policy controls/rules assigned to an entity (for policy audits).
236
- Options: --entity <externalKey> (required, e.g. application:bad-driving)
237
- --json
238
- nexarch policy-audit-template
239
- Generate a findings JSON template from policy controls/rules for an entity.
240
- Options: --entity <externalKey> (required)
241
- --control-id <uuid> (repeatable; optional filter)
242
- --default-result <pass|partial|fail> (default: fail)
243
- --output <path.json>
244
- --json
245
- nexarch policy-audit-submit
246
- Submit structured policy findings (writes policy_audit_finding rows).
247
- Options: --command-id <id> (required)
248
- --application-key <key> (required)
249
- --agent-key <key> (optional; defaults from identity)
250
- --finding <controlId|ruleId|result|rationale|missing1;missing2> (repeatable)
251
- --findings-json <json-array>
252
- --findings-file <path.json>
253
- --json
254
- nexarch policy-audit-results
255
- Retrieve stored results of previous policy audits for an application.
256
- Options: --entity <applicationEntityRef> (required)
257
- --limit <1-10> (default 1)
258
- --json
259
- nexarch applied-policies
260
- List policy documents applied to this company account.
261
- Options: --pack <packCode> filter to a specific pack
262
- --markdown include full document markdown
263
- --json
264
- nexarch governance-summary
265
- Print review queue, graph stats, and per-application policy
266
- audit rollup (latest run status, pass/partial/fail counts).
267
- Options: --json
78
+ console.log(`
79
+ nexarch — Your architecture workspace for AI delivery.
80
+
81
+ Usage:
82
+ nexarch login Authenticate in browser and store company-scoped credentials
83
+ Option: --company <id>
84
+ nexarch logout Remove stored credentials
85
+ nexarch status Check connection and show architecture summary
86
+ nexarch setup One-step onboarding: login (if needed) + MCP config + register agent
87
+ Names the workspace it will write to and confirms it before
88
+ registering anything; answer 'n' to pick a different one.
89
+ Options: --company <id|code> target a workspace directly
90
+ --yes accept the stored workspace without asking
91
+ nexarch mcp-config Print MCP server config block for manual setup
92
+ Client list is registry-managed (see 'nexarch mcp-config --client <code>')
93
+ nexarch mcp-proxy Run as stdio MCP proxy (used by MCP clients)
94
+ nexarch init-agent Run handshake + mandatory agent registration in graph (advanced/manual)
95
+ Options: --agent-id <id> --bind-to-external-key <key>
96
+ --bind-relationship-type <code> --redact-hostname
97
+ --json --strict
98
+ nexarch agent identify
99
+ Capture richer coding-agent identity metadata
100
+ Options: --agent-id <id> --provider <provider> --model <model>
101
+ --client <name> [--framework <name>] [--session-id <id>]
102
+ [--tool-version <v>] [--capabilities <csv>]
103
+ [--notes <text>] [--json]
104
+ nexarch agent-identify
105
+ Alias of 'nexarch agent identify'
106
+ nexarch init-project
107
+ Scan a project directory, resolve detected packages/env vars/
108
+ config files against the reference library, write entities and
109
+ relationships to the architecture graph, and log unresolved
110
+ names as reference candidates.
111
+ Monorepos register a project entity plus one proposed
112
+ application per deployable package (sourced_from the project).
113
+ Single-package repos register the repo's one application; when
114
+ similar applications exist they are listed, and the new
115
+ application is created as proposed for review at activation.
116
+ Terraform repositories take a different path: no dependency
117
+ scan and no applications. They register a project plus the
118
+ environments their root modules define, and hand over the
119
+ per-root ingest-infra commands that read the actual estate.
120
+ Options: --dir <path> (default: cwd)
121
+ --name <name> override project name
122
+ --entity-type <code> (default: application)
123
+ --application-ref <entityRef> force mapping target
124
+ --create-application force new application entity
125
+ --auto-map-application auto-map only when high confidence
126
+ --non-interactive deprecated (mapping no longer prompts)
127
+ --batch-size <n> upsert batch size (default: 10)
128
+ --profile include timing/profile data in JSON output
129
+ --dry-run preview without writing
130
+ --json
131
+ nexarch update-project
132
+ Re-scan a previously registered project directory, refresh
133
+ entities and relationships in the graph, and diff the new scan
134
+ against the current graph state to surface stale relationships
135
+ and removed sub-packages for the calling agent to review.
136
+ Accepts all the same options as init-project plus:
137
+ --application-ref <entityRef> target project key (recommended)
138
+ --auto-map-application auto-select best-match application
139
+ Output includes enrichmentRequired.diff with:
140
+ newRelationships — detected but not yet in graph
141
+ staleRelationships — in graph but absent from manifests
142
+ removedSubPackages — previously registered, no longer on disk
143
+ --json
144
+ nexarch update-entity
145
+ Update the name and/or description of an existing graph entity.
146
+ Use this after init-project to enrich the entity with meaningful
147
+ content from the project README or docs.
148
+ Options: --key <externalKey> (required)
149
+ --name <name>
150
+ --description <text>
151
+ --entity-type <code> (default: application)
152
+ --subtype <code>
153
+ --icon <lucide-name> (convenience; sets attributes.application_icon)
154
+ --attributes-json '<json object>'
155
+ --attributes-file <path.json>
156
+ --json
157
+ nexarch add-relationship
158
+ Add relationships between existing graph entities (single or batch).
159
+ Single options: --from <externalKey>
160
+ --to <externalKey>
161
+ --type <code> (e.g. part_of, depends_on)
162
+ Batch options: --relationships-json '<json array>'
163
+ --relationships-file <path.json>
164
+ --json
165
+ nexarch register-alias
166
+ Register a company-scoped alias for an entity so future
167
+ scans resolve it instead of logging it as a candidate.
168
+ Use after enriching internal monorepo packages.
169
+ Options: --alias <value> (required, e.g. @scope/name)
170
+ --key <externalKey> (required)
171
+ --name <name> (required)
172
+ --entity-type <code> (required)
173
+ --subtype <code>
174
+ --description <text>
175
+ --json
176
+ nexarch resolve-names
177
+ Look up one or more raw names (package names, platform
178
+ names) against the global reference library and return
179
+ their canonical external keys. Useful for gap-check
180
+ results before calling add-relationship.
181
+ Options: --names <csv> (required, e.g. "vercel,neon")
182
+ --json
183
+ nexarch list-entities
184
+ List entities from the workspace graph.
185
+ Options: --type <entityTypeCode>
186
+ --status <status>
187
+ --query <text>
188
+ --limit <1-500>
189
+ --json
190
+ nexarch list-relationships
191
+ List relationships from the workspace graph.
192
+ Options: --type <relationshipTypeCode>
193
+ --status <status>
194
+ --from <fromExternalKey>
195
+ --to <toExternalKey>
196
+ --limit <1-500>
197
+ --json
198
+ nexarch register-runtime
199
+ Register or refresh runtime + optional application context
200
+ without performing check-in.
201
+ Options: --application-ref <entityRef>
202
+ --client <name>
203
+ --version <semver>
204
+ --json
205
+ nexarch check-in Preview pending application-target commands (no auto-claim)
206
+ and report draft/proposed applications needing review so the
207
+ agent can prompt the user to explore and instantiate them.
208
+ Use command-claim to explicitly claim a specific command.
209
+ Scope is resolved server-side from active company context.
210
+ Options: --agent-key <key> override stored agent key
211
+ --application-ref <entityRef> narrow preview scope
212
+ --json JSON output includes draftApplications[] and proposedApplications[]
213
+ nexarch proposals start
214
+ Start a new application workspace from a proposed NexArch app.
215
+ Lists proposed apps, shows policy review gates, writes a starter
216
+ project scaffold, and activates the proposal to active once
217
+ required policy controls are acknowledged.
218
+ Options: --id <applicationId>
219
+ --dir <path>
220
+ --reason <text>
221
+ --repo <url>
222
+ --skip-activate
223
+ --activate
224
+ --force
225
+ --non-interactive
226
+ --json
227
+ nexarch command-claim
228
+ Explicitly claim a pending command by ID.
229
+ Options: --id <commandId> (required)
230
+ --agent-key <key> override stored agent key
231
+ --application-ref <entityRef> required for application-target commands
232
+ --json
233
+ nexarch command-done
234
+ Mark a claimed command as completed.
235
+ Options: --id <commandId> (required)
236
+ --summary <text> short summary of what was done
237
+ --summary-file <path.md|txt>
238
+ --json
239
+ nexarch command-fail
240
+ Mark a claimed command as failed.
241
+ Options: --id <commandId> (required)
242
+ --error <message> (required)
243
+ --json
244
+ nexarch policy-controls
245
+ Fetch policy controls/rules assigned to an entity (for policy audits).
246
+ Options: --entity <externalKey> (required, e.g. application:bad-driving)
247
+ --json
248
+ nexarch policy-audit-template
249
+ Generate a findings JSON template from policy controls/rules for an entity.
250
+ Options: --entity <externalKey> (required)
251
+ --control-id <uuid> (repeatable; optional filter)
252
+ --default-result <pass|partial|fail> (default: fail)
253
+ --output <path.json>
254
+ --json
255
+ nexarch policy-audit-submit
256
+ Submit structured policy findings (writes policy_audit_finding rows).
257
+ Options: --command-id <id> (required)
258
+ --application-key <key> (required)
259
+ --agent-key <key> (optional; defaults from identity)
260
+ --finding <controlId|ruleId|result|rationale|missing1;missing2> (repeatable)
261
+ --findings-json <json-array>
262
+ --findings-file <path.json>
263
+ --json
264
+ nexarch policy-audit-results
265
+ Retrieve stored results of previous policy audits for an application.
266
+ Options: --entity <applicationEntityRef> (required)
267
+ --limit <1-10> (default 1)
268
+ --json
269
+ nexarch applied-policies
270
+ List policy documents applied to this company account.
271
+ Options: --pack <packCode> filter to a specific pack
272
+ --markdown include full document markdown
273
+ --json
274
+ nexarch governance-summary
275
+ Print review queue, graph stats, and per-application policy
276
+ audit rollup (latest run status, pass/partial/fail counts).
277
+ Options: --json
268
278
  `);
269
279
  process.exit(command ? 1 : 0);
270
280
  }
@@ -4,7 +4,35 @@ import { readFileSync, writeFileSync, mkdirSync, existsSync, rmSync } from "fs";
4
4
  function credentialsPath() {
5
5
  return join(homedir(), ".nexarch", "credentials.json");
6
6
  }
7
+ /**
8
+ * Credentials supplied by the environment, for CI.
9
+ *
10
+ * A pipeline cannot run `nexarch login` — that flow needs a browser and a
11
+ * human — so unattended commands such as `ingest-infra` take a service
12
+ * credential from the environment instead. `NEXARCH_TOKEN` is the token issued
13
+ * by `init-agent`; the company is carried by the token itself, so
14
+ * `NEXARCH_COMPANY_ID` is only needed for legacy static tokens.
15
+ *
16
+ * No local expiry check: the gateway is the authority on whether a service
17
+ * credential is still valid, and a stale clock in a runner should not be able
18
+ * to fail a build with a misleading "session expired".
19
+ */
20
+ function credentialsFromEnvironment() {
21
+ const token = process.env.NEXARCH_TOKEN?.trim();
22
+ if (!token)
23
+ return null;
24
+ return {
25
+ token,
26
+ email: process.env.NEXARCH_ACTOR ?? "ci",
27
+ company: "",
28
+ companyId: process.env.NEXARCH_COMPANY_ID?.trim() ?? "",
29
+ expiresAt: new Date(Date.now() + 60 * 60 * 1000).toISOString(),
30
+ };
31
+ }
7
32
  export function loadCredentials() {
33
+ const fromEnv = credentialsFromEnvironment();
34
+ if (fromEnv)
35
+ return fromEnv;
8
36
  const path = credentialsPath();
9
37
  if (!existsSync(path))
10
38
  return null;
@@ -35,8 +63,12 @@ export function removeCredentials() {
35
63
  export function requireCredentials() {
36
64
  const creds = loadCredentials();
37
65
  if (!creds) {
38
- throw new Error("Not logged in. Run `nexarch login` to authenticate.");
66
+ throw new Error("Not logged in. Run `nexarch login` to authenticate, or set NEXARCH_TOKEN for unattended use.");
39
67
  }
68
+ // Environment-supplied service credentials are validated by the gateway, not
69
+ // by this process; only the stored interactive session carries a local expiry.
70
+ if (process.env.NEXARCH_TOKEN?.trim())
71
+ return creds;
40
72
  if (new Date(creds.expiresAt) < new Date()) {
41
73
  throw new Error("Your session has expired. Run `nexarch login` to re-authenticate.");
42
74
  }