@jive-sh/skill-sync 0.10.3 → 0.10.4-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 -214
- 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 -642
- 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/import-legacy.js +0 -13
- package/dist/internal/skill-refinement/feedback/import-legacy.js.map +0 -1
- 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/feedback/managed-intake.js +0 -19
- package/dist/internal/skill-refinement/feedback/managed-intake.js.map +0 -1
- package/dist/internal/skill-refinement/feedback/outbox.js +0 -44
- package/dist/internal/skill-refinement/feedback/outbox.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/managed-daemon.js +0 -30
- package/dist/internal/skill-refinement/managed-daemon.js.map +0 -1
- package/dist/internal/skill-refinement/managed-worker-credentials.js +0 -60
- package/dist/internal/skill-refinement/managed-worker-credentials.js.map +0 -1
- package/dist/internal/skill-refinement/managed-worker-files.js +0 -25
- package/dist/internal/skill-refinement/managed-worker-files.js.map +0 -1
- package/dist/internal/skill-refinement/managed-worker-loop.js +0 -36
- package/dist/internal/skill-refinement/managed-worker-loop.js.map +0 -1
- package/dist/internal/skill-refinement/organization-site.js +0 -13
- package/dist/internal/skill-refinement/organization-site.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 -356
- 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 -44
- package/dist/internal/skill-refinement/workflow/retry.js.map +0 -1
- package/dist/internal/skill-refinement/workflow/skill-refinement.js +0 -668
- package/dist/internal/skill-refinement/workflow/skill-refinement.js.map +0 -1
- package/dist/internal/skill-refinement/writer/impl.js +0 -2
- package/dist/internal/skill-refinement/writer/impl.js.map +0 -1
- package/dist/internal/skill-refinement/writer/interface.js +0 -2
- 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/dist/internal/writer/claude.js +0 -84
- package/dist/internal/writer/claude.js.map +0 -1
- package/dist/internal/writer/codex.js +0 -102
- package/dist/internal/writer/codex.js.map +0 -1
- package/dist/internal/writer/interface.js +0 -6
- package/dist/internal/writer/interface.js.map +0 -1
- package/dist/internal/writer/live.js +0 -13
- package/dist/internal/writer/live.js.map +0 -1
- package/dist/internal/writer/reset.js +0 -38
- package/dist/internal/writer/reset.js.map +0 -1
- package/dist/internal/writer/selection.js +0 -79
- package/dist/internal/writer/selection.js.map +0 -1
- package/postinstall.cjs +0 -663
- package/src/daemons/skill-sync-daemon.ts +0 -647
- 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/import-legacy.ts +0 -16
- package/src/internal/skill-refinement/feedback/intake.ts +0 -66
- package/src/internal/skill-refinement/feedback/managed-intake.ts +0 -19
- package/src/internal/skill-refinement/feedback/outbox.ts +0 -50
- 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/managed-daemon.ts +0 -38
- package/src/internal/skill-refinement/managed-worker-credentials.ts +0 -59
- package/src/internal/skill-refinement/managed-worker-files.ts +0 -24
- package/src/internal/skill-refinement/managed-worker-loop.ts +0 -46
- package/src/internal/skill-refinement/organization-site.ts +0 -15
- 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 -413
- package/src/internal/skill-refinement/skills/skill-text.ts +0 -290
- package/src/internal/skill-refinement/workflow/retry.ts +0 -61
- package/src/internal/skill-refinement/workflow/skill-refinement.ts +0 -756
- package/src/internal/skill-refinement/writer/impl.ts +0 -1
- package/src/internal/skill-refinement/writer/interface.ts +0 -1
- package/src/internal/sync.ts +0 -216
- package/src/internal/wire.ts +0 -439
- package/src/internal/writer/claude.ts +0 -98
- package/src/internal/writer/codex.ts +0 -93
- package/src/internal/writer/interface.ts +0 -48
- package/src/internal/writer/live.ts +0 -19
- package/src/internal/writer/reset.ts +0 -34
- package/src/internal/writer/selection.ts +0 -84
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WHERE THE WORKFLOW'S FILES ARE: the `autonomous-skill-refinement` skill's copies on this machine (each agent account's
|
|
3
|
-
* skills folder holds one), the one whose `.local/` holds this machine's data, the synced skills folder around it, and the
|
|
4
|
-
* code itself. The daemon locates them once at start (`locateSkillCopy`); a test passes its own folders.
|
|
5
|
-
*/
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
import path from 'node:path';
|
|
8
|
-
|
|
9
|
-
/** The skill this workflow serves, whose folder holds its rules, its Jev key and this machine's data. */
|
|
10
|
-
export const OWNING_SKILL_FOLDER = 'autonomous-skill-refinement';
|
|
11
|
-
/** The workflow's code, which step records link their definitions to. */
|
|
12
|
-
export const CODE_ROOT = import.meta.dir;
|
|
13
|
-
|
|
14
|
-
/** Where one machine keeps the workflow's data, and the skills folder it edits. */
|
|
15
|
-
export interface WorkflowFolders {
|
|
16
|
-
/**
|
|
17
|
-
* The workflow's databases, intake and run files. Named with a leading dot: skill-sync's file listing skips such names,
|
|
18
|
-
* so this machine's live databases are never copied between machines (as the evals' `.results` already is).
|
|
19
|
-
*/
|
|
20
|
-
readonly local: string;
|
|
21
|
-
/** The synced skills folder the workflow reads and installs into. */
|
|
22
|
-
readonly skills: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** The copy of the skill this machine's runner works from, and what is read from it. */
|
|
26
|
-
export interface SkillCopy {
|
|
27
|
-
readonly skillFolder: string;
|
|
28
|
-
readonly folders: WorkflowFolders;
|
|
29
|
-
/** Jev's API key, where Alex puts it: the skill folder, synced with everything else in it. */
|
|
30
|
-
readonly jevKeyFile: string;
|
|
31
|
-
/** The Claude Code config folder holding the copy: the account the generative calls run on unless one is set. */
|
|
32
|
-
readonly accountFolder: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const copyAt = (skillFolder: string): SkillCopy => ({
|
|
36
|
-
skillFolder,
|
|
37
|
-
folders: { local: path.join(skillFolder, '.local'), skills: path.dirname(skillFolder) },
|
|
38
|
-
jevKeyFile: path.join(skillFolder, 'typesafe-api-key'),
|
|
39
|
-
accountFolder: path.dirname(path.dirname(skillFolder)),
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
/** Every copy of the skill in a dot-folder of `home` (`~/.claude-alex/skills/…`, `~/.grok/skills/…`), by folder name. */
|
|
43
|
-
export const skillCopies = (home: string): ReadonlyArray<string> => fs.readdirSync(home)
|
|
44
|
-
.filter((d) => d.startsWith('.'))
|
|
45
|
-
.sort()
|
|
46
|
-
.map((d) => path.join(home, d, 'skills', OWNING_SKILL_FOLDER))
|
|
47
|
-
.filter((d) => fs.existsSync(path.join(d, 'SKILL.md')));
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* The copy this machine's runner works from: the one in `claudeConfigDir` when one is set; else the one whose `.local/`
|
|
51
|
-
* already holds the workflow's database, so a machine keeps its queue and records; else the first Claude account's copy.
|
|
52
|
-
* None when the machine has no copy of the skill.
|
|
53
|
-
*/
|
|
54
|
-
export const locateSkillCopy = (input: { readonly home: string; readonly claudeConfigDir: string | undefined }): SkillCopy | null => {
|
|
55
|
-
if (input.claudeConfigDir !== undefined) {
|
|
56
|
-
const set = path.join(input.claudeConfigDir, 'skills', OWNING_SKILL_FOLDER);
|
|
57
|
-
return fs.existsSync(path.join(set, 'SKILL.md')) ? copyAt(set) : null;
|
|
58
|
-
}
|
|
59
|
-
const copies = skillCopies(input.home);
|
|
60
|
-
const withData = copies.find((d) => fs.existsSync(platformDatabase(copyAt(d).folders)));
|
|
61
|
-
const claude = copies.find((d) => /^\.claude(-|$)/.test(path.basename(path.dirname(path.dirname(d)))));
|
|
62
|
-
const chosen = withData ?? claude ?? copies[0];
|
|
63
|
-
return chosen === undefined ? null : copyAt(chosen);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/** One file per feedback item handed to the workflow, named by the item's id. */
|
|
67
|
-
export const intakeFolder = (f: WorkflowFolders) => path.join(f.local, 'intake');
|
|
68
|
-
/**
|
|
69
|
-
* Every intake on this machine: one per copy of this skill, since each agent account's skills folder holds its own copy
|
|
70
|
-
* and an agent hands feedback to the copy it loaded. The one runner a machine has reads them all.
|
|
71
|
-
*/
|
|
72
|
-
export const machineIntakeFolders = (input: { readonly home: string; readonly own: WorkflowFolders }): ReadonlyArray<string> => {
|
|
73
|
-
const copies = skillCopies(input.home).map((d) => path.join(d, '.local', 'intake')).filter((d) => fs.existsSync(d));
|
|
74
|
-
return [...new Set([intakeFolder(input.own), ...copies])];
|
|
75
|
-
};
|
|
76
|
-
/** One file per item the workflow installed a change for; its presence takes the item off the list. */
|
|
77
|
-
export const installedFolder = (f: WorkflowFolders) => path.join(f.local, 'installed');
|
|
78
|
-
/** Each run's texts too big for a record (drafts, replies, verdicts), one folder per run. */
|
|
79
|
-
export const runFolder = (f: WorkflowFolders, run: string) => path.join(f.local, 'runs', run);
|
|
80
|
-
/** The platform's database: step records, tasks, input runs, the two limits per workflow. */
|
|
81
|
-
export const platformDatabase = (f: WorkflowFolders) => path.join(f.local, 'skill-refinement.db');
|
|
82
|
-
/** The workflow engine's own database (effect/cluster's `cluster_*` tables). */
|
|
83
|
-
export const engineDatabase = (f: WorkflowFolders) => path.join(f.local, 'skill-refinement-engine.db');
|
|
84
|
-
/** Texts stored by their content hash, for task notes (the platform's `TextStore`). */
|
|
85
|
-
export const textsFolder = (f: WorkflowFolders) => path.join(f.local, 'texts');
|
|
86
|
-
/** The A/B examples every skill change is tested on. */
|
|
87
|
-
export const evalCasesFolder = (f: WorkflowFolders) => path.join(f.skills, 'agentic-collaboration', 'evals', 'cases');
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* THIS WORKFLOW ON THE WORKFLOW PLATFORM (`@jive-sh/workflow-platform`): the facts the platform cannot know about skill
|
|
3
|
-
* maintenance, and where its records live. Every step of the workflow is defined, measured and queued by the platform
|
|
4
|
-
* through this one instance.
|
|
5
|
-
*/
|
|
6
|
-
import { createWorkflowPlatform, sqliteStorage, type ProcessIdentity, type RunLightNow } from '@jive-sh/workflow-platform';
|
|
7
|
-
import fs from 'node:fs';
|
|
8
|
-
import os from 'node:os';
|
|
9
|
-
import path from 'node:path';
|
|
10
|
-
import { CODE_ROOT, engineDatabase, platformDatabase, textsFolder, type WorkflowFolders } from './paths';
|
|
11
|
-
|
|
12
|
-
const runLightNow: RunLightNow = (command, options) => {
|
|
13
|
-
const r = Bun.spawnSync([...command], { stdout: 'pipe', stderr: 'pipe', ...(options?.env === undefined ? {} : { env: { ...process.env, ...options.env } }) });
|
|
14
|
-
return { code: r.exitCode, stdout: r.stdout.toString(), stdoutBytes: new Uint8Array(r.stdout), stderr: r.stderr.toString() };
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/** When a process started, in unix seconds, as `ps` reports it; none for a process that is gone. */
|
|
18
|
-
const startedAtOf = (pid: number): number | null => {
|
|
19
|
-
const r = runLightNow(['ps', '-o', 'lstart=', '-p', String(pid)]);
|
|
20
|
-
const at = Date.parse(r.stdout.trim());
|
|
21
|
-
return r.code === 0 && !Number.isNaN(at) ? Math.floor(at / 1000) : null;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
let self: ProcessIdentity | null = null;
|
|
25
|
-
const thisProcess = (): ProcessIdentity => {
|
|
26
|
-
self ??= { pid: process.pid, startedAt: startedAtOf(process.pid) ?? Math.floor(Date.now() / 1000) };
|
|
27
|
-
return self;
|
|
28
|
-
};
|
|
29
|
-
const isAlive = (p: ProcessIdentity): boolean => startedAtOf(p.pid) === p.startedAt;
|
|
30
|
-
|
|
31
|
-
/** Texts by content hash, one file each: what a task note's change names. */
|
|
32
|
-
const textStore = (folder: string) => ({
|
|
33
|
-
write: (text: string) => {
|
|
34
|
-
const sha = new Bun.CryptoHasher('sha256').update(text).digest('hex');
|
|
35
|
-
fs.mkdirSync(folder, { recursive: true });
|
|
36
|
-
const file = path.join(folder, sha);
|
|
37
|
-
if (!fs.existsSync(file)) fs.writeFileSync(file, text);
|
|
38
|
-
return sha;
|
|
39
|
-
},
|
|
40
|
-
read: (sha: string) => {
|
|
41
|
-
const text = fs.readFileSync(path.join(folder, sha), 'utf8');
|
|
42
|
-
if (new Bun.CryptoHasher('sha256').update(text).digest('hex') !== sha) throw new Error(`text ${sha} does not match its hash`);
|
|
43
|
-
return text;
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
export const skillRefinementPlatform = (folders: WorkflowFolders) => {
|
|
48
|
-
fs.mkdirSync(folders.local, { recursive: true });
|
|
49
|
-
return createWorkflowPlatform<never>({
|
|
50
|
-
project: {
|
|
51
|
-
sourceRoot: CODE_ROOT,
|
|
52
|
-
// No agent step here has tools, so none edits a file: the skills folder is only where a step's changed files would be read from.
|
|
53
|
-
tree: { root: folders.skills, snapshots: path.join(folders.local, 'step-files'), notTree: [] },
|
|
54
|
-
texts: textStore(textsFolder(folders)),
|
|
55
|
-
runLightNow,
|
|
56
|
-
processes: { thisProcess, isAlive },
|
|
57
|
-
stepRecordVariable: 'SKILL_REFINEMENT_STEP_RECORD',
|
|
58
|
-
isTransientFailure: (e) => String(e).includes('database is locked'),
|
|
59
|
-
// No CPU pool: every step here waits on a model, not on this machine.
|
|
60
|
-
cpu: { limit: () => os.cpus().length, newestUse: () => null },
|
|
61
|
-
},
|
|
62
|
-
storage: sqliteStorage({
|
|
63
|
-
stepRecordsFile: () => platformDatabase(folders),
|
|
64
|
-
engineFile: () => engineDatabase(folders),
|
|
65
|
-
budgetsFile: () => platformDatabase(folders),
|
|
66
|
-
processes: { thisProcess, isAlive },
|
|
67
|
-
}),
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export type SkillRefinementPlatform = ReturnType<typeof skillRefinementPlatform>;
|
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* THE SKILL REFINEMENT RUNNER: hosts the workflow engine inside the skill-sync daemon and keeps the workflow's runs going.
|
|
3
|
-
* Each turn it reads the intake (the workflow's list of work) and starts the runs the workflow's run limit keeps above those
|
|
4
|
-
* going (`planRunStarts`). A turn runs when an item lands in the intake, when a run ends, and otherwise every minute as the
|
|
5
|
-
* fallback. The daemon starts it (`startSkillRefinement`), reports what the platform's dashboard shows (`pageData`) and
|
|
6
|
-
* passes on the dashboard's limit changes (`setLimit`).
|
|
7
|
-
*
|
|
8
|
-
* Configuration, read once at the start: `TYPESAFE_API_KEY` (or the skill folder's `typesafe-api-key` file) for Jev, and
|
|
9
|
-
* `SKILL_REFINEMENT_CLAUDE_CONFIG_DIR`, the Claude Code config folder whose account the generative calls run on (by
|
|
10
|
-
* default the account folder holding the copy the runner works from, `locateSkillCopy`). Nothing here names a machine.
|
|
11
|
-
*/
|
|
12
|
-
import { SqliteClient } from '@effect/sql-sqlite-bun';
|
|
13
|
-
import {
|
|
14
|
-
claimsCounting,
|
|
15
|
-
describeFailure, KEEP_RUNNING_EVERY_SECONDS, newRunId, oneTurnAtATime, planRunStarts, runsNow, SET_WORKFLOW_BUDGET_SQL, SET_WORKFLOW_RUNS_SQL,
|
|
16
|
-
START_LIMIT_SECONDS, TURN_LIMIT_MS, WORKFLOW_BUDGET_SQL,
|
|
17
|
-
} from '@jive-sh/workflow-platform';
|
|
18
|
-
import { Database } from 'bun:sqlite';
|
|
19
|
-
import { Crypto, Duration, Effect, Layer, ManagedRuntime, Option, pipe } from 'effect';
|
|
20
|
-
import { ClusterWorkflowEngine, RunnerAddress, SingleRunner } from 'effect/cluster';
|
|
21
|
-
import fs from 'node:fs';
|
|
22
|
-
import os from 'node:os';
|
|
23
|
-
import path from 'node:path';
|
|
24
|
-
import { judgeVersion } from './evals/cases';
|
|
25
|
-
import { itemId, makeIntake } from './feedback/intake';
|
|
26
|
-
import { importLegacyFeedback } from './feedback/import-legacy';
|
|
27
|
-
import { makeFeedbackOutbox, type FeedbackToSend } from './feedback/outbox';
|
|
28
|
-
import { makeManagedIntake } from './feedback/managed-intake';
|
|
29
|
-
import { makeManagedWorkerFiles } from './managed-worker-files';
|
|
30
|
-
import { runManagedWorker } from './managed-worker-loop';
|
|
31
|
-
import { JevLive } from './jev/impl';
|
|
32
|
-
import { engineDatabase, installedFolder, intakeFolder, locateSkillCopy, machineIntakeFolders, platformDatabase, runFolder, type WorkflowFolders } from './paths';
|
|
33
|
-
import OPUS_JUDGE_ORIGINAL from './evals/opus-judge-original.json';
|
|
34
|
-
import OPUS_ACTION_JUDGE_ORIGINAL from './evals/opus-action-judge-original.json';
|
|
35
|
-
import { skillRefinementPlatform } from './platform';
|
|
36
|
-
import { SkillFiles, SkillFilesLive, skillsTextSha, type SyncedSkills } from './skills/skill-text';
|
|
37
|
-
import type { Jev } from './jev/interface';
|
|
38
|
-
import { defineSkillRefinement, draftVersion, WORKFLOW } from './workflow/skill-refinement';
|
|
39
|
-
import { Writer } from '../writer/interface';
|
|
40
|
-
import { liveWriters } from '../writer/live';
|
|
41
|
-
import type { WriterSelection } from '../writer/selection';
|
|
42
|
-
import type { LimitChange, RefinementPageData } from '../wire';
|
|
43
|
-
|
|
44
|
-
/** Bun's WebCrypto, as the cluster's message storage needs it. */
|
|
45
|
-
const CryptoLive = Layer.succeed(Crypto.Crypto, Crypto.make({
|
|
46
|
-
randomBytes: (size) => globalThis.crypto.getRandomValues(new Uint8Array(size)),
|
|
47
|
-
digest: (algorithm, data) => Effect.promise(async () => new Uint8Array(await globalThis.crypto.subtle.digest(algorithm, new Uint8Array(data)))),
|
|
48
|
-
}));
|
|
49
|
-
|
|
50
|
-
export interface ServiceConfig {
|
|
51
|
-
readonly folders: WorkflowFolders;
|
|
52
|
-
/** Jev's API key, read when used; empty while none is set, so its steps fail with that reason. */
|
|
53
|
-
readonly typesafeApiKey: () => string;
|
|
54
|
-
readonly jevModel: string;
|
|
55
|
-
readonly claudeConfigDir: string;
|
|
56
|
-
readonly writerModel: string;
|
|
57
|
-
/** The Opus judge's grades of the original replies, the bar Jev is calibrated against. */
|
|
58
|
-
readonly opusJudgeGrades: ReadonlyArray<{ readonly case: string; readonly pass: boolean }>;
|
|
59
|
-
/** The evals' original action-judge prompt's grades of the action originals, the bar the action judge is held to. */
|
|
60
|
-
readonly opusActionJudgeGrades: ReadonlyArray<{ readonly case: string; readonly pass: boolean }>;
|
|
61
|
-
/** Every intake the items are read from (`machineIntakeFolders`). */
|
|
62
|
-
readonly intakes: ReadonlyArray<string>;
|
|
63
|
-
/** The time now, unix seconds, which decides when a failed item runs again (`retry.ts`); a test gives its own clock. */
|
|
64
|
-
readonly now?: () => number;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* EACH WORKFLOW STARTS AT ONE RUN AND ONE AGENT (`spawn-subthread` section 2, step 3): set once, never changed here; the
|
|
69
|
-
* owner changes them in the `workflow_budgets` table.
|
|
70
|
-
*/
|
|
71
|
-
const ensureLimits = (folders: WorkflowFolders) => {
|
|
72
|
-
const db = new Database(platformDatabase(folders), { create: true });
|
|
73
|
-
try {
|
|
74
|
-
db.run('CREATE TABLE IF NOT EXISTS workflow_budgets (workflow TEXT PRIMARY KEY, budget INTEGER NOT NULL, runs INTEGER, changed_at REAL NOT NULL)');
|
|
75
|
-
if (db.query(WORKFLOW_BUDGET_SQL).get(WORKFLOW) === null) {
|
|
76
|
-
db.query(SET_WORKFLOW_BUDGET_SQL).run(WORKFLOW, 1, Date.now() / 1000);
|
|
77
|
-
db.query(SET_WORKFLOW_RUNS_SQL).run(WORKFLOW, 1, Date.now() / 1000);
|
|
78
|
-
}
|
|
79
|
-
} finally {
|
|
80
|
-
db.close();
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/** The workflow, its engine and its modules, on one machine's folders; a test gives fake modules. */
|
|
85
|
-
export const makeService = (config: ServiceConfig, modules: Layer.Layer<Jev | Writer | SkillFiles>, legacyCutOver = () => false, writers?: WriterSelection) => {
|
|
86
|
-
const { folders } = config;
|
|
87
|
-
fs.mkdirSync(intakeFolder(folders), { recursive: true });
|
|
88
|
-
ensureLimits(folders);
|
|
89
|
-
const platform = skillRefinementPlatform(folders);
|
|
90
|
-
const intake = makeIntake({ intake: intakeFolder(folders), intakes: config.intakes, installed: installedFolder(folders) });
|
|
91
|
-
// Everything a run reads beyond the item: an item that ended without an install runs again once any of it changes.
|
|
92
|
-
// A key put in place queues the items its absence stopped; a change to Draft or the judge queues every item that
|
|
93
|
-
// ended under the old one; an edit to a skill (an install, another machine's edit pulled) queues those that would draft on it.
|
|
94
|
-
const now = config.now ?? (() => Date.now() / 1000);
|
|
95
|
-
const configFingerprint = () => JSON.stringify({
|
|
96
|
-
judge: judgeVersion(), draft: draftVersion(), skills: skillsTextSha(folders.skills),
|
|
97
|
-
jev: config.jevModel, jevKeySet: config.typesafeApiKey().length > 0, writer: config.writerModel, account: config.claudeConfigDir,
|
|
98
|
-
});
|
|
99
|
-
const maintenance = defineSkillRefinement({ platform, intake, folders, opusJudgeGrades: config.opusJudgeGrades, opusActionJudgeGrades: config.opusActionJudgeGrades, configFingerprint, now, writers, models: { jev: config.jevModel, writer: config.writerModel } });
|
|
100
|
-
const layer = pipe(
|
|
101
|
-
// The platform's own workflows (Retention) run in the same engine as this one.
|
|
102
|
-
Layer.mergeAll(maintenance.layer as Layer.Layer<never>, platform.system.layer as Layer.Layer<never>),
|
|
103
|
-
Layer.provideMerge(ClusterWorkflowEngine.layer),
|
|
104
|
-
Layer.provideMerge(SingleRunner.layer({
|
|
105
|
-
runnerStorage: 'sql',
|
|
106
|
-
shardingConfig: { runnerAddress: Option.some(RunnerAddress.make('skill-refinement', process.pid)), entityTerminationTimeout: Duration.minutes(10) },
|
|
107
|
-
})),
|
|
108
|
-
Layer.provideMerge(SqliteClient.layer({ filename: engineDatabase(folders), busyTimeout: Duration.seconds(1) })),
|
|
109
|
-
Layer.provideMerge(CryptoLive),
|
|
110
|
-
Layer.provideMerge(modules),
|
|
111
|
-
);
|
|
112
|
-
const runtime = ManagedRuntime.make(layer);
|
|
113
|
-
let importing = false;
|
|
114
|
-
let startsInFlight = 0;
|
|
115
|
-
|
|
116
|
-
/** One turn: the list read into the task queue, then the runs the limits keep, started and left to the engine. */
|
|
117
|
-
const turn = oneTurnAtATime(async (stillCurrent) => {
|
|
118
|
-
if (importing || legacyCutOver()) return;
|
|
119
|
-
const declared = platform.steps.declaredWorkflows();
|
|
120
|
-
for (const d of declared) {
|
|
121
|
-
if (d.pending === undefined) continue;
|
|
122
|
-
const work = await Effect.runPromise(d.pending());
|
|
123
|
-
await Effect.runPromise(platform.tasks.recordListing({ workflow: d.name, work, everyItem: false }));
|
|
124
|
-
}
|
|
125
|
-
const limits = await Effect.runPromise(platform.storage.budgets.limitsOf(WORKFLOW));
|
|
126
|
-
const going = await Effect.runPromise(platform.storage.engine.runningRuns(WORKFLOW));
|
|
127
|
-
const noWork = await Effect.runPromise(platform.steps.whyNoRunCanTakeWork(WORKFLOW));
|
|
128
|
-
const plans = planRunStarts({
|
|
129
|
-
declared,
|
|
130
|
-
limitsOf: () => limits ?? { agents: 0, runs: null },
|
|
131
|
-
runningRuns: () => going,
|
|
132
|
-
noWork: () => noWork,
|
|
133
|
-
});
|
|
134
|
-
for (const p of plans) {
|
|
135
|
-
for (let i = 0; i < p.start; i++) {
|
|
136
|
-
if (importing || legacyCutOver() || !stillCurrent()) return;
|
|
137
|
-
const run = newRunId();
|
|
138
|
-
startsInFlight += 1;
|
|
139
|
-
try {
|
|
140
|
-
await runtime.runPromise(Effect.timeout(Effect.asVoid(p.declaration.start(run)), `${START_LIMIT_SECONDS} seconds`));
|
|
141
|
-
console.log(`[keep running] ${p.declaration.name}: started run ${run}`);
|
|
142
|
-
} catch (e) {
|
|
143
|
-
console.error(`[keep running] ${p.declaration.name}: run ${run} did not start: ${describeFailure(e)}`);
|
|
144
|
-
} finally {
|
|
145
|
-
startsInFlight -= 1;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}, TURN_LIMIT_MS);
|
|
150
|
-
const kick = () => { void turn().catch((e: unknown) => console.error(`[keep running] ${describeFailure(e)}`)); };
|
|
151
|
-
platform.steps.onRunEnded(kick);
|
|
152
|
-
// A retry time passing (`retry.ts`) changes an item's inputs with no note, listing or edit to announce it: the waiting
|
|
153
|
-
// Pick is woken for it. The first check covers every time already passed, so a restart picks up what fell due while down.
|
|
154
|
-
let retriesCheckedTo = 0;
|
|
155
|
-
const wakeDueRetries = async () => {
|
|
156
|
-
const to = now();
|
|
157
|
-
const due = await runtime.runPromise(maintenance.retryFallsDue({ from: retriesCheckedTo, to }));
|
|
158
|
-
retriesCheckedTo = to;
|
|
159
|
-
if (due) platform.wakes.wakePicksOf(WORKFLOW, "a failed item's retry time passed");
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
const copyDrainedQueue = (input: { readonly managedCompletedRealWork: boolean; readonly commit: (items: ReadonlyArray<FeedbackToSend>) => void }) =>
|
|
163
|
-
importLegacyFeedback({
|
|
164
|
-
...input,
|
|
165
|
-
withDrainedLegacyQueue: async (read) => {
|
|
166
|
-
if (importing) throw new Error('Legacy queue import is already running');
|
|
167
|
-
importing = true;
|
|
168
|
-
try {
|
|
169
|
-
const deadline = Date.now() + 10_000;
|
|
170
|
-
while (startsInFlight > 0 || await Effect.runPromise(platform.storage.engine.runningRuns(WORKFLOW)) > 0) {
|
|
171
|
-
if (Date.now() >= deadline) throw new Error('Legacy workflow still has active runs');
|
|
172
|
-
await Bun.sleep(250);
|
|
173
|
-
}
|
|
174
|
-
const items = await Effect.runPromise(intake.open());
|
|
175
|
-
return await read((async function* () {
|
|
176
|
-
for (const item of items) {
|
|
177
|
-
const text = await Effect.runPromise(intake.text(item));
|
|
178
|
-
const notes = await Effect.runPromise(platform.tasks.notesForAgent({ workflow: WORKFLOW, item }));
|
|
179
|
-
yield { item, text, ...(notes.length === 0 ? {} : { earlierTries: notes }) };
|
|
180
|
-
}
|
|
181
|
-
})());
|
|
182
|
-
} finally {
|
|
183
|
-
importing = false;
|
|
184
|
-
kick();
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
return { platform, intake, runtime, turn, kick, wakeDueRetries, copyDrainedQueue };
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
/** What the live modules need beyond the service's configuration: the `claude` CLI, and skill-sync's synced list. */
|
|
193
|
-
export interface LiveInputs {
|
|
194
|
-
readonly claudeCommand: string;
|
|
195
|
-
readonly syncedSkills: SyncedSkills;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/** The live modules the workflow's steps call: Jev, the generative model and the synced skills. */
|
|
199
|
-
export const liveModules = (config: ServiceConfig, live: Pick<LiveInputs, 'syncedSkills'>, writers: WriterSelection): Layer.Layer<Jev | Writer | SkillFiles> => Layer.mergeAll(
|
|
200
|
-
JevLive({ apiKey: config.typesafeApiKey, model: config.jevModel }),
|
|
201
|
-
Layer.succeed(Writer, writers.writer),
|
|
202
|
-
SkillFilesLive({ root: config.folders.skills, syncedSkills: live.syncedSkills }),
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
/** The window of each workflow's figures, as the platform's dashboard states it. */
|
|
206
|
-
const FIGURES_HOURS = 24;
|
|
207
|
-
/** A runner whose heartbeat is older than this is gone, whatever its process does now. */
|
|
208
|
-
const RUNNER_HEARTBEAT_STALE_MS = 60_000;
|
|
209
|
-
|
|
210
|
-
/** The running workflow, as the daemon uses it. */
|
|
211
|
-
export interface SkillRefinementRunner {
|
|
212
|
-
/** The dashboard's data, all of it read at the call. */
|
|
213
|
-
readonly pageData: () => Promise<RefinementPageData>;
|
|
214
|
-
/** Sets one limit of the workflow and has its runs act on it at once. A whole number of 0 or more; none, for runs only, is its default. */
|
|
215
|
-
readonly setLimit: (r: LimitChange) => Promise<void>;
|
|
216
|
-
/** Hands one feedback item to the workflow, in this machine's copy of the skill; gives its id. */
|
|
217
|
-
readonly addFeedback: (r: { readonly slug: string; readonly text: string }) => Promise<string>;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/** Why this machine runs no workflow, in a line for the daemon's log and the dashboard. */
|
|
221
|
-
export type NotRunning = { readonly notRunning: string };
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Another live process running this workflow on the same engine database: the runner a machine had before the daemon
|
|
225
|
-
* took the work over (`skill-refinement.service`), or a copy started by hand. Read from the engine's own runner
|
|
226
|
-
* registrations, each named `<host>:<pid>` and heartbeating while it lives.
|
|
227
|
-
*/
|
|
228
|
-
export const otherLiveRunner = (folders: WorkflowFolders, now: number): string | null => {
|
|
229
|
-
const file = engineDatabase(folders);
|
|
230
|
-
if (!fs.existsSync(file)) return null;
|
|
231
|
-
const db = new Database(file, { readonly: true });
|
|
232
|
-
try {
|
|
233
|
-
if (db.query(`SELECT 1 FROM sqlite_master WHERE name = 'cluster_runners'`).get() === null) return null;
|
|
234
|
-
const rows = db.query('SELECT address, last_heartbeat FROM cluster_runners').all() as ReadonlyArray<{ address: string; last_heartbeat: string }>;
|
|
235
|
-
for (const row of rows) {
|
|
236
|
-
const pid = Number(row.address.split(':').pop());
|
|
237
|
-
const beat = Date.parse(`${row.last_heartbeat.replace(' ', 'T')}Z`);
|
|
238
|
-
if (!Number.isInteger(pid) || pid === process.pid || Number.isNaN(beat) || now - beat > RUNNER_HEARTBEAT_STALE_MS) continue;
|
|
239
|
-
try {
|
|
240
|
-
process.kill(pid, 0);
|
|
241
|
-
return `process ${pid} runs it (heartbeat ${new Date(beat).toISOString()})`;
|
|
242
|
-
} catch {
|
|
243
|
-
// Gone: its row is left from before.
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
return null;
|
|
247
|
-
} finally {
|
|
248
|
-
db.close();
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Starts the workflow on this machine's copy of the skill, once no other process runs it. Waits, checking every minute,
|
|
254
|
-
* while one does, so the runner a machine had before hands over by stopping. Gives the runner, or why there is none.
|
|
255
|
-
*/
|
|
256
|
-
export const startSkillRefinement = async (input: {
|
|
257
|
-
readonly home: string;
|
|
258
|
-
readonly claudeCommand: string | undefined;
|
|
259
|
-
readonly syncedSkills: SyncedSkills;
|
|
260
|
-
/** Called once the runner is up, and again with why whenever it is waiting or cannot run. */
|
|
261
|
-
readonly onState: (state: SkillRefinementRunner | NotRunning) => void;
|
|
262
|
-
/** Present only when the daemon can acquire purpose-scoped credentials for its configured organization. */
|
|
263
|
-
readonly managed?: {
|
|
264
|
-
readonly signal: AbortSignal;
|
|
265
|
-
readonly connect: () => Promise<{
|
|
266
|
-
readonly deployment: URL;
|
|
267
|
-
readonly site: URL;
|
|
268
|
-
readonly workToken: () => Promise<string>;
|
|
269
|
-
readonly intakeToken: () => Promise<string>;
|
|
270
|
-
}>;
|
|
271
|
-
readonly workOnce: (input: {
|
|
272
|
-
readonly deployment: URL;
|
|
273
|
-
readonly token: () => Promise<string>;
|
|
274
|
-
readonly filesForRun: (run: string) => ReturnType<typeof makeManagedWorkerFiles>['forRun'] extends (run: string) => infer Files ? Files : never;
|
|
275
|
-
readonly config: ServiceConfig;
|
|
276
|
-
readonly live: LiveInputs;
|
|
277
|
-
}) => Promise<{ readonly worked: boolean; readonly installedTask: string | undefined }>;
|
|
278
|
-
};
|
|
279
|
-
}): Promise<void> => {
|
|
280
|
-
const copy = locateSkillCopy({ home: input.home, claudeConfigDir: process.env["SKILL_REFINEMENT_CLAUDE_CONFIG_DIR"] });
|
|
281
|
-
if (copy === null) return input.onState({ notRunning: 'this machine has no copy of the autonomous-skill-refinement skill' });
|
|
282
|
-
let waitingFor = '';
|
|
283
|
-
for (;;) {
|
|
284
|
-
const other = otherLiveRunner(copy.folders, Date.now());
|
|
285
|
-
if (other === null) break;
|
|
286
|
-
if (other !== waitingFor) input.onState({ notRunning: `waiting to take over: ${other}` });
|
|
287
|
-
waitingFor = other;
|
|
288
|
-
await Bun.sleep(60_000);
|
|
289
|
-
}
|
|
290
|
-
const config: ServiceConfig = {
|
|
291
|
-
folders: copy.folders,
|
|
292
|
-
typesafeApiKey: () => process.env["TYPESAFE_API_KEY"] ?? (fs.existsSync(copy.jevKeyFile) ? fs.readFileSync(copy.jevKeyFile, 'utf8').trim() : ''),
|
|
293
|
-
jevModel: 'jev-latest',
|
|
294
|
-
claudeConfigDir: process.env["SKILL_REFINEMENT_CLAUDE_CONFIG_DIR"] ?? copy.accountFolder,
|
|
295
|
-
writerModel: 'claude-opus-5-5',
|
|
296
|
-
opusJudgeGrades: OPUS_JUDGE_ORIGINAL.grades,
|
|
297
|
-
opusActionJudgeGrades: OPUS_ACTION_JUDGE_ORIGINAL.grades,
|
|
298
|
-
intakes: machineIntakeFolders({ home: input.home, own: copy.folders }),
|
|
299
|
-
};
|
|
300
|
-
const writers = liveWriters({
|
|
301
|
-
home: input.home, scratch: runFolder(config.folders, 'writer-scratch'),
|
|
302
|
-
claudeCommand: input.claudeCommand, claudeConfigDir: config.claudeConfigDir, claudeModel: config.writerModel,
|
|
303
|
-
});
|
|
304
|
-
if (writers === undefined) return input.onState({ notRunning: 'no generative writer CLI was found on this machine' });
|
|
305
|
-
const service = makeService(config, liveModules(config, input, writers), () => outbox?.cutOver() ?? false, writers);
|
|
306
|
-
const outboxPath = path.join(config.folders.local, 'managed-refinement-outbox.db');
|
|
307
|
-
const outboxDb = input.managed !== undefined || fs.existsSync(outboxPath) ? new Database(outboxPath) : undefined;
|
|
308
|
-
const outbox = outboxDb === undefined ? undefined : makeFeedbackOutbox(outboxDb);
|
|
309
|
-
let managedOutbox: ReturnType<typeof makeFeedbackOutbox> | undefined;
|
|
310
|
-
console.log(`[skill refinement] working from ${copy.skillFolder}; Jev key ${config.typesafeApiKey().length > 0 ? 'set' : 'NOT set: Classify fails until it is'}; generative writers: ${writers.tools.join(', ')}`);
|
|
311
|
-
// The engine starts with the runtime; resumed runs continue from their records.
|
|
312
|
-
await service.runtime.runPromise(Effect.void);
|
|
313
|
-
if (input.managed !== undefined && outbox !== undefined && input.claudeCommand !== undefined) {
|
|
314
|
-
const managed = input.managed;
|
|
315
|
-
const live = { claudeCommand: input.claudeCommand, syncedSkills: input.syncedSkills };
|
|
316
|
-
void runManagedWorker({
|
|
317
|
-
signal: managed.signal,
|
|
318
|
-
wait: async () => { await Bun.sleep(5_000); },
|
|
319
|
-
deliverNext: outbox.deliverNext,
|
|
320
|
-
connect: async () => {
|
|
321
|
-
const connection = await managed.connect();
|
|
322
|
-
const sendFeedback = makeManagedIntake({ site: connection.site, token: connection.intakeToken });
|
|
323
|
-
const files = makeManagedWorkerFiles({ site: connection.site, token: connection.workToken });
|
|
324
|
-
managedOutbox = outbox;
|
|
325
|
-
if (!outbox.cutOver() && outbox.installedRealFeedback()) {
|
|
326
|
-
await service.copyDrainedQueue({ managedCompletedRealWork: true, commit: outbox.commitLegacy }).catch(() => {
|
|
327
|
-
// Existing managed work can proceed while a legacy run finishes or the import is retried.
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
return {
|
|
331
|
-
sendFeedback,
|
|
332
|
-
workOnce: async () => {
|
|
333
|
-
const result = await managed.workOnce({ deployment: connection.deployment, token: connection.workToken, filesForRun: files.forRun, config, live });
|
|
334
|
-
if (result.installedTask !== undefined) outbox.recordInstallation(result.installedTask);
|
|
335
|
-
return result.worked;
|
|
336
|
-
},
|
|
337
|
-
};
|
|
338
|
-
},
|
|
339
|
-
onUnavailable: (operation) => {
|
|
340
|
-
if (operation === 'connection') managedOutbox = undefined;
|
|
341
|
-
},
|
|
342
|
-
}).catch(() => {
|
|
343
|
-
console.error('skill refinement: the managed worker stopped');
|
|
344
|
-
}).finally(() => {
|
|
345
|
-
managedOutbox = undefined;
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
for (const folder of config.intakes) fs.watch(folder, () => service.kick());
|
|
349
|
-
// The key's arrival changes every task's inputs (`configFingerprint`), which no note or listing announces: the waiting Pick is woken to read them.
|
|
350
|
-
fs.watch(copy.skillFolder, (_, file) => { if (file === path.basename(copy.jevKeyFile)) service.platform.wakes.wakePicksOf(WORKFLOW, 'the Jev key was set'); });
|
|
351
|
-
// Likewise a skill's text (`configFingerprint`): one pulled from another machine arrives with no run or item to wake the Pick.
|
|
352
|
-
for (const skill of fs.readdirSync(copy.folders.skills).filter((d) => fs.existsSync(path.join(copy.folders.skills, d, 'SKILL.md')))) {
|
|
353
|
-
fs.watch(path.join(copy.folders.skills, skill), (_, file) => { if (file === 'SKILL.md') service.platform.wakes.wakePicksOf(WORKFLOW, `skill ${skill} changed`); });
|
|
354
|
-
}
|
|
355
|
-
const keepRunning = () => {
|
|
356
|
-
void service.wakeDueRetries().catch((e: unknown) => console.error(`[skill refinement] could not check for retries due: ${describeFailure(e)}`));
|
|
357
|
-
service.kick();
|
|
358
|
-
};
|
|
359
|
-
setInterval(keepRunning, KEEP_RUNNING_EVERY_SECONDS * 1000);
|
|
360
|
-
keepRunning();
|
|
361
|
-
// The platform's own workflows, each on its own schedule: Retention prunes step records past the days they are kept.
|
|
362
|
-
for (const w of service.platform.system.workflows) {
|
|
363
|
-
let turn = 0;
|
|
364
|
-
const runIt = () => { turn += 1; void service.runtime.runPromise(w.start(turn)).catch((e: unknown) => console.error(`[skill refinement] ${w.name} did not start: ${describeFailure(e)}`)); };
|
|
365
|
-
setTimeout(() => { runIt(); setInterval(runIt, w.everySeconds * 1000); }, w.firstAfterSeconds * 1000);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
const { platform } = service;
|
|
369
|
-
// Each queue counted when it may have changed, for the dashboard's queues over time; only the process running the workflow records them.
|
|
370
|
-
platform.queueCounts.record((count) => service.runtime.runPromise(count));
|
|
371
|
-
input.onState({
|
|
372
|
-
pageData: async () => {
|
|
373
|
-
const now = Date.now() / 1000;
|
|
374
|
-
const declared = platform.steps.declaredWorkflows();
|
|
375
|
-
const unfinished = await Effect.runPromise(platform.storage.engine.unfinishedRuns());
|
|
376
|
-
const newest = await Effect.runPromise(platform.storage.stepRecords.newestStepRecords(unfinished.map((u) => u.run)));
|
|
377
|
-
const figures: Record<string, object> = {};
|
|
378
|
-
for (const d of declared) {
|
|
379
|
-
const read = await Effect.runPromise(platform.figures({ workflow: d.name, now, hours: FIGURES_HOURS }));
|
|
380
|
-
if (read !== null) figures[d.name] = read;
|
|
381
|
-
}
|
|
382
|
-
return {
|
|
383
|
-
view: await Effect.runPromise(platform.view({ now, top: WORKFLOW })),
|
|
384
|
-
runsNow: runsNow({ declared, unfinished, newest, claims: claimsCounting(await Effect.runPromise(platform.storage.claims.openAgentClaims()), new Set(unfinished.map((u) => u.run))) }),
|
|
385
|
-
cpu: { limit: os.cpus().length, use: null },
|
|
386
|
-
figures,
|
|
387
|
-
};
|
|
388
|
-
},
|
|
389
|
-
setLimit: async ({ workflow, limit, value }) => {
|
|
390
|
-
if (!platform.steps.declaredWorkflows().some((d) => d.name === workflow)) throw new Error(`no workflow ${workflow} runs here`);
|
|
391
|
-
if (value !== null && (!Number.isInteger(value) || value < 0)) throw new Error(`a limit is a whole number of 0 or more, not ${value}`);
|
|
392
|
-
if (value === null && limit === 'agents') throw new Error('the agents\' limit needs a number');
|
|
393
|
-
const db = new Database(platformDatabase(copy.folders));
|
|
394
|
-
try {
|
|
395
|
-
db.query(limit === 'runs' ? SET_WORKFLOW_RUNS_SQL : SET_WORKFLOW_BUDGET_SQL).run(workflow, value, Date.now() / 1000);
|
|
396
|
-
} finally {
|
|
397
|
-
db.close();
|
|
398
|
-
}
|
|
399
|
-
// A run past a lower limit stands down at its next agent step; a higher one starts more at once.
|
|
400
|
-
platform.wakes.runPlanChanged({ workflow, source: `its ${limit === 'runs' ? 'run' : 'agents\''} limit set from the dashboard` });
|
|
401
|
-
service.kick();
|
|
402
|
-
console.log(`[skill refinement] ${workflow}: ${limit} limit set to ${String(value)} from the dashboard`);
|
|
403
|
-
},
|
|
404
|
-
addFeedback: async ({ slug, text }) => {
|
|
405
|
-
const arrived = new Date();
|
|
406
|
-
const destination = outbox?.cutOver() ? outbox : managedOutbox;
|
|
407
|
-
if (destination === undefined) return Effect.runPromise(service.intake.add({ arrived, slug, text }));
|
|
408
|
-
const item = itemId({ arrived, slug });
|
|
409
|
-
destination.enqueue({ item, text });
|
|
410
|
-
return item;
|
|
411
|
-
},
|
|
412
|
-
});
|
|
413
|
-
};
|