nexarch 0.12.6 → 0.12.7

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,202 @@ 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
+ nexarch mcp-config Print MCP server config block for manual setup
88
+ Client list is registry-managed (see 'nexarch mcp-config --client <code>')
89
+ nexarch mcp-proxy Run as stdio MCP proxy (used by MCP clients)
90
+ nexarch init-agent Run handshake + mandatory agent registration in graph (advanced/manual)
91
+ Options: --agent-id <id> --bind-to-external-key <key>
92
+ --bind-relationship-type <code> --redact-hostname
93
+ --json --strict
94
+ nexarch agent identify
95
+ Capture richer coding-agent identity metadata
96
+ Options: --agent-id <id> --provider <provider> --model <model>
97
+ --client <name> [--framework <name>] [--session-id <id>]
98
+ [--tool-version <v>] [--capabilities <csv>]
99
+ [--notes <text>] [--json]
100
+ nexarch agent-identify
101
+ Alias of 'nexarch agent identify'
102
+ nexarch init-project
103
+ Scan a project directory, resolve detected packages/env vars/
104
+ config files against the reference library, write entities and
105
+ relationships to the architecture graph, and log unresolved
106
+ names as reference candidates.
107
+ Monorepos register a project entity plus one proposed
108
+ application per deployable package (sourced_from the project).
109
+ Single-package repos register the repo's one application; when
110
+ similar applications exist they are listed, and the new
111
+ application is created as proposed for review at activation.
112
+ Terraform repositories take a different path: no dependency
113
+ scan and no applications. They register a project plus the
114
+ environments their root modules define, and hand over the
115
+ per-root ingest-infra commands that read the actual estate.
116
+ Options: --dir <path> (default: cwd)
117
+ --name <name> override project name
118
+ --entity-type <code> (default: application)
119
+ --application-ref <entityRef> force mapping target
120
+ --create-application force new application entity
121
+ --auto-map-application auto-map only when high confidence
122
+ --non-interactive deprecated (mapping no longer prompts)
123
+ --batch-size <n> upsert batch size (default: 10)
124
+ --profile include timing/profile data in JSON output
125
+ --dry-run preview without writing
126
+ --json
127
+ nexarch update-project
128
+ Re-scan a previously registered project directory, refresh
129
+ entities and relationships in the graph, and diff the new scan
130
+ against the current graph state to surface stale relationships
131
+ and removed sub-packages for the calling agent to review.
132
+ Accepts all the same options as init-project plus:
133
+ --application-ref <entityRef> target project key (recommended)
134
+ --auto-map-application auto-select best-match application
135
+ Output includes enrichmentRequired.diff with:
136
+ newRelationships — detected but not yet in graph
137
+ staleRelationships — in graph but absent from manifests
138
+ removedSubPackages — previously registered, no longer on disk
139
+ --json
140
+ nexarch update-entity
141
+ Update the name and/or description of an existing graph entity.
142
+ Use this after init-project to enrich the entity with meaningful
143
+ content from the project README or docs.
144
+ Options: --key <externalKey> (required)
145
+ --name <name>
146
+ --description <text>
147
+ --entity-type <code> (default: application)
148
+ --subtype <code>
149
+ --icon <lucide-name> (convenience; sets attributes.application_icon)
150
+ --attributes-json '<json object>'
151
+ --attributes-file <path.json>
152
+ --json
153
+ nexarch add-relationship
154
+ Add relationships between existing graph entities (single or batch).
155
+ Single options: --from <externalKey>
156
+ --to <externalKey>
157
+ --type <code> (e.g. part_of, depends_on)
158
+ Batch options: --relationships-json '<json array>'
159
+ --relationships-file <path.json>
160
+ --json
161
+ nexarch register-alias
162
+ Register a company-scoped alias for an entity so future
163
+ scans resolve it instead of logging it as a candidate.
164
+ Use after enriching internal monorepo packages.
165
+ Options: --alias <value> (required, e.g. @scope/name)
166
+ --key <externalKey> (required)
167
+ --name <name> (required)
168
+ --entity-type <code> (required)
169
+ --subtype <code>
170
+ --description <text>
171
+ --json
172
+ nexarch resolve-names
173
+ Look up one or more raw names (package names, platform
174
+ names) against the global reference library and return
175
+ their canonical external keys. Useful for gap-check
176
+ results before calling add-relationship.
177
+ Options: --names <csv> (required, e.g. "vercel,neon")
178
+ --json
179
+ nexarch list-entities
180
+ List entities from the workspace graph.
181
+ Options: --type <entityTypeCode>
182
+ --status <status>
183
+ --query <text>
184
+ --limit <1-500>
185
+ --json
186
+ nexarch list-relationships
187
+ List relationships from the workspace graph.
188
+ Options: --type <relationshipTypeCode>
189
+ --status <status>
190
+ --from <fromExternalKey>
191
+ --to <toExternalKey>
192
+ --limit <1-500>
193
+ --json
194
+ nexarch register-runtime
195
+ Register or refresh runtime + optional application context
196
+ without performing check-in.
197
+ Options: --application-ref <entityRef>
198
+ --client <name>
199
+ --version <semver>
200
+ --json
201
+ nexarch check-in Preview pending application-target commands (no auto-claim)
202
+ and report draft/proposed applications needing review so the
203
+ agent can prompt the user to explore and instantiate them.
204
+ Use command-claim to explicitly claim a specific command.
205
+ Scope is resolved server-side from active company context.
206
+ Options: --agent-key <key> override stored agent key
207
+ --application-ref <entityRef> narrow preview scope
208
+ --json JSON output includes draftApplications[] and proposedApplications[]
209
+ nexarch proposals start
210
+ Start a new application workspace from a proposed NexArch app.
211
+ Lists proposed apps, shows policy review gates, writes a starter
212
+ project scaffold, and activates the proposal to active once
213
+ required policy controls are acknowledged.
214
+ Options: --id <applicationId>
215
+ --dir <path>
216
+ --reason <text>
217
+ --repo <url>
218
+ --skip-activate
219
+ --activate
220
+ --force
221
+ --non-interactive
222
+ --json
223
+ nexarch command-claim
224
+ Explicitly claim a pending command by ID.
225
+ Options: --id <commandId> (required)
226
+ --agent-key <key> override stored agent key
227
+ --application-ref <entityRef> required for application-target commands
228
+ --json
229
+ nexarch command-done
230
+ Mark a claimed command as completed.
231
+ Options: --id <commandId> (required)
232
+ --summary <text> short summary of what was done
233
+ --summary-file <path.md|txt>
234
+ --json
235
+ nexarch command-fail
236
+ Mark a claimed command as failed.
237
+ Options: --id <commandId> (required)
238
+ --error <message> (required)
239
+ --json
240
+ nexarch policy-controls
241
+ Fetch policy controls/rules assigned to an entity (for policy audits).
242
+ Options: --entity <externalKey> (required, e.g. application:bad-driving)
243
+ --json
244
+ nexarch policy-audit-template
245
+ Generate a findings JSON template from policy controls/rules for an entity.
246
+ Options: --entity <externalKey> (required)
247
+ --control-id <uuid> (repeatable; optional filter)
248
+ --default-result <pass|partial|fail> (default: fail)
249
+ --output <path.json>
250
+ --json
251
+ nexarch policy-audit-submit
252
+ Submit structured policy findings (writes policy_audit_finding rows).
253
+ Options: --command-id <id> (required)
254
+ --application-key <key> (required)
255
+ --agent-key <key> (optional; defaults from identity)
256
+ --finding <controlId|ruleId|result|rationale|missing1;missing2> (repeatable)
257
+ --findings-json <json-array>
258
+ --findings-file <path.json>
259
+ --json
260
+ nexarch policy-audit-results
261
+ Retrieve stored results of previous policy audits for an application.
262
+ Options: --entity <applicationEntityRef> (required)
263
+ --limit <1-10> (default 1)
264
+ --json
265
+ nexarch applied-policies
266
+ List policy documents applied to this company account.
267
+ Options: --pack <packCode> filter to a specific pack
268
+ --markdown include full document markdown
269
+ --json
270
+ nexarch governance-summary
271
+ Print review queue, graph stats, and per-application policy
272
+ audit rollup (latest run status, pass/partial/fail counts).
273
+ Options: --json
268
274
  `);
269
275
  process.exit(command ? 1 : 0);
270
276
  }
@@ -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
  }