@zinn-dev/cli 0.40.0 → 0.41.0
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/README.md +166 -38
- package/index.js +24 -13
- package/package.json +7 -2
- package/skills/zinn/SKILL.md +63 -0
- package/src/actor.d.ts +2 -1
- package/src/actor.js +78 -11
- package/src/capabilities-schema.d.ts +163 -0
- package/src/capabilities-schema.js +124 -0
- package/src/capabilities.d.ts +21 -0
- package/src/capabilities.js +22 -0
- package/src/database.d.ts +1 -1
- package/src/database.js +4 -4
- package/src/errors.d.ts +158 -0
- package/src/errors.js +224 -0
- package/src/input.d.ts +116 -0
- package/src/input.js +119 -0
- package/src/lib.d.ts +42 -7
- package/src/lib.js +213 -17
- package/src/presentation/activity-presentation.js +16 -2
- package/src/presentation/column-presentation.d.ts +3 -5
- package/src/presentation/info-presentation.d.ts +4 -0
- package/src/presentation/info-presentation.js +96 -0
- package/src/presentation/task-presentation.d.ts +2 -10
- package/src/project.d.ts +6 -0
- package/src/project.js +23 -10
- package/src/result-schemas.d.ts +987 -0
- package/src/result-schemas.js +220 -0
- package/src/results.d.ts +23 -0
- package/src/results.js +17 -0
- package/src/routes/activity-router.d.ts +71 -0
- package/src/routes/activity-router.js +59 -11
- package/src/routes/backup-router.d.ts +17 -0
- package/src/routes/backup-router.js +15 -3
- package/src/routes/capabilities-router.d.ts +21 -0
- package/src/routes/capabilities-router.js +28 -0
- package/src/routes/comment-router.d.ts +183 -4
- package/src/routes/comment-router.js +136 -29
- package/src/routes/info-router.d.ts +21 -0
- package/src/routes/info-router.js +29 -0
- package/src/routes/label-router.d.ts +165 -0
- package/src/routes/label-router.js +111 -29
- package/src/routes/migrate-router.d.ts +17 -0
- package/src/routes/migrate-router.js +17 -5
- package/src/routes/project-router.d.ts +349 -0
- package/src/routes/project-router.js +278 -92
- package/src/routes/reindex-router.d.ts +17 -0
- package/src/routes/reindex-router.js +15 -3
- package/src/routes/relation-router.d.ts +108 -12
- package/src/routes/relation-router.js +74 -14
- package/src/routes/restore-router.d.ts +29 -0
- package/src/routes/restore-router.js +30 -13
- package/src/routes/router.d.ts +1 -1
- package/src/routes/router.js +44 -25
- package/src/routes/routes.d.ts +1565 -0
- package/src/routes/routes.js +5 -1
- package/src/routes/task-router.d.ts +861 -0
- package/src/routes/task-router.js +419 -163
- package/src/text-edit.d.ts +20 -2
- package/src/text-edit.js +22 -10
- package/src/types.d.ts +14 -0
package/src/actor.js
CHANGED
|
@@ -16,24 +16,78 @@ const AGENT_MARKERS = [
|
|
|
16
16
|
{ variables: ["COPILOT_AGENT_SESSION_ID"], name: "copilot" },
|
|
17
17
|
{ variables: ["CRUSH"], name: "crush" },
|
|
18
18
|
];
|
|
19
|
-
|
|
19
|
+
const SESSION_DECLARATIONS = [
|
|
20
|
+
{ session: "ZINN_SESSION_ID", thread: "ZINN_THREAD_ID" },
|
|
21
|
+
{ session: "CLAUDE_CODE_SESSION_ID", thread: null },
|
|
22
|
+
{ session: "CODEX_SESSION_ID", thread: "CODEX_THREAD_ID" },
|
|
23
|
+
// OpenCode exports the executing session's ID, which is a subagent's own ID in its shell.
|
|
24
|
+
{ session: null, thread: "OPENCODE_SESSION_ID" },
|
|
25
|
+
];
|
|
26
|
+
function readDeclaration(env, variable) {
|
|
27
|
+
const value = variable === null ? undefined : env[variable]?.trim();
|
|
28
|
+
return value == null || value.length === 0 ? null : value;
|
|
29
|
+
}
|
|
30
|
+
function readExecutionIdentity(env) {
|
|
31
|
+
let sessionId = null;
|
|
32
|
+
let threadId = null;
|
|
33
|
+
for (const declaration of SESSION_DECLARATIONS) {
|
|
34
|
+
const declaredSession = readDeclaration(env, declaration.session);
|
|
35
|
+
const declaredThread = readDeclaration(env, declaration.thread);
|
|
36
|
+
const hasDeclaration = declaredSession !== null || declaredThread !== null;
|
|
37
|
+
if (hasDeclaration) {
|
|
38
|
+
sessionId = declaredSession;
|
|
39
|
+
threadId = declaredThread;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
sessionId,
|
|
45
|
+
threadId,
|
|
46
|
+
agent: readDeclaration(env, "ZINN_AGENT"),
|
|
47
|
+
model: readDeclaration(env, "ZINN_MODEL"),
|
|
48
|
+
effort: readDeclaration(env, "ZINN_EFFORT"),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Generic flags establish an unnamed agent only when no identifying marker follows. */
|
|
20
52
|
export function detectAgent(env) {
|
|
53
|
+
let flagSource = null;
|
|
21
54
|
for (const marker of AGENT_MARKERS) {
|
|
22
55
|
for (const variable of marker.variables) {
|
|
23
|
-
const value = env
|
|
24
|
-
if (value
|
|
56
|
+
const value = readDeclaration(env, variable);
|
|
57
|
+
if (value === null) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const isGenericFlag = marker.name === null && /^(?:\d+|true|false|yes|no|on|off)$/i.test(value);
|
|
61
|
+
if (isGenericFlag) {
|
|
62
|
+
flagSource ??= `env:${variable}`;
|
|
25
63
|
continue;
|
|
26
64
|
}
|
|
27
|
-
return {
|
|
65
|
+
return {
|
|
66
|
+
name: marker.name ?? value,
|
|
67
|
+
email: null,
|
|
68
|
+
kind: "agent",
|
|
69
|
+
source: `env:${variable}`,
|
|
70
|
+
...readExecutionIdentity(env),
|
|
71
|
+
};
|
|
28
72
|
}
|
|
29
73
|
}
|
|
74
|
+
if (flagSource !== null) {
|
|
75
|
+
return {
|
|
76
|
+
name: null,
|
|
77
|
+
email: null,
|
|
78
|
+
kind: "agent",
|
|
79
|
+
source: flagSource,
|
|
80
|
+
...readExecutionIdentity(env),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
30
83
|
return null;
|
|
31
84
|
}
|
|
32
|
-
function readGitConfig(key) {
|
|
85
|
+
function readGitConfig(key, env) {
|
|
33
86
|
try {
|
|
34
87
|
const value = execFileSync("git", ["config", key], {
|
|
35
88
|
encoding: "utf-8",
|
|
36
89
|
stdio: ["ignore", "pipe", "ignore"],
|
|
90
|
+
env,
|
|
37
91
|
}).trim();
|
|
38
92
|
return value.length > 0 ? value : null;
|
|
39
93
|
}
|
|
@@ -42,21 +96,34 @@ function readGitConfig(key) {
|
|
|
42
96
|
return null;
|
|
43
97
|
}
|
|
44
98
|
}
|
|
45
|
-
function resolveActor() {
|
|
46
|
-
const agent = detectAgent(
|
|
99
|
+
export function resolveActor(env) {
|
|
100
|
+
const agent = detectAgent(env);
|
|
47
101
|
if (agent != null) {
|
|
48
102
|
return agent;
|
|
49
103
|
}
|
|
50
|
-
const
|
|
104
|
+
const identity = readExecutionIdentity(env);
|
|
105
|
+
const gitName = readGitConfig("user.name", env);
|
|
51
106
|
if (gitName != null) {
|
|
52
|
-
return {
|
|
107
|
+
return {
|
|
108
|
+
name: gitName,
|
|
109
|
+
email: readGitConfig("user.email", env),
|
|
110
|
+
kind: "human",
|
|
111
|
+
source: "git-config",
|
|
112
|
+
...identity,
|
|
113
|
+
};
|
|
53
114
|
}
|
|
54
|
-
return {
|
|
115
|
+
return {
|
|
116
|
+
name: userInfo().username,
|
|
117
|
+
email: null,
|
|
118
|
+
kind: "human",
|
|
119
|
+
source: "os-user",
|
|
120
|
+
...identity,
|
|
121
|
+
};
|
|
55
122
|
}
|
|
56
123
|
let actor = null;
|
|
57
124
|
export function currentActor() {
|
|
58
125
|
if (actor == null) {
|
|
59
|
-
actor = resolveActor();
|
|
126
|
+
actor = resolveActor(process.env);
|
|
60
127
|
}
|
|
61
128
|
return actor;
|
|
62
129
|
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const jsonValueSchema: z.ZodJSONSchema;
|
|
3
|
+
export declare const capabilitiesSchema: z.ZodObject<{
|
|
4
|
+
manifestVersion: z.ZodLiteral<1>;
|
|
5
|
+
cli: z.ZodObject<{
|
|
6
|
+
name: z.ZodString;
|
|
7
|
+
version: z.ZodString;
|
|
8
|
+
}, z.core.$strict>;
|
|
9
|
+
invocation: z.ZodObject<{
|
|
10
|
+
routerOptions: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
11
|
+
type: z.ZodEnum<{
|
|
12
|
+
string: "string";
|
|
13
|
+
boolean: "boolean";
|
|
14
|
+
}>;
|
|
15
|
+
short: z.ZodOptional<z.ZodString>;
|
|
16
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
|
|
18
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
value: z.ZodOptional<z.ZodObject<{
|
|
20
|
+
kind: z.ZodString;
|
|
21
|
+
name: z.ZodOptional<z.ZodString>;
|
|
22
|
+
choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
23
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
24
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
25
|
+
description: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, z.core.$strict>>;
|
|
27
|
+
description: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, z.core.$strict>>;
|
|
29
|
+
routerOptionPlacement: z.ZodLiteral<"exact-tokens-anywhere-before-separator">;
|
|
30
|
+
optionSeparator: z.ZodLiteral<"--">;
|
|
31
|
+
literalOptionValue: z.ZodLiteral<"equals">;
|
|
32
|
+
singularOptions: z.ZodLiteral<"reject-repetition">;
|
|
33
|
+
jsonFailure: z.ZodLiteral<"one-stderr-document-with-buffered-diagnostics">;
|
|
34
|
+
jsonSuccessDiagnostics: z.ZodLiteral<"text-on-stderr-at-completion">;
|
|
35
|
+
canonicalArgv: z.ZodArray<z.ZodEnum<{
|
|
36
|
+
"command-path": "command-path";
|
|
37
|
+
"options-with-equals-values": "options-with-equals-values";
|
|
38
|
+
"--json": "--json";
|
|
39
|
+
"separator-if-positionals": "separator-if-positionals";
|
|
40
|
+
positionals: "positionals";
|
|
41
|
+
}>>;
|
|
42
|
+
version: z.ZodObject<{
|
|
43
|
+
spellings: z.ZodArray<z.ZodString>;
|
|
44
|
+
placement: z.ZodLiteral<"sole-argument">;
|
|
45
|
+
stdout: z.ZodLiteral<"text">;
|
|
46
|
+
exitCode: z.ZodLiteral<0>;
|
|
47
|
+
}, z.core.$strict>;
|
|
48
|
+
help: z.ZodObject<{
|
|
49
|
+
spellings: z.ZodArray<z.ZodString>;
|
|
50
|
+
stdout: z.ZodLiteral<"text">;
|
|
51
|
+
exitCode: z.ZodLiteral<0>;
|
|
52
|
+
precedence: z.ZodLiteral<"root-first-token-otherwise-router-prefix-before-help">;
|
|
53
|
+
scansRouterOptionsFirst: z.ZodLiteral<true>;
|
|
54
|
+
}, z.core.$strict>;
|
|
55
|
+
}, z.core.$strict>;
|
|
56
|
+
commands: z.ZodArray<z.ZodObject<{
|
|
57
|
+
path: z.ZodArray<z.ZodString>;
|
|
58
|
+
summary: z.ZodString;
|
|
59
|
+
input: z.ZodObject<{
|
|
60
|
+
options: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
61
|
+
type: z.ZodEnum<{
|
|
62
|
+
string: "string";
|
|
63
|
+
boolean: "boolean";
|
|
64
|
+
}>;
|
|
65
|
+
short: z.ZodOptional<z.ZodString>;
|
|
66
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
67
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
|
|
68
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
69
|
+
value: z.ZodOptional<z.ZodObject<{
|
|
70
|
+
kind: z.ZodString;
|
|
71
|
+
name: z.ZodOptional<z.ZodString>;
|
|
72
|
+
choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
73
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
74
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
75
|
+
description: z.ZodOptional<z.ZodString>;
|
|
76
|
+
}, z.core.$strict>>;
|
|
77
|
+
description: z.ZodOptional<z.ZodString>;
|
|
78
|
+
}, z.core.$strict>>;
|
|
79
|
+
forms: z.ZodArray<z.ZodObject<{
|
|
80
|
+
id: z.ZodString;
|
|
81
|
+
positionals: z.ZodArray<z.ZodObject<{
|
|
82
|
+
name: z.ZodString;
|
|
83
|
+
min: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>]>;
|
|
84
|
+
max: z.ZodNullable<z.ZodLiteral<1>>;
|
|
85
|
+
value: z.ZodObject<{
|
|
86
|
+
kind: z.ZodString;
|
|
87
|
+
name: z.ZodOptional<z.ZodString>;
|
|
88
|
+
choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
89
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
90
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
91
|
+
description: z.ZodOptional<z.ZodString>;
|
|
92
|
+
}, z.core.$strict>;
|
|
93
|
+
}, z.core.$strict>>;
|
|
94
|
+
}, z.core.$strict>>;
|
|
95
|
+
constraints: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
96
|
+
kind: z.ZodLiteral<"exclusive">;
|
|
97
|
+
members: z.ZodArray<z.ZodString>;
|
|
98
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
99
|
+
kind: z.ZodLiteral<"requires">;
|
|
100
|
+
input: z.ZodString;
|
|
101
|
+
requires: z.ZodString;
|
|
102
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
103
|
+
kind: z.ZodLiteral<"atLeastOne">;
|
|
104
|
+
members: z.ZodArray<z.ZodString>;
|
|
105
|
+
}, z.core.$strict>], "kind">>;
|
|
106
|
+
notes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
107
|
+
}, z.core.$strict>;
|
|
108
|
+
effects: z.ZodObject<{
|
|
109
|
+
domain: z.ZodEnum<{
|
|
110
|
+
read: "read";
|
|
111
|
+
create: "create";
|
|
112
|
+
update: "update";
|
|
113
|
+
delete: "delete";
|
|
114
|
+
replace: "replace";
|
|
115
|
+
none: "none";
|
|
116
|
+
}>;
|
|
117
|
+
storage: z.ZodEnum<{
|
|
118
|
+
backup: "backup";
|
|
119
|
+
none: "none";
|
|
120
|
+
"normal-open": "normal-open";
|
|
121
|
+
restore: "restore";
|
|
122
|
+
migrate: "migrate";
|
|
123
|
+
reindex: "reindex";
|
|
124
|
+
inspect: "inspect";
|
|
125
|
+
}>;
|
|
126
|
+
}, z.core.$strict>;
|
|
127
|
+
confirmation: z.ZodObject<{
|
|
128
|
+
kind: z.ZodEnum<{
|
|
129
|
+
prompt: "prompt";
|
|
130
|
+
none: "none";
|
|
131
|
+
"project-delete": "project-delete";
|
|
132
|
+
}>;
|
|
133
|
+
description: z.ZodOptional<z.ZodString>;
|
|
134
|
+
}, z.core.$strict>;
|
|
135
|
+
results: z.ZodArray<z.ZodObject<{
|
|
136
|
+
selector: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
137
|
+
kind: z.ZodLiteral<"always">;
|
|
138
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
139
|
+
kind: z.ZodLiteral<"booleanOption">;
|
|
140
|
+
name: z.ZodString;
|
|
141
|
+
value: z.ZodBoolean;
|
|
142
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
143
|
+
kind: z.ZodLiteral<"positionalCount">;
|
|
144
|
+
name: z.ZodString;
|
|
145
|
+
min: z.ZodNumber;
|
|
146
|
+
max: z.ZodNullable<z.ZodNumber>;
|
|
147
|
+
}, z.core.$strict>], "kind">;
|
|
148
|
+
schemaRef: z.ZodString;
|
|
149
|
+
mode: z.ZodLiteral<"json">;
|
|
150
|
+
stream: z.ZodLiteral<"stdout">;
|
|
151
|
+
exitCode: z.ZodLiteral<0>;
|
|
152
|
+
}, z.core.$strict>>;
|
|
153
|
+
}, z.core.$strict>>;
|
|
154
|
+
error: z.ZodObject<{
|
|
155
|
+
schemaRef: z.ZodString;
|
|
156
|
+
exitCode: z.ZodLiteral<1>;
|
|
157
|
+
stream: z.ZodLiteral<"stderr">;
|
|
158
|
+
}, z.core.$strict>;
|
|
159
|
+
schemas: z.ZodObject<{
|
|
160
|
+
$schema: z.ZodLiteral<"http://json-schema.org/draft-07/schema#">;
|
|
161
|
+
definitions: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
|
|
162
|
+
}, z.core.$strict>;
|
|
163
|
+
}, z.core.$strict>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { invocation } from "./input.js";
|
|
3
|
+
export const jsonValueSchema = z.json();
|
|
4
|
+
const inputValue = z.strictObject({
|
|
5
|
+
kind: z.string(),
|
|
6
|
+
name: z.string().optional(),
|
|
7
|
+
choices: z.array(z.string()).optional(),
|
|
8
|
+
caseInsensitive: z.boolean().optional(),
|
|
9
|
+
pattern: z.string().optional(),
|
|
10
|
+
description: z.string().optional(),
|
|
11
|
+
});
|
|
12
|
+
const inputOption = z.strictObject({
|
|
13
|
+
type: z.enum(["string", "boolean"]),
|
|
14
|
+
short: z.string().optional(),
|
|
15
|
+
multiple: z.boolean().optional(),
|
|
16
|
+
default: z.union([z.string(), z.boolean(), z.array(z.string()), z.array(z.boolean())]).optional(),
|
|
17
|
+
required: z.boolean().optional(),
|
|
18
|
+
value: inputValue.optional(),
|
|
19
|
+
description: z.string().optional(),
|
|
20
|
+
});
|
|
21
|
+
const options = z.record(z.string(), inputOption);
|
|
22
|
+
const inputReference = z.string().regex(/^(option|positional):.+$/);
|
|
23
|
+
const members = z.array(inputReference);
|
|
24
|
+
const constraint = z.discriminatedUnion("kind", [
|
|
25
|
+
z.strictObject({ kind: z.literal("exclusive"), members }),
|
|
26
|
+
z.strictObject({ kind: z.literal("requires"), input: inputReference, requires: inputReference }),
|
|
27
|
+
z.strictObject({ kind: z.literal("atLeastOne"), members }),
|
|
28
|
+
]);
|
|
29
|
+
const form = z.strictObject({
|
|
30
|
+
id: z.string(),
|
|
31
|
+
positionals: z.array(z.strictObject({
|
|
32
|
+
name: z.string(),
|
|
33
|
+
min: z.union([z.literal(0), z.literal(1)]),
|
|
34
|
+
max: z.literal(1).nullable(),
|
|
35
|
+
value: inputValue,
|
|
36
|
+
})),
|
|
37
|
+
});
|
|
38
|
+
const selector = z.discriminatedUnion("kind", [
|
|
39
|
+
z.strictObject({ kind: z.literal("always") }),
|
|
40
|
+
z.strictObject({ kind: z.literal("booleanOption"), name: z.string(), value: z.boolean() }),
|
|
41
|
+
z.strictObject({
|
|
42
|
+
kind: z.literal("positionalCount"),
|
|
43
|
+
name: z.string(),
|
|
44
|
+
min: z.number().int().nonnegative(),
|
|
45
|
+
max: z.number().int().nonnegative().nullable(),
|
|
46
|
+
}),
|
|
47
|
+
]);
|
|
48
|
+
const schemaRef = z.string().regex(/^#\/schemas\/definitions\/[^/]+$/);
|
|
49
|
+
export const capabilitiesSchema = z.strictObject({
|
|
50
|
+
manifestVersion: z.literal(1),
|
|
51
|
+
cli: z.strictObject({ name: z.string(), version: z.string() }),
|
|
52
|
+
invocation: z.strictObject({
|
|
53
|
+
routerOptions: options,
|
|
54
|
+
routerOptionPlacement: z.literal(invocation.routerOptionPlacement),
|
|
55
|
+
optionSeparator: z.literal(invocation.optionSeparator),
|
|
56
|
+
literalOptionValue: z.literal(invocation.literalOptionValue),
|
|
57
|
+
singularOptions: z.literal(invocation.singularOptions),
|
|
58
|
+
jsonFailure: z.literal(invocation.jsonFailure),
|
|
59
|
+
jsonSuccessDiagnostics: z.literal(invocation.jsonSuccessDiagnostics),
|
|
60
|
+
canonicalArgv: z
|
|
61
|
+
.array(z.enum(invocation.canonicalArgv))
|
|
62
|
+
.length(invocation.canonicalArgv.length),
|
|
63
|
+
version: z.strictObject({
|
|
64
|
+
spellings: z.array(z.string()),
|
|
65
|
+
placement: z.literal(invocation.version.placement),
|
|
66
|
+
stdout: z.literal("text"),
|
|
67
|
+
exitCode: z.literal(0),
|
|
68
|
+
}),
|
|
69
|
+
help: z.strictObject({
|
|
70
|
+
spellings: z.array(z.string()),
|
|
71
|
+
stdout: z.literal("text"),
|
|
72
|
+
exitCode: z.literal(0),
|
|
73
|
+
precedence: z.literal(invocation.help.precedence),
|
|
74
|
+
scansRouterOptionsFirst: z.literal(true),
|
|
75
|
+
}),
|
|
76
|
+
}),
|
|
77
|
+
commands: z
|
|
78
|
+
.array(z.strictObject({
|
|
79
|
+
path: z.array(z.string()).min(1),
|
|
80
|
+
summary: z.string(),
|
|
81
|
+
input: z.strictObject({
|
|
82
|
+
options,
|
|
83
|
+
forms: z.array(form).min(1),
|
|
84
|
+
constraints: z.array(constraint),
|
|
85
|
+
notes: z.array(z.string()).optional(),
|
|
86
|
+
}),
|
|
87
|
+
effects: z.strictObject({
|
|
88
|
+
domain: z.enum(["read", "create", "update", "delete", "replace", "none"]),
|
|
89
|
+
storage: z.enum([
|
|
90
|
+
"normal-open",
|
|
91
|
+
"backup",
|
|
92
|
+
"restore",
|
|
93
|
+
"migrate",
|
|
94
|
+
"reindex",
|
|
95
|
+
"inspect",
|
|
96
|
+
"none",
|
|
97
|
+
]),
|
|
98
|
+
}),
|
|
99
|
+
confirmation: z.strictObject({
|
|
100
|
+
kind: z.enum(["none", "prompt", "project-delete"]),
|
|
101
|
+
description: z.string().optional(),
|
|
102
|
+
}),
|
|
103
|
+
results: z
|
|
104
|
+
.array(z.strictObject({
|
|
105
|
+
selector,
|
|
106
|
+
schemaRef,
|
|
107
|
+
mode: z.literal("json"),
|
|
108
|
+
stream: z.literal("stdout"),
|
|
109
|
+
exitCode: z.literal(0),
|
|
110
|
+
}))
|
|
111
|
+
.min(1),
|
|
112
|
+
}))
|
|
113
|
+
.min(1),
|
|
114
|
+
error: z.strictObject({
|
|
115
|
+
schemaRef,
|
|
116
|
+
exitCode: z.literal(1),
|
|
117
|
+
stream: z.literal("stderr"),
|
|
118
|
+
}),
|
|
119
|
+
schemas: z.strictObject({
|
|
120
|
+
$schema: z.literal("http://json-schema.org/draft-07/schema#"),
|
|
121
|
+
// Schema documents contain JSON values rather than another manifest instance.
|
|
122
|
+
definitions: z.record(z.string(), z.record(z.string(), jsonValueSchema)),
|
|
123
|
+
}),
|
|
124
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Command } from "./types.js";
|
|
2
|
+
import { invocation } from "./input.js";
|
|
3
|
+
import { generateResultSchemas } from "./result-schemas.js";
|
|
4
|
+
export type Capabilities = {
|
|
5
|
+
manifestVersion: 1;
|
|
6
|
+
cli: {
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
};
|
|
10
|
+
invocation: typeof invocation;
|
|
11
|
+
commands: Array<Pick<Command, "summary" | "input" | "effects" | "confirmation" | "results"> & {
|
|
12
|
+
path: string[];
|
|
13
|
+
}>;
|
|
14
|
+
error: {
|
|
15
|
+
schemaRef: "#/schemas/definitions/ErrorEnvelope";
|
|
16
|
+
exitCode: 1;
|
|
17
|
+
stream: "stderr";
|
|
18
|
+
};
|
|
19
|
+
schemas: ReturnType<typeof generateResultSchemas>;
|
|
20
|
+
};
|
|
21
|
+
export declare function generateCapabilities(): Capabilities;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { invocation } from "./input.js";
|
|
2
|
+
import { generateResultSchemas } from "./result-schemas.js";
|
|
3
|
+
import { parseRoutes } from "./routes/router.js";
|
|
4
|
+
import { routes } from "./routes/routes.js";
|
|
5
|
+
import packageJson from "../package.json" with { type: "json" };
|
|
6
|
+
export function generateCapabilities() {
|
|
7
|
+
return {
|
|
8
|
+
manifestVersion: 1,
|
|
9
|
+
cli: { name: packageJson.name, version: packageJson.version },
|
|
10
|
+
invocation,
|
|
11
|
+
commands: parseRoutes(routes).map(({ command, summary, input, effects, confirmation, results }) => ({
|
|
12
|
+
path: command.split(" "),
|
|
13
|
+
summary,
|
|
14
|
+
input,
|
|
15
|
+
effects,
|
|
16
|
+
confirmation,
|
|
17
|
+
results,
|
|
18
|
+
})),
|
|
19
|
+
error: { schemaRef: "#/schemas/definitions/ErrorEnvelope", exitCode: 1, stream: "stderr" },
|
|
20
|
+
schemas: generateResultSchemas(),
|
|
21
|
+
};
|
|
22
|
+
}
|
package/src/database.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ import type { DatabaseFacts, LockWait, OpenPolicy } from "@zinn-dev/core";
|
|
|
3
3
|
export declare function reportLockWait({ budgetMs }: LockWait): void;
|
|
4
4
|
export declare function reportLegacyRead({ databasePath }: DatabaseFacts): void;
|
|
5
5
|
/** How the CLI asks core to open the database. */
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function getCliOpenPolicy(): OpenPolicy;
|
package/src/database.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import packageJson from "../package.json" with { type: "json" };
|
|
2
|
-
import { isLegacyReadAllowed } from "./lib.js";
|
|
2
|
+
import { diagnostic, isLegacyReadAllowed } from "./lib.js";
|
|
3
3
|
import { RELEASE_MODE } from "./release-identity.js";
|
|
4
4
|
const MS_PER_SECOND = 1000;
|
|
5
5
|
/** Says once on stderr that the command waits for another process to finish with the database. */
|
|
6
6
|
export function reportLockWait({ budgetMs }) {
|
|
7
|
-
|
|
7
|
+
diagnostic(`Another process is using the database. Waiting up to ${budgetMs / MS_PER_SECOND} seconds for it to finish.`);
|
|
8
8
|
}
|
|
9
9
|
export function reportLegacyRead({ databasePath }) {
|
|
10
|
-
|
|
10
|
+
diagnostic(`Warning: the database at ${databasePath} has no schema version. Reads are best effort and may fail or omit data.`);
|
|
11
11
|
}
|
|
12
12
|
/** How the CLI asks core to open the database. */
|
|
13
|
-
export function
|
|
13
|
+
export function getCliOpenPolicy() {
|
|
14
14
|
return {
|
|
15
15
|
client: "cli",
|
|
16
16
|
version: packageJson.version,
|
package/src/errors.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const errorCodeSchema: z.ZodEnum<{
|
|
3
|
+
invalid_input: "invalid_input";
|
|
4
|
+
not_found: "not_found";
|
|
5
|
+
conflict: "conflict";
|
|
6
|
+
storage: "storage";
|
|
7
|
+
internal: "internal";
|
|
8
|
+
}>;
|
|
9
|
+
export declare const errorDetailsSchema: z.ZodObject<{
|
|
10
|
+
argument: z.ZodOptional<z.ZodString>;
|
|
11
|
+
field: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
12
|
+
entity: z.ZodOptional<z.ZodEnum<{
|
|
13
|
+
project: "project";
|
|
14
|
+
task: "task";
|
|
15
|
+
comment: "comment";
|
|
16
|
+
label: "label";
|
|
17
|
+
column: "column";
|
|
18
|
+
relation: "relation";
|
|
19
|
+
activity: "activity";
|
|
20
|
+
database: "database";
|
|
21
|
+
backup: "backup";
|
|
22
|
+
}>>;
|
|
23
|
+
key: z.ZodOptional<z.ZodString>;
|
|
24
|
+
source: z.ZodOptional<z.ZodEnum<{
|
|
25
|
+
explicit: "explicit";
|
|
26
|
+
defaultProject: "defaultProject";
|
|
27
|
+
}>>;
|
|
28
|
+
settingsPath: z.ZodOptional<z.ZodString>;
|
|
29
|
+
reason: z.ZodOptional<z.ZodEnum<{
|
|
30
|
+
archived: "archived";
|
|
31
|
+
confirmation_required: "confirmation_required";
|
|
32
|
+
invalid_json: "invalid_json";
|
|
33
|
+
invalid_settings: "invalid_settings";
|
|
34
|
+
invalid_storage: "invalid_storage";
|
|
35
|
+
already_exists: "already_exists";
|
|
36
|
+
parent_exists: "parent_exists";
|
|
37
|
+
cycle: "cycle";
|
|
38
|
+
different_project: "different_project";
|
|
39
|
+
different_column: "different_column";
|
|
40
|
+
ambiguous_reference: "ambiguous_reference";
|
|
41
|
+
text_match_count: "text_match_count";
|
|
42
|
+
no_columns: "no_columns";
|
|
43
|
+
unmarked_database: "unmarked_database";
|
|
44
|
+
newer_database: "newer_database";
|
|
45
|
+
older_database: "older_database";
|
|
46
|
+
invalid_backup: "invalid_backup";
|
|
47
|
+
busy: "busy";
|
|
48
|
+
locked: "locked";
|
|
49
|
+
permission_denied: "permission_denied";
|
|
50
|
+
read_only: "read_only";
|
|
51
|
+
disk_full: "disk_full";
|
|
52
|
+
corrupt: "corrupt";
|
|
53
|
+
not_database: "not_database";
|
|
54
|
+
missing_index: "missing_index";
|
|
55
|
+
io: "io";
|
|
56
|
+
}>>;
|
|
57
|
+
matchCount: z.ZodOptional<z.ZodNumber>;
|
|
58
|
+
candidateIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
59
|
+
path: z.ZodOptional<z.ZodString>;
|
|
60
|
+
databasePath: z.ZodOptional<z.ZodString>;
|
|
61
|
+
backupDirectory: z.ZodOptional<z.ZodString>;
|
|
62
|
+
backupPath: z.ZodOptional<z.ZodString>;
|
|
63
|
+
schemaVersion: z.ZodOptional<z.ZodNumber>;
|
|
64
|
+
supportedSchemaVersion: z.ZodOptional<z.ZodNumber>;
|
|
65
|
+
cause: z.ZodOptional<z.ZodObject<{
|
|
66
|
+
code: z.ZodOptional<z.ZodString>;
|
|
67
|
+
errcode: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
message: z.ZodString;
|
|
69
|
+
}, z.core.$strict>>;
|
|
70
|
+
}, z.core.$strict>;
|
|
71
|
+
export declare const errorDocumentSchema: z.ZodObject<{
|
|
72
|
+
error: z.ZodObject<{
|
|
73
|
+
code: z.ZodEnum<{
|
|
74
|
+
invalid_input: "invalid_input";
|
|
75
|
+
not_found: "not_found";
|
|
76
|
+
conflict: "conflict";
|
|
77
|
+
storage: "storage";
|
|
78
|
+
internal: "internal";
|
|
79
|
+
}>;
|
|
80
|
+
message: z.ZodString;
|
|
81
|
+
help: z.ZodOptional<z.ZodString>;
|
|
82
|
+
details: z.ZodOptional<z.ZodObject<{
|
|
83
|
+
argument: z.ZodOptional<z.ZodString>;
|
|
84
|
+
field: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
85
|
+
entity: z.ZodOptional<z.ZodEnum<{
|
|
86
|
+
project: "project";
|
|
87
|
+
task: "task";
|
|
88
|
+
comment: "comment";
|
|
89
|
+
label: "label";
|
|
90
|
+
column: "column";
|
|
91
|
+
relation: "relation";
|
|
92
|
+
activity: "activity";
|
|
93
|
+
database: "database";
|
|
94
|
+
backup: "backup";
|
|
95
|
+
}>>;
|
|
96
|
+
key: z.ZodOptional<z.ZodString>;
|
|
97
|
+
source: z.ZodOptional<z.ZodEnum<{
|
|
98
|
+
explicit: "explicit";
|
|
99
|
+
defaultProject: "defaultProject";
|
|
100
|
+
}>>;
|
|
101
|
+
settingsPath: z.ZodOptional<z.ZodString>;
|
|
102
|
+
reason: z.ZodOptional<z.ZodEnum<{
|
|
103
|
+
archived: "archived";
|
|
104
|
+
confirmation_required: "confirmation_required";
|
|
105
|
+
invalid_json: "invalid_json";
|
|
106
|
+
invalid_settings: "invalid_settings";
|
|
107
|
+
invalid_storage: "invalid_storage";
|
|
108
|
+
already_exists: "already_exists";
|
|
109
|
+
parent_exists: "parent_exists";
|
|
110
|
+
cycle: "cycle";
|
|
111
|
+
different_project: "different_project";
|
|
112
|
+
different_column: "different_column";
|
|
113
|
+
ambiguous_reference: "ambiguous_reference";
|
|
114
|
+
text_match_count: "text_match_count";
|
|
115
|
+
no_columns: "no_columns";
|
|
116
|
+
unmarked_database: "unmarked_database";
|
|
117
|
+
newer_database: "newer_database";
|
|
118
|
+
older_database: "older_database";
|
|
119
|
+
invalid_backup: "invalid_backup";
|
|
120
|
+
busy: "busy";
|
|
121
|
+
locked: "locked";
|
|
122
|
+
permission_denied: "permission_denied";
|
|
123
|
+
read_only: "read_only";
|
|
124
|
+
disk_full: "disk_full";
|
|
125
|
+
corrupt: "corrupt";
|
|
126
|
+
not_database: "not_database";
|
|
127
|
+
missing_index: "missing_index";
|
|
128
|
+
io: "io";
|
|
129
|
+
}>>;
|
|
130
|
+
matchCount: z.ZodOptional<z.ZodNumber>;
|
|
131
|
+
candidateIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
132
|
+
path: z.ZodOptional<z.ZodString>;
|
|
133
|
+
databasePath: z.ZodOptional<z.ZodString>;
|
|
134
|
+
backupDirectory: z.ZodOptional<z.ZodString>;
|
|
135
|
+
backupPath: z.ZodOptional<z.ZodString>;
|
|
136
|
+
schemaVersion: z.ZodOptional<z.ZodNumber>;
|
|
137
|
+
supportedSchemaVersion: z.ZodOptional<z.ZodNumber>;
|
|
138
|
+
cause: z.ZodOptional<z.ZodObject<{
|
|
139
|
+
code: z.ZodOptional<z.ZodString>;
|
|
140
|
+
errcode: z.ZodOptional<z.ZodNumber>;
|
|
141
|
+
message: z.ZodString;
|
|
142
|
+
}, z.core.$strict>>;
|
|
143
|
+
}, z.core.$strict>>;
|
|
144
|
+
diagnostics: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
145
|
+
}, z.core.$strict>;
|
|
146
|
+
}, z.core.$strict>;
|
|
147
|
+
export type ErrorCode = z.infer<typeof errorCodeSchema>;
|
|
148
|
+
export type ErrorDetails = z.infer<typeof errorDetailsSchema>;
|
|
149
|
+
export type CliFailure = z.infer<typeof errorDocumentSchema>["error"];
|
|
150
|
+
/** A failure detected by the CLI, with only facts intended for its public output. */
|
|
151
|
+
export declare class CliError extends Error {
|
|
152
|
+
readonly code: ErrorCode;
|
|
153
|
+
readonly details?: ErrorDetails | undefined;
|
|
154
|
+
help?: string | undefined;
|
|
155
|
+
constructor(message: string, code?: ErrorCode, details?: ErrorDetails | undefined, help?: string | undefined);
|
|
156
|
+
}
|
|
157
|
+
/** Finds causes of initialization wrappers without serializing their error chains. */
|
|
158
|
+
export declare function classifyFailure(error: unknown): Omit<CliFailure, "message">;
|