nexarch 0.6.3 → 0.6.4
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/commands/check-in.js +29 -90
- package/dist/commands/command-claim.js +97 -0
- package/dist/index.js +10 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import process from "process";
|
|
2
|
-
import { existsSync, readFileSync
|
|
2
|
+
import { existsSync, readFileSync } from "fs";
|
|
3
3
|
import { join } from "path";
|
|
4
4
|
import { homedir } from "os";
|
|
5
5
|
import { requireCredentials } from "../lib/credentials.js";
|
|
@@ -35,66 +35,6 @@ function loadIdentity() {
|
|
|
35
35
|
return { agentKey: null, projectKeys: [] };
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
function safeReadText(path, maxChars = 6000) {
|
|
39
|
-
if (!existsSync(path))
|
|
40
|
-
return null;
|
|
41
|
-
try {
|
|
42
|
-
return readFileSync(path, "utf8").slice(0, maxChars);
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function collectEvidenceFromRepo() {
|
|
49
|
-
const cwd = process.cwd();
|
|
50
|
-
const readme = safeReadText(join(cwd, "README.md"), 8000)
|
|
51
|
-
?? safeReadText(join(cwd, "readme.md"), 8000)
|
|
52
|
-
?? undefined;
|
|
53
|
-
const packageJson = safeReadText(join(cwd, "package.json"), 5000);
|
|
54
|
-
const notes = [];
|
|
55
|
-
if (packageJson)
|
|
56
|
-
notes.push("package.json detected");
|
|
57
|
-
const files = [];
|
|
58
|
-
if (packageJson)
|
|
59
|
-
files.push({ path: "package.json", content: packageJson });
|
|
60
|
-
const srcDir = join(cwd, "src");
|
|
61
|
-
if (existsSync(srcDir)) {
|
|
62
|
-
try {
|
|
63
|
-
const entries = readdirSync(srcDir)
|
|
64
|
-
.filter((name) => /\.(ts|tsx|js|jsx)$/i.test(name))
|
|
65
|
-
.slice(0, 8);
|
|
66
|
-
for (const name of entries) {
|
|
67
|
-
const full = join(srcDir, name);
|
|
68
|
-
try {
|
|
69
|
-
if (!statSync(full).isFile())
|
|
70
|
-
continue;
|
|
71
|
-
const content = safeReadText(full, 4000);
|
|
72
|
-
if (content)
|
|
73
|
-
files.push({ path: `src/${name}`, content });
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
// ignore per-file failures
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (entries.length > 0)
|
|
80
|
-
notes.push(`included ${entries.length} source file snippet(s)`);
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
83
|
-
// ignore directory read issues
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
const summary = [
|
|
87
|
-
`cwd=${cwd}`,
|
|
88
|
-
readme ? "README included" : "README missing",
|
|
89
|
-
files.length > 0 ? `evidence files=${files.length}` : "no evidence files collected",
|
|
90
|
-
].join("; ");
|
|
91
|
-
return {
|
|
92
|
-
summary,
|
|
93
|
-
...(readme ? { readme } : {}),
|
|
94
|
-
...(notes.length ? { notes: notes.join("; ") } : {}),
|
|
95
|
-
...(files.length ? { files } : {}),
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
38
|
export async function checkIn(args) {
|
|
99
39
|
const asJson = parseFlag(args, "--json");
|
|
100
40
|
const agentKeyArg = parseOptionValue(args, "--agent-key");
|
|
@@ -102,7 +42,6 @@ export async function checkIn(args) {
|
|
|
102
42
|
const creds = requireCredentials();
|
|
103
43
|
const identity = loadIdentity();
|
|
104
44
|
const agentKey = agentKeyArg ?? identity.agentKey;
|
|
105
|
-
// Use --project flag as a single override, otherwise send all stored keys
|
|
106
45
|
const resolvedProjectKeys = projectKey ? [projectKey] : identity.projectKeys;
|
|
107
46
|
if (!agentKey) {
|
|
108
47
|
if (asJson) {
|
|
@@ -113,46 +52,46 @@ export async function checkIn(args) {
|
|
|
113
52
|
}
|
|
114
53
|
return;
|
|
115
54
|
}
|
|
116
|
-
const mcpOpts = { companyId: creds.companyId };
|
|
117
|
-
const evidence = collectEvidenceFromRepo();
|
|
118
55
|
const raw = await callMcpTool("nexarch_claim_command", {
|
|
119
56
|
agentKey,
|
|
120
57
|
...(resolvedProjectKeys.length > 0 ? { projectKeys: resolvedProjectKeys } : {}),
|
|
121
|
-
evidence,
|
|
122
58
|
companyId: creds.companyId,
|
|
123
|
-
},
|
|
59
|
+
}, { companyId: creds.companyId });
|
|
124
60
|
const result = parseToolText(raw);
|
|
125
61
|
if (asJson) {
|
|
126
62
|
process.stdout.write(JSON.stringify(result) + "\n");
|
|
127
63
|
return;
|
|
128
64
|
}
|
|
129
|
-
|
|
130
|
-
|
|
65
|
+
const commands = result.commands ?? [];
|
|
66
|
+
if (commands.length === 0) {
|
|
67
|
+
console.log("No pending application-target commands found.");
|
|
131
68
|
return;
|
|
132
69
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
70
|
+
console.log("\nPending application-target commands (preview only; nothing claimed):");
|
|
71
|
+
for (const cmd of commands) {
|
|
72
|
+
const claimable = cmd.claimable ? "yes" : "no";
|
|
73
|
+
const reason = cmd.claimReason ?? (cmd.claimable ? "in_project_scope" : "missing_project_scope");
|
|
74
|
+
console.log(`\n- ID : ${cmd.id}`);
|
|
75
|
+
console.log(` Type : ${cmd.command_type}`);
|
|
76
|
+
console.log(` Target : ${cmd.target_entity_key ?? "(none)"}`);
|
|
77
|
+
console.log(` Priority : ${cmd.priority}`);
|
|
78
|
+
console.log(` Claimable : ${claimable} (${reason})`);
|
|
79
|
+
if (cmd.command_type_version != null)
|
|
80
|
+
console.log(` Type ver : ${cmd.command_type_version}`);
|
|
81
|
+
if (cmd.resolved_runtime_handler)
|
|
82
|
+
console.log(` Runtime : ${cmd.resolved_runtime_handler}`);
|
|
83
|
+
if (cmd.claimable) {
|
|
84
|
+
console.log(` Claim cmd : npx nexarch command-claim --id "${cmd.id}"${cmd.target_entity_key ? ` --project "${cmd.target_entity_key}"` : ""}`);
|
|
85
|
+
}
|
|
147
86
|
}
|
|
148
|
-
|
|
149
|
-
|
|
87
|
+
console.log("\nCurrent project scope:");
|
|
88
|
+
if (resolvedProjectKeys.length === 0) {
|
|
89
|
+
console.log(" (none) — use --project <application:key> to scope claims");
|
|
150
90
|
}
|
|
151
|
-
|
|
152
|
-
|
|
91
|
+
else {
|
|
92
|
+
for (const key of resolvedProjectKeys)
|
|
93
|
+
console.log(` - ${key}`);
|
|
153
94
|
}
|
|
154
|
-
console.log(
|
|
155
|
-
console.log(
|
|
156
|
-
console.log(`\nIf it fails, run:`);
|
|
157
|
-
console.log(` npx nexarch command-fail --id "${cmd.id}" --error "..."`);
|
|
95
|
+
console.log("\nTo validate an application target is accessible in Nexarch before claiming:");
|
|
96
|
+
console.log(" npx nexarch policy-controls --entity <application:key> --json");
|
|
158
97
|
}
|
|
@@ -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 loadIdentity() {
|
|
24
|
+
const identityPath = join(homedir(), ".nexarch", "identity.json");
|
|
25
|
+
if (!existsSync(identityPath))
|
|
26
|
+
return { agentKey: null, projectKeys: [] };
|
|
27
|
+
try {
|
|
28
|
+
const data = JSON.parse(readFileSync(identityPath, "utf8"));
|
|
29
|
+
return {
|
|
30
|
+
agentKey: data.agentKey ?? null,
|
|
31
|
+
projectKeys: Array.isArray(data.projectKeys) ? data.projectKeys : [],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return { agentKey: null, projectKeys: [] };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export async function commandClaim(args) {
|
|
39
|
+
const asJson = parseFlag(args, "--json");
|
|
40
|
+
const id = parseOptionValue(args, "--id");
|
|
41
|
+
const agentKeyArg = parseOptionValue(args, "--agent-key");
|
|
42
|
+
const projectKey = parseOptionValue(args, "--project");
|
|
43
|
+
if (!id) {
|
|
44
|
+
console.error("error: --id <commandId> is required");
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
const creds = requireCredentials();
|
|
48
|
+
const identity = loadIdentity();
|
|
49
|
+
const agentKey = agentKeyArg ?? identity.agentKey;
|
|
50
|
+
const resolvedProjectKeys = projectKey ? [projectKey] : identity.projectKeys;
|
|
51
|
+
if (!agentKey) {
|
|
52
|
+
console.error("error: no agent key found. Pass --agent-key or run nexarch init-agent first.");
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
const raw = await callMcpTool("nexarch_claim_command_by_id", {
|
|
56
|
+
commandId: id,
|
|
57
|
+
agentKey,
|
|
58
|
+
...(resolvedProjectKeys.length > 0 ? { projectKeys: resolvedProjectKeys } : {}),
|
|
59
|
+
companyId: creds.companyId,
|
|
60
|
+
}, { companyId: creds.companyId });
|
|
61
|
+
const result = parseToolText(raw);
|
|
62
|
+
if (asJson) {
|
|
63
|
+
process.stdout.write(JSON.stringify(result) + "\n");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (!result.command) {
|
|
67
|
+
console.log(`Command ${id} was not claimed.`);
|
|
68
|
+
if (result.reason)
|
|
69
|
+
console.log(`Reason: ${result.reason}`);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const cmd = result.command;
|
|
73
|
+
console.log(`\n╔══════════════════════════════════════════════════════════════════╗`);
|
|
74
|
+
console.log(`║ COMMAND CLAIMED — action required ║`);
|
|
75
|
+
console.log(`╚══════════════════════════════════════════════════════════════════╝`);
|
|
76
|
+
console.log(`\nCommand ID : ${cmd.id}`);
|
|
77
|
+
console.log(`Type : ${cmd.command_type}`);
|
|
78
|
+
console.log(`Target : ${cmd.target_entity_key ?? "(any)"}`);
|
|
79
|
+
console.log(`Priority : ${cmd.priority}`);
|
|
80
|
+
if (cmd.resolved_runtime_handler)
|
|
81
|
+
console.log(`Runtime : ${cmd.resolved_runtime_handler}`);
|
|
82
|
+
if (cmd.command_type_version != null)
|
|
83
|
+
console.log(`Type ver : ${cmd.command_type_version}`);
|
|
84
|
+
if (Object.keys(cmd.command_params).length > 0) {
|
|
85
|
+
console.log(`Params : ${JSON.stringify(cmd.command_params)}`);
|
|
86
|
+
}
|
|
87
|
+
if (cmd.resolved_playbook_text?.trim()) {
|
|
88
|
+
console.log(`\nPlaybook:\n${cmd.resolved_playbook_text}`);
|
|
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
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import { resolveNames } from "./commands/resolve-names.js";
|
|
|
15
15
|
import { checkIn } from "./commands/check-in.js";
|
|
16
16
|
import { commandDone } from "./commands/command-done.js";
|
|
17
17
|
import { commandFail } from "./commands/command-fail.js";
|
|
18
|
+
import { commandClaim } from "./commands/command-claim.js";
|
|
18
19
|
import { policyControls } from "./commands/policy-controls.js";
|
|
19
20
|
import { policyAuditSubmit } from "./commands/policy-audit-submit.js";
|
|
20
21
|
const [, , command, ...args] = process.argv;
|
|
@@ -35,6 +36,7 @@ const commands = {
|
|
|
35
36
|
"check-in": checkIn,
|
|
36
37
|
"command-done": commandDone,
|
|
37
38
|
"command-fail": commandFail,
|
|
39
|
+
"command-claim": commandClaim,
|
|
38
40
|
"policy-controls": policyControls,
|
|
39
41
|
"policy-audit-submit": policyAuditSubmit,
|
|
40
42
|
};
|
|
@@ -117,12 +119,18 @@ Usage:
|
|
|
117
119
|
results before calling add-relationship.
|
|
118
120
|
Options: --names <csv> (required, e.g. "vercel,neon")
|
|
119
121
|
--json
|
|
120
|
-
nexarch check-in
|
|
121
|
-
|
|
122
|
+
nexarch check-in Preview pending application-target commands for this agent scope
|
|
123
|
+
without claiming. Reads agent key from ~/.nexarch/identity.json
|
|
122
124
|
(written by init-agent) or via --agent-key.
|
|
123
125
|
Options: --agent-key <key> override stored agent key
|
|
124
126
|
--project <key> application entity key
|
|
125
127
|
--json
|
|
128
|
+
nexarch command-claim
|
|
129
|
+
Explicitly claim a pending command by ID.
|
|
130
|
+
Options: --id <commandId> (required)
|
|
131
|
+
--agent-key <key> override stored agent key
|
|
132
|
+
--project <key> application entity key
|
|
133
|
+
--json
|
|
126
134
|
nexarch command-done
|
|
127
135
|
Mark a claimed command as completed.
|
|
128
136
|
Options: --id <commandId> (required)
|