trekoon 0.4.2 → 0.4.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.
Files changed (40) hide show
  1. package/.agents/skills/trekoon/SKILL.md +97 -208
  2. package/.agents/skills/trekoon/reference/execution-with-team.md +87 -149
  3. package/.agents/skills/trekoon/reference/execution.md +170 -380
  4. package/.agents/skills/trekoon/reference/harness-primitives.md +77 -0
  5. package/.agents/skills/trekoon/reference/planning.md +193 -330
  6. package/.agents/skills/trekoon/reference/sync.md +56 -103
  7. package/README.md +29 -10
  8. package/docs/ai-agents.md +48 -4
  9. package/docs/commands.md +34 -25
  10. package/docs/machine-contracts.md +1 -1
  11. package/docs/quickstart.md +9 -9
  12. package/package.json +2 -2
  13. package/src/board/asset-root.ts +73 -0
  14. package/src/board/assets/app.js +5 -3
  15. package/src/board/assets/components/Component.js +6 -8
  16. package/src/board/assets/state/actions.js +3 -0
  17. package/src/board/assets/state/api.js +48 -34
  18. package/src/board/assets/state/store.js +3 -0
  19. package/src/board/event-bus.ts +15 -0
  20. package/src/board/routes.ts +94 -83
  21. package/src/board/server.ts +35 -8
  22. package/src/board/snapshot.ts +6 -0
  23. package/src/board/types.ts +2 -34
  24. package/src/board/wal-watcher.ts +170 -28
  25. package/src/commands/board.ts +20 -42
  26. package/src/commands/help.ts +11 -12
  27. package/src/commands/init.ts +0 -29
  28. package/src/commands/quickstart.ts +1 -1
  29. package/src/commands/skills.ts +17 -5
  30. package/src/domain/mutation-service.ts +61 -42
  31. package/src/domain/tracker-domain.ts +20 -16
  32. package/src/domain/types.ts +3 -0
  33. package/src/export/render-markdown.ts +1 -2
  34. package/src/runtime/daemon.ts +110 -49
  35. package/src/runtime/version.ts +10 -2
  36. package/src/storage/database.ts +9 -2
  37. package/src/storage/migrations.ts +19 -2
  38. package/src/storage/path.ts +0 -36
  39. package/src/sync/service.ts +47 -27
  40. package/src/board/install.ts +0 -196
