@try-works/dsh-righthand 0.1.3 → 0.1.4
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 +5 -4
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/lib/task-tools.d.ts +44 -0
- package/lib/task-tools.d.ts.map +1 -0
- package/lib/task-tools.js +212 -0
- package/lib/task-tools.js.map +1 -0
- package/package.json +1 -1
- package/skills/dsh-righthand/SKILL.md +10 -2
- package/src/index.ts +4 -1
- package/src/task-tools.ts +236 -0
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ dsh --profile <profile> --patch ./cordis.patch.yml
|
|
|
25
25
|
| Tool | Family | Backing service |
|
|
26
26
|
|---|---|---|
|
|
27
27
|
| `rh_store_put` / `rh_store_get` / `rh_store_delete` / `rh_store_list` | store | `ctx.storageDomain` (domain KV) |
|
|
28
|
+
| `rh_task_create` / `rh_task_list` / `rh_task_next` / `rh_task_update` / `rh_task_delete` | tasks | `ctx.storageDomain` (typed `righthand_tasks` domain; state machine open → done/failed) |
|
|
28
29
|
| `rh_credential_describe` / `rh_credential_set` / `rh_credential_unset` | secrets | `ctx.credentials` (values never echoed) |
|
|
29
30
|
| `rh_settings_get` / `rh_settings_set` | secrets | `ctx.settings` (namespace `righthand`) |
|
|
30
31
|
| `rh_run` | exec | `ctx.subprocess` (collect mode, bounded output) |
|
|
@@ -137,10 +138,10 @@ so the agent cannot deploy or destroy without the gate.
|
|
|
137
138
|
|
|
138
139
|
## Service availability
|
|
139
140
|
|
|
140
|
-
The store
|
|
141
|
-
(`storage` + `storage-json` + `storage-domain` rows). In a profile
|
|
142
|
-
it — e.g. the headless bundle —
|
|
143
|
-
seven tools still register; the plugin never fails the boot.
|
|
141
|
+
The store and task families need `ctx.storageDomain`, which the web profile
|
|
142
|
+
provides (`storage` + `storage-json` + `storage-domain` rows). In a profile
|
|
143
|
+
without it — e.g. the headless bundle — those nine tools stay dormant and the
|
|
144
|
+
other seven tools still register; the plugin never fails the boot.
|
|
144
145
|
|
|
145
146
|
## Development
|
|
146
147
|
|
package/lib/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* Modules (each individually mountable via `export * as ...`):
|
|
15
15
|
* - store-tools: rh_store_put/get/delete/list over ctx.storageDomain
|
|
16
16
|
* - secrets-tools: rh_credential_describe/set/unset + rh_settings_get/set
|
|
17
|
+
* - task-tools: rh_task_create/list/next/update/delete over ctx.storageDomain
|
|
17
18
|
* - exec-tools: rh_run / rh_run_bg over ctx.subprocess + ctx.jobs
|
|
18
19
|
* - guard-tools: tools/pre-execute policy (config.rules)
|
|
19
20
|
* - skills: the packaged dsh-righthand skill (ctx.skills)
|
|
@@ -25,6 +26,7 @@ import * as storeTools from './store-tools.ts';
|
|
|
25
26
|
import * as secretsTools from './secrets-tools.ts';
|
|
26
27
|
import * as execTools from './exec-tools.ts';
|
|
27
28
|
import * as guardTools from './guard-tools.ts';
|
|
29
|
+
import * as taskTools from './task-tools.ts';
|
|
28
30
|
import * as righthandSkills from './skills.ts';
|
|
29
31
|
import type { GuardRule } from './guard-tools.ts';
|
|
30
32
|
export declare const name = "dsh-righthand";
|
|
@@ -42,7 +44,7 @@ export interface RighthandConfig {
|
|
|
42
44
|
* instead of failing the whole plugin.
|
|
43
45
|
*/
|
|
44
46
|
export declare function apply(ctx: Context, config?: RighthandConfig): void;
|
|
45
|
-
export { storeTools, secretsTools, execTools, guardTools, righthandSkills };
|
|
47
|
+
export { storeTools, secretsTools, execTools, taskTools, guardTools, righthandSkills };
|
|
46
48
|
export { SKILL_NAME, SKILL_DESCRIPTION, skillDirectory, skillBody } from './skills.ts';
|
|
47
49
|
export type { GuardRule } from './guard-tools.ts';
|
|
48
50
|
export { guardFactsFor } from './guard-tools.ts';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAA;AAC9C,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAA;AAC9C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,eAAe,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAEjD,eAAO,MAAM,IAAI,kBAAkB,CAAA;AAEnC,iFAAiF;AACjF,eAAO,MAAM,MAAM,EAAE,MAAM,EAAO,CAAA;AAElC,qCAAqC;AACrC,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,KAAK,CAAC,EAAE,SAAS,EAAE,CAAA;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,eAAoB,GAAG,IAAI,CAOtE;AAGD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,CAAA;AACtF,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACtF,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* Modules (each individually mountable via `export * as ...`):
|
|
15
15
|
* - store-tools: rh_store_put/get/delete/list over ctx.storageDomain
|
|
16
16
|
* - secrets-tools: rh_credential_describe/set/unset + rh_settings_get/set
|
|
17
|
+
* - task-tools: rh_task_create/list/next/update/delete over ctx.storageDomain
|
|
17
18
|
* - exec-tools: rh_run / rh_run_bg over ctx.subprocess + ctx.jobs
|
|
18
19
|
* - guard-tools: tools/pre-execute policy (config.rules)
|
|
19
20
|
* - skills: the packaged dsh-righthand skill (ctx.skills)
|
|
@@ -24,6 +25,7 @@ import * as storeTools from "./store-tools.js";
|
|
|
24
25
|
import * as secretsTools from "./secrets-tools.js";
|
|
25
26
|
import * as execTools from "./exec-tools.js";
|
|
26
27
|
import * as guardTools from "./guard-tools.js";
|
|
28
|
+
import * as taskTools from "./task-tools.js";
|
|
27
29
|
import * as righthandSkills from "./skills.js";
|
|
28
30
|
export const name = 'dsh-righthand';
|
|
29
31
|
/** The combined plugin needs no services itself; each child waits on its own. */
|
|
@@ -38,11 +40,12 @@ export function apply(ctx, config = {}) {
|
|
|
38
40
|
ctx.plugin(storeTools);
|
|
39
41
|
ctx.plugin(secretsTools);
|
|
40
42
|
ctx.plugin(execTools);
|
|
43
|
+
ctx.plugin(taskTools);
|
|
41
44
|
ctx.plugin(guardTools, { rules: config.rules ?? [] });
|
|
42
45
|
ctx.plugin(righthandSkills);
|
|
43
46
|
}
|
|
44
47
|
// Individual modules stay importable for selective mounting.
|
|
45
|
-
export { storeTools, secretsTools, execTools, guardTools, righthandSkills };
|
|
48
|
+
export { storeTools, secretsTools, execTools, taskTools, guardTools, righthandSkills };
|
|
46
49
|
export { SKILL_NAME, SKILL_DESCRIPTION, skillDirectory, skillBody } from "./skills.js";
|
|
47
50
|
export { guardFactsFor } from "./guard-tools.js";
|
|
48
51
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.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 -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* task-tools — rh_task_* over ctx.storageDomain.
|
|
3
|
+
* A typed task board with a state machine: open → done | failed.
|
|
4
|
+
* `rh_task_next` is the queue discipline — the oldest open task is what to
|
|
5
|
+
* work on now. Descriptions carry the rule that a task's failure is recorded
|
|
6
|
+
* like an answer: a run that could not happen is news the owner needs.
|
|
7
|
+
* @module dsh-righthand/task-tools
|
|
8
|
+
*/
|
|
9
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
10
|
+
import type { Domain } from '@deepseek-ai/dsh-storage-domain';
|
|
11
|
+
export declare const name = "righthand-task";
|
|
12
|
+
export declare const inject: string[];
|
|
13
|
+
export type TaskState = 'open' | 'done' | 'failed';
|
|
14
|
+
export interface Task {
|
|
15
|
+
id: string;
|
|
16
|
+
title: string;
|
|
17
|
+
detail: string;
|
|
18
|
+
due: string;
|
|
19
|
+
state: TaskState;
|
|
20
|
+
result: string;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
updatedAt: string;
|
|
23
|
+
}
|
|
24
|
+
/** Domain spec: the typed task table. */
|
|
25
|
+
export declare const taskDomain: {
|
|
26
|
+
name: string;
|
|
27
|
+
version: number;
|
|
28
|
+
tables: {
|
|
29
|
+
tasks: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, {
|
|
30
|
+
id: string;
|
|
31
|
+
title: string;
|
|
32
|
+
detail: string;
|
|
33
|
+
due: string;
|
|
34
|
+
state: "failed" | "open" | "done";
|
|
35
|
+
result: string;
|
|
36
|
+
createdAt: string;
|
|
37
|
+
updatedAt: string;
|
|
38
|
+
}>;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export type TaskDomain = Domain<typeof taskDomain>;
|
|
42
|
+
/** Open the task domain and register the model-facing tools. */
|
|
43
|
+
export declare function apply(ctx: Context): void;
|
|
44
|
+
//# sourceMappingURL=task-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-tools.d.ts","sourceRoot":"","sources":["../src/task-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGlD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAA;AAG7D,eAAO,MAAM,IAAI,mBAAmB,CAAA;AACpC,eAAO,MAAM,MAAM,UAA6B,CAAA;AAEhD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAA;AAElD,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,SAAS,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,yCAAyC;AACzC,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;CAerB,CAAA;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAA;AAMlD,gEAAgE;AAChE,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAgLxC"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* task-tools — rh_task_* over ctx.storageDomain.
|
|
3
|
+
* A typed task board with a state machine: open → done | failed.
|
|
4
|
+
* `rh_task_next` is the queue discipline — the oldest open task is what to
|
|
5
|
+
* work on now. Descriptions carry the rule that a task's failure is recorded
|
|
6
|
+
* like an answer: a run that could not happen is news the owner needs.
|
|
7
|
+
* @module dsh-righthand/task-tools
|
|
8
|
+
*/
|
|
9
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
10
|
+
import { defineDomain, domainTable } from '@deepseek-ai/dsh-storage-domain';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
export const name = 'righthand-task';
|
|
13
|
+
export const inject = ['tools', 'storageDomain'];
|
|
14
|
+
/** Domain spec: the typed task table. */
|
|
15
|
+
export const taskDomain = defineDomain({
|
|
16
|
+
name: 'righthand_tasks',
|
|
17
|
+
version: 1,
|
|
18
|
+
tables: {
|
|
19
|
+
tasks: domainTable(z.object({
|
|
20
|
+
id: z.string(),
|
|
21
|
+
title: z.string(),
|
|
22
|
+
detail: z.string(),
|
|
23
|
+
due: z.string(),
|
|
24
|
+
state: z.enum(['open', 'done', 'failed']),
|
|
25
|
+
result: z.string(),
|
|
26
|
+
createdAt: z.string(),
|
|
27
|
+
updatedAt: z.string(),
|
|
28
|
+
})),
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
function newId() {
|
|
32
|
+
return 't-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 6);
|
|
33
|
+
}
|
|
34
|
+
/** Open the task domain and register the model-facing tools. */
|
|
35
|
+
export function apply(ctx) {
|
|
36
|
+
let domain;
|
|
37
|
+
let ready;
|
|
38
|
+
ctx.effect(() => {
|
|
39
|
+
ready = (async () => {
|
|
40
|
+
domain = await ctx.storageDomain.open(taskDomain);
|
|
41
|
+
})();
|
|
42
|
+
return () => { };
|
|
43
|
+
});
|
|
44
|
+
const ensure = async () => {
|
|
45
|
+
if (domain === undefined) {
|
|
46
|
+
await ready;
|
|
47
|
+
}
|
|
48
|
+
if (domain === undefined)
|
|
49
|
+
throw new Error('righthand tasks are not open (storageDomain not mounted)');
|
|
50
|
+
return domain;
|
|
51
|
+
};
|
|
52
|
+
const all = async () => {
|
|
53
|
+
const d = await ensure();
|
|
54
|
+
return [...d.table('tasks').entries()].map(([, t]) => t);
|
|
55
|
+
};
|
|
56
|
+
ctx.tools.register(defineTool({
|
|
57
|
+
name: 'rh_task_create',
|
|
58
|
+
description: 'Add a task with a title, optional detail and due date. Returns the created task with a generated id and state open. A task the agent cannot run is still recorded — its failure is delivered like an answer.',
|
|
59
|
+
parameters: {
|
|
60
|
+
title: { type: 'string', required: true, description: 'What the task is, e.g. "deploy vision-worker".' },
|
|
61
|
+
detail: { type: 'string', description: 'Optional longer description of what done means.' },
|
|
62
|
+
due: { type: 'string', description: 'Optional due date, YYYY-MM-DD.' },
|
|
63
|
+
},
|
|
64
|
+
output: {
|
|
65
|
+
schema: {
|
|
66
|
+
type: 'object',
|
|
67
|
+
additionalProperties: false,
|
|
68
|
+
properties: {
|
|
69
|
+
id: { type: 'string', required: true },
|
|
70
|
+
title: { type: 'string', required: true },
|
|
71
|
+
state: { type: 'string', required: true },
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
render: (_args, value) => [{ type: 'text', text: 'task ' + value.id + ' created: ' + value.title + ' (open)' }],
|
|
75
|
+
},
|
|
76
|
+
async execute(args) {
|
|
77
|
+
const d = await ensure();
|
|
78
|
+
const now = new Date().toISOString();
|
|
79
|
+
const task = {
|
|
80
|
+
id: newId(),
|
|
81
|
+
title: args.title.trim(),
|
|
82
|
+
detail: args.detail ?? '',
|
|
83
|
+
due: args.due ?? '',
|
|
84
|
+
state: 'open',
|
|
85
|
+
result: '',
|
|
86
|
+
createdAt: now,
|
|
87
|
+
updatedAt: now,
|
|
88
|
+
};
|
|
89
|
+
if (task.title === '')
|
|
90
|
+
throw new Error('a task needs a title');
|
|
91
|
+
await d.table('tasks').put(task.id, task);
|
|
92
|
+
return { id: task.id, title: task.title, state: task.state };
|
|
93
|
+
},
|
|
94
|
+
}));
|
|
95
|
+
ctx.tools.register(defineTool({
|
|
96
|
+
name: 'rh_task_list',
|
|
97
|
+
description: 'List tasks, open ones first (oldest open first). Optionally filter by state.',
|
|
98
|
+
parameters: {
|
|
99
|
+
state: { type: 'string', description: 'Filter: open | done | failed. Omit for all tasks.' },
|
|
100
|
+
},
|
|
101
|
+
output: {
|
|
102
|
+
schema: {
|
|
103
|
+
type: 'array',
|
|
104
|
+
items: {
|
|
105
|
+
type: 'object',
|
|
106
|
+
additionalProperties: false,
|
|
107
|
+
properties: {
|
|
108
|
+
id: { type: 'string', required: true },
|
|
109
|
+
title: { type: 'string', required: true },
|
|
110
|
+
state: { type: 'string', required: true },
|
|
111
|
+
due: { type: 'string' },
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
render: (_args, tasks) => [{ type: 'text', text: tasks.length === 0 ? '(no tasks)' : tasks.map((t) => '[' + t.state + '] ' + t.title).join(' / ') }],
|
|
116
|
+
},
|
|
117
|
+
async execute(args) {
|
|
118
|
+
const tasks = await all();
|
|
119
|
+
const wanted = args.state ?? null;
|
|
120
|
+
const filtered = wanted ? tasks.filter(t => t.state === wanted) : tasks;
|
|
121
|
+
const rank = { open: 0, done: 1, failed: 2 };
|
|
122
|
+
filtered.sort((a, b) => (rank[a.state] - rank[b.state]) || a.createdAt.localeCompare(b.createdAt));
|
|
123
|
+
return filtered.map(t => ({ id: t.id, title: t.title, state: t.state, ...t.due ? { due: t.due } : {} }));
|
|
124
|
+
},
|
|
125
|
+
}));
|
|
126
|
+
ctx.tools.register(defineTool({
|
|
127
|
+
name: 'rh_task_next',
|
|
128
|
+
description: 'The next open task — what to work on now. Oldest open task first. Returns found: false when nothing is open.',
|
|
129
|
+
parameters: {},
|
|
130
|
+
output: {
|
|
131
|
+
schema: {
|
|
132
|
+
type: 'object',
|
|
133
|
+
additionalProperties: false,
|
|
134
|
+
properties: {
|
|
135
|
+
found: { type: 'boolean', required: true },
|
|
136
|
+
id: { type: 'string' },
|
|
137
|
+
title: { type: 'string' },
|
|
138
|
+
detail: { type: 'string' },
|
|
139
|
+
due: { type: 'string' },
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
render: (_args, value) => [{ type: 'text', text: value.found ? 'next: ' + value.title : '(nothing open)' }],
|
|
143
|
+
},
|
|
144
|
+
async execute() {
|
|
145
|
+
const tasks = await all();
|
|
146
|
+
const open = tasks.filter(t => t.state === 'open').sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
147
|
+
const t = open[0];
|
|
148
|
+
if (t === undefined)
|
|
149
|
+
return { found: false };
|
|
150
|
+
return { found: true, id: t.id, title: t.title, ...t.detail ? { detail: t.detail } : {}, ...t.due ? { due: t.due } : {} };
|
|
151
|
+
},
|
|
152
|
+
}));
|
|
153
|
+
ctx.tools.register(defineTool({
|
|
154
|
+
name: 'rh_task_update',
|
|
155
|
+
description: 'Change a task: its state (open | done | failed) and/or its result. A failed task should carry its result — what was tried and what went wrong — so the record says what happened, not just that something did.',
|
|
156
|
+
parameters: {
|
|
157
|
+
id: { type: 'string', required: true, description: 'The task id from rh_task_create or rh_task_list.' },
|
|
158
|
+
state: { type: 'string', description: 'New state: open | done | failed.' },
|
|
159
|
+
result: { type: 'string', description: 'What happened — the outcome, or the failure reason.' },
|
|
160
|
+
},
|
|
161
|
+
output: {
|
|
162
|
+
schema: {
|
|
163
|
+
type: 'object',
|
|
164
|
+
additionalProperties: false,
|
|
165
|
+
properties: {
|
|
166
|
+
found: { type: 'boolean', required: true },
|
|
167
|
+
id: { type: 'string', required: true },
|
|
168
|
+
state: { type: 'string', required: true },
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
render: (_args, value) => [{ type: 'text', text: value.found ? 'task ' + value.id + ' -> ' + value.state : 'task ' + value.id + ' not found' }],
|
|
172
|
+
},
|
|
173
|
+
async execute(args) {
|
|
174
|
+
const d = await ensure();
|
|
175
|
+
const task = d.table('tasks').get(args.id);
|
|
176
|
+
if (task === undefined)
|
|
177
|
+
return { found: false, id: args.id, state: 'open' };
|
|
178
|
+
const next = {
|
|
179
|
+
...task,
|
|
180
|
+
...args.state !== undefined ? { state: args.state } : {},
|
|
181
|
+
...args.result !== undefined ? { result: args.result } : {},
|
|
182
|
+
updatedAt: new Date().toISOString(),
|
|
183
|
+
};
|
|
184
|
+
await d.table('tasks').put(args.id, next);
|
|
185
|
+
return { found: true, id: args.id, state: next.state };
|
|
186
|
+
},
|
|
187
|
+
}));
|
|
188
|
+
ctx.tools.register(defineTool({
|
|
189
|
+
name: 'rh_task_delete',
|
|
190
|
+
description: 'Remove a task by id. Returns whether it existed.',
|
|
191
|
+
parameters: {
|
|
192
|
+
id: { type: 'string', required: true, description: 'The task id to remove.' },
|
|
193
|
+
},
|
|
194
|
+
output: {
|
|
195
|
+
schema: {
|
|
196
|
+
type: 'object',
|
|
197
|
+
additionalProperties: false,
|
|
198
|
+
properties: {
|
|
199
|
+
id: { type: 'string', required: true },
|
|
200
|
+
existed: { type: 'boolean', required: true },
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
render: (_args, value) => [{ type: 'text', text: 'deleted ' + value.id + ': ' + value.existed }],
|
|
204
|
+
},
|
|
205
|
+
async execute(args) {
|
|
206
|
+
const d = await ensure();
|
|
207
|
+
const existed = await d.table('tasks').delete(args.id);
|
|
208
|
+
return { id: args.id, existed };
|
|
209
|
+
},
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=task-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-tools.js","sourceRoot":"","sources":["../src/task-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAE3E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,IAAI,GAAG,gBAAgB,CAAA;AACpC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;AAehD,yCAAyC;AACzC,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;IACrC,IAAI,EAAE,iBAAiB;IACvB,OAAO,EAAE,CAAC;IACV,MAAM,EAAE;QACN,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC;YAC1B,EAAE,EAAE,CAAC,CAAC,MA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,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@try-works/dsh-righthand",
|
|
3
3
|
"description": "DeepSeek Harness plugin: DSH-native righthand tools — durable KV store, credential/settings management, governed exec, and a tool guard",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -12,6 +12,7 @@ The righthand toolkit: DSH-native tools over the harness's own services. Use thi
|
|
|
12
12
|
| Family | Tools | Backing service | Use when |
|
|
13
13
|
|--------|-------|-----------------|----------|
|
|
14
14
|
| store | `rh_store_put` / `rh_store_get` / `rh_store_delete` / `rh_store_list` | `ctx.storageDomain` (domain KV) | The task needs durable state across turns: a catalog, counter, cache, or note. Prefer this over files for structured JSON records. |
|
|
15
|
+
| tasks | `rh_task_create` / `rh_task_list` / `rh_task_next` / `rh_task_update` / `rh_task_delete` | `ctx.storageDomain` (typed `righthand_tasks` domain) | A task board with a state machine (open → done/failed). `rh_task_next` is the oldest open task — what to work on now. A failed task's `result` records what went wrong: a task that cannot run is still recorded, never silently dropped. |
|
|
15
16
|
| secrets | `rh_credential_describe` / `rh_credential_set` / `rh_credential_unset` | `ctx.credentials` | The task must check, store, or remove a credential reference (e.g. `CLOUDFLARE_API_TOKEN`). Values are written durably and **never echoed back**. |
|
|
16
17
|
| settings | `rh_settings_get` / `rh_settings_set` | `ctx.settings` (namespace `righthand`) | Reading or patching righthand settings (`accountId`, `defaultZone`, `defaultScriptPrefix`). |
|
|
17
18
|
| exec | `rh_run` / `rh_run_bg` | `ctx.subprocess` + `ctx.jobs` | Running one command (argv array, no shell interpretation). `rh_run` collects bounded output; `rh_run_bg` starts an owner-scoped background job and returns its id. |
|
|
@@ -23,6 +24,13 @@ The righthand toolkit: DSH-native tools over the harness's own services. Use thi
|
|
|
23
24
|
- `rh_store_get` returns `{ found, key, value?, updatedAt? }` — `found: false` means the key is absent, not an error.
|
|
24
25
|
- Writes are durable (backend flush before commit) and serialized on one write chain; values must be JSON-serializable.
|
|
25
26
|
|
|
27
|
+
## Task semantics
|
|
28
|
+
|
|
29
|
+
- One domain `righthand_tasks`: a `tasks` table keyed by generated task id (`t-...`).
|
|
30
|
+
- States: `open` → `done` | `failed`. `rh_task_next` returns the oldest open task; nothing open returns `{ found: false }`.
|
|
31
|
+
- `rh_task_update` takes a state and/or a `result` — a failed task should carry what was tried and what went wrong, so the record says what happened.
|
|
32
|
+
- `rh_task_list` sorts open first (oldest first), then done, then failed; `state` filters.
|
|
33
|
+
|
|
26
34
|
## Credential semantics
|
|
27
35
|
|
|
28
36
|
- `rh_credential_describe` reports `configured`, `source`, `writable` — never the value.
|
|
@@ -45,5 +53,5 @@ Rules come from the plugin config (`rules: [{ toolPrefix, mode, ask?, destructiv
|
|
|
45
53
|
|
|
46
54
|
## Service availability
|
|
47
55
|
|
|
48
|
-
- **web profile**: all
|
|
49
|
-
- **other profiles** (e.g. headless): the store
|
|
56
|
+
- **web profile**: all sixteen tools register (`storageDomain` is provided by the web app rows).
|
|
57
|
+
- **other profiles** (e.g. headless): the store and task families stay dormant; the other seven tools still register. The plugin never fails the boot.
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* Modules (each individually mountable via `export * as ...`):
|
|
15
15
|
* - store-tools: rh_store_put/get/delete/list over ctx.storageDomain
|
|
16
16
|
* - secrets-tools: rh_credential_describe/set/unset + rh_settings_get/set
|
|
17
|
+
* - task-tools: rh_task_create/list/next/update/delete over ctx.storageDomain
|
|
17
18
|
* - exec-tools: rh_run / rh_run_bg over ctx.subprocess + ctx.jobs
|
|
18
19
|
* - guard-tools: tools/pre-execute policy (config.rules)
|
|
19
20
|
* - skills: the packaged dsh-righthand skill (ctx.skills)
|
|
@@ -26,6 +27,7 @@ import * as storeTools from './store-tools.ts'
|
|
|
26
27
|
import * as secretsTools from './secrets-tools.ts'
|
|
27
28
|
import * as execTools from './exec-tools.ts'
|
|
28
29
|
import * as guardTools from './guard-tools.ts'
|
|
30
|
+
import * as taskTools from './task-tools.ts'
|
|
29
31
|
import * as righthandSkills from './skills.ts'
|
|
30
32
|
import type { GuardRule } from './guard-tools.ts'
|
|
31
33
|
|
|
@@ -50,12 +52,13 @@ export function apply(ctx: Context, config: RighthandConfig = {}): void {
|
|
|
50
52
|
ctx.plugin(storeTools)
|
|
51
53
|
ctx.plugin(secretsTools)
|
|
52
54
|
ctx.plugin(execTools)
|
|
55
|
+
ctx.plugin(taskTools)
|
|
53
56
|
ctx.plugin(guardTools, { rules: config.rules ?? [] })
|
|
54
57
|
ctx.plugin(righthandSkills)
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
// Individual modules stay importable for selective mounting.
|
|
58
|
-
export { storeTools, secretsTools, execTools, guardTools, righthandSkills }
|
|
61
|
+
export { storeTools, secretsTools, execTools, taskTools, guardTools, righthandSkills }
|
|
59
62
|
export { SKILL_NAME, SKILL_DESCRIPTION, skillDirectory, skillBody } from './skills.ts'
|
|
60
63
|
export type { GuardRule } from './guard-tools.ts'
|
|
61
64
|
export { guardFactsFor } from './guard-tools.ts'
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* task-tools — rh_task_* over ctx.storageDomain.
|
|
3
|
+
* A typed task board with a state machine: open → done | failed.
|
|
4
|
+
* `rh_task_next` is the queue discipline — the oldest open task is what to
|
|
5
|
+
* work on now. Descriptions carry the rule that a task's failure is recorded
|
|
6
|
+
* like an answer: a run that could not happen is news the owner needs.
|
|
7
|
+
* @module dsh-righthand/task-tools
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
11
|
+
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
12
|
+
import { defineDomain, domainTable } from '@deepseek-ai/dsh-storage-domain'
|
|
13
|
+
import type { Domain } from '@deepseek-ai/dsh-storage-domain'
|
|
14
|
+
import { z } from 'zod'
|
|
15
|
+
|
|
16
|
+
export const name = 'righthand-task'
|
|
17
|
+
export const inject = ['tools', 'storageDomain']
|
|
18
|
+
|
|
19
|
+
export type TaskState = 'open' | 'done' | 'failed'
|
|
20
|
+
|
|
21
|
+
export interface Task {
|
|
22
|
+
id: string
|
|
23
|
+
title: string
|
|
24
|
+
detail: string
|
|
25
|
+
due: string
|
|
26
|
+
state: TaskState
|
|
27
|
+
result: string
|
|
28
|
+
createdAt: string
|
|
29
|
+
updatedAt: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Domain spec: the typed task table. */
|
|
33
|
+
export const taskDomain = defineDomain({
|
|
34
|
+
name: 'righthand_tasks',
|
|
35
|
+
version: 1,
|
|
36
|
+
tables: {
|
|
37
|
+
tasks: domainTable(z.object({
|
|
38
|
+
id: z.string(),
|
|
39
|
+
title: z.string(),
|
|
40
|
+
detail: z.string(),
|
|
41
|
+
due: z.string(),
|
|
42
|
+
state: z.enum(['open', 'done', 'failed']),
|
|
43
|
+
result: z.string(),
|
|
44
|
+
createdAt: z.string(),
|
|
45
|
+
updatedAt: z.string(),
|
|
46
|
+
})),
|
|
47
|
+
},
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
export type TaskDomain = Domain<typeof taskDomain>
|
|
51
|
+
|
|
52
|
+
function newId(): string {
|
|
53
|
+
return 't-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 6)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Open the task domain and register the model-facing tools. */
|
|
57
|
+
export function apply(ctx: Context): void {
|
|
58
|
+
let domain: TaskDomain | undefined
|
|
59
|
+
let ready: Promise<void> | undefined
|
|
60
|
+
|
|
61
|
+
ctx.effect(() => {
|
|
62
|
+
ready = (async () => {
|
|
63
|
+
domain = await ctx.storageDomain.open(taskDomain)
|
|
64
|
+
})()
|
|
65
|
+
return () => { /* domain facility owns the domain */ }
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const ensure = async (): Promise<TaskDomain> => {
|
|
69
|
+
if (domain === undefined) { await ready; }
|
|
70
|
+
if (domain === undefined) throw new Error('righthand tasks are not open (storageDomain not mounted)')
|
|
71
|
+
return domain
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const all = async (): Promise<Task[]> => {
|
|
75
|
+
const d = await ensure()
|
|
76
|
+
return [...d.table('tasks').entries()].map(([, t]) => t)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
ctx.tools.register(defineTool({
|
|
80
|
+
name: 'rh_task_create',
|
|
81
|
+
description: 'Add a task with a title, optional detail and due date. Returns the created task with a generated id and state open. A task the agent cannot run is still recorded — its failure is delivered like an answer.',
|
|
82
|
+
parameters: {
|
|
83
|
+
title: { type: 'string', required: true, description: 'What the task is, e.g. "deploy vision-worker".' },
|
|
84
|
+
detail: { type: 'string', description: 'Optional longer description of what done means.' },
|
|
85
|
+
due: { type: 'string', description: 'Optional due date, YYYY-MM-DD.' },
|
|
86
|
+
},
|
|
87
|
+
output: {
|
|
88
|
+
schema: {
|
|
89
|
+
type: 'object',
|
|
90
|
+
additionalProperties: false,
|
|
91
|
+
properties: {
|
|
92
|
+
id: { type: 'string', required: true },
|
|
93
|
+
title: { type: 'string', required: true },
|
|
94
|
+
state: { type: 'string', required: true },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
render: (_args, value) => [{ type: 'text', text: 'task ' + value.id + ' created: ' + value.title + ' (open)' }],
|
|
98
|
+
},
|
|
99
|
+
async execute(args) {
|
|
100
|
+
const d = await ensure()
|
|
101
|
+
const now = new Date().toISOString()
|
|
102
|
+
const task: Task = {
|
|
103
|
+
id: newId(),
|
|
104
|
+
title: args.title.trim(),
|
|
105
|
+
detail: args.detail ?? '',
|
|
106
|
+
due: args.due ?? '',
|
|
107
|
+
state: 'open',
|
|
108
|
+
result: '',
|
|
109
|
+
createdAt: now,
|
|
110
|
+
updatedAt: now,
|
|
111
|
+
}
|
|
112
|
+
if (task.title === '') throw new Error('a task needs a title')
|
|
113
|
+
await d.table('tasks').put(task.id, task)
|
|
114
|
+
return { id: task.id, title: task.title, state: task.state }
|
|
115
|
+
},
|
|
116
|
+
}))
|
|
117
|
+
ctx.tools.register(defineTool({
|
|
118
|
+
name: 'rh_task_list',
|
|
119
|
+
description: 'List tasks, open ones first (oldest open first). Optionally filter by state.',
|
|
120
|
+
parameters: {
|
|
121
|
+
state: { type: 'string', description: 'Filter: open | done | failed. Omit for all tasks.' },
|
|
122
|
+
},
|
|
123
|
+
output: {
|
|
124
|
+
schema: {
|
|
125
|
+
type: 'array',
|
|
126
|
+
items: {
|
|
127
|
+
type: 'object',
|
|
128
|
+
additionalProperties: false,
|
|
129
|
+
properties: {
|
|
130
|
+
id: { type: 'string', required: true },
|
|
131
|
+
title: { type: 'string', required: true },
|
|
132
|
+
state: { type: 'string', required: true },
|
|
133
|
+
due: { type: 'string' },
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
render: (_args, tasks) => [{ type: 'text', text: tasks.length === 0 ? '(no tasks)' : tasks.map((t: any) => '[' + t.state + '] ' + t.title).join(' / ') }],
|
|
138
|
+
},
|
|
139
|
+
async execute(args) {
|
|
140
|
+
const tasks = await all()
|
|
141
|
+
const wanted = args.state ?? null
|
|
142
|
+
const filtered = wanted ? tasks.filter(t => t.state === wanted) : tasks
|
|
143
|
+
const rank = { open: 0, done: 1, failed: 2 } as Record<string, number>
|
|
144
|
+
filtered.sort((a, b) => (rank[a.state] - rank[b.state]) || a.createdAt.localeCompare(b.createdAt))
|
|
145
|
+
return filtered.map(t => ({ id: t.id, title: t.title, state: t.state, ...t.due ? { due: t.due } : {} }))
|
|
146
|
+
},
|
|
147
|
+
}))
|
|
148
|
+
|
|
149
|
+
ctx.tools.register(defineTool({
|
|
150
|
+
name: 'rh_task_next',
|
|
151
|
+
description: 'The next open task — what to work on now. Oldest open task first. Returns found: false when nothing is open.',
|
|
152
|
+
parameters: {},
|
|
153
|
+
output: {
|
|
154
|
+
schema: {
|
|
155
|
+
type: 'object',
|
|
156
|
+
additionalProperties: false,
|
|
157
|
+
properties: {
|
|
158
|
+
found: { type: 'boolean', required: true },
|
|
159
|
+
id: { type: 'string' },
|
|
160
|
+
title: { type: 'string' },
|
|
161
|
+
detail: { type: 'string' },
|
|
162
|
+
due: { type: 'string' },
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
render: (_args, value) => [{ type: 'text', text: value.found ? 'next: ' + value.title : '(nothing open)' }],
|
|
166
|
+
},
|
|
167
|
+
async execute() {
|
|
168
|
+
const tasks = await all()
|
|
169
|
+
const open = tasks.filter(t => t.state === 'open').sort((a, b) => a.createdAt.localeCompare(b.createdAt))
|
|
170
|
+
const t = open[0]
|
|
171
|
+
if (t === undefined) return { found: false }
|
|
172
|
+
return { found: true, id: t.id, title: t.title, ...t.detail ? { detail: t.detail } : {}, ...t.due ? { due: t.due } : {} }
|
|
173
|
+
},
|
|
174
|
+
}))
|
|
175
|
+
ctx.tools.register(defineTool({
|
|
176
|
+
name: 'rh_task_update',
|
|
177
|
+
description: 'Change a task: its state (open | done | failed) and/or its result. A failed task should carry its result — what was tried and what went wrong — so the record says what happened, not just that something did.',
|
|
178
|
+
parameters: {
|
|
179
|
+
id: { type: 'string', required: true, description: 'The task id from rh_task_create or rh_task_list.' },
|
|
180
|
+
state: { type: 'string', description: 'New state: open | done | failed.' },
|
|
181
|
+
result: { type: 'string', description: 'What happened — the outcome, or the failure reason.' },
|
|
182
|
+
},
|
|
183
|
+
output: {
|
|
184
|
+
schema: {
|
|
185
|
+
type: 'object',
|
|
186
|
+
additionalProperties: false,
|
|
187
|
+
properties: {
|
|
188
|
+
found: { type: 'boolean', required: true },
|
|
189
|
+
id: { type: 'string', required: true },
|
|
190
|
+
state: { type: 'string', required: true },
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
render: (_args, value) => [{ type: 'text', text: value.found ? 'task ' + value.id + ' -> ' + value.state : 'task ' + value.id + ' not found' }],
|
|
194
|
+
},
|
|
195
|
+
async execute(args) {
|
|
196
|
+
const d = await ensure()
|
|
197
|
+
const task = d.table('tasks').get(args.id)
|
|
198
|
+
if (task === undefined) return { found: false, id: args.id, state: 'open' }
|
|
199
|
+
const next: Task = {
|
|
200
|
+
...task,
|
|
201
|
+
...args.state !== undefined ? { state: args.state as TaskState } : {},
|
|
202
|
+
...args.result !== undefined ? { result: args.result } : {},
|
|
203
|
+
updatedAt: new Date().toISOString(),
|
|
204
|
+
}
|
|
205
|
+
await d.table('tasks').put(args.id, next)
|
|
206
|
+
return { found: true, id: args.id, state: next.state }
|
|
207
|
+
},
|
|
208
|
+
}))
|
|
209
|
+
|
|
210
|
+
ctx.tools.register(defineTool({
|
|
211
|
+
name: 'rh_task_delete',
|
|
212
|
+
description: 'Remove a task by id. Returns whether it existed.',
|
|
213
|
+
parameters: {
|
|
214
|
+
id: { type: 'string', required: true, description: 'The task id to remove.' },
|
|
215
|
+
},
|
|
216
|
+
output: {
|
|
217
|
+
schema: {
|
|
218
|
+
type: 'object',
|
|
219
|
+
additionalProperties: false,
|
|
220
|
+
properties: {
|
|
221
|
+
id: { type: 'string', required: true },
|
|
222
|
+
existed: { type: 'boolean', required: true },
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
render: (_args, value) => [{ type: 'text', text: 'deleted ' + value.id + ': ' + value.existed }],
|
|
226
|
+
},
|
|
227
|
+
async execute(args) {
|
|
228
|
+
const d = await ensure()
|
|
229
|
+
const existed = await d.table('tasks').delete(args.id)
|
|
230
|
+
return { id: args.id, existed }
|
|
231
|
+
},
|
|
232
|
+
}))
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|