nexarch 0.1.32 → 0.1.33

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.
@@ -0,0 +1,97 @@
1
+ import process from "process";
2
+ import { existsSync, readFileSync } from "fs";
3
+ import { join } from "path";
4
+ import { homedir } from "os";
5
+ import { requireCredentials } from "../lib/credentials.js";
6
+ import { callMcpTool } from "../lib/mcp.js";
7
+ function parseFlag(args, flag) {
8
+ return args.includes(flag);
9
+ }
10
+ function parseOptionValue(args, option) {
11
+ const idx = args.indexOf(option);
12
+ if (idx === -1)
13
+ return null;
14
+ const v = args[idx + 1];
15
+ if (!v || v.startsWith("--"))
16
+ return null;
17
+ return v;
18
+ }
19
+ function parseToolText(result) {
20
+ const text = result.content?.[0]?.text ?? "{}";
21
+ return JSON.parse(text);
22
+ }
23
+ function loadStoredAgentKey() {
24
+ const identityPath = join(homedir(), ".nexarch", "identity.json");
25
+ if (!existsSync(identityPath))
26
+ return null;
27
+ try {
28
+ const data = JSON.parse(readFileSync(identityPath, "utf8"));
29
+ return data.agentKey ?? null;
30
+ }
31
+ catch {
32
+ return null;
33
+ }
34
+ }
35
+ const COMMAND_TYPE_HINTS = {
36
+ update_project: "Re-scan the project with `npx nexarch init-project` to update the architecture graph.",
37
+ drift_audit: "Compare the current codebase to the architecture graph and report any drift or missing entities.",
38
+ access_audit: "Audit which agents and users have access to this application and report findings.",
39
+ gap_check: "Run a gap analysis: identify architecturally significant platforms or infrastructure not yet in the graph.",
40
+ policy_check: "Use nexarch_get_entity_policy_controls with the target entity key to fetch the policy controls linked to this application, evaluate the application against each control, and report findings. If no controls are returned, inform the user that policy_control entities must be linked to the application via 'governs' relationships in the workspace.",
41
+ enrich_entity: "Update the entity description, subtype, and metadata using information from the README or codebase.",
42
+ register_aliases: "Find internal package names that are unresolved and register them as company aliases.",
43
+ custom: "Execute the custom instructions provided.",
44
+ };
45
+ export async function checkIn(args) {
46
+ const asJson = parseFlag(args, "--json");
47
+ const agentKeyArg = parseOptionValue(args, "--agent-key");
48
+ const projectKey = parseOptionValue(args, "--project");
49
+ const creds = requireCredentials();
50
+ const agentKey = agentKeyArg ?? loadStoredAgentKey();
51
+ if (!agentKey) {
52
+ if (asJson) {
53
+ process.stdout.write(JSON.stringify({ command: null, reason: "no-agent-key" }) + "\n");
54
+ }
55
+ else {
56
+ console.log("No agent key found. Pass --agent-key or run nexarch init-agent first.");
57
+ }
58
+ return;
59
+ }
60
+ const mcpOpts = { companyId: creds.companyId };
61
+ const raw = await callMcpTool("nexarch_claim_command", {
62
+ agentKey,
63
+ ...(projectKey ? { projectKey } : {}),
64
+ companyId: creds.companyId,
65
+ }, mcpOpts);
66
+ const result = parseToolText(raw);
67
+ if (asJson) {
68
+ process.stdout.write(JSON.stringify(result) + "\n");
69
+ return;
70
+ }
71
+ if (!result.command) {
72
+ console.log("No pending commands. Nothing to do.");
73
+ return;
74
+ }
75
+ const cmd = result.command;
76
+ const hint = COMMAND_TYPE_HINTS[cmd.command_type] ?? "";
77
+ console.log(`\n╔══════════════════════════════════════════════════════════════════╗`);
78
+ console.log(`║ COMMAND QUEUED — action required ║`);
79
+ console.log(`╚══════════════════════════════════════════════════════════════════╝`);
80
+ console.log(`\nCommand ID : ${cmd.id}`);
81
+ console.log(`Type : ${cmd.command_type}`);
82
+ console.log(`Target : ${cmd.target_entity_key ?? "(any)"}`);
83
+ console.log(`Priority : ${cmd.priority}`);
84
+ if (Object.keys(cmd.command_params).length > 0) {
85
+ console.log(`Params : ${JSON.stringify(cmd.command_params)}`);
86
+ }
87
+ if (hint) {
88
+ console.log(`\n${hint}`);
89
+ }
90
+ if (cmd.instructions) {
91
+ console.log(`\nInstructions:\n${cmd.instructions}`);
92
+ }
93
+ console.log(`\nWhen done, run:`);
94
+ console.log(` npx nexarch command-done --id "${cmd.id}" --summary "..."`);
95
+ console.log(`\nIf it fails, run:`);
96
+ console.log(` npx nexarch command-fail --id "${cmd.id}" --error "..."`);
97
+ }
@@ -0,0 +1,37 @@
1
+ import process from "process";
2
+ import { requireCredentials } from "../lib/credentials.js";
3
+ import { callMcpTool } from "../lib/mcp.js";
4
+ function parseFlag(args, flag) {
5
+ return args.includes(flag);
6
+ }
7
+ function parseOptionValue(args, option) {
8
+ const idx = args.indexOf(option);
9
+ if (idx === -1)
10
+ return null;
11
+ const v = args[idx + 1];
12
+ if (!v || v.startsWith("--"))
13
+ return null;
14
+ return v;
15
+ }
16
+ function parseToolText(result) {
17
+ return JSON.parse(result.content?.[0]?.text ?? "{}");
18
+ }
19
+ export async function commandDone(args) {
20
+ const asJson = parseFlag(args, "--json");
21
+ const id = parseOptionValue(args, "--id");
22
+ const summary = parseOptionValue(args, "--summary");
23
+ if (!id) {
24
+ console.error("error: --id <commandId> is required");
25
+ process.exit(1);
26
+ }
27
+ const creds = requireCredentials();
28
+ const raw = await callMcpTool("nexarch_complete_command", { commandId: id, ...(summary ? { summary } : {}), companyId: creds.companyId }, { companyId: creds.companyId });
29
+ const result = parseToolText(raw);
30
+ if (asJson) {
31
+ process.stdout.write(JSON.stringify(result) + "\n");
32
+ return;
33
+ }
34
+ console.log(`Command ${id} marked completed.`);
35
+ if (summary)
36
+ console.log(`Summary: ${summary}`);
37
+ }
@@ -0,0 +1,44 @@
1
+ import process from "process";
2
+ import { requireCredentials } from "../lib/credentials.js";
3
+ import { callMcpTool } from "../lib/mcp.js";
4
+ function parseFlag(args, flag) {
5
+ return args.includes(flag);
6
+ }
7
+ function parseOptionValue(args, option) {
8
+ const idx = args.indexOf(option);
9
+ if (idx === -1)
10
+ return null;
11
+ const v = args[idx + 1];
12
+ if (!v || v.startsWith("--"))
13
+ return null;
14
+ return v;
15
+ }
16
+ function parseToolText(result) {
17
+ return JSON.parse(result.content?.[0]?.text ?? "{}");
18
+ }
19
+ export async function commandFail(args) {
20
+ const asJson = parseFlag(args, "--json");
21
+ const id = parseOptionValue(args, "--id");
22
+ const error = parseOptionValue(args, "--error");
23
+ if (!id) {
24
+ console.error("error: --id <commandId> is required");
25
+ process.exit(1);
26
+ }
27
+ if (!error) {
28
+ console.error("error: --error <message> is required");
29
+ process.exit(1);
30
+ }
31
+ const creds = requireCredentials();
32
+ const raw = await callMcpTool("nexarch_fail_command", { commandId: id, errorMessage: error, companyId: creds.companyId }, { companyId: creds.companyId });
33
+ const result = parseToolText(raw);
34
+ if (asJson) {
35
+ process.stdout.write(JSON.stringify(result) + "\n");
36
+ return;
37
+ }
38
+ if (result.retrying) {
39
+ console.log(`Command ${id} failed — will be retried.`);
40
+ }
41
+ else {
42
+ console.log(`Command ${id} marked failed.`);
43
+ }
44
+ }
@@ -4,7 +4,7 @@ import { join } from "path";
4
4
  import process from "process";
