@teamclaws/teamclaw 2026.8.1 → 2026.11.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/cli.mjs +46 -15
- package/dist/src/config.js +33 -2
- package/dist/src/controller/clarification-routes.js +315 -0
- package/dist/src/controller/controller-intake.js +895 -0
- package/dist/src/controller/controller-planning.js +813 -0
- package/dist/src/controller/controller-runs.js +175 -0
- package/dist/src/controller/controller-service.js +271 -40
- package/dist/src/controller/controller-tools.js +11 -6
- package/dist/src/controller/http-server.js +256 -6004
- package/dist/src/controller/kickoff-orchestrator.js +32 -6
- package/dist/src/controller/message-delivery.js +28 -0
- package/dist/src/controller/message-routes.js +114 -0
- package/dist/src/controller/orchestration-manifest.js +6 -28
- package/dist/src/controller/preview-proxy.js +98 -0
- package/dist/src/controller/profile-switch.js +289 -0
- package/dist/src/controller/project-registry.js +294 -0
- package/dist/src/controller/prompt-injector.js +19 -9
- package/dist/src/controller/repo-routes.js +63 -0
- package/dist/src/controller/role-inference.js +231 -20
- package/dist/src/controller/route-table.js +1353 -0
- package/dist/src/controller/task-assignment.js +508 -0
- package/dist/src/controller/task-cleanup.js +258 -0
- package/dist/src/controller/task-execution.js +240 -0
- package/dist/src/controller/task-results.js +461 -0
- package/dist/src/controller/task-router.js +74 -4
- package/dist/src/controller/task-routes.js +703 -0
- package/dist/src/controller/teamauto-routes.js +124 -0
- package/dist/src/controller/ui-assets.js +68 -0
- package/dist/src/controller/worker-provisioning.js +30 -4
- package/dist/src/controller/worker-routes.js +188 -0
- package/dist/src/identity.js +3 -2
- package/dist/src/interaction-contracts.js +7 -7
- package/dist/src/openclaw-workspace.js +40 -18
- package/dist/src/profile-loader.js +486 -0
- package/dist/src/profiles/banking.json +178 -0
- package/dist/src/profiles/crossborder-ecom.json +253 -0
- package/dist/src/profiles/insurance.json +157 -0
- package/dist/src/profiles/knowledge/hs-structure.md +97 -0
- package/dist/src/profiles/knowledge/incoterms-2020.md +188 -0
- package/dist/src/profiles/knowledge/vat-principles.md +85 -0
- package/dist/src/profiles/schema.json +201 -0
- package/dist/src/profiles/securities.json +137 -0
- package/dist/src/profiles/software-rd.json +264 -0
- package/dist/src/profiles/trading-co.json +200 -0
- package/dist/src/prompt-policy.js +26 -13
- package/dist/src/role-ids.js +29 -0
- package/dist/src/roles.js +54 -13
- package/dist/src/session-roles.js +14 -0
- package/dist/src/state.js +188 -10
- package/dist/src/task-executor.js +7 -17
- package/dist/src/teamauto/github-client.js +18 -0
- package/dist/src/teamauto/repo-sync.js +228 -6
- package/dist/src/teamauto/scanner.js +40 -12
- package/dist/src/teamauto/scheduler.js +231 -12
- package/dist/src/types.js +62 -15
- package/dist/src/ui/app.js +592 -24
- package/dist/src/ui/index.html +44 -11
- package/dist/src/ui/style.css +194 -0
- package/dist/src/worker/prompt-injector.js +44 -8
- package/dist/src/worker/skill-installer.js +3 -1
- package/dist/src/worker/worker-service.js +76 -3
- package/openclaw.plugin.json +28 -1
- package/package.json +3 -2
- package/src/config.ts +33 -2
- package/src/controller/clarification-routes.ts +404 -0
- package/src/controller/controller-intake.ts +1113 -0
- package/src/controller/controller-planning.ts +1029 -0
- package/src/controller/controller-runs.ts +239 -0
- package/src/controller/controller-service.ts +295 -41
- package/src/controller/controller-tools.ts +11 -7
- package/src/controller/http-server.ts +294 -6971
- package/src/controller/kickoff-orchestrator.ts +70 -7
- package/src/controller/message-delivery.ts +49 -0
- package/src/controller/message-routes.ts +137 -0
- package/src/controller/orchestration-manifest.ts +6 -29
- package/src/controller/preview-proxy.ts +127 -0
- package/src/controller/profile-switch.ts +366 -0
- package/src/controller/project-registry.ts +361 -0
- package/src/controller/prompt-injector.ts +23 -8
- package/src/controller/repo-routes.ts +91 -0
- package/src/controller/role-inference.ts +260 -22
- package/src/controller/route-table.ts +1616 -0
- package/src/controller/task-assignment.ts +618 -0
- package/src/controller/task-cleanup.ts +344 -0
- package/src/controller/task-execution.ts +356 -0
- package/src/controller/task-results.ts +544 -0
- package/src/controller/task-router.ts +98 -6
- package/src/controller/task-routes.ts +812 -0
- package/src/controller/teamauto-routes.ts +121 -0
- package/src/controller/ui-assets.ts +70 -0
- package/src/controller/websocket.ts +13 -1
- package/src/controller/worker-provisioning.ts +32 -4
- package/src/controller/worker-routes.ts +241 -0
- package/src/identity.ts +3 -2
- package/src/interaction-contracts.ts +7 -7
- package/src/openclaw-workspace.ts +44 -18
- package/src/profile-loader.ts +650 -0
- package/src/profiles/banking.json +178 -0
- package/src/profiles/crossborder-ecom.json +253 -0
- package/src/profiles/insurance.json +157 -0
- package/src/profiles/knowledge/hs-structure.md +97 -0
- package/src/profiles/knowledge/incoterms-2020.md +188 -0
- package/src/profiles/knowledge/vat-principles.md +85 -0
- package/src/profiles/schema.json +201 -0
- package/src/profiles/securities.json +137 -0
- package/src/profiles/software-rd.json +264 -0
- package/src/profiles/trading-co.json +200 -0
- package/src/prompt-policy.ts +27 -13
- package/src/role-ids.ts +31 -0
- package/src/roles.ts +60 -14
- package/src/session-roles.ts +14 -0
- package/src/state.ts +236 -9
- package/src/task-executor.ts +7 -18
- package/src/teamauto/github-client.ts +21 -0
- package/src/teamauto/repo-sync.ts +246 -6
- package/src/teamauto/scanner.ts +47 -13
- package/src/teamauto/scheduler.ts +259 -16
- package/src/teamauto/store.ts +12 -0
- package/src/types.ts +133 -16
- package/src/ui/app.js +592 -24
- package/src/ui/index.html +44 -11
- package/src/ui/style.css +194 -0
- package/src/worker/prompt-injector.ts +48 -8
- package/src/worker/skill-installer.ts +3 -1
- package/src/worker/worker-service.ts +83 -3
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
// PR-C of issue #204 (http-server monolith split): the controller project
|
|
2
|
+
// identity/registry family and the controller-run session queries extracted
|
|
3
|
+
// verbatim from controller/http-server.ts. Zero behavior change. This module
|
|
4
|
+
// must NEVER import http-server (the reverse edge exists:
|
|
5
|
+
// http-server -> project-registry); every function here is pure over
|
|
6
|
+
// TeamState/ControllerRunInfo snapshots.
|
|
7
|
+
import type {
|
|
8
|
+
ControllerRunInfo,
|
|
9
|
+
TeamState,
|
|
10
|
+
} from "../types.js";
|
|
11
|
+
import { deriveStableProjectKey } from "../openclaw-workspace.js";
|
|
12
|
+
import { normalizeControllerIntakeSessionKey } from "./task-execution.js";
|
|
13
|
+
|
|
14
|
+
const EXISTING_PROJECT_REUSE_HINT_RE = /\b(existing|optimi(?:s|z)e|optimi(?:s|z)ation|improvement|enhanc(?:e|ement)|follow[- ]?up|extend|update|bugfix|bug fix)\b/iu;
|
|
15
|
+
const GENERIC_PROJECT_FOLLOW_UP_RE = /\b(continue|continuing|next step|what else|what's next|follow[- ]?up|more|remaining)\b|继续|接下来|下一步|还有哪些|还可以做什么/u;
|
|
16
|
+
const PROJECT_MATCH_STOPWORDS = new Set([
|
|
17
|
+
"a",
|
|
18
|
+
"an",
|
|
19
|
+
"and",
|
|
20
|
+
"app",
|
|
21
|
+
"application",
|
|
22
|
+
"build",
|
|
23
|
+
"complete",
|
|
24
|
+
"existing",
|
|
25
|
+
"follow",
|
|
26
|
+
"for",
|
|
27
|
+
"hub",
|
|
28
|
+
"improvement",
|
|
29
|
+
"improvements",
|
|
30
|
+
"internal",
|
|
31
|
+
"optimization",
|
|
32
|
+
"product",
|
|
33
|
+
"project",
|
|
34
|
+
"requirement",
|
|
35
|
+
"request",
|
|
36
|
+
"studio",
|
|
37
|
+
"system",
|
|
38
|
+
"the",
|
|
39
|
+
"this",
|
|
40
|
+
"up",
|
|
41
|
+
"update",
|
|
42
|
+
"web",
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
export function resolveExistingProjectIdentityFromMessage(
|
|
46
|
+
message: string,
|
|
47
|
+
state: TeamState | null,
|
|
48
|
+
): { projectId?: string; projectDir?: string } | undefined {
|
|
49
|
+
const normalizedMessage = normalizeProjectMatchingText(message);
|
|
50
|
+
if (!normalizedMessage) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const explicitAlias = normalizeProjectMatchingText(extractExplicitProjectNameHint(message) ?? "");
|
|
54
|
+
|
|
55
|
+
let best: { projectId?: string; projectDir: string; score: number; updatedAt: number } | null = null;
|
|
56
|
+
const candidates = collectExistingProjectCandidates(state);
|
|
57
|
+
for (const candidate of candidates) {
|
|
58
|
+
const normalizedAliases = Array.from(candidate.aliases)
|
|
59
|
+
.map((alias) => normalizeProjectMatchingText(alias))
|
|
60
|
+
.filter(Boolean)
|
|
61
|
+
.reduce<string[]>((acc, alias) => {
|
|
62
|
+
acc.push(alias);
|
|
63
|
+
return acc;
|
|
64
|
+
}, []);
|
|
65
|
+
const hasExplicitAliasMatch = explicitAlias
|
|
66
|
+
? normalizedAliases.some((alias) => alias.includes(explicitAlias) || explicitAlias.includes(alias))
|
|
67
|
+
: false;
|
|
68
|
+
if (explicitAlias && !hasExplicitAliasMatch) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const aliasScore = normalizedAliases
|
|
72
|
+
.reduce((score, alias) => {
|
|
73
|
+
if (!alias) {
|
|
74
|
+
return score;
|
|
75
|
+
}
|
|
76
|
+
return normalizedMessage.includes(alias)
|
|
77
|
+
? Math.max(score, alias.split(" ").length + 10)
|
|
78
|
+
: score;
|
|
79
|
+
}, 0);
|
|
80
|
+
const tokenScore = scoreProjectTokenOverlap(normalizedMessage, candidate.searchText);
|
|
81
|
+
const totalScore = Math.max(aliasScore, tokenScore);
|
|
82
|
+
if (totalScore < 2) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (!best || totalScore > best.score || (totalScore === best.score && candidate.updatedAt > best.updatedAt)) {
|
|
86
|
+
best = {
|
|
87
|
+
projectId: candidate.projectId,
|
|
88
|
+
projectDir: candidate.projectDir,
|
|
89
|
+
score: totalScore,
|
|
90
|
+
updatedAt: candidate.updatedAt,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (best) {
|
|
95
|
+
return { projectId: best.projectId, projectDir: best.projectDir };
|
|
96
|
+
}
|
|
97
|
+
if ((EXISTING_PROJECT_REUSE_HINT_RE.test(message) || GENERIC_PROJECT_FOLLOW_UP_RE.test(message)) && candidates.length === 1) {
|
|
98
|
+
return {
|
|
99
|
+
projectId: candidates[0]?.projectId,
|
|
100
|
+
projectDir: candidates[0]?.projectDir,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function collectExistingProjectCandidates(state: TeamState | null): Array<{
|
|
107
|
+
projectId?: string;
|
|
108
|
+
projectDir: string;
|
|
109
|
+
aliases: Set<string>;
|
|
110
|
+
searchText: string;
|
|
111
|
+
updatedAt: number;
|
|
112
|
+
}> {
|
|
113
|
+
const byProjectDir = new Map<string, { projectId?: string; aliases: Set<string>; texts: string[]; updatedAt: number }>();
|
|
114
|
+
const addCandidate = (
|
|
115
|
+
projectDir: string | undefined,
|
|
116
|
+
text: string | undefined,
|
|
117
|
+
updatedAt: number,
|
|
118
|
+
alias?: string | null,
|
|
119
|
+
projectId?: string,
|
|
120
|
+
) => {
|
|
121
|
+
if (!projectDir) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const entry = byProjectDir.get(projectDir) ?? { projectId, aliases: new Set<string>(), texts: [], updatedAt: 0 };
|
|
125
|
+
if (!entry.projectId && projectId) {
|
|
126
|
+
entry.projectId = projectId;
|
|
127
|
+
}
|
|
128
|
+
if (text && text.trim()) {
|
|
129
|
+
entry.texts.push(text);
|
|
130
|
+
}
|
|
131
|
+
if (alias && alias.trim()) {
|
|
132
|
+
entry.aliases.add(alias.trim());
|
|
133
|
+
}
|
|
134
|
+
entry.updatedAt = Math.max(entry.updatedAt, updatedAt);
|
|
135
|
+
byProjectDir.set(projectDir, entry);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
for (const project of Object.values(state?.projects ?? {})) {
|
|
139
|
+
addCandidate(project.projectDir, project.summary, project.updatedAt, project.id, project.id);
|
|
140
|
+
for (const alias of project.aliases ?? []) {
|
|
141
|
+
addCandidate(project.projectDir, alias, project.updatedAt, alias, project.id);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (const run of Object.values(state?.controllerRuns ?? {})) {
|
|
145
|
+
addCandidate(run.projectDir, run.request, run.updatedAt, extractProjectAliasFromText(run.request), run.projectId);
|
|
146
|
+
addCandidate(run.projectDir, run.title, run.updatedAt, extractProjectAliasFromText(run.title), run.projectId);
|
|
147
|
+
addCandidate(run.projectDir, run.manifest?.projectName, run.updatedAt, run.manifest?.projectName, run.projectId);
|
|
148
|
+
}
|
|
149
|
+
for (const task of Object.values(state?.tasks ?? {})) {
|
|
150
|
+
addCandidate(task.projectDir, task.title, task.updatedAt, extractProjectAliasFromText(task.title), task.projectId);
|
|
151
|
+
addCandidate(task.projectDir, task.description, task.updatedAt, extractProjectAliasFromText(task.description), task.projectId);
|
|
152
|
+
addCandidate(task.projectDir, task.resultContract?.summary, task.updatedAt, null, task.projectId);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return Array.from(byProjectDir.entries()).map(([projectDir, entry]) => ({
|
|
156
|
+
projectId: entry.projectId,
|
|
157
|
+
projectDir,
|
|
158
|
+
aliases: entry.aliases,
|
|
159
|
+
searchText: entry.texts.join("\n"),
|
|
160
|
+
updatedAt: entry.updatedAt,
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function extractExplicitProjectNameHint(text: string | undefined): string | undefined {
|
|
165
|
+
const value = String(text ?? "");
|
|
166
|
+
const namedMatch = value.match(/(?:品牌|brand|project\s*name|产品名|名字)\s*[::]?\s*[`"'“”]?([a-z][a-z0-9_-]{1,39})[`"'“”]?/iu);
|
|
167
|
+
if (namedMatch?.[1]) {
|
|
168
|
+
return deriveStableProjectKey(namedMatch[1]);
|
|
169
|
+
}
|
|
170
|
+
const inlineNames = Array.from(value.matchAll(/`([a-z][a-z0-9_-]{1,39})`/giu))
|
|
171
|
+
.map((match) => deriveStableProjectKey(match[1]))
|
|
172
|
+
.filter(Boolean);
|
|
173
|
+
return inlineNames.length === 1 ? inlineNames[0] : undefined;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function findProjectRecordByDir(state: TeamState | null, projectDir: string | undefined) {
|
|
177
|
+
if (!state || !projectDir) {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
return Object.values(state.projects ?? {}).find((project) => project.projectDir === projectDir);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function syncProjectRegistryEntry(
|
|
184
|
+
state: TeamState,
|
|
185
|
+
input: {
|
|
186
|
+
projectId?: string;
|
|
187
|
+
projectDir?: string;
|
|
188
|
+
aliases?: Array<string | undefined | null>;
|
|
189
|
+
summary?: string;
|
|
190
|
+
updatedAt: number;
|
|
191
|
+
},
|
|
192
|
+
): { projectId?: string; projectDir?: string } {
|
|
193
|
+
state.projects = state.projects && typeof state.projects === "object" ? state.projects : {};
|
|
194
|
+
let normalizedProjectId = deriveStableProjectKey(input.projectId ?? "");
|
|
195
|
+
let existing = normalizedProjectId ? state.projects[normalizedProjectId] : undefined;
|
|
196
|
+
const byDir = findProjectRecordByDir(state, input.projectDir);
|
|
197
|
+
if (!existing && byDir) {
|
|
198
|
+
existing = byDir;
|
|
199
|
+
}
|
|
200
|
+
if (!existing && input.projectDir) {
|
|
201
|
+
normalizedProjectId = normalizedProjectId || deriveStableProjectKey(input.projectDir);
|
|
202
|
+
if (normalizedProjectId) {
|
|
203
|
+
existing = {
|
|
204
|
+
id: normalizedProjectId,
|
|
205
|
+
projectDir: input.projectDir,
|
|
206
|
+
aliases: [],
|
|
207
|
+
createdAt: input.updatedAt,
|
|
208
|
+
updatedAt: input.updatedAt,
|
|
209
|
+
lastUsedAt: input.updatedAt,
|
|
210
|
+
};
|
|
211
|
+
state.projects[normalizedProjectId] = existing;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (!existing) {
|
|
215
|
+
return { projectId: normalizedProjectId || undefined, projectDir: input.projectDir };
|
|
216
|
+
}
|
|
217
|
+
if (normalizedProjectId && existing.id !== normalizedProjectId && !state.projects[normalizedProjectId]) {
|
|
218
|
+
delete state.projects[existing.id];
|
|
219
|
+
existing.id = normalizedProjectId;
|
|
220
|
+
state.projects[normalizedProjectId] = existing;
|
|
221
|
+
}
|
|
222
|
+
if (!existing.projectDir && input.projectDir) {
|
|
223
|
+
existing.projectDir = input.projectDir;
|
|
224
|
+
}
|
|
225
|
+
const aliasSet = new Set(existing.aliases ?? []);
|
|
226
|
+
aliasSet.add(existing.id);
|
|
227
|
+
if (existing.projectDir) {
|
|
228
|
+
aliasSet.add(existing.projectDir);
|
|
229
|
+
}
|
|
230
|
+
for (const alias of input.aliases ?? []) {
|
|
231
|
+
const normalizedAlias = deriveStableProjectKey(String(alias ?? ""));
|
|
232
|
+
if (normalizedAlias) {
|
|
233
|
+
aliasSet.add(normalizedAlias);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
existing.aliases = Array.from(aliasSet);
|
|
237
|
+
existing.summary = input.summary || existing.summary;
|
|
238
|
+
existing.updatedAt = Math.max(existing.updatedAt || 0, input.updatedAt);
|
|
239
|
+
existing.lastUsedAt = Math.max(existing.lastUsedAt || 0, input.updatedAt);
|
|
240
|
+
return { projectId: existing.id, projectDir: existing.projectDir };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function resolveProjectIdentityForSession(
|
|
244
|
+
sessionKey: string,
|
|
245
|
+
state: TeamState | null,
|
|
246
|
+
): { projectId?: string; projectDir?: string } | undefined {
|
|
247
|
+
const runId = findLatestControllerRunIdForSession(sessionKey, state, { preferActive: true });
|
|
248
|
+
if (!runId) {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
const run = state?.controllerRuns[runId];
|
|
252
|
+
if (!run) {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
const project = findProjectRecordByDir(state, run.projectDir);
|
|
256
|
+
return {
|
|
257
|
+
projectId: run.projectId ?? project?.id,
|
|
258
|
+
projectDir: run.projectDir ?? project?.projectDir,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function resolveProjectIdentityForTaskId(
|
|
263
|
+
taskId: string,
|
|
264
|
+
state: TeamState | null,
|
|
265
|
+
): { projectId?: string; projectDir?: string } | undefined {
|
|
266
|
+
const task = state?.tasks?.[taskId];
|
|
267
|
+
if (!task) {
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
const project = findProjectRecordByDir(state, task.projectDir);
|
|
271
|
+
return {
|
|
272
|
+
projectId: task.projectId ?? project?.id,
|
|
273
|
+
projectDir: task.projectDir ?? project?.projectDir,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function extractProjectAliasFromText(text: string | undefined): string | null {
|
|
278
|
+
const firstMeaningfulLine = String(text ?? "")
|
|
279
|
+
.split(/\n+/u)
|
|
280
|
+
.map((line) => line.replace(/^#+\s*/u, "").trim())
|
|
281
|
+
.find(Boolean);
|
|
282
|
+
if (!firstMeaningfulLine) {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
const normalized = firstMeaningfulLine
|
|
286
|
+
.replace(/^(product|optimization)\s+requirement[::]\s*/iu, "")
|
|
287
|
+
.replace(/^implement\s+/iu, "")
|
|
288
|
+
.replace(/^design\s+/iu, "")
|
|
289
|
+
.replace(/^enhance\s+/iu, "")
|
|
290
|
+
.replace(/^qa[:\s-]+/iu, "")
|
|
291
|
+
.replace(/\s+(architecture|application|web app|workflows?|improvements?)$/iu, "")
|
|
292
|
+
.trim();
|
|
293
|
+
if (normalized.length < 4 || normalized.length > 80) {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
return normalized;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export function normalizeProjectMatchingText(text: string): string {
|
|
300
|
+
return text
|
|
301
|
+
.toLowerCase()
|
|
302
|
+
.replace(/[`*_#:[\]()/\\-]+/gu, " ")
|
|
303
|
+
.replace(/\s+/gu, " ")
|
|
304
|
+
.trim();
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export function scoreProjectTokenOverlap(message: string, candidateText: string): number {
|
|
308
|
+
const messageTokens = tokenizeProjectMatchingText(message);
|
|
309
|
+
if (messageTokens.size === 0) {
|
|
310
|
+
return 0;
|
|
311
|
+
}
|
|
312
|
+
const candidateTokens = tokenizeProjectMatchingText(candidateText);
|
|
313
|
+
let overlap = 0;
|
|
314
|
+
for (const token of candidateTokens) {
|
|
315
|
+
if (messageTokens.has(token)) {
|
|
316
|
+
overlap += 1;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return overlap;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export function tokenizeProjectMatchingText(text: string): Set<string> {
|
|
323
|
+
return new Set(
|
|
324
|
+
normalizeProjectMatchingText(text)
|
|
325
|
+
.split(" ")
|
|
326
|
+
.map((token) => token.trim())
|
|
327
|
+
.filter((token) => token.length >= 4 && !PROJECT_MATCH_STOPWORDS.has(token)),
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export function isActiveControllerRun(run: ControllerRunInfo): boolean {
|
|
332
|
+
return run.status === "pending" || run.status === "running";
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export function findLatestControllerRunIdForSession(
|
|
336
|
+
sessionKey: string,
|
|
337
|
+
state: TeamState | null,
|
|
338
|
+
options?: { preferActive?: boolean },
|
|
339
|
+
): string | null {
|
|
340
|
+
const normalizedSessionKey = normalizeControllerIntakeSessionKey(sessionKey);
|
|
341
|
+
const matchingRuns = Object.values(state?.controllerRuns ?? {})
|
|
342
|
+
.filter((run) => normalizeControllerIntakeSessionKey(run.sessionKey) === normalizedSessionKey)
|
|
343
|
+
.sort((left, right) => {
|
|
344
|
+
if (options?.preferActive) {
|
|
345
|
+
const leftScore = isActiveControllerRun(left) ? 1 : 0;
|
|
346
|
+
const rightScore = isActiveControllerRun(right) ? 1 : 0;
|
|
347
|
+
if (leftScore !== rightScore) {
|
|
348
|
+
return rightScore - leftScore;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return right.updatedAt - left.updatedAt;
|
|
352
|
+
});
|
|
353
|
+
return matchingRuns[0]?.id ?? null;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export function resolveProjectDirForSession(
|
|
357
|
+
sessionKey: string,
|
|
358
|
+
state: TeamState | null,
|
|
359
|
+
): string | undefined {
|
|
360
|
+
return resolveProjectIdentityForSession(sessionKey, state)?.projectDir;
|
|
361
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PluginConfig, TeamState } from "../types.js";
|
|
2
|
-
|
|
2
|
+
// Phase 1.3: the advertised role set comes from the active TeamProfile.
|
|
3
|
+
import { getActiveDomainInstructions, getActiveRoles } from "../profile-loader.js";
|
|
3
4
|
import {
|
|
4
5
|
buildControllerCompletionRules,
|
|
5
6
|
buildControllerDisciplineRules,
|
|
@@ -8,6 +9,7 @@ import {
|
|
|
8
9
|
buildControllerStructuredContractRules,
|
|
9
10
|
buildControllerToolRules,
|
|
10
11
|
buildControllerWorkflowRules,
|
|
12
|
+
buildRoleOperatingRules,
|
|
11
13
|
composePrompt,
|
|
12
14
|
} from "../prompt-policy.js";
|
|
13
15
|
import { hasOnDemandWorkerProvisioning, shouldBlockControllerWithoutWorkers } from "./controller-capacity.js";
|
|
@@ -15,11 +17,9 @@ import { resolveTeamClawWorkspaceDir } from "../openclaw-workspace.js";
|
|
|
15
17
|
import fs from "node:fs";
|
|
16
18
|
import path from "node:path";
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"designer", "marketing", "data-engineer",
|
|
22
|
-
];
|
|
20
|
+
// Phase 1.2: the local TEAMCLAW_ROLE_IDS_TEXT copy that used to live here was
|
|
21
|
+
// dead code (no references) and duplicated the canonical role id list; the
|
|
22
|
+
// shared text is exported from prompt-policy.ts (TEAMCLAW_ROLE_IDS_TEXT).
|
|
23
23
|
|
|
24
24
|
export type ControllerPromptDeps = {
|
|
25
25
|
config: PluginConfig;
|
|
@@ -60,7 +60,7 @@ export function createControllerPromptInjector(deps: ControllerPromptDeps) {
|
|
|
60
60
|
}
|
|
61
61
|
} else {
|
|
62
62
|
for (const w of workers) {
|
|
63
|
-
const roleDef =
|
|
63
|
+
const roleDef = getActiveRoles().find((r) => r.id === w.role);
|
|
64
64
|
const statusIcon = w.status === "idle" ? "[idle]" : w.status === "busy" ? "[busy]" : "[offline]";
|
|
65
65
|
const currentTask = w.currentTaskId ? ` (task: ${w.currentTaskId})` : "";
|
|
66
66
|
parts.push(`- ${roleDef?.icon ?? ""} ${w.label} (${w.id}) ${statusIcon}${currentTask}`);
|
|
@@ -89,13 +89,28 @@ export function createControllerPromptInjector(deps: ControllerPromptDeps) {
|
|
|
89
89
|
|
|
90
90
|
parts.push("");
|
|
91
91
|
parts.push("### Available Roles");
|
|
92
|
-
for (const role of
|
|
92
|
+
for (const role of getActiveRoles()) {
|
|
93
93
|
const skillLine = role.recommendedSkills.length > 0
|
|
94
94
|
? ` Recommended skills: ${role.recommendedSkills.join(", ")}.`
|
|
95
95
|
: "";
|
|
96
96
|
parts.push(`- ${role.icon} ${role.label}: ${role.description}.${skillLine}`);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
// Phase 2.4 (design 2.4): when the active profile carries industry
|
|
100
|
+
// guardrails, the controller's operating contract is replaced by them,
|
|
101
|
+
// assembled right after the role catalog (the controller-side analog of
|
|
102
|
+
// "after the role systemPrompt" on the worker pipeline). Profiles without
|
|
103
|
+
// domainInstructions (software-rd) inject nothing, so the controller
|
|
104
|
+
// prompt bytes are unchanged (Phase 1.7 golden).
|
|
105
|
+
const domainInstructions = getActiveDomainInstructions();
|
|
106
|
+
if (domainInstructions) {
|
|
107
|
+
parts.push(...buildRoleOperatingRules({
|
|
108
|
+
suggestedRoles: [],
|
|
109
|
+
recommendedSkills: [],
|
|
110
|
+
domainInstructions,
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
|
|
99
114
|
// List existing projects so the controller can distinguish new vs. existing
|
|
100
115
|
parts.push("");
|
|
101
116
|
parts.push("### Existing Projects in Workspace");
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// PR-B of issue #204 (http-server monolith split): the git collaboration
|
|
2
|
+
// read-side routes (GET /api/v1/repo status, GET /api/v1/repo/bundle export)
|
|
3
|
+
// and the repo state refresh glue extracted verbatim from
|
|
4
|
+
// controller/http-server.ts. Zero behavior change - the route shells in
|
|
5
|
+
// http-server keep the method+pathname matches and call these functions with
|
|
6
|
+
// the same deps object as before. This module must NEVER import http-server
|
|
7
|
+
// (the reverse edge exists: http-server -> repo-routes); POST /repo/import
|
|
8
|
+
// stays in http-server for now because its recordTaskExecutionEvent
|
|
9
|
+
// dependency is task-lifecycle glue owned by the PR-C cut.
|
|
10
|
+
import type { ServerResponse } from "node:http";
|
|
11
|
+
import type { PluginLogger } from "../../api.js";
|
|
12
|
+
import type { GitRepoState, PluginConfig, TeamState } from "../types.js";
|
|
13
|
+
import { sendJson, sendError } from "../protocol.js";
|
|
14
|
+
import { getActiveProfile } from "../profile-loader.js";
|
|
15
|
+
import { ensureControllerGitRepo, exportControllerGitBundle } from "../git-collaboration.js";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Structural slice of ControllerHttpDeps (http-server.ts) covering exactly
|
|
19
|
+
* the fields the repo route handlers and the refresh glue read. http-server
|
|
20
|
+
* keeps passing its full ControllerHttpDeps object; TypeScript structural
|
|
21
|
+
* typing accepts it, so no call site changes beyond the import path.
|
|
22
|
+
*/
|
|
23
|
+
export type RepoRouteDeps = {
|
|
24
|
+
config: PluginConfig;
|
|
25
|
+
logger: PluginLogger;
|
|
26
|
+
getTeamState: () => TeamState | null;
|
|
27
|
+
updateTeamState: (updater: (state: TeamState) => void) => TeamState;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export async function refreshControllerRepoState(deps: RepoRouteDeps): Promise<GitRepoState | null> {
|
|
31
|
+
// Phase 2.3: the ACTIVE PROFILE's git switch outranks the legacy config
|
|
32
|
+
// knob here - refreshing (or stamping) repo state for a profile that
|
|
33
|
+
// declared git off would re-introduce exactly the repo field the switch
|
|
34
|
+
// omitted for it (design 2.3: banking keeps no repo initialization). All
|
|
35
|
+
// callers already treat null as "no repo" (same as config gitEnabled off).
|
|
36
|
+
if (!deps.config.gitEnabled || !getActiveProfile().capabilities.git) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const repo = await ensureControllerGitRepo(deps.config, deps.logger);
|
|
42
|
+
if (repo) {
|
|
43
|
+
deps.updateTeamState((s) => {
|
|
44
|
+
s.repo = repo;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return repo;
|
|
48
|
+
} catch (err) {
|
|
49
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
50
|
+
deps.logger.warn(`Controller: failed to refresh git repo state: ${message}`);
|
|
51
|
+
deps.updateTeamState((s) => {
|
|
52
|
+
if (s.repo?.enabled) {
|
|
53
|
+
s.repo = {
|
|
54
|
+
...s.repo,
|
|
55
|
+
error: message,
|
|
56
|
+
lastPreparedAt: Date.now(),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return deps.getTeamState()?.repo ?? null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// GET /api/v1/repo
|
|
65
|
+
export async function handleRepoStatusRequest(deps: RepoRouteDeps, res: ServerResponse): Promise<void> {
|
|
66
|
+
const repo = await refreshControllerRepoState(deps);
|
|
67
|
+
if (!repo?.enabled) {
|
|
68
|
+
sendJson(res, 200, { enabled: false });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
sendJson(res, 200, { repo });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// GET /api/v1/repo/bundle
|
|
76
|
+
export async function handleRepoBundleRequest(deps: RepoRouteDeps, res: ServerResponse): Promise<void> {
|
|
77
|
+
try {
|
|
78
|
+
const exported = await exportControllerGitBundle(deps.config, deps.logger);
|
|
79
|
+
res.writeHead(200, {
|
|
80
|
+
"Content-Type": "application/octet-stream",
|
|
81
|
+
"Content-Length": exported.data.byteLength,
|
|
82
|
+
"Content-Disposition": `attachment; filename="${exported.filename}"`,
|
|
83
|
+
"Access-Control-Allow-Origin": "*",
|
|
84
|
+
"Access-Control-Allow-Methods": "GET, POST, PATCH, DELETE, OPTIONS",
|
|
85
|
+
"Access-Control-Allow-Headers": "Content-Type",
|
|
86
|
+
});
|
|
87
|
+
res.end(exported.data);
|
|
88
|
+
} catch (err) {
|
|
89
|
+
sendError(res, 503, err instanceof Error ? err.message : String(err));
|
|
90
|
+
}
|
|
91
|
+
}
|