@@ -1,196 +0,0 @@
1
- import {
2
- createHash,
3
- } from "node:crypto";
4
- import {
5
- cpSync,
6
- existsSync,
7
- mkdirSync,
8
- readdirSync,
9
- readFileSync,
10
- rmSync,
11
- statSync,
12
- writeFileSync,
13
- } from "node:fs";
14
- import { dirname, join, relative, resolve } from "node:path";
15
- import { fileURLToPath } from "node:url";
16
-
17
- import { CLI_VERSION } from "../runtime/version";
18
- import {
19
- resolveStoragePaths,
20
- TREKOON_BOARD_ENTRY_FILENAME,
21
- TREKOON_BOARD_MANIFEST_FILENAME,
22
- } from "../storage/path";
23
- import {
24
- BOARD_ASSET_CONTRACT_VERSION,
25
- BOARD_BUNDLED_ASSET_DIRNAME,
26
- BoardInstallError,
27
- type BoardAssetManifest,
28
- type BoardInstallAction,
29
- type BoardInstallResult,
30
- type EnsureBoardInstalledOptions,
31
- } from "./types";
32
-
33
- function resolveBundledBoardAssetRoot(): string {
34
- return fileURLToPath(new URL(`./${BOARD_BUNDLED_ASSET_DIRNAME}`, import.meta.url));
35
- }
36
-
37
- function listRelativeFiles(rootPath: string, currentPath: string = rootPath): string[] {
38
- const entries = readdirSync(currentPath, { withFileTypes: true });
39
- const files: string[] = [];
40
-
41
- for (const entry of entries) {
42
- const entryPath: string = join(currentPath, entry.name);
43
- if (entry.isDirectory()) {
44
- files.push(...listRelativeFiles(rootPath, entryPath));
45
- continue;
46
- }
47
-
48
- if (entry.isFile()) {
49
- files.push(relative(rootPath, entryPath));
50
- }
51
- }
52
-
53
- return files.sort((left, right) => left.localeCompare(right));
54
- }
55
-
56
- interface ReadManifestResult {
57
- readonly manifest: BoardAssetManifest | null;
58
- readonly damaged: boolean;
59
- }
60
-
61
- function readManifest(manifestFile: string): ReadManifestResult {
62
- if (!existsSync(manifestFile)) {
63
- return {
64
- manifest: null,
65
- damaged: false,
66
- };
67
- }
68
-
69
- try {
70
- const rawManifest: string = readFileSync(manifestFile, "utf8");
71
- return {
72
- manifest: JSON.parse(rawManifest) as BoardAssetManifest,
73
- damaged: false,
74
- };
75
- } catch {
76
- return {
77
- manifest: null,
78
- damaged: true,
79
- };
80
- }
81
- }
82
-
83
- function createAssetDigest(sourceRoot: string, files: readonly string[]): string {
84
- const hash = createHash("sha256");
85
-
86
- for (const relativeFile of files) {
87
- hash.update(relativeFile);
88
- hash.update("\0");
89
- hash.update(readFileSync(join(sourceRoot, relativeFile)));
90
- hash.update("\0");
91
- }
92
-
93
- return hash.digest("hex");
94
- }
95
-
96
- function createManifest(sourceRoot: string, assetVersion: string, files: readonly string[]): BoardAssetManifest {
97
- return {
98
- contractVersion: BOARD_ASSET_CONTRACT_VERSION,
99
- assetVersion,
100
- entryFile: TREKOON_BOARD_ENTRY_FILENAME,
101
- files,
102
- assetDigest: createAssetDigest(sourceRoot, files),
103
- };
104
- }
105
-
106
- function installBoardFiles(sourceRoot: string, runtimeRoot: string, manifest: BoardAssetManifest): void {
107
- rmSync(runtimeRoot, { recursive: true, force: true });
108
- mkdirSync(dirname(runtimeRoot), { recursive: true });
109
- cpSync(sourceRoot, runtimeRoot, { recursive: true });
110
- writeFileSync(join(runtimeRoot, TREKOON_BOARD_MANIFEST_FILENAME), `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
111
- }
112
-
113
- function determineAction(
114
- runtimeRoot: string,
115
- entryFile: string,
116
- currentManifest: BoardAssetManifest | null,
117
- manifestDamaged: boolean,
118
- nextManifest: BoardAssetManifest,
119
- ): BoardInstallAction {
120
- if (manifestDamaged) {
121
- return "reinstalled";
122
- }
123
-
124
- if (!existsSync(runtimeRoot) || !existsSync(entryFile) || currentManifest === null) {
125
- return currentManifest === null && !existsSync(runtimeRoot) ? "installed" : "reinstalled";
126
- }
127
-
128
- if (
129
- currentManifest.contractVersion !== nextManifest.contractVersion ||
130
- currentManifest.assetVersion !== nextManifest.assetVersion ||
131
- currentManifest.entryFile !== nextManifest.entryFile ||
132
- JSON.stringify(currentManifest.files) !== JSON.stringify(nextManifest.files) ||
133
- currentManifest.assetDigest !== nextManifest.assetDigest
134
- ) {
135
- return "updated";
136
- }
137
-
138
- for (const relativeFile of nextManifest.files) {
139
- if (!existsSync(join(runtimeRoot, relativeFile))) {
140
- return "reinstalled";
141
- }
142
- }
143
-
144
- return "unchanged";
145
- }
146
-
147
- export function ensureBoardInstalled(options: EnsureBoardInstalledOptions = {}): BoardInstallResult {
148
- const paths = resolveStoragePaths(options.workingDirectory);
149
- const sourceRoot: string = resolve(options.bundledAssetRoot ?? resolveBundledBoardAssetRoot());
150
- const runtimeRoot: string = paths.boardDir;
151
- const entryFile: string = paths.boardEntryFile;
152
- const manifestFile: string = paths.boardManifestFile;
153
-
154
- if (!existsSync(sourceRoot) || !statSync(sourceRoot).isDirectory()) {
155
- throw new BoardInstallError("missing_asset", `Bundled board asset directory not found at ${sourceRoot}`, {
156
- sourceRoot,
157
- });
158
- }
159
-
160
- const sourceFiles: string[] = listRelativeFiles(sourceRoot);
161
- if (!sourceFiles.includes(TREKOON_BOARD_ENTRY_FILENAME)) {
162
- throw new BoardInstallError("missing_asset", `Bundled board entry file not found at ${join(sourceRoot, TREKOON_BOARD_ENTRY_FILENAME)}`, {
163
- sourceRoot,
164
- missingFile: TREKOON_BOARD_ENTRY_FILENAME,
165
- });
166
- }
167
-
168
- const manifest: BoardAssetManifest = createManifest(sourceRoot, options.assetVersion ?? CLI_VERSION, sourceFiles);
169
- const currentManifestResult: ReadManifestResult = readManifest(manifestFile);
170
- const action: BoardInstallAction = determineAction(
171
- runtimeRoot,
172
- entryFile,
173
- currentManifestResult.manifest,
174
- currentManifestResult.damaged,
175
- manifest,
176
- );
177
-
178
- if (action !== "unchanged") {
179
- installBoardFiles(sourceRoot, runtimeRoot, manifest);
180
- }
181
-
182
- return {
183
- action,
184
- paths: {
185
- sourceRoot,
186
- runtimeRoot,
187
- entryFile,
188
- manifestFile,
189
- },
190
- manifest,
191
- };
192
- }
193
-
194
- export function updateBoardInstallation(options: EnsureBoardInstalledOptions = {}): BoardInstallResult {
195
- return ensureBoardInstalled(options);
196
- }