5
5
  import { requireCredentials } from "../lib/credentials.js";
6
6
  import { callMcpTool, mcpInitialize, mcpListTools } from "../lib/mcp.js";
7
- const CLI_VERSION = "0.1.32";
7
+ const CLI_VERSION = "0.1.33";
8
8
  const AGENT_ENTITY_TYPE = "agent";
9
9
  const TECH_COMPONENT_ENTITY_TYPE = "technology_component";
10
10
  function parseFlag(args, flag) {
@@ -572,6 +572,15 @@ export async function initAgent(args) {
572
572
  let bootstrapFilePath = null;
573
573
  let agentConfigResults = [];
574
574
  if (registration.ok) {
575
+ try {
576
+ // Save identity so check-in can find the agent key
577
+ const identityDir = join(homedir(), ".nexarch");
578
+ mkdirSync(identityDir, { recursive: true });
579
+ writeFileSync(join(identityDir, "identity.json"), JSON.stringify({ agentKey: `agent:${agentId}` }, null, 2), { mode: 0o600 });
580
+ }
581
+ catch {
582
+ // non-fatal
583
+ }
575
584
  try {
576
585
  bootstrapFilePath = writeAgentBootstrap({
577
586
  agentId,
package/dist/index.js CHANGED
@@ -15,6 +15,9 @@ import { updateEntity } from "./commands/update-entity.js";
15
15
  import { addRelationship } from "./commands/add-relationship.js";
16
16
  import { registerAlias } from "./commands/register-alias.js";
17
17
  import { resolveNames } from "./commands/resolve-names.js";
18
+ import { checkIn } from "./commands/check-in.js";
19
+ import { commandDone } from "./commands/command-done.js";
20
+ import { commandFail } from "./commands/command-fail.js";
18
21
  const [, , command, ...args] = process.argv;
19
22
  const commands = {
20
23
  login,
@@ -30,6 +33,9 @@ const commands = {
30
33
  "add-relationship": addRelationship,
31
34
  "register-alias": registerAlias,
32
35
  "resolve-names": resolveNames,
36
+ "check-in": checkIn,
37
+ "command-done": commandDone,
38
+ "command-fail": commandFail,
33
39
  };
34
40
  async function main() {
35
41
  if (command === "agent") {
@@ -123,6 +129,22 @@ Usage:
123
129
  results before calling add-relationship.
124
130
  Options: --names <csv> (required, e.g. "vercel,neon")
125
131
  --json
132
+ nexarch check-in Poll the command queue and claim the next pending command
133
+ for this agent. Reads agent key from ~/.nexarch/identity.json
134
+ (written by init-agent) or via --agent-key.
135
+ Options: --agent-key <key> override stored agent key
136
+ --project <key> application entity key
137
+ --json
138
+ nexarch command-done
139
+ Mark a claimed command as completed.
140
+ Options: --id <commandId> (required)
141
+ --summary <text> short summary of what was done
142
+ --json
143
+ nexarch command-fail
144
+ Mark a claimed command as failed.
145
+ Options: --id <commandId> (required)
146
+ --error <message> (required)
147
+ --json
126
148
  `);
127
149
  process.exit(command ? 1 : 0);
128
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexarch",
3
- "version": "0.1.32",
3
+ "version": "0.1.33",
4
4
  "description": "Connect AI coding tools to your Nexarch architecture workspace",
5
5
  "keywords": [
6
6
  "nexarch",