@swarmclawai/swarmclaw 0.7.7 → 0.8.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/README.md +12 -14
- package/next.config.ts +13 -2
- package/package.json +4 -2
- package/src/app/api/agents/[id]/thread/route.ts +9 -0
- package/src/app/api/agents/route.ts +4 -0
- package/src/app/api/agents/thread-route.test.ts +133 -0
- package/src/app/api/approvals/route.test.ts +148 -0
- package/src/app/api/canvas/[sessionId]/route.ts +3 -1
- package/src/app/api/chatrooms/[id]/chat/route.ts +4 -2
- package/src/app/api/chats/[id]/devserver/route.ts +48 -7
- package/src/app/api/chats/[id]/messages/route.ts +42 -18
- package/src/app/api/chats/[id]/route.ts +1 -1
- package/src/app/api/chats/[id]/stop/route.ts +5 -4
- package/src/app/api/chats/route.ts +23 -2
- package/src/app/api/clawhub/install/route.ts +28 -8
- package/src/app/api/connectors/[id]/route.ts +46 -3
- package/src/app/api/connectors/route.ts +12 -8
- package/src/app/api/external-agents/route.test.ts +165 -0
- package/src/app/api/gateways/[id]/health/route.ts +27 -12
- package/src/app/api/gateways/[id]/route.ts +2 -0
- package/src/app/api/gateways/health-route.test.ts +135 -0
- package/src/app/api/gateways/route.ts +2 -0
- package/src/app/api/mcp-servers/route.test.ts +130 -0
- package/src/app/api/openclaw/deploy/route.ts +38 -5
- package/src/app/api/plugins/install/route.ts +46 -6
- package/src/app/api/plugins/marketplace/route.ts +48 -15
- package/src/app/api/preview-server/route.ts +26 -11
- package/src/app/api/projects/[id]/route.ts +6 -2
- package/src/app/api/projects/route.ts +4 -3
- package/src/app/api/schedules/[id]/run/route.ts +4 -0
- package/src/app/api/schedules/route.test.ts +86 -0
- package/src/app/api/schedules/route.ts +6 -1
- package/src/app/api/secrets/[id]/route.ts +1 -0
- package/src/app/api/secrets/route.ts +2 -1
- package/src/app/api/settings/route.ts +2 -0
- package/src/app/api/setup/check-provider/route.test.ts +19 -0
- package/src/app/api/setup/check-provider/route.ts +40 -10
- package/src/app/api/skills/[id]/route.ts +12 -0
- package/src/app/api/skills/import/route.ts +14 -12
- package/src/app/api/skills/route.ts +13 -1
- package/src/app/api/tasks/[id]/route.ts +10 -1
- package/src/app/api/tasks/import/github/route.test.ts +65 -0
- package/src/app/api/tasks/import/github/route.ts +337 -0
- package/src/app/api/wallets/[id]/approve/route.ts +17 -3
- package/src/app/api/wallets/[id]/route.ts +79 -33
- package/src/app/api/wallets/[id]/send/route.ts +19 -33
- package/src/app/api/wallets/route.ts +78 -61
- package/src/app/api/webhooks/[id]/route.ts +33 -6
- package/src/app/api/webhooks/route.test.ts +272 -0
- package/src/cli/index.js +1 -0
- package/src/cli/spec.js +1 -0
- package/src/components/agents/agent-card.tsx +9 -2
- package/src/components/agents/agent-chat-list.tsx +18 -2
- package/src/components/agents/agent-list.tsx +1 -0
- package/src/components/agents/agent-sheet.tsx +257 -38
- package/src/components/agents/inspector-panel.tsx +41 -0
- package/src/components/canvas/canvas-panel.tsx +236 -65
- package/src/components/chat/chat-area.tsx +36 -19
- package/src/components/chat/chat-card.tsx +36 -13
- package/src/components/chat/chat-header.tsx +48 -16
- package/src/components/chat/chat-list.tsx +28 -4
- package/src/components/chat/checkpoint-timeline.tsx +50 -34
- package/src/components/chat/delegation-banner.test.ts +14 -1
- package/src/components/chat/delegation-banner.tsx +1 -1
- package/src/components/chat/message-bubble.tsx +208 -145
- package/src/components/chat/message-list.tsx +48 -19
- package/src/components/chatrooms/chatroom-message.tsx +2 -2
- package/src/components/chatrooms/chatroom-sheet.tsx +16 -2
- package/src/components/connectors/connector-health.tsx +1 -1
- package/src/components/connectors/connector-list.tsx +7 -2
- package/src/components/connectors/connector-sheet.tsx +337 -148
- package/src/components/gateways/gateway-sheet.tsx +2 -2
- package/src/components/layout/app-layout.tsx +40 -23
- package/src/components/mcp-servers/mcp-server-list.tsx +26 -5
- package/src/components/mcp-servers/mcp-server-sheet.tsx +19 -2
- package/src/components/openclaw/openclaw-deploy-panel.tsx +269 -21
- package/src/components/plugins/plugin-list.tsx +45 -9
- package/src/components/plugins/plugin-sheet.tsx +55 -7
- package/src/components/projects/project-detail.tsx +217 -0
- package/src/components/projects/project-sheet.tsx +176 -4
- package/src/components/providers/provider-list.tsx +2 -1
- package/src/components/providers/provider-sheet.tsx +21 -2
- package/src/components/schedules/schedule-card.tsx +25 -1
- package/src/components/schedules/schedule-sheet.tsx +44 -2
- package/src/components/secrets/secret-sheet.tsx +21 -2
- package/src/components/shared/agent-switch-dialog.tsx +12 -1
- package/src/components/shared/bottom-sheet.tsx +13 -3
- package/src/components/shared/command-palette.tsx +8 -1
- package/src/components/shared/confirm-dialog.tsx +19 -4
- package/src/components/shared/connector-platform-icon.test.ts +28 -0
- package/src/components/shared/connector-platform-icon.tsx +39 -6
- package/src/components/shared/settings/plugin-manager.tsx +29 -6
- package/src/components/shared/settings/section-capability-policy.tsx +45 -3
- package/src/components/shared/settings/section-voice.tsx +11 -3
- package/src/components/skills/skill-list.tsx +25 -0
- package/src/components/skills/skill-sheet.tsx +84 -12
- package/src/components/tasks/approvals-panel.tsx +289 -34
- package/src/components/tasks/task-board.tsx +410 -25
- package/src/components/tasks/task-card.tsx +66 -8
- package/src/components/tasks/task-sheet.tsx +16 -4
- package/src/components/ui/dialog.tsx +2 -2
- package/src/components/wallets/wallet-approval-dialog.tsx +4 -2
- package/src/components/wallets/wallet-panel.tsx +435 -90
- package/src/components/wallets/wallet-section.tsx +198 -48
- package/src/components/webhooks/webhook-sheet.tsx +22 -2
- package/src/lib/approval-display.ts +20 -0
- package/src/lib/canvas-content.ts +198 -0
- package/src/lib/chat-artifact-summary.ts +165 -0
- package/src/lib/chat-display.test.ts +91 -0
- package/src/lib/chat-display.ts +58 -0
- package/src/lib/chat-streaming-state.test.ts +47 -1
- package/src/lib/chat-streaming-state.ts +42 -0
- package/src/lib/ollama-model.ts +10 -0
- package/src/lib/openclaw-endpoint.test.ts +8 -0
- package/src/lib/openclaw-endpoint.ts +6 -1
- package/src/lib/plugin-install-cors.ts +46 -0
- package/src/lib/plugin-sources.test.ts +43 -0
- package/src/lib/plugin-sources.ts +77 -0
- package/src/lib/providers/ollama.ts +16 -6
- package/src/lib/providers/openclaw.test.ts +54 -0
- package/src/lib/providers/openclaw.ts +127 -11
- package/src/lib/schedule-dedupe-advanced.test.ts +1335 -0
- package/src/lib/schedule-dedupe.test.ts +66 -1
- package/src/lib/schedule-dedupe.ts +169 -12
- package/src/lib/schedule-origin.test.ts +20 -0
- package/src/lib/schedule-origin.ts +15 -0
- package/src/lib/server/__fixtures__/fake-mcp-stdio-server.mjs +27 -0
- package/src/lib/server/agent-availability.ts +16 -0
- package/src/lib/server/agent-runtime-config.ts +12 -4
- package/src/lib/server/agent-thread-session.test.ts +51 -0
- package/src/lib/server/agent-thread-session.ts +7 -0
- package/src/lib/server/approval-match.ts +205 -0
- package/src/lib/server/approvals-auto-approve.test.ts +538 -1
- package/src/lib/server/approvals.ts +214 -1
- package/src/lib/server/assistant-control.test.ts +29 -0
- package/src/lib/server/assistant-control.ts +23 -0
- package/src/lib/server/build-llm.test.ts +79 -0
- package/src/lib/server/build-llm.ts +14 -4
- package/src/lib/server/canvas-content.test.ts +32 -0
- package/src/lib/server/canvas-content.ts +6 -0
- package/src/lib/server/capability-router.test.ts +33 -0
- package/src/lib/server/capability-router.ts +80 -19
- package/src/lib/server/chat-execution-advanced.test.ts +651 -0
- package/src/lib/server/chat-execution-disabled.test.ts +94 -0
- package/src/lib/server/chat-execution-tool-events.test.ts +157 -0
- package/src/lib/server/chat-execution.ts +378 -73
- package/src/lib/server/clawhub-client.test.ts +14 -8
- package/src/lib/server/connectors/manager-reconnect.test.ts +47 -0
- package/src/lib/server/connectors/manager.test.ts +1147 -0
- package/src/lib/server/connectors/manager.ts +461 -137
- package/src/lib/server/connectors/pairing.ts +26 -5
- package/src/lib/server/connectors/types.ts +2 -0
- package/src/lib/server/connectors/whatsapp.test.ts +134 -0
- package/src/lib/server/connectors/whatsapp.ts +271 -47
- package/src/lib/server/context-manager.ts +6 -1
- package/src/lib/server/daemon-state.ts +84 -47
- package/src/lib/server/data-dir.test.ts +37 -0
- package/src/lib/server/data-dir.ts +20 -1
- package/src/lib/server/delegation-jobs-advanced.test.ts +513 -0
- package/src/lib/server/devserver-launch.test.ts +60 -0
- package/src/lib/server/devserver-launch.ts +85 -0
- package/src/lib/server/elevenlabs.test.ts +247 -1
- package/src/lib/server/elevenlabs.ts +147 -43
- package/src/lib/server/ethereum.ts +590 -0
- package/src/lib/server/eval/agent-regression-advanced.test.ts +302 -0
- package/src/lib/server/eval/agent-regression.test.ts +18 -1
- package/src/lib/server/eval/agent-regression.ts +383 -11
- package/src/lib/server/evm-swap.ts +475 -0
- package/src/lib/server/execution-log.ts +1 -0
- package/src/lib/server/heartbeat-service-timer.test.ts +173 -0
- package/src/lib/server/heartbeat-service.ts +20 -11
- package/src/lib/server/heartbeat-wake.test.ts +112 -0
- package/src/lib/server/heartbeat-wake.ts +338 -57
- package/src/lib/server/main-agent-loop-advanced.test.ts +538 -0
- package/src/lib/server/main-agent-loop.test.ts +260 -0
- package/src/lib/server/main-agent-loop.ts +559 -14
- package/src/lib/server/mcp-client.test.ts +16 -0
- package/src/lib/server/mcp-client.ts +25 -0
- package/src/lib/server/memory-integration.test.ts +719 -0
- package/src/lib/server/memory-policy.test.ts +43 -0
- package/src/lib/server/memory-policy.ts +132 -0
- package/src/lib/server/memory-tiers.test.ts +60 -0
- package/src/lib/server/memory-tiers.ts +16 -0
- package/src/lib/server/ollama-runtime.ts +58 -0
- package/src/lib/server/openclaw-deploy.test.ts +109 -1
- package/src/lib/server/openclaw-deploy.ts +557 -81
- package/src/lib/server/openclaw-gateway.test.ts +131 -0
- package/src/lib/server/openclaw-gateway.ts +10 -4
- package/src/lib/server/openclaw-health.test.ts +35 -0
- package/src/lib/server/openclaw-health.ts +215 -47
- package/src/lib/server/orchestrator-lg.ts +3 -2
- package/src/lib/server/orchestrator.ts +2 -0
- package/src/lib/server/plugins-advanced.test.ts +351 -0
- package/src/lib/server/plugins.ts +211 -6
- package/src/lib/server/project-context.ts +162 -0
- package/src/lib/server/project-utils.ts +150 -0
- package/src/lib/server/queue-advanced.test.ts +528 -0
- package/src/lib/server/queue-followups.test.ts +409 -2
- package/src/lib/server/queue-reconcile.test.ts +128 -0
- package/src/lib/server/queue.ts +527 -68
- package/src/lib/server/scheduler.ts +29 -1
- package/src/lib/server/session-note.test.ts +36 -0
- package/src/lib/server/session-note.ts +42 -0
- package/src/lib/server/session-run-manager.ts +83 -4
- package/src/lib/server/session-tools/canvas.ts +14 -12
- package/src/lib/server/session-tools/connector-inputs.test.ts +37 -0
- package/src/lib/server/session-tools/connector.test.ts +138 -0
- package/src/lib/server/session-tools/connector.ts +366 -54
- package/src/lib/server/session-tools/context.ts +17 -3
- package/src/lib/server/session-tools/crud.ts +484 -84
- package/src/lib/server/session-tools/delegate-fallback.test.ts +103 -0
- package/src/lib/server/session-tools/delegate-resume.test.ts +50 -0
- package/src/lib/server/session-tools/delegate.ts +102 -10
- package/src/lib/server/session-tools/discovery-approvals.test.ts +142 -0
- package/src/lib/server/session-tools/discovery.ts +80 -12
- package/src/lib/server/session-tools/file-normalize.test.ts +36 -0
- package/src/lib/server/session-tools/file.ts +43 -4
- package/src/lib/server/session-tools/human-loop.ts +35 -5
- package/src/lib/server/session-tools/index.ts +44 -9
- package/src/lib/server/session-tools/manage-connectors.test.ts +139 -0
- package/src/lib/server/session-tools/manage-schedules-advanced.test.ts +564 -0
- package/src/lib/server/session-tools/manage-schedules.test.ts +283 -0
- package/src/lib/server/session-tools/manage-tasks-advanced.test.ts +852 -0
- package/src/lib/server/session-tools/manage-tasks.test.ts +114 -0
- package/src/lib/server/session-tools/memory.test.ts +93 -0
- package/src/lib/server/session-tools/memory.ts +554 -75
- package/src/lib/server/session-tools/normalize-tool-args.ts +1 -1
- package/src/lib/server/session-tools/platform-access.test.ts +58 -0
- package/src/lib/server/session-tools/platform.ts +60 -19
- package/src/lib/server/session-tools/plugin-creator.ts +57 -1
- package/src/lib/server/session-tools/primitive-tools.test.ts +6 -0
- package/src/lib/server/session-tools/schedule.ts +6 -1
- package/src/lib/server/session-tools/shell-normalize.test.ts +25 -1
- package/src/lib/server/session-tools/shell.ts +22 -3
- package/src/lib/server/session-tools/wallet-tool.test.ts +254 -0
- package/src/lib/server/session-tools/wallet.ts +1374 -139
- package/src/lib/server/session-tools/web-inputs.test.ts +178 -0
- package/src/lib/server/session-tools/web.ts +621 -70
- package/src/lib/server/skill-discovery.ts +128 -0
- package/src/lib/server/skill-eligibility.test.ts +84 -0
- package/src/lib/server/skill-eligibility.ts +95 -0
- package/src/lib/server/skill-prompt-budget.test.ts +102 -0
- package/src/lib/server/skill-prompt-budget.ts +125 -0
- package/src/lib/server/skills-normalize.test.ts +54 -0
- package/src/lib/server/skills-normalize.ts +372 -26
- package/src/lib/server/solana.ts +214 -29
- package/src/lib/server/storage.ts +65 -36
- package/src/lib/server/stream-agent-chat.test.ts +437 -2
- package/src/lib/server/stream-agent-chat.ts +957 -79
- package/src/lib/server/system-events.ts +1 -1
- package/src/lib/server/tool-aliases.ts +2 -0
- package/src/lib/server/tool-capability-policy-advanced.test.ts +502 -0
- package/src/lib/server/tool-capability-policy.test.ts +24 -0
- package/src/lib/server/tool-capability-policy.ts +29 -1
- package/src/lib/server/tool-loop-detection.test.ts +105 -0
- package/src/lib/server/tool-loop-detection.ts +260 -0
- package/src/lib/server/tool-planning.test.ts +44 -0
- package/src/lib/server/tool-planning.ts +271 -0
- package/src/lib/server/wallet-execution.test.ts +198 -0
- package/src/lib/server/wallet-portfolio.test.ts +98 -0
- package/src/lib/server/wallet-portfolio.ts +724 -0
- package/src/lib/server/wallet-service.test.ts +57 -0
- package/src/lib/server/wallet-service.ts +213 -0
- package/src/lib/server/watch-jobs-advanced.test.ts +594 -0
- package/src/lib/server/watch-jobs.ts +17 -2
- package/src/lib/server/workspace-context.ts +111 -0
- package/src/lib/skill-save-payload.test.ts +39 -0
- package/src/lib/skill-save-payload.ts +37 -0
- package/src/lib/tasks.ts +28 -0
- package/src/lib/tool-definitions.ts +2 -1
- package/src/lib/tool-event-summary.test.ts +30 -0
- package/src/lib/tool-event-summary.ts +37 -0
- package/src/lib/validation/schemas.ts +1 -0
- package/src/lib/wallet-transactions.test.ts +75 -0
- package/src/lib/wallet-transactions.ts +43 -0
- package/src/lib/wallet.test.ts +17 -0
- package/src/lib/wallet.ts +183 -0
- package/src/proxy.test.ts +31 -0
- package/src/proxy.ts +34 -2
- package/src/stores/use-chat-store.ts +15 -1
- package/src/types/index.ts +249 -14
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import type { Project } from '@/types'
|
|
3
|
+
import { WORKSPACE_DIR } from './data-dir'
|
|
4
|
+
import { loadAgents, loadProjects } from './storage'
|
|
5
|
+
import { buildProjectSnapshot, type ProjectResourceSummary } from './project-utils'
|
|
6
|
+
|
|
7
|
+
export interface ActiveProjectContext {
|
|
8
|
+
projectId: string | null
|
|
9
|
+
project: (Project & { workspaceRoot: string; resourceSummary: ProjectResourceSummary }) | null
|
|
10
|
+
projectRoot: string | null
|
|
11
|
+
objective: string | null
|
|
12
|
+
audience: string | null
|
|
13
|
+
priorities: string[]
|
|
14
|
+
openObjectives: string[]
|
|
15
|
+
capabilityHints: string[]
|
|
16
|
+
credentialRequirements: string[]
|
|
17
|
+
successMetrics: string[]
|
|
18
|
+
heartbeatPrompt: string | null
|
|
19
|
+
heartbeatIntervalSec: number | null
|
|
20
|
+
resourceSummary: ProjectResourceSummary | null
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function normalizeProjectId(value: unknown): string | null {
|
|
24
|
+
return typeof value === 'string' && value.trim() ? value.trim() : null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function inferProjectIdFromCwd(cwd: unknown): string | null {
|
|
28
|
+
if (typeof cwd !== 'string' || !cwd.trim()) return null
|
|
29
|
+
const projectsRoot = path.resolve(path.join(WORKSPACE_DIR, 'projects'))
|
|
30
|
+
const resolvedCwd = path.resolve(cwd)
|
|
31
|
+
const relative = path.relative(projectsRoot, resolvedCwd)
|
|
32
|
+
if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) return null
|
|
33
|
+
const [projectId] = relative.split(path.sep).filter(Boolean)
|
|
34
|
+
return normalizeProjectId(projectId)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function extractProjectHints(project: Project | null): {
|
|
38
|
+
objective: string | null
|
|
39
|
+
audience: string | null
|
|
40
|
+
priorities: string[]
|
|
41
|
+
openObjectives: string[]
|
|
42
|
+
capabilityHints: string[]
|
|
43
|
+
credentialRequirements: string[]
|
|
44
|
+
successMetrics: string[]
|
|
45
|
+
heartbeatPrompt: string | null
|
|
46
|
+
heartbeatIntervalSec: number | null
|
|
47
|
+
} {
|
|
48
|
+
if (!project) {
|
|
49
|
+
return {
|
|
50
|
+
objective: null,
|
|
51
|
+
audience: null,
|
|
52
|
+
priorities: [],
|
|
53
|
+
openObjectives: [],
|
|
54
|
+
capabilityHints: [],
|
|
55
|
+
credentialRequirements: [],
|
|
56
|
+
successMetrics: [],
|
|
57
|
+
heartbeatPrompt: null,
|
|
58
|
+
heartbeatIntervalSec: null,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (
|
|
62
|
+
project.objective
|
|
63
|
+
|| project.audience
|
|
64
|
+
|| project.priorities?.length
|
|
65
|
+
|| project.openObjectives?.length
|
|
66
|
+
|| project.capabilityHints?.length
|
|
67
|
+
|| project.credentialRequirements?.length
|
|
68
|
+
|| project.successMetrics?.length
|
|
69
|
+
|| project.heartbeatPrompt
|
|
70
|
+
|| typeof project.heartbeatIntervalSec === 'number'
|
|
71
|
+
) {
|
|
72
|
+
return {
|
|
73
|
+
objective: project.objective || null,
|
|
74
|
+
audience: project.audience || null,
|
|
75
|
+
priorities: Array.isArray(project.priorities) ? project.priorities : [],
|
|
76
|
+
openObjectives: Array.isArray(project.openObjectives) ? project.openObjectives : [],
|
|
77
|
+
capabilityHints: Array.isArray(project.capabilityHints) ? project.capabilityHints : [],
|
|
78
|
+
credentialRequirements: Array.isArray(project.credentialRequirements) ? project.credentialRequirements : [],
|
|
79
|
+
successMetrics: Array.isArray(project.successMetrics) ? project.successMetrics : [],
|
|
80
|
+
heartbeatPrompt: project.heartbeatPrompt || null,
|
|
81
|
+
heartbeatIntervalSec: typeof project.heartbeatIntervalSec === 'number' ? project.heartbeatIntervalSec : null,
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const description = project.description || ''
|
|
86
|
+
if (!description) {
|
|
87
|
+
return {
|
|
88
|
+
objective: null,
|
|
89
|
+
audience: null,
|
|
90
|
+
priorities: [],
|
|
91
|
+
openObjectives: [],
|
|
92
|
+
capabilityHints: [],
|
|
93
|
+
credentialRequirements: [],
|
|
94
|
+
successMetrics: [],
|
|
95
|
+
heartbeatPrompt: null,
|
|
96
|
+
heartbeatIntervalSec: null,
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const audienceMatch = description.match(/\bfor\s+([^.!?]+?)(?:\.|,|;|$)/i)
|
|
100
|
+
const objectiveMatch = description.match(/^([^.!?]+?)(?:\.|!|\?)/)
|
|
101
|
+
const focusMatch = description.match(/\b(?:focused on|focuses on|pilot priorities(?: are| include)?|priority is)\s+([^.!?]+)/i)
|
|
102
|
+
const audience = normalizeProjectId(audienceMatch?.[1]?.replace(/^the\s+/i, '').trim()) || null
|
|
103
|
+
const priorities = (focusMatch?.[1] || '')
|
|
104
|
+
.split(/\s+(?:and|&)\s+|,\s+/)
|
|
105
|
+
.map((value) => value.trim())
|
|
106
|
+
.filter((value) => value.length > 0)
|
|
107
|
+
.slice(0, 4)
|
|
108
|
+
return {
|
|
109
|
+
objective: normalizeProjectId(objectiveMatch?.[1]?.trim()) || null,
|
|
110
|
+
audience,
|
|
111
|
+
priorities,
|
|
112
|
+
openObjectives: [],
|
|
113
|
+
capabilityHints: [],
|
|
114
|
+
credentialRequirements: [],
|
|
115
|
+
successMetrics: [],
|
|
116
|
+
heartbeatPrompt: null,
|
|
117
|
+
heartbeatIntervalSec: null,
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function resolveActiveProjectContext(sessionLike: { agentId?: string | null; cwd?: string | null; projectId?: string | null }): ActiveProjectContext {
|
|
122
|
+
const agents = loadAgents()
|
|
123
|
+
const projects = loadProjects() as Record<string, Project>
|
|
124
|
+
const explicitProjectId = normalizeProjectId(sessionLike.projectId)
|
|
125
|
+
const agentProjectId = normalizeProjectId(sessionLike.agentId ? agents[sessionLike.agentId]?.projectId : null)
|
|
126
|
+
const cwdProjectId = inferProjectIdFromCwd(sessionLike.cwd)
|
|
127
|
+
const projectId = explicitProjectId || agentProjectId || cwdProjectId
|
|
128
|
+
if (!projectId) {
|
|
129
|
+
return {
|
|
130
|
+
projectId: null,
|
|
131
|
+
project: null,
|
|
132
|
+
projectRoot: null,
|
|
133
|
+
objective: null,
|
|
134
|
+
audience: null,
|
|
135
|
+
priorities: [],
|
|
136
|
+
openObjectives: [],
|
|
137
|
+
capabilityHints: [],
|
|
138
|
+
credentialRequirements: [],
|
|
139
|
+
successMetrics: [],
|
|
140
|
+
heartbeatPrompt: null,
|
|
141
|
+
heartbeatIntervalSec: null,
|
|
142
|
+
resourceSummary: null,
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const project = projects[projectId] ? buildProjectSnapshot(projects[projectId]) : null
|
|
146
|
+
const hints = extractProjectHints(project)
|
|
147
|
+
return {
|
|
148
|
+
projectId,
|
|
149
|
+
project,
|
|
150
|
+
projectRoot: project?.workspaceRoot || path.join(WORKSPACE_DIR, 'projects', projectId),
|
|
151
|
+
objective: hints.objective,
|
|
152
|
+
audience: hints.audience,
|
|
153
|
+
priorities: hints.priorities,
|
|
154
|
+
openObjectives: hints.openObjectives,
|
|
155
|
+
capabilityHints: hints.capabilityHints,
|
|
156
|
+
credentialRequirements: hints.credentialRequirements,
|
|
157
|
+
successMetrics: hints.successMetrics,
|
|
158
|
+
heartbeatPrompt: hints.heartbeatPrompt,
|
|
159
|
+
heartbeatIntervalSec: hints.heartbeatIntervalSec,
|
|
160
|
+
resourceSummary: project?.resourceSummary || null,
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import type { OrchestratorSecret, Project, Schedule, Skill, BoardTask } from '@/types'
|
|
4
|
+
import { WORKSPACE_DIR } from './data-dir'
|
|
5
|
+
import { loadSchedules, loadSecrets, loadSkills, loadTasks } from './storage'
|
|
6
|
+
|
|
7
|
+
function normalizeText(value: unknown, maxLen = 400): string | undefined {
|
|
8
|
+
if (typeof value !== 'string') return undefined
|
|
9
|
+
const trimmed = value.replace(/\s+/g, ' ').trim()
|
|
10
|
+
if (!trimmed) return undefined
|
|
11
|
+
return trimmed.slice(0, maxLen)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function normalizeColor(value: unknown): string | undefined {
|
|
15
|
+
if (typeof value !== 'string') return undefined
|
|
16
|
+
const trimmed = value.trim()
|
|
17
|
+
if (!trimmed) return undefined
|
|
18
|
+
return trimmed.slice(0, 32)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function normalizeStringArray(value: unknown, maxItems = 8, maxLen = 160): string[] | undefined {
|
|
22
|
+
const rawItems = Array.isArray(value)
|
|
23
|
+
? value
|
|
24
|
+
: typeof value === 'string'
|
|
25
|
+
? value.split(/\r?\n|[,;]+/)
|
|
26
|
+
: []
|
|
27
|
+
const items = rawItems
|
|
28
|
+
.map((entry) => typeof entry === 'string' ? entry.replace(/\s+/g, ' ').trim() : '')
|
|
29
|
+
.filter(Boolean)
|
|
30
|
+
.slice(0, maxItems)
|
|
31
|
+
.map((entry) => entry.slice(0, maxLen))
|
|
32
|
+
return items.length > 0 ? items : undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function normalizeInteger(value: unknown, min: number, max: number): number | undefined {
|
|
36
|
+
const parsed = Number(value)
|
|
37
|
+
if (!Number.isFinite(parsed)) return undefined
|
|
38
|
+
return Math.max(min, Math.min(max, Math.trunc(parsed)))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function normalizeProjectCreateInput(input: Record<string, unknown>): Omit<Project, 'id' | 'createdAt' | 'updatedAt'> {
|
|
42
|
+
return {
|
|
43
|
+
name: normalizeText(input.name, 140) || 'Unnamed Project',
|
|
44
|
+
description: normalizeText(input.description, 4000) || '',
|
|
45
|
+
color: normalizeColor(input.color),
|
|
46
|
+
objective: normalizeText(input.objective, 240),
|
|
47
|
+
audience: normalizeText(input.audience, 240),
|
|
48
|
+
priorities: normalizeStringArray(input.priorities, 10),
|
|
49
|
+
openObjectives: normalizeStringArray(input.openObjectives, 12),
|
|
50
|
+
capabilityHints: normalizeStringArray(input.capabilityHints, 12),
|
|
51
|
+
credentialRequirements: normalizeStringArray(input.credentialRequirements, 12),
|
|
52
|
+
successMetrics: normalizeStringArray(input.successMetrics, 10),
|
|
53
|
+
heartbeatPrompt: normalizeText(input.heartbeatPrompt, 300),
|
|
54
|
+
heartbeatIntervalSec: normalizeInteger(input.heartbeatIntervalSec, 0, 86_400),
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function normalizeProjectPatchInput(input: Record<string, unknown>): Partial<Project> {
|
|
59
|
+
const patch: Partial<Project> = {}
|
|
60
|
+
|
|
61
|
+
if ('name' in input) patch.name = normalizeText(input.name, 140) || 'Unnamed Project'
|
|
62
|
+
if ('description' in input) patch.description = normalizeText(input.description, 4000) || ''
|
|
63
|
+
if ('color' in input) patch.color = normalizeColor(input.color)
|
|
64
|
+
if ('objective' in input) patch.objective = normalizeText(input.objective, 240)
|
|
65
|
+
if ('audience' in input) patch.audience = normalizeText(input.audience, 240)
|
|
66
|
+
if ('priorities' in input) patch.priorities = normalizeStringArray(input.priorities, 10) || []
|
|
67
|
+
if ('openObjectives' in input) patch.openObjectives = normalizeStringArray(input.openObjectives, 12) || []
|
|
68
|
+
if ('capabilityHints' in input) patch.capabilityHints = normalizeStringArray(input.capabilityHints, 12) || []
|
|
69
|
+
if ('credentialRequirements' in input) patch.credentialRequirements = normalizeStringArray(input.credentialRequirements, 12) || []
|
|
70
|
+
if ('successMetrics' in input) patch.successMetrics = normalizeStringArray(input.successMetrics, 10) || []
|
|
71
|
+
if ('heartbeatPrompt' in input) patch.heartbeatPrompt = normalizeText(input.heartbeatPrompt, 300)
|
|
72
|
+
if ('heartbeatIntervalSec' in input) patch.heartbeatIntervalSec = normalizeInteger(input.heartbeatIntervalSec, 0, 86_400)
|
|
73
|
+
|
|
74
|
+
return patch
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function projectWorkspaceRoot(projectId: string): string {
|
|
78
|
+
return path.join(WORKSPACE_DIR, 'projects', projectId)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function ensureProjectWorkspace(projectId: string, projectName?: string): string {
|
|
82
|
+
const root = projectWorkspaceRoot(projectId)
|
|
83
|
+
fs.mkdirSync(root, { recursive: true })
|
|
84
|
+
const readmePath = path.join(root, 'README.md')
|
|
85
|
+
if (!fs.existsSync(readmePath)) {
|
|
86
|
+
const title = (projectName || 'Project Workspace').trim() || 'Project Workspace'
|
|
87
|
+
fs.writeFileSync(readmePath, `# ${title}\n\nThis workspace belongs to project ${projectId}.\n`, 'utf8')
|
|
88
|
+
}
|
|
89
|
+
return root
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface ProjectResourceSummary {
|
|
93
|
+
openTaskCount: number
|
|
94
|
+
queuedTaskCount: number
|
|
95
|
+
runningTaskCount: number
|
|
96
|
+
activeScheduleCount: number
|
|
97
|
+
secretCount: number
|
|
98
|
+
skillCount: number
|
|
99
|
+
topTaskTitles: string[]
|
|
100
|
+
scheduleNames: string[]
|
|
101
|
+
secretNames: string[]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function byUpdatedDesc<T extends { updatedAt?: number; createdAt?: number }>(a: T, b: T): number {
|
|
105
|
+
return (Number(b.updatedAt || b.createdAt || 0) - Number(a.updatedAt || a.createdAt || 0))
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function summarizeProjectResources(projectId: string): ProjectResourceSummary {
|
|
109
|
+
const tasks = Object.values(loadTasks() as Record<string, BoardTask>)
|
|
110
|
+
.filter((task) => task?.projectId === projectId)
|
|
111
|
+
const schedules = Object.values(loadSchedules() as Record<string, Schedule>)
|
|
112
|
+
.filter((schedule) => schedule?.projectId === projectId)
|
|
113
|
+
const secrets = Object.values(loadSecrets() as Record<string, OrchestratorSecret & { projectId?: string }>)
|
|
114
|
+
.filter((secret) => secret?.projectId === projectId)
|
|
115
|
+
const skills = Object.values(loadSkills() as Record<string, Skill>)
|
|
116
|
+
.filter((skill) => skill?.projectId === projectId)
|
|
117
|
+
|
|
118
|
+
const openTasks = tasks
|
|
119
|
+
.filter((task) => ['backlog', 'queued', 'running'].includes(String(task.status || '').toLowerCase()))
|
|
120
|
+
.sort(byUpdatedDesc)
|
|
121
|
+
const activeSchedules = schedules
|
|
122
|
+
.filter((schedule) => String(schedule.status || '').toLowerCase() === 'active')
|
|
123
|
+
.sort(byUpdatedDesc)
|
|
124
|
+
const recentSecrets = secrets
|
|
125
|
+
.slice()
|
|
126
|
+
.sort(byUpdatedDesc)
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
openTaskCount: openTasks.length,
|
|
130
|
+
queuedTaskCount: openTasks.filter((task) => task.status === 'queued').length,
|
|
131
|
+
runningTaskCount: openTasks.filter((task) => task.status === 'running').length,
|
|
132
|
+
activeScheduleCount: activeSchedules.length,
|
|
133
|
+
secretCount: secrets.length,
|
|
134
|
+
skillCount: skills.length,
|
|
135
|
+
topTaskTitles: openTasks.slice(0, 3).map((task) => String(task.title || '').trim()).filter(Boolean),
|
|
136
|
+
scheduleNames: activeSchedules.slice(0, 3).map((schedule) => String(schedule.name || '').trim()).filter(Boolean),
|
|
137
|
+
secretNames: recentSecrets.slice(0, 3).map((secret) => String(secret.name || '').trim()).filter(Boolean),
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function buildProjectSnapshot(project: Project): Project & {
|
|
142
|
+
workspaceRoot: string
|
|
143
|
+
resourceSummary: ProjectResourceSummary
|
|
144
|
+
} {
|
|
145
|
+
return {
|
|
146
|
+
...project,
|
|
147
|
+
workspaceRoot: ensureProjectWorkspace(project.id, project.name),
|
|
148
|
+
resourceSummary: summarizeProjectResources(project.id),
|
|
149
|
+
}
|
|
150
|
+
}
|