@jive-sh/skill-sync 0.11.0-latest-darwin-x64 → 0.11.0
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/README.md +346 -0
- package/bin/package.json +1 -0
- package/bin/skill-sync +34 -0
- package/bin/skill-sync-daemon +34 -0
- package/dist/daemons/skill-sync-daemon.js +664 -0
- package/dist/daemons/skill-sync-daemon.js.map +1 -0
- package/dist/entrypoints/skill-sync.js +7 -0
- package/dist/entrypoints/skill-sync.js.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/agents/agent-tool.js +102 -0
- package/dist/internal/agents/agent-tool.js.map +1 -0
- package/dist/internal/agents/claude.js +424 -0
- package/dist/internal/agents/claude.js.map +1 -0
- package/dist/internal/agents/codex.js +270 -0
- package/dist/internal/agents/codex.js.map +1 -0
- package/dist/internal/agents/command.js +219 -0
- package/dist/internal/agents/command.js.map +1 -0
- package/dist/internal/agents/grok.js +170 -0
- package/dist/internal/agents/grok.js.map +1 -0
- package/dist/internal/agents/index.js +70 -0
- package/dist/internal/agents/index.js.map +1 -0
- package/dist/internal/cli.js +218 -0
- package/dist/internal/cli.js.map +1 -0
- package/dist/internal/comment-watch/held.js +14 -0
- package/dist/internal/comment-watch/held.js.map +1 -0
- package/dist/internal/comment-watch/key.js +4 -0
- package/dist/internal/comment-watch/key.js.map +1 -0
- package/dist/internal/comment-watch/message.js +37 -0
- package/dist/internal/comment-watch/message.js.map +1 -0
- package/dist/internal/comment-watch/paths.js +16 -0
- package/dist/internal/comment-watch/paths.js.map +1 -0
- package/dist/internal/comment-watch/platform.js +66 -0
- package/dist/internal/comment-watch/platform.js.map +1 -0
- package/dist/internal/comment-watch/protocol.js +124 -0
- package/dist/internal/comment-watch/protocol.js.map +1 -0
- package/dist/internal/comment-watch/recent.js +27 -0
- package/dist/internal/comment-watch/recent.js.map +1 -0
- package/dist/internal/comment-watch/replies.js +28 -0
- package/dist/internal/comment-watch/replies.js.map +1 -0
- package/dist/internal/comment-watch/service.js +174 -0
- package/dist/internal/comment-watch/service.js.map +1 -0
- package/dist/internal/comment-watch/settings.js +66 -0
- package/dist/internal/comment-watch/settings.js.map +1 -0
- package/dist/internal/comment-watch/source/github-pull-requests/conversations.js +85 -0
- package/dist/internal/comment-watch/source/github-pull-requests/conversations.js.map +1 -0
- package/dist/internal/comment-watch/source/github-pull-requests/impl.js +276 -0
- package/dist/internal/comment-watch/source/github-pull-requests/impl.js.map +1 -0
- package/dist/internal/comment-watch/source/github-pull-requests/queries.js +97 -0
- package/dist/internal/comment-watch/source/github-pull-requests/queries.js.map +1 -0
- package/dist/internal/comment-watch/source/google-doc/doc.js +57 -0
- package/dist/internal/comment-watch/source/google-doc/doc.js.map +1 -0
- package/dist/internal/comment-watch/source/google-doc/impl.js +190 -0
- package/dist/internal/comment-watch/source/google-doc/impl.js.map +1 -0
- package/dist/internal/comment-watch/source/http-api.js +74 -0
- package/dist/internal/comment-watch/source/http-api.js.map +1 -0
- package/dist/internal/comment-watch/source/interface.js +48 -0
- package/dist/internal/comment-watch/source/interface.js.map +1 -0
- package/dist/internal/comment-watch/source/sign-in.js +40 -0
- package/dist/internal/comment-watch/source/sign-in.js.map +1 -0
- package/dist/internal/comment-watch/source/sources.js +15 -0
- package/dist/internal/comment-watch/source/sources.js.map +1 -0
- package/dist/internal/comment-watch/store/impl.js +242 -0
- package/dist/internal/comment-watch/store/impl.js.map +1 -0
- package/dist/internal/comment-watch/store/interface.js +10 -0
- package/dist/internal/comment-watch/store/interface.js.map +1 -0
- package/dist/internal/comment-watch/t3.js +49 -0
- package/dist/internal/comment-watch/t3.js.map +1 -0
- package/dist/internal/comment-watch/watching.js +65 -0
- package/dist/internal/comment-watch/watching.js.map +1 -0
- package/dist/internal/comment-watch/workflow/comment-watch.js +19 -0
- package/dist/internal/comment-watch/workflow/comment-watch.js.map +1 -0
- package/dist/internal/comment-watch/workflow/deliver.js +104 -0
- package/dist/internal/comment-watch/workflow/deliver.js.map +1 -0
- package/dist/internal/comment-watch/workflow/find.js +67 -0
- package/dist/internal/comment-watch/workflow/find.js.map +1 -0
- package/dist/internal/comment-watch/workflow/post-once.js +66 -0
- package/dist/internal/comment-watch/workflow/post-once.js.map +1 -0
- package/dist/internal/comment-watch/workflow/post.js +40 -0
- package/dist/internal/comment-watch/workflow/post.js.map +1 -0
- package/dist/internal/config.js +131 -0
- package/dist/internal/config.js.map +1 -0
- package/dist/internal/control.js +113 -0
- package/dist/internal/control.js.map +1 -0
- package/dist/internal/daemon-control/impl.js +80 -0
- package/dist/internal/daemon-control/impl.js.map +1 -0
- package/dist/internal/daemon-control/interface.js +4 -0
- package/dist/internal/daemon-control/interface.js.map +1 -0
- package/dist/internal/folders.js +47 -0
- package/dist/internal/folders.js.map +1 -0
- package/dist/internal/local-skills.js +43 -0
- package/dist/internal/local-skills.js.map +1 -0
- package/dist/internal/path.js +36 -0
- package/dist/internal/path.js.map +1 -0
- package/dist/internal/server.js +80 -0
- package/dist/internal/server.js.map +1 -0
- package/dist/internal/skill-check.js +83 -0
- package/dist/internal/skill-check.js.map +1 -0
- package/dist/internal/skill-refinement/evals/cases.js +143 -0
- package/dist/internal/skill-refinement/evals/cases.js.map +1 -0
- package/dist/internal/skill-refinement/evals/opus-action-judge-original.json +350 -0
- package/dist/internal/skill-refinement/evals/opus-judge-original.json +165 -0
- package/dist/internal/skill-refinement/feedback/import-legacy.js +13 -0
- package/dist/internal/skill-refinement/feedback/import-legacy.js.map +1 -0
- package/dist/internal/skill-refinement/feedback/intake.js +52 -0
- package/dist/internal/skill-refinement/feedback/intake.js.map +1 -0
- package/dist/internal/skill-refinement/feedback/managed-intake.js +19 -0
- package/dist/internal/skill-refinement/feedback/managed-intake.js.map +1 -0
- package/dist/internal/skill-refinement/feedback/outbox.js +44 -0
- package/dist/internal/skill-refinement/feedback/outbox.js.map +1 -0
- package/dist/internal/skill-refinement/jev/impl.js +63 -0
- package/dist/internal/skill-refinement/jev/impl.js.map +1 -0
- package/dist/internal/skill-refinement/jev/interface.js +6 -0
- package/dist/internal/skill-refinement/jev/interface.js.map +1 -0
- package/dist/internal/skill-refinement/managed-daemon.js +30 -0
- package/dist/internal/skill-refinement/managed-daemon.js.map +1 -0
- package/dist/internal/skill-refinement/managed-worker-credentials.js +60 -0
- package/dist/internal/skill-refinement/managed-worker-credentials.js.map +1 -0
- package/dist/internal/skill-refinement/managed-worker-files.js +25 -0
- package/dist/internal/skill-refinement/managed-worker-files.js.map +1 -0
- package/dist/internal/skill-refinement/managed-worker-loop.js +36 -0
- package/dist/internal/skill-refinement/managed-worker-loop.js.map +1 -0
- package/dist/internal/skill-refinement/organization-site.js +13 -0
- package/dist/internal/skill-refinement/organization-site.js.map +1 -0
- package/dist/internal/skill-refinement/paths.js +62 -0
- package/dist/internal/skill-refinement/paths.js.map +1 -0
- package/dist/internal/skill-refinement/platform.js +67 -0
- package/dist/internal/skill-refinement/platform.js.map +1 -0
- package/dist/internal/skill-refinement/service.js +365 -0
- package/dist/internal/skill-refinement/service.js.map +1 -0
- package/dist/internal/skill-refinement/skills/skill-text.js +219 -0
- package/dist/internal/skill-refinement/skills/skill-text.js.map +1 -0
- package/dist/internal/skill-refinement/workflow/retry.js +44 -0
- package/dist/internal/skill-refinement/workflow/retry.js.map +1 -0
- package/dist/internal/skill-refinement/workflow/skill-refinement.js +690 -0
- package/dist/internal/skill-refinement/workflow/skill-refinement.js.map +1 -0
- package/dist/internal/skill-refinement/writer/impl.js +2 -0
- package/dist/internal/skill-refinement/writer/impl.js.map +1 -0
- package/dist/internal/skill-refinement/writer/interface.js +2 -0
- package/dist/internal/skill-refinement/writer/interface.js.map +1 -0
- package/dist/internal/sync.js +182 -0
- package/dist/internal/sync.js.map +1 -0
- package/dist/internal/wire.js +31 -0
- package/dist/internal/wire.js.map +1 -0
- package/dist/internal/writer/claude.js +84 -0
- package/dist/internal/writer/claude.js.map +1 -0
- package/dist/internal/writer/codex.js +102 -0
- package/dist/internal/writer/codex.js.map +1 -0
- package/dist/internal/writer/interface.js +6 -0
- package/dist/internal/writer/interface.js.map +1 -0
- package/dist/internal/writer/live.js +13 -0
- package/dist/internal/writer/live.js.map +1 -0
- package/dist/internal/writer/reset.js +38 -0
- package/dist/internal/writer/reset.js.map +1 -0
- package/dist/internal/writer/selection.js +79 -0
- package/dist/internal/writer/selection.js.map +1 -0
- package/package.json +45 -11
- package/postinstall.cjs +663 -0
- package/src/daemons/skill-sync-daemon.ts +677 -0
- package/src/entrypoints/skill-sync.ts +12 -0
- package/src/index.ts +15 -0
- package/src/internal/agents/agent-tool.ts +149 -0
- package/src/internal/agents/claude.ts +442 -0
- package/src/internal/agents/codex.ts +288 -0
- package/src/internal/agents/command.ts +257 -0
- package/src/internal/agents/grok.ts +174 -0
- package/src/internal/agents/index.ts +74 -0
- package/src/internal/cli.ts +249 -0
- package/src/internal/comment-watch/held.ts +20 -0
- package/src/internal/comment-watch/key.ts +5 -0
- package/src/internal/comment-watch/message.ts +39 -0
- package/src/internal/comment-watch/paths.ts +17 -0
- package/src/internal/comment-watch/platform.ts +69 -0
- package/src/internal/comment-watch/protocol.ts +140 -0
- package/src/internal/comment-watch/recent.ts +26 -0
- package/src/internal/comment-watch/replies.ts +28 -0
- package/src/internal/comment-watch/service.ts +198 -0
- package/src/internal/comment-watch/settings.ts +82 -0
- package/src/internal/comment-watch/source/github-pull-requests/conversations.ts +111 -0
- package/src/internal/comment-watch/source/github-pull-requests/impl.ts +291 -0
- package/src/internal/comment-watch/source/github-pull-requests/queries.ts +113 -0
- package/src/internal/comment-watch/source/google-doc/doc.ts +76 -0
- package/src/internal/comment-watch/source/google-doc/impl.ts +198 -0
- package/src/internal/comment-watch/source/http-api.ts +93 -0
- package/src/internal/comment-watch/source/interface.ts +116 -0
- package/src/internal/comment-watch/source/sign-in.ts +45 -0
- package/src/internal/comment-watch/source/sources.ts +20 -0
- package/src/internal/comment-watch/store/impl.ts +268 -0
- package/src/internal/comment-watch/store/interface.ts +83 -0
- package/src/internal/comment-watch/t3.ts +68 -0
- package/src/internal/comment-watch/watching.ts +122 -0
- package/src/internal/comment-watch/workflow/comment-watch.ts +34 -0
- package/src/internal/comment-watch/workflow/deliver.ts +115 -0
- package/src/internal/comment-watch/workflow/find.ts +78 -0
- package/src/internal/comment-watch/workflow/post-once.ts +72 -0
- package/src/internal/comment-watch/workflow/post.ts +56 -0
- package/src/internal/config.ts +172 -0
- package/src/internal/control.ts +165 -0
- package/src/internal/daemon-control/impl.ts +94 -0
- package/src/internal/daemon-control/interface.ts +46 -0
- package/src/internal/folders.ts +50 -0
- package/src/internal/local-skills.ts +58 -0
- package/src/internal/path.ts +32 -0
- package/src/internal/server.ts +76 -0
- package/src/internal/skill-check.ts +97 -0
- package/src/internal/skill-refinement/evals/cases.ts +167 -0
- package/src/internal/skill-refinement/evals/opus-action-judge-original.json +350 -0
- package/src/internal/skill-refinement/evals/opus-judge-original.json +165 -0
- package/src/internal/skill-refinement/feedback/import-legacy.ts +16 -0
- package/src/internal/skill-refinement/feedback/intake.ts +66 -0
- package/src/internal/skill-refinement/feedback/managed-intake.ts +19 -0
- package/src/internal/skill-refinement/feedback/outbox.ts +50 -0
- package/src/internal/skill-refinement/jev/impl.ts +76 -0
- package/src/internal/skill-refinement/jev/interface.ts +56 -0
- package/src/internal/skill-refinement/managed-daemon.ts +38 -0
- package/src/internal/skill-refinement/managed-worker-credentials.ts +59 -0
- package/src/internal/skill-refinement/managed-worker-files.ts +24 -0
- package/src/internal/skill-refinement/managed-worker-loop.ts +46 -0
- package/src/internal/skill-refinement/organization-site.ts +15 -0
- package/src/internal/skill-refinement/paths.ts +87 -0
- package/src/internal/skill-refinement/platform.ts +71 -0
- package/src/internal/skill-refinement/service.ts +418 -0
- package/src/internal/skill-refinement/skills/skill-text.ts +292 -0
- package/src/internal/skill-refinement/workflow/retry.ts +61 -0
- package/src/internal/skill-refinement/workflow/skill-refinement.ts +777 -0
- package/src/internal/skill-refinement/writer/impl.ts +1 -0
- package/src/internal/skill-refinement/writer/interface.ts +1 -0
- package/src/internal/sync.ts +216 -0
- package/src/internal/wire.ts +439 -0
- package/src/internal/writer/claude.ts +98 -0
- package/src/internal/writer/codex.ts +93 -0
- package/src/internal/writer/interface.ts +48 -0
- package/src/internal/writer/live.ts +19 -0
- package/src/internal/writer/reset.ts +34 -0
- package/src/internal/writer/selection.ts +84 -0
- package/multi-call-binary +0 -4
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE COMMENT WATCH ON THE WORKFLOW PLATFORM: the facts the platform cannot know about it, and where its records live, a
|
|
3
|
+
* database and an engine of its own beside skill refinement's.
|
|
4
|
+
*/
|
|
5
|
+
import { createWorkflowPlatform, sqliteStorage } from '@jive-sh/workflow-platform';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { CODE_ROOT, watchDatabase, watchEngineDatabase, watchTexts } from './paths';
|
|
10
|
+
const runLightNow = (command, options) => {
|
|
11
|
+
const r = Bun.spawnSync([...command], { stdout: 'pipe', stderr: 'pipe', ...(options?.env === undefined ? {} : { env: { ...process.env, ...options.env } }) });
|
|
12
|
+
return { code: r.exitCode, stdout: r.stdout.toString(), stdoutBytes: new Uint8Array(r.stdout), stderr: r.stderr.toString() };
|
|
13
|
+
};
|
|
14
|
+
/** When a process started, in unix seconds, as `ps` reports it; none for a process that is gone. */
|
|
15
|
+
const startedAtOf = (pid) => {
|
|
16
|
+
const r = runLightNow(['ps', '-o', 'lstart=', '-p', String(pid)]);
|
|
17
|
+
const at = Date.parse(r.stdout.trim());
|
|
18
|
+
return r.code === 0 && !Number.isNaN(at) ? Math.floor(at / 1000) : null;
|
|
19
|
+
};
|
|
20
|
+
let self = null;
|
|
21
|
+
const thisProcess = () => {
|
|
22
|
+
self ??= { pid: process.pid, startedAt: startedAtOf(process.pid) ?? Math.floor(Date.now() / 1000) };
|
|
23
|
+
return self;
|
|
24
|
+
};
|
|
25
|
+
const isAlive = (p) => startedAtOf(p.pid) === p.startedAt;
|
|
26
|
+
/** Texts by content hash, one file each: each reply's. */
|
|
27
|
+
export const textStore = (folder) => ({
|
|
28
|
+
write: (text) => {
|
|
29
|
+
const sha = new Bun.CryptoHasher('sha256').update(text).digest('hex');
|
|
30
|
+
fs.mkdirSync(folder, { recursive: true });
|
|
31
|
+
const file = path.join(folder, sha);
|
|
32
|
+
if (!fs.existsSync(file)) {
|
|
33
|
+
fs.writeFileSync(`${file}.new`, text);
|
|
34
|
+
fs.renameSync(`${file}.new`, file);
|
|
35
|
+
}
|
|
36
|
+
return sha;
|
|
37
|
+
},
|
|
38
|
+
read: (sha) => {
|
|
39
|
+
const text = fs.readFileSync(path.join(folder, sha), 'utf8');
|
|
40
|
+
if (new Bun.CryptoHasher('sha256').update(text).digest('hex') !== sha)
|
|
41
|
+
throw new Error(`text ${sha} does not match its hash`);
|
|
42
|
+
return text;
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
export const commentWatchPlatform = (folder) => {
|
|
46
|
+
fs.mkdirSync(folder, { recursive: true });
|
|
47
|
+
return createWorkflowPlatform({
|
|
48
|
+
project: {
|
|
49
|
+
sourceRoot: CODE_ROOT,
|
|
50
|
+
tree: { root: folder, snapshots: path.join(folder, 'step-files'), notTree: [] },
|
|
51
|
+
texts: textStore(watchTexts(folder)),
|
|
52
|
+
runLightNow,
|
|
53
|
+
processes: { thisProcess, isAlive },
|
|
54
|
+
stepRecordVariable: 'COMMENT_WATCH_STEP_RECORD',
|
|
55
|
+
isTransientFailure: (e) => String(e).includes('database is locked'),
|
|
56
|
+
cpu: { limit: () => os.cpus().length, newestUse: () => null },
|
|
57
|
+
},
|
|
58
|
+
storage: sqliteStorage({
|
|
59
|
+
stepRecordsFile: () => watchDatabase(folder),
|
|
60
|
+
engineFile: () => watchEngineDatabase(folder),
|
|
61
|
+
budgetsFile: () => watchDatabase(folder),
|
|
62
|
+
processes: { thisProcess, isAlive },
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../../../../../src/internal/comment-watch/platform.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAA0D,MAAM,4BAA4B,CAAC;AAC3I,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEpF,MAAM,WAAW,GAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;IACpD,MAAM,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,GAAG,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;IAC9J,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;AAC/H,CAAC,CAAC;AAEF,oGAAoG;AACpG,MAAM,WAAW,GAAG,CAAC,GAAW,EAAiB,EAAE;IACjD,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAA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AAC,CAAC,QAAQ,CAAC,oBAAoB,CAAC;YACnE,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE;SAC9D;QACD,OAAO,EAAE,aAAa,CAAC;YACrB,eAAe,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC;YAC5C,UAAU,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,MAAM,CAAC;YAC7C,WAAW,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC;YACxC,SAAS,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE;SACpC,CAAC;KACH,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE PROTOCOL BETWEEN A PERSON AND THE AGENTS THAT ANSWER FROM THEIR ACCOUNT, the same wherever a comment is left. Both post
|
|
3
|
+
* as one account, so what a post says is the only way to tell who wrote it:
|
|
4
|
+
*
|
|
5
|
+
* an agent's post starts with 🤖:, and is never an order, whatever else it says;
|
|
6
|
+
* on a pull request, a comment of theirs is for the agent when it tags it (`@clanker`), and only then;
|
|
7
|
+
* a change waits: the agent posts a plan of its own, **Plan**, and makes it once they approve it.
|
|
8
|
+
*
|
|
9
|
+
* Nothing this posts or delivers holds the bare tag: on GitHub it notifies whoever has that login, and in a post it would be
|
|
10
|
+
* an order to itself. All of it is pure.
|
|
11
|
+
*/
|
|
12
|
+
/** What every agent's post starts with. */
|
|
13
|
+
export const AGENT_PREFIX = '🤖:';
|
|
14
|
+
/** What a plan's text starts with, after its opening. */
|
|
15
|
+
export const PLAN = '**Plan**';
|
|
16
|
+
/** What code posts, after the opening, where a plan is approved; the agent edits it into its "Done in". */
|
|
17
|
+
export const ACKNOWLEDGEMENT = 'Plan is approved, working on it...';
|
|
18
|
+
/** What code shows on a comment as soon as it is queued, until it is answered: a reaction, or where there is none a reply. */
|
|
19
|
+
export const EYES = '👀';
|
|
20
|
+
export const EYES_REPLY = `${AGENT_PREFIX} ${EYES}`;
|
|
21
|
+
export const DEFAULT_TAG = 'clanker';
|
|
22
|
+
/** What another automation on the same account replies where it has seen a comment in a Doc, as this one shows 👀. */
|
|
23
|
+
export const SEEN_ELSEWHERE = '...';
|
|
24
|
+
const ACKNOWLEDGEMENT_LINE = '<!-- skill-sync comment-watch: plan approval ';
|
|
25
|
+
/** How the daemon that posted the first acknowledgements began the line. */
|
|
26
|
+
const EARLIER_ACKNOWLEDGEMENT_LINE = '<!-- pr-comment-daemon: plan approval ';
|
|
27
|
+
/**
|
|
28
|
+
* The hidden line an acknowledgement on GitHub ends with, before and after the agent's edit: how it is found again, so it is
|
|
29
|
+
* never posted twice, and how it is told from a plan or an answer.
|
|
30
|
+
*/
|
|
31
|
+
export const acknowledgementLine = (approval) => `${ACKNOWLEDGEMENT_LINE}${approval} -->`;
|
|
32
|
+
/** Whether a post holds an approval's hidden line, as it is written now or as the earlier daemon wrote it. */
|
|
33
|
+
export const holdsAcknowledgementLine = (input) => input.text.includes(input.line) || input.text.includes(input.line.replace(ACKNOWLEDGEMENT_LINE, EARLIER_ACKNOWLEDGEMENT_LINE));
|
|
34
|
+
export const isAcknowledgement = (text) => text.includes(ACKNOWLEDGEMENT_LINE) || text.includes(EARLIER_ACKNOWLEDGEMENT_LINE) || afterOpening(text).startsWith(ACKNOWLEDGEMENT);
|
|
35
|
+
/** Whether an agent wrote a post: one that starts with 🤖:, or is exactly another automation's "...". */
|
|
36
|
+
export const isAgents = (text) => text.trimStart().startsWith(AGENT_PREFIX) || text.trim() === SEEN_ELSEWHERE;
|
|
37
|
+
/** An agent's words, without the 🤖: and, where it opens with one, the link to what it answers. */
|
|
38
|
+
const afterOpening = (text) => {
|
|
39
|
+
const words = text.trimStart().slice(AGENT_PREFIX.length).trimStart();
|
|
40
|
+
return text.trimStart().startsWith(AGENT_PREFIX) ? (words.startsWith('https://') ? words.replace(/^\S+\s*/, '') : words) : '';
|
|
41
|
+
};
|
|
42
|
+
/** Whether a post is this watch's 👀 reply: one only it posts, and deletes. */
|
|
43
|
+
export const isEyes = (text) => afterOpening(text).trim() === EYES;
|
|
44
|
+
/** Whether a post only says that a comment was received, by this watch or another automation: no answer to it. */
|
|
45
|
+
export const isReceipt = (text) => isEyes(text) || text.trim() === SEEN_ELSEWHERE;
|
|
46
|
+
/**
|
|
47
|
+
* Whether a post is a plan. A plan is its own reply, starting **Plan**; a line starting so further down counts too, since an
|
|
48
|
+
* approval of a plan put after an answer must still reach the agent.
|
|
49
|
+
*/
|
|
50
|
+
export const isPlan = (text) => isAgents(text) && !isAcknowledgement(text) && afterOpening(text).split('\n').some((line) => line.startsWith(PLAN));
|
|
51
|
+
/** Whether a reply of theirs approves the plan above it, where the place has no 👍. */
|
|
52
|
+
export const isYes = (text) => /^yes[.!]*$/i.test(text.trim());
|
|
53
|
+
const escaped = (s) => s.replace(/[.*+?^$()|[\]\\{}]/g, '\\$&');
|
|
54
|
+
/**
|
|
55
|
+
* A comment's own words as Markdown shows them: no quoted line, no code (fenced, indented, in backticks, in `<code>` or
|
|
56
|
+
* `<pre>`), no HTML comment. What is cut leaves a space, so the words around it stay apart.
|
|
57
|
+
*/
|
|
58
|
+
export const ownWords = (text) => {
|
|
59
|
+
const kept = [];
|
|
60
|
+
let fence = null;
|
|
61
|
+
let previous = '';
|
|
62
|
+
let inCode = false;
|
|
63
|
+
for (const line of text.replace(/\r\n?/g, '\n').replace(/<!--[\s\S]*?(?:-->|$)/g, ' ').replace(/<(pre|code)\b[^>]*>[\s\S]*?(?:<\/\1>|$)/gi, ' ').split('\n')) {
|
|
64
|
+
const mark = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line);
|
|
65
|
+
if (fence !== null) {
|
|
66
|
+
if (mark !== null && mark[1].startsWith(fence) && mark[2].trim() === '')
|
|
67
|
+
fence = null;
|
|
68
|
+
kept.push('');
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
// A backtick fence's first line holds no other backtick: with one it is a code span in a sentence.
|
|
72
|
+
if (mark !== null && !(mark[1].startsWith('`') && mark[2].includes('`'))) {
|
|
73
|
+
fence = mark[1];
|
|
74
|
+
kept.push('');
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const quoted = /^ {0,3}>/.test(line);
|
|
78
|
+
// Four spaces start a code block after a blank line, never in a list, where they go on with an item.
|
|
79
|
+
const indented = /^(?: {4}|\t)/.test(line) && line.trim() !== '' && (inCode || (previous.trim() === '' && !lastWordsAreAList(kept)));
|
|
80
|
+
inCode = indented || (inCode && line.trim() === '');
|
|
81
|
+
previous = line;
|
|
82
|
+
kept.push(quoted || indented ? '' : line);
|
|
83
|
+
}
|
|
84
|
+
// A code span ends at as many backticks as it starts with, in the same paragraph.
|
|
85
|
+
return kept.join('\n').split(/\n[ \t]*\n/).map((paragraph) => paragraph.replace(/(?<!`)(`+)(?!`)([\s\S]*?[^`])\1(?!`)/g, ' ')).join('\n\n');
|
|
86
|
+
};
|
|
87
|
+
const lastWordsAreAList = (lines) => {
|
|
88
|
+
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
|
89
|
+
const line = lines[i];
|
|
90
|
+
if (line.trim() === '')
|
|
91
|
+
continue;
|
|
92
|
+
if (/^ {0,3}(?:[-*+]|\d{1,9}[.)])\s/.test(line))
|
|
93
|
+
return true;
|
|
94
|
+
// A line of an item's own text: the item is further up.
|
|
95
|
+
if (!/^(?: {2,}|\t)/.test(line))
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
};
|
|
100
|
+
/** Whether text tags the agent: the whole name after an @ that starts a word, in any case, in its own words. */
|
|
101
|
+
export const isTagged = (input) => new RegExp(`(?<![\\p{L}\\p{N}/@]|[\\p{L}\\p{N}]_)@${escaped(input.tag)}(?![\\p{L}\\p{N}]|[-_./@][\\p{L}\\p{N}])`, 'iu').test(ownWords(input.text));
|
|
102
|
+
/** Whether a comment of theirs is for the agent, where it has to say so. An agent's post never is. */
|
|
103
|
+
export const isOrder = (input) => !isAgents(input.text) && isTagged(input);
|
|
104
|
+
/** Text with the agent's name in place of its tag, however the @ is written: what is posted, and what is delivered. */
|
|
105
|
+
export const withoutTag = (input) => input.text.replace(new RegExp(`(?:@|�*64;|�*40;|@)+(?=${escaped(input.tag)})`, 'gi'), '');
|
|
106
|
+
/** An agent's words as they are posted: 🤖:, the link to what they answer where the place doesn't thread replies, the words. */
|
|
107
|
+
export const asAgents = (input) => {
|
|
108
|
+
const words = input.text.trim().replace(new RegExp(`^(?:${AGENT_PREFIX}\\s*)+`, 'u'), '');
|
|
109
|
+
return withoutTag({ text: [AGENT_PREFIX, ...(input.opening === null || words.startsWith(input.opening) ? [] : [input.opening]), words].join(' '), tag: input.tag });
|
|
110
|
+
};
|
|
111
|
+
/** Why a reply is not one the protocol lets an agent post; none where it is. */
|
|
112
|
+
export const replyRefusal = (text) => {
|
|
113
|
+
const words = text.trim().replace(new RegExp(`^(?:${AGENT_PREFIX}\\s*)+`, 'u'), '');
|
|
114
|
+
if (words === '')
|
|
115
|
+
return 'it is empty';
|
|
116
|
+
const lines = words.split('\n');
|
|
117
|
+
return !words.startsWith(PLAN) && lines.some((line) => line.startsWith(PLAN)) ? `a plan is a reply of its own, starting ${PLAN}: post the answer first, then the plan` : null;
|
|
118
|
+
};
|
|
119
|
+
/** Two posts' words as a service may have given them back: formatting marks and spacing apart. */
|
|
120
|
+
export const sameWords = (a, b) => {
|
|
121
|
+
const plain = (t) => t.normalize('NFC').replace(/[\s*_~`️]+/gu, '');
|
|
122
|
+
return plain(a) === plain(b);
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../../../src/internal/comment-watch/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;A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AO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;AACtK,CAAC,CAAC;AAEF,gFAAgF;AAChF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAY,EAAiB,EAAE;IAC1D,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,YAAY,QAAQ,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IACpF,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,aAAa,CAAC;IACvC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,0CAA0C,IAAI,wCAAwC,CAAC,CAAC,CAAC,IAAI,CAAC;AAChL,CAAC,CAAC;AAEF,kGAAkG;AAClG,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAS,EAAE,CAAS,EAAW,EAAE;IACzD,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;IAC7E,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** What was marked a moment ago, for as long as a window lasts: each mark forgets every one older than that, so none is kept on. */
|
|
2
|
+
export class Recent {
|
|
3
|
+
window;
|
|
4
|
+
at = new Map();
|
|
5
|
+
/** `window` is in the unit the clock given to each call counts in. */
|
|
6
|
+
constructor(window) {
|
|
7
|
+
this.window = window;
|
|
8
|
+
}
|
|
9
|
+
mark(input) {
|
|
10
|
+
for (const [item, at] of this.at)
|
|
11
|
+
if (at <= input.now - this.window)
|
|
12
|
+
this.at.delete(item);
|
|
13
|
+
this.at.set(input.item, input.now);
|
|
14
|
+
}
|
|
15
|
+
isRecent(input) {
|
|
16
|
+
const at = this.at.get(input.item);
|
|
17
|
+
return at !== undefined && at > input.now - this.window;
|
|
18
|
+
}
|
|
19
|
+
forget(item) {
|
|
20
|
+
this.at.delete(item);
|
|
21
|
+
}
|
|
22
|
+
/** How many are kept now. */
|
|
23
|
+
get size() {
|
|
24
|
+
return this.at.size;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=recent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recent.js","sourceRoot":"","sources":["../../../../../src/internal/comment-watch/recent.ts"],"names":[],"mappings":"AAAA,oIAAoI;AACpI,MAAM,OAAO,MAAM;IAIY;IAHZ,EAAE,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEhD,sEAAsE;IACtE,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C,IAAI,CAAC,KAAsD;QACzD,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,EAAE;YAAE,IAAI,EAAE,IAAI,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM;gBAAE,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC1F,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IAED,QAAQ,CAAC,KAAsD;QAC7D,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACnC,OAAO,EAAE,KAAK,SAAS,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC;IAC1D,CAAC;IAED,MAAM,CAAC,IAAY;QACjB,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,6BAA6B;IAC7B,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** WHAT AN ANSWERING THREAD HANDS BACK with `skill-sync reply`: its words, made into a post the protocol lets it make, and kept to be posted once. */
|
|
2
|
+
import { Effect, Option } from 'effect';
|
|
3
|
+
import { asAgents, replyRefusal } from './protocol';
|
|
4
|
+
import { acknowledgementText } from './workflow/deliver';
|
|
5
|
+
/** Keeps an agent's words for an event as a post to be made, or says why they are not one. */
|
|
6
|
+
export const handOver = (deps) => (input) => Effect.gen(function* () {
|
|
7
|
+
const { store, tag, now } = deps;
|
|
8
|
+
const found = yield* store.event(input.key);
|
|
9
|
+
if (Option.isNone(found))
|
|
10
|
+
return { refused: `${input.key} is no comment this machine was told of` };
|
|
11
|
+
const event = found.value;
|
|
12
|
+
const approved = event.kind === 'plan approved';
|
|
13
|
+
// The "Done in" of a plan they approved is still its own; any other reply waits for what they say after a 👎.
|
|
14
|
+
if (event.kind === 'plan rejected' || (!approved && store.standsRejected(event.key)))
|
|
15
|
+
return { refused: 'the plan was rejected: change nothing and post nothing until their next comment there' };
|
|
16
|
+
const why = replyRefusal(input.text);
|
|
17
|
+
if (why !== null)
|
|
18
|
+
return { refused: why };
|
|
19
|
+
const text = approved ? acknowledgementText({ event, text: input.text, tag }) : asAgents({ text: input.text, opening: event.opening, tag });
|
|
20
|
+
const source = deps.sources.find((s) => s.id === event.source);
|
|
21
|
+
if (source === undefined)
|
|
22
|
+
return { refused: `this machine no longer watches ${event.url}` };
|
|
23
|
+
const bytes = Buffer.byteLength(text);
|
|
24
|
+
if (Option.isSome(source.maxPostBytes) && bytes > source.maxPostBytes.value)
|
|
25
|
+
return { refused: `it is ${bytes} bytes as posted, and no more than ${source.maxPostBytes.value} can be` };
|
|
26
|
+
return { id: yield* store.addPost({ key: event.key, purpose: approved ? 'edit' : 'reply', text, at: now() }) };
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=replies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replies.js","sourceRoot":"","sources":["../../../../../src/internal/comment-watch/replies.ts"],"names":[],"mappings":"AAAA,sJAAsJ;AACtJ,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAIzD,8FAA8F;AAC9F,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAA0I,EAAE,EAAE,CACrK,CAAC,KAAsD,EAA0C,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IACtH,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACjC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,GAAG,yCAAyC,EAAE,CAAC;IACpG,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC1B,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,KAAK,eAAe,CAAC;IAChD,8GAA8G;IAC9G,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,IAAI,CAAC,CAAC,QAAQ,IAAI,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,GAA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AE,CAAC,EAAE,CAAC;AACjH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE COMMENT WATCH'S RUNNER: hosts its workflows' engine inside the skill-sync daemon, on a machine whose settings name
|
|
3
|
+
* something to watch, and starts their runs. Find runs each turn of its schedule and as the daemon starts. Deliver and Post
|
|
4
|
+
* run while something waits in their queues: one run of each at a time, the next as the last ends.
|
|
5
|
+
*/
|
|
6
|
+
import { SqliteClient } from '@effect/sql-sqlite-bun';
|
|
7
|
+
import { describeFailure, newRunId, oneTurnAtATime, queueOrder, SET_WORKFLOW_RUNS_SQL, START_LIMIT_SECONDS, TURN_LIMIT_MS, WORKFLOW_BUDGET_SQL, } from '@jive-sh/workflow-platform';
|
|
8
|
+
import { Database } from 'bun:sqlite';
|
|
9
|
+
import { Crypto, Duration, Effect, Layer, ManagedRuntime, Option, pipe } from 'effect';
|
|
10
|
+
import { ClusterWorkflowEngine, RunnerAddress, SingleRunner } from 'effect/cluster';
|
|
11
|
+
import { FetchHttpClient, HttpClient } from 'effect/http';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { liveWriters } from '../writer/live';
|
|
14
|
+
import { locateSkillCopy } from '../skill-refinement/paths';
|
|
15
|
+
import { heldIn } from './held';
|
|
16
|
+
import { Recent } from './recent';
|
|
17
|
+
import { commentWatchPlatform } from './platform';
|
|
18
|
+
import { t3File, watchDatabase, watchEngineDatabase, watchFolder, watchHeld } from './paths';
|
|
19
|
+
import { handOver } from './replies';
|
|
20
|
+
import { readSettings } from './settings';
|
|
21
|
+
import { CommandSignIn } from './source/sign-in';
|
|
22
|
+
import { sourcesOf } from './source/sources';
|
|
23
|
+
import { SqliteCommentStore } from './store/impl';
|
|
24
|
+
import { defineCommentWatch } from './workflow/comment-watch';
|
|
25
|
+
import { DELIVER_WORKFLOW } from './workflow/deliver';
|
|
26
|
+
import { FIND_WORKFLOW } from './workflow/find';
|
|
27
|
+
import { POST_WORKFLOW } from './workflow/post';
|
|
28
|
+
import { readT3Settings, T3 } from './t3';
|
|
29
|
+
import { watchedPlace } from './watching';
|
|
30
|
+
/** How often every source is read. */
|
|
31
|
+
export const FIND_EVERY_SECONDS = 30;
|
|
32
|
+
/** Less than a turn, so each turn tries again. */
|
|
33
|
+
const REST_SECONDS = FIND_EVERY_SECONDS - 5;
|
|
34
|
+
/** How long `skill-sync reply` waits for its post to be made before it says it is still waiting. */
|
|
35
|
+
const REPLY_WAIT_MS = 25_000;
|
|
36
|
+
/** Bun's WebCrypto, as the cluster's message storage needs it. */
|
|
37
|
+
const CryptoLive = Layer.succeed(Crypto.Crypto, Crypto.make({
|
|
38
|
+
randomBytes: (size) => globalThis.crypto.getRandomValues(new Uint8Array(size)),
|
|
39
|
+
digest: (algorithm, data) => Effect.promise(async () => new Uint8Array(await globalThis.crypto.subtle.digest(algorithm, new Uint8Array(data)))),
|
|
40
|
+
}));
|
|
41
|
+
/** One run of each at a time: a read overlapping the last would only read the same stretch twice. Set once, never changed here. */
|
|
42
|
+
const ensureLimits = (folder) => {
|
|
43
|
+
const db = new Database(watchDatabase(folder), { create: true });
|
|
44
|
+
try {
|
|
45
|
+
db.run('CREATE TABLE IF NOT EXISTS workflow_budgets (workflow TEXT PRIMARY KEY, budget INTEGER NOT NULL, runs INTEGER, changed_at REAL NOT NULL)');
|
|
46
|
+
for (const workflow of [FIND_WORKFLOW, DELIVER_WORKFLOW, POST_WORKFLOW])
|
|
47
|
+
if (db.query(WORKFLOW_BUDGET_SQL).get(workflow) === null)
|
|
48
|
+
db.query(SET_WORKFLOW_RUNS_SQL).run(workflow, 1, Date.now() / 1000);
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
db.close();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/** The watch on one folder and its sources; a test gives sources over fakes. */
|
|
55
|
+
export const makeCommentWatch = (input) => {
|
|
56
|
+
const { folder, sources, told, tag } = input;
|
|
57
|
+
const platform = commentWatchPlatform(folder);
|
|
58
|
+
ensureLimits(folder);
|
|
59
|
+
const store = new SqliteCommentStore(new Database(watchDatabase(folder)), heldIn(watchHeld(folder)));
|
|
60
|
+
const now = input.now ?? (() => Date.now() / 1000);
|
|
61
|
+
const said = (what) => (e) => console.error(`[comment watch] ${what}: ${describeFailure(e)}`);
|
|
62
|
+
/** What could not be done a moment ago, and when: it is tried again once a turn, not as soon as its run ends. */
|
|
63
|
+
const resting = new Recent(REST_SECONDS);
|
|
64
|
+
const watch = defineCommentWatch({ platform, sources, store, told, tag, now, rests: (item) => { resting.mark({ item, now: now() }); }, onQueued: () => { void deliver().catch(said('what was found could not be delivered')); } });
|
|
65
|
+
const runtime = ManagedRuntime.make(pipe(
|
|
66
|
+
// The platform's own workflows (Retention) run in the same engine.
|
|
67
|
+
Layer.mergeAll(watch.layer, platform.system.layer), Layer.provideMerge(ClusterWorkflowEngine.layer), Layer.provideMerge(SingleRunner.layer({
|
|
68
|
+
runnerStorage: 'sql',
|
|
69
|
+
shardingConfig: { runnerAddress: Option.some(RunnerAddress.make('comment-watch', process.pid)), entityTerminationTimeout: Duration.minutes(10) },
|
|
70
|
+
})), Layer.provideMerge(SqliteClient.layer({ filename: watchEngineDatabase(folder), busyTimeout: Duration.seconds(1) })), Layer.provideMerge(CryptoLive)));
|
|
71
|
+
const start = (workflow, payload) => {
|
|
72
|
+
const declaration = platform.steps.declaredWorkflows().find((d) => d.name === workflow);
|
|
73
|
+
return runtime.runPromise(Effect.timeout(declaration.startOn(payload, { wait: false }), `${START_LIMIT_SECONDS} seconds`));
|
|
74
|
+
};
|
|
75
|
+
/** Starts one Find. A turn is the time it starts: numbered from 1 each time the daemon starts, a turn already run would start nothing. */
|
|
76
|
+
const find = () => start(FIND_WORKFLOW, { turn: Date.now() });
|
|
77
|
+
/** Starts a run of a workflow where something waits in its queue and no run of it is going. */
|
|
78
|
+
const keepGoing = (workflow, label, work) => oneTurnAtATime(async (stillCurrent) => {
|
|
79
|
+
const items = (await Effect.runPromise(work())).filter((item) => !resting.isRecent({ item, now: now() }));
|
|
80
|
+
await Effect.runPromise(platform.tasks.recordListing({ workflow, work: { lines: [{ label, items }], waits: [] }, everyItem: false }));
|
|
81
|
+
if (queueOrder(await Effect.runPromise(platform.tasks.taskSummaries({ workflow }))).length === 0)
|
|
82
|
+
return;
|
|
83
|
+
if (await Effect.runPromise(platform.storage.engine.runningRuns(workflow)) > 0 || !stillCurrent())
|
|
84
|
+
return;
|
|
85
|
+
await start(workflow, { run: newRunId() });
|
|
86
|
+
}, TURN_LIMIT_MS);
|
|
87
|
+
const deliver = keepGoing(DELIVER_WORKFLOW, 'targets to tell', () => Effect.gen(() => store.toDeliver()));
|
|
88
|
+
const post = keepGoing(POST_WORKFLOW, 'posts to make', () => Effect.gen(() => store.toPost(now())));
|
|
89
|
+
/** Takes an agent's words for a comment, and posts them now. Gives the link, or why not; run again, it posts nothing more. */
|
|
90
|
+
const reply = async (words) => {
|
|
91
|
+
const handed = await Effect.runPromise(handOver({ store, sources, tag, now })(words));
|
|
92
|
+
if ('refused' in handed)
|
|
93
|
+
return handed;
|
|
94
|
+
const until = Date.now() + REPLY_WAIT_MS;
|
|
95
|
+
for (;;) {
|
|
96
|
+
await post();
|
|
97
|
+
const made = await Effect.runPromise(Effect.gen(() => store.post({ id: handed.id, now: now() })));
|
|
98
|
+
if (made.refused !== null)
|
|
99
|
+
return { refused: made.refused };
|
|
100
|
+
if (Option.isSome(made.posted))
|
|
101
|
+
return { posted: made.posted.value.url };
|
|
102
|
+
if (Date.now() > until)
|
|
103
|
+
return { waiting: 'it is kept, and is posted as soon as it can be' };
|
|
104
|
+
await Bun.sleep(250);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
return { platform, store, runtime, find, deliver, post, reply };
|
|
108
|
+
};
|
|
109
|
+
/** A watch that watches nothing, and why. */
|
|
110
|
+
export const watchingNothing = (input) => ({
|
|
111
|
+
notWatching: input.why, watching: async () => input.watching, reply: async () => ({ refused: `this machine watches nothing: ${input.why}` }),
|
|
112
|
+
});
|
|
113
|
+
/**
|
|
114
|
+
* The watch as the daemon starts it. What is asked of it meanwhile waits for it: an agent was told a refusal is final, so a
|
|
115
|
+
* reply sent as the daemon starts must not be refused for that. A start that fails watches nothing, and says why.
|
|
116
|
+
*/
|
|
117
|
+
export const startedCommentWatch = (starting) => {
|
|
118
|
+
const started = starting.catch((cause) => {
|
|
119
|
+
const reason = `it could not start: ${describeFailure(cause)}`;
|
|
120
|
+
return watchingNothing({ why: reason, watching: { state: 'not watching', reason } });
|
|
121
|
+
});
|
|
122
|
+
return { started, watching: async () => (await started).watching(), reply: async (words) => (await started).reply(words) };
|
|
123
|
+
};
|
|
124
|
+
/** Starts the watch on what the machine's settings file names. Nothing is made on a machine whose settings name nothing. */
|
|
125
|
+
export const startCommentWatch = async (input) => {
|
|
126
|
+
const { home } = input;
|
|
127
|
+
const cannot = (reason) => watchingNothing({ why: reason, watching: { state: 'not watching', reason } });
|
|
128
|
+
const settings = await Effect.runPromise(Effect.result(readSettings(input.settingsFile)));
|
|
129
|
+
if (settings._tag === 'Failure')
|
|
130
|
+
return cannot(settings.failure);
|
|
131
|
+
if (settings.success.sources.length === 0)
|
|
132
|
+
return watchingNothing({ why: 'this machine\'s settings name nothing to watch', watching: { state: 'nothing set up' } });
|
|
133
|
+
const t3 = await Effect.runPromise(Effect.result(readT3Settings(t3File(home))));
|
|
134
|
+
// 👀 on a comment nobody can be told of would say an agent has it.
|
|
135
|
+
if (t3._tag === 'Failure')
|
|
136
|
+
return cannot(t3.failure);
|
|
137
|
+
const client = await Effect.runPromise(pipe(HttpClient.HttpClient, Effect.provide(FetchHttpClient.layer)));
|
|
138
|
+
const { tag } = settings.success;
|
|
139
|
+
const sources = sourcesOf({ settings: settings.success, client, signIn: (by) => new CommandSignIn({ ...by, home }) });
|
|
140
|
+
const folder = watchFolder(home);
|
|
141
|
+
const copy = locateSkillCopy({ home, claudeConfigDir: process.env["SKILL_REFINEMENT_CLAUDE_CONFIG_DIR"] });
|
|
142
|
+
const agents = liveWriters({ home, scratch: path.join(folder, 'agents'), claudeCommand: input.claudeCommand, claudeConfigDir: copy?.accountFolder ?? path.join(home, '.claude'), claudeModel: 'claude-opus-5-5' });
|
|
143
|
+
const told = new T3({ settings: t3.success, client, availableAgents: async () => (agents === undefined ? [] : agents.available()) });
|
|
144
|
+
const watch = makeCommentWatch({ folder, sources, told, tag });
|
|
145
|
+
// The engine starts with the runtime; a run cut off by a restart goes on from its records.
|
|
146
|
+
await watch.runtime.runPromise(Effect.void);
|
|
147
|
+
const said = (what) => (e) => console.error(`[comment watch] ${what}: ${describeFailure(e)}`);
|
|
148
|
+
const waiting = () => {
|
|
149
|
+
void watch.deliver().catch(said('what was found could not be delivered'));
|
|
150
|
+
void watch.post().catch(said('what was handed over could not be posted'));
|
|
151
|
+
};
|
|
152
|
+
const turn = () => {
|
|
153
|
+
void watch.find().catch(said('a read did not start'));
|
|
154
|
+
waiting();
|
|
155
|
+
};
|
|
156
|
+
watch.platform.steps.onRunEnded(waiting);
|
|
157
|
+
setInterval(turn, FIND_EVERY_SECONDS * 1000);
|
|
158
|
+
turn();
|
|
159
|
+
for (const w of watch.platform.system.workflows) {
|
|
160
|
+
const run = () => { void watch.runtime.runPromise(w.start(Date.now())).catch(said(`${w.name} did not start`)); };
|
|
161
|
+
setTimeout(() => { run(); setInterval(run, w.everySeconds * 1000); }, w.firstAfterSeconds * 1000);
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
notWatching: null,
|
|
165
|
+
reply: watch.reply,
|
|
166
|
+
watching: () => Effect.runPromise(Effect.gen(function* () {
|
|
167
|
+
const places = [];
|
|
168
|
+
for (const source of sources)
|
|
169
|
+
places.push(...(yield* watch.store.watched(source)).map(watchedPlace));
|
|
170
|
+
return { state: 'watching', places };
|
|
171
|
+
})),
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|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CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;IACpG,CAAC;IACD,OAAO;QACL,WAAW,EAAE,IAAI;QACjB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YACpD,MAAM,MAAM,GAA2C,EAAE,CAAC;YAC1D,KAAK,MAAM,MAAM,IAAI,OAAO;gBAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;YACrG,OAAO,EAAE,KAAK,EAAE,UAAmB,EAAE,MAAM,EAAE,CAAC;QAChD,CAAC,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHAT THIS MACHINE WATCHES, from `commentWatch` in `~/.jive/skill-sync.json`. The code knows kinds of sources and nothing
|
|
3
|
+
* about any one of them: every Doc, repository, person and T3 project is named here, on the machine that watches them.
|
|
4
|
+
*/
|
|
5
|
+
import { Effect, Schema, SchemaIssue } from 'effect';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import { DEFAULT_TAG } from './protocol';
|
|
8
|
+
const Name = Schema.NonEmptyString;
|
|
9
|
+
/** Prints an access token on its standard output: a program and its arguments, run without a shell. */
|
|
10
|
+
const TokenCommand = Schema.NonEmptyArray(Name);
|
|
11
|
+
/** A Google Doc, and which of its tabs, by id: a tab's id is immutable and its title is not. */
|
|
12
|
+
export const GoogleDocSettings = Schema.Struct({
|
|
13
|
+
kind: Schema.Literal('google-doc'),
|
|
14
|
+
document: Name,
|
|
15
|
+
/** Each watched tab, and the T3 project whose command thread answers what is left on it. */
|
|
16
|
+
tabs: Schema.NonEmptyArray(Schema.Struct({ tab: Name, project: Name })),
|
|
17
|
+
tokenCommand: TokenCommand,
|
|
18
|
+
/** The Google Cloud project the Docs API counts the reads against, for a sign-in that names none. */
|
|
19
|
+
quotaProject: Schema.optionalKey(Name),
|
|
20
|
+
});
|
|
21
|
+
/** The open pull requests these authors wrote in these repositories (`owner/name`), read and answered as `gh` is signed in. */
|
|
22
|
+
export const GitHubPullRequestsSettings = Schema.Struct({
|
|
23
|
+
kind: Schema.Literal('github-pull-requests'),
|
|
24
|
+
repositories: Schema.NonEmptyArray(Schema.String.check(Schema.isPattern(/^[\w.-]+\/[\w.-]+$/))),
|
|
25
|
+
authors: Schema.NonEmptyArray(Schema.String.check(Schema.isPattern(/^[A-Za-z0-9-]+$/))),
|
|
26
|
+
});
|
|
27
|
+
const Listed = Schema.decodeUnknownEffect(Schema.Struct({
|
|
28
|
+
tag: Schema.optionalKey(Schema.String.check(Schema.isPattern(/^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/))),
|
|
29
|
+
sources: Schema.Array(Schema.Unknown),
|
|
30
|
+
}), { onExcessProperty: 'error' });
|
|
31
|
+
const sourceOfKind = {
|
|
32
|
+
'google-doc': Schema.decodeUnknownEffect(GoogleDocSettings, { onExcessProperty: 'error' }),
|
|
33
|
+
'github-pull-requests': Schema.decodeUnknownEffect(GitHubPullRequestsSettings, { onExcessProperty: 'error' }),
|
|
34
|
+
};
|
|
35
|
+
const isKind = Schema.is(Schema.Literals(['google-doc', 'github-pull-requests']));
|
|
36
|
+
const formatIssue = SchemaIssue.makeFormatterDefault();
|
|
37
|
+
export const repositoryAuthors = (sources) => sources.flatMap((s) => (s.kind === 'github-pull-requests' ? s.repositories.flatMap((repository) => s.authors.map((author) => ({ repository, author }))) : []));
|
|
38
|
+
/** Every place the settings name, one name each whatever its case. Pure. */
|
|
39
|
+
const places = (sources) => [
|
|
40
|
+
...sources.flatMap((s) => (s.kind === 'google-doc' ? [s.document, ...s.tabs.map((t) => `${s.document} ${t.tab}`)] : [])),
|
|
41
|
+
...repositoryAuthors(sources).map((p) => `${p.repository} ${p.author}`.toLowerCase()),
|
|
42
|
+
];
|
|
43
|
+
/** The settings' `commentWatch`, or why it names nothing this machine can watch. A typo'd key fails rather than being ignored. */
|
|
44
|
+
export const decodeSettings = (raw) => Effect.gen(function* () {
|
|
45
|
+
const listed = yield* Effect.mapError(Listed(raw), (e) => formatIssue(e.issue));
|
|
46
|
+
// Each by its own kind, so what is wrong with one is said of it and not of every kind it might have been.
|
|
47
|
+
const sources = yield* Effect.forEach(listed.sources, (source, i) => {
|
|
48
|
+
const kind = typeof source === 'object' && source !== null && 'kind' in source ? source.kind : undefined;
|
|
49
|
+
if (!isKind(kind))
|
|
50
|
+
return Effect.fail(`source ${i + 1}'s kind is neither google-doc nor github-pull-requests`);
|
|
51
|
+
return Effect.mapError(sourceOfKind[kind](source), (e) => `source ${i + 1} (${kind}): ${formatIssue(e.issue)}`);
|
|
52
|
+
});
|
|
53
|
+
const named = places(sources);
|
|
54
|
+
const twice = named.find((p, i) => named.indexOf(p) !== i);
|
|
55
|
+
if (twice !== undefined)
|
|
56
|
+
return yield* Effect.fail(`${twice} is named twice`);
|
|
57
|
+
return { tag: listed.tag ?? DEFAULT_TAG, sources };
|
|
58
|
+
});
|
|
59
|
+
/** What a settings file says to watch: no source where it names none. */
|
|
60
|
+
export const readSettings = (file) => Effect.gen(function* () {
|
|
61
|
+
const raw = yield* Effect.try({ try: () => (fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {}), catch: (e) => `${file} could not be read: ${String(e)}` });
|
|
62
|
+
if (raw.commentWatch === undefined)
|
|
63
|
+
return { tag: DEFAULT_TAG, sources: [] };
|
|
64
|
+
return yield* Effect.mapError(decodeSettings(raw.commentWatch), (why) => `commentWatch in ${file}: ${why}`);
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../../../../src/internal/comment-watch/settings.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,IAAI,GAAG,MAAM,CAAC,cAAc,CAAC;AACnC,uGAAuG;AACvG,MAAM,YAAY,GAAG,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AAEhD,gGAAgG;AAChG,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7C,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC;IAClC,QAAQ,EAAE,IAAI;IACd,4FAA4F;IAC5F,IAAI,EAAE,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACvE,YAAY,EAAE,YAAY;IAC1B,qGAAqG;IACrG,YAAY,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;CACvC,CAAC,CAAC;AAGH,+HAA+H;AAC/H,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC,MAAM,CAAC;IACtD,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC;IAC5C,YAAY,EAAE,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAC/F,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,i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