@picassohq/cli 0.0.0-stage → 1.0.2
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/agents/browser_agent.yaml +53 -0
- package/agents/code_reviewer.yaml +49 -0
- package/agents/codebase_investigator.yaml +70 -0
- package/agents/design_auditor.yaml +50 -0
- package/agents/devex_auditor.yaml +50 -0
- package/agents/doc_writer.yaml +54 -0
- package/agents/engineering_architect.yaml +51 -0
- package/agents/generalist.yaml +55 -0
- package/agents/migration_planner.yaml +51 -0
- package/agents/product_reviewer.yaml +48 -0
- package/agents/qa_operator.yaml +52 -0
- package/agents/release_engineer.yaml +50 -0
- package/agents/security_auditor.yaml +62 -0
- package/agents/test_writer.yaml +52 -0
- package/assets/first-light-lockup.png +0 -0
- package/assets/first-light-tagline.png +0 -0
- package/assets/house/README.md +26 -0
- package/assets/house/auraone-banner.png +0 -0
- package/assets/house/auraone-logo.png +0 -0
- package/assets/house/kiro-prism-banner.png +0 -0
- package/assets/house/kiro-prism-logo.png +0 -0
- package/assets/house/picasso-banner.png +0 -0
- package/assets/house/picasso-logo.png +0 -0
- package/assets/wordmark-app.png +0 -0
- package/assets/wordmark-tight.png +0 -0
- package/assets/wordmark.png +0 -0
- package/design/styles.css +1042 -0
- package/dist/build-info.json +37 -0
- package/dist/index.js +3062 -0
- package/goals/cli-hardening.yaml +40 -0
- package/goals/repo-maintenance.yaml +40 -0
- package/package.json +49 -4
- package/runtime/dsh/picasso-ecosystem.community.amendments.yml +24 -0
- package/runtime/dsh/picasso-ecosystem.community.json +185 -0
- package/runtime/dsh/picasso-ecosystem.community.patch.yml +40 -0
- package/runtime/dsh/picasso-ecosystem.cordis.patch.yml +143 -0
- package/runtime/dsh/picasso-isolation.patch.yml +25 -0
- package/runtime/dsh/picasso-providers.patch.yml +373 -0
- package/runtime/dsh/picasso-runtime.cordis.yml +738 -0
- package/runtime/dsh/picasso-sdk.patch.yml +204 -0
- package/runtime/engine-manifest.json +215 -0
- package/runtime/package.json +6 -0
- package/runtime/packages/picasso-cache-probe/cordis.patch.yml +5 -0
- package/runtime/packages/picasso-cache-probe/index.js +477 -0
- package/runtime/packages/picasso-cache-probe/package.json +38 -0
- package/runtime/packages/picasso-commands/cordis.patch.yml +4 -0
- package/runtime/packages/picasso-commands/fresh-review.js +573 -0
- package/runtime/packages/picasso-commands/index.js +497 -0
- package/runtime/packages/picasso-commands/package.json +28 -0
- package/runtime/packages/picasso-instructions/conflicts.js +115 -0
- package/runtime/packages/picasso-instructions/formats.js +145 -0
- package/runtime/packages/picasso-instructions/frontmatter.js +175 -0
- package/runtime/packages/picasso-instructions/glob.js +114 -0
- package/runtime/packages/picasso-instructions/globals.js +90 -0
- package/runtime/packages/picasso-instructions/imports.js +123 -0
- package/runtime/packages/picasso-instructions/index.js +326 -0
- package/runtime/packages/picasso-instructions/modes.js +64 -0
- package/runtime/packages/picasso-instructions/package.json +30 -0
- package/runtime/packages/picasso-instructions/parse.js +134 -0
- package/runtime/packages/picasso-instructions/report.js +161 -0
- package/runtime/packages/picasso-instructions/resolve.js +939 -0
- package/runtime/packages/picasso-instructions/scan.js +181 -0
- package/runtime/packages/picasso-instructions/settings.js +150 -0
- package/runtime/packages/picasso-instructions/skills.js +345 -0
- package/runtime/packages/picasso-lean-context/cordis.patch.yml +13 -0
- package/runtime/packages/picasso-lean-context/index.js +6280 -0
- package/runtime/packages/picasso-lean-context/package.json +26 -0
- package/runtime/packages/picasso-lean-context/read-image-recovery.js +306 -0
- package/runtime/packages/picasso-lean-context/timeline.js +418 -0
- package/runtime/packages/picasso-librarian/classify.js +146 -0
- package/runtime/packages/picasso-librarian/cordis.patch.yml +10 -0
- package/runtime/packages/picasso-librarian/index.js +878 -0
- package/runtime/packages/picasso-librarian/notes.js +159 -0
- package/runtime/packages/picasso-librarian/package.json +34 -0
- package/runtime/packages/picasso-librarian/state.js +478 -0
- package/runtime/packages/picasso-memory/index.js +1184 -0
- package/runtime/packages/picasso-memory/package.json +21 -0
- package/runtime/packages/picasso-model-router/connections.js +912 -0
- package/runtime/packages/picasso-model-router/cordis.patch.yml +17 -0
- package/runtime/packages/picasso-model-router/index.js +1083 -0
- package/runtime/packages/picasso-model-router/package.json +30 -0
- package/runtime/packages/picasso-options/cordis.patch.yml +4 -0
- package/runtime/packages/picasso-options/index.js +263 -0
- package/runtime/packages/picasso-options/package.json +28 -0
- package/runtime/packages/picasso-progress-reports/cordis.patch.yml +10 -0
- package/runtime/packages/picasso-progress-reports/index.js +267 -0
- package/runtime/packages/picasso-progress-reports/package.json +30 -0
- package/runtime/packages/picasso-progress-reports/report.js +235 -0
- package/runtime/packages/picasso-sdk-server/aside.js +142 -0
- package/runtime/packages/picasso-sdk-server/connections.js +38 -0
- package/runtime/packages/picasso-sdk-server/context-timeline.js +27 -0
- package/runtime/packages/picasso-sdk-server/egress-gate.js +520 -0
- package/runtime/packages/picasso-sdk-server/failure-policy.js +246 -0
- package/runtime/packages/picasso-sdk-server/file-input.js +169 -0
- package/runtime/packages/picasso-sdk-server/goal.js +131 -0
- package/runtime/packages/picasso-sdk-server/ignore-file.js +458 -0
- package/runtime/packages/picasso-sdk-server/ignore-plugin.js +12 -0
- package/runtime/packages/picasso-sdk-server/ignore-sandbox.js +122 -0
- package/runtime/packages/picasso-sdk-server/ignore-snapshot.js +131 -0
- package/runtime/packages/picasso-sdk-server/image-input.js +44 -0
- package/runtime/packages/picasso-sdk-server/index.js +891 -0
- package/runtime/packages/picasso-sdk-server/instructions.js +34 -0
- package/runtime/packages/picasso-sdk-server/jobs.js +113 -0
- package/runtime/packages/picasso-sdk-server/mcp-gate.js +51 -0
- package/runtime/packages/picasso-sdk-server/model-selection.js +162 -0
- package/runtime/packages/picasso-sdk-server/package.json +50 -0
- package/runtime/packages/picasso-sdk-server/picasso-records.js +50 -0
- package/runtime/packages/picasso-sdk-server/provider-reload.js +84 -0
- package/runtime/packages/picasso-sdk-server/queue.js +322 -0
- package/runtime/packages/picasso-sdk-server/requester.js +43 -0
- package/runtime/packages/picasso-sdk-server/rewind.js +108 -0
- package/runtime/packages/picasso-sdk-server/schedule.js +187 -0
- package/runtime/packages/picasso-sdk-server/session-grants.js +35 -0
- package/runtime/packages/picasso-sdk-server/session-state.js +118 -0
- package/runtime/packages/picasso-sdk-server/shell-paths.js +869 -0
- package/runtime/packages/picasso-sdk-server/stream-deltas.js +211 -0
- package/runtime/packages/picasso-sdk-server/team-tasks.js +451 -0
- package/runtime/packages/picasso-sdk-server/tool-output.js +128 -0
- package/runtime/packages/picasso-sdk-server/tools-list.js +51 -0
- package/runtime/packages/picasso-sdk-server/wave2-hooks.js +612 -0
- package/runtime/packages/picasso-sdk-server/workspace-archive.js +170 -0
- package/runtime/packages/picasso-sdk-server/workspace-restore.js +180 -0
- package/runtime/packages/picasso-web-search/backends.js +412 -0
- package/runtime/packages/picasso-web-search/config.js +121 -0
- package/runtime/packages/picasso-web-search/cordis.patch.yml +7 -0
- package/runtime/packages/picasso-web-search/failure.js +116 -0
- package/runtime/packages/picasso-web-search/format.js +42 -0
- package/runtime/packages/picasso-web-search/index.js +71 -0
- package/runtime/packages/picasso-web-search/package.json +38 -0
- package/runtime/packages/picasso-web-search/router.js +156 -0
- package/runtime/packages/picasso-x-reader/circle.js +324 -0
- package/runtime/packages/picasso-x-reader/command.js +169 -0
- package/runtime/packages/picasso-x-reader/cordis.patch.yml +8 -0
- package/runtime/packages/picasso-x-reader/index.js +170 -0
- package/runtime/packages/picasso-x-reader/package.json +39 -0
- package/runtime/packages/picasso-x-reader/read.js +370 -0
- package/runtime/packages/picasso-x-reader/rewrite.js +38 -0
- package/runtime/packages/picasso-x-reader/settings.js +131 -0
- package/runtime/packages/picasso-x-reader/urls.js +154 -0
- package/runtime/packages/picasso-x-reader/xmd.js +512 -0
- package/runtime/plugins/picasso-auth-bridge/index.js +380 -0
- package/runtime/plugins/picasso-auth-bridge/package.json +28 -0
- package/runtime/plugins/picasso-auto-approve/index.js +1003 -0
- package/runtime/plugins/picasso-auto-approve/package.json +28 -0
- package/runtime/plugins/picasso-browser/index.js +424 -0
- package/runtime/plugins/picasso-browser/package.json +28 -0
- package/runtime/plugins/picasso-checkpoints/evidence.js +210 -0
- package/runtime/plugins/picasso-checkpoints/index.js +885 -0
- package/runtime/plugins/picasso-checkpoints/package.json +29 -0
- package/runtime/plugins/picasso-commands/fresh-review.js +573 -0
- package/runtime/plugins/picasso-commands/index.js +497 -0
- package/runtime/plugins/picasso-commands/package.json +28 -0
- package/runtime/plugins/picasso-instructions/conflicts.js +115 -0
- package/runtime/plugins/picasso-instructions/formats.js +145 -0
- package/runtime/plugins/picasso-instructions/frontmatter.js +175 -0
- package/runtime/plugins/picasso-instructions/glob.js +114 -0
- package/runtime/plugins/picasso-instructions/globals.js +90 -0
- package/runtime/plugins/picasso-instructions/imports.js +123 -0
- package/runtime/plugins/picasso-instructions/index.js +326 -0
- package/runtime/plugins/picasso-instructions/modes.js +64 -0
- package/runtime/plugins/picasso-instructions/package.json +30 -0
- package/runtime/plugins/picasso-instructions/parse.js +134 -0
- package/runtime/plugins/picasso-instructions/report.js +161 -0
- package/runtime/plugins/picasso-instructions/resolve.js +939 -0
- package/runtime/plugins/picasso-instructions/scan.js +181 -0
- package/runtime/plugins/picasso-instructions/settings.js +150 -0
- package/runtime/plugins/picasso-instructions/skills.js +345 -0
- package/runtime/plugins/picasso-lean-context/index.js +6280 -0
- package/runtime/plugins/picasso-lean-context/package.json +26 -0
- package/runtime/plugins/picasso-lean-context/read-image-recovery.js +306 -0
- package/runtime/plugins/picasso-lean-context/timeline.js +418 -0
- package/runtime/plugins/picasso-librarian/classify.js +146 -0
- package/runtime/plugins/picasso-librarian/index.js +878 -0
- package/runtime/plugins/picasso-librarian/notes.js +159 -0
- package/runtime/plugins/picasso-librarian/package.json +34 -0
- package/runtime/plugins/picasso-librarian/state.js +478 -0
- package/runtime/plugins/picasso-lifecycle-hooks/index.js +186 -0
- package/runtime/plugins/picasso-lifecycle-hooks/package.json +25 -0
- package/runtime/plugins/picasso-mail/inbox.js +207 -0
- package/runtime/plugins/picasso-mail/index.js +293 -0
- package/runtime/plugins/picasso-mail/package.json +22 -0
- package/runtime/plugins/picasso-memory/index.js +1184 -0
- package/runtime/plugins/picasso-memory/package.json +21 -0
- package/runtime/plugins/picasso-model-router/connections.js +912 -0
- package/runtime/plugins/picasso-model-router/index.js +1083 -0
- package/runtime/plugins/picasso-model-router/package.json +30 -0
- package/runtime/plugins/picasso-options/index.js +263 -0
- package/runtime/plugins/picasso-options/package.json +28 -0
- package/runtime/plugins/picasso-progress-reports/index.js +267 -0
- package/runtime/plugins/picasso-progress-reports/package.json +30 -0
- package/runtime/plugins/picasso-progress-reports/report.js +235 -0
- package/runtime/plugins/picasso-provider-models/index.js +436 -0
- package/runtime/plugins/picasso-provider-models/package.json +28 -0
- package/runtime/plugins/picasso-repo-index/index.js +1850 -0
- package/runtime/plugins/picasso-repo-index/package.json +28 -0
- package/runtime/plugins/picasso-schedule-pause/index.js +344 -0
- package/runtime/plugins/picasso-schedule-pause/package.json +28 -0
- package/runtime/plugins/picasso-session-lifecycle/index.js +796 -0
- package/runtime/plugins/picasso-session-lifecycle/package.json +28 -0
- package/runtime/plugins/picasso-trackers/index.js +895 -0
- package/runtime/plugins/picasso-trackers/package.json +28 -0
- package/runtime/plugins/picasso-web-search/backends.js +412 -0
- package/runtime/plugins/picasso-web-search/config.js +121 -0
- package/runtime/plugins/picasso-web-search/failure.js +116 -0
- package/runtime/plugins/picasso-web-search/format.js +42 -0
- package/runtime/plugins/picasso-web-search/index.js +71 -0
- package/runtime/plugins/picasso-web-search/package.json +38 -0
- package/runtime/plugins/picasso-web-search/router.js +156 -0
- package/runtime/plugins/picasso-x-reader/circle.js +324 -0
- package/runtime/plugins/picasso-x-reader/command.js +169 -0
- package/runtime/plugins/picasso-x-reader/index.js +170 -0
- package/runtime/plugins/picasso-x-reader/package.json +39 -0
- package/runtime/plugins/picasso-x-reader/read.js +370 -0
- package/runtime/plugins/picasso-x-reader/rewrite.js +38 -0
- package/runtime/plugins/picasso-x-reader/settings.js +131 -0
- package/runtime/plugins/picasso-x-reader/urls.js +154 -0
- package/runtime/plugins/picasso-x-reader/xmd.js +512 -0
- package/runtime/relay/attachment-text.mjs +737 -0
- package/runtime/relay/companion/companion.css +126 -0
- package/runtime/relay/companion/companion.js +648 -0
- package/runtime/relay/companion/icon.svg +5 -0
- package/runtime/relay/companion/index.html +25 -0
- package/runtime/relay/companion/manifest.json +13 -0
- package/runtime/relay/companion/sw.js +41 -0
- package/runtime/relay/main.mjs +38580 -0
- package/runtime/relay/model-listing.mjs +614 -0
- package/runtime/relay/versions-routes.mjs +1400 -0
- package/runtime/verify-plugins.mjs +205 -0
- package/runtime-lock/package-lock.json +10779 -0
- package/runtime-lock/package.json +7 -0
- package/scripts/install-runtime.mjs +400 -0
- package/README.md +0 -3
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@picasso/repo-index",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "dsh cordis plugin: a durable per-workspace code index (files + symbols + imports + line text, node:sqlite + FTS5) under dshHomePath('repo-index'), the repoIndex/* Remote surface (status|reindex|search|symbols|file|map|wikiList|wikiPage|wikiAsk|wikiGenerate), the repo_search/repo_map model tools, fs/observed invalidation, and the RepoWiki pages behind the Mac's wiki surface.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./index.js",
|
|
10
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"dshTarget": "0.2.2-rc.3",
|
|
14
|
+
"dsh": {
|
|
15
|
+
"bundle": {
|
|
16
|
+
"patch": "./cordis.patch.yml"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "node --import ../../test/setup/hermetic-preload.mjs --test test/*.test.mjs"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"index.js",
|
|
24
|
+
"cordis.patch.yml",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"license": "UNLICENSED"
|
|
28
|
+
}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
// @picasso/schedule-pause — pause and resume for dsh schedules.
|
|
2
|
+
//
|
|
3
|
+
// dsh 0.2.2's schedule service has a native paused state: `edit({id, action: 'update', patch: {active}})` pauses and
|
|
4
|
+
// resumes a task in place (same id), and `edit({id, action: 'delete'})` removes it. This plugin keeps the Host Remote
|
|
5
|
+
// service the Mac already talks to (`schedulePause/*`) and maps it onto that API:
|
|
6
|
+
// pause `edit` with `active: false`; the task keeps its id and dsh stops delivering it.
|
|
7
|
+
// resume `edit` with `active: true`; dsh computes the next run. The reply's `id` equals `previousId`.
|
|
8
|
+
// delete Stop: `edit` with `action: 'delete'`.
|
|
9
|
+
// catalog dsh's `schedule/catalog`, each row given a top-level `sessionId` (from its `target`) and `paused`.
|
|
10
|
+
// list the paused tasks and the resume id mapping.
|
|
11
|
+
//
|
|
12
|
+
// Older engines (0.2.1, no `edit`) had no paused state, so this plugin paused by snapshotting the task into a JSON
|
|
13
|
+
// sidecar (`<dsh data>/picasso-schedule-pause.json`) and deleting it in dsh, and resumed by recreating it (a new id;
|
|
14
|
+
// `resumed[oldId] = {id: newId}`). That path stays for such an engine, and snapshots taken by it are still shown as
|
|
15
|
+
// paused and resumed by recreating them through 0.2.2's `create` (session target, same title, prompt and rule).
|
|
16
|
+
//
|
|
17
|
+
// Zero runtime dependencies, like @picasso/session-lifecycle: Remote methods use the gateway's source-mode markers and
|
|
18
|
+
// failures are structural dsh RemoteErrors (`isDSHRemoteError`, code `schedulePause/<code>`).
|
|
19
|
+
import { readFileSync } from 'node:fs';
|
|
20
|
+
import { mkdir, rename, writeFile } from 'node:fs/promises';
|
|
21
|
+
import { homedir } from 'node:os';
|
|
22
|
+
import { dirname, join, resolve } from 'node:path';
|
|
23
|
+
|
|
24
|
+
export const name = 'picasso-schedule-pause';
|
|
25
|
+
export const dshTarget = '0.2.2-rc.3';
|
|
26
|
+
export const SERVICE_KEY = 'schedulePause';
|
|
27
|
+
export const SIDECAR_FILENAME = 'picasso-schedule-pause.json';
|
|
28
|
+
/** At most this many old → new id mappings are kept. */
|
|
29
|
+
export const RESUMED_LIMIT = 200;
|
|
30
|
+
const REMOTE_METHOD_DESCRIPTOR = '@deepseek-ai/dsh-typert-protocol/remote-methods';
|
|
31
|
+
|
|
32
|
+
export class SchedulePauseError extends Error {
|
|
33
|
+
constructor(code, message, details = {}) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.name = 'RemoteError';
|
|
36
|
+
this.code = `schedulePause/${code}`;
|
|
37
|
+
this.details = details;
|
|
38
|
+
this.isDSHRemoteError = true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
43
|
+
const emptyState = () => ({ version: 1, paused: {}, resumed: {} });
|
|
44
|
+
const ONE_SHOT = new Set(['after', 'at']);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* dsh `schedule.create` request that rebuilds `record` (a `ScheduleRecord` from `schedule/catalog`): the same title,
|
|
48
|
+
* instruction and rule. One-shots target the record's committed instant.
|
|
49
|
+
*/
|
|
50
|
+
export function createRequestFor(record) {
|
|
51
|
+
const base = { title: record.title, prompt: record.prompt };
|
|
52
|
+
switch (record.kind) {
|
|
53
|
+
case 'after':
|
|
54
|
+
case 'at':
|
|
55
|
+
return { ...base, at: record.scheduledAt };
|
|
56
|
+
case 'every':
|
|
57
|
+
return { ...base, every_seconds: record.everySeconds };
|
|
58
|
+
case 'daily':
|
|
59
|
+
return { ...base, daily: { time: record.time, time_zone: record.timeZone } };
|
|
60
|
+
case 'weekly':
|
|
61
|
+
return { ...base, weekly: { time: record.time, time_zone: record.timeZone, weekdays: [...record.weekdays] } };
|
|
62
|
+
case 'cron':
|
|
63
|
+
return { ...base, cron: { expression: record.expression, time_zone: record.timeZone } };
|
|
64
|
+
default:
|
|
65
|
+
throw new SchedulePauseError('unsupported-kind', `Schedules of kind ${JSON.stringify(record.kind)} cannot be paused.`, { kind: record.kind });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** dsh 0.2.2 `schedule.create` request (`timing` carries the rule) that rebuilds `record` in `sessionId`. */
|
|
70
|
+
export function createRequestV2For(record, sessionId) {
|
|
71
|
+
const { title, prompt, ...rule } = createRequestFor(record);
|
|
72
|
+
const kind = Object.keys(rule)[0];
|
|
73
|
+
return { title, prompt, timing: { kind, ...rule }, target: { kind: 'session', sessionId } };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The Session a catalog row belongs to: 0.2.1's `sessionId`, else 0.2.2's `target.sessionId` or first involved one. */
|
|
77
|
+
export function sessionOfRow(row) {
|
|
78
|
+
if (typeof row?.sessionId === 'string') return row.sessionId;
|
|
79
|
+
if (typeof row?.target?.sessionId === 'string') return row.target.sessionId;
|
|
80
|
+
return Array.isArray(row?.involvedSessionIds) && typeof row.involvedSessionIds[0] === 'string' ? row.involvedSessionIds[0] : undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const rowInSession = (row, session) =>
|
|
84
|
+
sessionOfRow(row) === session || (Array.isArray(row?.involvedSessionIds) && row.involvedSessionIds.includes(session));
|
|
85
|
+
|
|
86
|
+
/** A non-mutating miss/conflict from 0.2.2 `edit`, as this plugin's refusal. */
|
|
87
|
+
function editRefusal(result, task) {
|
|
88
|
+
if (result?.code === 'schedule_conflict') return new SchedulePauseError('conflict', `Schedule ${task} changed meanwhile; try again.`, { id: task });
|
|
89
|
+
return new SchedulePauseError('schedule-not-found', `dsh no longer has schedule ${task}.`, { id: task });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The fields a recreated record must share with its snapshot; empty when it matches. */
|
|
93
|
+
export function definitionMismatches(original, recreated) {
|
|
94
|
+
const diffs = [];
|
|
95
|
+
const same = (key) => JSON.stringify(original[key]) === JSON.stringify(recreated[key]);
|
|
96
|
+
for (const key of ['title', 'prompt']) if (!same(key)) diffs.push(key);
|
|
97
|
+
if (ONE_SHOT.has(original.kind)) {
|
|
98
|
+
if (recreated.kind !== 'at') diffs.push('kind');
|
|
99
|
+
if (!same('scheduledAt')) diffs.push('scheduledAt');
|
|
100
|
+
return diffs;
|
|
101
|
+
}
|
|
102
|
+
if (original.kind !== recreated.kind) return [...diffs, 'kind'];
|
|
103
|
+
const rule = { every: ['everySeconds'], daily: ['time', 'timeZone'], weekly: ['time', 'timeZone', 'weekdays'], cron: ['expression', 'timeZone'] }[original.kind] ?? [];
|
|
104
|
+
for (const key of rule) if (!same(key)) diffs.push(key);
|
|
105
|
+
return diffs;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The pause store. `schedule` is dsh's schedule service, resolved on each call so the plugin can start before it:
|
|
110
|
+
* 0.2.2 (`catalog()`, `create(request, actor)`, `edit(request, actor)`) or 0.2.1 (`catalog()`,
|
|
111
|
+
* `create(sessionId, request)`, `delete({sessionId, id})`).
|
|
112
|
+
*/
|
|
113
|
+
export class SchedulePause {
|
|
114
|
+
constructor(options) {
|
|
115
|
+
this.dataDir = resolve(options.dataDir);
|
|
116
|
+
this.sidecar = join(this.dataDir, SIDECAR_FILENAME);
|
|
117
|
+
this.schedule = typeof options.schedule === 'function' ? options.schedule : () => options.schedule;
|
|
118
|
+
this.now = options.now ?? Date.now;
|
|
119
|
+
this.tail = Promise.resolve();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ── Remote surface (`schedulePause/<method>`; wire args are the parameter names) ───────────────────────────────
|
|
123
|
+
|
|
124
|
+
/** Pauses an active task: natively on 0.2.2; on 0.2.1 by snapshotting it, then deleting it in dsh. */
|
|
125
|
+
pause(sessionId, id) {
|
|
126
|
+
return this.serial(async () => {
|
|
127
|
+
const task = requireString(id, 'id');
|
|
128
|
+
const schedule = this.service();
|
|
129
|
+
// 0.2.2 tasks that start a new thread each time belong to no session: there, an empty sessionId matches by id.
|
|
130
|
+
const session = isNative(schedule) && (sessionId === '' || sessionId === undefined) ? undefined : requireString(sessionId, 'sessionId');
|
|
131
|
+
const state = this.read();
|
|
132
|
+
if (state.paused[task]) throw new SchedulePauseError('already-paused', `Schedule ${task} is already paused.`, { id: task });
|
|
133
|
+
if (isNative(schedule)) {
|
|
134
|
+
const entry = (await schedule.catalog()).find((row) => row.id === task && (session === undefined || rowInSession(row, session)));
|
|
135
|
+
if (!entry) throw new SchedulePauseError('schedule-not-found', `No schedule ${task} in session ${session}.`, { id: task, sessionId: session });
|
|
136
|
+
if (entry.status === 'paused') throw new SchedulePauseError('already-paused', `Schedule ${task} is already paused.`, { id: task });
|
|
137
|
+
if (entry.status !== 'active') throw new SchedulePauseError('schedule-ended', `Schedule ${task} has ended; only active schedules can be paused.`, { id: task });
|
|
138
|
+
const result = await schedule.edit({ id: task, action: 'update', patch: { active: false } }, undefined);
|
|
139
|
+
if (typeof result?.code === 'string') throw editRefusal(result, task);
|
|
140
|
+
return { id: task, sessionId: session ?? sessionOfRow(entry) ?? null, paused: true, pausedAt: this.now() };
|
|
141
|
+
}
|
|
142
|
+
const entry = (await schedule.catalog()).find((row) => row.id === task && row.sessionId === session);
|
|
143
|
+
if (!entry) throw new SchedulePauseError('schedule-not-found', `No schedule ${task} in session ${session}.`, { id: task, sessionId: session });
|
|
144
|
+
if (entry.status !== 'active') throw new SchedulePauseError('schedule-ended', `Schedule ${task} has ended; only active schedules can be paused.`, { id: task });
|
|
145
|
+
createRequestFor(entry);
|
|
146
|
+
const { sessionId: _s, status: _st, lastDelivery, ...record } = entry;
|
|
147
|
+
const pausedAt = this.now();
|
|
148
|
+
state.paused[task] = { sessionId: session, record, pausedAt, ...(lastDelivery ? { lastDelivery } : {}) };
|
|
149
|
+
await this.write(state);
|
|
150
|
+
let deleted;
|
|
151
|
+
try {
|
|
152
|
+
deleted = await schedule.delete({ sessionId: session, id: task });
|
|
153
|
+
} catch (error) {
|
|
154
|
+
await this.forget(task);
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
if (!deleted?.deleted) {
|
|
158
|
+
await this.forget(task);
|
|
159
|
+
throw new SchedulePauseError('schedule-not-found', `dsh no longer has schedule ${task}.`, { id: task, sessionId: session });
|
|
160
|
+
}
|
|
161
|
+
return { id: task, sessionId: session, paused: true, pausedAt };
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Recreates a paused task in dsh with the same definition and verifies it; the new id is in `id`. */
|
|
166
|
+
resume(id) {
|
|
167
|
+
return this.serial(async () => {
|
|
168
|
+
const task = requireString(id, 'id');
|
|
169
|
+
const schedule = this.service();
|
|
170
|
+
const state = this.read();
|
|
171
|
+
const entry = state.paused[task];
|
|
172
|
+
const native = isNative(schedule);
|
|
173
|
+
if (!entry && native) {
|
|
174
|
+
const row = (await schedule.catalog()).find((candidate) => candidate.id === task);
|
|
175
|
+
if (row?.status !== 'paused') throw new SchedulePauseError('not-paused', `Schedule ${task} is not paused.`, { id: task });
|
|
176
|
+
let result;
|
|
177
|
+
try {
|
|
178
|
+
result = await schedule.edit({ id: task, action: 'update', patch: { active: true } }, undefined);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (error?.isDSHRemoteError) throw error;
|
|
181
|
+
throw new SchedulePauseError('resume-refused', String(error?.message ?? error), { id: task, dshCode: typeof error?.code === 'string' ? error.code : 'edit-failed' });
|
|
182
|
+
}
|
|
183
|
+
if (typeof result?.code === 'string') throw editRefusal(result, task);
|
|
184
|
+
return { id: task, previousId: task, sessionId: sessionOfRow(row), resumed: true, record: result };
|
|
185
|
+
}
|
|
186
|
+
if (!entry) throw new SchedulePauseError('not-paused', `Schedule ${task} is not paused.`, { id: task });
|
|
187
|
+
let created;
|
|
188
|
+
try {
|
|
189
|
+
created = native
|
|
190
|
+
? await schedule.create(createRequestV2For(entry.record, entry.sessionId), undefined)
|
|
191
|
+
: await schedule.create(entry.sessionId, createRequestFor(entry.record));
|
|
192
|
+
} catch (error) {
|
|
193
|
+
if (error?.isDSHRemoteError) throw error;
|
|
194
|
+
const code = typeof error?.code === 'string' ? error.code : 'create-failed';
|
|
195
|
+
const message = code === 'not_future'
|
|
196
|
+
? `The time for "${entry.record.title}" passed while it was paused. Stop it, or ask for a new one.`
|
|
197
|
+
: String(error?.message ?? error);
|
|
198
|
+
throw new SchedulePauseError('resume-refused', message, { id: task, dshCode: code });
|
|
199
|
+
}
|
|
200
|
+
const recreated = (await schedule.catalog()).find((row) => row.id === created.id);
|
|
201
|
+
const diffs = recreated ? definitionMismatches(entry.record, recreated) : ['missing'];
|
|
202
|
+
if (recreated && sessionOfRow(recreated) !== entry.sessionId) diffs.push('sessionId');
|
|
203
|
+
if (diffs.length > 0) {
|
|
204
|
+
await removeTask(schedule, entry.sessionId, created.id).catch(() => undefined);
|
|
205
|
+
throw new SchedulePauseError('resume-mismatch', `dsh recreated schedule ${task} differently (${diffs.join(', ')}); it stays paused.`, { id: task, fields: diffs });
|
|
206
|
+
}
|
|
207
|
+
const latest = this.read();
|
|
208
|
+
delete latest.paused[task];
|
|
209
|
+
latest.resumed[task] = { id: created.id, resumedAt: this.now() };
|
|
210
|
+
const order = Object.entries(latest.resumed).sort((a, b) => b[1].resumedAt - a[1].resumedAt);
|
|
211
|
+
latest.resumed = Object.fromEntries(order.slice(0, RESUMED_LIMIT));
|
|
212
|
+
await this.write(latest);
|
|
213
|
+
return { id: created.id, previousId: task, sessionId: entry.sessionId, resumed: true, record: created };
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Stop: a paused task's snapshot is dropped; an active one is deleted in dsh. */
|
|
218
|
+
delete(sessionId, id) {
|
|
219
|
+
return this.serial(async () => {
|
|
220
|
+
const task = requireString(id, 'id');
|
|
221
|
+
const state = this.read();
|
|
222
|
+
const native = !state.paused[task] && isNative(this.service());
|
|
223
|
+
const session = native && (sessionId === '' || sessionId === undefined) ? undefined : requireString(sessionId, 'sessionId');
|
|
224
|
+
if (state.paused[task]) {
|
|
225
|
+
if (state.paused[task].sessionId !== session) throw new SchedulePauseError('schedule-not-found', `No schedule ${task} in session ${session}.`, { id: task });
|
|
226
|
+
delete state.paused[task];
|
|
227
|
+
await this.write(state);
|
|
228
|
+
return { id: task, deleted: true, paused: true };
|
|
229
|
+
}
|
|
230
|
+
const schedule = this.service();
|
|
231
|
+
if (isNative(schedule)) {
|
|
232
|
+
const row = (await schedule.catalog()).find((candidate) => candidate.id === task && (session === undefined || rowInSession(candidate, session)));
|
|
233
|
+
if (!row) throw new SchedulePauseError('schedule-not-found', `No schedule ${task} in session ${session}.`, { id: task });
|
|
234
|
+
}
|
|
235
|
+
const result = await removeTask(schedule, session, task);
|
|
236
|
+
if (typeof result?.code === 'string') throw editRefusal(result, task);
|
|
237
|
+
return { ...result, paused: false };
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** dsh's catalog with the paused tasks merged in, ordered like dsh's (scheduledAt, then id). */
|
|
242
|
+
catalog() {
|
|
243
|
+
return this.serial(async () => {
|
|
244
|
+
const live = (await this.service().catalog()).map((row) => {
|
|
245
|
+
const session = sessionOfRow(row);
|
|
246
|
+
return { ...row, ...(session === undefined ? {} : { sessionId: session }), ...(row.status === 'paused' ? { paused: true } : {}) };
|
|
247
|
+
});
|
|
248
|
+
const present = new Set(live.map((row) => row.id));
|
|
249
|
+
const paused = Object.entries(this.read().paused)
|
|
250
|
+
.filter(([id]) => !present.has(id))
|
|
251
|
+
.map(([id, entry]) => ({ ...entry.record, id, sessionId: entry.sessionId, status: 'paused', paused: true, pausedAt: entry.pausedAt, ...(entry.lastDelivery ? { lastDelivery: entry.lastDelivery } : {}) }));
|
|
252
|
+
return [...live, ...paused].sort((a, b) => String(a.scheduledAt).localeCompare(String(b.scheduledAt)) || String(a.id).localeCompare(String(b.id)));
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
list() {
|
|
257
|
+
return this.serial(async () => {
|
|
258
|
+
const state = this.read();
|
|
259
|
+
return {
|
|
260
|
+
paused: Object.entries(state.paused).map(([id, entry]) => ({ id, sessionId: entry.sessionId, pausedAt: entry.pausedAt, record: entry.record })).sort((a, b) => b.pausedAt - a.pausedAt),
|
|
261
|
+
resumed: state.resumed,
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ── Store ────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
267
|
+
|
|
268
|
+
service() {
|
|
269
|
+
let schedule;
|
|
270
|
+
try {
|
|
271
|
+
schedule = this.schedule();
|
|
272
|
+
} catch {
|
|
273
|
+
schedule = undefined;
|
|
274
|
+
}
|
|
275
|
+
if (!schedule || typeof schedule.catalog !== 'function' || typeof schedule.create !== 'function' || (typeof schedule.edit !== 'function' && typeof schedule.delete !== 'function')) {
|
|
276
|
+
throw new SchedulePauseError('schedule-unavailable', 'dsh\'s schedule service is not mounted.');
|
|
277
|
+
}
|
|
278
|
+
return schedule;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async forget(id) {
|
|
282
|
+
const state = this.read();
|
|
283
|
+
delete state.paused[id];
|
|
284
|
+
await this.write(state);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
read() {
|
|
288
|
+
try {
|
|
289
|
+
const parsed = JSON.parse(readFileSync(this.sidecar, 'utf8'));
|
|
290
|
+
if (!isRecord(parsed)) return emptyState();
|
|
291
|
+
return { version: 1, paused: isRecord(parsed.paused) ? parsed.paused : {}, resumed: isRecord(parsed.resumed) ? parsed.resumed : {} };
|
|
292
|
+
} catch {
|
|
293
|
+
return emptyState();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async write(state) {
|
|
298
|
+
await mkdir(this.dataDir, { recursive: true });
|
|
299
|
+
const temporary = `${this.sidecar}.${process.pid}.tmp`;
|
|
300
|
+
await writeFile(temporary, `${JSON.stringify(state, null, 2)}\n`, { mode: 0o600 });
|
|
301
|
+
await rename(temporary, this.sidecar);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
serial(body) {
|
|
305
|
+
const run = this.tail.then(body, body);
|
|
306
|
+
this.tail = run.catch(() => undefined);
|
|
307
|
+
return run;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** dsh 0.2.2+: the schedule service pauses, resumes and deletes through `edit`. */
|
|
312
|
+
function isNative(schedule) {
|
|
313
|
+
return typeof schedule.edit === 'function';
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** Deletes a task in dsh: 0.2.2 `edit({action: 'delete'})`, else 0.2.1 `delete({sessionId, id})`. */
|
|
317
|
+
function removeTask(schedule, sessionId, id) {
|
|
318
|
+
return isNative(schedule) ? schedule.edit({ id, action: 'delete' }, undefined) : schedule.delete({ sessionId, id });
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const REMOTE_METHODS = ['pause', 'resume', 'delete', 'catalog', 'list'];
|
|
322
|
+
|
|
323
|
+
Object.defineProperty(SchedulePause.prototype, REMOTE_METHOD_DESCRIPTOR, {
|
|
324
|
+
configurable: true,
|
|
325
|
+
value: Object.freeze({ version: 1, methods: Object.freeze(REMOTE_METHODS.map((method) => Object.freeze({ method, invocation: Object.freeze({ kind: 'direct' }) }))) }),
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
function requireString(value, field) {
|
|
329
|
+
if (typeof value !== 'string' || value.length === 0 || value.length > 512) throw new SchedulePauseError('bad-request', `${field} must be a non-empty string.`);
|
|
330
|
+
return value;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** The dsh data directory: the parent of config `root` (dshHomePath('sessions')), else `$DSH_HOME`, else `~/.dsh`. */
|
|
334
|
+
export function dataDirFor(config) {
|
|
335
|
+
if (isRecord(config) && typeof config.root === 'string' && config.root) return dirname(config.root);
|
|
336
|
+
return process.env.DSH_HOME || join(homedir(), '.dsh');
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** Cordis entry. Provides `schedulePause`, bound for the Typert gateway (`typertRemote`). */
|
|
340
|
+
export function apply(ctx, config) {
|
|
341
|
+
const service = new SchedulePause({ dataDir: dataDirFor(config), schedule: () => ctx.get('schedule') });
|
|
342
|
+
service.typertRemote = Object.freeze({ service, serviceKey: SERVICE_KEY, namespace: SERVICE_KEY });
|
|
343
|
+
ctx.provide(SERVICE_KEY, service);
|
|
344
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@picasso/schedule-pause",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "dsh cordis plugin: schedulePause/pause|resume|delete|catalog|list Host Remote endpoints. Pause snapshots a schedule into a JSON sidecar and deletes it in dsh; resume recreates it through dsh's schedule service and verifies the definition.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./index.js",
|
|
10
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"dshTarget": "0.2.2-rc.3",
|
|
14
|
+
"dsh": {
|
|
15
|
+
"bundle": {
|
|
16
|
+
"patch": "./cordis.patch.yml"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "node --import ../../test/setup/hermetic-preload.mjs --test test/*.test.mjs"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"index.js",
|
|
24
|
+
"cordis.patch.yml",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"license": "UNLICENSED"
|
|
28
|
+
}
|