moi-computer 0.5.2-next.1 → 0.6.0
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/client/AGENTS.md +9 -0
- package/client/api/app-ui-keys.ts +4 -0
- package/client/api/workspace-keys.ts +2 -2
- package/client/app/routes/WorkspaceRoute.tsx +8 -28
- package/client/components/shared/Composer.tsx +3 -6
- package/client/components/shared/IconGhost.tsx +130 -0
- package/client/components/ui/dropdown-menu.tsx +1 -1
- package/client/components/ui/spinner.tsx +18 -0
- package/client/components/ui/toast.tsx +220 -0
- package/client/features/chat/ChatComposer.tsx +3 -2
- package/client/features/chat/ChatPanel.tsx +7 -6
- package/client/features/chat/ChatPopup.tsx +10 -4
- package/client/features/chat/ChatSelector.tsx +263 -48
- package/client/features/chat/ModelPicker.tsx +13 -18
- package/client/features/chat/api.ts +36 -9
- package/client/features/chat/chat-frames.ts +35 -6
- package/client/features/chat/chat-send.ts +25 -1
- package/client/features/chat/chat-store.ts +43 -18
- package/client/features/chat/useChat.ts +54 -52
- package/client/features/chat/useSelectedSession.ts +151 -0
- package/client/features/chat/useStickToBottom.ts +3 -3
- package/client/features/home/api.ts +0 -2
- package/client/features/scratchpad/ScratchpadControls.tsx +2 -2
- package/client/features/settings/WorkspaceSettings.tsx +6 -6
- package/client/features/views/ViewBuilderTab.tsx +3 -4
- package/client/features/views/useViewBuilderActions.ts +3 -1
- package/client/features/workspace/WorkspaceScreen.tsx +38 -18
- package/client/features/workspace/WorkspaceTabs.tsx +10 -1
- package/client/main.tsx +2 -0
- package/client/runtime/useWorkspaceEvents.ts +1 -0
- package/client/store/ui.ts +2 -2
- package/dist/{chunk-zs4mte79.js → chunk-0pcdwjkp.js} +1 -1
- package/dist/chunk-55sh4dty.js +2 -0
- package/dist/{chunk-tzz101ea.js → chunk-9y2zbzqz.js} +1 -1
- package/dist/{chunk-jvhvme3z.js → chunk-afgbg75t.js} +1 -1
- package/dist/chunk-agtetn7n.css +1 -0
- package/dist/chunk-bv6vrvqf.js +27 -0
- package/dist/chunk-dfs36zgc.js +1 -0
- package/dist/chunk-exj6hr30.js +9 -0
- package/dist/{chunk-bcrkdhwe.js → chunk-m11ckkxd.js} +1 -1
- package/dist/{chunk-xwhya7kb.js → chunk-n6t40enm.js} +1 -1
- package/dist/{chunk-kfw1qwqe.js → chunk-rxvx4ta9.js} +3 -3
- package/dist/index.html +1 -1
- package/lib/attachment-note.ts +18 -0
- package/lib/chat-title.ts +6 -0
- package/lib/types.ts +24 -10
- package/package.json +1 -1
- package/server/api.ts +90 -9
- package/server/app-settings.ts +1 -1
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +6 -0
- package/server/harness/claude-code/adapter.ts +2 -2
- package/server/harness/claude-code/index.ts +7 -1
- package/server/harness/claude-code/session-title.ts +106 -0
- package/server/harness/claude-code/session.ts +87 -13
- package/server/harness/claude-code/sessions.ts +35 -4
- package/server/harness/codex/client.ts +30 -12
- package/server/harness/codex/index.ts +2 -0
- package/server/harness/codex/session-title.ts +149 -0
- package/server/harness/codex/session.ts +84 -11
- package/server/harness/openclaw/adapter.ts +4 -2
- package/server/harness/openclaw/discovery.ts +2 -0
- package/server/harness/openclaw/session.ts +15 -7
- package/server/harness/session-title.ts +96 -0
- package/server/harness/types.ts +2 -0
- package/server/selected-session.ts +132 -0
- package/server/{thread-config.ts → session-config.ts} +57 -39
- package/server/web.ts +12 -1
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +16 -26
- package/workspace/.claude/skills/moi-workspace/SKILL.md +8 -2
- package/dist/chunk-94m3q9ce.js +0 -1
- package/dist/chunk-k9dcnd73.js +0 -27
- package/dist/chunk-pk11vfzs.js +0 -9
- package/dist/chunk-r2bqaege.js +0 -2
- package/dist/chunk-y4g8j7mv.css +0 -1
package/dist/index.html
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
</script>
|
|
23
23
|
|
|
24
|
-
<link rel="stylesheet" crossorigin href="/chunk-
|
|
24
|
+
<link rel="stylesheet" crossorigin href="/chunk-agtetn7n.css"><script type="module" crossorigin src="/chunk-n6t40enm.js"></script></head>
|
|
25
25
|
<body>
|
|
26
26
|
<div id="root"></div>
|
|
27
27
|
|
package/lib/attachment-note.ts
CHANGED
|
@@ -16,6 +16,24 @@ export const ATTACHMENT_ONLY_PLACEHOLDER = '(see attached files)'
|
|
|
16
16
|
|
|
17
17
|
export type AttachmentNoteFile = { filename: string; path: string }
|
|
18
18
|
|
|
19
|
+
export function attachmentOnlyPlaceholder(filenames: readonly string[]): string {
|
|
20
|
+
return filenames.length > 0
|
|
21
|
+
? `${ATTACHMENT_ONLY_PLACEHOLDER} ${filenames.join(', ')}`
|
|
22
|
+
: ATTACHMENT_ONLY_PLACEHOLDER
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function attachmentOnlyFilenames(text: string): string[] {
|
|
26
|
+
if (!text.startsWith(`${ATTACHMENT_ONLY_PLACEHOLDER} `)) return []
|
|
27
|
+
return text
|
|
28
|
+
.slice(ATTACHMENT_ONLY_PLACEHOLDER.length + 1)
|
|
29
|
+
.split(', ')
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function isAttachmentOnlyPlaceholder(text: string): boolean {
|
|
34
|
+
return text === ATTACHMENT_ONLY_PLACEHOLDER || text.startsWith(`${ATTACHMENT_ONLY_PLACEHOLDER} `)
|
|
35
|
+
}
|
|
36
|
+
|
|
19
37
|
// `text` plus the note listing each attachment as `- <filename>: <path>`.
|
|
20
38
|
// Filenames are sanitized at upload time (no colons/newlines), so the line
|
|
21
39
|
// format is unambiguous for `splitAttachmentNote`.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const MAX_CHAT_TITLE_LENGTH = 64
|
|
2
|
+
|
|
3
|
+
export function formatChatTitle(text: string, filenames: readonly string[] = []): string {
|
|
4
|
+
const source = text.trim() || filenames.filter(Boolean).join(', ')
|
|
5
|
+
return source.replace(/\s+/gu, ' ').trim().slice(0, MAX_CHAT_TITLE_LENGTH).trimEnd()
|
|
6
|
+
}
|
package/lib/types.ts
CHANGED
|
@@ -258,17 +258,21 @@ export type SessionInfo = {
|
|
|
258
258
|
cwd?: string
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
// Per-
|
|
261
|
+
// Per-session agent settings, persisted server-side in one global file in moi's
|
|
262
262
|
// data dir (NOT in the workspace), exposed via GET/PUT
|
|
263
|
-
// /api/workspaces/:id/sessions/:sessionId/config. A
|
|
264
|
-
// model/effort/Fast mode it last ran with; a brand-new
|
|
263
|
+
// /api/workspaces/:id/sessions/:sessionId/config. A session reopens with the same
|
|
264
|
+
// model/effort/Fast mode it last ran with; a brand-new session is seeded from the
|
|
265
265
|
// corresponding workspace defaults.
|
|
266
|
-
export type
|
|
266
|
+
export type SessionConfig = {
|
|
267
267
|
model?: string
|
|
268
268
|
effort?: string
|
|
269
269
|
fastMode?: boolean
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
+
export type SelectedSessionState = {
|
|
273
|
+
sessionId: string | null
|
|
274
|
+
}
|
|
275
|
+
|
|
272
276
|
// App-wide settings, persisted server-side as `settings.json` in moi's data
|
|
273
277
|
// dir and exposed via GET/PATCH /api/settings. Every key has a default, so
|
|
274
278
|
// GET always returns a complete object.
|
|
@@ -308,6 +312,7 @@ export type ServerMessage =
|
|
|
308
312
|
| PreviewFrame
|
|
309
313
|
| StatusMessage
|
|
310
314
|
| SessionRenamedMessage
|
|
315
|
+
| SessionsChangedMessage
|
|
311
316
|
| WorkspaceSwitchMessage
|
|
312
317
|
| ErrorFrame
|
|
313
318
|
| StoppedFrame
|
|
@@ -351,6 +356,7 @@ export type BroadcastFrame =
|
|
|
351
356
|
| Omit<PreviewFrame, 'workspaceId'>
|
|
352
357
|
| Omit<StatusMessage, 'workspaceId'>
|
|
353
358
|
| Omit<SessionRenamedMessage, 'workspaceId'>
|
|
359
|
+
| Omit<SessionsChangedMessage, 'workspaceId'>
|
|
354
360
|
| Omit<ErrorFrame, 'workspaceId'>
|
|
355
361
|
| Omit<StoppedFrame, 'workspaceId'>
|
|
356
362
|
|
|
@@ -437,6 +443,12 @@ export type SessionRenamedMessage = {
|
|
|
437
443
|
to: string
|
|
438
444
|
}
|
|
439
445
|
|
|
446
|
+
export type SessionsChangedMessage = {
|
|
447
|
+
type: 'sessions_changed'
|
|
448
|
+
workspaceId: string
|
|
449
|
+
sessionId: string
|
|
450
|
+
}
|
|
451
|
+
|
|
440
452
|
export type ErrorFrame = {
|
|
441
453
|
kind: 'error'
|
|
442
454
|
workspaceId: string
|
|
@@ -513,13 +525,13 @@ export type WorkspaceLayout = {
|
|
|
513
525
|
// doesn't map back to these aliases — hence we persist the pick here.
|
|
514
526
|
//
|
|
515
527
|
// This (with `selectedEffort` and `selectedFastMode`) is the *workspace
|
|
516
|
-
// default*: the value the picker edits when no
|
|
517
|
-
// brand-new
|
|
518
|
-
// override (see `
|
|
528
|
+
// default*: the value the picker edits when no session is open, and the seed a
|
|
529
|
+
// brand-new session copies. Once a session exists it carries its own per-session
|
|
530
|
+
// override (see `SessionConfig`).
|
|
519
531
|
selectedModel?: string
|
|
520
|
-
// Reasoning-effort default for new
|
|
532
|
+
// Reasoning-effort default for new sessions (a `supportedEffortLevels` value).
|
|
521
533
|
selectedEffort?: string
|
|
522
|
-
// Fast-mode default for new
|
|
534
|
+
// Fast-mode default for new sessions. Undefined inherits the provider setting.
|
|
523
535
|
selectedFastMode?: boolean
|
|
524
536
|
theme?: {
|
|
525
537
|
font: import('./themes').FontTheme
|
|
@@ -550,7 +562,7 @@ export type WidgetThumbnails = {
|
|
|
550
562
|
// Home-screen workspace card preview: a few captured widget thumbnails (WebP
|
|
551
563
|
// data URLs) from the stored layout, rendered as a loose stack, plus the latest
|
|
552
564
|
// provider session activity. A workspace with no widgets may instead carry its
|
|
553
|
-
// oldest
|
|
565
|
+
// oldest session's first user message.
|
|
554
566
|
export type WorkspacePreview = {
|
|
555
567
|
thumbnails: string[]
|
|
556
568
|
firstUserMessage?: string
|
|
@@ -620,4 +632,6 @@ export type WorkspaceModels = {
|
|
|
620
632
|
// shows the "Live typing" toggle only when true). Provider-wide, not per-model
|
|
621
633
|
// — Claude Code streams uniformly via `includePartialMessages`.
|
|
622
634
|
supportsStreaming?: boolean
|
|
635
|
+
// Whether the provider can archive chats from the chat selector.
|
|
636
|
+
supportsArchiving?: boolean
|
|
623
637
|
}
|
package/package.json
CHANGED
package/server/api.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
AppletKind,
|
|
9
9
|
AppSettings,
|
|
10
10
|
HarnessAvailability,
|
|
11
|
+
SessionInfo,
|
|
11
12
|
UploadInfo,
|
|
12
13
|
ViewBuilderInput,
|
|
13
14
|
WorkspaceEntry,
|
|
@@ -33,6 +34,7 @@ import {
|
|
|
33
34
|
} from './layout'
|
|
34
35
|
import { getClientFrameLog, getWireLog } from './harness/debug'
|
|
35
36
|
import { allHarnesses, harnessFor, isHarnessType } from './harness/registry'
|
|
37
|
+
import { broadcast } from './state'
|
|
36
38
|
import {
|
|
37
39
|
discoverWorkspace,
|
|
38
40
|
discoverWorkspaces,
|
|
@@ -45,10 +47,17 @@ import {
|
|
|
45
47
|
} from './registry'
|
|
46
48
|
import { loadScratchpadDoc, saveScratchpadDoc } from './scratchpad'
|
|
47
49
|
import { MAX_ASSET_BYTES, scratchpadAssetFile, storeScratchpadAsset } from './scratchpad-assets'
|
|
50
|
+
import {
|
|
51
|
+
clearSelectedSession,
|
|
52
|
+
getSelectedSession,
|
|
53
|
+
initializeSelectedSession,
|
|
54
|
+
saveSelectedSession
|
|
55
|
+
} from './selected-session'
|
|
56
|
+
import type { SelectedSessionUpdate } from './selected-session'
|
|
57
|
+
import { getSessionConfig, saveSessionConfig } from './session-config'
|
|
58
|
+
import type { SessionConfigPatch } from './session-config'
|
|
48
59
|
import { DIST_DIR, prebuilt } from './static'
|
|
49
60
|
import { getWorkspaceSkillsStatus, updateWorkspaceSkills } from './skill-update'
|
|
50
|
-
import { getThreadConfig, saveThreadConfig } from './thread-config'
|
|
51
|
-
import type { ThreadConfigPatch } from './thread-config'
|
|
52
61
|
import { serveWorkspaceImagePreview } from './preview'
|
|
53
62
|
import { MAX_UPLOAD_BYTES, addUpload, getUpload } from './uploads'
|
|
54
63
|
import { requiredEnvFor } from './required-env'
|
|
@@ -78,6 +87,15 @@ import type { EnvUpdate } from './workspace-env'
|
|
|
78
87
|
// `/api/workspaces/:id/*` handler can read it without re-querying the registry.
|
|
79
88
|
type ApiEnv = { Variables: { ws: WorkspaceEntry } }
|
|
80
89
|
|
|
90
|
+
function publishSelectedSession(workspaceId: string, update: SelectedSessionUpdate): void {
|
|
91
|
+
if (!update.changed) return
|
|
92
|
+
publishEvent({
|
|
93
|
+
type: 'selected-session:updated',
|
|
94
|
+
workspaceId,
|
|
95
|
+
sessionId: update.sessionId
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
81
99
|
async function handleFunctionCall(
|
|
82
100
|
req: Request,
|
|
83
101
|
tail: string,
|
|
@@ -258,6 +276,7 @@ one.post('/view-builders/:builderId/submit', async c => {
|
|
|
258
276
|
directives: viewBuilderDirectives(builder.id, availableIcons)
|
|
259
277
|
}
|
|
260
278
|
try {
|
|
279
|
+
publishSelectedSession(ws.id, await saveSelectedSession(ws.path, builder.sessionId))
|
|
261
280
|
await harnessFor(ws).sendMessage({
|
|
262
281
|
workspaceId: ws.id,
|
|
263
282
|
workspacePath: ws.path,
|
|
@@ -441,17 +460,78 @@ one.get('/sessions', async c => {
|
|
|
441
460
|
return c.json(await harnessFor(ws).listSessions(ws))
|
|
442
461
|
})
|
|
443
462
|
|
|
463
|
+
one.get('/selected-session', async c => {
|
|
464
|
+
const ws = c.get('ws')
|
|
465
|
+
let sessionId = await getSelectedSession(ws.path)
|
|
466
|
+
if (sessionId === undefined) {
|
|
467
|
+
const sessions = await harnessFor(ws).listSessions(ws)
|
|
468
|
+
const latest = sessions.reduce<SessionInfo | undefined>(
|
|
469
|
+
(current, session) =>
|
|
470
|
+
!current ||
|
|
471
|
+
session.lastModified > current.lastModified ||
|
|
472
|
+
(session.lastModified === current.lastModified &&
|
|
473
|
+
session.sessionId.localeCompare(current.sessionId) < 0)
|
|
474
|
+
? session
|
|
475
|
+
: current,
|
|
476
|
+
undefined
|
|
477
|
+
)
|
|
478
|
+
sessionId = await initializeSelectedSession(ws.path, latest?.sessionId ?? null)
|
|
479
|
+
}
|
|
480
|
+
return c.json({ sessionId })
|
|
481
|
+
})
|
|
482
|
+
|
|
483
|
+
one.put('/selected-session', async c => {
|
|
484
|
+
const ws = c.get('ws')
|
|
485
|
+
const body: unknown = await c.req.json().catch(() => null)
|
|
486
|
+
if (!body || typeof body !== 'object') return c.text('Bad request', 400)
|
|
487
|
+
|
|
488
|
+
const input = body as { sessionId?: unknown; previousSessionId?: unknown }
|
|
489
|
+
const validSessionId = input.sessionId === null || typeof input.sessionId === 'string'
|
|
490
|
+
const hasPreviousSessionId = Object.prototype.hasOwnProperty.call(input, 'previousSessionId')
|
|
491
|
+
const validPreviousSessionId =
|
|
492
|
+
!hasPreviousSessionId ||
|
|
493
|
+
input.previousSessionId === null ||
|
|
494
|
+
typeof input.previousSessionId === 'string'
|
|
495
|
+
if (!validSessionId || !validPreviousSessionId) return c.text('Bad request', 400)
|
|
496
|
+
|
|
497
|
+
const update = await saveSelectedSession(
|
|
498
|
+
ws.path,
|
|
499
|
+
input.sessionId as string | null,
|
|
500
|
+
hasPreviousSessionId ? (input.previousSessionId as string | null) : undefined
|
|
501
|
+
)
|
|
502
|
+
publishSelectedSession(ws.id, update)
|
|
503
|
+
return c.json({ sessionId: update.sessionId })
|
|
504
|
+
})
|
|
505
|
+
|
|
506
|
+
one.post('/sessions/:sessionId/archive', async c => {
|
|
507
|
+
const ws = c.get('ws')
|
|
508
|
+
const harness = harnessFor(ws)
|
|
509
|
+
const sessionId = c.req.param('sessionId')
|
|
510
|
+
if (!harness.archiveSession) return c.text('Chat archiving is not supported', 501)
|
|
511
|
+
|
|
512
|
+
try {
|
|
513
|
+
await harness.interrupt(ws.id, sessionId)
|
|
514
|
+
await harness.archiveSession(ws, sessionId)
|
|
515
|
+
publishSelectedSession(ws.id, await clearSelectedSession(ws.path, sessionId))
|
|
516
|
+
broadcast(ws.id, { type: 'sessions_changed', sessionId })
|
|
517
|
+
return c.body(null, 204)
|
|
518
|
+
} catch (error) {
|
|
519
|
+
console.error(`[api] archive chat failed for ${harness.id}`, error)
|
|
520
|
+
return c.text('Couldn’t archive chat', 500)
|
|
521
|
+
}
|
|
522
|
+
})
|
|
523
|
+
|
|
444
524
|
one.get('/sessions/:sessionId/events', async c => {
|
|
445
525
|
const ws = c.get('ws')
|
|
446
526
|
return c.json(await harnessFor(ws).sessionEvents(ws, c.req.param('sessionId')))
|
|
447
527
|
})
|
|
448
528
|
|
|
449
|
-
// Per-
|
|
450
|
-
// returns the stored config ({} for
|
|
529
|
+
// Per-session agent settings (model, reasoning effort, and Fast mode). GET
|
|
530
|
+
// returns the stored config ({} for sessions that never overrode the workspace
|
|
451
531
|
// defaults); PUT patches it (a field as `null` clears it, omitted leaves it).
|
|
452
|
-
// The change takes effect on the
|
|
532
|
+
// The change takes effect on the session's next message.
|
|
453
533
|
one.get('/sessions/:sessionId/config', async c => {
|
|
454
|
-
return c.json(await
|
|
534
|
+
return c.json(await getSessionConfig(c.get('ws').path, c.req.param('sessionId')))
|
|
455
535
|
})
|
|
456
536
|
|
|
457
537
|
one.put('/sessions/:sessionId/config', async c => {
|
|
@@ -459,7 +539,7 @@ one.put('/sessions/:sessionId/config', async c => {
|
|
|
459
539
|
if (typeof body !== 'object' || body === null) {
|
|
460
540
|
return c.text('Expected a JSON object', 400)
|
|
461
541
|
}
|
|
462
|
-
const patch:
|
|
542
|
+
const patch: SessionConfigPatch = {}
|
|
463
543
|
const record = body as Record<string, unknown>
|
|
464
544
|
for (const key of ['model', 'effort'] as const) {
|
|
465
545
|
if (!(key in record)) continue
|
|
@@ -476,7 +556,7 @@ one.put('/sessions/:sessionId/config', async c => {
|
|
|
476
556
|
}
|
|
477
557
|
patch.fastMode = value
|
|
478
558
|
}
|
|
479
|
-
return c.json(await
|
|
559
|
+
return c.json(await saveSessionConfig(c.get('ws').path, c.req.param('sessionId'), patch))
|
|
480
560
|
})
|
|
481
561
|
|
|
482
562
|
one.get('/mcp', async c => {
|
|
@@ -594,7 +674,8 @@ one.get('/models', async c => {
|
|
|
594
674
|
return c.json({
|
|
595
675
|
provider: harness.id,
|
|
596
676
|
models,
|
|
597
|
-
supportsStreaming: harness.capabilities.supportsStreaming
|
|
677
|
+
supportsStreaming: harness.capabilities.supportsStreaming,
|
|
678
|
+
supportsArchiving: Boolean(harness.archiveSession)
|
|
598
679
|
} satisfies WorkspaceModels)
|
|
599
680
|
})
|
|
600
681
|
|
package/server/app-settings.ts
CHANGED
|
@@ -33,7 +33,7 @@ export function pickAppSettingsPatch(body: Record<string, unknown>): AppSettings
|
|
|
33
33
|
let _dir = DATA_DIR
|
|
34
34
|
let _store: Conf<AppSettings> | null = null
|
|
35
35
|
|
|
36
|
-
// Test seam: point the store at a scratch dir (mirrors
|
|
36
|
+
// Test seam: point the store at a scratch dir (mirrors setSessionConfigPath).
|
|
37
37
|
export function setAppSettingsDir(dir: string): void {
|
|
38
38
|
_dir = dir
|
|
39
39
|
_store = null
|
package/server/data-dir.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Single source of truth for the OS data dir holding moi's global state
|
|
2
|
-
// (workspaces.json, settings.json,
|
|
2
|
+
// (workspaces.json, settings.json, session-config.json, selected-sessions.json, …).
|
|
3
3
|
//
|
|
4
4
|
// MOI_DATA_DIR overrides it wholesale. This is the isolation seam for CLI
|
|
5
5
|
// e2e tests: env-paths only honors XDG_DATA_HOME on Linux, so on macOS a
|
package/server/harness/README.md
CHANGED
|
@@ -34,6 +34,8 @@ Socket-protocol notes the layers rely on (all defined in `lib/types.ts`):
|
|
|
34
34
|
|
|
35
35
|
- **`session_renamed`** — a new thread is created under the client's temporary
|
|
36
36
|
uuid, then rekeyed to the backend's real session/thread id.
|
|
37
|
+
- **`sessions_changed`** — a provider changed session-list metadata such as a
|
|
38
|
+
generated session title; clients refresh that workspace's session list.
|
|
37
39
|
- **Optimistic-id rendezvous** — the client sends `optimisticId` with each
|
|
38
40
|
chat; the user's bubble must upsert under that id. Backends differ: Codex
|
|
39
41
|
echoes it natively (`clientUserMessageId` → `clientId`), Claude Code never
|
|
@@ -69,6 +71,10 @@ server/harness/
|
|
|
69
71
|
```
|
|
70
72
|
|
|
71
73
|
- Nothing inside one harness folder imports from a sibling harness.
|
|
74
|
+
- Internal harness metadata and helpers use session naming, including
|
|
75
|
+
`sessionTitle`, `generateSessionTitle`, and `session-title.ts`. Chat naming is
|
|
76
|
+
for client and UI labels. Thread naming stays at provider wire and RPC
|
|
77
|
+
boundaries.
|
|
72
78
|
- Outside code imports only this folder's top level. Documented exceptions:
|
|
73
79
|
`cli.ts` (`moi openclaw init` provisioning) imports
|
|
74
80
|
`harness/openclaw/discovery.ts`; tests may import harness internals.
|
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
TurnOrigin
|
|
15
15
|
} from '@/lib/format'
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { isAttachmentOnlyPlaceholder, splitAttachmentNote } from '@/lib/attachment-note'
|
|
18
18
|
import { stripMoiContext } from '@/lib/moi-context'
|
|
19
19
|
|
|
20
20
|
// Loose SDK message shape — we don't pull in the full SDK type tree; the
|
|
@@ -532,7 +532,7 @@ export class ClaudeAdapter {
|
|
|
532
532
|
}
|
|
533
533
|
// An attachment-only message carries a synthesized placeholder
|
|
534
534
|
// prompt; the bubble should show just the attachments.
|
|
535
|
-
if (text
|
|
535
|
+
if (isAttachmentOnlyPlaceholder(text) && parts.some(p => p.type === 'file')) {
|
|
536
536
|
text = ''
|
|
537
537
|
}
|
|
538
538
|
}
|
|
@@ -18,7 +18,12 @@ import {
|
|
|
18
18
|
restartWorkspaceSessions,
|
|
19
19
|
sendCCMessage
|
|
20
20
|
} from './session'
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
archiveClaudeSession,
|
|
23
|
+
getSessionEvents,
|
|
24
|
+
getSessions,
|
|
25
|
+
getSessionWorkspacePreview
|
|
26
|
+
} from './sessions'
|
|
22
27
|
|
|
23
28
|
function fmtDuration(ms: number): string {
|
|
24
29
|
const s = Math.floor(ms / 1000)
|
|
@@ -79,6 +84,7 @@ export const claudeCodeHarness: Harness = {
|
|
|
79
84
|
|
|
80
85
|
sendMessage: input => sendCCMessage(input),
|
|
81
86
|
interrupt: (workspaceId, sessionId) => interruptCCSession(workspaceId, sessionId),
|
|
87
|
+
archiveSession: (ws, sessionId) => archiveClaudeSession(sessionId, ws.path),
|
|
82
88
|
activeSessions: () => getCCActiveSessions(),
|
|
83
89
|
|
|
84
90
|
listSessions: ws => getSessions(ws.path),
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { getSessionInfo, renameSession, type SDKSessionInfo } from '@anthropic-ai/claude-agent-sdk'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
SESSION_TITLE_SCHEMA,
|
|
5
|
+
SESSION_TITLE_SYSTEM_PROMPT,
|
|
6
|
+
SESSION_TITLE_TIMEOUT_MS,
|
|
7
|
+
createSessionTitleTempDir,
|
|
8
|
+
parseGeneratedSessionTitle,
|
|
9
|
+
removeSessionTitleTempDir,
|
|
10
|
+
runSessionTitleCommand
|
|
11
|
+
} from '../session-title'
|
|
12
|
+
import { requireHarnessExecutable } from '../executable'
|
|
13
|
+
|
|
14
|
+
export function claudeSessionTitleCommand(executable: string): string[] {
|
|
15
|
+
return [
|
|
16
|
+
executable,
|
|
17
|
+
'-p',
|
|
18
|
+
'--model',
|
|
19
|
+
'haiku',
|
|
20
|
+
'--effort',
|
|
21
|
+
'low',
|
|
22
|
+
'--max-turns',
|
|
23
|
+
'1',
|
|
24
|
+
'--tools',
|
|
25
|
+
'',
|
|
26
|
+
'--safe-mode',
|
|
27
|
+
'--no-session-persistence',
|
|
28
|
+
'--disable-slash-commands',
|
|
29
|
+
'--strict-mcp-config',
|
|
30
|
+
'--setting-sources',
|
|
31
|
+
'',
|
|
32
|
+
'--permission-mode',
|
|
33
|
+
'dontAsk',
|
|
34
|
+
'--system-prompt',
|
|
35
|
+
SESSION_TITLE_SYSTEM_PROMPT,
|
|
36
|
+
'--output-format',
|
|
37
|
+
'json',
|
|
38
|
+
'--json-schema',
|
|
39
|
+
JSON.stringify(SESSION_TITLE_SCHEMA)
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function parseClaudeSessionTitleOutput(value: string): string | null {
|
|
44
|
+
try {
|
|
45
|
+
const result = JSON.parse(value) as { structured_output?: unknown }
|
|
46
|
+
return parseGeneratedSessionTitle(result.structured_output)
|
|
47
|
+
} catch {
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function generateClaudeSessionTitle(input: {
|
|
53
|
+
source: string
|
|
54
|
+
abortController: AbortController
|
|
55
|
+
timeoutMs?: number
|
|
56
|
+
}): Promise<string | null> {
|
|
57
|
+
if (!input.source || input.abortController.signal.aborted) return null
|
|
58
|
+
const timer = setTimeout(
|
|
59
|
+
() => input.abortController.abort(),
|
|
60
|
+
input.timeoutMs ?? SESSION_TITLE_TIMEOUT_MS
|
|
61
|
+
)
|
|
62
|
+
let tempDir: string | undefined
|
|
63
|
+
try {
|
|
64
|
+
tempDir = await createSessionTitleTempDir()
|
|
65
|
+
const output = await runSessionTitleCommand({
|
|
66
|
+
command: claudeSessionTitleCommand(requireHarnessExecutable('claude-code')),
|
|
67
|
+
cwd: tempDir,
|
|
68
|
+
stdin: JSON.stringify({ sessionTitleSource: input.source }),
|
|
69
|
+
signal: input.abortController.signal,
|
|
70
|
+
env: { ...process.env, CLAUDECODE: undefined, DISABLE_AUTOUPDATER: '1' }
|
|
71
|
+
})
|
|
72
|
+
return output ? parseClaudeSessionTitleOutput(output) : null
|
|
73
|
+
} finally {
|
|
74
|
+
clearTimeout(timer)
|
|
75
|
+
if (tempDir) await removeSessionTitleTempDir(tempDir).catch(() => {})
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type ClaudeSessionTitleRenameTransport = {
|
|
80
|
+
getSessionInfo: (sessionId: string, workspacePath: string) => Promise<SDKSessionInfo | undefined>
|
|
81
|
+
renameSession: (sessionId: string, title: string, workspacePath: string) => Promise<void>
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const defaultSessionTitleRenameTransport: ClaudeSessionTitleRenameTransport = {
|
|
85
|
+
getSessionInfo: (sessionId, workspacePath) => getSessionInfo(sessionId, { dir: workspacePath }),
|
|
86
|
+
renameSession: (sessionId, title, workspacePath) =>
|
|
87
|
+
renameSession(sessionId, title, { dir: workspacePath })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function renameClaudeSessionIfUnchanged(
|
|
91
|
+
input: {
|
|
92
|
+
sessionId: string
|
|
93
|
+
workspacePath: string
|
|
94
|
+
title: string
|
|
95
|
+
isCurrent?: () => boolean
|
|
96
|
+
},
|
|
97
|
+
transport: ClaudeSessionTitleRenameTransport = defaultSessionTitleRenameTransport
|
|
98
|
+
): Promise<boolean> {
|
|
99
|
+
const info = await transport.getSessionInfo(input.sessionId, input.workspacePath)
|
|
100
|
+
if (!info || info.customTitle || !info.firstPrompt || info.summary !== info.firstPrompt) {
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
if (input.isCurrent && !input.isCurrent()) return false
|
|
104
|
+
await transport.renameSession(input.sessionId, input.title, input.workspacePath)
|
|
105
|
+
return true
|
|
106
|
+
}
|