picocode-core 0.9.193 → 0.9.195
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 +21 -7
- package/src/derive.js +11 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "picocode-core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.195",
|
|
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
|
@@ -204,10 +204,11 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
204
204
|
state.events.push(event)
|
|
205
205
|
state.persisted = state.events.length
|
|
206
206
|
reDerive()
|
|
207
|
-
if (state.busy && !state.compacting) {
|
|
207
|
+
if (state.busy && !state.compacting && direction === 'outgoing') {
|
|
208
208
|
const items = [...state.overlay]
|
|
209
209
|
flushStream(items)
|
|
210
|
-
|
|
210
|
+
const item = state.derived.transcript.findLast((item) => item.kind === 'peer' && item.messageId === message.id)
|
|
211
|
+
items.push(item)
|
|
211
212
|
set({ overlay: items })
|
|
212
213
|
}
|
|
213
214
|
})()
|
|
@@ -479,7 +480,7 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
479
480
|
}
|
|
480
481
|
if (shell.killedBy === 'user') {
|
|
481
482
|
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 })
|
|
483
|
+
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
484
|
return
|
|
484
485
|
}
|
|
485
486
|
flash(`shell ${shell.id} exited · code ${shell.exitCode}`)
|
|
@@ -487,16 +488,16 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
487
488
|
noteSystem(
|
|
488
489
|
`[system notification] background shell ${shell.id} (${shell.description || shell.command}) exited with code ${shell.exitCode} after ${shellRuntime(shell)}.` +
|
|
489
490
|
(tail ? `\nRecent output:\n${tail}` : ''),
|
|
490
|
-
{ wake: true, sessionId: shell.sessionId, sessionFile: shell.sessionFile },
|
|
491
|
+
{ wake: true, duringTurn: true, sessionId: shell.sessionId, sessionFile: shell.sessionFile },
|
|
491
492
|
)
|
|
492
493
|
})
|
|
493
494
|
|
|
494
495
|
// a note for a session that has not started yet waits for its first
|
|
495
496
|
// message; `ensure` starts the session now so the note is persisted and
|
|
496
497
|
// 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 } = {}) {
|
|
498
|
+
function noteSystem(text, { wake, agentId, duringTurn = false, ensure = false, sessionId = state.session?.id, sessionFile = state.session?.file } = {}) {
|
|
498
499
|
if (ensure && !state.session && !state.busy) ensureSession()
|
|
499
|
-
pendingSystemNotes.push({ text, wake, agentId, sessionId: sessionId ?? state.session?.id, sessionFile: sessionFile ?? state.session?.file })
|
|
500
|
+
pendingSystemNotes.push({ text, wake, agentId, duringTurn, sessionId: sessionId ?? state.session?.id, sessionFile: sessionFile ?? state.session?.file })
|
|
500
501
|
flushSystemNotes()
|
|
501
502
|
}
|
|
502
503
|
|
|
@@ -505,6 +506,15 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
505
506
|
pendingSystemNotes = pendingSystemNotes.filter((note) => !collected.has(String(note.agentId)))
|
|
506
507
|
}
|
|
507
508
|
|
|
509
|
+
function takeTurnNotes(signal) {
|
|
510
|
+
if (signal.aborted || state.held || peerTransition || shuttingDown || !state.session || state.expedited.length || state.views.length) return []
|
|
511
|
+
const current = pendingSystemNotes.filter((note) => note.duringTurn && (!note.sessionId || note.sessionId === state.session.id))
|
|
512
|
+
if (!current.length) return []
|
|
513
|
+
const taken = new Set(current)
|
|
514
|
+
pendingSystemNotes = pendingSystemNotes.filter((note) => !taken.has(note))
|
|
515
|
+
return [{ role: 'user', content: current.map((note) => note.text).join('\n\n') }]
|
|
516
|
+
}
|
|
517
|
+
|
|
508
518
|
function flushSystemNotes() {
|
|
509
519
|
schedulePeerWake()
|
|
510
520
|
if (!pendingSystemNotes.length || state.busy || state.held || peerTransition || shuttingDown || !state.session) return
|
|
@@ -822,6 +832,7 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
822
832
|
system: context.system,
|
|
823
833
|
signal: controller.signal,
|
|
824
834
|
onStream: streamHandler(recorder, controller),
|
|
835
|
+
beforeRequest: () => takeTurnNotes(controller.signal),
|
|
825
836
|
})
|
|
826
837
|
} catch (err) {
|
|
827
838
|
abort = null
|
|
@@ -833,7 +844,10 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
833
844
|
|
|
834
845
|
const turnTranscript = [...state.overlay]
|
|
835
846
|
flushStream(turnTranscript)
|
|
836
|
-
for (const message of result.messages)
|
|
847
|
+
for (const message of result.messages) {
|
|
848
|
+
if (message.role === 'user') persist(makeEvent('system_note', { text: message.content }))
|
|
849
|
+
else persist(makeEvent('message', { message, hideFromTranscript: true }))
|
|
850
|
+
}
|
|
837
851
|
persist(makeEvent('turn_transcript', { items: turnTranscript }))
|
|
838
852
|
for (const entry of recorder.entries) persist(makeEvent('tool_meta', entry))
|
|
839
853
|
for (const path of tracker.loaded) {
|
package/src/derive.js
CHANGED
|
@@ -149,6 +149,12 @@ 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) {
|
|
154
|
+
entry.item.read = true
|
|
155
|
+
state.transcript = state.transcript.filter(item => item !== entry.item)
|
|
156
|
+
state.transcript.push(entry.item)
|
|
157
|
+
}
|
|
152
158
|
pushHistory(state, peerInputMessage(peer), eventId)
|
|
153
159
|
}
|
|
154
160
|
}
|
|
@@ -253,6 +259,7 @@ export function deriveState(events) {
|
|
|
253
259
|
const item = {
|
|
254
260
|
kind: 'peer', direction: peer.direction, from: peer.from, to: peer.to,
|
|
255
261
|
text: peer.message, urgent: peer.urgent ?? false, status: peer.status || 'unknown', messageId: peer.id,
|
|
262
|
+
...(peer.direction === 'incoming' ? { read: false } : {}),
|
|
256
263
|
eventId: event.id, at: event.at ?? null,
|
|
257
264
|
}
|
|
258
265
|
state.transcript.push(item)
|
|
@@ -278,6 +285,7 @@ export function deriveState(events) {
|
|
|
278
285
|
const restored = { ...item, eventId: event.id, at: item.at ?? event.at ?? null }
|
|
279
286
|
if (restored.kind === 'peer') {
|
|
280
287
|
const entry = state.peerMessages.get(restored.messageId)
|
|
288
|
+
if (entry?.peer.direction === 'incoming') continue
|
|
281
289
|
if (entry?.item) {
|
|
282
290
|
state.transcript = state.transcript.filter((candidate) => candidate !== entry.item)
|
|
283
291
|
Object.assign(restored, { status: entry.item.status, error: entry.item.error })
|
|
@@ -396,6 +404,9 @@ export function deriveState(events) {
|
|
|
396
404
|
state.pendingPeerMessages = [...state.peerMessages.values()]
|
|
397
405
|
.filter(({ peer }) => peer.direction === 'incoming' && !consumedPeerIds.has(peer.id))
|
|
398
406
|
.map(({ peer }) => peer)
|
|
407
|
+
const unread = state.transcript.filter(item => item.kind === 'peer' && item.direction === 'incoming' && !item.read)
|
|
408
|
+
const unreadItems = new Set(unread)
|
|
409
|
+
state.transcript = [...state.transcript.filter(item => !unreadItems.has(item)), ...unread]
|
|
399
410
|
state.estimatedPromptTokens = contextEdited && measuredBaseline
|
|
400
411
|
? Math.max(0, measuredBaseline.tokens + historyTokens() - measuredBaseline.history)
|
|
401
412
|
: null
|