@jive-sh/skill-sync 0.5.1 → 0.6.0-latest-darwin-arm64
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/multi-call-binary +4 -0
- package/package.json +11 -39
- package/README.md +0 -138
- package/bin/package.json +0 -1
- package/bin/skill-sync +0 -576
- package/bin/skill-sync-daemon +0 -576
- package/dist/daemons/skill-sync-daemon.js +0 -499
- package/dist/daemons/skill-sync-daemon.js.map +0 -1
- package/dist/entrypoints/skill-sync.js +0 -153
- package/dist/entrypoints/skill-sync.js.map +0 -1
- package/dist/index.js +0 -10
- package/dist/index.js.map +0 -1
- package/dist/internal/agents/agent-tool.js +0 -92
- package/dist/internal/agents/agent-tool.js.map +0 -1
- package/dist/internal/agents/claude.js +0 -422
- package/dist/internal/agents/claude.js.map +0 -1
- package/dist/internal/agents/codex.js +0 -294
- package/dist/internal/agents/codex.js.map +0 -1
- package/dist/internal/agents/command.js +0 -79
- package/dist/internal/agents/command.js.map +0 -1
- package/dist/internal/agents/grok.js +0 -115
- package/dist/internal/agents/grok.js.map +0 -1
- package/dist/internal/agents/index.js +0 -70
- package/dist/internal/agents/index.js.map +0 -1
- package/dist/internal/config.js +0 -131
- package/dist/internal/config.js.map +0 -1
- package/dist/internal/control.js +0 -101
- package/dist/internal/control.js.map +0 -1
- package/dist/internal/folders.js +0 -47
- package/dist/internal/folders.js.map +0 -1
- package/dist/internal/path.js +0 -36
- package/dist/internal/path.js.map +0 -1
- package/dist/internal/server.js +0 -32
- package/dist/internal/server.js.map +0 -1
- package/dist/internal/skill-check.js +0 -83
- package/dist/internal/skill-check.js.map +0 -1
- package/dist/internal/sync.js +0 -183
- package/dist/internal/sync.js.map +0 -1
- package/dist/internal/wire.js +0 -24
- package/dist/internal/wire.js.map +0 -1
- package/install.cjs +0 -576
- package/src/daemons/skill-sync-daemon.ts +0 -491
- package/src/entrypoints/skill-sync.ts +0 -156
- package/src/index.ts +0 -15
- package/src/internal/agents/agent-tool.ts +0 -136
- package/src/internal/agents/claude.ts +0 -440
- package/src/internal/agents/codex.ts +0 -314
- package/src/internal/agents/command.ts +0 -97
- package/src/internal/agents/grok.ts +0 -117
- package/src/internal/agents/index.ts +0 -74
- package/src/internal/config.ts +0 -172
- package/src/internal/control.ts +0 -140
- package/src/internal/folders.ts +0 -50
- package/src/internal/path.ts +0 -32
- package/src/internal/server.ts +0 -34
- package/src/internal/skill-check.ts +0 -97
- package/src/internal/sync.ts +0 -217
- package/src/internal/wire.ts +0 -279
package/src/internal/sync.ts
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, rmdirSync, rmSync, statSync, utimesSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { dirname, join } from "node:path";
|
|
3
|
-
import { hashBytes, isLock, listLocalFiles, type Config, type State } from "./config";
|
|
4
|
-
import { invalidPathReason } from "./path";
|
|
5
|
-
import { fetchServer } from "./server";
|
|
6
|
-
import { skillOf, type ListFilesResponse, type PutFileRequest } from "./wire";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* One sync cycle: take every newer edit the server has, then send every newer edit this folder has.
|
|
10
|
-
*
|
|
11
|
-
* The latest edit wins, always. Every file carries the time it was last edited: here, the file's
|
|
12
|
-
* modification time; on the server, the edit time of the version it holds. When this folder and the
|
|
13
|
-
* server disagree about a file, whichever was edited later is kept, on both sides. Nothing is merged and
|
|
14
|
-
* nothing is set aside, so every folder converges on the same bytes.
|
|
15
|
-
*
|
|
16
|
-
* A pulled file is given the server's edit time as its modification time, so the next cycle does not
|
|
17
|
-
* mistake the pull for a local edit.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
export interface Report {
|
|
21
|
-
readonly pulled: string[];
|
|
22
|
-
readonly pushed: string[];
|
|
23
|
-
readonly deletedLocally: string[];
|
|
24
|
-
/** Paths the server offered that this machine refused to write. */
|
|
25
|
-
readonly rejected: string[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** True when a report has nothing in it worth telling anyone. */
|
|
29
|
-
export function isQuiet(report: Report): boolean {
|
|
30
|
-
return [report.pulled, report.pushed, report.deletedLocally, report.rejected].every((list) => list.length === 0);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* What a cycle changed, as the dashboard shows it under the folder: per direction, how many files in
|
|
35
|
-
* which skills ("pulled 64 files: agentic-collaboration 52, senior-swe 12"), never the file paths, which
|
|
36
|
-
* after a large pull fill the page. Empty when nothing changed.
|
|
37
|
-
*/
|
|
38
|
-
export function describeActivity(report: Report): string {
|
|
39
|
-
const direction = (verb: string, paths: ReadonlyArray<string>): string => {
|
|
40
|
-
if (paths.length === 0) return "";
|
|
41
|
-
const perSkill = new Map<string, number>();
|
|
42
|
-
for (const path of paths) perSkill.set(skillOf(path), (perSkill.get(skillOf(path)) ?? 0) + 1);
|
|
43
|
-
const skills = [...perSkill].sort(([a], [b]) => a.localeCompare(b)).map(([skill, files]) => `${skill} ${files}`);
|
|
44
|
-
return `${verb} ${paths.length} ${paths.length === 1 ? "file" : "files"}: ${skills.join(", ")}`;
|
|
45
|
-
};
|
|
46
|
-
return [
|
|
47
|
-
direction("pulled", report.pulled),
|
|
48
|
-
direction("pushed", report.pushed),
|
|
49
|
-
direction("deleted", report.deletedLocally),
|
|
50
|
-
].filter(Boolean).join("; ");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* `skills` is the synced list. Every other skill in the folder is local to it: never pushed, never
|
|
55
|
-
* overwritten, never deleted by a sync.
|
|
56
|
-
*/
|
|
57
|
-
export async function syncOnce(config: Config, folder: string, state: State, skills: ReadonlySet<string>): Promise<Report> {
|
|
58
|
-
const report: Report = { pulled: [], pushed: [], deletedLocally: [], rejected: [] };
|
|
59
|
-
mkdirSync(folder, { recursive: true });
|
|
60
|
-
|
|
61
|
-
// A skill added to the list since last cycle may have server files older than the cursor; re-read from the start.
|
|
62
|
-
if ([...skills].some((skill) => !(state.skills ?? []).includes(skill))) state.cursor = 0;
|
|
63
|
-
state.skills = [...skills].sort();
|
|
64
|
-
// A skill removed from the list stops being tracked here. Left in `known`, its files would look deleted
|
|
65
|
-
// from this folder and the push would delete them on every machine.
|
|
66
|
-
for (const path of Object.keys(state.known)) {
|
|
67
|
-
if (!skills.has(skillOf(path)) || path.split("/").some(isLock)) delete state.known[path];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const present = new Set(listLocalFiles(folder, config.exclude).filter((path) => skills.has(skillOf(path))));
|
|
71
|
-
// Files deleted here since the last cycle. When they were deleted is not recorded anywhere, so the
|
|
72
|
-
// deletion counts as an edit made now: the pull leaves these paths alone and the push deletes them.
|
|
73
|
-
const deletedHere = new Set(Object.keys(state.known).filter((path) => !present.has(path)));
|
|
74
|
-
|
|
75
|
-
const ctx: Cycle = { config, folder, state, report, skills };
|
|
76
|
-
await pull(ctx, deletedHere, present);
|
|
77
|
-
await push(ctx, present);
|
|
78
|
-
return report;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
interface Cycle {
|
|
82
|
-
readonly config: Config;
|
|
83
|
-
readonly folder: string;
|
|
84
|
-
readonly state: State;
|
|
85
|
-
readonly report: Report;
|
|
86
|
-
readonly skills: ReadonlySet<string>;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** When this file was last edited here, to the millisecond the server stores. */
|
|
90
|
-
const editedAt = (file: string): number => Math.floor(statSync(file).mtimeMs);
|
|
91
|
-
|
|
92
|
-
async function pull(ctx: Cycle, deletedHere: ReadonlySet<string>, present: Set<string>): Promise<void> {
|
|
93
|
-
const { config, folder, state, report } = ctx;
|
|
94
|
-
const body = await (await call(config, `/files?since=${state.cursor}`)).json() as ListFilesResponse;
|
|
95
|
-
|
|
96
|
-
for (const file of body.files) {
|
|
97
|
-
// The server is not trusted to supply a path either: one bad row would otherwise write outside the
|
|
98
|
-
// skills directory on every machine that syncs.
|
|
99
|
-
const badPath = invalidPathReason(file.path);
|
|
100
|
-
if (badPath) {
|
|
101
|
-
report.rejected.push(`${file.path} (${badPath})`);
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
if (!ctx.skills.has(skillOf(file.path))) continue;
|
|
105
|
-
// Never written here: the file listing skips lock names, so a pulled one would read as deleted next cycle.
|
|
106
|
-
if (file.path.split("/").some(isLock)) continue;
|
|
107
|
-
// Deleted here, which is newer than anything the server has; the push sends the deletion.
|
|
108
|
-
if (deletedHere.has(file.path)) continue;
|
|
109
|
-
|
|
110
|
-
const local = join(folder, file.path);
|
|
111
|
-
const exists = existsSync(local);
|
|
112
|
-
const localHash = exists ? hashBytes(readFileSync(local)) : undefined;
|
|
113
|
-
if (localHash === (file.hash ?? undefined)) {
|
|
114
|
-
if (file.hash === null) delete state.known[file.path];
|
|
115
|
-
else state.known[file.path] = file.hash;
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
// Edited here since this folder last agreed with the server, and later than the server's version:
|
|
119
|
-
// this folder's edit wins, and the push sends it.
|
|
120
|
-
if (exists && localHash !== state.known[file.path] && editedAt(local) > file.editedAt) continue;
|
|
121
|
-
|
|
122
|
-
await apply(ctx, file, present);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
state.cursor = body.cursor;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async function push(ctx: Cycle, present: Set<string>): Promise<void> {
|
|
129
|
-
const { config, folder, state, report } = ctx;
|
|
130
|
-
for (const path of [...present]) {
|
|
131
|
-
const file = join(folder, path);
|
|
132
|
-
const bytes = readFileSync(file);
|
|
133
|
-
const hash = hashBytes(bytes);
|
|
134
|
-
if (state.known[path] === hash) continue;
|
|
135
|
-
const later = await put(config, { path, hash, content: Buffer.from(bytes).toString("base64"), editedAt: editedAt(file) });
|
|
136
|
-
if (later === undefined) {
|
|
137
|
-
state.known[path] = hash;
|
|
138
|
-
report.pushed.push(path);
|
|
139
|
-
} else {
|
|
140
|
-
await apply(ctx, { path, ...later }, present);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// A path this folder agreed on that is no longer on disk was deleted here. The server keeps the
|
|
145
|
-
// deletion, or the next machine to sync would upload the file again.
|
|
146
|
-
for (const path of Object.keys(state.known)) {
|
|
147
|
-
if (present.has(path)) continue;
|
|
148
|
-
const later = await put(config, { path, hash: null, content: null, editedAt: Date.now() });
|
|
149
|
-
if (later === undefined) {
|
|
150
|
-
delete state.known[path];
|
|
151
|
-
report.pushed.push(`${path} (deleted)`);
|
|
152
|
-
} else {
|
|
153
|
-
await apply(ctx, { path, ...later }, present);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/** The server's version of a file, as it answers a refused write. */
|
|
159
|
-
interface ServerVersion {
|
|
160
|
-
readonly hash: string | null;
|
|
161
|
-
readonly editedAt: number;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Writes the server's version of a file here: its bytes with its edit time, or a deletion. Used by the
|
|
166
|
-
* pull, and by the push when the server refuses a write because it holds a later edit, so a refused write
|
|
167
|
-
* settles at once rather than waiting for a pull that may never list the file again.
|
|
168
|
-
*/
|
|
169
|
-
async function apply(ctx: Cycle, file: ServerVersion & { readonly path: string }, present: Set<string>): Promise<void> {
|
|
170
|
-
const { config, folder, state, report } = ctx;
|
|
171
|
-
const local = join(folder, file.path);
|
|
172
|
-
if (file.hash === null) {
|
|
173
|
-
rmSync(local, { force: true });
|
|
174
|
-
removeEmptyParents(folder, local);
|
|
175
|
-
present.delete(file.path);
|
|
176
|
-
delete state.known[file.path];
|
|
177
|
-
report.deletedLocally.push(file.path);
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
const content = new Uint8Array(await (await call(config, `/content/${file.hash}`)).arrayBuffer());
|
|
181
|
-
mkdirSync(dirname(local), { recursive: true });
|
|
182
|
-
writeFileSync(local, content);
|
|
183
|
-
utimesSync(local, new Date(), new Date(file.editedAt));
|
|
184
|
-
state.known[file.path] = file.hash;
|
|
185
|
-
present.add(file.path);
|
|
186
|
-
report.pulled.push(file.path);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/** A deleted skill leaves no empty directory behind, which would still show up as a skill. */
|
|
190
|
-
function removeEmptyParents(folder: string, file: string): void {
|
|
191
|
-
for (let dir = dirname(file); dir !== folder && dir.startsWith(folder); dir = dirname(dir)) {
|
|
192
|
-
if (readdirSync(dir).length > 0) return;
|
|
193
|
-
rmdirSync(dir);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/** Undefined when the server took the write; otherwise the later version it holds instead. */
|
|
198
|
-
async function put(config: Config, body: Omit<PutFileRequest, "machine">): Promise<ServerVersion | undefined> {
|
|
199
|
-
const request: PutFileRequest = { ...body, machine: config.machine };
|
|
200
|
-
const response = await fetchServer(config, "/files", {
|
|
201
|
-
method: "PUT",
|
|
202
|
-
headers: { "content-type": "application/json" },
|
|
203
|
-
body: JSON.stringify(request),
|
|
204
|
-
});
|
|
205
|
-
if (response.status === 409) {
|
|
206
|
-
const current = await response.json() as { currentHash: string | null; currentEditedAt: number };
|
|
207
|
-
return { hash: current.currentHash, editedAt: current.currentEditedAt };
|
|
208
|
-
}
|
|
209
|
-
if (!response.ok) throw new Error(`PUT /files ${body.path}: ${response.status} ${await response.text()}`);
|
|
210
|
-
return undefined;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
async function call(config: Config, path: string): Promise<Response> {
|
|
214
|
-
const response = await fetchServer(config, path);
|
|
215
|
-
if (!response.ok) throw new Error(`GET ${path}: ${response.status} ${await response.text()}`);
|
|
216
|
-
return response;
|
|
217
|
-
}
|
package/src/internal/wire.ts
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The shapes the daemon and the service exchange.
|
|
3
|
-
*
|
|
4
|
-
* Declared in the library and imported by the service so there is one definition rather than two that
|
|
5
|
-
* drift. The service depends on the library; nothing goes the other way.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export interface RemoteFile {
|
|
9
|
-
readonly path: string;
|
|
10
|
-
/** Null when the file is deleted; the row stays, so the deletion reaches every machine. */
|
|
11
|
-
readonly hash: string | null;
|
|
12
|
-
/** When this version was edited, in milliseconds since the epoch. The latest edit wins. */
|
|
13
|
-
readonly editedAt: number;
|
|
14
|
-
readonly updatedBy: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface ListFilesResponse {
|
|
18
|
-
/** Highest sequence number in this page; the caller sends it back as `since`. */
|
|
19
|
-
readonly cursor: number;
|
|
20
|
-
readonly files: ReadonlyArray<RemoteFile>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** Taken only when `editedAt` is later than the edit the server holds; refused with 409 otherwise. */
|
|
24
|
-
export interface PutFileRequest {
|
|
25
|
-
readonly path: string;
|
|
26
|
-
/** When the file was edited: its modification time, or for a deletion, when it was noticed. */
|
|
27
|
-
readonly editedAt: number;
|
|
28
|
-
/** Null to delete. */
|
|
29
|
-
readonly hash: string | null;
|
|
30
|
-
/** Base64, absent for a delete. */
|
|
31
|
-
readonly content: string | null;
|
|
32
|
-
readonly machine: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Where a folder's sync stands, as the dashboard shows it. `attention` means a cycle failed; `detail` says why. */
|
|
36
|
-
export type FolderState = "idle" | "attention";
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* A skill is a top-level entry of a skills folder — usually a directory like `jive/` holding `SKILL.md`
|
|
40
|
-
* and its files — and it is the unit of opting in: all of its files sync, or none do, so a skill never
|
|
41
|
-
* arrives half-present on another machine.
|
|
42
|
-
*/
|
|
43
|
-
export const skillOf = (path: string): string => path.split("/")[0]!;
|
|
44
|
-
|
|
45
|
-
/** A file and the SHA-256 of its content — the same hash the server stores, so copies can be compared. */
|
|
46
|
-
export interface FileHash {
|
|
47
|
-
readonly path: string;
|
|
48
|
-
readonly hash: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** One skill as a folder holds it. */
|
|
52
|
-
export interface LocalSkill {
|
|
53
|
-
readonly name: string;
|
|
54
|
-
readonly files: ReadonlyArray<FileHash>;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* `POST /folders`: every folder this machine found, with the skills in each, for the dashboard. Answered
|
|
59
|
-
* with the enabled folders, each with the synced list: the daemon pushes and pulls exactly those skills,
|
|
60
|
-
* and never touches any other.
|
|
61
|
-
*/
|
|
62
|
-
export interface FoldersRequest {
|
|
63
|
-
readonly folders: ReadonlyArray<{ readonly path: string; readonly skills: ReadonlyArray<LocalSkill> }>;
|
|
64
|
-
}
|
|
65
|
-
export interface FolderPrefs {
|
|
66
|
-
readonly path: string;
|
|
67
|
-
readonly skills: ReadonlyArray<string>;
|
|
68
|
-
}
|
|
69
|
-
export interface FoldersResponse {
|
|
70
|
-
readonly folders: ReadonlyArray<FolderPrefs>;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Whether a name can be a skill's: lowercase letters and digits in hyphen-joined words, at most 64
|
|
75
|
-
* characters, which is what Claude, Codex and Grok accept as a skill name. The daemon checks it before
|
|
76
|
-
* asking, and the service again before writing, so both judge a name by this one rule.
|
|
77
|
-
*/
|
|
78
|
-
export const isSkillName = (name: string): boolean => name.length <= 64 && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name);
|
|
79
|
-
|
|
80
|
-
/** `PUT /skills/<name>`: puts a skill on the synced list. `added` is false when it was already on it. */
|
|
81
|
-
export interface AddSkillResponse {
|
|
82
|
-
readonly added: boolean;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** `GET /skills`: the synced list, as `skill-sync list` shows it. Deleted skills are not on it. */
|
|
86
|
-
export interface ListSkillsResponse {
|
|
87
|
-
readonly skills: ReadonlyArray<ListedSkill>;
|
|
88
|
-
}
|
|
89
|
-
export interface ListedSkill {
|
|
90
|
-
readonly name: string;
|
|
91
|
-
/** Live files on the server; zero for a skill ticked before any machine has pushed it. */
|
|
92
|
-
readonly files: number;
|
|
93
|
-
/** The latest edit of any of its files, and the display name of the machine it came from; null with no files. */
|
|
94
|
-
readonly editedAt: number | null;
|
|
95
|
-
readonly editedBy: string | null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* The header a daemon names its own version in when it opens its WebSocket to the hub, so the dashboard
|
|
100
|
-
* can show which version each machine runs. Daemons before 0.4.6 do not send it.
|
|
101
|
-
*/
|
|
102
|
-
export const DAEMON_VERSION_HEADER = "x-skill-sync-version";
|
|
103
|
-
|
|
104
|
-
/** One usage limit of an account: how much of it is used and when it starts over. */
|
|
105
|
-
export interface UsageWindow {
|
|
106
|
-
/**
|
|
107
|
-
* The limit's name, the same for every tool and machine so the dashboard gives each one a column:
|
|
108
|
-
* `5-hour`, `weekly`, or a limit on one model, such as `weekly Fable`.
|
|
109
|
-
*/
|
|
110
|
-
readonly name: string;
|
|
111
|
-
/** How long the window is, in minutes (300 for five hours, 10080 for a week); null when the tool does not say. */
|
|
112
|
-
readonly minutes: number | null;
|
|
113
|
-
/** Percent of the limit used, from 0 to 100. */
|
|
114
|
-
readonly usedPercent: number;
|
|
115
|
-
/** When the window starts over, in milliseconds since the epoch; null when no window is running. */
|
|
116
|
-
readonly resetsAt: number | null;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** Money as the tool records it: an amount in the currency's smallest unit, so 1234 with exponent 2 is 12.34. */
|
|
120
|
-
export interface Money {
|
|
121
|
-
readonly amountMinor: number;
|
|
122
|
-
readonly currency: string;
|
|
123
|
-
readonly exponent: number;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Which account a tool is signed in to, as its own CLI reports it (`claude auth status`, Codex's
|
|
128
|
-
* `account/read`). The same account signed in on several machines has the same `id`, so the dashboard
|
|
129
|
-
* shows it once.
|
|
130
|
-
*/
|
|
131
|
-
export interface AccountIdentity {
|
|
132
|
-
/** Claude's organization id; Codex's email. */
|
|
133
|
-
readonly id: string;
|
|
134
|
-
/** The email the account is signed in with. */
|
|
135
|
-
readonly email: string;
|
|
136
|
-
/** The plan as the tool names it (`max`, `pro`); null when it does not say. */
|
|
137
|
-
readonly plan: string | null;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* The account's plan limits, which its provider counts across every machine it is used on.
|
|
142
|
-
*
|
|
143
|
-
* `reading`: `asOf` is when they were read. `source` says from where: `account` when the tool's CLI fetched
|
|
144
|
-
* them from its service for this reading (`claude /usage`, Codex's `account/rateLimits/read`), `saved`
|
|
145
|
-
* when the CLI could not be run and they come from the tool's own record of its last fetch, which is as
|
|
146
|
-
* old as the tool's last use of the account. `none`: the account has no plan limits, or the tool offers
|
|
147
|
-
* no way to read them; `reason` says which. `unknown`: reading them failed; `reason` says why.
|
|
148
|
-
*/
|
|
149
|
-
export type AccountLimits =
|
|
150
|
-
| {
|
|
151
|
-
readonly state: "reading";
|
|
152
|
-
readonly asOf: number;
|
|
153
|
-
readonly source: "account" | "saved";
|
|
154
|
-
/** With `saved`: why the CLI was not asked, or failed. */
|
|
155
|
-
readonly cliFailure?: string;
|
|
156
|
-
readonly windows: ReadonlyArray<UsageWindow>;
|
|
157
|
-
/** Spent beyond the plan, when the account pays for usage past its limits; absent when it does not. */
|
|
158
|
-
readonly spent?: { readonly used: Money; readonly limit: Money | null };
|
|
159
|
-
}
|
|
160
|
-
| { readonly state: "none"; readonly reason: string }
|
|
161
|
-
| { readonly state: "unknown"; readonly reason: string };
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* What this machine's sessions of the account used over the last `periodDays` days, read from the files
|
|
165
|
-
* the tool writes on this machine. Other machines' use of the same account is not in it.
|
|
166
|
-
*
|
|
167
|
-
* `spend`: the sum of the tool's own cost figure for each session: Claude Code's estimate at list price,
|
|
168
|
-
* which it saves when a session ends, is cleared, resumed or forked, so a running session counts as of
|
|
169
|
-
* its last save; Grok's, from `grok usage`. `tokens`: the tokens Codex counted, cached input included.
|
|
170
|
-
*/
|
|
171
|
-
export type LocalUse =
|
|
172
|
-
| {
|
|
173
|
-
readonly state: "spend";
|
|
174
|
-
/** When the newest session counted was last active. */
|
|
175
|
-
readonly asOf: number;
|
|
176
|
-
readonly periodDays: number;
|
|
177
|
-
readonly spent: Money;
|
|
178
|
-
readonly sessions: number;
|
|
179
|
-
/** Claude Code could not price a model in at least one session, so the true cost is higher. */
|
|
180
|
-
readonly partial: boolean;
|
|
181
|
-
/** `bedrock` when the account's settings or the model IDs its sessions used say so; null when nothing says. */
|
|
182
|
-
readonly provider: "bedrock" | null;
|
|
183
|
-
}
|
|
184
|
-
| { readonly state: "tokens"; readonly periodDays: number; readonly count: number; readonly sessions: number }
|
|
185
|
-
| { readonly state: "none" }
|
|
186
|
-
| { readonly state: "unknown"; readonly reason: string };
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* One Claude, Codex or Grok account on a machine. Never a credential: the CLIs make the authenticated
|
|
190
|
-
* calls, and only these numbers and the account's email leave the machine.
|
|
191
|
-
*/
|
|
192
|
-
export interface AccountUsage {
|
|
193
|
-
readonly tool: "claude" | "codex" | "grok";
|
|
194
|
-
/** The account's folder in the home directory, such as `.claude-work` or `.codex`. */
|
|
195
|
-
readonly home: string;
|
|
196
|
-
/** Null when the tool is signed out, or cannot say who is signed in (Grok). */
|
|
197
|
-
readonly identity: AccountIdentity | null;
|
|
198
|
-
readonly limits: AccountLimits;
|
|
199
|
-
readonly local: LocalUse;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/** Daemon → hub, over the daemon's WebSocket. */
|
|
203
|
-
export type DaemonMessage =
|
|
204
|
-
| {
|
|
205
|
-
readonly type: "status";
|
|
206
|
-
readonly folder: string;
|
|
207
|
-
readonly state: FolderState;
|
|
208
|
-
readonly detail?: string;
|
|
209
|
-
/** A one-line summary of what the last cycle changed, when it changed anything. */
|
|
210
|
-
readonly activity?: string;
|
|
211
|
-
}
|
|
212
|
-
/** Every account on the machine, sent on connecting and whenever a number changes. The hub drops entries in the shape daemons before 0.5.0 sent. */
|
|
213
|
-
| { readonly type: "usage"; readonly accounts: ReadonlyArray<AccountUsage> };
|
|
214
|
-
|
|
215
|
-
/** Hub → daemon. `prefs` replaces what syncs; `changed` means another write landed on the server. */
|
|
216
|
-
export type HubToDaemon =
|
|
217
|
-
| { readonly type: "prefs"; readonly folders: ReadonlyArray<FolderPrefs> }
|
|
218
|
-
| { readonly type: "changed" };
|
|
219
|
-
|
|
220
|
-
export interface SkillView {
|
|
221
|
-
readonly name: string;
|
|
222
|
-
/** On the list of synced skills, which every enabled folder sends and receives. */
|
|
223
|
-
readonly synced: boolean;
|
|
224
|
-
/** The folder has a copy on disk. */
|
|
225
|
-
readonly local: boolean;
|
|
226
|
-
readonly files: ReadonlyArray<FileHash>;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export interface FolderView {
|
|
230
|
-
readonly path: string;
|
|
231
|
-
readonly enabled: boolean;
|
|
232
|
-
readonly state: FolderState;
|
|
233
|
-
readonly detail: string | null;
|
|
234
|
-
readonly lastActivityAt: number | null;
|
|
235
|
-
readonly lastActivity: string | null;
|
|
236
|
-
readonly skills: ReadonlyArray<SkillView>;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export interface MachineView {
|
|
240
|
-
/** The name the machine's daemon uses; it identifies the machine and never changes. */
|
|
241
|
-
readonly machine: string;
|
|
242
|
-
/** What the dashboard calls it: renamed there, or the machine name until then. */
|
|
243
|
-
readonly name: string;
|
|
244
|
-
/** True while this machine's daemon holds a connection to the hub. */
|
|
245
|
-
readonly online: boolean;
|
|
246
|
-
/** The version its connected daemon runs; null while offline, or when the daemon is too old to say. */
|
|
247
|
-
readonly daemonVersion: string | null;
|
|
248
|
-
/** Each account's usage as its connected daemon last sent it; empty while offline, or from a daemon before 0.5.0. */
|
|
249
|
-
readonly accounts: ReadonlyArray<AccountUsage>;
|
|
250
|
-
readonly lastSeen: number | null;
|
|
251
|
-
readonly folders: ReadonlyArray<FolderView>;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/** A skill on the synced list, as the server holds it: the version every enabled folder converges on. */
|
|
255
|
-
export interface SyncedSkill {
|
|
256
|
-
readonly name: string;
|
|
257
|
-
readonly files: ReadonlyArray<FileHash & { readonly updatedBy: string; readonly editedAt: number }>;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/** Hub → dashboard: the whole picture, resent on every change. It is small, and a diff protocol is not. */
|
|
261
|
-
export interface Snapshot {
|
|
262
|
-
readonly type: "snapshot";
|
|
263
|
-
/** The deployed service version. A dashboard built by another version reloads itself. */
|
|
264
|
-
readonly version: string;
|
|
265
|
-
/** The `latest` version of this package on npm, which every daemon upgrades to; null if npm could not be reached. */
|
|
266
|
-
readonly publishedVersion: string | null;
|
|
267
|
-
/** Display name for every machine name that appears anywhere in the snapshot, including old log entries. */
|
|
268
|
-
readonly names: Readonly<Record<string, string>>;
|
|
269
|
-
readonly skills: ReadonlyArray<SyncedSkill>;
|
|
270
|
-
readonly machines: ReadonlyArray<MachineView>;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/** Dashboard → hub. */
|
|
274
|
-
export type DashboardMessage =
|
|
275
|
-
| { readonly type: "setFolder"; readonly machine: string; readonly path: string; readonly enabled: boolean }
|
|
276
|
-
/** Adds a skill to the synced list, or removes it: one list for every machine and folder. */
|
|
277
|
-
| { readonly type: "setSkill"; readonly skill: string; readonly synced: boolean }
|
|
278
|
-
/** An empty name restores the machine name. */
|
|
279
|
-
| { readonly type: "renameMachine"; readonly machine: string; readonly name: string };
|