picocode-core 0.9.194 → 0.9.196
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 +4 -2
- package/src/codex-models.js +4 -1
- package/src/controller.js +43 -11
- package/src/derive.js +14 -2
- package/src/stream-transcript.js +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "picocode-core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.196",
|
|
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.10.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
|
@@ -58,10 +58,11 @@ export function compactionHistory(history, prompt) {
|
|
|
58
58
|
return hydrateImages([...history.filter((m) => m.role !== 'system'), { role: 'user', content: prompt }])
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
export async function compactHistory({ history, modelName, auth, prompt, signal, onStream }) {
|
|
61
|
+
export async function compactHistory({ history, modelName, speed, auth, prompt, signal, onStream }) {
|
|
62
62
|
const out = await compose(
|
|
63
63
|
model({
|
|
64
64
|
model: modelName,
|
|
65
|
+
...(speed && { speed }),
|
|
65
66
|
...(auth?.apiKey && { apiKey: auth.apiKey }),
|
|
66
67
|
...(auth?.headers && { headers: auth.headers }),
|
|
67
68
|
}),
|
|
@@ -102,7 +103,7 @@ function estimateTokens(value) {
|
|
|
102
103
|
return Math.ceil(JSON.stringify(value ?? '').length / 4)
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
export async function runTurn({ history, tools, recorder, modelName, effort, auth, system, signal, onStream, beforeRequest, stallMs = STALL_MS }) {
|
|
106
|
+
export async function runTurn({ history, tools, recorder, modelName, effort, speed, auth, system, signal, onStream, beforeRequest, stallMs = STALL_MS }) {
|
|
106
107
|
const collected = []
|
|
107
108
|
let roundText = ''
|
|
108
109
|
let usageSeen = null
|
|
@@ -201,6 +202,7 @@ export async function runTurn({ history, tools, recorder, modelName, effort, aut
|
|
|
201
202
|
return { ...request, history: [...request.history, ...messages] }
|
|
202
203
|
},
|
|
203
204
|
...(effort && { effort }),
|
|
205
|
+
...(speed && { speed }),
|
|
204
206
|
...(auth?.apiKey && { apiKey: auth.apiKey }),
|
|
205
207
|
...(auth?.headers && { headers: auth.headers }),
|
|
206
208
|
})({ ...ctx, history: hydratedHistory, abortSignal: internal.signal })
|
package/src/codex-models.js
CHANGED
|
@@ -18,6 +18,7 @@ export function mapCodexModels(entries) {
|
|
|
18
18
|
desc: `${m.description || m.label || m.slug} · via ChatGPT plan`,
|
|
19
19
|
price: null,
|
|
20
20
|
effort: true,
|
|
21
|
+
speed: (m.service_tiers || []).some(tier => ['priority', 'fast'].includes(tier.id)) || (m.additional_speed_tiers || []).includes('fast'),
|
|
21
22
|
context: m.context_window || null,
|
|
22
23
|
}))
|
|
23
24
|
}
|
|
@@ -27,7 +28,7 @@ export async function loadCodexModels(credentials, { force = false, fetcher = fe
|
|
|
27
28
|
try {
|
|
28
29
|
cached = JSON.parse(await readFile(cacheFile(), 'utf-8'))
|
|
29
30
|
} catch {}
|
|
30
|
-
if (!force && cached && Date.now() - cached.at < TTL) return mapCodexModels(cached.models)
|
|
31
|
+
if (!force && cached && Date.now() - cached.at < TTL && cached.models.every(model => Array.isArray(model.service_tiers) || Array.isArray(model.additional_speed_tiers))) return mapCodexModels(cached.models)
|
|
31
32
|
if (!credentials) return mapCodexModels(cached?.models || [])
|
|
32
33
|
|
|
33
34
|
try {
|
|
@@ -42,6 +43,8 @@ export async function loadCodexModels(credentials, { force = false, fetcher = fe
|
|
|
42
43
|
const data = await response.json()
|
|
43
44
|
const models = (data.models || []).map((m) => ({
|
|
44
45
|
slug: m.slug,
|
|
46
|
+
service_tiers: m.service_tiers || [],
|
|
47
|
+
additional_speed_tiers: m.additional_speed_tiers || [],
|
|
45
48
|
description: m.description,
|
|
46
49
|
label: m.label || m.display_name,
|
|
47
50
|
context_window: m.context_window || m.max_context_window || null,
|
package/src/controller.js
CHANGED
|
@@ -11,7 +11,6 @@ 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'
|
|
15
14
|
import { runDeliberation, validateDeliberation } from './deliberation.js'
|
|
16
15
|
import { deliberationsFromEvents } from './deliberation-history.js'
|
|
17
16
|
import { compactionPrompt, formatCompactSummary, summarySections, compactionKeepFrom } from './compaction.js'
|
|
@@ -37,6 +36,11 @@ import { MAX_DELIBERATION_ROUNDS } from './deliberation.js'
|
|
|
37
36
|
import { buildUserContent, finalizeUserContent, inputTextFromContent, mediaTypeFor, stashImages } from './attachments.js'
|
|
38
37
|
import { settlePending } from './pending.js'
|
|
39
38
|
|
|
39
|
+
export const SPEED_LEVELS = [
|
|
40
|
+
{ key: 'standard', usage: '1x usage' },
|
|
41
|
+
{ key: 'fast', usage: '2.5x usage' },
|
|
42
|
+
]
|
|
43
|
+
|
|
40
44
|
export const EFFORT_LEVELS = [
|
|
41
45
|
{ key: null, desc: 'let the provider decide how much to think' },
|
|
42
46
|
{ key: 'low', desc: 'quick answers, minimal thinking' },
|
|
@@ -115,6 +119,8 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
115
119
|
defaultModel: boot.initialModel,
|
|
116
120
|
effort: boot.initialEffort,
|
|
117
121
|
defaultEffort: boot.initialEffort,
|
|
122
|
+
speedDefaults: { ...boot.speedDefaults },
|
|
123
|
+
speed: boot.speedDefaults?.[boot.initialModel.name] === 'fast' ? 'fast' : 'standard',
|
|
118
124
|
busy: false,
|
|
119
125
|
compacting: false,
|
|
120
126
|
compactOutcome: null,
|
|
@@ -205,11 +211,11 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
205
211
|
state.events.push(event)
|
|
206
212
|
state.persisted = state.events.length
|
|
207
213
|
reDerive()
|
|
208
|
-
if (state.busy && !state.compacting) {
|
|
214
|
+
if (state.busy && !state.compacting && direction === 'outgoing') {
|
|
209
215
|
const items = [...state.overlay]
|
|
210
|
-
|
|
216
|
+
flushStream(items)
|
|
211
217
|
const item = state.derived.transcript.findLast((item) => item.kind === 'peer' && item.messageId === message.id)
|
|
212
|
-
items.push(
|
|
218
|
+
items.push(item)
|
|
213
219
|
set({ overlay: items })
|
|
214
220
|
}
|
|
215
221
|
})()
|
|
@@ -294,6 +300,9 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
294
300
|
// by file needs to hear about it
|
|
295
301
|
emit('session', state.session)
|
|
296
302
|
}
|
|
303
|
+
if (!state.events.some(event => event.type === 'speed')) {
|
|
304
|
+
state.events.push(makeEvent('speed', { to: state.speed }))
|
|
305
|
+
}
|
|
297
306
|
while (state.persisted < state.events.length) {
|
|
298
307
|
state.session.append(state.events[state.persisted])
|
|
299
308
|
state.persisted++
|
|
@@ -302,10 +311,6 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
302
311
|
|
|
303
312
|
function reDerive() {
|
|
304
313
|
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)
|
|
309
314
|
emit('derived', state.derived)
|
|
310
315
|
changed()
|
|
311
316
|
}
|
|
@@ -355,6 +360,7 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
355
360
|
recorder,
|
|
356
361
|
modelName: worker.name,
|
|
357
362
|
effort: worker.effort ? 'low' : null,
|
|
363
|
+
...(worker.provider === 'codex' && { speed: 'standard' }),
|
|
358
364
|
auth,
|
|
359
365
|
system: context.system,
|
|
360
366
|
signal,
|
|
@@ -426,6 +432,7 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
426
432
|
recorder: toolset.recorder,
|
|
427
433
|
modelName: roleWorkers[role].name,
|
|
428
434
|
effort: roleWorkers[role].effort ? 'low' : null,
|
|
435
|
+
...(roleWorkers[role].provider === 'codex' && { speed: 'standard' }),
|
|
429
436
|
auth: roleAuths[role],
|
|
430
437
|
system: context.system,
|
|
431
438
|
signal: workerSignal,
|
|
@@ -545,8 +552,7 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
545
552
|
}
|
|
546
553
|
|
|
547
554
|
function flushStream(items) {
|
|
548
|
-
|
|
549
|
-
items.splice(0, items.length, ...flushed)
|
|
555
|
+
if (state.streaming) items.push({ kind: 'assistant', text: state.streaming })
|
|
550
556
|
state.streaming = null
|
|
551
557
|
}
|
|
552
558
|
|
|
@@ -612,6 +618,7 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
612
618
|
const raw = await compactHistory({
|
|
613
619
|
history: current.providerHistory,
|
|
614
620
|
modelName: state.model.name,
|
|
621
|
+
...(state.model.provider === 'codex' && { speed: speedApplies() ? state.speed : 'standard' }),
|
|
615
622
|
auth,
|
|
616
623
|
prompt: compactionPrompt(instructions),
|
|
617
624
|
signal: controller.signal,
|
|
@@ -834,6 +841,7 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
834
841
|
recorder,
|
|
835
842
|
modelName: state.model.name,
|
|
836
843
|
effort: effortApplies() ? state.effort ?? 'auto' : null,
|
|
844
|
+
...(state.model.provider === 'codex' && { speed: speedApplies() ? state.speed : 'standard' }),
|
|
837
845
|
auth,
|
|
838
846
|
system: context.system,
|
|
839
847
|
signal: controller.signal,
|
|
@@ -952,7 +960,7 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
952
960
|
set({ queued: [...state.expedited, ...state.queued], expedited: [] })
|
|
953
961
|
}
|
|
954
962
|
|
|
955
|
-
function resetConversation({ model, effort } = {}) {
|
|
963
|
+
function resetConversation({ model, effort, speed } = {}) {
|
|
956
964
|
state.session = null
|
|
957
965
|
state.events = []
|
|
958
966
|
state.persisted = 0
|
|
@@ -964,6 +972,7 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
964
972
|
state.peerPaused = false
|
|
965
973
|
state.model = model ?? state.defaultModel
|
|
966
974
|
state.effort = effort === undefined ? state.defaultEffort : effort
|
|
975
|
+
state.speed = speed ?? defaultSpeed(state.model)
|
|
967
976
|
}
|
|
968
977
|
|
|
969
978
|
async function newSession() {
|
|
@@ -1198,6 +1207,7 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
1198
1207
|
reDerive()
|
|
1199
1208
|
restoreModelFromSession()
|
|
1200
1209
|
state.effort = state.derived.effort === undefined ? state.defaultEffort : state.derived.effort
|
|
1210
|
+
state.speed = state.derived.speed ?? 'standard'
|
|
1201
1211
|
state.sent = userEntries(state.derived).map((e) => ({ text: recallText(e), at: header.createdAt }))
|
|
1202
1212
|
changed()
|
|
1203
1213
|
emit('session', state.session)
|
|
@@ -1325,6 +1335,8 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
1325
1335
|
}
|
|
1326
1336
|
persist(makeEvent('model_switch', { from: state.model.name, to: pick.name }))
|
|
1327
1337
|
state.model = pick
|
|
1338
|
+
state.speed = defaultSpeed(pick)
|
|
1339
|
+
persist(makeEvent('speed', { to: state.speed }))
|
|
1328
1340
|
if (asDefault) {
|
|
1329
1341
|
state.defaultModel = pick
|
|
1330
1342
|
writeConfig({ defaultModel: pick.name }).catch(() => {})
|
|
@@ -1341,6 +1353,23 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
1341
1353
|
switchModel(pick, { note: adhoc ? ' (not in catalog, pricing unknown)' : '' })
|
|
1342
1354
|
}
|
|
1343
1355
|
|
|
1356
|
+
const defaultSpeed = model => state.speedDefaults[model.name] === 'fast' ? 'fast' : 'standard'
|
|
1357
|
+
const speedApplies = () => state.model.provider === 'codex' && !!state.model.speed
|
|
1358
|
+
|
|
1359
|
+
function applySpeed(next, { asDefault = false } = {}) {
|
|
1360
|
+
if (!speedApplies()) return flash(`${state.model.name} does not support Fast mode`)
|
|
1361
|
+
if (!SPEED_LEVELS.some(level => level.key === next)) return flash('usage: /speed <standard|fast>')
|
|
1362
|
+
persist(makeEvent('speed', { to: next }))
|
|
1363
|
+
state.speed = next
|
|
1364
|
+
if (asDefault) {
|
|
1365
|
+
state.speedDefaults[state.model.name] = next
|
|
1366
|
+
writeConfig({ speedDefaults: { [state.model.name]: next } }).catch(error => flash(`speed default failed: ${errorText(error, 80)}`))
|
|
1367
|
+
}
|
|
1368
|
+
changed()
|
|
1369
|
+
flash(`speed: ${next}`)
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
const speedCommand = arg => applySpeed(arg.toLowerCase())
|
|
1344
1373
|
const effortApplies = () => !!state.model.effort
|
|
1345
1374
|
|
|
1346
1375
|
function setEffort(next, { asDefault = false } = {}) {
|
|
@@ -1720,6 +1749,9 @@ export function createController({ boot, run = runTurn, peerDirectory } = {}) {
|
|
|
1720
1749
|
resolveModel,
|
|
1721
1750
|
switchModel,
|
|
1722
1751
|
switchModelByName,
|
|
1752
|
+
speedApplies,
|
|
1753
|
+
applySpeed,
|
|
1754
|
+
speedCommand,
|
|
1723
1755
|
effortApplies,
|
|
1724
1756
|
setEffort,
|
|
1725
1757
|
setEffortByName,
|
package/src/derive.js
CHANGED
|
@@ -150,7 +150,11 @@ function flushConsumedPeers(state) {
|
|
|
150
150
|
if (state.openToolCalls.size) return
|
|
151
151
|
for (const { peer, eventId } of state.deferredConsumedPeers.splice(0)) {
|
|
152
152
|
const entry = state.peerMessages.get(peer.id)
|
|
153
|
-
if (entry?.item)
|
|
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
|
+
}
|
|
154
158
|
pushHistory(state, peerInputMessage(peer), eventId)
|
|
155
159
|
}
|
|
156
160
|
}
|
|
@@ -192,6 +196,7 @@ export function deriveState(events) {
|
|
|
192
196
|
historyEventIds: [],
|
|
193
197
|
model: null,
|
|
194
198
|
effort: undefined,
|
|
199
|
+
speed: undefined,
|
|
195
200
|
usage: spentUsage,
|
|
196
201
|
usageByModel: spentUsageByModel,
|
|
197
202
|
usageActive: emptyUsage(),
|
|
@@ -281,9 +286,10 @@ export function deriveState(events) {
|
|
|
281
286
|
const restored = { ...item, eventId: event.id, at: item.at ?? event.at ?? null }
|
|
282
287
|
if (restored.kind === 'peer') {
|
|
283
288
|
const entry = state.peerMessages.get(restored.messageId)
|
|
289
|
+
if (entry?.peer.direction === 'incoming') continue
|
|
284
290
|
if (entry?.item) {
|
|
285
291
|
state.transcript = state.transcript.filter((candidate) => candidate !== entry.item)
|
|
286
|
-
Object.assign(restored, { status: entry.item.status, error: entry.item.error
|
|
292
|
+
Object.assign(restored, { status: entry.item.status, error: entry.item.error })
|
|
287
293
|
entry.item = restored
|
|
288
294
|
}
|
|
289
295
|
}
|
|
@@ -305,6 +311,9 @@ export function deriveState(events) {
|
|
|
305
311
|
case 'model_switch':
|
|
306
312
|
state.model = event.data.to
|
|
307
313
|
break
|
|
314
|
+
case 'speed':
|
|
315
|
+
state.speed = event.data.to
|
|
316
|
+
break
|
|
308
317
|
case 'effort':
|
|
309
318
|
state.effort = event.data.to
|
|
310
319
|
break
|
|
@@ -399,6 +408,9 @@ export function deriveState(events) {
|
|
|
399
408
|
state.pendingPeerMessages = [...state.peerMessages.values()]
|
|
400
409
|
.filter(({ peer }) => peer.direction === 'incoming' && !consumedPeerIds.has(peer.id))
|
|
401
410
|
.map(({ peer }) => peer)
|
|
411
|
+
const unread = state.transcript.filter(item => item.kind === 'peer' && item.direction === 'incoming' && !item.read)
|
|
412
|
+
const unreadItems = new Set(unread)
|
|
413
|
+
state.transcript = [...state.transcript.filter(item => !unreadItems.has(item)), ...unread]
|
|
402
414
|
state.estimatedPromptTokens = contextEdited && measuredBaseline
|
|
403
415
|
? Math.max(0, measuredBaseline.tokens + historyTokens() - measuredBaseline.history)
|
|
404
416
|
: null
|
package/src/stream-transcript.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
}
|