@picassohq/cli 0.0.0-stage → 1.0.1
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 +3028 -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 +214 -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 +6049 -0
- package/runtime/packages/picasso-lean-context/package.json +26 -0
- package/runtime/packages/picasso-lean-context/timeline.js +417 -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 +895 -0
- package/runtime/packages/picasso-model-router/cordis.patch.yml +17 -0
- package/runtime/packages/picasso-model-router/index.js +1081 -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 +128 -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 +886 -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 +350 -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 +111 -0
- package/runtime/packages/picasso-web-search/format.js +35 -0
- package/runtime/packages/picasso-web-search/index.js +66 -0
- package/runtime/packages/picasso-web-search/package.json +38 -0
- package/runtime/packages/picasso-web-search/router.js +155 -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 +6049 -0
- package/runtime/plugins/picasso-lean-context/package.json +26 -0
- package/runtime/plugins/picasso-lean-context/timeline.js +417 -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 +895 -0
- package/runtime/plugins/picasso-model-router/index.js +1081 -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 +350 -0
- package/runtime/plugins/picasso-web-search/config.js +121 -0
- package/runtime/plugins/picasso-web-search/failure.js +111 -0
- package/runtime/plugins/picasso-web-search/format.js +35 -0
- package/runtime/plugins/picasso-web-search/index.js +66 -0
- package/runtime/plugins/picasso-web-search/package.json +38 -0
- package/runtime/plugins/picasso-web-search/router.js +155 -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 +37252 -0
- package/runtime/relay/model-listing.mjs +614 -0
- package/runtime/relay/versions-routes.mjs +1198 -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,293 @@
|
|
|
1
|
+
// @picasso/mail — cross-session messaging (B11): any thread can send a durable message into another top-level
|
|
2
|
+
// thread's inbox with the sender attributed on the message, and agents can exchange mail the same way.
|
|
3
|
+
//
|
|
4
|
+
// Transport needs no engine change: `session/prompt`'s Remote wrapper admits any `sessionId` and cold-resumes the
|
|
5
|
+
// target (`dsh-api-session-controller/lib/index.js:925-966`). What the wrapper cannot do is attribution — it pins
|
|
6
|
+
// `source = {kind:'user', rpcId, clientTimeZone?, principal?}` (:3218-3230). This plugin calls the same
|
|
7
|
+
// `commands.prompt(request, source)` the wrapper calls, but stamps the sender in: the delivered message keeps
|
|
8
|
+
// `kind:'user'` (every downstream fold — prompt bubble, `api-session/activity`, rpcId dedup, upload retirement —
|
|
9
|
+
// keys on it) and carries `source.mail {fromId, fromTitle, at, senderKind}` for the surfaces that know to look.
|
|
10
|
+
// The inbox schema is `z.custom()` per message, so the extra field survives durable persistence verbatim.
|
|
11
|
+
//
|
|
12
|
+
// The model still reads attribution from the content itself: a first text part opens with the envelope
|
|
13
|
+
// `Mail from thread "<title>" (<id>):` — mirroring dsh's `Agent <id> sent a message:` convention
|
|
14
|
+
// (`dsh-subagent/lib/index.js:443-465`) — plus the send_mail reply guidance, so a dsh that ever tightened source
|
|
15
|
+
// validation degrades to "prompts that name their sender", never to lost mail.
|
|
16
|
+
//
|
|
17
|
+
// mail/send Remote: {requestId, fromSessionId?, fromTitle?, toSessionId, delivery, content} →
|
|
18
|
+
// {accepted:true, requestId}. `delivery` is "queue" (next-turn, `agent.followup`) or "steer"
|
|
19
|
+
// (next-step, `agent.steer`); the requestId is the durable dedup key. Self-sends are refused
|
|
20
|
+
// (`mail/self-send`), unknown sessions propagate `session/not-found` verbatim.
|
|
21
|
+
// send_mail tool: {thread_id, message} — the agent path; sender = `exec.agent`, stamped `senderKind:'agent'`,
|
|
22
|
+
// always queued, capped at `maxPerTurn` per turn so two agents cannot mail each other forever.
|
|
23
|
+
//
|
|
24
|
+
// Zero runtime dependencies on purpose: it ships beside the relay (not inside dsh's node_modules), so it registers
|
|
25
|
+
// its Remote methods with the gateway's source-mode markers (like picasso-session-lifecycle) and raises failures
|
|
26
|
+
// as structural dsh RemoteErrors (`isDSHRemoteError`) so the code reaches the caller on the 422 channel.
|
|
27
|
+
import { randomUUID } from 'node:crypto';
|
|
28
|
+
import { applyInbox } from './inbox.js';
|
|
29
|
+
|
|
30
|
+
export { INBOX_SERVICE_KEY, InboxService, InboxError, moveQueued } from './inbox.js';
|
|
31
|
+
|
|
32
|
+
export const name = 'picasso-mail';
|
|
33
|
+
/** The dsh release this plugin is written and tested against (Picasso pins the engine to it). */
|
|
34
|
+
export const dshTarget = '0.2.2-rc.3';
|
|
35
|
+
export const SERVICE_KEY = 'mail';
|
|
36
|
+
/** The model-facing tool name (`send_mail {thread_id, message}`). */
|
|
37
|
+
export const SEND_MAIL_TOOL = 'send_mail';
|
|
38
|
+
/** `send_mail` calls allowed per agent per turn — the loop guard for two-way agent mail. */
|
|
39
|
+
export const DEFAULT_MAX_PER_TURN = 4;
|
|
40
|
+
const REMOTE_METHOD_DESCRIPTOR = '@deepseek-ai/dsh-typert-protocol/remote-methods';
|
|
41
|
+
const REMOTE_METHODS = ['send'];
|
|
42
|
+
|
|
43
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
44
|
+
const nonempty = (value) => (typeof value === 'string' && value.length > 0 ? value : undefined);
|
|
45
|
+
|
|
46
|
+
/** A dsh RemoteError, identified structurally by the gateway (`remoteErrorOf`), so the code reaches the client. */
|
|
47
|
+
export class MailError extends Error {
|
|
48
|
+
constructor(code, message, details = {}) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.name = 'RemoteError';
|
|
51
|
+
this.code = `mail/${code}`;
|
|
52
|
+
this.details = details;
|
|
53
|
+
this.isDSHRemoteError = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The model-facing attribution line, first content part of every mailed message — the `Mail from thread "<title>"
|
|
59
|
+
* (<id>):` opener the UI's "from" chip mirrors (`ThreadMail.envelopePrefix` on the Mac reads it back off the
|
|
60
|
+
* message), followed by the send_mail reply address so two-way agent mail needs no directory. The receiving agent
|
|
61
|
+
* is asked to reply only when it has something new: two threads mailing each other forever is the v1 loop risk.
|
|
62
|
+
* Quotes in a title are straightened so the envelope keeps its `("…")` shape.
|
|
63
|
+
*/
|
|
64
|
+
export function envelopeText(fromTitle, fromId) {
|
|
65
|
+
const title = String(fromTitle ?? '').replaceAll('"', "'").trim() || 'Untitled';
|
|
66
|
+
const id = String(fromId ?? '').trim();
|
|
67
|
+
const head = id ? `Mail from thread "${title}" (${id}):` : `Mail from thread "${title}":`;
|
|
68
|
+
if (!id) return `${head} `;
|
|
69
|
+
return `${head} reply with the ${SEND_MAIL_TOOL} tool (thread_id "${id}") only if you have something new to send back.\n`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The durable attribution stamped on the delivered message: `kind:'user'` on purpose (see header), `rpcId` = the
|
|
74
|
+
* request's dedup key, `mail` = `{fromId, fromTitle, at, senderKind}` — `fromId`/`fromTitle` only when known.
|
|
75
|
+
* `senderKind` is "person" through `mail/send` and "agent" through `send_mail`; the stamp is a Picasso-owned
|
|
76
|
+
* convention dsh never inspects, so UI reads it and the model reads the envelope text instead.
|
|
77
|
+
*/
|
|
78
|
+
export function mailSource({ requestId, fromId, fromTitle, at, senderKind }) {
|
|
79
|
+
const mail = { at, senderKind: nonempty(senderKind) ?? 'person' };
|
|
80
|
+
if (nonempty(fromId)) mail.fromId = fromId;
|
|
81
|
+
if (nonempty(fromTitle)) mail.fromTitle = String(fromTitle).replaceAll('"', "'").trim();
|
|
82
|
+
return { kind: 'user', rpcId: requestId, mail };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** dsh `session/prompt`'s content rule (`hasPromptContent`): at least one non-whitespace text part or attachment. */
|
|
86
|
+
export function hasMailContent(content) {
|
|
87
|
+
return Array.isArray(content) && content.some((part) => isRecord(part) && (part.type !== 'text' || (typeof part.text === 'string' && part.text.trim().length > 0)));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The `mail/*` Remote surface. Wire args are the parameter names (`send(requestId, fromSessionId, fromTitle,
|
|
92
|
+
* toSessionId, delivery, content)`); the gateway binds named wire fields to parameters in source mode, so
|
|
93
|
+
* `mail/send {toSessionId, delivery, content, requestId?}` admits the optionals as `undefined`.
|
|
94
|
+
*/
|
|
95
|
+
export class MailService {
|
|
96
|
+
/**
|
|
97
|
+
* @param options.commands - lazy `SessionCommandController` accessor (`ctx.sessionController.commands`): the
|
|
98
|
+
* plugin resolves it per call because the session controller mounts before remotes are ever invoked.
|
|
99
|
+
* @param options.titleOf - best-effort sender title for the envelope when the caller supplies none.
|
|
100
|
+
* @param options.now/mint - clock and request-id mint, injectable for tests.
|
|
101
|
+
*/
|
|
102
|
+
constructor(options) {
|
|
103
|
+
this.commands = options.commands;
|
|
104
|
+
this.titleOf = options.titleOf ?? (() => undefined);
|
|
105
|
+
this.now = options.now ?? (() => Date.now());
|
|
106
|
+
this.mint = options.mint ?? randomUUID;
|
|
107
|
+
/** The gateway binding (`readBinding` requires `service` to be this very instance). */
|
|
108
|
+
this.typertRemote = Object.freeze({ service: this, serviceKey: SERVICE_KEY, namespace: SERVICE_KEY });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* `mail/send` — person path (relay `POST /threads/:id/mail`, `/remote/mail/send`). `fromSessionId`/`fromTitle`
|
|
113
|
+
* attribute the sending thread; the person can't spoof another sender because the Mac always names its own.
|
|
114
|
+
* `session/not-found` and friends propagate verbatim; `delivery` is checked here because this call bypasses
|
|
115
|
+
* `session/prompt`'s own Remote validation.
|
|
116
|
+
*/
|
|
117
|
+
send(requestId, fromSessionId, fromTitle, toSessionId, delivery, content, signal) {
|
|
118
|
+
signal?.throwIfAborted?.();
|
|
119
|
+
return this.deliver({ requestId, fromId: fromSessionId, fromTitle, toId: toSessionId, delivery, content, senderKind: 'person', signal });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* One mail item into `toId`'s inbox. `fromId`/`fromTitle` name the sender in the stamp and the envelope;
|
|
124
|
+
* `senderKind` records whether a person or an agent sent it. Resolves the target through the session
|
|
125
|
+
* controller's own `commands.prompt` — cold-resume, rpcId dedup, and every dsh refusal included.
|
|
126
|
+
*/
|
|
127
|
+
async deliver({ requestId, fromId, fromTitle, toId, delivery, content, senderKind, signal }) {
|
|
128
|
+
const target = nonempty(toId);
|
|
129
|
+
if (target === undefined) throw new MailError('bad-request', 'toSessionId must be a non-empty string.');
|
|
130
|
+
const mode = delivery === undefined || delivery === null ? 'queue' : delivery;
|
|
131
|
+
if (mode !== 'queue' && mode !== 'steer') throw new MailError('bad-request', `Unknown delivery ${JSON.stringify(delivery)} — mail queues for the next turn ("queue") or steers a running one ("steer").`, { delivery });
|
|
132
|
+
if (!hasMailContent(content)) throw new MailError('bad-request', 'mail content must include non-whitespace text or an attachment.');
|
|
133
|
+
if (nonempty(fromId) === target) throw new MailError('self-send', 'A thread cannot send mail to itself.', { sessionId: target });
|
|
134
|
+
const rid = nonempty(requestId) ?? this.mint();
|
|
135
|
+
const title = nonempty(fromTitle) ?? (nonempty(fromId) === undefined ? undefined : this.titleOf(fromId));
|
|
136
|
+
const source = mailSource({ requestId: rid, fromId, fromTitle: title ?? fromId, at: this.now(), senderKind });
|
|
137
|
+
const stamped = [
|
|
138
|
+
{ type: 'text', text: envelopeText(source.mail.fromTitle ?? source.mail.fromId, source.mail.fromId) },
|
|
139
|
+
...content,
|
|
140
|
+
];
|
|
141
|
+
const commands = this.commands();
|
|
142
|
+
if (commands === undefined || typeof commands.prompt !== 'function') throw new MailError('unavailable', 'The session controller is not mounted — mail cannot be delivered.');
|
|
143
|
+
signal?.throwIfAborted?.();
|
|
144
|
+
const result = await commands.prompt({ requestId: rid, sessionId: target, mode, content: stamped }, source);
|
|
145
|
+
return { accepted: result?.accepted === true, requestId: rid };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** The gateway's source-mode Remote markers, as `@Remote()` would write them on the class prototype. */
|
|
150
|
+
Object.defineProperty(MailService.prototype, REMOTE_METHOD_DESCRIPTOR, {
|
|
151
|
+
configurable: true,
|
|
152
|
+
value: Object.freeze({ version: 1, methods: Object.freeze(REMOTE_METHODS.map((method) => Object.freeze({ method, invocation: Object.freeze({ kind: 'direct' }) }))) }),
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
/** A live session's folded title (dsh `title` projection); `undefined` for cold or untitled sessions. */
|
|
156
|
+
function liveTitle(ctx, sessionId) {
|
|
157
|
+
try {
|
|
158
|
+
const session = ctx.get('sessions')?.get?.(sessionId);
|
|
159
|
+
if (session === undefined) return undefined;
|
|
160
|
+
const title = ctx.get('sessionProjections')?.snapshot?.(session, ['title'])?.values?.title;
|
|
161
|
+
return nonempty(title);
|
|
162
|
+
} catch {
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The workspace a session belongs to, best effort: a live Session exposes `cwd` (and some builds
|
|
169
|
+
* `workspace.cwd`/`workspacePath`). Cold targets resolve to `undefined` — the approval gate is the
|
|
170
|
+
* boundary there (AO-011.08): a read-only or plan session's ask is denied before mail is ever queued.
|
|
171
|
+
*/
|
|
172
|
+
function sessionCwd(ctx, sessionId) {
|
|
173
|
+
try {
|
|
174
|
+
const session = ctx.get('sessions')?.get?.(sessionId);
|
|
175
|
+
if (session === undefined) return undefined;
|
|
176
|
+
return nonempty(session.cwd) ?? nonempty(session.workspace?.cwd) ?? nonempty(session.workspacePath);
|
|
177
|
+
} catch {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Cordis entry. Provides `mail` (`mail/send`), binds it for the Typert gateway (`typertRemote`), resets the
|
|
184
|
+
* per-turn mail counter on every `turn/start`, and mounts `send_mail` on the session's tool registry.
|
|
185
|
+
* Config: `{ maxPerTurn?: number }` (default 4).
|
|
186
|
+
*/
|
|
187
|
+
export function apply(ctx, config = {}) {
|
|
188
|
+
const maxPerTurn = Number.isInteger(config.maxPerTurn) && config.maxPerTurn > 0 ? config.maxPerTurn : DEFAULT_MAX_PER_TURN;
|
|
189
|
+
const service = new MailService({
|
|
190
|
+
commands: () => ctx.get('sessionController')?.commands,
|
|
191
|
+
titleOf: (id) => liveTitle(ctx, id),
|
|
192
|
+
});
|
|
193
|
+
ctx.provide(SERVICE_KEY, service);
|
|
194
|
+
// The person's inbox controls (interrupt, reorder) ride beside mail: same inbox, same mount (`inbox.js`).
|
|
195
|
+
applyInbox(ctx);
|
|
196
|
+
|
|
197
|
+
/** `send_mail` deliveries per session in the open turn; `turn/start` resets it (session/event fold). */
|
|
198
|
+
const sentThisTurn = new Map();
|
|
199
|
+
try {
|
|
200
|
+
ctx.on('session/event', (session, event) => {
|
|
201
|
+
if (event?.type === 'turn/start' && typeof session?.id === 'string') sentThisTurn.delete(session.id);
|
|
202
|
+
});
|
|
203
|
+
} catch {
|
|
204
|
+
// No session/event bus: the cap just engages conservatively (per session, not per turn).
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// AO-011.08: `send_mail` is a mutating, cross-session tool — it goes through the same
|
|
208
|
+
// `tools/pre-execute` → approval pipeline as the mutating browser tools. Read-only and plan
|
|
209
|
+
// presets deny the ask (a plan-mode session can never cold-resume another thread with a queued
|
|
210
|
+
// prompt); a child session's ask resolves against the parent's effective policy — inherited
|
|
211
|
+
// `never` denies, an explicit allow answers.
|
|
212
|
+
/**
|
|
213
|
+
* The calling session's effective permission preset. `permissionPresets.current(session)` is the engine's answer
|
|
214
|
+
* (the same service picasso-sdk-server's allow-modified guard reads); the launch-time `DSH_PERMISSION_MODE` is only the
|
|
215
|
+
* fallback when the engine cannot report one. Picasso's `/plan` switches the session to `read-only`.
|
|
216
|
+
*/
|
|
217
|
+
const senderPreset = (exec) => {
|
|
218
|
+
let preset;
|
|
219
|
+
try {
|
|
220
|
+
const presets = ctx.get?.('permissionPresets') ?? ctx.permissionPresets;
|
|
221
|
+
preset = presets?.current?.(exec?.agent?.session);
|
|
222
|
+
} catch {
|
|
223
|
+
preset = undefined;
|
|
224
|
+
}
|
|
225
|
+
return typeof preset === 'string' && preset.length > 0 ? preset : process.env.DSH_PERMISSION_MODE;
|
|
226
|
+
};
|
|
227
|
+
const READ_ONLY_REASON = `${SEND_MAIL_TOOL} is unavailable in a read-only or plan session: it queues a prompt in another thread.`;
|
|
228
|
+
|
|
229
|
+
ctx.on('tools/pre-execute', (exec, next) => {
|
|
230
|
+
if (exec.name !== SEND_MAIL_TOOL) return next();
|
|
231
|
+
// A read-only (and so plan) session never gets to ask: mailing another thread would queue a prompt there.
|
|
232
|
+
if (senderPreset(exec) === 'read-only') return Promise.resolve({ kind: 'deny', reason: READ_ONLY_REASON, displayReason: { en: READ_ONLY_REASON } });
|
|
233
|
+
const args = isRecord(exec.arguments) ? exec.arguments : {};
|
|
234
|
+
const reason = `Send mail to thread ${typeof args.thread_id === 'string' ? args.thread_id : '(unknown)'}`;
|
|
235
|
+
return Promise.resolve({ kind: 'ask', reason, displayReason: { en: reason } });
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// The agent path: `send_mail {thread_id, message}` — same transport as mail/send, stamped `senderKind:'agent'`,
|
|
239
|
+
// so two unrelated top-level sessions genuinely exchange mail (not just parent↔child like `send_message`).
|
|
240
|
+
// Mounted softly: without a `tools` service the Remote half above still applies.
|
|
241
|
+
ctx.inject?.(['tools'], (inner) => {
|
|
242
|
+
inner.tools.register({
|
|
243
|
+
name: SEND_MAIL_TOOL,
|
|
244
|
+
description:
|
|
245
|
+
'Send mail to another thread — a durable message that lands in its inbox with this thread named as the sender. Use it to answer mail a thread sent you or to hand a result to a thread you coordinate with; replies are not automatic, so only send when you have something new to say.',
|
|
246
|
+
parameters: {
|
|
247
|
+
type: 'object',
|
|
248
|
+
properties: {
|
|
249
|
+
thread_id: { type: 'string', description: 'The target thread\u2019s session id — the <id> in a "Mail from thread" envelope or the thread list.' },
|
|
250
|
+
message: { type: 'string', description: 'The message to deliver. Plain text; keep it self-contained.' },
|
|
251
|
+
},
|
|
252
|
+
required: ['thread_id', 'message'],
|
|
253
|
+
additionalProperties: false,
|
|
254
|
+
},
|
|
255
|
+
output: {
|
|
256
|
+
schema: { type: 'object' },
|
|
257
|
+
render: (args, value) => [{ type: 'text', text: `mail delivered to thread ${args.thread_id} (requestId ${value?.requestId ?? 'unknown'})` }],
|
|
258
|
+
},
|
|
259
|
+
isConcurrencySafe: () => false,
|
|
260
|
+
async execute(args, exec) {
|
|
261
|
+
const sender = exec?.agent;
|
|
262
|
+
if (sender === undefined || typeof sender.id !== 'string') throw new Error(`${SEND_MAIL_TOOL} requires a calling agent (exec.agent was undefined)`);
|
|
263
|
+
// Defense in depth: the approval pipeline already denied a read-only sender; refuse here too if it was bypassed.
|
|
264
|
+
if (senderPreset(exec) === 'read-only') throw new Error(READ_ONLY_REASON);
|
|
265
|
+
const threadId = String(args?.thread_id ?? '').trim();
|
|
266
|
+
if (!threadId) throw new Error(`${SEND_MAIL_TOOL}: 'thread_id' is required`);
|
|
267
|
+
const message = String(args?.message ?? '');
|
|
268
|
+
if (!message.trim()) throw new Error(`${SEND_MAIL_TOOL}: 'message' is required`);
|
|
269
|
+
const sent = sentThisTurn.get(sender.id) ?? 0;
|
|
270
|
+
if (sent >= maxPerTurn) throw new Error(`${SEND_MAIL_TOOL}: this turn already sent ${maxPerTurn} mail(s) — reply again next turn`);
|
|
271
|
+
// AO-011.08: targets stay inside the sender's workspace — a live target resolvable to a
|
|
272
|
+
// different cwd is refused outright; a cold target relies on the approval gate above.
|
|
273
|
+
const senderCwd = sessionCwd(ctx, sender.id);
|
|
274
|
+
const targetCwd = sessionCwd(ctx, threadId);
|
|
275
|
+
if (senderCwd !== undefined && targetCwd !== undefined && targetCwd !== senderCwd) {
|
|
276
|
+
throw new Error(`${SEND_MAIL_TOOL}: thread ${threadId} is outside this thread's workspace`);
|
|
277
|
+
}
|
|
278
|
+
const result = await service.deliver({
|
|
279
|
+
requestId: randomUUID(),
|
|
280
|
+
fromId: sender.id,
|
|
281
|
+
fromTitle: liveTitle(ctx, sender.id),
|
|
282
|
+
toId: threadId,
|
|
283
|
+
delivery: 'queue',
|
|
284
|
+
content: [{ type: 'text', text: message }],
|
|
285
|
+
senderKind: 'agent',
|
|
286
|
+
signal: exec?.signal,
|
|
287
|
+
});
|
|
288
|
+
sentThisTurn.set(sender.id, sent + 1);
|
|
289
|
+
return result;
|
|
290
|
+
},
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@picasso/mail",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "dsh cordis plugin: cross-session mail (B11). `mail/send` Host Remote delivers a prompt into any thread's inbox stamped `source.mail {fromId, fromTitle, at, senderKind}` so the sender is attributed on the message, not impersonating the person; the `send_mail` model tool gives agents the same path for genuine two-way agent mail between unrelated top-level sessions.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./index.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"dshTarget": "0.2.2-rc.3",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "node --import ../../test/setup/hermetic-preload.mjs --test test/*.test.mjs"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"index.js",
|
|
18
|
+
"inbox.js",
|
|
19
|
+
"test"
|
|
20
|
+
],
|
|
21
|
+
"license": "UNLICENSED"
|
|
22
|
+
}
|