@chroxy/server 0.11.10 → 0.11.11
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/CONFIG.md +4 -2
- package/package.json +3 -3
- package/src/acp-session.js +5 -1
- package/src/agent-connections.js +12 -1
- package/src/agent-control/client.js +29 -0
- package/src/agent-control/events.js +8 -4
- package/src/agent-control/local-connection.js +34 -16
- package/src/agent-control/mcp-server.js +2 -0
- package/src/anthropic-compatible-config.js +1 -0
- package/src/anthropic-gemini-shim.js +444 -0
- package/src/anthropic-gemini-translate.js +1030 -0
- package/src/base-session.js +319 -2
- package/src/bound-client-policy.js +12 -0
- package/src/byok-mcp-config.js +9 -5
- package/src/byok-mcp-trust.js +34 -20
- package/src/byok-session.js +62 -9
- package/src/byok-tool-executor.js +81 -1
- package/src/claude-setting-sources.js +74 -0
- package/src/claude-tui/pty-driver.js +5 -1
- package/src/claude-tui/usage-limit.js +2 -2
- package/src/claude-tui-session.js +57 -4
- package/src/cli/agent-cmd.js +236 -0
- package/src/cli/connection-state.js +54 -0
- package/src/cli/freshness-cmd.js +53 -0
- package/src/cli/pages-cmd.js +6 -4
- package/src/cli/pair-code-cmd.js +7 -6
- package/src/cli/pair-discord-cmd.js +7 -6
- package/src/cli/schedule-cmd.js +25 -3
- package/src/cli/server-cmd.js +6 -0
- package/src/cli/shell-cmd.js +7 -4
- package/src/cli/status-cmd.js +19 -5
- package/src/cli-session.js +190 -11
- package/src/cli.js +4 -0
- package/src/codex-app-server-session.js +78 -17
- package/src/codex-error-text.js +114 -0
- package/src/config-dir-migration.js +11 -6
- package/src/config.js +23 -3
- package/src/connection-info.js +73 -14
- package/src/continuations.js +153 -40
- package/src/conversation-scanner.js +2 -21
- package/src/conversation-search.js +4 -17
- package/src/dev-preview.js +2 -1
- package/src/docker-session.js +10 -1
- package/src/doctor.js +14 -3
- package/src/durable-write.js +35 -0
- package/src/environments/authority.js +7 -1
- package/src/event-normalizer.js +35 -2
- package/src/folder-trust-wire.js +137 -0
- package/src/folder-trust-worker.js +17 -0
- package/src/folder-trust.js +1572 -0
- package/src/freshness/activity-meter.js +101 -0
- package/src/freshness/adapter.js +199 -0
- package/src/freshness/checks.js +239 -0
- package/src/freshness/config.js +98 -0
- package/src/freshness/core.js +185 -0
- package/src/freshness/derive.js +680 -0
- package/src/freshness/exchange.js +305 -0
- package/src/freshness/file-ledger.js +400 -0
- package/src/freshness/grade.js +81 -0
- package/src/freshness/hash.js +45 -0
- package/src/freshness/inbox.js +163 -0
- package/src/freshness/index.js +20 -0
- package/src/freshness/investigation.js +474 -0
- package/src/freshness/keys.js +177 -0
- package/src/freshness/ledger.js +122 -0
- package/src/freshness/outbox.js +131 -0
- package/src/freshness/policy.js +599 -0
- package/src/freshness/queue.js +843 -0
- package/src/freshness/read-errors.js +23 -0
- package/src/freshness/render.js +153 -0
- package/src/freshness/runtime.js +113 -0
- package/src/freshness/session-registry-adapter.js +161 -0
- package/src/freshness/state-file-adapter.js +167 -0
- package/src/freshness-runner/build-info.js +139 -0
- package/src/freshness-runner/cli.js +105 -0
- package/src/freshness-runner/run-tick.js +109 -0
- package/src/freshness-runner/stamp.js +57 -0
- package/src/freshness-sources/claude-transcript-adapter.js +211 -0
- package/src/freshness-sources/codex-transcript-adapter.js +33 -0
- package/src/freshness-sources/index.js +8 -0
- package/src/gemini-byok-session.js +292 -0
- package/src/gemini-credentials.js +67 -0
- package/src/gemini-key-safety.js +246 -0
- package/src/gemini-models.js +386 -0
- package/src/handler-utils.js +6 -13
- package/src/handlers/checkpoint-handlers.js +8 -0
- package/src/handlers/folder-trust-handlers.js +90 -0
- package/src/handlers/input-handlers.js +40 -11
- package/src/handlers/principal-admin-handlers.js +229 -0
- package/src/handlers/principal-handlers.js +262 -0
- package/src/handlers/scheduler-handlers.js +4 -4
- package/src/handlers/session-handlers.js +10 -1
- package/src/handlers/settings-handlers.js +42 -8
- package/src/handlers/skills-handlers.js +7 -0
- package/src/history-page.js +8 -0
- package/src/jsonl-reader.js +90 -10
- package/src/jsonl-subprocess-session.js +4 -1
- package/src/logger.js +105 -15
- package/src/mailbox-route.js +102 -0
- package/src/notification-prefs.js +15 -0
- package/src/orchestration/orchestration-manager.js +38 -9
- package/src/orchestration/permission-gate.js +4 -1
- package/src/orchestration/run-record.js +11 -0
- package/src/orchestration/turn-driver.js +151 -33
- package/src/orphan-reaper.js +77 -20
- package/src/outgoing-policy.js +10 -4
- package/src/permission-floor.js +54 -2
- package/src/permission-manager.js +32 -13
- package/src/permission-resolved-by.js +89 -0
- package/src/permission-resolver.js +7 -3
- package/src/platform.js +156 -4
- package/src/principal-audit.js +189 -0
- package/src/principal-binding.js +25 -0
- package/src/principal-brakes.js +21 -0
- package/src/principal-effect.js +101 -0
- package/src/principal-journal.js +905 -0
- package/src/principal-kill-switch.js +183 -0
- package/src/principal-label.js +5 -0
- package/src/principal-pending-permissions.js +177 -0
- package/src/principal-policy.js +1094 -0
- package/src/principal-sessions-snapshot.js +208 -0
- package/src/principal-store.js +488 -0
- package/src/principal-subscriptions.js +283 -0
- package/src/providers.js +2 -0
- package/src/redaction.js +181 -22
- package/src/scheduled-task-store.js +12 -0
- package/src/scheduler.js +304 -17
- package/src/sdk-session.js +60 -7
- package/src/server-cli/push-notification-handler.js +6 -1
- package/src/server-cli.js +30 -1
- package/src/session-ci-watcher.js +210 -37
- package/src/session-manager.js +590 -19
- package/src/session-message-history.js +121 -2
- package/src/session-name-allocator.js +685 -0
- package/src/statusline.js +78 -19
- package/src/summarize-session.js +2 -0
- package/src/turn-outcome.js +5 -2
- package/src/utils/argv-safety.js +29 -0
- package/src/utils/binary-package-manifest.js +57 -15
- package/src/utils/bounded-regex-worker.js +4 -0
- package/src/utils/bounded-regex.js +16 -7
- package/src/utils/pid-liveness.js +47 -0
- package/src/web-task-manager.js +45 -4
- package/src/worktree-gc.js +195 -4
- package/src/ws-auth.js +103 -19
- package/src/ws-broadcaster.js +39 -7
- package/src/ws-client-manager.js +8 -0
- package/src/ws-file-ops/browser.js +35 -3
- package/src/ws-forwarding.js +23 -3
- package/src/ws-handler-context.js +18 -0
- package/src/ws-history.js +79 -12
- package/src/ws-message-handlers.js +10 -2
- package/src/ws-server.js +253 -13
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent principal's session roster snapshot (docs/security/agent-principals.md
|
|
3
|
+
* sections 4 and 7.3; #9120, S5 of #9112).
|
|
4
|
+
*
|
|
5
|
+
* `collectSessionsSnapshot` returns one minimal row per session asked about: its observed
|
|
6
|
+
* status, what the agent declared, which model the daemon resolved for it and which is running, and the
|
|
7
|
+
* reasons a handoff must not start from it right now (#8281).
|
|
8
|
+
*
|
|
9
|
+
* Every row is read from THAT session's own entry and from `getHandoffBlockers`. Nothing here
|
|
10
|
+
* calls `listSessions()`: it runs provider getters for EVERY session, so a session the
|
|
11
|
+
* principal is not granted could change (or break) the reply. The caller has already checked
|
|
12
|
+
* every id against the principal's grant; this module reads what it is told to and knows
|
|
13
|
+
* nothing about who is asking.
|
|
14
|
+
*
|
|
15
|
+
* - FAIL SAFE, never open. A row whose read throws still appears, with its unreadable fields
|
|
16
|
+
* null and `blockers: [{ code: 'unavailable' }]`. An EMPTY blocker list means "safe to hand
|
|
17
|
+
* off", so it is never what a failed read produces. Other rows are unaffected.
|
|
18
|
+
* - A session `getHandoffBlockers` does not know (`not_found`) is omitted.
|
|
19
|
+
* - Blockers are projected through a per-code detail whitelist (the same table the outgoing
|
|
20
|
+
* frame is rebuilt from, principal-policy.js). A code this module does not know is
|
|
21
|
+
* delivered as `{ code }` with no detail: it is still a blocker.
|
|
22
|
+
* - `leaseHolder` is always null here and is filled by S8 (leases), so the wire shape is
|
|
23
|
+
* stable. No cwd, history, cost, billing or capability field exists in a row.
|
|
24
|
+
* - Bounded: at most `PRINCIPAL_SESSIONS_SNAPSHOT_MAX` rows, in the order of `sessionIds`
|
|
25
|
+
* (the caller's order), with `truncated` when more existed.
|
|
26
|
+
*/
|
|
27
|
+
import { DeclaredStatusSchema } from '@chroxy/protocol'
|
|
28
|
+
import { busyStateOf } from './session-busy-state.js'
|
|
29
|
+
import { redactBounded } from './redaction.js'
|
|
30
|
+
import { PRINCIPAL_BLOCKER_DETAIL_FIELDS, PRINCIPAL_DECLARED_STATUS_FIELDS } from './principal-policy.js'
|
|
31
|
+
|
|
32
|
+
/** The most rows one reply carries (the protocol schema's `.max()`). */
|
|
33
|
+
export const PRINCIPAL_SESSIONS_SNAPSHOT_MAX = 100
|
|
34
|
+
|
|
35
|
+
const NAME_MAX = 200
|
|
36
|
+
const PROVIDER_MAX = 64
|
|
37
|
+
const MODEL_MAX = 200
|
|
38
|
+
const DECLARED_TEXT_MAX = 280
|
|
39
|
+
const BLOCKER_CODE_MAX = 64
|
|
40
|
+
const REQUEST_IDS_MAX = 100
|
|
41
|
+
const REQUEST_ID_MAX = 256
|
|
42
|
+
|
|
43
|
+
const UNAVAILABLE = Object.freeze({ code: 'unavailable' })
|
|
44
|
+
|
|
45
|
+
const redactedModel = (value) => {
|
|
46
|
+
if (typeof value !== 'string' || value.length === 0) return null
|
|
47
|
+
const text = redactBounded(value, MODEL_MAX)
|
|
48
|
+
return text.length > 0 ? text : null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const boundedString = (value, max) => (typeof value === 'string' && value.length > 0 ? value.slice(0, max) : null)
|
|
52
|
+
|
|
53
|
+
/** One blocker, projected through the detail whitelist. Anything that is not a blocker is `unavailable`. */
|
|
54
|
+
function projectBlocker(blocker) {
|
|
55
|
+
if (blocker === null || typeof blocker !== 'object' || typeof blocker.code !== 'string' || blocker.code.length === 0) {
|
|
56
|
+
return { ...UNAVAILABLE }
|
|
57
|
+
}
|
|
58
|
+
const out = { code: blocker.code.slice(0, BLOCKER_CODE_MAX) }
|
|
59
|
+
const spec = Object.hasOwn(PRINCIPAL_BLOCKER_DETAIL_FIELDS, blocker.code) ? PRINCIPAL_BLOCKER_DETAIL_FIELDS[blocker.code] : null
|
|
60
|
+
const detail = blocker.detail
|
|
61
|
+
if (spec === null || detail === null || typeof detail !== 'object') return out
|
|
62
|
+
const kept = {}
|
|
63
|
+
for (const [field, kind] of Object.entries(spec)) {
|
|
64
|
+
const value = detail[field]
|
|
65
|
+
if (kind === 'count') {
|
|
66
|
+
if (Number.isSafeInteger(value) && value >= 0) kept[field] = value
|
|
67
|
+
} else if (kind === 'bool') {
|
|
68
|
+
if (typeof value === 'boolean') kept[field] = value
|
|
69
|
+
} else if (kind === 'string') {
|
|
70
|
+
if (typeof value === 'string' && value.length > 0) kept[field] = value.slice(0, REQUEST_ID_MAX)
|
|
71
|
+
} else if (kind === 'strings') {
|
|
72
|
+
if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {
|
|
73
|
+
kept[field] = value.slice(0, REQUEST_IDS_MAX).map((v) => v.slice(0, REQUEST_ID_MAX))
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (Object.keys(kept).length > 0) out.detail = kept
|
|
78
|
+
return out
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The declared status of an entry, validated against the daemon's own schema and with its
|
|
83
|
+
* free text redacted, or null when there is none (or it does not validate: nothing unvalidated
|
|
84
|
+
* is relayed).
|
|
85
|
+
*/
|
|
86
|
+
function projectDeclaredStatus(declared) {
|
|
87
|
+
if (declared === undefined || declared === null) return null
|
|
88
|
+
const parsed = DeclaredStatusSchema.safeParse(declared)
|
|
89
|
+
if (!parsed.success) return null
|
|
90
|
+
const out = {}
|
|
91
|
+
for (const key of Object.keys(PRINCIPAL_DECLARED_STATUS_FIELDS)) {
|
|
92
|
+
const value = parsed.data[key]
|
|
93
|
+
if (value === undefined) continue
|
|
94
|
+
if (typeof value === 'string' && key !== 'state' && key !== 'source') {
|
|
95
|
+
const text = redactBounded(value, DECLARED_TEXT_MAX)
|
|
96
|
+
if (text.length > 0) out[key] = text
|
|
97
|
+
} else {
|
|
98
|
+
out[key] = value
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return out
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* One row, or null when the session is not there. Every read of the session is guarded: one
|
|
106
|
+
* that throws marks the row `unavailable` and leaves the others untouched.
|
|
107
|
+
*/
|
|
108
|
+
function buildRow(sessionId, sessionManager, evaluatorPending) {
|
|
109
|
+
let failed = false
|
|
110
|
+
const read = (fn, fallback = null) => {
|
|
111
|
+
try { return fn() } catch { failed = true; return fallback }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let entry
|
|
115
|
+
try {
|
|
116
|
+
entry = typeof sessionManager?.getSession === 'function' ? sessionManager.getSession(sessionId) : null
|
|
117
|
+
} catch {
|
|
118
|
+
// The entry itself cannot be read: the session is there (the grant check saw it), its row is not.
|
|
119
|
+
return {
|
|
120
|
+
sessionId, name: null, provider: null, status: null, declaredStatus: null, model: null,
|
|
121
|
+
blockers: [{ ...UNAVAILABLE }], leaseHolder: null, lastActivityAt: null,
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (entry === null || entry === undefined) return null
|
|
125
|
+
|
|
126
|
+
// `evaluatorPending` is WS-layer state the accessor cannot see (its own doc says the
|
|
127
|
+
// caller must pass it); it is asked per session, and a failure to ask is a failed read.
|
|
128
|
+
const evaluatorFlag = read(() => evaluatorPending(sessionId) === true)
|
|
129
|
+
// The WHOLE inspection of the accessor's answer is guarded, not just the call: a blocker
|
|
130
|
+
// with a throwing getter must mark this row unavailable, never fail the snapshot. Two
|
|
131
|
+
// things SessionManager.getHandoffBlockers answers with "[]" (no session object, a provider
|
|
132
|
+
// without the accessor) are not "nothing blocks": it could not ask, so it is a failed read.
|
|
133
|
+
let notFound = false
|
|
134
|
+
const blockers = read(() => {
|
|
135
|
+
const rawBlockers = sessionManager.getHandoffBlockers(sessionId, { evaluatorPending: evaluatorFlag === true })
|
|
136
|
+
if (!Array.isArray(rawBlockers)) throw new Error('not a list')
|
|
137
|
+
if (rawBlockers.length === 1 && rawBlockers[0]?.code === 'not_found') { notFound = true; return null }
|
|
138
|
+
if (entry.session == null || typeof entry.session.getHandoffBlockers !== 'function') throw new Error('no accessor')
|
|
139
|
+
const projected = rawBlockers.map(projectBlocker)
|
|
140
|
+
// A provider may report ready before its async start settles: a starting session is not ready.
|
|
141
|
+
if (entry._starting === true && !projected.some((b) => b.code === 'not_ready')) projected.push({ code: 'not_ready' })
|
|
142
|
+
return projected
|
|
143
|
+
})
|
|
144
|
+
if (notFound) return null
|
|
145
|
+
|
|
146
|
+
const session = entry.session
|
|
147
|
+
const status = read(() => {
|
|
148
|
+
const busy = busyStateOf(session)
|
|
149
|
+
return {
|
|
150
|
+
isBusy: busy.busyReason !== null,
|
|
151
|
+
busyReason: busy.busyReason,
|
|
152
|
+
starting: entry._starting === true,
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
const model = read(() => ({
|
|
156
|
+
// `requested` is the model the daemon resolved for the session (at create, or the last
|
|
157
|
+
// model switch), so it includes an applied daemon default; null only when none was
|
|
158
|
+
// resolved. An explicit override cannot be told from an applied default yet. `observed`
|
|
159
|
+
// is what is running. Both are free text: redacted, then bounded.
|
|
160
|
+
requested: redactedModel(session?.model),
|
|
161
|
+
observed: redactedModel(session?.bootedModel),
|
|
162
|
+
}))
|
|
163
|
+
const name = read(() => (typeof entry.name === 'string' ? redactBounded(entry.name, NAME_MAX) : null))
|
|
164
|
+
const provider = read(() => boundedString(entry.provider || sessionManager.providerType, PROVIDER_MAX))
|
|
165
|
+
const declaredStatus = read(() => projectDeclaredStatus(entry.declaredStatus))
|
|
166
|
+
const activity = read(() => (typeof sessionManager.getLastActivityAt === 'function' ? sessionManager.getLastActivityAt(sessionId) : null))
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
sessionId,
|
|
170
|
+
name,
|
|
171
|
+
provider,
|
|
172
|
+
status,
|
|
173
|
+
declaredStatus,
|
|
174
|
+
model,
|
|
175
|
+
// An empty list means "safe to hand off": a failed read must never produce one.
|
|
176
|
+
blockers: failed || blockers === null ? [{ ...UNAVAILABLE }] : blockers,
|
|
177
|
+
leaseHolder: null, // filled by S8 (leases)
|
|
178
|
+
lastActivityAt: Number.isFinite(activity) && activity >= 0 ? Math.trunc(activity) : null,
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @param {object} opts
|
|
184
|
+
* @param {string[]} opts.sessionIds granted, de-duplicated session ids, in reply order
|
|
185
|
+
* @param {object|null} opts.sessionManager needs `getSession`, `getHandoffBlockers`
|
|
186
|
+
* @param {(sessionId: string) => boolean} opts.evaluatorPending does the prompt evaluator hold this session's draft
|
|
187
|
+
* @param {number} [opts.now]
|
|
188
|
+
* @param {number} [opts.max]
|
|
189
|
+
* @returns {{ generatedAt: number, sessions: object[], truncated: boolean }}
|
|
190
|
+
*/
|
|
191
|
+
export function collectSessionsSnapshot({
|
|
192
|
+
sessionIds, sessionManager, evaluatorPending, now = Date.now(), max = PRINCIPAL_SESSIONS_SNAPSHOT_MAX,
|
|
193
|
+
}) {
|
|
194
|
+
const sessions = []
|
|
195
|
+
let truncated = false
|
|
196
|
+
for (const sessionId of sessionIds) {
|
|
197
|
+
if (sessions.length >= max) {
|
|
198
|
+
// Past the cap only existence is asked, so a further row is never built.
|
|
199
|
+
let present = false
|
|
200
|
+
try { present = sessionManager?.getSession?.(sessionId) != null } catch { present = true }
|
|
201
|
+
if (present) { truncated = true; break }
|
|
202
|
+
continue
|
|
203
|
+
}
|
|
204
|
+
const row = buildRow(sessionId, sessionManager, evaluatorPending)
|
|
205
|
+
if (row !== null) sessions.push(row)
|
|
206
|
+
}
|
|
207
|
+
return { generatedAt: now, sessions, truncated }
|
|
208
|
+
}
|