@jive-sh/skill-sync 0.8.1 → 0.8.2-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 -45
- package/README.md +0 -205
- package/bin/package.json +0 -1
- package/bin/skill-sync +0 -34
- package/bin/skill-sync-daemon +0 -34
- package/dist/daemons/skill-sync-daemon.js +0 -640
- package/dist/daemons/skill-sync-daemon.js.map +0 -1
- package/dist/entrypoints/skill-sync.js +0 -7
- 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 -102
- package/dist/internal/agents/agent-tool.js.map +0 -1
- package/dist/internal/agents/claude.js +0 -424
- package/dist/internal/agents/claude.js.map +0 -1
- package/dist/internal/agents/codex.js +0 -270
- package/dist/internal/agents/codex.js.map +0 -1
- package/dist/internal/agents/command.js +0 -219
- package/dist/internal/agents/command.js.map +0 -1
- package/dist/internal/agents/grok.js +0 -170
- 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/cli.js +0 -185
- package/dist/internal/cli.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 -113
- package/dist/internal/control.js.map +0 -1
- package/dist/internal/daemon-control/impl.js +0 -68
- package/dist/internal/daemon-control/impl.js.map +0 -1
- package/dist/internal/daemon-control/interface.js +0 -4
- package/dist/internal/daemon-control/interface.js.map +0 -1
- package/dist/internal/folders.js +0 -47
- package/dist/internal/folders.js.map +0 -1
- package/dist/internal/local-skills.js +0 -43
- package/dist/internal/local-skills.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 -80
- 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/skill-refinement/evals/cases.js +0 -143
- package/dist/internal/skill-refinement/evals/cases.js.map +0 -1
- package/dist/internal/skill-refinement/evals/opus-action-judge-original.json +0 -350
- package/dist/internal/skill-refinement/evals/opus-judge-original.json +0 -165
- package/dist/internal/skill-refinement/feedback/intake.js +0 -52
- package/dist/internal/skill-refinement/feedback/intake.js.map +0 -1
- package/dist/internal/skill-refinement/jev/impl.js +0 -63
- package/dist/internal/skill-refinement/jev/impl.js.map +0 -1
- package/dist/internal/skill-refinement/jev/interface.js +0 -6
- package/dist/internal/skill-refinement/jev/interface.js.map +0 -1
- package/dist/internal/skill-refinement/paths.js +0 -62
- package/dist/internal/skill-refinement/paths.js.map +0 -1
- package/dist/internal/skill-refinement/platform.js +0 -67
- package/dist/internal/skill-refinement/platform.js.map +0 -1
- package/dist/internal/skill-refinement/service.js +0 -255
- package/dist/internal/skill-refinement/service.js.map +0 -1
- package/dist/internal/skill-refinement/skills/skill-text.js +0 -217
- package/dist/internal/skill-refinement/skills/skill-text.js.map +0 -1
- package/dist/internal/skill-refinement/workflow/retry.js +0 -69
- package/dist/internal/skill-refinement/workflow/retry.js.map +0 -1
- package/dist/internal/skill-refinement/workflow/skill-refinement.js +0 -595
- package/dist/internal/skill-refinement/workflow/skill-refinement.js.map +0 -1
- package/dist/internal/skill-refinement/writer/impl.js +0 -74
- package/dist/internal/skill-refinement/writer/impl.js.map +0 -1
- package/dist/internal/skill-refinement/writer/interface.js +0 -6
- package/dist/internal/skill-refinement/writer/interface.js.map +0 -1
- package/dist/internal/sync.js +0 -182
- package/dist/internal/sync.js.map +0 -1
- package/dist/internal/wire.js +0 -31
- package/dist/internal/wire.js.map +0 -1
- package/postinstall.cjs +0 -663
- package/src/daemons/skill-sync-daemon.ts +0 -645
- package/src/entrypoints/skill-sync.ts +0 -12
- package/src/index.ts +0 -15
- package/src/internal/agents/agent-tool.ts +0 -149
- package/src/internal/agents/claude.ts +0 -442
- package/src/internal/agents/codex.ts +0 -288
- package/src/internal/agents/command.ts +0 -257
- package/src/internal/agents/grok.ts +0 -174
- package/src/internal/agents/index.ts +0 -74
- package/src/internal/cli.ts +0 -217
- package/src/internal/config.ts +0 -172
- package/src/internal/control.ts +0 -157
- package/src/internal/daemon-control/impl.ts +0 -80
- package/src/internal/daemon-control/interface.ts +0 -40
- package/src/internal/folders.ts +0 -50
- package/src/internal/local-skills.ts +0 -58
- package/src/internal/path.ts +0 -32
- package/src/internal/server.ts +0 -76
- package/src/internal/skill-check.ts +0 -97
- package/src/internal/skill-refinement/evals/cases.ts +0 -167
- package/src/internal/skill-refinement/evals/opus-action-judge-original.json +0 -350
- package/src/internal/skill-refinement/evals/opus-judge-original.json +0 -165
- package/src/internal/skill-refinement/feedback/intake.ts +0 -66
- package/src/internal/skill-refinement/jev/impl.ts +0 -76
- package/src/internal/skill-refinement/jev/interface.ts +0 -56
- package/src/internal/skill-refinement/paths.ts +0 -87
- package/src/internal/skill-refinement/platform.ts +0 -71
- package/src/internal/skill-refinement/service.ts +0 -301
- package/src/internal/skill-refinement/skills/skill-text.ts +0 -290
- package/src/internal/skill-refinement/workflow/retry.ts +0 -76
- package/src/internal/skill-refinement/workflow/skill-refinement.ts +0 -667
- package/src/internal/skill-refinement/writer/impl.ts +0 -86
- package/src/internal/skill-refinement/writer/interface.ts +0 -34
- package/src/internal/sync.ts +0 -216
- package/src/internal/wire.ts +0 -439
package/src/internal/control.ts
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { createConnection, createServer, type Server, type Socket } from "node:net";
|
|
2
|
-
import { chmodSync, rmSync } from "node:fs";
|
|
3
|
-
import { Cause, Data, Effect, Queue, Stream } from "effect";
|
|
4
|
-
import { CONTROL_SOCKET } from "./config";
|
|
5
|
-
import type { ListedSkill } from "./wire";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The channel between the CLI and the running daemon.
|
|
9
|
-
*
|
|
10
|
-
* The daemon owns the sync token: it claims it from the server once a passkey approves its sign-in, and keeps it in `~/.jive/`, so it never
|
|
11
|
-
* passes through the CLI. The CLI's `login`, `logout`, `list` and `add` are requests to the daemon over this
|
|
12
|
-
* channel. Messages are newline-delimited JSON; each request gets events until one that
|
|
13
|
-
* ends it.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
export type ControlRequest =
|
|
17
|
-
| { readonly type: "login" }
|
|
18
|
-
| { readonly type: "logout" }
|
|
19
|
-
/** The synced list, which the daemon fetches from the server with its token. */
|
|
20
|
-
| { readonly type: "list" }
|
|
21
|
-
/** Puts a skill on this machine on the synced list, after checking its files (`checkSkillToAdd`). */
|
|
22
|
-
| { readonly type: "add"; readonly skill: string }
|
|
23
|
-
/** Hands one feedback item to this machine's skill refinement workflow: a few words naming it, and its text. */
|
|
24
|
-
| { readonly type: "feedback"; readonly slug: string; readonly text: string };
|
|
25
|
-
|
|
26
|
-
export type ControlEvent =
|
|
27
|
-
/** Sign-in has started: the page that approves it with a passkey, from a browser on this computer or any other. */
|
|
28
|
-
| { readonly type: "open"; readonly url: string }
|
|
29
|
-
| { readonly type: "signedIn"; readonly machine: string }
|
|
30
|
-
| { readonly type: "signedOut"; readonly revoked: boolean }
|
|
31
|
-
| { readonly type: "list"; readonly skills: ReadonlyArray<ListedSkill> }
|
|
32
|
-
/**
|
|
33
|
-
* The skill is on the synced list. `added` is false when it already was. `folders` are this machine's
|
|
34
|
-
* folders that hold it; `syncingFolders` are those ticked on the dashboard, which upload it.
|
|
35
|
-
*/
|
|
36
|
-
| {
|
|
37
|
-
readonly type: "added";
|
|
38
|
-
readonly skill: string;
|
|
39
|
-
readonly added: boolean;
|
|
40
|
-
readonly folders: ReadonlyArray<string>;
|
|
41
|
-
readonly syncingFolders: ReadonlyArray<string>;
|
|
42
|
-
}
|
|
43
|
-
/** The item is in the workflow's intake, under this id. */
|
|
44
|
-
| { readonly type: "feedbackAdded"; readonly id: string }
|
|
45
|
-
| { readonly type: "error"; readonly message: string };
|
|
46
|
-
|
|
47
|
-
const isFinal = (event: ControlEvent): boolean => event.type !== "open";
|
|
48
|
-
|
|
49
|
-
/** No daemon is listening on the control socket: it is stopped, or has not started since the install. */
|
|
50
|
-
export class DaemonNotRunning extends Data.TaggedError("DaemonNotRunning")<{ readonly message: string }> {}
|
|
51
|
-
|
|
52
|
-
/** The daemon is running but the request failed: it refused it, answered nonsense, or hung up. */
|
|
53
|
-
export class DaemonFailed extends Data.TaggedError("DaemonFailed")<{ readonly message: string }> {}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Sends one request and streams the daemon's events, ending after the final one. The socket is closed when the
|
|
57
|
-
* stream ends or is interrupted, so a caller that stops waiting (a time limit on Tab) leaves nothing open.
|
|
58
|
-
*/
|
|
59
|
-
export function requestEvents(message: ControlRequest): Stream.Stream<ControlEvent, DaemonNotRunning | DaemonFailed> {
|
|
60
|
-
return Stream.callback<ControlEvent, DaemonNotRunning | DaemonFailed>((queue) => Effect.acquireRelease(
|
|
61
|
-
Effect.sync(() => {
|
|
62
|
-
let settled = false;
|
|
63
|
-
const fail = (error: DaemonNotRunning | DaemonFailed) => {
|
|
64
|
-
if (settled) return;
|
|
65
|
-
settled = true;
|
|
66
|
-
Queue.failCauseUnsafe(queue, Cause.fail(error));
|
|
67
|
-
};
|
|
68
|
-
const socket = createConnection(CONTROL_SOCKET);
|
|
69
|
-
socket.on("connect", () => socket.write(`${JSON.stringify(message)}\n`));
|
|
70
|
-
socket.on("error", (cause: NodeJS.ErrnoException) => fail(cause.code === "ENOENT" || cause.code === "ECONNREFUSED"
|
|
71
|
-
? new DaemonNotRunning({ message: `the skill-sync daemon is not running (${cause.code} on ${CONTROL_SOCKET})` })
|
|
72
|
-
: new DaemonFailed({ message: cause.message })));
|
|
73
|
-
readLines(socket, (line) => {
|
|
74
|
-
if (settled) return;
|
|
75
|
-
let event: ControlEvent;
|
|
76
|
-
try {
|
|
77
|
-
event = JSON.parse(line) as ControlEvent;
|
|
78
|
-
} catch {
|
|
79
|
-
return fail(new DaemonFailed({ message: `unexpected answer from the daemon: ${line}` }));
|
|
80
|
-
}
|
|
81
|
-
Queue.offerUnsafe(queue, event);
|
|
82
|
-
if (isFinal(event)) {
|
|
83
|
-
settled = true;
|
|
84
|
-
socket.end();
|
|
85
|
-
Queue.endUnsafe(queue);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
socket.on("close", () => fail(new DaemonFailed({ message: "the daemon closed the connection without answering" })));
|
|
89
|
-
return socket;
|
|
90
|
-
}),
|
|
91
|
-
(socket) => Effect.sync(() => socket.destroy()),
|
|
92
|
-
));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** One request being answered: send events, and end the conversation with a final one. */
|
|
96
|
-
export interface Reply {
|
|
97
|
-
readonly send: (event: ControlEvent) => void;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Listens on the control socket. Resolves false, without listening, when another live daemon already
|
|
102
|
-
* holds it: two installs of skill-sync mean two daemons, and the second stands down rather than fight.
|
|
103
|
-
*/
|
|
104
|
-
export async function serve(handle: (message: ControlRequest, reply: Reply) => void): Promise<Server | false> {
|
|
105
|
-
if (await answers()) return false;
|
|
106
|
-
// Nothing answered, so a socket file left here is from a daemon that died; it would block the listen.
|
|
107
|
-
if (process.platform !== "win32") rmSync(CONTROL_SOCKET, { force: true });
|
|
108
|
-
|
|
109
|
-
const server = createServer((socket) => {
|
|
110
|
-
const reply: Reply = {
|
|
111
|
-
send: (event) => {
|
|
112
|
-
if (socket.writable) socket.write(`${JSON.stringify(event)}\n`);
|
|
113
|
-
if (isFinal(event)) socket.end();
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
readLines(socket, (line) => {
|
|
117
|
-
try {
|
|
118
|
-
handle(JSON.parse(line) as ControlRequest, reply);
|
|
119
|
-
} catch (cause) {
|
|
120
|
-
reply.send({ type: "error", message: cause instanceof Error ? cause.message : String(cause) });
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
socket.on("error", () => undefined); // A CLI that went away mid-request; nothing to tell it.
|
|
124
|
-
});
|
|
125
|
-
await new Promise<void>((resolve, reject) => {
|
|
126
|
-
server.once("error", reject);
|
|
127
|
-
server.listen(CONTROL_SOCKET, () => resolve());
|
|
128
|
-
});
|
|
129
|
-
// Only this user may talk to the daemon that holds their token.
|
|
130
|
-
if (process.platform !== "win32") chmodSync(CONTROL_SOCKET, 0o600);
|
|
131
|
-
return server;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/** Whether a live daemon is listening on the control socket. */
|
|
135
|
-
function answers(): Promise<boolean> {
|
|
136
|
-
return new Promise((resolve) => {
|
|
137
|
-
const socket = createConnection(CONTROL_SOCKET);
|
|
138
|
-
socket.on("connect", () => {
|
|
139
|
-
socket.end();
|
|
140
|
-
resolve(true);
|
|
141
|
-
});
|
|
142
|
-
socket.on("error", () => resolve(false));
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function readLines(socket: Socket, onLine: (line: string) => void): void {
|
|
147
|
-
let buffer = "";
|
|
148
|
-
socket.on("data", (chunk) => {
|
|
149
|
-
buffer += chunk.toString();
|
|
150
|
-
let newline: number;
|
|
151
|
-
while ((newline = buffer.indexOf("\n")) >= 0) {
|
|
152
|
-
const line = buffer.slice(0, newline).trim();
|
|
153
|
-
buffer = buffer.slice(newline + 1);
|
|
154
|
-
if (line !== "") onLine(line);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { Effect, Layer, Option, Stream, pipe } from "effect";
|
|
3
|
-
import { daemonStatuses } from "jive-abstract-library";
|
|
4
|
-
import { name } from "../../../package.json";
|
|
5
|
-
import { DaemonFailed, requestEvents, type ControlEvent, type ControlRequest } from "../control";
|
|
6
|
-
import type { ListedSkill } from "../wire";
|
|
7
|
-
import { DaemonControl, type AddedSkill, type DaemonError, type IDaemonControl } from "./interface";
|
|
8
|
-
|
|
9
|
-
class DaemonControlImpl implements IDaemonControl {
|
|
10
|
-
*login(openSignInPage: (url: string) => Effect.Effect<void>): Effect.fn.Return<string, DaemonError> {
|
|
11
|
-
const event = yield* finalEvent({ type: "login" }, (event) => event.type === "open" ? openSignInPage(event.url) : Effect.void);
|
|
12
|
-
if (event.type !== "signedIn") return yield* unexpected(event);
|
|
13
|
-
return event.machine;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
*logout(): Effect.fn.Return<boolean, DaemonError> {
|
|
17
|
-
const event = yield* finalEvent({ type: "logout" });
|
|
18
|
-
if (event.type !== "signedOut") return yield* unexpected(event);
|
|
19
|
-
return event.revoked;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
*listSyncedSkills(): Effect.fn.Return<ReadonlyArray<ListedSkill>, DaemonError> {
|
|
23
|
-
const event = yield* finalEvent({ type: "list" });
|
|
24
|
-
if (event.type !== "list") return yield* unexpected(event);
|
|
25
|
-
return event.skills;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
*addSkill(skill: string): Effect.fn.Return<AddedSkill, DaemonError> {
|
|
29
|
-
const event = yield* finalEvent({ type: "add", skill });
|
|
30
|
-
if (event.type !== "added") return yield* unexpected(event);
|
|
31
|
-
return { added: event.added, folders: event.folders, syncingFolders: event.syncingFolders };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
*addFeedback(item: { readonly slug: string; readonly text: string }): Effect.fn.Return<string, DaemonError> {
|
|
35
|
-
const event = yield* finalEvent({ type: "feedback", slug: item.slug, text: item.text });
|
|
36
|
-
if (event.type !== "feedbackAdded") return yield* unexpected(event);
|
|
37
|
-
return event.id;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
*startDaemon(): Effect.fn.Return<void> {
|
|
41
|
-
const statuses = yield* pipe(daemonStatuses, Effect.catch(() => Effect.succeed([])));
|
|
42
|
-
const ours = statuses.filter((status) => status.registration.packageName === name && status.executableExists);
|
|
43
|
-
for (const { registration } of ours) {
|
|
44
|
-
const command: string[] = registration.kind === "launchd"
|
|
45
|
-
? ["launchctl", "kickstart", "-k", `gui/${process.getuid?.() ?? 0}/${registration.unit}`]
|
|
46
|
-
: registration.kind === "systemd"
|
|
47
|
-
? ["systemctl", "--user", "restart", registration.unit]
|
|
48
|
-
: ["schtasks", "/Run", "/TN", registration.unit];
|
|
49
|
-
const result = yield* Effect.sync(() => spawnSync(command[0]!, command.slice(1), { stdio: ["ignore", "ignore", "pipe"] }));
|
|
50
|
-
if (result.status !== 0) {
|
|
51
|
-
yield* Effect.logError(`Could not start ${registration.unit}: ${String(result.stderr ?? "").trim() || `exit ${result.status}`}`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** The event that ends the conversation, after handing each earlier one (only `open`, during login) to `onEvent`. */
|
|
58
|
-
function finalEvent(
|
|
59
|
-
message: ControlRequest,
|
|
60
|
-
onEvent: (event: ControlEvent) => Effect.Effect<void> = () => Effect.void,
|
|
61
|
-
): Effect.Effect<ControlEvent, DaemonError> {
|
|
62
|
-
return pipe(
|
|
63
|
-
requestEvents(message),
|
|
64
|
-
Stream.tap(onEvent),
|
|
65
|
-
Stream.runLast,
|
|
66
|
-
Effect.flatMap(Option.match({
|
|
67
|
-
onNone: () => Effect.fail(new DaemonFailed({ message: "the daemon closed the connection without answering" })),
|
|
68
|
-
onSome: (event) => Effect.succeed(event),
|
|
69
|
-
})),
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** An `error` event is the daemon refusing the request; anything else is an answer to a different request. */
|
|
74
|
-
function unexpected(event: ControlEvent): Effect.Effect<never, DaemonFailed> {
|
|
75
|
-
return Effect.fail(new DaemonFailed({
|
|
76
|
-
message: event.type === "error" ? event.message : `unexpected answer from the daemon: ${JSON.stringify(event)}`,
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export const DaemonControlLive = Layer.succeed(DaemonControl, new DaemonControlImpl());
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Context, type Effect } from "effect";
|
|
2
|
-
import type { DaemonFailed, DaemonNotRunning } from "../control";
|
|
3
|
-
import type { ListedSkill } from "../wire";
|
|
4
|
-
|
|
5
|
-
export type DaemonError = DaemonNotRunning | DaemonFailed;
|
|
6
|
-
|
|
7
|
-
/** What `addSkill` did; see the `added` event in `control.ts`. */
|
|
8
|
-
export interface AddedSkill {
|
|
9
|
-
/** False when the skill was already on the synced list. */
|
|
10
|
-
readonly added: boolean;
|
|
11
|
-
/** This machine's folders that hold the skill. */
|
|
12
|
-
readonly folders: ReadonlyArray<string>;
|
|
13
|
-
/** Those of them ticked on the dashboard, which upload it. */
|
|
14
|
-
readonly syncingFolders: ReadonlyArray<string>;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* What the CLI asks of the running daemon, which owns the sync token, so every request that needs the token goes
|
|
19
|
-
* through it. Every method fails with `DaemonNotRunning` when no daemon listens; none starts one by itself, so Tab
|
|
20
|
-
* completion can ask without waiting for a daemon to start.
|
|
21
|
-
*/
|
|
22
|
-
export interface IDaemonControl {
|
|
23
|
-
/**
|
|
24
|
-
* Signs this machine in. `openSignInPage` is given the page where a passkey approves the sign-in, on this computer or
|
|
25
|
-
* any other, and the method returns the machine's name once the daemon has claimed its token.
|
|
26
|
-
*/
|
|
27
|
-
login(openSignInPage: (url: string) => Effect.Effect<void>): Effect.fn.Return<string, DaemonError>;
|
|
28
|
-
/** Signs this machine out; returns whether the server revoked the token. */
|
|
29
|
-
logout(): Effect.fn.Return<boolean, DaemonError>;
|
|
30
|
-
/** The synced list, as the server holds it. */
|
|
31
|
-
listSyncedSkills(): Effect.fn.Return<ReadonlyArray<ListedSkill>, DaemonError>;
|
|
32
|
-
/** Puts a skill on this machine on the synced list, once the daemon has checked its files. */
|
|
33
|
-
addSkill(skill: string): Effect.fn.Return<AddedSkill, DaemonError>;
|
|
34
|
-
/** Hands one feedback item to this machine's skill refinement workflow; returns its id in the intake. */
|
|
35
|
-
addFeedback(item: { readonly slug: string; readonly text: string }): Effect.fn.Return<string, DaemonError>;
|
|
36
|
-
/** Starts this package's registered daemon through its service manager (launchd, systemd or Task Scheduler). */
|
|
37
|
-
startDaemon(): Effect.fn.Return<void>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export class DaemonControl extends Context.Service<DaemonControl, IDaemonControl>()("DaemonControl") {}
|
package/src/internal/folders.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { detectFolders } from "./agents";
|
|
4
|
-
import { hashBytes, listLocalFiles, type Config } from "./config";
|
|
5
|
-
import { fetchServer } from "./server";
|
|
6
|
-
import {
|
|
7
|
-
skillOf, type FileHash, type FolderPrefs, type FoldersRequest, type FoldersResponse, type LocalSkill,
|
|
8
|
-
} from "./wire";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* What this machine tells the service about its folders, and what it hears back.
|
|
12
|
-
*
|
|
13
|
-
* The daemon and the CLI both register, so this lives in one place: they must describe a folder the same
|
|
14
|
-
* way, or the dashboard would show whichever of them spoke last.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The skills on disk in one folder, with each file's hash. Hashing every file on each check is cheap at
|
|
19
|
-
* skills' size, and it is what lets the dashboard show whether this folder's copy is the synced one.
|
|
20
|
-
*/
|
|
21
|
-
export function localSkills(folder: string, config: Config): LocalSkill[] {
|
|
22
|
-
const byName = new Map<string, FileHash[]>();
|
|
23
|
-
for (const path of listLocalFiles(folder, config.exclude)) {
|
|
24
|
-
const name = skillOf(path);
|
|
25
|
-
let hash: string;
|
|
26
|
-
try {
|
|
27
|
-
hash = hashBytes(readFileSync(join(folder, path)));
|
|
28
|
-
} catch {
|
|
29
|
-
continue; // Deleted between listing and reading; the next check reports the folder as it is.
|
|
30
|
-
}
|
|
31
|
-
byName.set(name, [...(byName.get(name) ?? []), { path, hash }]);
|
|
32
|
-
}
|
|
33
|
-
return [...byName].map(([name, files]) => ({ name, files }));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Everything registration sends, so a caller can tell when it has changed and is worth re-sending. */
|
|
37
|
-
export function describe(config: Config): FoldersRequest {
|
|
38
|
-
return { folders: detectFolders().map((path) => ({ path, skills: localSkills(path, config) })) };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Registers this machine's folders and skills; returns the folders to sync and the skills in each. */
|
|
42
|
-
export async function register(config: Config, request: FoldersRequest): Promise<ReadonlyArray<FolderPrefs>> {
|
|
43
|
-
const response = await fetchServer(config, "/folders", {
|
|
44
|
-
method: "POST",
|
|
45
|
-
headers: { "content-type": "application/json" },
|
|
46
|
-
body: JSON.stringify(request),
|
|
47
|
-
});
|
|
48
|
-
if (!response.ok) throw new Error(`POST /folders: ${response.status} ${await response.text()}`);
|
|
49
|
-
return (await response.json() as FoldersResponse).folders;
|
|
50
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { Option } from "effect";
|
|
4
|
-
import { isLock } from "./config";
|
|
5
|
-
import { checkSkillToAdd, readFrontmatter } from "./skill-check";
|
|
6
|
-
|
|
7
|
-
/** Skills as this machine's detected skills folders hold them, for the CLI's `show` and `add`. */
|
|
8
|
-
|
|
9
|
-
/** One folder's copy of a skill, with the description its `SKILL.md` frontmatter gives. */
|
|
10
|
-
export interface SkillCopy {
|
|
11
|
-
readonly path: string;
|
|
12
|
-
readonly description: Option.Option<string>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Every copy of `skill` in `folders`, in the order of `folders`. */
|
|
16
|
-
export function skillCopies(input: { readonly skill: string; readonly folders: ReadonlyArray<string> }): ReadonlyArray<SkillCopy> {
|
|
17
|
-
return input.folders
|
|
18
|
-
.map((folder) => join(folder, input.skill))
|
|
19
|
-
.filter((path) => existsSync(path))
|
|
20
|
-
.map((path) => ({ path, description: readDescription(join(path, "SKILL.md")) }));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* What `skill-sync show` prints: each description above the paths of the copies that have it. Copies agree once
|
|
25
|
-
* synced, so this is usually one description; copies that differ are shown apart rather than one hiding another.
|
|
26
|
-
*/
|
|
27
|
-
export function formatSkillCopies(copies: ReadonlyArray<SkillCopy>): string {
|
|
28
|
-
const byDescription = Map.groupBy(copies, (copy) => Option.getOrElse(copy.description, () => "(its SKILL.md has no description)"));
|
|
29
|
-
return [...byDescription]
|
|
30
|
-
.map(([description, group]) => [description, ...group.map((copy) => ` ${copy.path}`)].join("\n"))
|
|
31
|
-
.join("\n\n");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* The skills in `folders` that are not on the synced list and that `skill-sync add` would accept: the same check
|
|
36
|
-
* the daemon runs before adding (`checkSkillToAdd`), so Tab offers nothing the daemon would refuse.
|
|
37
|
-
*/
|
|
38
|
-
export function addableSkills(input: {
|
|
39
|
-
readonly folders: ReadonlyArray<string>;
|
|
40
|
-
readonly exclude: ReadonlyArray<string>;
|
|
41
|
-
readonly synced: ReadonlyArray<string>;
|
|
42
|
-
}): ReadonlyArray<string> {
|
|
43
|
-
const { folders, exclude, synced } = input;
|
|
44
|
-
const names = new Set(folders.flatMap((folder) => entries(folder).filter((entry) => !entry.startsWith(".") && !isLock(entry))));
|
|
45
|
-
return [...names]
|
|
46
|
-
.filter((skill) => !synced.includes(skill) && checkSkillToAdd({ skill, folders, exclude }).ok)
|
|
47
|
-
.sort();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function readDescription(skillFile: string): Option.Option<string> {
|
|
51
|
-
if (!existsSync(skillFile)) return Option.none();
|
|
52
|
-
const description = readFrontmatter(readFileSync(skillFile, "utf8"))?.get("description");
|
|
53
|
-
return description === undefined || description === "" ? Option.none() : Option.some(description);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function entries(folder: string): ReadonlyArray<string> {
|
|
57
|
-
return existsSync(folder) ? readdirSync(folder) : [];
|
|
58
|
-
}
|
package/src/internal/path.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validation for the one piece of untrusted input that becomes a filesystem path.
|
|
3
|
-
*
|
|
4
|
-
* Shared by the Worker and the daemon on purpose, and deliberately free of any Node import so the Worker
|
|
5
|
-
* can bundle it. Both ends check: the server so one compromised client cannot poison what every machine
|
|
6
|
-
* pulls, and the daemon because a server it does not control is not a thing to take paths from either.
|
|
7
|
-
*
|
|
8
|
-
* Without this, a pushed path of `../../.ssh/authorized_keys` is joined to the skills directory and
|
|
9
|
-
* written wherever the daemon's user can write.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/** Long enough for any real nesting, short enough that nothing can be used to exhaust anything. */
|
|
13
|
-
const MAX_LENGTH = 512;
|
|
14
|
-
|
|
15
|
-
export function invalidPathReason(path: string): string | undefined {
|
|
16
|
-
if (path.length === 0 || path.length > MAX_LENGTH) return "path is empty or too long";
|
|
17
|
-
if (path.includes("\0")) return "path contains a null byte";
|
|
18
|
-
if (path.includes("\\")) return "path must use forward slashes";
|
|
19
|
-
if (path.startsWith("/")) return "path must be relative";
|
|
20
|
-
// A Windows drive letter is absolute on the machine that matters even though it has no leading slash.
|
|
21
|
-
if (/^[A-Za-z]:/.test(path)) return "path must be relative";
|
|
22
|
-
|
|
23
|
-
for (const segment of path.split("/")) {
|
|
24
|
-
if (segment === "") return "path has an empty segment";
|
|
25
|
-
if (segment === "." || segment === "..") return "path must not contain . or .. segments";
|
|
26
|
-
}
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function isValidPath(path: string): boolean {
|
|
31
|
-
return invalidPathReason(path) === undefined;
|
|
32
|
-
}
|
package/src/internal/server.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { Config } from "./config";
|
|
2
|
-
import { MACHINE_HEADER, MACHINE_MISMATCH_STATUS, type MachineMismatch, type SignInClaim, type SignInRequestCreated } from "./wire";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Requests to the skill-sync service, signed with this machine's token.
|
|
6
|
-
*
|
|
7
|
-
* Every request goes through `fetchServer`, so a token the server no longer accepts, or one issued to another
|
|
8
|
-
* machine, is noticed the same way whichever request hits it first.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/** The server answered 401: the token was revoked or is unknown, so no retry with it can succeed. */
|
|
12
|
-
export class TokenRejected extends Error {
|
|
13
|
-
constructor(message: string, readonly token: string) {
|
|
14
|
-
super(message);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* The server answered that the token belongs to `tokenMachine`, not to the machine this one is configured as:
|
|
20
|
-
* most often a token file copied from another computer. No request with it can succeed, and the token is
|
|
21
|
-
* still that other machine's, so it must not be revoked from here.
|
|
22
|
-
*/
|
|
23
|
-
export class TokenOfAnotherMachine extends Error {
|
|
24
|
-
constructor(readonly configuredMachine: string, readonly tokenMachine: string, readonly token: string) {
|
|
25
|
-
super(`this machine is configured as "${configuredMachine}" but its token belongs to "${tokenMachine}"`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function authHeaders(config: Config, extra: Record<string, string>): Record<string, string> {
|
|
30
|
-
return { authorization: `Bearer ${config.token}`, [MACHINE_HEADER]: config.machine, ...extra };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Sends one request to the server with the token. Throws `TokenRejected` on 401 and `TokenOfAnotherMachine` on
|
|
35
|
-
* the service's machine mismatch; every other status is returned for the caller to judge, since some (a 409
|
|
36
|
-
* from `PUT /files`) are answers rather than failures.
|
|
37
|
-
*/
|
|
38
|
-
export async function fetchServer(config: Config, path: string, init: RequestInit = {}): Promise<Response> {
|
|
39
|
-
const response = await fetch(`${config.endpoint}${path}`, {
|
|
40
|
-
...init,
|
|
41
|
-
headers: authHeaders(config, (init.headers ?? {}) as Record<string, string>),
|
|
42
|
-
});
|
|
43
|
-
if (response.status === 401) {
|
|
44
|
-
throw new TokenRejected(`${init.method ?? "GET"} ${path}: the server rejected this machine's token`, config.token);
|
|
45
|
-
}
|
|
46
|
-
if (response.status === MACHINE_MISMATCH_STATUS) {
|
|
47
|
-
const body = await response.clone().json().catch(() => undefined) as Partial<MachineMismatch> | undefined;
|
|
48
|
-
if (typeof body?.tokenMachine === "string") throw new TokenOfAnotherMachine(config.machine, body.tokenMachine, config.token);
|
|
49
|
-
}
|
|
50
|
-
return response;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Opens a request to sign `machine` in. Sent without a token: the machine has none yet. See `SignInRequestCreated`
|
|
55
|
-
* for what comes back and why the claim secret never leaves this process.
|
|
56
|
-
*/
|
|
57
|
-
export async function openSignInRequest(input: { readonly endpoint: string; readonly machine: string }): Promise<SignInRequestCreated> {
|
|
58
|
-
const response = await fetch(`${input.endpoint}/cli/sign-in-requests`, {
|
|
59
|
-
method: "POST",
|
|
60
|
-
headers: { "content-type": "application/json" },
|
|
61
|
-
body: JSON.stringify({ machine: input.machine }),
|
|
62
|
-
});
|
|
63
|
-
if (!response.ok) throw new Error(`POST /cli/sign-in-requests: ${response.status} ${await response.text()}`);
|
|
64
|
-
return await response.json() as SignInRequestCreated;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Asks whether the request was approved; the answer carries the token once it was. */
|
|
68
|
-
export async function claimSignInRequest(input: { readonly endpoint: string; readonly claimSecret: string }): Promise<SignInClaim> {
|
|
69
|
-
const response = await fetch(`${input.endpoint}/cli/sign-in-requests/claim`, {
|
|
70
|
-
method: "POST",
|
|
71
|
-
headers: { "content-type": "application/json" },
|
|
72
|
-
body: JSON.stringify({ claimSecret: input.claimSecret }),
|
|
73
|
-
});
|
|
74
|
-
if (!response.ok) throw new Error(`POST /cli/sign-in-requests/claim: ${response.status} ${await response.text()}`);
|
|
75
|
-
return await response.json() as SignInClaim;
|
|
76
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { isSkillName } from "./wire";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Whether a skill on this machine may go on the synced list, checked before `skill-sync add` asks the
|
|
7
|
-
* server to add it.
|
|
8
|
-
*
|
|
9
|
-
* The synced list is for skills meant for every project. A skill made for one project lives in that
|
|
10
|
-
* project (its `.claude/skills`, `.agents/skills` or `.grok/skills`), which is never one of the folders
|
|
11
|
-
* skill-sync detects, so a skill is accepted only from a detected folder. That is the one sign of a
|
|
12
|
-
* project-specific skill that can be read from disk; a skill written into a home folder but about one
|
|
13
|
-
* project is not caught here.
|
|
14
|
-
*/
|
|
15
|
-
export type SkillCheck =
|
|
16
|
-
| { readonly ok: true; readonly folders: ReadonlyArray<string> }
|
|
17
|
-
| { readonly ok: false; readonly reason: string };
|
|
18
|
-
|
|
19
|
-
export function checkSkillToAdd(input: {
|
|
20
|
-
readonly skill: string;
|
|
21
|
-
/** The skills folders skill-sync detects on this machine (`detectFolders`). */
|
|
22
|
-
readonly folders: ReadonlyArray<string>;
|
|
23
|
-
/** Top-level names skill-sync never syncs (`Settings.exclude`). */
|
|
24
|
-
readonly exclude: ReadonlyArray<string>;
|
|
25
|
-
}): SkillCheck {
|
|
26
|
-
const { skill, folders, exclude } = input;
|
|
27
|
-
if (!isSkillName(skill)) {
|
|
28
|
-
return { ok: false, reason: `"${skill}" is not a skill name: lowercase letters and digits in hyphen-joined words, at most 64 characters` };
|
|
29
|
-
}
|
|
30
|
-
if (exclude.includes(skill)) {
|
|
31
|
-
return { ok: false, reason: `"${skill}" is excluded from syncing in ~/.jive/skill-sync.json` };
|
|
32
|
-
}
|
|
33
|
-
const holding = folders.filter((folder) => isDirectory(join(folder, skill)));
|
|
34
|
-
if (holding.length === 0) {
|
|
35
|
-
return {
|
|
36
|
-
ok: false,
|
|
37
|
-
reason: `no skills folder skill-sync syncs has a "${skill}" folder; it looked in ${folders.join(", ") || "no folders"}. `
|
|
38
|
-
+ "Only skills meant for every project sync: write the skill into one of those folders. A skill inside a "
|
|
39
|
-
+ "project's own skills folder is specific to that project and stays there.",
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
for (const folder of holding) {
|
|
43
|
-
const problem = frontmatterProblem(skill, join(folder, skill, "SKILL.md"));
|
|
44
|
-
if (problem !== undefined) return { ok: false, reason: problem };
|
|
45
|
-
}
|
|
46
|
-
return { ok: true, folders: holding };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Why a skill's `SKILL.md` would not load as that skill, or undefined when it would. */
|
|
50
|
-
function frontmatterProblem(skill: string, path: string): string | undefined {
|
|
51
|
-
if (!existsSync(path)) return `${path} does not exist; every skill needs a SKILL.md`;
|
|
52
|
-
const fields = readFrontmatter(readFileSync(path, "utf8"));
|
|
53
|
-
if (fields === undefined) return `${path} does not start with a frontmatter block between --- lines`;
|
|
54
|
-
const name = fields.get("name");
|
|
55
|
-
if (name === undefined || name === "") return `${path}'s frontmatter has no name`;
|
|
56
|
-
if (name !== skill) return `${path}'s frontmatter name is "${name}", but its folder is "${skill}"; they must match`;
|
|
57
|
-
if ((fields.get("description") ?? "") === "") return `${path}'s frontmatter has no description, which is how agents decide to load it`;
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* The top-level keys of a `SKILL.md`'s frontmatter, with their values as text. Covers what skills use: a
|
|
63
|
-
* plain or quoted value on the key's line, or a block (`>` or `|`) on the indented lines after it.
|
|
64
|
-
*/
|
|
65
|
-
export function readFrontmatter(text: string): Map<string, string> | undefined {
|
|
66
|
-
const lines = text.replace(/^/, "").split(/\r?\n/);
|
|
67
|
-
if (lines[0]?.trim() !== "---") return undefined;
|
|
68
|
-
const end = lines.findIndex((line, index) => index > 0 && line.trim() === "---");
|
|
69
|
-
if (end === -1) return undefined;
|
|
70
|
-
const fields = new Map<string, string>();
|
|
71
|
-
let blockKey: string | undefined;
|
|
72
|
-
for (const line of lines.slice(1, end)) {
|
|
73
|
-
const field = /^([A-Za-z0-9_-]+):\s*(.*)$/.exec(line);
|
|
74
|
-
if (field !== null) {
|
|
75
|
-
const key = field[1]!;
|
|
76
|
-
const raw = field[2]!;
|
|
77
|
-
blockKey = /^[>|][+-]?$/.test(raw.trim()) ? key : undefined;
|
|
78
|
-
fields.set(key, blockKey === undefined ? unquote(raw.trim()) : "");
|
|
79
|
-
} else if (blockKey !== undefined && /^\s+\S/.test(line)) {
|
|
80
|
-
fields.set(blockKey, `${fields.get(blockKey)} ${line.trim()}`.trim());
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return fields;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function unquote(value: string): string {
|
|
87
|
-
const quoted = /^(["'])(.*)\1$/.exec(value);
|
|
88
|
-
return quoted === null ? value : quoted[2]!;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function isDirectory(path: string): boolean {
|
|
92
|
-
try {
|
|
93
|
-
return statSync(path).isDirectory();
|
|
94
|
-
} catch {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
}
|