@zinn-dev/cli 0.39.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.
Files changed (113) hide show
  1. package/README.md +171 -40
  2. package/index.d.ts +2 -0
  3. package/index.js +34 -0
  4. package/package.json +27 -18
  5. package/skills/zinn/SKILL.md +63 -0
  6. package/src/actor.d.ts +7 -0
  7. package/src/actor.js +129 -0
  8. package/src/capabilities-schema.d.ts +163 -0
  9. package/src/capabilities-schema.js +124 -0
  10. package/src/capabilities.d.ts +21 -0
  11. package/src/capabilities.js +22 -0
  12. package/src/database.d.ts +6 -0
  13. package/src/database.js +27 -0
  14. package/src/errors.d.ts +158 -0
  15. package/src/errors.js +224 -0
  16. package/src/input.d.ts +116 -0
  17. package/src/input.js +119 -0
  18. package/src/lib.d.ts +66 -0
  19. package/src/lib.js +333 -0
  20. package/src/presentation/activity-presentation.d.ts +23 -0
  21. package/src/presentation/activity-presentation.js +403 -0
  22. package/src/presentation/color.d.ts +9 -0
  23. package/src/presentation/color.js +21 -0
  24. package/src/presentation/column-presentation.d.ts +14 -0
  25. package/src/presentation/column-presentation.js +29 -0
  26. package/src/presentation/description-presentation.d.ts +3 -0
  27. package/src/presentation/description-presentation.js +11 -0
  28. package/src/presentation/info-presentation.d.ts +4 -0
  29. package/src/presentation/info-presentation.js +96 -0
  30. package/src/presentation/row-layout.d.ts +22 -0
  31. package/src/presentation/row-layout.js +58 -0
  32. package/src/presentation/section.d.ts +4 -0
  33. package/src/presentation/section.js +9 -0
  34. package/src/presentation/task-presentation.d.ts +9 -0
  35. package/src/presentation/task-presentation.js +62 -0
  36. package/src/presentation/time.d.ts +1 -0
  37. package/src/presentation/time.js +13 -0
  38. package/src/project.d.ts +12 -0
  39. package/src/project.js +44 -0
  40. package/src/release-identity.d.ts +2 -0
  41. package/src/release-identity.js +1 -0
  42. package/src/result-schemas.d.ts +987 -0
  43. package/src/result-schemas.js +220 -0
  44. package/src/results.d.ts +23 -0
  45. package/src/results.js +17 -0
  46. package/src/routes/activity-router.d.ts +81 -0
  47. package/src/routes/activity-router.js +119 -0
  48. package/src/routes/backup-router.d.ts +21 -0
  49. package/src/routes/backup-router.js +30 -0
  50. package/src/routes/capabilities-router.d.ts +21 -0
  51. package/src/routes/capabilities-router.js +28 -0
  52. package/src/routes/comment-router.d.ts +203 -0
  53. package/src/routes/comment-router.js +241 -0
  54. package/src/routes/info-router.d.ts +21 -0
  55. package/src/routes/info-router.js +29 -0
  56. package/src/routes/label-router.d.ts +183 -0
  57. package/src/routes/label-router.js +218 -0
  58. package/src/routes/migrate-router.d.ts +21 -0
  59. package/src/routes/migrate-router.js +49 -0
  60. package/src/routes/project-router.d.ts +389 -0
  61. package/src/routes/project-router.js +514 -0
  62. package/src/routes/reindex-router.d.ts +21 -0
  63. package/src/routes/reindex-router.js +33 -0
  64. package/src/routes/relation-router.d.ts +124 -0
  65. package/src/routes/relation-router.js +223 -0
  66. package/src/routes/restore-router.d.ts +33 -0
  67. package/src/routes/restore-router.js +88 -0
  68. package/src/routes/router.d.ts +6 -0
  69. package/src/routes/router.js +204 -0
  70. package/src/routes/routes.d.ts +1735 -0
  71. package/src/routes/routes.js +23 -0
  72. package/src/routes/task-router.d.ts +945 -0
  73. package/src/routes/task-router.js +789 -0
  74. package/src/text-edit.d.ts +43 -0
  75. package/src/text-edit.js +57 -0
  76. package/src/types.d.ts +24 -0
  77. package/src/types.js +1 -0
  78. package/index.ts +0 -26
  79. package/release-stamp.json +0 -1
  80. package/src/actor.test.ts +0 -41
  81. package/src/actor.ts +0 -78
  82. package/src/database.test.ts +0 -70
  83. package/src/database.ts +0 -41
  84. package/src/lib.test.ts +0 -86
  85. package/src/lib.ts +0 -159
  86. package/src/presentation/activity-presentation.test.ts +0 -112
  87. package/src/presentation/activity-presentation.ts +0 -490
  88. package/src/presentation/color.ts +0 -29
  89. package/src/presentation/column-presentation.ts +0 -48
  90. package/src/presentation/description-presentation.ts +0 -18
  91. package/src/presentation/row-layout.ts +0 -77
  92. package/src/presentation/section.ts +0 -16
  93. package/src/presentation/task-presentation.ts +0 -92
  94. package/src/presentation/time.ts +0 -17
  95. package/src/project.test.ts +0 -479
  96. package/src/project.ts +0 -53
  97. package/src/routes/activity-router.ts +0 -81
  98. package/src/routes/backup-router.ts +0 -24
  99. package/src/routes/comment-router.ts +0 -171
  100. package/src/routes/label-router.ts +0 -168
  101. package/src/routes/migrate-router.test.ts +0 -31
  102. package/src/routes/migrate-router.ts +0 -48
  103. package/src/routes/project-router.ts +0 -415
  104. package/src/routes/reindex-router.ts +0 -27
  105. package/src/routes/relation-router.ts +0 -194
  106. package/src/routes/restore-router.test.ts +0 -44
  107. package/src/routes/restore-router.ts +0 -90
  108. package/src/routes/router.test.ts +0 -136
  109. package/src/routes/router.ts +0 -248
  110. package/src/routes/routes.ts +0 -20
  111. package/src/routes/task-router.ts +0 -649
  112. package/src/text-edit.ts +0 -68
  113. package/src/types.ts +0 -6
