picocode-core 0.9.193 → 0.9.194
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/package.json +2 -2
- package/src/agent.js +11 -1
- package/src/controller.js +28 -8
- package/src/derive.js +4 -1
- package/src/stream-transcript.js +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "picocode-core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.194",
|
|
4
4
|
"description": "The agent runtime behind pico: sessions, tools, subagents, MCP, memory, and model access",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
28
|
-
"@prsm/ai": "^1.
|
|
28
|
+
"@prsm/ai": "^1.9.0",
|
|
29
29
|
"diff": "^7.0.0",
|
|
30
30
|
"globby": "^16.2.4",
|
|
31
31
|
"proper-lockfile": "^4.1.2",
|
package/src/agent.js
CHANGED
|
@@ -102,7 +102,7 @@ function estimateTokens(value) {
|
|
|
102
102
|
return Math.ceil(JSON.stringify(value ?? '').length / 4)
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
export async function runTurn({ history, tools, recorder, modelName, effort, auth, system, signal, onStream, stallMs = STALL_MS }) {
|
|
105
|
+
export async function runTurn({ history, tools, recorder, modelName, effort, auth, system, signal, onStream, beforeRequest, stallMs = STALL_MS }) {
|
|
106
106
|
const collected = []
|
|
107
107
|
let roundText = ''
|
|
108
108
|
let usageSeen = null
|
|
@@ -190,6 +190,16 @@ export async function runTurn({ history, tools, recorder, modelName, effort, aut
|
|
|
190
190
|
onStream?.({ type: 'usage_estimate', usage: estimatedUsage() })
|
|
191
191
|
const out = await model({
|
|
192
192
|
model: modelName,
|
|
193
|
+
beforeRequest: async (request) => {
|
|
194
|
+
if (internal.signal.aborted) return request
|
|
195
|
+
const messages = await beforeRequest?.() || []
|
|
196
|
+
if (messages.length && roundText) {
|
|
197
|
+
collected.push({ role: 'assistant', content: roundText })
|
|
198
|
+
roundText = ''
|
|
199
|
+
}
|
|
200
|
+
collected.push(...messages)
|
|
201
|
+
return { ...request, history: [...request.history, ...messages] }
|
|
202
|
+
},
|
|
193
203
|
...(effort && { effort }),
|
|
194
204
|
...(auth?.apiKey && { apiKey: auth.apiKey }),
|
|
195
205
|
...(auth?.headers && { headers: auth.headers }),
|
package/src/controller.js
CHANGED
|
@@ -11,6 +11,7 @@ import { appendPrompt } from './history.js'
|
|
|
11
11
|
import { runTurn, summarizeText, compactHistory, compactProgress } from './agent.js'
|
|
12
12
|
import { createAgentManager } from './agents.js'
|
|
13
13
|
import { createPeers } from './peers.js'
|
|
14
|
+
import { streamTranscript } from './stream-transcript.js'
|
|
14
15
|
import { runDeliberation, validateDeliberation } from './deliberation.js'
|
|
15
16
|
import { deliberationsFromEvents } from './deliberation-history.js'
|
|
16
17
|
import { compactionPrompt, formatCompactSummary, summarySections, compactionKeepFrom } from './compaction.js'
|
|
@@ -206,8 +207,9 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
206
207
|
reDerive()
|
|
207
208
|
if (state.busy && !state.compacting) {
|
|
208
209
|
const items = [...state.overlay]
|
|
209
|
-
flushStream(items)
|
|
210
|
-
|
|
210
|
+
if (direction === 'outgoing') flushStream(items)
|
|
211
|
+
const item = state.derived.transcript.findLast((item) => item.kind === 'peer' && item.messageId === message.id)
|
|
212
|
+
items.push({ ...item, ...(direction === 'incoming' && state.streaming !== null ? { streamPending: true } : {}) })
|
|
211
213
|
set({ overlay: items })
|
|
212
214
|
}
|
|
213
215
|
})()
|
|
@@ -300,6 +302,10 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
300
302
|
|
|
301
303
|
function reDerive() {
|
|
302
304
|
state.derived = deriveState(state.events)
|
|
305
|
+
const peerItems = new Map(state.derived.transcript.filter(item => item.kind === 'peer').map(item => [item.messageId, item]))
|
|
306
|
+
state.overlay = state.overlay.map(item => item.kind === 'peer' && item.direction === 'incoming'
|
|
307
|
+
? { ...item, read: peerItems.get(item.messageId)?.read ?? item.read }
|
|
308
|
+
: item)
|
|
303
309
|
emit('derived', state.derived)
|
|
304
310
|
changed()
|
|
305
311
|
}
|
|
@@ -479,7 +485,7 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
479
485
|
}
|
|
480
486
|
if (shell.killedBy === 'user') {
|
|
481
487
|
flash(`shell ${shell.id} killed`)
|
|
482
|
-
noteSystem(`[system notification] the user manually killed background shell ${shell.id} (${shell.description || shell.command}) from the shells panel (SIGTERM). This was deliberate; do not restart it unless asked.`, { wake: false, sessionId: shell.sessionId, sessionFile: shell.sessionFile })
|
|
488
|
+
noteSystem(`[system notification] the user manually killed background shell ${shell.id} (${shell.description || shell.command}) from the shells panel (SIGTERM). This was deliberate; do not restart it unless asked.`, { wake: false, duringTurn: true, sessionId: shell.sessionId, sessionFile: shell.sessionFile })
|
|
483
489
|
return
|
|
484
490
|
}
|
|
485
491
|
flash(`shell ${shell.id} exited · code ${shell.exitCode}`)
|
|
@@ -487,16 +493,16 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
487
493
|
noteSystem(
|
|
488
494
|
`[system notification] background shell ${shell.id} (${shell.description || shell.command}) exited with code ${shell.exitCode} after ${shellRuntime(shell)}.` +
|
|
489
495
|
(tail ? `\nRecent output:\n${tail}` : ''),
|
|
490
|
-
{ wake: true, sessionId: shell.sessionId, sessionFile: shell.sessionFile },
|
|
496
|
+
{ wake: true, duringTurn: true, sessionId: shell.sessionId, sessionFile: shell.sessionFile },
|
|
491
497
|
)
|
|
492
498
|
})
|
|
493
499
|
|
|
494
500
|
// a note for a session that has not started yet waits for its first
|
|
495
501
|
// message; `ensure` starts the session now so the note is persisted and
|
|
496
502
|
// in view before the first turn, not after it
|
|
497
|
-
function noteSystem(text, { wake, agentId, ensure = false, sessionId = state.session?.id, sessionFile = state.session?.file } = {}) {
|
|
503
|
+
function noteSystem(text, { wake, agentId, duringTurn = false, ensure = false, sessionId = state.session?.id, sessionFile = state.session?.file } = {}) {
|
|
498
504
|
if (ensure && !state.session && !state.busy) ensureSession()
|
|
499
|
-
pendingSystemNotes.push({ text, wake, agentId, sessionId: sessionId ?? state.session?.id, sessionFile: sessionFile ?? state.session?.file })
|
|
505
|
+
pendingSystemNotes.push({ text, wake, agentId, duringTurn, sessionId: sessionId ?? state.session?.id, sessionFile: sessionFile ?? state.session?.file })
|
|
500
506
|
flushSystemNotes()
|
|
501
507
|
}
|
|
502
508
|
|
|
@@ -505,6 +511,15 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
505
511
|
pendingSystemNotes = pendingSystemNotes.filter((note) => !collected.has(String(note.agentId)))
|
|
506
512
|
}
|
|
507
513
|
|
|
514
|
+
function takeTurnNotes(signal) {
|
|
515
|
+
if (signal.aborted || state.held || peerTransition || shuttingDown || !state.session || state.expedited.length || state.views.length) return []
|
|
516
|
+
const current = pendingSystemNotes.filter((note) => note.duringTurn && (!note.sessionId || note.sessionId === state.session.id))
|
|
517
|
+
if (!current.length) return []
|
|
518
|
+
const taken = new Set(current)
|
|
519
|
+
pendingSystemNotes = pendingSystemNotes.filter((note) => !taken.has(note))
|
|
520
|
+
return [{ role: 'user', content: current.map((note) => note.text).join('\n\n') }]
|
|
521
|
+
}
|
|
522
|
+
|
|
508
523
|
function flushSystemNotes() {
|
|
509
524
|
schedulePeerWake()
|
|
510
525
|
if (!pendingSystemNotes.length || state.busy || state.held || peerTransition || shuttingDown || !state.session) return
|
|
@@ -530,7 +545,8 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
530
545
|
}
|
|
531
546
|
|
|
532
547
|
function flushStream(items) {
|
|
533
|
-
|
|
548
|
+
const flushed = streamTranscript(items, state.streaming)
|
|
549
|
+
items.splice(0, items.length, ...flushed)
|
|
534
550
|
state.streaming = null
|
|
535
551
|
}
|
|
536
552
|
|
|
@@ -822,6 +838,7 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
822
838
|
system: context.system,
|
|
823
839
|
signal: controller.signal,
|
|
824
840
|
onStream: streamHandler(recorder, controller),
|
|
841
|
+
beforeRequest: () => takeTurnNotes(controller.signal),
|
|
825
842
|
})
|
|
826
843
|
} catch (err) {
|
|
827
844
|
abort = null
|
|
@@ -833,7 +850,10 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
833
850
|
|
|
834
851
|
const turnTranscript = [...state.overlay]
|
|
835
852
|
flushStream(turnTranscript)
|
|
836
|
-
for (const message of result.messages)
|
|
853
|
+
for (const message of result.messages) {
|
|
854
|
+
if (message.role === 'user') persist(makeEvent('system_note', { text: message.content }))
|
|
855
|
+
else persist(makeEvent('message', { message, hideFromTranscript: true }))
|
|
856
|
+
}
|
|
837
857
|
persist(makeEvent('turn_transcript', { items: turnTranscript }))
|
|
838
858
|
for (const entry of recorder.entries) persist(makeEvent('tool_meta', entry))
|
|
839
859
|
for (const path of tracker.loaded) {
|
package/src/derive.js
CHANGED
|
@@ -149,6 +149,8 @@ function peerInputMessage(peer) {
|
|
|
149
149
|
function flushConsumedPeers(state) {
|
|
150
150
|
if (state.openToolCalls.size) return
|
|
151
151
|
for (const { peer, eventId } of state.deferredConsumedPeers.splice(0)) {
|
|
152
|
+
const entry = state.peerMessages.get(peer.id)
|
|
153
|
+
if (entry?.item) entry.item.read = true
|
|
152
154
|
pushHistory(state, peerInputMessage(peer), eventId)
|
|
153
155
|
}
|
|
154
156
|
}
|
|
@@ -253,6 +255,7 @@ export function deriveState(events) {
|
|
|
253
255
|
const item = {
|
|
254
256
|
kind: 'peer', direction: peer.direction, from: peer.from, to: peer.to,
|
|
255
257
|
text: peer.message, urgent: peer.urgent ?? false, status: peer.status || 'unknown', messageId: peer.id,
|
|
258
|
+
...(peer.direction === 'incoming' ? { read: false } : {}),
|
|
256
259
|
eventId: event.id, at: event.at ?? null,
|
|
257
260
|
}
|
|
258
261
|
state.transcript.push(item)
|
|
@@ -280,7 +283,7 @@ export function deriveState(events) {
|
|
|
280
283
|
const entry = state.peerMessages.get(restored.messageId)
|
|
281
284
|
if (entry?.item) {
|
|
282
285
|
state.transcript = state.transcript.filter((candidate) => candidate !== entry.item)
|
|
283
|
-
Object.assign(restored, { status: entry.item.status, error: entry.item.error })
|
|
286
|
+
Object.assign(restored, { status: entry.item.status, error: entry.item.error, ...(entry.peer.direction === 'incoming' ? { read: entry.item.read } : {}) })
|
|
284
287
|
entry.item = restored
|
|
285
288
|
}
|
|
286
289
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function streamTranscript(items, text) {
|
|
2
|
+
const boundary = items.findIndex(item => item.streamPending)
|
|
3
|
+
const index = boundary < 0 ? items.length : boundary
|
|
4
|
+
return [
|
|
5
|
+
...items.slice(0, index),
|
|
6
|
+
...(text ? [{ kind: 'assistant', text }] : []),
|
|
7
|
+
...items.slice(index).map(({ streamPending, ...item }) => item),
|
|
8
|
+
]
|
|
9
|
+
}
|