@picassohq/cli 0.0.0-stage → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/browser_agent.yaml +53 -0
- package/agents/code_reviewer.yaml +49 -0
- package/agents/codebase_investigator.yaml +70 -0
- package/agents/design_auditor.yaml +50 -0
- package/agents/devex_auditor.yaml +50 -0
- package/agents/doc_writer.yaml +54 -0
- package/agents/engineering_architect.yaml +51 -0
- package/agents/generalist.yaml +55 -0
- package/agents/migration_planner.yaml +51 -0
- package/agents/product_reviewer.yaml +48 -0
- package/agents/qa_operator.yaml +52 -0
- package/agents/release_engineer.yaml +50 -0
- package/agents/security_auditor.yaml +62 -0
- package/agents/test_writer.yaml +52 -0
- package/assets/first-light-lockup.png +0 -0
- package/assets/first-light-tagline.png +0 -0
- package/assets/house/README.md +26 -0
- package/assets/house/auraone-banner.png +0 -0
- package/assets/house/auraone-logo.png +0 -0
- package/assets/house/kiro-prism-banner.png +0 -0
- package/assets/house/kiro-prism-logo.png +0 -0
- package/assets/house/picasso-banner.png +0 -0
- package/assets/house/picasso-logo.png +0 -0
- package/assets/wordmark-app.png +0 -0
- package/assets/wordmark-tight.png +0 -0
- package/assets/wordmark.png +0 -0
- package/design/styles.css +1042 -0
- package/dist/build-info.json +37 -0
- package/dist/index.js +3062 -0
- package/goals/cli-hardening.yaml +40 -0
- package/goals/repo-maintenance.yaml +40 -0
- package/package.json +49 -4
- package/runtime/dsh/picasso-ecosystem.community.amendments.yml +24 -0
- package/runtime/dsh/picasso-ecosystem.community.json +185 -0
- package/runtime/dsh/picasso-ecosystem.community.patch.yml +40 -0
- package/runtime/dsh/picasso-ecosystem.cordis.patch.yml +143 -0
- package/runtime/dsh/picasso-isolation.patch.yml +25 -0
- package/runtime/dsh/picasso-providers.patch.yml +373 -0
- package/runtime/dsh/picasso-runtime.cordis.yml +738 -0
- package/runtime/dsh/picasso-sdk.patch.yml +204 -0
- package/runtime/engine-manifest.json +215 -0
- package/runtime/package.json +6 -0
- package/runtime/packages/picasso-cache-probe/cordis.patch.yml +5 -0
- package/runtime/packages/picasso-cache-probe/index.js +477 -0
- package/runtime/packages/picasso-cache-probe/package.json +38 -0
- package/runtime/packages/picasso-commands/cordis.patch.yml +4 -0
- package/runtime/packages/picasso-commands/fresh-review.js +573 -0
- package/runtime/packages/picasso-commands/index.js +497 -0
- package/runtime/packages/picasso-commands/package.json +28 -0
- package/runtime/packages/picasso-instructions/conflicts.js +115 -0
- package/runtime/packages/picasso-instructions/formats.js +145 -0
- package/runtime/packages/picasso-instructions/frontmatter.js +175 -0
- package/runtime/packages/picasso-instructions/glob.js +114 -0
- package/runtime/packages/picasso-instructions/globals.js +90 -0
- package/runtime/packages/picasso-instructions/imports.js +123 -0
- package/runtime/packages/picasso-instructions/index.js +326 -0
- package/runtime/packages/picasso-instructions/modes.js +64 -0
- package/runtime/packages/picasso-instructions/package.json +30 -0
- package/runtime/packages/picasso-instructions/parse.js +134 -0
- package/runtime/packages/picasso-instructions/report.js +161 -0
- package/runtime/packages/picasso-instructions/resolve.js +939 -0
- package/runtime/packages/picasso-instructions/scan.js +181 -0
- package/runtime/packages/picasso-instructions/settings.js +150 -0
- package/runtime/packages/picasso-instructions/skills.js +345 -0
- package/runtime/packages/picasso-lean-context/cordis.patch.yml +13 -0
- package/runtime/packages/picasso-lean-context/index.js +6280 -0
- package/runtime/packages/picasso-lean-context/package.json +26 -0
- package/runtime/packages/picasso-lean-context/read-image-recovery.js +306 -0
- package/runtime/packages/picasso-lean-context/timeline.js +418 -0
- package/runtime/packages/picasso-librarian/classify.js +146 -0
- package/runtime/packages/picasso-librarian/cordis.patch.yml +10 -0
- package/runtime/packages/picasso-librarian/index.js +878 -0
- package/runtime/packages/picasso-librarian/notes.js +159 -0
- package/runtime/packages/picasso-librarian/package.json +34 -0
- package/runtime/packages/picasso-librarian/state.js +478 -0
- package/runtime/packages/picasso-memory/index.js +1184 -0
- package/runtime/packages/picasso-memory/package.json +21 -0
- package/runtime/packages/picasso-model-router/connections.js +912 -0
- package/runtime/packages/picasso-model-router/cordis.patch.yml +17 -0
- package/runtime/packages/picasso-model-router/index.js +1083 -0
- package/runtime/packages/picasso-model-router/package.json +30 -0
- package/runtime/packages/picasso-options/cordis.patch.yml +4 -0
- package/runtime/packages/picasso-options/index.js +263 -0
- package/runtime/packages/picasso-options/package.json +28 -0
- package/runtime/packages/picasso-progress-reports/cordis.patch.yml +10 -0
- package/runtime/packages/picasso-progress-reports/index.js +267 -0
- package/runtime/packages/picasso-progress-reports/package.json +30 -0
- package/runtime/packages/picasso-progress-reports/report.js +235 -0
- package/runtime/packages/picasso-sdk-server/aside.js +142 -0
- package/runtime/packages/picasso-sdk-server/connections.js +38 -0
- package/runtime/packages/picasso-sdk-server/context-timeline.js +27 -0
- package/runtime/packages/picasso-sdk-server/egress-gate.js +520 -0
- package/runtime/packages/picasso-sdk-server/failure-policy.js +246 -0
- package/runtime/packages/picasso-sdk-server/file-input.js +169 -0
- package/runtime/packages/picasso-sdk-server/goal.js +131 -0
- package/runtime/packages/picasso-sdk-server/ignore-file.js +458 -0
- package/runtime/packages/picasso-sdk-server/ignore-plugin.js +12 -0
- package/runtime/packages/picasso-sdk-server/ignore-sandbox.js +122 -0
- package/runtime/packages/picasso-sdk-server/ignore-snapshot.js +131 -0
- package/runtime/packages/picasso-sdk-server/image-input.js +44 -0
- package/runtime/packages/picasso-sdk-server/index.js +891 -0
- package/runtime/packages/picasso-sdk-server/instructions.js +34 -0
- package/runtime/packages/picasso-sdk-server/jobs.js +113 -0
- package/runtime/packages/picasso-sdk-server/mcp-gate.js +51 -0
- package/runtime/packages/picasso-sdk-server/model-selection.js +162 -0
- package/runtime/packages/picasso-sdk-server/package.json +50 -0
- package/runtime/packages/picasso-sdk-server/picasso-records.js +50 -0
- package/runtime/packages/picasso-sdk-server/provider-reload.js +84 -0
- package/runtime/packages/picasso-sdk-server/queue.js +322 -0
- package/runtime/packages/picasso-sdk-server/requester.js +43 -0
- package/runtime/packages/picasso-sdk-server/rewind.js +108 -0
- package/runtime/packages/picasso-sdk-server/schedule.js +187 -0
- package/runtime/packages/picasso-sdk-server/session-grants.js +35 -0
- package/runtime/packages/picasso-sdk-server/session-state.js +118 -0
- package/runtime/packages/picasso-sdk-server/shell-paths.js +869 -0
- package/runtime/packages/picasso-sdk-server/stream-deltas.js +211 -0
- package/runtime/packages/picasso-sdk-server/team-tasks.js +451 -0
- package/runtime/packages/picasso-sdk-server/tool-output.js +128 -0
- package/runtime/packages/picasso-sdk-server/tools-list.js +51 -0
- package/runtime/packages/picasso-sdk-server/wave2-hooks.js +612 -0
- package/runtime/packages/picasso-sdk-server/workspace-archive.js +170 -0
- package/runtime/packages/picasso-sdk-server/workspace-restore.js +180 -0
- package/runtime/packages/picasso-web-search/backends.js +412 -0
- package/runtime/packages/picasso-web-search/config.js +121 -0
- package/runtime/packages/picasso-web-search/cordis.patch.yml +7 -0
- package/runtime/packages/picasso-web-search/failure.js +116 -0
- package/runtime/packages/picasso-web-search/format.js +42 -0
- package/runtime/packages/picasso-web-search/index.js +71 -0
- package/runtime/packages/picasso-web-search/package.json +38 -0
- package/runtime/packages/picasso-web-search/router.js +156 -0
- package/runtime/packages/picasso-x-reader/circle.js +324 -0
- package/runtime/packages/picasso-x-reader/command.js +169 -0
- package/runtime/packages/picasso-x-reader/cordis.patch.yml +8 -0
- package/runtime/packages/picasso-x-reader/index.js +170 -0
- package/runtime/packages/picasso-x-reader/package.json +39 -0
- package/runtime/packages/picasso-x-reader/read.js +370 -0
- package/runtime/packages/picasso-x-reader/rewrite.js +38 -0
- package/runtime/packages/picasso-x-reader/settings.js +131 -0
- package/runtime/packages/picasso-x-reader/urls.js +154 -0
- package/runtime/packages/picasso-x-reader/xmd.js +512 -0
- package/runtime/plugins/picasso-auth-bridge/index.js +380 -0
- package/runtime/plugins/picasso-auth-bridge/package.json +28 -0
- package/runtime/plugins/picasso-auto-approve/index.js +1003 -0
- package/runtime/plugins/picasso-auto-approve/package.json +28 -0
- package/runtime/plugins/picasso-browser/index.js +424 -0
- package/runtime/plugins/picasso-browser/package.json +28 -0
- package/runtime/plugins/picasso-checkpoints/evidence.js +210 -0
- package/runtime/plugins/picasso-checkpoints/index.js +885 -0
- package/runtime/plugins/picasso-checkpoints/package.json +29 -0
- package/runtime/plugins/picasso-commands/fresh-review.js +573 -0
- package/runtime/plugins/picasso-commands/index.js +497 -0
- package/runtime/plugins/picasso-commands/package.json +28 -0
- package/runtime/plugins/picasso-instructions/conflicts.js +115 -0
- package/runtime/plugins/picasso-instructions/formats.js +145 -0
- package/runtime/plugins/picasso-instructions/frontmatter.js +175 -0
- package/runtime/plugins/picasso-instructions/glob.js +114 -0
- package/runtime/plugins/picasso-instructions/globals.js +90 -0
- package/runtime/plugins/picasso-instructions/imports.js +123 -0
- package/runtime/plugins/picasso-instructions/index.js +326 -0
- package/runtime/plugins/picasso-instructions/modes.js +64 -0
- package/runtime/plugins/picasso-instructions/package.json +30 -0
- package/runtime/plugins/picasso-instructions/parse.js +134 -0
- package/runtime/plugins/picasso-instructions/report.js +161 -0
- package/runtime/plugins/picasso-instructions/resolve.js +939 -0
- package/runtime/plugins/picasso-instructions/scan.js +181 -0
- package/runtime/plugins/picasso-instructions/settings.js +150 -0
- package/runtime/plugins/picasso-instructions/skills.js +345 -0
- package/runtime/plugins/picasso-lean-context/index.js +6280 -0
- package/runtime/plugins/picasso-lean-context/package.json +26 -0
- package/runtime/plugins/picasso-lean-context/read-image-recovery.js +306 -0
- package/runtime/plugins/picasso-lean-context/timeline.js +418 -0
- package/runtime/plugins/picasso-librarian/classify.js +146 -0
- package/runtime/plugins/picasso-librarian/index.js +878 -0
- package/runtime/plugins/picasso-librarian/notes.js +159 -0
- package/runtime/plugins/picasso-librarian/package.json +34 -0
- package/runtime/plugins/picasso-librarian/state.js +478 -0
- package/runtime/plugins/picasso-lifecycle-hooks/index.js +186 -0
- package/runtime/plugins/picasso-lifecycle-hooks/package.json +25 -0
- package/runtime/plugins/picasso-mail/inbox.js +207 -0
- package/runtime/plugins/picasso-mail/index.js +293 -0
- package/runtime/plugins/picasso-mail/package.json +22 -0
- package/runtime/plugins/picasso-memory/index.js +1184 -0
- package/runtime/plugins/picasso-memory/package.json +21 -0
- package/runtime/plugins/picasso-model-router/connections.js +912 -0
- package/runtime/plugins/picasso-model-router/index.js +1083 -0
- package/runtime/plugins/picasso-model-router/package.json +30 -0
- package/runtime/plugins/picasso-options/index.js +263 -0
- package/runtime/plugins/picasso-options/package.json +28 -0
- package/runtime/plugins/picasso-progress-reports/index.js +267 -0
- package/runtime/plugins/picasso-progress-reports/package.json +30 -0
- package/runtime/plugins/picasso-progress-reports/report.js +235 -0
- package/runtime/plugins/picasso-provider-models/index.js +436 -0
- package/runtime/plugins/picasso-provider-models/package.json +28 -0
- package/runtime/plugins/picasso-repo-index/index.js +1850 -0
- package/runtime/plugins/picasso-repo-index/package.json +28 -0
- package/runtime/plugins/picasso-schedule-pause/index.js +344 -0
- package/runtime/plugins/picasso-schedule-pause/package.json +28 -0
- package/runtime/plugins/picasso-session-lifecycle/index.js +796 -0
- package/runtime/plugins/picasso-session-lifecycle/package.json +28 -0
- package/runtime/plugins/picasso-trackers/index.js +895 -0
- package/runtime/plugins/picasso-trackers/package.json +28 -0
- package/runtime/plugins/picasso-web-search/backends.js +412 -0
- package/runtime/plugins/picasso-web-search/config.js +121 -0
- package/runtime/plugins/picasso-web-search/failure.js +116 -0
- package/runtime/plugins/picasso-web-search/format.js +42 -0
- package/runtime/plugins/picasso-web-search/index.js +71 -0
- package/runtime/plugins/picasso-web-search/package.json +38 -0
- package/runtime/plugins/picasso-web-search/router.js +156 -0
- package/runtime/plugins/picasso-x-reader/circle.js +324 -0
- package/runtime/plugins/picasso-x-reader/command.js +169 -0
- package/runtime/plugins/picasso-x-reader/index.js +170 -0
- package/runtime/plugins/picasso-x-reader/package.json +39 -0
- package/runtime/plugins/picasso-x-reader/read.js +370 -0
- package/runtime/plugins/picasso-x-reader/rewrite.js +38 -0
- package/runtime/plugins/picasso-x-reader/settings.js +131 -0
- package/runtime/plugins/picasso-x-reader/urls.js +154 -0
- package/runtime/plugins/picasso-x-reader/xmd.js +512 -0
- package/runtime/relay/attachment-text.mjs +737 -0
- package/runtime/relay/companion/companion.css +126 -0
- package/runtime/relay/companion/companion.js +648 -0
- package/runtime/relay/companion/icon.svg +5 -0
- package/runtime/relay/companion/index.html +25 -0
- package/runtime/relay/companion/manifest.json +13 -0
- package/runtime/relay/companion/sw.js +41 -0
- package/runtime/relay/main.mjs +38580 -0
- package/runtime/relay/model-listing.mjs +614 -0
- package/runtime/relay/versions-routes.mjs +1400 -0
- package/runtime/verify-plugins.mjs +205 -0
- package/runtime-lock/package-lock.json +10779 -0
- package/runtime-lock/package.json +7 -0
- package/scripts/install-runtime.mjs +400 -0
- package/README.md +0 -3
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
// @picasso/cache-probe — Phase 0 spike probe & Lean-Context Tier-1 / prompt-cache stability observer.
|
|
2
|
+
// A dependency-light Cordis plugin that proves the three integration seams the
|
|
3
|
+
// adoption plan relies on:
|
|
4
|
+
// 1. ctx.llm stream observability — llm/stream is a (options, next) waterfall:
|
|
5
|
+
// listeners MUST call next() to obtain the chunk stream and return it.
|
|
6
|
+
// Listens with { global: true } so both root-scoped TUI (sdk) and
|
|
7
|
+
// preset-scoped Desktop (web) sessions are observed.
|
|
8
|
+
// 2. tool registration via ctx.tools.register(defineTool(...))
|
|
9
|
+
// 3. tools/result (live) and tool/result (durable) observability logging
|
|
10
|
+
// The probe writes a JSONL record stream to $DSH_HOME/picasso-probe/probe.jsonl.
|
|
11
|
+
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
12
|
+
import { createHash } from 'node:crypto'
|
|
13
|
+
import { appendFileSync, mkdirSync } from 'node:fs'
|
|
14
|
+
import { join } from 'node:path'
|
|
15
|
+
import { homedir } from 'node:os'
|
|
16
|
+
|
|
17
|
+
export const name = 'picasso-cache-probe'
|
|
18
|
+
export const inject = ['tools']
|
|
19
|
+
|
|
20
|
+
function probeDir() {
|
|
21
|
+
const home = process.env.DSH_HOME && process.env.DSH_HOME.trim() ? process.env.DSH_HOME.trim() : join(homedir(), '.dsh')
|
|
22
|
+
return join(home, 'picasso-probe')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function logFile() {
|
|
26
|
+
return join(probeDir(), 'probe.jsonl')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function record(kind, data) {
|
|
30
|
+
try {
|
|
31
|
+
mkdirSync(probeDir(), { recursive: true })
|
|
32
|
+
appendFileSync(logFile(), JSON.stringify({ t: new Date().toISOString(), kind, data }) + '\n')
|
|
33
|
+
} catch {
|
|
34
|
+
// The probe must never take down the runtime it observes.
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function safeValue(value) {
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(JSON.stringify(value))
|
|
41
|
+
} catch {
|
|
42
|
+
return String(value)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function sha256(text) {
|
|
47
|
+
return createHash('sha256').update(String(text ?? ''), 'utf8').digest('hex')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function messageText(message) {
|
|
51
|
+
if (!message) return ''
|
|
52
|
+
if (typeof message === 'string') return message
|
|
53
|
+
if (typeof message.content === 'string') return message.content
|
|
54
|
+
if (Array.isArray(message.content)) {
|
|
55
|
+
return message.content
|
|
56
|
+
.map((part) => (part && typeof part.text === 'string' ? part.text : ''))
|
|
57
|
+
.filter(Boolean)
|
|
58
|
+
.join('\n')
|
|
59
|
+
}
|
|
60
|
+
return ''
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function extractSystemText(request) {
|
|
64
|
+
if (typeof request?.system === 'string' && request.system.length > 0) {
|
|
65
|
+
return request.system
|
|
66
|
+
}
|
|
67
|
+
const messages = Array.isArray(request?.messages) ? request.messages : []
|
|
68
|
+
return messages
|
|
69
|
+
.filter((msg) => msg && (msg.role === 'system' || msg.source?.kind === 'system-prompt'))
|
|
70
|
+
.map(messageText)
|
|
71
|
+
.filter(Boolean)
|
|
72
|
+
.join('\n\n')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function sumSourceBytes(messages, sourceKind) {
|
|
76
|
+
if (!Array.isArray(messages)) return 0
|
|
77
|
+
let total = 0
|
|
78
|
+
for (const msg of messages) {
|
|
79
|
+
if (msg && msg.source?.kind === sourceKind) {
|
|
80
|
+
total += Buffer.byteLength(messageText(msg), 'utf8')
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return total
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function computeUsageAndHitRate(rawUsage) {
|
|
87
|
+
if (!rawUsage || typeof rawUsage !== 'object') {
|
|
88
|
+
return { usage: null, hitRate: 0 }
|
|
89
|
+
}
|
|
90
|
+
const u = rawUsage.usage && typeof rawUsage.usage === 'object' ? rawUsage.usage : rawUsage
|
|
91
|
+
const inputTokens =
|
|
92
|
+
Number(
|
|
93
|
+
u.inputTokens ??
|
|
94
|
+
u.prompt_tokens ??
|
|
95
|
+
u.input_tokens ??
|
|
96
|
+
0,
|
|
97
|
+
) || 0
|
|
98
|
+
const cachedTokens =
|
|
99
|
+
Number(
|
|
100
|
+
u.cachedInputTokens ??
|
|
101
|
+
u.cacheReadInputTokens ??
|
|
102
|
+
u.cacheReadTokens ??
|
|
103
|
+
u.cache_read_input_tokens ??
|
|
104
|
+
u.prompt_tokens_details?.cached_tokens ??
|
|
105
|
+
0,
|
|
106
|
+
) || 0
|
|
107
|
+
const outputTokens =
|
|
108
|
+
Number(
|
|
109
|
+
u.outputTokens ??
|
|
110
|
+
u.completion_tokens ??
|
|
111
|
+
u.output_tokens ??
|
|
112
|
+
0,
|
|
113
|
+
) || 0
|
|
114
|
+
const cacheWriteTokens =
|
|
115
|
+
Number(
|
|
116
|
+
u.cacheWriteTokens ??
|
|
117
|
+
u.cacheCreationInputTokens ??
|
|
118
|
+
u.cache_creation_input_tokens ??
|
|
119
|
+
0,
|
|
120
|
+
) || 0
|
|
121
|
+
const denominator = inputTokens > 0 ? inputTokens : inputTokens + cachedTokens
|
|
122
|
+
const hitRate =
|
|
123
|
+
typeof u.cacheHitRate === 'number'
|
|
124
|
+
? u.cacheHitRate
|
|
125
|
+
: denominator > 0
|
|
126
|
+
? Number((cachedTokens / denominator).toFixed(4))
|
|
127
|
+
: 0
|
|
128
|
+
return {
|
|
129
|
+
usage: {
|
|
130
|
+
...safeValue(u),
|
|
131
|
+
inputTokens,
|
|
132
|
+
outputTokens,
|
|
133
|
+
cachedInputTokens: cachedTokens,
|
|
134
|
+
cacheWriteTokens,
|
|
135
|
+
cacheHitRate: hitRate,
|
|
136
|
+
},
|
|
137
|
+
hitRate,
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Compute a per-turn cache-probe row from an `llm/stream` request and the
|
|
143
|
+
* previous turn's row for the same session.
|
|
144
|
+
*/
|
|
145
|
+
export function buildProbeRow(request, prev, turnNumber) {
|
|
146
|
+
const messages = Array.isArray(request?.messages) ? request.messages : []
|
|
147
|
+
const tools = Array.isArray(request?.tools) ? request.tools : []
|
|
148
|
+
const systemText = extractSystemText(request)
|
|
149
|
+
const toolsJson = JSON.stringify(tools)
|
|
150
|
+
|
|
151
|
+
const systemBytes = Buffer.byteLength(systemText, 'utf8')
|
|
152
|
+
const toolsBytes = Buffer.byteLength(toolsJson, 'utf8')
|
|
153
|
+
const skillCatalogBytes = sumSourceBytes(messages, 'skill-catalog')
|
|
154
|
+
const instructionsBytes = sumSourceBytes(messages, 'agent-instructions')
|
|
155
|
+
const runtimeContextBytes = sumSourceBytes(messages, 'runtime-context')
|
|
156
|
+
const memoryBytes = sumSourceBytes(messages, 'picasso-memory')
|
|
157
|
+
const tier1Bytes =
|
|
158
|
+
systemBytes +
|
|
159
|
+
toolsBytes +
|
|
160
|
+
skillCatalogBytes +
|
|
161
|
+
instructionsBytes +
|
|
162
|
+
runtimeContextBytes +
|
|
163
|
+
memoryBytes
|
|
164
|
+
|
|
165
|
+
const systemSha256 = sha256(systemText)
|
|
166
|
+
const toolsSha256 = sha256(toolsJson)
|
|
167
|
+
const tier1Sha256 = sha256(JSON.stringify({ system: systemText, tools }))
|
|
168
|
+
|
|
169
|
+
const nonSystemMessages = messages.filter(
|
|
170
|
+
(msg) => msg && msg.role !== 'system' && msg.source?.kind !== 'system-prompt',
|
|
171
|
+
)
|
|
172
|
+
const firstMsg = nonSystemMessages[0] ?? messages[0]
|
|
173
|
+
const firstMsgSha256 = sha256(firstMsg ? messageText(firstMsg) : '')
|
|
174
|
+
|
|
175
|
+
const breakReasons = []
|
|
176
|
+
if (prev != null && typeof prev === 'object') {
|
|
177
|
+
if (prev.systemSha256 !== systemSha256) breakReasons.push('system-changed')
|
|
178
|
+
if (prev.toolsSha256 !== toolsSha256) breakReasons.push('tools-changed')
|
|
179
|
+
if (prev.firstMsgSha256 !== firstMsgSha256) breakReasons.push('first-message-changed')
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const prefixStable =
|
|
183
|
+
prev == null || typeof prev !== 'object'
|
|
184
|
+
? true
|
|
185
|
+
: prev.systemSha256 === systemSha256 && prev.toolsSha256 === toolsSha256
|
|
186
|
+
const stable = breakReasons.length === 0
|
|
187
|
+
|
|
188
|
+
const { usage, hitRate } = computeUsageAndHitRate(request?.usage)
|
|
189
|
+
const turn =
|
|
190
|
+
typeof turnNumber === 'number'
|
|
191
|
+
? turnNumber
|
|
192
|
+
: prev && typeof prev.turn === 'number'
|
|
193
|
+
? prev.turn + 1
|
|
194
|
+
: 1
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
turn,
|
|
198
|
+
at: new Date().toISOString(),
|
|
199
|
+
sessionId: request?.sessionId ?? 'default',
|
|
200
|
+
provider: request?.provider ?? 'unknown',
|
|
201
|
+
model: request?.model ?? 'unknown',
|
|
202
|
+
purpose: request?.purpose,
|
|
203
|
+
toolCount: tools.length,
|
|
204
|
+
messageCount: messages.length,
|
|
205
|
+
systemBytes,
|
|
206
|
+
toolsBytes,
|
|
207
|
+
skillCatalogBytes,
|
|
208
|
+
instructionsBytes,
|
|
209
|
+
runtimeContextBytes,
|
|
210
|
+
memoryBytes,
|
|
211
|
+
tier1Bytes,
|
|
212
|
+
tier1Sha256,
|
|
213
|
+
systemSha256,
|
|
214
|
+
toolsSha256,
|
|
215
|
+
firstMsgSha256,
|
|
216
|
+
prefixStable,
|
|
217
|
+
stable,
|
|
218
|
+
breakReasons,
|
|
219
|
+
usage,
|
|
220
|
+
hitRate,
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const sessionTurns = new Map()
|
|
225
|
+
const allRows = []
|
|
226
|
+
|
|
227
|
+
export function getProbeRows(sessionId) {
|
|
228
|
+
if (sessionId === undefined) return [...allRows]
|
|
229
|
+
return [...(sessionTurns.get(sessionId) ?? [])]
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function clearProbeRows() {
|
|
233
|
+
sessionTurns.clear()
|
|
234
|
+
allRows.length = 0
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function formatCacheReport(rows = allRows) {
|
|
238
|
+
if (!Array.isArray(rows) || rows.length === 0) {
|
|
239
|
+
return 'No cache-probe turns recorded yet.'
|
|
240
|
+
}
|
|
241
|
+
const latest = rows[rows.length - 1]
|
|
242
|
+
const vsMcpPct = (((847_722 - latest.tier1Bytes) / 847_722) * 100).toFixed(1)
|
|
243
|
+
const vsNoMcpPct = (((142_568 - latest.tier1Bytes) / 142_568) * 100).toFixed(1)
|
|
244
|
+
const header = `Tier-1 Breakdown (latest=${latest.tier1Bytes} B; -${vsMcpPct}% vs 847722 B MCP baseline, -${vsNoMcpPct}% vs 142568 B non-MCP baseline):`
|
|
245
|
+
const lines = rows.map(
|
|
246
|
+
(r) =>
|
|
247
|
+
`Turn ${r.turn} [${r.provider}/${r.model}] tier1=${r.tier1Bytes}B (sys=${r.systemBytes}B tools=${r.toolsBytes}B skills=${r.skillCatalogBytes}B instr=${r.instructionsBytes}B ctx=${r.runtimeContextBytes}B mem=${r.memoryBytes}B) prefixStable=${r.prefixStable} stable=${r.stable} hitRate=${Math.round((r.hitRate ?? 0) * 100)}%`,
|
|
248
|
+
)
|
|
249
|
+
return [header, ...lines].join('\n')
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Transparent pass-through wrapper over the llm chunk stream: records
|
|
253
|
+
// usage-bearing chunks without disturbing the stream contract.
|
|
254
|
+
async function* observeStream(stream, row) {
|
|
255
|
+
for await (const chunk of stream) {
|
|
256
|
+
try {
|
|
257
|
+
if (chunk && (chunk.type === 'usage' || chunk.usage)) {
|
|
258
|
+
const { usage, hitRate } = computeUsageAndHitRate(chunk)
|
|
259
|
+
if (row) {
|
|
260
|
+
row.usage = usage
|
|
261
|
+
row.hitRate = hitRate
|
|
262
|
+
}
|
|
263
|
+
record('llm-stream-usage', {
|
|
264
|
+
...safeValue(chunk),
|
|
265
|
+
...(row ? { sessionId: row.sessionId, turn: row.turn, hitRate, tier1Bytes: row.tier1Bytes, prefixStable: row.prefixStable } : {}),
|
|
266
|
+
})
|
|
267
|
+
}
|
|
268
|
+
} catch {
|
|
269
|
+
// observation must never break the stream
|
|
270
|
+
}
|
|
271
|
+
yield chunk
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function apply(ctx) {
|
|
276
|
+
record('plugin-boot', { name })
|
|
277
|
+
|
|
278
|
+
// --- 1. ctx.llm observability -------------------------------------------
|
|
279
|
+
const llm = ctx.get?.('llm')
|
|
280
|
+
if (llm) {
|
|
281
|
+
let routes = []
|
|
282
|
+
try {
|
|
283
|
+
routes = typeof llm.listProviders === 'function' ? llm.listProviders() : []
|
|
284
|
+
} catch {
|
|
285
|
+
routes = []
|
|
286
|
+
}
|
|
287
|
+
record('llm-present', { routes })
|
|
288
|
+
} else {
|
|
289
|
+
record('llm-absent', {})
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// llm/stream is a waterfall listener: (options, next) => stream.
|
|
293
|
+
// Listen with { global: true } so picasso-cache-probe captures requests in both
|
|
294
|
+
// root-scoped TUI (sdk) and preset-scoped Desktop (web) sessions.
|
|
295
|
+
const onLlmStream = (options, next) => {
|
|
296
|
+
let row
|
|
297
|
+
try {
|
|
298
|
+
const normalized =
|
|
299
|
+
options && typeof options === 'object' && options.request
|
|
300
|
+
? {
|
|
301
|
+
...options.request,
|
|
302
|
+
sessionId: options.sessionId ?? options.request.sessionId,
|
|
303
|
+
purpose: options.purpose ?? options.request.purpose,
|
|
304
|
+
usage: options.usage ?? options.request.usage,
|
|
305
|
+
}
|
|
306
|
+
: (options ?? {})
|
|
307
|
+
const sessionId = normalized.sessionId || 'default'
|
|
308
|
+
const history = sessionTurns.get(sessionId) ?? []
|
|
309
|
+
const prev = history[history.length - 1]
|
|
310
|
+
row = buildProbeRow(normalized, prev, history.length + 1)
|
|
311
|
+
history.push(row)
|
|
312
|
+
sessionTurns.set(sessionId, history)
|
|
313
|
+
allRows.push(row)
|
|
314
|
+
record('llm-stream-request', row)
|
|
315
|
+
} catch {
|
|
316
|
+
// no-op
|
|
317
|
+
}
|
|
318
|
+
const stream = typeof next === 'function' ? next() : undefined
|
|
319
|
+
return stream == null ? stream : observeStream(stream, row)
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
let disposeStream = () => {}
|
|
323
|
+
try {
|
|
324
|
+
disposeStream = ctx.on('llm/stream', onLlmStream, { global: true }) || (() => {})
|
|
325
|
+
} catch {
|
|
326
|
+
try {
|
|
327
|
+
disposeStream = ctx.on('llm/stream', onLlmStream) || (() => {})
|
|
328
|
+
} catch {
|
|
329
|
+
// no-op
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
let disposeAdapters = () => {}
|
|
334
|
+
try {
|
|
335
|
+
disposeAdapters =
|
|
336
|
+
ctx.on(
|
|
337
|
+
'llm/adapters-updated',
|
|
338
|
+
() => {
|
|
339
|
+
let routes2 = []
|
|
340
|
+
try {
|
|
341
|
+
const llmNow = ctx.get?.('llm')
|
|
342
|
+
routes2 = llmNow && typeof llmNow.listProviders === 'function' ? llmNow.listProviders() : []
|
|
343
|
+
} catch {
|
|
344
|
+
routes2 = []
|
|
345
|
+
}
|
|
346
|
+
record('llm-adapters-updated', { routes: routes2 })
|
|
347
|
+
},
|
|
348
|
+
{ global: true },
|
|
349
|
+
) || (() => {})
|
|
350
|
+
} catch {
|
|
351
|
+
// no-op
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Optional /cache command registration when commands service is available
|
|
355
|
+
let disposeCommand = () => {}
|
|
356
|
+
try {
|
|
357
|
+
const commands = ctx.get?.('commands') ?? ctx.commands
|
|
358
|
+
if (commands && typeof commands.register === 'function') {
|
|
359
|
+
disposeCommand =
|
|
360
|
+
commands.register({
|
|
361
|
+
name: 'cache',
|
|
362
|
+
description: 'Show per-turn prompt-cache and Tier-1 context breakdown.',
|
|
363
|
+
handler: (invocation) => {
|
|
364
|
+
const sessionId = invocation?.agent?.session?.id
|
|
365
|
+
const rows = sessionId ? getProbeRows(sessionId) : getProbeRows()
|
|
366
|
+
return {
|
|
367
|
+
kind: 'success',
|
|
368
|
+
text: formatCacheReport(rows.length > 0 ? rows : getProbeRows()),
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
}) || (() => {})
|
|
372
|
+
}
|
|
373
|
+
} catch {
|
|
374
|
+
// ignore if /cache is already registered or commands unavailable
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// --- 2. tool registration ------------------------------------------------
|
|
378
|
+
let dispose = () => {}
|
|
379
|
+
try {
|
|
380
|
+
dispose = ctx.tools.register(
|
|
381
|
+
defineTool({
|
|
382
|
+
name: 'picasso_cache_probe',
|
|
383
|
+
description:
|
|
384
|
+
'Report picasso cache-harness adoption status: harness levels (H0-H3), scenario suite size, cache policy source, and the mounted dsh LLM routes.',
|
|
385
|
+
parameters: {},
|
|
386
|
+
output: {
|
|
387
|
+
schema: {
|
|
388
|
+
type: 'object',
|
|
389
|
+
properties: {
|
|
390
|
+
status: { type: 'string' },
|
|
391
|
+
harnessLevels: { type: 'array', items: { type: 'string' } },
|
|
392
|
+
scenarios: { type: 'number' },
|
|
393
|
+
cachePolicy: { type: 'string' },
|
|
394
|
+
llmRoutes: { type: 'array', items: { type: 'string' } },
|
|
395
|
+
probeLog: { type: 'string' },
|
|
396
|
+
},
|
|
397
|
+
additionalProperties: false,
|
|
398
|
+
},
|
|
399
|
+
render: (_args, value) => [{ type: 'text', text: JSON.stringify(value) }],
|
|
400
|
+
},
|
|
401
|
+
execute: async (_args, _exec) => {
|
|
402
|
+
let routes3 = []
|
|
403
|
+
const llm2 = ctx.get?.('llm')
|
|
404
|
+
try {
|
|
405
|
+
routes3 = llm2 && typeof llm2.listProviders === 'function' ? llm2.listProviders() : []
|
|
406
|
+
} catch {
|
|
407
|
+
routes3 = []
|
|
408
|
+
}
|
|
409
|
+
const value = {
|
|
410
|
+
status: 'probe-ok',
|
|
411
|
+
harnessLevels: ['H0', 'H1', 'H2', 'H3'],
|
|
412
|
+
scenarios: 9,
|
|
413
|
+
cachePolicy: '@picasso/cache-harness (cache policy / context packs)',
|
|
414
|
+
llmRoutes: routes3.map((route) =>
|
|
415
|
+
typeof route === 'string' ? route : (route && route.name) || String(route),
|
|
416
|
+
),
|
|
417
|
+
probeLog: logFile(),
|
|
418
|
+
}
|
|
419
|
+
record('tool-executed', { name: 'picasso_cache_probe', ...value })
|
|
420
|
+
return value
|
|
421
|
+
},
|
|
422
|
+
}),
|
|
423
|
+
)
|
|
424
|
+
record('tool-registered', { name: 'picasso_cache_probe' })
|
|
425
|
+
} catch (error) {
|
|
426
|
+
record('tool-register-failed', {
|
|
427
|
+
message: String(error && error.message ? error.message : error),
|
|
428
|
+
})
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// --- 3. tools/result (live) + tool/result (durable) observability --------
|
|
432
|
+
ctx.on(
|
|
433
|
+
'tools/result',
|
|
434
|
+
(execution) => {
|
|
435
|
+
record('tools-result-live', {
|
|
436
|
+
name: execution && execution.name,
|
|
437
|
+
isError: execution && execution.result && execution.result.isError,
|
|
438
|
+
})
|
|
439
|
+
},
|
|
440
|
+
{ global: true },
|
|
441
|
+
)
|
|
442
|
+
ctx.on(
|
|
443
|
+
'tool/result',
|
|
444
|
+
(event) => {
|
|
445
|
+
record('tool-result-durable', {
|
|
446
|
+
name: event && event.name,
|
|
447
|
+
isError: event && event.isError,
|
|
448
|
+
})
|
|
449
|
+
},
|
|
450
|
+
{ global: true },
|
|
451
|
+
)
|
|
452
|
+
|
|
453
|
+
record('plugin-ready', {})
|
|
454
|
+
return () => {
|
|
455
|
+
try {
|
|
456
|
+
disposeStream()
|
|
457
|
+
disposeAdapters()
|
|
458
|
+
disposeCommand()
|
|
459
|
+
dispose()
|
|
460
|
+
} catch {
|
|
461
|
+
// no-op
|
|
462
|
+
}
|
|
463
|
+
record('plugin-disposed', {})
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export default {
|
|
468
|
+
name,
|
|
469
|
+
inject,
|
|
470
|
+
apply,
|
|
471
|
+
buildProbeRow,
|
|
472
|
+
getProbeRows,
|
|
473
|
+
clearProbeRows,
|
|
474
|
+
formatCacheReport,
|
|
475
|
+
logFile,
|
|
476
|
+
}
|
|
477
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@picasso/cache-probe",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Phase 0 spike: cache-usage observability probe as an official dsh profile bundle. Exercises ctx.llm stream hooks (llm/stream waterfall), a registered tool (ctx.tools.register via defineTool), and tools/result observability.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "node --import ../../test/setup/hermetic-preload.mjs --test test/*.test.mjs"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./index.js",
|
|
13
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"dsh": {
|
|
17
|
+
"bundle": {
|
|
18
|
+
"patch": "./cordis.patch.yml"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"index.js",
|
|
23
|
+
"cordis.patch.yml",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.3"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@deepseek-ai/dsh-tools": ">=0.2.2-rc.3 <0.3.0-0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependenciesMeta": {
|
|
33
|
+
"@deepseek-ai/dsh-tools": {
|
|
34
|
+
"optional": true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"license": "UNLICENSED"
|
|
38
|
+
}
|