@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,169 @@
|
|
|
1
|
+
// 5e: `/x` and the pasted-link preview — the surface half shared by the TUI, the Mac relay and the engine command.
|
|
2
|
+
//
|
|
3
|
+
// /x <url> a post or thread (or a profile/search URL)
|
|
4
|
+
// /x search <query> [latest|top|photos|videos|users|media]
|
|
5
|
+
// /x @handle [followers|following|history]
|
|
6
|
+
// /x circle @handle
|
|
7
|
+
//
|
|
8
|
+
// Each runs `x_read` and returns the result as one Markdown source the surface attaches to the thread.
|
|
9
|
+
import { runXRead, SEARCH_FEEDS } from './read.js';
|
|
10
|
+
import { classifyXUrl, isTcoUrl, isXUrl, resolveTco } from './urls.js';
|
|
11
|
+
import { failureLine } from './xmd.js';
|
|
12
|
+
|
|
13
|
+
export const X_COMMAND = 'x';
|
|
14
|
+
export const X_COMMAND_DESCRIPTION = 'Read X: a post or thread, a search, a profile, followers/following, history, or an interaction circle.';
|
|
15
|
+
export const X_COMMAND_USAGE = '/x <url> | /x search <query> [feed] | /x @handle [followers|following|history] | /x circle @handle';
|
|
16
|
+
const FEED_WORDS = new Set([...SEARCH_FEEDS, 'media']);
|
|
17
|
+
const HANDLE = /^@?([A-Za-z0-9_]{1,15})$/;
|
|
18
|
+
|
|
19
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
20
|
+
|
|
21
|
+
/** Parse the text after `/x` into `x_read` arguments, or `{error}`. */
|
|
22
|
+
export function parseXCommand(rawInput) {
|
|
23
|
+
const input = String(rawInput ?? '').trim().replace(/^\/x(?:\s+|$)/i, '');
|
|
24
|
+
if (input === '') return { error: `Usage: ${X_COMMAND_USAGE}` };
|
|
25
|
+
const words = input.split(/\s+/);
|
|
26
|
+
const [first, ...rest] = words;
|
|
27
|
+
if (/^https?:\/\//i.test(first)) {
|
|
28
|
+
if (!isXUrl(first)) return { error: `Not an X link: ${first}` };
|
|
29
|
+
return { kind: 'url', url: first };
|
|
30
|
+
}
|
|
31
|
+
if (first.toLowerCase() === 'search') {
|
|
32
|
+
if (rest.length === 0) return { error: 'Usage: /x search <query> [latest|top|photos|videos|users|media]' };
|
|
33
|
+
const last = rest.at(-1).toLowerCase();
|
|
34
|
+
const feed = rest.length > 1 && FEED_WORDS.has(last) ? last : undefined;
|
|
35
|
+
const q = (feed === undefined ? rest : rest.slice(0, -1)).join(' ');
|
|
36
|
+
return { kind: 'args', args: { mode: 'search', q, ...(feed === undefined ? {} : { feed }), limit: 20, pages: 1 } };
|
|
37
|
+
}
|
|
38
|
+
if (first.toLowerCase() === 'circle') {
|
|
39
|
+
const match = HANDLE.exec(rest[0] ?? '');
|
|
40
|
+
if (match === null) return { error: 'Usage: /x circle @handle' };
|
|
41
|
+
return { kind: 'args', args: { mode: 'circle', handle: match[1] } };
|
|
42
|
+
}
|
|
43
|
+
const match = HANDLE.exec(first);
|
|
44
|
+
if (match !== null && first.startsWith('@')) {
|
|
45
|
+
const sub = (rest[0] ?? '').toLowerCase();
|
|
46
|
+
if (sub === '') return { kind: 'args', args: { mode: 'profile', handle: match[1], pages: 1 } };
|
|
47
|
+
if (sub === 'followers' || sub === 'following') return { kind: 'args', args: { mode: sub, handle: match[1], pages: 1 } };
|
|
48
|
+
if (sub === 'history') return { kind: 'args', args: { mode: 'history', handle: match[1], pages: 1 } };
|
|
49
|
+
return { error: 'Usage: /x @handle [followers|following|history]' };
|
|
50
|
+
}
|
|
51
|
+
return { error: `Usage: ${X_COMMAND_USAGE}` };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** `x_read` arguments for an X URL (`/x <url>`, the preview's attach). */
|
|
55
|
+
async function urlArgs(url, { format, fetch: fetchImpl, signal }) {
|
|
56
|
+
let target = url;
|
|
57
|
+
if (isTcoUrl(target)) {
|
|
58
|
+
const resolved = await resolveTco(target, { fetch: fetchImpl, signal });
|
|
59
|
+
if (!resolved.ok) return { error: resolved.error };
|
|
60
|
+
target = resolved.url;
|
|
61
|
+
if (!isXUrl(target)) return { error: `That short link leads off X (${target}).` };
|
|
62
|
+
}
|
|
63
|
+
const kind = classifyXUrl(target);
|
|
64
|
+
switch (kind.kind) {
|
|
65
|
+
case 'post':
|
|
66
|
+
return { args: { mode: 'post', url: kind.url, thread: 'full', context: 'full', replies: 'top', format: format === 'obsidian' ? 'obsidian' : 'markdown' } };
|
|
67
|
+
case 'profile':
|
|
68
|
+
return { args: { mode: 'profile', handle: kind.handle, pages: 1, ...(kind.withReplies ? { with_replies: true } : {}) } };
|
|
69
|
+
case 'followers':
|
|
70
|
+
case 'following':
|
|
71
|
+
return { args: { mode: kind.kind, handle: kind.handle, pages: 1 } };
|
|
72
|
+
case 'search':
|
|
73
|
+
return { args: { mode: 'search', q: kind.q, ...(kind.feed === undefined ? {} : { feed: kind.feed }), limit: 20, pages: 1 } };
|
|
74
|
+
default:
|
|
75
|
+
return { error: `x.md cannot read this link: ${kind.reason}` };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function sourceName(args) {
|
|
80
|
+
const clean = (text) => String(text ?? '').replace(/[^A-Za-z0-9_-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 48);
|
|
81
|
+
switch (args.mode) {
|
|
82
|
+
case 'post': {
|
|
83
|
+
const kind = classifyXUrl(args.url);
|
|
84
|
+
return `x-${clean(kind.handle)}-${clean(kind.id)}.md`;
|
|
85
|
+
}
|
|
86
|
+
case 'search':
|
|
87
|
+
return `x-search-${clean(args.q)}.md`;
|
|
88
|
+
default:
|
|
89
|
+
return `x-${clean(args.handle)}-${args.mode}.md`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function sourceTitle(args) {
|
|
94
|
+
switch (args.mode) {
|
|
95
|
+
case 'post':
|
|
96
|
+
return `X post ${args.url}`;
|
|
97
|
+
case 'search':
|
|
98
|
+
return `X search "${args.q}"${args.feed ? ` (${args.feed})` : ''}`;
|
|
99
|
+
case 'profile':
|
|
100
|
+
return `X profile @${args.handle}`;
|
|
101
|
+
case 'circle':
|
|
102
|
+
return `X circle @${args.handle}`;
|
|
103
|
+
default:
|
|
104
|
+
return `X ${args.mode} @${args.handle}`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Run one `/x` line. Resolves `{ok:true, title, fileName, markdown, summary, args}` or `{ok:false, error}`.
|
|
110
|
+
* `deps = {client, format, fetch?, signal?}` where `format` is the saved-note format setting.
|
|
111
|
+
*/
|
|
112
|
+
export async function runXCommand(line, deps) {
|
|
113
|
+
const parsed = parseXCommand(line);
|
|
114
|
+
if (parsed.error !== undefined) return { ok: false, error: parsed.error };
|
|
115
|
+
let args = parsed.args;
|
|
116
|
+
if (parsed.kind === 'url') {
|
|
117
|
+
const built = await urlArgs(parsed.url, deps);
|
|
118
|
+
if (built.error !== undefined) return { ok: false, error: built.error };
|
|
119
|
+
args = built.args;
|
|
120
|
+
}
|
|
121
|
+
const result = await runXRead(deps.client, args, { signal: deps.signal, fetch: deps.fetch });
|
|
122
|
+
if (result.isError) return { ok: false, error: result.text, args };
|
|
123
|
+
const summary = result.text.split('\n')[0] ?? '';
|
|
124
|
+
return { ok: true, title: sourceTitle(args), fileName: sourceName(args), markdown: result.text, summary, args, value: result.value };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const firstLines = (text, lines = 3, chars = 280) => {
|
|
128
|
+
const out = String(text ?? '').split('\n').map((line) => line.trim()).filter(Boolean).slice(0, lines).join('\n');
|
|
129
|
+
return out.length > chars ? `${out.slice(0, chars - 1).trimEnd()}…` : out;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The pasted-link preview card: author, the first lines, and "thread of N", plus the Markdown the one-click attach
|
|
134
|
+
* adds as a source (in the saved-note format). Resolves `{ok:true, url, author, firstLines, threadCount, postCount,
|
|
135
|
+
* warnings, markdown, fileName, title}` or `{ok:false, error}`. Only post links preview.
|
|
136
|
+
*/
|
|
137
|
+
export async function previewXLink(url, deps) {
|
|
138
|
+
const built = await urlArgs(String(url ?? '').trim(), deps);
|
|
139
|
+
if (built.error !== undefined) return { ok: false, error: built.error };
|
|
140
|
+
if (built.args.mode !== 'post') return { ok: false, error: 'Only X post links have a preview card; use /x to read profiles and searches.' };
|
|
141
|
+
const res = await deps.client.request('/api/v1/posts', { url: built.args.url, thread: 'full', context: 'full', replies: 'top', format: 'json' }, { signal: deps.signal });
|
|
142
|
+
if (!res.ok) return { ok: false, error: failureLine(res) };
|
|
143
|
+
const body = isRecord(res.json) ? res.json : {};
|
|
144
|
+
const posts = Array.isArray(body.posts) ? body.posts : [];
|
|
145
|
+
const main = posts.find((post) => post?.context === 'post') ?? posts[0];
|
|
146
|
+
if (main === undefined) return { ok: false, error: 'x.md returned no post for this link.' };
|
|
147
|
+
const authorHandle = main.author?.screen_name;
|
|
148
|
+
const threadCount = posts.filter((post) => (post?.context === 'post' || post?.context === 'thread') && post?.author?.screen_name === authorHandle).length || 1;
|
|
149
|
+
let markdown = typeof body.markdown === 'string' ? body.markdown : '';
|
|
150
|
+
if (deps.format === 'obsidian') {
|
|
151
|
+
const note = await deps.client.request('/api/v1/posts', { url: built.args.url, thread: 'full', context: 'full', replies: 'top', format: 'obsidian' }, { accept: 'text/markdown', signal: deps.signal });
|
|
152
|
+
if (!note.ok) return { ok: false, error: failureLine(note) };
|
|
153
|
+
markdown = note.text;
|
|
154
|
+
}
|
|
155
|
+
const lead = typeof main.article?.title === 'string' && main.article.title.trim() !== '' ? `${main.article.title}\n${main.article.preview_text ?? ''}` : main.text;
|
|
156
|
+
return {
|
|
157
|
+
ok: true,
|
|
158
|
+
url: body.url ?? built.args.url,
|
|
159
|
+
author: { name: main.author?.name ?? authorHandle ?? '', screenName: authorHandle ?? '', avatarUrl: main.author?.avatar_url },
|
|
160
|
+
firstLines: firstLines(lead),
|
|
161
|
+
threadCount,
|
|
162
|
+
postCount: posts.length,
|
|
163
|
+
warnings: Array.isArray(body.warnings) ? body.warnings : [],
|
|
164
|
+
markdown,
|
|
165
|
+
fileName: sourceName(built.args),
|
|
166
|
+
title: sourceTitle(built.args),
|
|
167
|
+
...(res.apiKeyStatus === undefined ? {} : { apiKeyStatus: res.apiKeyStatus }),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// @picasso/x-reader — reading X natively through x.md (mdfromx.com), on both surfaces.
|
|
2
|
+
//
|
|
3
|
+
// 5a The rewrite: every `web_fetch` provider the engine registers is wrapped, so an `x.com`, `twitter.com`,
|
|
4
|
+
// `mobile.twitter.com` or `t.co` URL is read through the x.md base URL (versioned `/api/v1/*`,
|
|
5
|
+
// `Accept: text/markdown`) instead of X, which blocks plain page fetches. Provider selection, the tool's schema
|
|
6
|
+
// and its Tier-1 bytes are untouched: no new wire tool, no prompt text.
|
|
7
|
+
// 5b `x_read`: a deferred tool (off-wire, listed in the tool catalog, reached through `tool_call`) with one mode per
|
|
8
|
+
// documented endpoint, plus `circle` (5c).
|
|
9
|
+
// 5e `/x`: an engine command returning the result as Markdown; the TUI and the Mac composer attach it as a source.
|
|
10
|
+
//
|
|
11
|
+
// Settings are live from the shared settings.json (`settings.xReader`); the optional key comes from the system
|
|
12
|
+
// keychain (settings.js). Turning the reader off restores the engine's own fetch for X URLs.
|
|
13
|
+
import { runXCommand, previewXLink, X_COMMAND, X_COMMAND_DESCRIPTION } from './command.js';
|
|
14
|
+
import { runXRead, X_READ_DESCRIPTION, X_READ_PARAMETERS, X_READ_TOOL } from './read.js';
|
|
15
|
+
import { fetchThroughXmd } from './rewrite.js';
|
|
16
|
+
import { apiKeyReader, settingsReader } from './settings.js';
|
|
17
|
+
import { XmdClient } from './xmd.js';
|
|
18
|
+
|
|
19
|
+
export * from './xmd.js';
|
|
20
|
+
export * from './urls.js';
|
|
21
|
+
export * from './settings.js';
|
|
22
|
+
export * from './read.js';
|
|
23
|
+
export * from './circle.js';
|
|
24
|
+
export * from './command.js';
|
|
25
|
+
export { fetchThroughXmd } from './rewrite.js';
|
|
26
|
+
|
|
27
|
+
export const name = 'picasso-x-reader';
|
|
28
|
+
/** The dsh release this plugin is written and tested against. */
|
|
29
|
+
export const dshTarget = '0.2.2-rc.3';
|
|
30
|
+
const WRAPPED = Symbol.for('picasso.x-reader.wrapped');
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The reader as the surfaces use it (TUI, CLI, Mac relay): live settings, a client with the current key, and the
|
|
34
|
+
* `/x`, preview and key-check operations. `deps`: `{env, settingsFile, fetch, readKeychain, now}`.
|
|
35
|
+
*/
|
|
36
|
+
export function createXReader(deps = {}) {
|
|
37
|
+
const env = deps.env ?? process.env;
|
|
38
|
+
const settings = deps.settings ?? settingsReader({ settingsFile: deps.settingsFile, env });
|
|
39
|
+
const apiKey = deps.apiKey ?? apiKeyReader({ env, ...(deps.readKeychain === undefined ? {} : { readKeychain: deps.readKeychain }) });
|
|
40
|
+
const client = async () => new XmdClient({ baseUrl: settings().baseUrl, apiKey: await apiKey(), fetch: deps.fetch, ...(deps.sleep ? { sleep: deps.sleep } : {}) });
|
|
41
|
+
return {
|
|
42
|
+
settings,
|
|
43
|
+
client,
|
|
44
|
+
/** Forget the cached key after this process saved or removed it. */
|
|
45
|
+
invalidateKey() {
|
|
46
|
+
apiKey.invalidate?.();
|
|
47
|
+
},
|
|
48
|
+
async read(args, options = {}) {
|
|
49
|
+
return runXRead(await client(), args, { signal: options.signal, fetch: deps.fetch, now: deps.now });
|
|
50
|
+
},
|
|
51
|
+
async command(line, options = {}) {
|
|
52
|
+
const current = settings();
|
|
53
|
+
if (!current.enabled) return { ok: false, error: 'Reading X links through x.md is off (Settings › Read X links through x.md).' };
|
|
54
|
+
return runXCommand(line, { client: await client(), format: current.format, fetch: deps.fetch, signal: options.signal });
|
|
55
|
+
},
|
|
56
|
+
async preview(url, options = {}) {
|
|
57
|
+
const current = settings();
|
|
58
|
+
if (!current.enabled) return { ok: false, error: 'Reading X links through x.md is off.' };
|
|
59
|
+
return previewXLink(url, { client: await client(), format: current.format, fetch: deps.fetch, signal: options.signal });
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Check a key (the stored one unless `candidate` is given) against the configured deployment without spending
|
|
63
|
+
* quota (`history index=true` spends only the general request allowance). `{status:'valid'|'invalid'|'absent'|
|
|
64
|
+
* 'unknown', httpStatus, keyStatus?}`.
|
|
65
|
+
*/
|
|
66
|
+
async checkKey(candidate, options = {}) {
|
|
67
|
+
const key = typeof candidate === 'string' && candidate.trim() !== '' ? candidate.trim() : await apiKey();
|
|
68
|
+
if (key === undefined) return { status: 'absent', baseUrl: settings().baseUrl };
|
|
69
|
+
const probe = new XmdClient({ baseUrl: settings().baseUrl, apiKey: key, fetch: deps.fetch });
|
|
70
|
+
const res = await probe.request('/api/v1/profiles/x/posts', { index: true }, { signal: options.signal });
|
|
71
|
+
const keyStatus = res.apiKeyStatus;
|
|
72
|
+
const status = keyStatus === 'valid' ? 'valid' : keyStatus === 'invalid' || res.status === 401 ? 'invalid' : 'unknown';
|
|
73
|
+
return { status, httpStatus: res.status, baseUrl: probe.baseUrl, ...(keyStatus === undefined ? {} : { keyStatus }) };
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Wrap one engine fetch provider so X URLs go through x.md; everything else (and the reader switched off) is untouched. */
|
|
79
|
+
export function wrapFetchProvider(provider, reader, { fetch: fetchImpl } = {}) {
|
|
80
|
+
if (provider === null || typeof provider !== 'object' || provider[WRAPPED] === true || typeof provider.fetch !== 'function') return provider;
|
|
81
|
+
const wrapped = Object.create(provider);
|
|
82
|
+
Object.defineProperty(wrapped, WRAPPED, { value: true });
|
|
83
|
+
Object.defineProperty(wrapped, 'original', { value: provider });
|
|
84
|
+
wrapped.fetch = async function fetch(request, signal) {
|
|
85
|
+
const url = typeof request?.url === 'string' ? request.url : '';
|
|
86
|
+
if (!reader.settings().enabled) return provider.fetch(request, signal);
|
|
87
|
+
const outcome = await fetchThroughXmd(url, { client: await reader.client(), signal, fetch: fetchImpl });
|
|
88
|
+
if (!outcome.handled) return provider.fetch(outcome.url === url ? request : { ...request, url: outcome.url }, signal);
|
|
89
|
+
return outcome.result;
|
|
90
|
+
};
|
|
91
|
+
return wrapped;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Wrap every provider in the web seam's fetch registry, now and as later plugins register theirs (registration
|
|
96
|
+
* order never matters). The seam's own selection rules still pick the provider. Returns the disposer.
|
|
97
|
+
*/
|
|
98
|
+
export function interceptWebFetch(web, reader, options = {}) {
|
|
99
|
+
const store = web?.fetchProviders;
|
|
100
|
+
if (!(store instanceof Map)) return undefined;
|
|
101
|
+
const set = Map.prototype.set;
|
|
102
|
+
for (const [id, provider] of store) set.call(store, id, wrapFetchProvider(provider, reader, options));
|
|
103
|
+
Object.defineProperty(store, 'set', {
|
|
104
|
+
configurable: true,
|
|
105
|
+
writable: true,
|
|
106
|
+
value: function setWrapped(id, provider) {
|
|
107
|
+
return set.call(this, id, wrapFetchProvider(provider, reader, options));
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
return () => {
|
|
111
|
+
delete store.set;
|
|
112
|
+
for (const [id, provider] of store) if (provider?.[WRAPPED] === true) set.call(store, id, provider.original);
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export const X_READ_OUTPUT_SCHEMA = Object.freeze({ type: 'object' });
|
|
117
|
+
|
|
118
|
+
/** The `x_read` tool definition over a reader (registered on the engine's tools service). */
|
|
119
|
+
export function xReadToolDefinition(reader) {
|
|
120
|
+
return {
|
|
121
|
+
name: X_READ_TOOL,
|
|
122
|
+
description: X_READ_DESCRIPTION,
|
|
123
|
+
parameters: X_READ_PARAMETERS,
|
|
124
|
+
output: {
|
|
125
|
+
schema: X_READ_OUTPUT_SCHEMA,
|
|
126
|
+
render: (_args, value) => [{ type: 'text', text: typeof value?.text === 'string' ? value.text : JSON.stringify(value ?? {}) }],
|
|
127
|
+
},
|
|
128
|
+
isConcurrencySafe: () => true,
|
|
129
|
+
async execute(args, exec) {
|
|
130
|
+
if (!reader.settings().enabled) throw new Error('x_read is off: reading X through x.md is switched off in Settings.');
|
|
131
|
+
const result = await reader.read(args, { signal: exec?.signal });
|
|
132
|
+
// C1: a failed read is an error result carrying x.md's own problem text, never an empty or invented answer.
|
|
133
|
+
if (result.isError) throw new Error(result.text);
|
|
134
|
+
return { text: result.text, ...result.value };
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function apply(ctx, config = {}) {
|
|
140
|
+
const reader = createXReader({ settingsFile: typeof config?.settingsFile === 'string' ? config.settingsFile : undefined });
|
|
141
|
+
|
|
142
|
+
ctx.inject?.(['web'], (inner) => {
|
|
143
|
+
const dispose = interceptWebFetch(inner.web, reader);
|
|
144
|
+
if (dispose === undefined) {
|
|
145
|
+
ctx.logger?.warn?.('picasso-x-reader: the web seam exposes no fetch registry; X links use the engine fetch');
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
inner.on?.('dispose', dispose);
|
|
150
|
+
} catch {
|
|
151
|
+
// Older cordis: the provider wrappers live as long as the engine process.
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
ctx.inject?.(['tools'], (inner) => {
|
|
156
|
+
inner.tools.register(xReadToolDefinition(reader));
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
ctx.inject?.(['commands'], (inner) => {
|
|
160
|
+
inner.commands.register({
|
|
161
|
+
name: X_COMMAND,
|
|
162
|
+
description: X_COMMAND_DESCRIPTION,
|
|
163
|
+
input: { hint: '<url> | search <query> [feed] | @handle [followers|following|history] | circle @handle' },
|
|
164
|
+
handler: async (invocation) => {
|
|
165
|
+
const outcome = await reader.command(invocation?.rawInput ?? '', { signal: invocation?.signal });
|
|
166
|
+
return outcome.ok ? { kind: 'success', text: outcome.markdown } : { kind: 'error', text: outcome.error };
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@picasso/x-reader",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "dsh cordis plugin: reads public X through x.md (mdfromx.com). Rewrites x.com/twitter.com/t.co web_fetch calls onto the versioned x.md API (Accept: text/markdown), adds the deferred x_read tool (post, replies, search, profile, followers, following, history, circle) and the /x command. Zero runtime dependencies.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"default": "./index.js"
|
|
13
|
+
},
|
|
14
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"dshTarget": "0.2.2-rc.3",
|
|
18
|
+
"dsh": {
|
|
19
|
+
"bundle": {
|
|
20
|
+
"patch": "./cordis.patch.yml"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"test": "node --import ../../test/setup/hermetic-preload.mjs --test test/*.test.mjs"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"index.js",
|
|
28
|
+
"index.d.ts",
|
|
29
|
+
"xmd.js",
|
|
30
|
+
"urls.js",
|
|
31
|
+
"settings.js",
|
|
32
|
+
"read.js",
|
|
33
|
+
"circle.js",
|
|
34
|
+
"command.js",
|
|
35
|
+
"rewrite.js",
|
|
36
|
+
"cordis.patch.yml"
|
|
37
|
+
],
|
|
38
|
+
"license": "UNLICENSED"
|
|
39
|
+
}
|