package/src/actor.js ADDED
@@ -0,0 +1,129 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { userInfo } from "node:os";
3
+ /**
4
+ * Environment variables that coding agents set in the shells they run.
5
+ * Undetected tools can set `AI_AGENT` through their own env configuration.
6
+ */
7
+ const AGENT_MARKERS = [
8
+ { variables: ["AI_AGENT"], name: null },
9
+ { variables: ["AGENT"], name: null },
10
+ { variables: ["CLAUDECODE"], name: "claude-code" },
11
+ { variables: ["CODEX_THREAD_ID", "CODEX_SANDBOX"], name: "codex" },
12
+ { variables: ["OPENCODE"], name: "opencode" },
13
+ { variables: ["GEMINI_CLI"], name: "gemini-cli" },
14
+ { variables: ["CLINE_ACTIVE"], name: "cline" },
15
+ { variables: ["CURSOR_AGENT"], name: "cursor" },
16
+ { variables: ["COPILOT_AGENT_SESSION_ID"], name: "copilot" },
17
+ { variables: ["CRUSH"], name: "crush" },
18
+ ];
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. */
52
+ export function detectAgent(env) {
53
+ let flagSource = null;
54
+ for (const marker of AGENT_MARKERS) {
55
+ for (const variable of marker.variables) {
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}`;
63
+ continue;
64
+ }
65
+ return {
66
+ name: marker.name ?? value,
67
+ email: null,
68
+ kind: "agent",
69
+ source: `env:${variable}`,
70
+ ...readExecutionIdentity(env),
71
+ };
72
+ }
73
+ }
74
+ if (flagSource !== null) {
75
+ return {
76
+ name: null,
77
+ email: null,
78
+ kind: "agent",
79
+ source: flagSource,
80
+ ...readExecutionIdentity(env),
81
+ };
82
+ }
83
+ return null;
84
+ }
85
+ function readGitConfig(key, env) {
86
+ try {
87
+ const value = execFileSync("git", ["config", key], {
88
+ encoding: "utf-8",
89
+ stdio: ["ignore", "pipe", "ignore"],
90
+ env,
91
+ }).trim();
92
+ return value.length > 0 ? value : null;
93
+ }
94
+ catch {
95
+ // git is missing or the key is unset
96
+ return null;
97
+ }
98
+ }
99
+ export function resolveActor(env) {
100
+ const agent = detectAgent(env);
101
+ if (agent != null) {
102
+ return agent;
103
+ }
104
+ const identity = readExecutionIdentity(env);
105
+ const gitName = readGitConfig("user.name", env);
106
+ if (gitName != null) {
107
+ return {
108
+ name: gitName,
109
+ email: readGitConfig("user.email", env),
110
+ kind: "human",
111
+ source: "git-config",
112
+ ...identity,
113
+ };
114
+ }
115
+ return {
116
+ name: userInfo().username,
117
+ email: null,
118
+ kind: "human",
119
+ source: "os-user",
120
+ ...identity,
121
+ };
122
+ }
123
+ let actor = null;
124
+ export function currentActor() {
125
+ if (actor == null) {
126
+ actor = resolveActor(process.env);
127
+ }
128
+ return actor;
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
+ }
@@ -0,0 +1,6 @@
1
+ import type { DatabaseFacts, LockWait, OpenPolicy } from "@zinn-dev/core";
2
+ /** Says once on stderr that the command waits for another process to finish with the database. */
3
+ export declare function reportLockWait({ budgetMs }: LockWait): void;
4
+ export declare function reportLegacyRead({ databasePath }: DatabaseFacts): void;
5
+ /** How the CLI asks core to open the database. */
6
+ export declare function getCliOpenPolicy(): OpenPolicy;
@@ -0,0 +1,27 @@
1
+ import packageJson from "../package.json" with { type: "json" };
2
+ import { diagnostic, isLegacyReadAllowed } from "./lib.js";
3
+ import { RELEASE_MODE } from "./release-identity.js";
4
+ const MS_PER_SECOND = 1000;
5
+ /** Says once on stderr that the command waits for another process to finish with the database. */
6
+ export function reportLockWait({ budgetMs }) {
7
+ diagnostic(`Another process is using the database. Waiting up to ${budgetMs / MS_PER_SECOND} seconds for it to finish.`);
8
+ }
9
+ export function reportLegacyRead({ databasePath }) {
10
+ diagnostic(`Warning: the database at ${databasePath} has no schema version. Reads are best effort and may fail or omit data.`);
11
+ }
12
+ /** How the CLI asks core to open the database. */
13
+ export function getCliOpenPolicy() {
14
+ return {
15
+ client: "cli",
16
+ version: packageJson.version,
17
+ // The script the CLI runs from; the runtime itself when there is none.
18
+ executable: process.argv[1] ?? process.execPath,
19
+ release: RELEASE_MODE,
20
+ // Read when the database opens, after the router has handled `--allow-legacy-read`
21
+ get allowsLegacyRead() {
22
+ return isLegacyReadAllowed();
23
+ },
24
+ onWait: reportLockWait,
25
+ onLegacyRead: reportLegacyRead,
26
+ };
27
+ }
@@ -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">;