@teamclaws/teamclaw 2026.8.1 → 2026.11.1
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 +318 -17
- package/dist/index.js +54 -32
- package/dist/src/config.js +57 -2
- package/dist/src/controller/auth-routes.js +129 -0
- 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 +814 -0
- package/dist/src/controller/controller-routes.js +195 -0
- package/dist/src/controller/controller-runs.js +175 -0
- package/dist/src/controller/controller-service.js +338 -50
- package/dist/src/controller/controller-tools.js +14 -7
- package/dist/src/controller/github-auth.js +2 -1
- package/dist/src/controller/http-server.js +290 -6003
- package/dist/src/controller/kickoff-orchestrator.js +33 -43
- package/dist/src/controller/message-delivery.js +31 -0
- package/dist/src/controller/message-routes.js +114 -0
- package/dist/src/controller/orchestration-manifest.js +11 -93
- package/dist/src/controller/preview-manager.js +51 -3
- package/dist/src/controller/preview-proxy.js +98 -0
- package/dist/src/controller/profile-switch.js +309 -0
- package/dist/src/controller/project-registry.js +294 -0
- package/dist/src/controller/prompt-injector.js +19 -9
- package/dist/src/controller/provisioning/backend-contract.js +9 -0
- package/dist/src/controller/provisioning/container-shared.js +64 -0
- package/dist/src/controller/provisioning/docker.js +214 -0
- package/dist/src/controller/provisioning/kubernetes.js +244 -0
- package/dist/src/controller/provisioning/plugin-root.js +41 -0
- package/dist/src/controller/provisioning/process-supervisor.js +190 -0
- package/dist/src/controller/provisioning-config.js +239 -0
- package/dist/src/controller/repo-routes.js +129 -0
- package/dist/src/controller/report-routes.js +56 -0
- package/dist/src/controller/role-inference.js +231 -20
- package/dist/src/controller/route-table.js +375 -0
- package/dist/src/controller/security.js +775 -0
- package/dist/src/controller/status-routes.js +287 -0
- package/dist/src/controller/task-assignment.js +511 -0
- package/dist/src/controller/task-cleanup.js +258 -0
- package/dist/src/controller/task-execution.js +271 -0
- package/dist/src/controller/task-results.js +471 -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/tunnel-manager.js +41 -8
- package/dist/src/controller/tunnel-routes.js +225 -0
- package/dist/src/controller/ui-assets.js +68 -0
- package/dist/src/controller/websocket.js +6 -2
- package/dist/src/controller/webui-routes.js +49 -0
- package/dist/src/controller/worker-provisioning.js +69 -953
- package/dist/src/controller/worker-routes.js +188 -0
- package/dist/src/controller/workflow-routes.js +407 -0
- package/dist/src/controller/workspace-routes.js +200 -0
- package/dist/src/git-collaboration.js +4 -9
- package/dist/src/identity.js +15 -3
- package/dist/src/interaction-contracts.js +7 -7
- package/dist/src/openclaw-workspace.js +40 -18
- package/dist/src/profile-loader.js +604 -0
- package/dist/src/profiles/banking.json +202 -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 +281 -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 +42 -17
- package/dist/src/protocol.js +66 -3
- 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/shared/clarification-schema.js +65 -0
- package/dist/src/shared/github-auth.js +15 -0
- package/dist/src/shared/kickoff-prompt.js +37 -0
- package/dist/src/shared/utils.js +47 -0
- package/dist/src/state.js +275 -11
- 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 +77 -16
- package/dist/src/ui/app.js +1434 -82
- package/dist/src/ui/github-login.html +1 -0
- package/dist/src/ui/index.html +144 -45
- package/dist/src/ui/style.css +194 -0
- package/dist/src/worker/http-handler.js +59 -0
- package/dist/src/worker/prompt-injector.js +44 -8
- package/dist/src/worker/skill-installer.js +6 -10
- package/dist/src/worker/tools.js +20 -10
- package/dist/src/worker/worker-service.js +93 -7
- package/index.ts +61 -32
- package/openclaw.plugin.json +50 -2
- package/package.json +3 -2
- package/src/config.ts +57 -2
- package/src/controller/auth-routes.ts +157 -0
- package/src/controller/clarification-routes.ts +404 -0
- package/src/controller/controller-intake.ts +1113 -0
- package/src/controller/controller-planning.ts +1037 -0
- package/src/controller/controller-routes.ts +237 -0
- package/src/controller/controller-runs.ts +239 -0
- package/src/controller/controller-service.ts +422 -50
- package/src/controller/controller-tools.ts +16 -9
- package/src/controller/github-auth.ts +28 -63
- package/src/controller/http-server.ts +336 -6964
- package/src/controller/kickoff-orchestrator.ts +69 -45
- package/src/controller/message-delivery.ts +52 -0
- package/src/controller/message-routes.ts +137 -0
- package/src/controller/orchestration-manifest.ts +14 -100
- package/src/controller/preview-manager.ts +53 -3
- package/src/controller/preview-proxy.ts +127 -0
- package/src/controller/profile-switch.ts +396 -0
- package/src/controller/project-registry.ts +361 -0
- package/src/controller/prompt-injector.ts +23 -8
- package/src/controller/provisioning/backend-contract.ts +51 -0
- package/src/controller/provisioning/container-shared.ts +84 -0
- package/src/controller/provisioning/docker.ts +260 -0
- package/src/controller/provisioning/kubernetes.ts +263 -0
- package/src/controller/provisioning/plugin-root.ts +42 -0
- package/src/controller/provisioning/process-supervisor.ts +214 -0
- package/src/controller/provisioning-config.ts +289 -0
- package/src/controller/repo-routes.ts +163 -0
- package/src/controller/report-routes.ts +64 -0
- package/src/controller/role-inference.ts +260 -22
- package/src/controller/route-table.ts +597 -0
- package/src/controller/security.ts +899 -0
- package/src/controller/status-routes.ts +354 -0
- package/src/controller/task-assignment.ts +622 -0
- package/src/controller/task-cleanup.ts +344 -0
- package/src/controller/task-execution.ts +399 -0
- package/src/controller/task-results.ts +556 -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/tunnel-manager.ts +45 -8
- package/src/controller/tunnel-routes.ts +231 -0
- package/src/controller/ui-assets.ts +70 -0
- package/src/controller/websocket.ts +32 -4
- package/src/controller/webui-routes.ts +55 -0
- package/src/controller/worker-provisioning.ts +83 -1121
- package/src/controller/worker-routes.ts +241 -0
- package/src/controller/workflow-routes.ts +498 -0
- package/src/controller/workspace-routes.ts +222 -0
- package/src/git-collaboration.ts +4 -9
- package/src/identity.ts +16 -3
- package/src/interaction-contracts.ts +7 -7
- package/src/openclaw-workspace.ts +44 -18
- package/src/profile-loader.ts +816 -0
- package/src/profiles/banking.json +202 -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 +281 -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 +44 -17
- package/src/protocol.ts +72 -2
- package/src/role-ids.ts +31 -0
- package/src/roles.ts +60 -14
- package/src/session-roles.ts +14 -0
- package/src/shared/clarification-schema.ts +81 -0
- package/src/shared/github-auth.ts +92 -0
- package/src/shared/kickoff-prompt.ts +47 -0
- package/src/shared/utils.ts +51 -0
- package/src/state.ts +326 -10
- package/src/task-executor.ts +7 -18
- package/src/teamauto/github-client.ts +23 -1
- package/src/teamauto/repo-sync.ts +248 -7
- package/src/teamauto/scanner.ts +47 -13
- package/src/teamauto/scheduler.ts +261 -17
- package/src/teamauto/store.ts +12 -0
- package/src/types.ts +263 -17
- package/src/ui/app.js +1434 -82
- package/src/ui/github-login.html +1 -0
- package/src/ui/index.html +144 -45
- package/src/ui/style.css +194 -0
- package/src/worker/http-handler.ts +64 -1
- package/src/worker/prompt-injector.ts +48 -8
- package/src/worker/skill-installer.ts +6 -10
- package/src/worker/tools.ts +21 -10
- package/src/worker/worker-service.ts +101 -7
package/src/prompt-policy.ts
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import type { RoleId } from "./types.js";
|
|
2
2
|
import { buildTeamClawProjectAgentRelativePath } from "./openclaw-workspace.js";
|
|
3
|
+
// Phase 1.2: the role id list is derived from the canonical role-ids.ts leaf
|
|
4
|
+
// module. prompt-policy.ts cannot value-import roles.ts (roles.ts imports
|
|
5
|
+
// this module and evaluates its builders at module init), so the dependency-
|
|
6
|
+
// free leaf keeps a single source of truth without a module cycle. roles.ts
|
|
7
|
+
// asserts its ROLES registry agrees with the same list.
|
|
8
|
+
import { ROLE_IDS } from "./role-ids.js";
|
|
9
|
+
import { getActiveRoleIds } from "./profile-loader.js";
|
|
3
10
|
|
|
4
|
-
export const TEAMCLAW_ROLE_IDS: RoleId[] =
|
|
5
|
-
"pm",
|
|
6
|
-
"architect",
|
|
7
|
-
"developer",
|
|
8
|
-
"qa",
|
|
9
|
-
"release-engineer",
|
|
10
|
-
"infra-engineer",
|
|
11
|
-
"devops",
|
|
12
|
-
"security-engineer",
|
|
13
|
-
"designer",
|
|
14
|
-
"marketing",
|
|
15
|
-
"data-engineer",
|
|
16
|
-
];
|
|
11
|
+
export const TEAMCLAW_ROLE_IDS: RoleId[] = ROLE_IDS;
|
|
17
12
|
|
|
18
13
|
export const TEAMCLAW_ROLE_IDS_TEXT = TEAMCLAW_ROLE_IDS.join(", ");
|
|
19
14
|
|
|
15
|
+
// #251 (design 2.3): the four role-list prompt injections must reflect the
|
|
16
|
+
// ACTIVE team profile, not the software-11 constant - a banking team must
|
|
17
|
+
// not be told to collaborate using "architect"/"release-engineer" IDs.
|
|
18
|
+
// profile-loader is runtime dependency-free (fs + JSON only), so importing
|
|
19
|
+
// it here cannot create a module cycle. Under software-rd the active list
|
|
20
|
+
// IS the canonical software-11 list, so baseline prompts are byte-identical.
|
|
21
|
+
function activeRoleIdsText(): string {
|
|
22
|
+
return getActiveRoleIds().join(", ");
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
type PromptSection = string | string[] | null | undefined | false;
|
|
21
26
|
|
|
22
27
|
export function composePrompt(...sections: PromptSection[]): string {
|
|
@@ -34,10 +39,32 @@ export function composePrompt(...sections: PromptSection[]): string {
|
|
|
34
39
|
return lines.join("\n");
|
|
35
40
|
}
|
|
36
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Phase 2.4 (design 2.1/2.4, replacement semantics): when the caller passes a
|
|
44
|
+
* non-empty `domainInstructions` (the active TeamProfile's industry
|
|
45
|
+
* guardrails), the domain lines REPLACE the software engineering operating
|
|
46
|
+
* rules wholesale - none of the software rules below are injected. Without
|
|
47
|
+
* the option (software-rd baseline, roles.ts registry init) the output is
|
|
48
|
+
* byte-identical to the pre-Phase-2.4 value, which the Phase 1.7 prompt
|
|
49
|
+
* goldens lock. The option is injected by the prompt pipelines (controller
|
|
50
|
+
* and worker prompt-injector) rather than read from the loader here.
|
|
51
|
+
* (#251 exception: the four role-LIST injections below now read
|
|
52
|
+
* getActiveRoleIds() directly - see activeRoleIdsText(). profile-loader is
|
|
53
|
+
* runtime dependency-free, so this still cannot cycle.)
|
|
54
|
+
*/
|
|
37
55
|
export function buildRoleOperatingRules(options: {
|
|
38
56
|
suggestedRoles: string[];
|
|
39
57
|
recommendedSkills: string[];
|
|
58
|
+
domainInstructions?: string[];
|
|
40
59
|
}): string[] {
|
|
60
|
+
const domainInstructions = options.domainInstructions ?? [];
|
|
61
|
+
if (domainInstructions.length > 0) {
|
|
62
|
+
return [
|
|
63
|
+
"",
|
|
64
|
+
"## TeamClaw Operating Contract",
|
|
65
|
+
...domainInstructions,
|
|
66
|
+
];
|
|
67
|
+
}
|
|
41
68
|
const suggestedRoles = options.suggestedRoles.length > 0 ? options.suggestedRoles.join(", ") : "none";
|
|
42
69
|
const recommendedSkills = options.recommendedSkills.length > 0 ? options.recommendedSkills.join(", ") : "none";
|
|
43
70
|
return [
|
|
@@ -56,7 +83,7 @@ export function buildRoleOperatingRules(options: {
|
|
|
56
83
|
"- Treat other workers' OpenClaw sessions and session keys as unavailable; use the shared workspace, the current task context, and teammate messages instead of trying cross-session inspection.",
|
|
57
84
|
"- Do not mark a task completed or failed via progress updates. Finish by returning the deliverable or raising the blocking error so TeamClaw can close the task correctly.",
|
|
58
85
|
"- Do not infer ownership, license scope, or lack of user authorization from technical characteristics such as proprietary branding, bundled assets, binary files, minified code, or repository layout. Focus on technical feasibility and the user's explicit requirements.",
|
|
59
|
-
`- Use exact TeamClaw role IDs when collaborating: ${
|
|
86
|
+
`- Use exact TeamClaw role IDs when collaborating: ${activeRoleIdsText()}.`,
|
|
60
87
|
`- If a true follow-up is required after your deliverable, prefer these exact next roles: ${suggestedRoles}.`,
|
|
61
88
|
`- Default starter skills for this role: ${recommendedSkills}. If the task includes more specific recommended skills, prefer those.`,
|
|
62
89
|
];
|
|
@@ -90,7 +117,7 @@ export function buildWorkerSessionRules(): string[] {
|
|
|
90
117
|
"7. If another role must continue later, use review/handoff tools on the current task instead of spawning work.",
|
|
91
118
|
"8. Other workers' OpenClaw sessions are isolated from this worker. Do not attempt cross-session inspection; use task context, the shared workspace, and queued team messages instead.",
|
|
92
119
|
"9. Do not mark the task completed or failed via progress updates. Return the final deliverable and let TeamClaw close the task.",
|
|
93
|
-
`10. Valid TeamClaw role IDs: ${
|
|
120
|
+
`10. Valid TeamClaw role IDs: ${activeRoleIdsText()}.`,
|
|
94
121
|
"11. Treat file paths from documents, plans, and teammate messages as hints, not guarantees. Verify the real path exists in the current workspace before reading or editing it; if it does not exist, search for the closest real file and note the drift instead of repeatedly calling missing paths.",
|
|
95
122
|
"12. The workspace may be backed by a TeamClaw-managed git repository. Treat the current checkout as canonical project state; do not delete `.git` or replace the repo with ad-hoc archives.",
|
|
96
123
|
"13. If the assigned task includes recommended skills, use those exact skill slugs first. Missing skills should be searched/installed before execution when supported by the runtime.",
|
|
@@ -125,7 +152,7 @@ export function buildTaskExecutionRules(rateLimitWaitingSentinel: string): strin
|
|
|
125
152
|
`- Do NOT use sessions_yield or end your turn while background work, coding agents, or process sessions are still running; if the task is not complete yet, reply with exactly ${rateLimitWaitingSentinel}.`,
|
|
126
153
|
"- Never return 'running in background' as the final result for a TeamClaw task. If you spawn a helper session, keep monitoring it and only return after you have the actual deliverable.",
|
|
127
154
|
"- Use structured fields on progress, review, handoff, and messaging tools whenever coordination is needed.",
|
|
128
|
-
`- When naming a role, use exact TeamClaw role IDs: ${
|
|
155
|
+
`- When naming a role, use exact TeamClaw role IDs: ${activeRoleIdsText()}.`,
|
|
129
156
|
];
|
|
130
157
|
}
|
|
131
158
|
|
|
@@ -378,7 +405,7 @@ export function buildControllerDisciplineRules(options: { canProvisionWithoutWor
|
|
|
378
405
|
? "- If no workers are currently registered but on-demand provisioning is enabled, you may still create execution-ready tasks so the required roles can be provisioned."
|
|
379
406
|
: "- If no workers are registered, you may mention which roles would be needed, but stop there and report the worker-capacity block to the human.",
|
|
380
407
|
"- Use the controller itself for requirement analysis; use the PM role only for PM-owned deliverables after intake is clear.",
|
|
381
|
-
`- Use exact TeamClaw role IDs only: ${
|
|
408
|
+
`- Use exact TeamClaw role IDs only: ${activeRoleIdsText()}.`,
|
|
382
409
|
"- Never guess or summarize a worker's unfinished output as if it were a completed result. While work is still in flight, report only current status plus the next concrete step.",
|
|
383
410
|
"- Never fabricate downstream readiness from intent alone. Downstream creation requires evidence: completed task state, a structured result contract, concrete deliverables, or an explicit handoff.",
|
|
384
411
|
"- Never ask the human to manually run an obvious machine step such as rebuild/retest/repro/verification (for example git pull, go build, npm test, rerun and report whether it still crashes) when TeamClaw can create an execution task and do that work itself.",
|
package/src/protocol.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
1
2
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
3
|
import type { HeartbeatPayload, RegistrationRequest, RoleId } from "./types.js";
|
|
3
4
|
|
|
@@ -7,12 +8,64 @@ export const HEARTBEAT_MS = 10000;
|
|
|
7
8
|
export const WORKER_TIMEOUT_MS = 30000;
|
|
8
9
|
export const API_PREFIX = "/api/v1";
|
|
9
10
|
|
|
11
|
+
// Issue #255 P0-1: id fragments used to come from the V8 Math PRNG
|
|
12
|
+
// (xorshift128+ - the internal state is recoverable from a handful of
|
|
13
|
+
// observed outputs, so past fragments leak future ones). Fragments now
|
|
14
|
+
// derive from the CSPRNG. The output shape (timestamp + 6 base36 chars) is
|
|
15
|
+
// kept byte-compatible so no generateId consumer sees a format change.
|
|
16
|
+
const ID_FRAGMENT_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
17
|
+
|
|
18
|
+
function randomIdFragment(length = 6): string {
|
|
19
|
+
let fragment = "";
|
|
20
|
+
while (fragment.length < length) {
|
|
21
|
+
for (const byte of randomBytes(length * 2)) {
|
|
22
|
+
// 256 is not a multiple of 36: bytes >= 252 would bias the last four
|
|
23
|
+
// alphabet symbols - reject them and draw again.
|
|
24
|
+
if (byte >= 252) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
fragment += ID_FRAGMENT_ALPHABET[byte % 36]!;
|
|
28
|
+
if (fragment.length === length) {
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return fragment;
|
|
34
|
+
}
|
|
35
|
+
|
|
10
36
|
function generateId(): string {
|
|
11
37
|
const ts = Date.now().toString(36);
|
|
12
|
-
const rand =
|
|
38
|
+
const rand = randomIdFragment();
|
|
13
39
|
return `${ts}-${rand}`;
|
|
14
40
|
}
|
|
15
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Issue #255 P0-1: bearer token a provisioned worker must present at
|
|
44
|
+
* registration (and that the controller echoes on task dispatch). 256 bits
|
|
45
|
+
* from the CSPRNG, hex-encoded. This is an internal value with no external
|
|
46
|
+
* format contract - it travels controller -> worker through the
|
|
47
|
+
* TEAMCLAW_LAUNCH_TOKEN env var and is only ever equality-checked - so the
|
|
48
|
+
* old `${generateId()}-${generateId()}` shape (two ~31-bit xorshift128+
|
|
49
|
+
* fragments) is replaced outright. Tokens minted by older builds stay valid:
|
|
50
|
+
* the check is an equality either way (now constant-time), only generation
|
|
51
|
+
* changes.
|
|
52
|
+
*/
|
|
53
|
+
function generateLaunchToken(): string {
|
|
54
|
+
return randomBytes(32).toString("hex");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Constant-time string equality for secrets (length guard: token length is
|
|
58
|
+
* a public format detail, not secret content).
|
|
59
|
+
* #259 follow-up: canonical home is this leaf module so controller leaves
|
|
60
|
+
* (worker-provisioning) can compare secrets without importing
|
|
61
|
+
* controller/security.ts, which would close a module cycle
|
|
62
|
+
* (http-server <-> route-table <-> security <-> worker-provisioning). */
|
|
63
|
+
export function secretsEqual(a: string, b: string): boolean {
|
|
64
|
+
const left = Buffer.from(a, "utf8");
|
|
65
|
+
const right = Buffer.from(b, "utf8");
|
|
66
|
+
return left.length === right.length && timingSafeEqual(left, right);
|
|
67
|
+
}
|
|
68
|
+
|
|
16
69
|
async function parseJsonBody(req: IncomingMessage): Promise<Record<string, unknown>> {
|
|
17
70
|
const raw = await readRequestBody(req);
|
|
18
71
|
if (!raw.length) {
|
|
@@ -37,12 +90,27 @@ async function readRequestBody(req: IncomingMessage): Promise<Buffer> {
|
|
|
37
90
|
});
|
|
38
91
|
}
|
|
39
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Issue #23: the Access-Control-Allow-Origin value a response should carry.
|
|
95
|
+
* A header the security gate PINNED before dispatch (device protection on:
|
|
96
|
+
* same-origin echo, or an explicit empty value for foreign origins) wins;
|
|
97
|
+
* with nothing pinned (protection off / non-browser requests) the value is
|
|
98
|
+
* the historical wildcard, byte for byte. Every response path that sets
|
|
99
|
+
* ACAO (sendJson here, the raw-file and repo-bundle octet-stream writers in
|
|
100
|
+
* the controller routes) must go through this helper so no route can widen
|
|
101
|
+
* a pinned response back to the L0 wildcard.
|
|
102
|
+
*/
|
|
103
|
+
function pinnedCorsAllowOrigin(res: ServerResponse): string {
|
|
104
|
+
const pinned = res.getHeader("Access-Control-Allow-Origin");
|
|
105
|
+
return typeof pinned === "string" ? pinned : "*";
|
|
106
|
+
}
|
|
107
|
+
|
|
40
108
|
function sendJson(res: ServerResponse, status: number, data: unknown): void {
|
|
41
109
|
const body = JSON.stringify(data);
|
|
42
110
|
res.writeHead(status, {
|
|
43
111
|
"Content-Type": "application/json",
|
|
44
112
|
"Content-Length": Buffer.byteLength(body),
|
|
45
|
-
"Access-Control-Allow-Origin":
|
|
113
|
+
"Access-Control-Allow-Origin": pinnedCorsAllowOrigin(res),
|
|
46
114
|
"Access-Control-Allow-Methods": "GET, POST, PATCH, DELETE, OPTIONS",
|
|
47
115
|
"Access-Control-Allow-Headers": "Content-Type",
|
|
48
116
|
});
|
|
@@ -79,10 +147,12 @@ function createHeartbeatPayload(
|
|
|
79
147
|
|
|
80
148
|
export {
|
|
81
149
|
generateId,
|
|
150
|
+
generateLaunchToken,
|
|
82
151
|
parseJsonBody,
|
|
83
152
|
readRequestBody,
|
|
84
153
|
sendJson,
|
|
85
154
|
sendError,
|
|
155
|
+
pinnedCorsAllowOrigin,
|
|
86
156
|
createRegistrationRequest,
|
|
87
157
|
createHeartbeatPayload,
|
|
88
158
|
};
|
package/src/role-ids.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { RoleId } from "./types.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Canonical ordered TeamClaw role id list (Phase 1.2 single-source
|
|
5
|
+
* convergence, vertical-team-profiles-design.md section 1.1).
|
|
6
|
+
*
|
|
7
|
+
* This module is deliberately dependency-free (type-only import) so it can be
|
|
8
|
+
* imported from anywhere - including prompt-policy.ts and
|
|
9
|
+
* openclaw-workspace.ts, which sit BELOW roles.ts in the module graph and
|
|
10
|
+
* therefore cannot value-import roles.ts without creating a cycle
|
|
11
|
+
* (roles.ts -> prompt-policy.ts -> openclaw-workspace.ts at runtime).
|
|
12
|
+
*
|
|
13
|
+
* roles.ts keeps ROLE_IDS derived from its ROLES registry and asserts at
|
|
14
|
+
* module init that both lists agree, so this file and the registry can never
|
|
15
|
+
* silently drift apart. The manifest generator
|
|
16
|
+
* (scripts/sync-teamclaw-plugin-manifest.mjs) extracts this array from the
|
|
17
|
+
* source text so openclaw.plugin.json derives from the same list.
|
|
18
|
+
*/
|
|
19
|
+
export const ROLE_IDS: RoleId[] = [
|
|
20
|
+
"pm",
|
|
21
|
+
"architect",
|
|
22
|
+
"developer",
|
|
23
|
+
"qa",
|
|
24
|
+
"release-engineer",
|
|
25
|
+
"infra-engineer",
|
|
26
|
+
"devops",
|
|
27
|
+
"security-engineer",
|
|
28
|
+
"designer",
|
|
29
|
+
"marketing",
|
|
30
|
+
"data-engineer",
|
|
31
|
+
];
|
package/src/roles.ts
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import type { RoleDefinition, RoleId } from "./types.js";
|
|
2
2
|
import { buildRoleOperatingRules, buildWorkerMemoryContractRules, composePrompt } from "./prompt-policy.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"qa",
|
|
9
|
-
"release-engineer",
|
|
10
|
-
"infra-engineer",
|
|
11
|
-
"devops",
|
|
12
|
-
"security-engineer",
|
|
13
|
-
"designer",
|
|
14
|
-
"marketing",
|
|
15
|
-
"data-engineer",
|
|
16
|
-
];
|
|
3
|
+
// Phase 1.2 single-source convergence: the canonical role id list lives in
|
|
4
|
+
// the dependency-free role-ids.ts leaf (importable by prompt-policy.ts and
|
|
5
|
+
// openclaw-workspace.ts, which sit below this module). The guard below makes
|
|
6
|
+
// this registry and that list impossible to drift apart silently.
|
|
7
|
+
import { ROLE_IDS as CANONICAL_ROLE_IDS } from "./role-ids.js";
|
|
17
8
|
|
|
18
9
|
const ROLES: RoleDefinition[] = [
|
|
19
10
|
{
|
|
@@ -325,6 +316,61 @@ for (const role of ROLES) {
|
|
|
325
316
|
const ROLE_MAP = new Map<string, RoleDefinition>(ROLES.map((r) => [r.id, r]));
|
|
326
317
|
const ROLE_IDS: RoleId[] = ROLES.map((r) => r.id);
|
|
327
318
|
|
|
319
|
+
// Fail fast when the ROLES registry and the canonical role-ids.ts list
|
|
320
|
+
// disagree (length, order, or membership): every consumer of either module
|
|
321
|
+
// must see exactly one role set.
|
|
322
|
+
if (ROLE_IDS.length !== CANONICAL_ROLE_IDS.length || ROLE_IDS.some((id, index) => id !== CANONICAL_ROLE_IDS[index])) {
|
|
323
|
+
const registryOnly = ROLE_IDS.filter((id) => !CANONICAL_ROLE_IDS.includes(id));
|
|
324
|
+
const leafOnly = CANONICAL_ROLE_IDS.filter((id) => !ROLE_IDS.includes(id));
|
|
325
|
+
throw new Error(
|
|
326
|
+
`roles.ts ROLES ids and role-ids.ts ROLE_IDS have drifted apart - update both so the registry, prompts, and manifest stay in sync `
|
|
327
|
+
+ `(registry-only: [${registryOnly.join(", ")}]; role-ids.ts-only: [${leafOnly.join(", ")}])`,
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Phase 0.3 convergence point for `as RoleId` casts: validate an untrusted
|
|
333
|
+
* value against the registered role ids. Returns the trimmed role id when
|
|
334
|
+
* `raw` is a string that matches a registered role, otherwise `undefined`.
|
|
335
|
+
* Never throws — callers treat invalid input exactly like a missing field.
|
|
336
|
+
* Semantics intentionally mirror the former normalizeContractRole guard in
|
|
337
|
+
* interaction-contracts.ts, which now delegates here.
|
|
338
|
+
*/
|
|
339
|
+
export function validateRoleId(raw: unknown): RoleId | undefined {
|
|
340
|
+
if (typeof raw !== "string") {
|
|
341
|
+
return undefined;
|
|
342
|
+
}
|
|
343
|
+
return ROLE_MAP.get(raw.trim())?.id;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Array-filtering counterpart of validateRoleId: keeps order, drops
|
|
348
|
+
* non-strings, blank entries, and unknown roles, and dedupes by first
|
|
349
|
+
* occurrence. Phase 0.3 replaces the per-file list guards (types.ts
|
|
350
|
+
* parseRoleList, orchestration-manifest.ts normalizeManifestRoleList).
|
|
351
|
+
*/
|
|
352
|
+
export function validateRoleIdList(raw: unknown): RoleId[] {
|
|
353
|
+
if (!Array.isArray(raw)) {
|
|
354
|
+
return [];
|
|
355
|
+
}
|
|
356
|
+
const roleIds: RoleId[] = [];
|
|
357
|
+
for (const entry of raw) {
|
|
358
|
+
const roleId = validateRoleId(entry);
|
|
359
|
+
if (roleId && !roleIds.includes(roleId)) {
|
|
360
|
+
roleIds.push(roleId);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return roleIds;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Single source of truth for the fallback role used when no better signal
|
|
368
|
+
* exists (role inference miss, unconfigured startup provisioning, unset
|
|
369
|
+
* worker config role). Callers must import this constant instead of
|
|
370
|
+
* hardcoding a role id.
|
|
371
|
+
*/
|
|
372
|
+
export const DEFAULT_ROLE: RoleId = "developer";
|
|
373
|
+
|
|
328
374
|
function getRole(id: RoleId): RoleDefinition | undefined {
|
|
329
375
|
return ROLE_MAP.get(id);
|
|
330
376
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-role string normalization, shared by the controller http-server and
|
|
3
|
+
* the worker task executor (single source since issue #204's dedupe finding).
|
|
4
|
+
*/
|
|
5
|
+
export function normalizeSessionRole(value: unknown): string {
|
|
6
|
+
if (typeof value !== "string") {
|
|
7
|
+
return "";
|
|
8
|
+
}
|
|
9
|
+
const normalized = value.trim().toLowerCase().replace(/[-\s]+/g, "_");
|
|
10
|
+
if (normalized === "toolresult") {
|
|
11
|
+
return "tool_result";
|
|
12
|
+
}
|
|
13
|
+
return normalized;
|
|
14
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Shared contracts layer (issue #226, W3): the structured clarification
|
|
2
|
+
// question schema normalization family, lifted verbatim from
|
|
3
|
+
// controller/orchestration-manifest.ts. The worker imports this contract
|
|
4
|
+
// (worker/tools.ts asks the question schema through it), so it must live in
|
|
5
|
+
// the shared layer — worker must never import the controller tree. The
|
|
6
|
+
// manifest-specific normalizers (role lists, created/deferred tasks,
|
|
7
|
+
// completion opportunities) stay in orchestration-manifest.ts and now import
|
|
8
|
+
// this module (controller -> shared direction only).
|
|
9
|
+
import type {
|
|
10
|
+
ClarificationQuestionOption,
|
|
11
|
+
ClarificationQuestionSchema,
|
|
12
|
+
} from "../types.js";
|
|
13
|
+
|
|
14
|
+
export function normalizeOptionalManifestText(raw: unknown): string | undefined {
|
|
15
|
+
if (typeof raw !== "string") {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const normalized = raw.trim();
|
|
19
|
+
return normalized || undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function normalizeClarificationOptions(raw: unknown): ClarificationQuestionOption[] {
|
|
23
|
+
if (!Array.isArray(raw)) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
return raw
|
|
27
|
+
.filter((entry): entry is Record<string, unknown> => !!entry && typeof entry === "object")
|
|
28
|
+
.map((entry) => ({
|
|
29
|
+
value: typeof entry.value === "string" ? entry.value.trim() : "",
|
|
30
|
+
label: typeof entry.label === "string" ? entry.label.trim() : "",
|
|
31
|
+
hint: typeof entry.hint === "string" && entry.hint.trim() ? entry.hint.trim() : undefined,
|
|
32
|
+
}))
|
|
33
|
+
.filter((entry) => entry.value && entry.label);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function normalizeClarificationQuestionSchema(raw: unknown): ClarificationQuestionSchema | undefined {
|
|
37
|
+
if (!raw || typeof raw !== "object") {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const input = raw as Record<string, unknown>;
|
|
41
|
+
const kind = typeof input.kind === "string" ? input.kind.trim() : "";
|
|
42
|
+
const title = typeof input.title === "string" ? input.title.trim() : "";
|
|
43
|
+
if (!title || !["single-select", "multi-select", "number", "text"].includes(kind)) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const options = normalizeClarificationOptions(input.options);
|
|
47
|
+
const schema: ClarificationQuestionSchema = {
|
|
48
|
+
kind: kind as ClarificationQuestionSchema["kind"],
|
|
49
|
+
title,
|
|
50
|
+
description: normalizeOptionalManifestText(input.description),
|
|
51
|
+
required: input.required == null ? true : Boolean(input.required),
|
|
52
|
+
allowOther: Boolean(input.allowOther),
|
|
53
|
+
placeholder: normalizeOptionalManifestText(input.placeholder),
|
|
54
|
+
unit: normalizeOptionalManifestText(input.unit),
|
|
55
|
+
};
|
|
56
|
+
if (options.length > 0) {
|
|
57
|
+
schema.options = options;
|
|
58
|
+
}
|
|
59
|
+
if (typeof input.min === "number" && Number.isFinite(input.min)) {
|
|
60
|
+
schema.min = input.min;
|
|
61
|
+
}
|
|
62
|
+
if (typeof input.max === "number" && Number.isFinite(input.max)) {
|
|
63
|
+
schema.max = input.max;
|
|
64
|
+
}
|
|
65
|
+
if (typeof input.step === "number" && Number.isFinite(input.step)) {
|
|
66
|
+
schema.step = input.step;
|
|
67
|
+
}
|
|
68
|
+
if ((schema.kind === "single-select" || schema.kind === "multi-select") && (!schema.options || schema.options.length === 0)) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
return schema;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function normalizeClarificationQuestionSchemas(raw: unknown): ClarificationQuestionSchema[] {
|
|
75
|
+
if (!Array.isArray(raw)) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
return raw
|
|
79
|
+
.map((entry) => normalizeClarificationQuestionSchema(entry))
|
|
80
|
+
.filter((entry): entry is ClarificationQuestionSchema => Boolean(entry));
|
|
81
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Shared contracts layer (issue #226, W5): the GitHub auth manager TYPE
|
|
2
|
+
// contract. The teamauto subsystem consumes this type (github-client,
|
|
3
|
+
// scheduler, repo-sync all take a GithubAuthManager), so the cross-subsystem
|
|
4
|
+
// contract lives here — teamauto must not import the controller tree. Only
|
|
5
|
+
// types moved; the factory (createGithubAuthManager) and the singleton cache
|
|
6
|
+
// (getGithubAuthManager) stay in controller/github-auth.ts, which annotates
|
|
7
|
+
// the factory's return type with this contract so the compiler keeps the
|
|
8
|
+
// structural definition in lockstep with the implementation.
|
|
9
|
+
//
|
|
10
|
+
// GithubAuthManager was previously `ReturnType<typeof createGithubAuthManager>`;
|
|
11
|
+
// the explicit structural form below is signature-identical (each member
|
|
12
|
+
// mirrors one returned closure verbatim) and no longer requires importing the
|
|
13
|
+
// controller factory to name the type.
|
|
14
|
+
|
|
15
|
+
/** GitHub account profile loaded from /user at login time. */
|
|
16
|
+
export type GithubAccountInfo = {
|
|
17
|
+
id: number;
|
|
18
|
+
login: string;
|
|
19
|
+
name: string | null;
|
|
20
|
+
avatarUrl: string | null;
|
|
21
|
+
htmlUrl: string | null;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type GithubAuthStore = {
|
|
25
|
+
version: number;
|
|
26
|
+
clientId: string;
|
|
27
|
+
/** Which OAuth flow produced this token; device-flow tokens refresh without a client secret. */
|
|
28
|
+
flowOrigin: "device" | "web";
|
|
29
|
+
account: GithubAccountInfo | null;
|
|
30
|
+
accessToken: string;
|
|
31
|
+
refreshToken: string | null;
|
|
32
|
+
obtainedAt: number;
|
|
33
|
+
/** Epoch ms when the access token expires; null when it does not expire. */
|
|
34
|
+
expiresAt: number | null;
|
|
35
|
+
/** Epoch ms when the refresh token expires; null when unknown. */
|
|
36
|
+
refreshExpiresAt: number | null;
|
|
37
|
+
updatedAt: number;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type GithubDeviceFlowInfo = {
|
|
41
|
+
userCode: string;
|
|
42
|
+
verificationUri: string;
|
|
43
|
+
expiresAt: number;
|
|
44
|
+
intervalMs: number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type GithubAuthStatus = {
|
|
48
|
+
authenticated: boolean;
|
|
49
|
+
account: GithubAccountInfo | null;
|
|
50
|
+
clientId: string;
|
|
51
|
+
clientSecretConfigured: boolean;
|
|
52
|
+
expiresAt: number | null;
|
|
53
|
+
refreshExpiresAt: number | null;
|
|
54
|
+
callbackPath: string;
|
|
55
|
+
callbackUrl: string | null;
|
|
56
|
+
/** Absolute URL of the standalone device-login page, when origin is known. */
|
|
57
|
+
loginPageUrl: string | null;
|
|
58
|
+
/** Active device-flow login (user code to enter at github.com/login/device), if any. */
|
|
59
|
+
device: GithubDeviceFlowInfo | null;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type GithubLoginStart = {
|
|
63
|
+
authorizeUrl: string;
|
|
64
|
+
state: string;
|
|
65
|
+
callbackUrl: string;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type GithubLoginCallbackParams = {
|
|
69
|
+
code?: string;
|
|
70
|
+
state?: string;
|
|
71
|
+
error?: string;
|
|
72
|
+
errorDescription?: string;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The manager surface created by controller/github-auth.ts's
|
|
77
|
+
* createGithubAuthManager. Consumers (teamauto, controller routes) depend
|
|
78
|
+
* only on this shape.
|
|
79
|
+
*/
|
|
80
|
+
export type GithubAuthManager = {
|
|
81
|
+
beginLogin: (origin: string) => GithubLoginStart;
|
|
82
|
+
beginDeviceLogin: () => Promise<GithubDeviceFlowInfo>;
|
|
83
|
+
completeLogin: (params: GithubLoginCallbackParams) => Promise<GithubAccountInfo>;
|
|
84
|
+
getAccessToken: () => Promise<string>;
|
|
85
|
+
getAuthHeaders: () => Promise<Record<string, string>>;
|
|
86
|
+
getStatus: (origin?: string) => Promise<GithubAuthStatus>;
|
|
87
|
+
forceRefresh: () => Promise<GithubAuthStore>;
|
|
88
|
+
logout: () => Promise<void>;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/** Default GitHub OAuth client id (moved from controller/github-auth, W3 residual edge). */
|
|
92
|
+
export const DEFAULT_GITHUB_CLIENT_ID = "Iv23liqWmzrS3swGiIvK";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Shared contracts layer (issue #226, W3): the kickoff assessment prompt
|
|
2
|
+
// builder, lifted verbatim from controller/kickoff-orchestrator.ts. The
|
|
3
|
+
// worker builds this prompt when it answers a kickoff assessment request
|
|
4
|
+
// (worker/worker-service.ts), so the prompt contract must live in the shared
|
|
5
|
+
// layer — worker must never import the controller tree. Pure function: its
|
|
6
|
+
// only dependencies are the RoleId type and the active-profile role lookup,
|
|
7
|
+
// both root-level modules, so the move drags in zero controller code.
|
|
8
|
+
import type { RoleId } from "../types.js";
|
|
9
|
+
import { getActiveRole } from "../profile-loader.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Build the kickoff assessment prompt sent to a worker.
|
|
13
|
+
* The worker should respond with structured JSON matching KickoffAssessment.
|
|
14
|
+
*/
|
|
15
|
+
export function buildKickoffAssessmentPrompt(role: RoleId, requirement: string): string {
|
|
16
|
+
const roleDef = getActiveRole(role);
|
|
17
|
+
const roleLabel = roleDef?.label ?? role;
|
|
18
|
+
|
|
19
|
+
return [
|
|
20
|
+
`You are the ${roleLabel} in a virtual software team.`,
|
|
21
|
+
`Your team is conducting a kickoff meeting for a new requirement.`,
|
|
22
|
+
``,
|
|
23
|
+
`## Requirement`,
|
|
24
|
+
requirement,
|
|
25
|
+
``,
|
|
26
|
+
`## Your Task`,
|
|
27
|
+
`Evaluate this requirement from your professional perspective as ${roleLabel}.`,
|
|
28
|
+
`Respond with a JSON object (and nothing else) with these fields:`,
|
|
29
|
+
``,
|
|
30
|
+
`{`,
|
|
31
|
+
` "needed": boolean, // Is your role needed for this project?`,
|
|
32
|
+
` "scope": string, // What would you contribute? (1-2 sentences)`,
|
|
33
|
+
` "suggestedTasks": string[], // Specific tasks you'd handle (2-5 items)`,
|
|
34
|
+
` "dependencies": string[], // What you need from other roles before or during your work`,
|
|
35
|
+
` "risks": string[], // Concerns or risks from your perspective`,
|
|
36
|
+
` "questions": string[] // Clarifications you'd want before starting`,
|
|
37
|
+
`}`,
|
|
38
|
+
``,
|
|
39
|
+
`Guidelines:`,
|
|
40
|
+
`- Be honest about whether your role is truly needed. Don't inflate your importance.`,
|
|
41
|
+
`- For "needed", consider: does the project actually require ${roleLabel}-level expertise?`,
|
|
42
|
+
`- A simple single-file script does NOT need an architect. A TODO app does NOT need a security engineer.`,
|
|
43
|
+
`- Keep suggestedTasks concrete and actionable, not vague.`,
|
|
44
|
+
`- Only list dependencies on roles that are actually relevant.`,
|
|
45
|
+
`- Return ONLY the JSON object, no markdown fencing, no explanation.`,
|
|
46
|
+
].join("\n");
|
|
47
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Shared generic utilities (issue #226 W6 dedup + W1 worker-provisioning
|
|
2
|
+
// split). Everything here is extracted VERBATIM from its former private
|
|
3
|
+
// copies - semantics are frozen, see the W6 notes per function:
|
|
4
|
+
// - pathExists strict: only ENOENT resolves false, other errors
|
|
5
|
+
// rethrow (former worker-provisioning.ts copy)
|
|
6
|
+
// - pathExistsTolerant swallowing: any access error resolves false (the
|
|
7
|
+
// former git-collaboration.ts / worker/skill-installer.ts
|
|
8
|
+
// / index.ts copies, kept as a distinct name so each
|
|
9
|
+
// call site keeps its exact original behavior)
|
|
10
|
+
// - sleep / cloneJson / sanitizePathSegment / sanitizeName: single shared
|
|
11
|
+
// copies of byte-identical former duplicates.
|
|
12
|
+
import fs from "node:fs/promises";
|
|
13
|
+
|
|
14
|
+
export function sleep(ms: number): Promise<void> {
|
|
15
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function cloneJson<T>(value: T): T {
|
|
19
|
+
return JSON.parse(JSON.stringify(value)) as T;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function pathExists(targetPath: string): Promise<boolean> {
|
|
23
|
+
try {
|
|
24
|
+
await fs.access(targetPath);
|
|
25
|
+
return true;
|
|
26
|
+
} catch (err) {
|
|
27
|
+
if ((err as NodeJS.ErrnoException).code === "ENOENT") {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function pathExistsTolerant(targetPath: string): Promise<boolean> {
|
|
35
|
+
try {
|
|
36
|
+
await fs.access(targetPath);
|
|
37
|
+
return true;
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function sanitizePathSegment(value: string): string {
|
|
44
|
+
const normalized = value.toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
45
|
+
return normalized || "worker";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function sanitizeName(value: string, maxLength = 63): string {
|
|
49
|
+
const normalized = sanitizePathSegment(value).slice(0, maxLength).replace(/^-+|-+$/g, "");
|
|
50
|
+
return normalized || "teamclaw";
|
|
51
|
+
}
|