trekoon 0.1.8 → 0.1.9
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/.agents/skills/trekoon/SKILL.md +42 -0
- package/README.md +71 -12
- package/package.json +1 -1
- package/src/commands/arg-parser.ts +82 -0
- package/src/commands/epic.ts +70 -1
- package/src/commands/help.ts +12 -1
- package/src/commands/subtask.ts +23 -1
- package/src/commands/sync.ts +130 -52
- package/src/commands/task.ts +71 -1
- package/src/index.ts +1 -1
- package/src/io/output.ts +98 -5
- package/src/runtime/cli-shell.ts +159 -22
- package/src/runtime/command-types.ts +18 -0
- package/src/storage/path.ts +58 -1
package/src/runtime/cli-shell.ts
CHANGED
|
@@ -11,8 +11,9 @@ import { runSync } from "../commands/sync";
|
|
|
11
11
|
import { runTask } from "../commands/task";
|
|
12
12
|
import { runWipe } from "../commands/wipe";
|
|
13
13
|
import { failResult, okResult, renderResult } from "../io/output";
|
|
14
|
-
import { type CliContext, type CliResult, type OutputMode } from "./command-types";
|
|
14
|
+
import { type CliContext, type CliResult, type CompatibilityMode, type OutputMode } from "./command-types";
|
|
15
15
|
import { CLI_VERSION } from "./version";
|
|
16
|
+
import { resolveStoragePaths } from "../storage/path";
|
|
16
17
|
|
|
17
18
|
const SUPPORTED_ROOT_COMMANDS: readonly string[] = [
|
|
18
19
|
"help",
|
|
@@ -31,6 +32,9 @@ const SUPPORTED_ROOT_COMMANDS: readonly string[] = [
|
|
|
31
32
|
|
|
32
33
|
export interface ParsedInvocation {
|
|
33
34
|
readonly mode: OutputMode;
|
|
35
|
+
readonly compatibilityMode: CompatibilityMode | null;
|
|
36
|
+
readonly compatibilityModeRaw: string | null;
|
|
37
|
+
readonly compatibilityModeMissingValue: boolean;
|
|
34
38
|
readonly command: string | null;
|
|
35
39
|
readonly args: readonly string[];
|
|
36
40
|
readonly wantsHelp: boolean;
|
|
@@ -44,11 +48,18 @@ export interface ParseInvocationOptions {
|
|
|
44
48
|
export function parseInvocation(argv: readonly string[], options: ParseInvocationOptions = {}): ParsedInvocation {
|
|
45
49
|
const stdoutIsTTY: boolean = options.stdoutIsTTY ?? Boolean(process.stdout.isTTY);
|
|
46
50
|
let explicitMode: OutputMode | null = null;
|
|
51
|
+
let compatibilityModeRaw: string | null = null;
|
|
52
|
+
let compatibilityModeMissingValue = false;
|
|
47
53
|
let wantsHelp = false;
|
|
48
54
|
let wantsVersion = false;
|
|
49
55
|
const positionals: string[] = [];
|
|
50
56
|
|
|
51
|
-
for (
|
|
57
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
58
|
+
const token: string | undefined = argv[index];
|
|
59
|
+
if (!token) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
52
63
|
if (token === "--json") {
|
|
53
64
|
explicitMode = "json";
|
|
54
65
|
continue;
|
|
@@ -69,11 +80,29 @@ export function parseInvocation(argv: readonly string[], options: ParseInvocatio
|
|
|
69
80
|
continue;
|
|
70
81
|
}
|
|
71
82
|
|
|
83
|
+
if (token === "--compat") {
|
|
84
|
+
const maybeValue: string | undefined = argv[index + 1];
|
|
85
|
+
if (!maybeValue || maybeValue.startsWith("--")) {
|
|
86
|
+
compatibilityModeMissingValue = true;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
compatibilityModeRaw = maybeValue;
|
|
91
|
+
index += 1;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
|
|
72
95
|
positionals.push(token);
|
|
73
96
|
}
|
|
74
97
|
|
|
98
|
+
const compatibilityMode: CompatibilityMode | null =
|
|
99
|
+
compatibilityModeRaw === "legacy-sync-command-ids" ? compatibilityModeRaw : null;
|
|
100
|
+
|
|
75
101
|
return {
|
|
76
102
|
mode: explicitMode ?? (stdoutIsTTY ? "human" : "json"),
|
|
103
|
+
compatibilityMode,
|
|
104
|
+
compatibilityModeRaw,
|
|
105
|
+
compatibilityModeMissingValue,
|
|
77
106
|
command: positionals[0] ?? null,
|
|
78
107
|
args: positionals.slice(1),
|
|
79
108
|
wantsHelp,
|
|
@@ -81,11 +110,96 @@ export function parseInvocation(argv: readonly string[], options: ParseInvocatio
|
|
|
81
110
|
};
|
|
82
111
|
}
|
|
83
112
|
|
|
84
|
-
export function renderShellResult(result: CliResult, mode: OutputMode): string {
|
|
85
|
-
|
|
113
|
+
export function renderShellResult(result: CliResult, mode: OutputMode, compatibilityMode: CompatibilityMode | null = null): string {
|
|
114
|
+
const effectiveCompatibilityMode: CompatibilityMode | null =
|
|
115
|
+
compatibilityMode === "legacy-sync-command-ids" && result.command.startsWith("sync.")
|
|
116
|
+
? compatibilityMode
|
|
117
|
+
: null;
|
|
118
|
+
|
|
119
|
+
return renderResult(result, mode, { compatibilityMode: effectiveCompatibilityMode });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function withStorageRootDiagnostics(result: CliResult, cwd: string): CliResult {
|
|
123
|
+
const diagnostics = resolveStoragePaths(cwd).diagnostics;
|
|
124
|
+
if (diagnostics.warnings.length === 0 && diagnostics.errors.length === 0) {
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
...result,
|
|
130
|
+
meta: {
|
|
131
|
+
...(result.meta ?? {}),
|
|
132
|
+
storageRootDiagnostics: {
|
|
133
|
+
invocationCwd: diagnostics.invocationCwd,
|
|
134
|
+
canonicalRoot: diagnostics.canonicalRoot,
|
|
135
|
+
warning: diagnostics.warnings[0] ?? null,
|
|
136
|
+
error: diagnostics.errors[0] ?? null,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
};
|
|
86
140
|
}
|
|
87
141
|
|
|
88
142
|
export async function executeShell(parsed: ParsedInvocation, cwd: string = process.cwd()): Promise<CliResult> {
|
|
143
|
+
if (parsed.compatibilityModeMissingValue) {
|
|
144
|
+
return failResult({
|
|
145
|
+
command: "shell",
|
|
146
|
+
human: "--compat requires an explicit mode value.",
|
|
147
|
+
data: {
|
|
148
|
+
option: "--compat",
|
|
149
|
+
allowedModes: ["legacy-sync-command-ids"],
|
|
150
|
+
},
|
|
151
|
+
error: {
|
|
152
|
+
code: "invalid_args",
|
|
153
|
+
message: "Missing compatibility mode value for --compat.",
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (parsed.compatibilityModeRaw !== null && parsed.compatibilityMode === null) {
|
|
159
|
+
return failResult({
|
|
160
|
+
command: "shell",
|
|
161
|
+
human: `Unsupported compatibility mode '${parsed.compatibilityModeRaw}'.`,
|
|
162
|
+
data: {
|
|
163
|
+
providedMode: parsed.compatibilityModeRaw,
|
|
164
|
+
allowedModes: ["legacy-sync-command-ids"],
|
|
165
|
+
},
|
|
166
|
+
error: {
|
|
167
|
+
code: "invalid_args",
|
|
168
|
+
message: `Unsupported compatibility mode '${parsed.compatibilityModeRaw}'.`,
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (parsed.compatibilityMode !== null && parsed.mode === "human") {
|
|
174
|
+
return failResult({
|
|
175
|
+
command: "shell",
|
|
176
|
+
human: "Compatibility mode is machine-only; use --json or --toon.",
|
|
177
|
+
data: {
|
|
178
|
+
mode: parsed.mode,
|
|
179
|
+
compatibilityMode: parsed.compatibilityMode,
|
|
180
|
+
},
|
|
181
|
+
error: {
|
|
182
|
+
code: "invalid_args",
|
|
183
|
+
message: "Compatibility mode requires machine output mode.",
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (parsed.compatibilityMode === "legacy-sync-command-ids" && parsed.command !== "sync") {
|
|
189
|
+
return failResult({
|
|
190
|
+
command: "shell",
|
|
191
|
+
human: "--compat legacy-sync-command-ids only supports sync commands.",
|
|
192
|
+
data: {
|
|
193
|
+
compatibilityMode: parsed.compatibilityMode,
|
|
194
|
+
command: parsed.command,
|
|
195
|
+
},
|
|
196
|
+
error: {
|
|
197
|
+
code: "invalid_args",
|
|
198
|
+
message: "Compatibility mode can only be used with the sync command.",
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
89
203
|
if (parsed.wantsVersion) {
|
|
90
204
|
return okResult({
|
|
91
205
|
command: "version",
|
|
@@ -101,19 +215,23 @@ export async function executeShell(parsed: ParsedInvocation, cwd: string = proce
|
|
|
101
215
|
args: parsed.command ? [parsed.command] : [],
|
|
102
216
|
};
|
|
103
217
|
|
|
104
|
-
return runHelp(helpContext);
|
|
218
|
+
return withStorageRootDiagnostics(await runHelp(helpContext), cwd);
|
|
105
219
|
}
|
|
106
220
|
|
|
107
221
|
if (!parsed.command) {
|
|
108
|
-
return
|
|
222
|
+
return withStorageRootDiagnostics(
|
|
223
|
+
await runHelp({
|
|
109
224
|
mode: parsed.mode,
|
|
110
225
|
args: [],
|
|
111
226
|
cwd,
|
|
112
|
-
|
|
227
|
+
}),
|
|
228
|
+
cwd,
|
|
229
|
+
);
|
|
113
230
|
}
|
|
114
231
|
|
|
115
232
|
if (!SUPPORTED_ROOT_COMMANDS.includes(parsed.command)) {
|
|
116
|
-
return
|
|
233
|
+
return withStorageRootDiagnostics(
|
|
234
|
+
failResult({
|
|
117
235
|
command: "shell",
|
|
118
236
|
human: `Unknown command: ${parsed.command}\nRun 'trekoon --help' for usage.`,
|
|
119
237
|
data: {
|
|
@@ -124,7 +242,9 @@ export async function executeShell(parsed: ParsedInvocation, cwd: string = proce
|
|
|
124
242
|
code: "unknown_command",
|
|
125
243
|
message: `Unknown command '${parsed.command}'`,
|
|
126
244
|
},
|
|
127
|
-
|
|
245
|
+
}),
|
|
246
|
+
cwd,
|
|
247
|
+
);
|
|
128
248
|
}
|
|
129
249
|
|
|
130
250
|
const context: CliContext = {
|
|
@@ -133,33 +253,47 @@ export async function executeShell(parsed: ParsedInvocation, cwd: string = proce
|
|
|
133
253
|
cwd,
|
|
134
254
|
};
|
|
135
255
|
|
|
256
|
+
let result: CliResult;
|
|
257
|
+
|
|
136
258
|
switch (parsed.command) {
|
|
137
259
|
case "help":
|
|
138
|
-
|
|
260
|
+
result = await runHelp(context);
|
|
261
|
+
break;
|
|
139
262
|
case "init":
|
|
140
|
-
|
|
263
|
+
result = await runInit(context);
|
|
264
|
+
break;
|
|
141
265
|
case "quickstart":
|
|
142
|
-
|
|
266
|
+
result = await runQuickstart(context);
|
|
267
|
+
break;
|
|
143
268
|
case "wipe":
|
|
144
|
-
|
|
269
|
+
result = await runWipe(context);
|
|
270
|
+
break;
|
|
145
271
|
case "epic":
|
|
146
|
-
|
|
272
|
+
result = await runEpic(context);
|
|
273
|
+
break;
|
|
147
274
|
case "task":
|
|
148
|
-
|
|
275
|
+
result = await runTask(context);
|
|
276
|
+
break;
|
|
149
277
|
case "subtask":
|
|
150
|
-
|
|
278
|
+
result = await runSubtask(context);
|
|
279
|
+
break;
|
|
151
280
|
case "dep":
|
|
152
|
-
|
|
281
|
+
result = await runDep(context);
|
|
282
|
+
break;
|
|
153
283
|
case "events":
|
|
154
|
-
|
|
284
|
+
result = await runEvents(context);
|
|
285
|
+
break;
|
|
155
286
|
case "migrate":
|
|
156
|
-
|
|
287
|
+
result = await runMigrate(context);
|
|
288
|
+
break;
|
|
157
289
|
case "sync":
|
|
158
|
-
|
|
290
|
+
result = await runSync(context);
|
|
291
|
+
break;
|
|
159
292
|
case "skills":
|
|
160
|
-
|
|
293
|
+
result = await runSkills(context);
|
|
294
|
+
break;
|
|
161
295
|
default:
|
|
162
|
-
|
|
296
|
+
result = failResult({
|
|
163
297
|
command: "shell",
|
|
164
298
|
human: `Unhandled command: ${parsed.command}`,
|
|
165
299
|
data: { command: parsed.command },
|
|
@@ -168,5 +302,8 @@ export async function executeShell(parsed: ParsedInvocation, cwd: string = proce
|
|
|
168
302
|
message: `No shell handler for '${parsed.command}'`,
|
|
169
303
|
},
|
|
170
304
|
});
|
|
305
|
+
break;
|
|
171
306
|
}
|
|
307
|
+
|
|
308
|
+
return withStorageRootDiagnostics(result, cwd);
|
|
172
309
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type OutputMode = "human" | "json" | "toon";
|
|
2
|
+
export type CompatibilityMode = "legacy-sync-command-ids";
|
|
2
3
|
|
|
3
4
|
export interface CliContext {
|
|
4
5
|
readonly mode: OutputMode;
|
|
@@ -11,10 +12,27 @@ export interface ToonError {
|
|
|
11
12
|
readonly message: string;
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
export interface ContractMetadata {
|
|
16
|
+
readonly contractVersion: string;
|
|
17
|
+
readonly requestId: string;
|
|
18
|
+
readonly compatibility?: CompatibilityMetadata;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CompatibilityMetadata {
|
|
22
|
+
readonly mode: CompatibilityMode;
|
|
23
|
+
readonly warningCode: "compatibility_mode_deprecated";
|
|
24
|
+
readonly deprecatedSince: string;
|
|
25
|
+
readonly removalAfter: string;
|
|
26
|
+
readonly migration: string;
|
|
27
|
+
readonly canonicalCommand: string;
|
|
28
|
+
readonly compatibilityCommand: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
14
31
|
export interface ToonEnvelope {
|
|
15
32
|
readonly ok: boolean;
|
|
16
33
|
readonly command: string;
|
|
17
34
|
readonly data: unknown;
|
|
35
|
+
readonly metadata: ContractMetadata;
|
|
18
36
|
readonly error?: ToonError;
|
|
19
37
|
readonly meta?: Record<string, unknown>;
|
|
20
38
|
}
|
package/src/storage/path.ts
CHANGED
|
@@ -1,22 +1,79 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
1
2
|
import { resolve } from "node:path";
|
|
2
3
|
|
|
3
4
|
const DB_DIRNAME = ".trekoon";
|
|
4
5
|
const DB_FILENAME = "trekoon.db";
|
|
5
6
|
|
|
6
7
|
export interface StoragePaths {
|
|
8
|
+
readonly invocationCwd: string;
|
|
7
9
|
readonly worktreeRoot: string;
|
|
8
10
|
readonly storageDir: string;
|
|
9
11
|
readonly databaseFile: string;
|
|
12
|
+
readonly diagnostics: StoragePathDiagnostics;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface StoragePathIssue {
|
|
16
|
+
readonly code: string;
|
|
17
|
+
readonly message: string;
|
|
18
|
+
readonly invocationCwd: string;
|
|
19
|
+
readonly canonicalRoot: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface StoragePathDiagnostics {
|
|
23
|
+
readonly invocationCwd: string;
|
|
24
|
+
readonly canonicalRoot: string;
|
|
25
|
+
readonly warnings: readonly StoragePathIssue[];
|
|
26
|
+
readonly errors: readonly StoragePathIssue[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function resolveGitTopLevel(workingDirectory: string): string | null {
|
|
30
|
+
const result = spawnSync("git", ["rev-parse", "--show-toplevel"], {
|
|
31
|
+
cwd: workingDirectory,
|
|
32
|
+
encoding: "utf8",
|
|
33
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (result.status !== 0) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const topLevel: string = result.stdout.trim();
|
|
41
|
+
if (!topLevel) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return resolve(topLevel);
|
|
10
46
|
}
|
|
11
47
|
|
|
12
48
|
export function resolveStoragePaths(workingDirectory: string = process.cwd()): StoragePaths {
|
|
13
|
-
const
|
|
49
|
+
const invocationCwd: string = resolve(workingDirectory);
|
|
50
|
+
const canonicalRoot: string = resolveGitTopLevel(invocationCwd) ?? invocationCwd;
|
|
51
|
+
const worktreeRoot: string = canonicalRoot;
|
|
14
52
|
const storageDir: string = resolve(worktreeRoot, DB_DIRNAME);
|
|
15
53
|
const databaseFile: string = resolve(storageDir, DB_FILENAME);
|
|
54
|
+
const warnings: StoragePathIssue[] = [];
|
|
55
|
+
|
|
56
|
+
if (invocationCwd !== canonicalRoot) {
|
|
57
|
+
warnings.push({
|
|
58
|
+
code: "storage_root_diverged_from_cwd",
|
|
59
|
+
message: "Resolved storage root differs from invocation cwd.",
|
|
60
|
+
invocationCwd,
|
|
61
|
+
canonicalRoot,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const diagnostics: StoragePathDiagnostics = {
|
|
66
|
+
invocationCwd,
|
|
67
|
+
canonicalRoot,
|
|
68
|
+
warnings,
|
|
69
|
+
errors: [],
|
|
70
|
+
};
|
|
16
71
|
|
|
17
72
|
return {
|
|
73
|
+
invocationCwd,
|
|
18
74
|
worktreeRoot,
|
|
19
75
|
storageDir,
|
|
20
76
|
databaseFile,
|
|
77
|
+
diagnostics,
|
|
21
78
|
};
|
|
22
79
|
}
|