@teamclaws/teamclaw 2026.11.0 → 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 +272 -2
- package/dist/index.js +54 -32
- package/dist/src/config.js +24 -0
- package/dist/src/controller/auth-routes.js +129 -0
- package/dist/src/controller/clarification-routes.js +1 -1
- package/dist/src/controller/controller-planning.js +1 -0
- package/dist/src/controller/controller-routes.js +195 -0
- package/dist/src/controller/controller-service.js +67 -10
- package/dist/src/controller/controller-tools.js +3 -1
- package/dist/src/controller/github-auth.js +2 -1
- package/dist/src/controller/http-server.js +51 -16
- package/dist/src/controller/kickoff-orchestrator.js +3 -39
- package/dist/src/controller/message-delivery.js +4 -1
- package/dist/src/controller/orchestration-manifest.js +5 -65
- package/dist/src/controller/preview-manager.js +51 -3
- package/dist/src/controller/profile-switch.js +42 -22
- 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 +70 -4
- package/dist/src/controller/report-routes.js +56 -0
- package/dist/src/controller/route-table.js +67 -1045
- package/dist/src/controller/security.js +775 -0
- package/dist/src/controller/status-routes.js +287 -0
- package/dist/src/controller/task-assignment.js +5 -2
- package/dist/src/controller/task-execution.js +31 -0
- package/dist/src/controller/task-results.js +10 -0
- package/dist/src/controller/tunnel-manager.js +41 -8
- package/dist/src/controller/tunnel-routes.js +225 -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 +39 -949
- 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 +12 -1
- package/dist/src/profile-loader.js +119 -1
- package/dist/src/profiles/banking.json +26 -2
- package/dist/src/profiles/schema.json +82 -2
- package/dist/src/prompt-policy.js +18 -6
- package/dist/src/protocol.js +66 -3
- 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 +89 -3
- package/dist/src/types.js +15 -1
- package/dist/src/ui/app.js +846 -62
- package/dist/src/ui/github-login.html +1 -0
- package/dist/src/ui/index.html +102 -36
- package/dist/src/worker/http-handler.js +59 -0
- package/dist/src/worker/skill-installer.js +3 -9
- package/dist/src/worker/tools.js +20 -10
- package/dist/src/worker/worker-service.js +17 -4
- package/index.ts +61 -32
- package/openclaw.plugin.json +23 -2
- package/package.json +1 -1
- package/src/config.ts +24 -0
- package/src/controller/auth-routes.ts +157 -0
- package/src/controller/clarification-routes.ts +1 -1
- package/src/controller/controller-planning.ts +8 -0
- package/src/controller/controller-routes.ts +237 -0
- package/src/controller/controller-service.ts +128 -10
- package/src/controller/controller-tools.ts +5 -2
- package/src/controller/github-auth.ts +28 -63
- package/src/controller/http-server.ts +66 -17
- package/src/controller/kickoff-orchestrator.ts +3 -42
- package/src/controller/message-delivery.ts +4 -1
- package/src/controller/orchestration-manifest.ts +8 -71
- package/src/controller/preview-manager.ts +53 -3
- package/src/controller/profile-switch.ts +53 -23
- 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 +84 -12
- package/src/controller/report-routes.ts +64 -0
- package/src/controller/route-table.ts +133 -1152
- package/src/controller/security.ts +899 -0
- package/src/controller/status-routes.ts +354 -0
- package/src/controller/task-assignment.ts +5 -1
- package/src/controller/task-execution.ts +43 -0
- package/src/controller/task-results.ts +12 -0
- package/src/controller/tunnel-manager.ts +45 -8
- package/src/controller/tunnel-routes.ts +231 -0
- package/src/controller/websocket.ts +19 -3
- package/src/controller/webui-routes.ts +55 -0
- package/src/controller/worker-provisioning.ts +51 -1117
- 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 +13 -1
- package/src/profile-loader.ts +167 -1
- package/src/profiles/banking.json +26 -2
- package/src/profiles/schema.json +82 -2
- package/src/prompt-policy.ts +19 -6
- package/src/protocol.ts +72 -2
- 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 +92 -3
- package/src/teamauto/github-client.ts +2 -1
- package/src/teamauto/repo-sync.ts +2 -1
- package/src/teamauto/scheduler.ts +2 -1
- package/src/types.ts +130 -1
- package/src/ui/app.js +846 -62
- package/src/ui/github-login.html +1 -0
- package/src/ui/index.html +102 -36
- package/src/worker/http-handler.ts +64 -1
- package/src/worker/skill-installer.ts +3 -9
- package/src/worker/tools.ts +21 -10
- package/src/worker/worker-service.ts +18 -4
package/src/prompt-policy.ts
CHANGED
|
@@ -6,11 +6,22 @@ import { buildTeamClawProjectAgentRelativePath } from "./openclaw-workspace.js";
|
|
|
6
6
|
// free leaf keeps a single source of truth without a module cycle. roles.ts
|
|
7
7
|
// asserts its ROLES registry agrees with the same list.
|
|
8
8
|
import { ROLE_IDS } from "./role-ids.js";
|
|
9
|
+
import { getActiveRoleIds } from "./profile-loader.js";
|
|
9
10
|
|
|
10
11
|
export const TEAMCLAW_ROLE_IDS: RoleId[] = ROLE_IDS;
|
|
11
12
|
|
|
12
13
|
export const TEAMCLAW_ROLE_IDS_TEXT = TEAMCLAW_ROLE_IDS.join(", ");
|
|
13
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
|
+
|
|
14
25
|
type PromptSection = string | string[] | null | undefined | false;
|
|
15
26
|
|
|
16
27
|
export function composePrompt(...sections: PromptSection[]): string {
|
|
@@ -36,8 +47,10 @@ export function composePrompt(...sections: PromptSection[]): string {
|
|
|
36
47
|
* the option (software-rd baseline, roles.ts registry init) the output is
|
|
37
48
|
* byte-identical to the pre-Phase-2.4 value, which the Phase 1.7 prompt
|
|
38
49
|
* goldens lock. The option is injected by the prompt pipelines (controller
|
|
39
|
-
* and worker prompt-injector) rather than read from the loader here
|
|
40
|
-
*
|
|
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.)
|
|
41
54
|
*/
|
|
42
55
|
export function buildRoleOperatingRules(options: {
|
|
43
56
|
suggestedRoles: string[];
|
|
@@ -70,7 +83,7 @@ export function buildRoleOperatingRules(options: {
|
|
|
70
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.",
|
|
71
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.",
|
|
72
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.",
|
|
73
|
-
`- Use exact TeamClaw role IDs when collaborating: ${
|
|
86
|
+
`- Use exact TeamClaw role IDs when collaborating: ${activeRoleIdsText()}.`,
|
|
74
87
|
`- If a true follow-up is required after your deliverable, prefer these exact next roles: ${suggestedRoles}.`,
|
|
75
88
|
`- Default starter skills for this role: ${recommendedSkills}. If the task includes more specific recommended skills, prefer those.`,
|
|
76
89
|
];
|
|
@@ -104,7 +117,7 @@ export function buildWorkerSessionRules(): string[] {
|
|
|
104
117
|
"7. If another role must continue later, use review/handoff tools on the current task instead of spawning work.",
|
|
105
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.",
|
|
106
119
|
"9. Do not mark the task completed or failed via progress updates. Return the final deliverable and let TeamClaw close the task.",
|
|
107
|
-
`10. Valid TeamClaw role IDs: ${
|
|
120
|
+
`10. Valid TeamClaw role IDs: ${activeRoleIdsText()}.`,
|
|
108
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.",
|
|
109
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.",
|
|
110
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.",
|
|
@@ -139,7 +152,7 @@ export function buildTaskExecutionRules(rateLimitWaitingSentinel: string): strin
|
|
|
139
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}.`,
|
|
140
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.",
|
|
141
154
|
"- Use structured fields on progress, review, handoff, and messaging tools whenever coordination is needed.",
|
|
142
|
-
`- When naming a role, use exact TeamClaw role IDs: ${
|
|
155
|
+
`- When naming a role, use exact TeamClaw role IDs: ${activeRoleIdsText()}.`,
|
|
143
156
|
];
|
|
144
157
|
}
|
|
145
158
|
|
|
@@ -392,7 +405,7 @@ export function buildControllerDisciplineRules(options: { canProvisionWithoutWor
|
|
|
392
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."
|
|
393
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.",
|
|
394
407
|
"- Use the controller itself for requirement analysis; use the PM role only for PM-owned deliverables after intake is clear.",
|
|
395
|
-
`- Use exact TeamClaw role IDs only: ${
|
|
408
|
+
`- Use exact TeamClaw role IDs only: ${activeRoleIdsText()}.`,
|
|
396
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.",
|
|
397
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.",
|
|
398
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
|
};
|
|
@@ -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
|
+
}
|
package/src/state.ts
CHANGED
|
@@ -93,9 +93,67 @@ function migrateState(raw: unknown): TeamState | null {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
// Issue #23: device-pairing security state (additive optional field). No
|
|
97
|
+
// `security` key = protection off (L0 zero-friction default). A malformed
|
|
98
|
+
// persisted shape is sanitized in place, mirroring the transition policy
|
|
99
|
+
// above: devices without a usable identity/tokenHash are dropped (such a
|
|
100
|
+
// device could never authenticate again anyway), and malformed pairing
|
|
101
|
+
// codes / observation records are discarded.
|
|
102
|
+
if (state.security !== undefined) {
|
|
103
|
+
const security = state.security as Record<string, unknown>;
|
|
104
|
+
if (!security || typeof security !== "object" || Array.isArray(security)) {
|
|
105
|
+
delete state.security;
|
|
106
|
+
} else {
|
|
107
|
+
if (security.enabledAt !== undefined && typeof security.enabledAt !== "number") {
|
|
108
|
+
delete security.enabledAt;
|
|
109
|
+
}
|
|
110
|
+
security.devices = Array.isArray(security.devices)
|
|
111
|
+
? security.devices.filter(isValidPersistedSecurityDevice)
|
|
112
|
+
: [];
|
|
113
|
+
if (security.pairingCode !== undefined) {
|
|
114
|
+
const pairingCode = security.pairingCode as Record<string, unknown>;
|
|
115
|
+
const codeOk = typeof pairingCode?.code === "string" && /^[A-Z2-7]{8}$/.test(pairingCode.code);
|
|
116
|
+
const expiresOk = typeof pairingCode?.expiresAt === "number";
|
|
117
|
+
const purposeOk = typeof pairingCode?.purpose === "string" && Boolean(pairingCode.purpose.trim());
|
|
118
|
+
const usedOk = pairingCode?.usedAt === undefined || typeof pairingCode.usedAt === "number";
|
|
119
|
+
if (!codeOk || !expiresOk || !purposeOk || !usedOk) {
|
|
120
|
+
delete security.pairingCode;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (security.lastNonLanPeer !== undefined) {
|
|
124
|
+
const observation = security.lastNonLanPeer as Record<string, unknown>;
|
|
125
|
+
if (
|
|
126
|
+
typeof observation?.ip !== "string" ||
|
|
127
|
+
typeof observation?.at !== "number" ||
|
|
128
|
+
typeof observation?.path !== "string"
|
|
129
|
+
) {
|
|
130
|
+
delete security.lastNonLanPeer;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
96
136
|
return state as unknown as TeamState;
|
|
97
137
|
}
|
|
98
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Issue #23: persisted-device structural guard for the migration above. A
|
|
141
|
+
* device needs a non-empty id, a sha256-hex tokenHash (64 lowercase hex
|
|
142
|
+
* chars) and a creation timestamp; anything else is corrupt state and is
|
|
143
|
+
* dropped rather than half-loaded.
|
|
144
|
+
*/
|
|
145
|
+
function isValidPersistedSecurityDevice(entry: unknown): boolean {
|
|
146
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
const device = entry as Record<string, unknown>;
|
|
150
|
+
return (
|
|
151
|
+
typeof device.id === "string" && Boolean(device.id.trim()) &&
|
|
152
|
+
typeof device.tokenHash === "string" && /^[0-9a-f]{64}$/.test(device.tokenHash) &&
|
|
153
|
+
typeof device.createdAt === "number"
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
99
157
|
function resolvePluginStateDir(): string {
|
|
100
158
|
const explicitStateDir = process.env.OPENCLAW_STATE_DIR?.trim();
|
|
101
159
|
if (explicitStateDir) {
|
|
@@ -152,9 +210,35 @@ async function ensureDir(dir: string): Promise<void> {
|
|
|
152
210
|
await fs.mkdir(dir, { recursive: true });
|
|
153
211
|
}
|
|
154
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Issue #255 P1-4: every file written through this helper is controller
|
|
215
|
+
* state that can carry plaintext secrets - team-state.json holds the device
|
|
216
|
+
* pairingCode and each provisioned worker's launchToken, the archived team
|
|
217
|
+
* envelopes and worker-identity.json ride the same path. Writes are now
|
|
218
|
+
* owner-only (0600), matching the github-auth.ts auth-store precedent:
|
|
219
|
+
* - the tmp file is created with mode 0600 and the rename carries that
|
|
220
|
+
* mode onto the final path, and
|
|
221
|
+
* - an existing file from an older build (created 0644 by this same
|
|
222
|
+
* helper before the mode existed) is pre-tightened before the rewrite
|
|
223
|
+
* (#242 process-supervisor pattern: chmod first, ENOENT tolerated for
|
|
224
|
+
* first writes).
|
|
225
|
+
*/
|
|
155
226
|
async function writeFileAtomically(filePath: string, contents: string): Promise<void> {
|
|
156
227
|
const tmpPath = `${filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
157
|
-
|
|
228
|
+
try {
|
|
229
|
+
await fs.chmod(filePath, 0o600);
|
|
230
|
+
} catch (error) {
|
|
231
|
+
if ((error as NodeJS.ErrnoException)?.code !== "ENOENT") {
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
await fs.writeFile(tmpPath, contents, { encoding: "utf8", mode: 0o600 });
|
|
236
|
+
try {
|
|
237
|
+
await fs.chmod(tmpPath, 0o600);
|
|
238
|
+
} catch {
|
|
239
|
+
// Best-effort: the write itself already requested mode 0600; some
|
|
240
|
+
// filesystems (e.g. network mounts) reject explicit chmod.
|
|
241
|
+
}
|
|
158
242
|
await fs.rename(tmpPath, filePath);
|
|
159
243
|
}
|
|
160
244
|
|
|
@@ -280,7 +364,7 @@ async function saveTeamState(state: TeamState): Promise<void> {
|
|
|
280
364
|
// ---------------------------------------------------------------------------
|
|
281
365
|
|
|
282
366
|
const ARCHIVED_TEAMS_DIR_NAME = "archived";
|
|
283
|
-
const ARCHIVE_FILE_RE = /^([a-z0-9-]+)-(\d+)
|
|
367
|
+
const ARCHIVE_FILE_RE = /^([a-z0-9-]+)-(\d+)(?:-([a-z0-9]+))?\.json$/;
|
|
284
368
|
|
|
285
369
|
/** Embedded profile snapshot stored alongside the archived team state. */
|
|
286
370
|
export type ArchivedTeamProfileSnapshot = {
|
|
@@ -331,7 +415,12 @@ async function archiveTeamState(
|
|
|
331
415
|
): Promise<string> {
|
|
332
416
|
const dir = archivedTeamsDirPath();
|
|
333
417
|
await ensureDir(dir);
|
|
334
|
-
|
|
418
|
+
// #251: a short random suffix disambiguates same-millisecond archives
|
|
419
|
+
// (two switches inside one ms would otherwise silently overwrite each
|
|
420
|
+
// other). Capture groups 1/2 keep their original semantics; group 3 is
|
|
421
|
+
// the optional suffix, so pre-#251 archive names still parse.
|
|
422
|
+
const suffix = Math.random().toString(36).slice(2, 8).padEnd(6, "0");
|
|
423
|
+
const fileName = `${state.profileId}-${Date.now()}-${suffix}.json`;
|
|
335
424
|
const filePath = path.join(dir, fileName);
|
|
336
425
|
const envelope: ArchivedTeamEnvelope = {
|
|
337
426
|
archivedAt: Date.now(),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// Issue #226 W5: cross-subsystem contract lives in the shared layer now.
|
|
2
|
+
import type { GithubAuthManager } from "../shared/github-auth.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Minimal GitHub REST client for TeamAuto: ETag-conditional GETs, light
|
|
@@ -3,7 +3,8 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// Issue #226 W5: cross-subsystem contract lives in the shared layer now.
|
|
7
|
+
import type { GithubAuthManager } from "../shared/github-auth.js";
|
|
7
8
|
import { repoSlugToDirName, resolveTeamAutoPaths } from "./store.js";
|
|
8
9
|
|
|
9
10
|
const exec = promisify(execFile);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
|
|
3
3
|
import type { PluginLogger } from "../../api.js";
|
|
4
|
-
|
|
4
|
+
// Issue #226 W5: cross-subsystem contract lives in the shared layer now.
|
|
5
|
+
import type { GithubAuthManager } from "../shared/github-auth.js";
|
|
5
6
|
// Phase 2.3/2.5 (cross-review adopted suggestion): manual-proposal roles
|
|
6
7
|
// validate against the ACTIVE profile and default to its defaultRole instead
|
|
7
8
|
// of hardcoded software role literals.
|