Files
next-tjwater-agent/.opencode/tools/propose_task_action.ts
T
jiang 7383ed6d13 feat(agent): migrate OpenCode 2 runtime and sandbox tools
Upgrade the runtime and native plugin API to OpenCode 2.0.24. Restore
session-scoped learning, credential renewal, typed project queries and
controlled frontend actions from the legacy Agent.

Replace host Shell execution with an approved Landlock/seccomp executor
and persistent per-session workspaces. Add typed Bocha search and Tianditu
geocoding bridges using the owning session credential. Require a working
kernel sandbox before startup and persist workspace files in deployments.

Validation completed before this commit: TypeScript checks, 150 Bun tests,
Docker build and UID 10001 sandbox execution, native Shell approval and
session recovery. Tianditu succeeded; Bocha currently reports exhausted
account quota. Unrelated investigation-report contract work is excluded.
2026-10-08 15:46:37 +08:00

49 lines
2.6 KiB
TypeScript

import { tool } from "../tool.js";
import { getInternalBridgeConfig } from "../internalBridge.js";
import { proposedTaskActionSchema } from "../../src/product/operational-task-contract.js";
export default tool({
description: "Propose a work-order creation or command action for human approval after its node exists in the published current plan. This tool only creates a pending approval record and can never execute the action. After success, republish the plan with the returned action_id in action_refs before publishing the final report. create_work_order requires title, description and work_order_type; its priority is normal or urgent. issue_command requires command_type, target, parameters, impact_summary, non-empty preconditions and expires_at.",
args: {
request_id: tool.schema.string().describe("Stable UUID idempotency key for this proposal"),
kind: tool.schema.enum(["create_work_order", "issue_command"]),
reason: tool.schema.string(),
payload: tool.schema.union([
tool.schema.object({
title: tool.schema.string(),
description: tool.schema.string(),
work_order_type: tool.schema.string(),
priority: tool.schema.enum(["normal", "urgent"]).default("normal"),
scheduled_at: tool.schema.string().nullable().optional(),
location: tool.schema.string().nullable().optional(),
assignee: tool.schema.string().nullable().optional(),
}).strict(),
tool.schema.object({
command_type: tool.schema.string(),
target: tool.schema.object({
kind: tool.schema.string(),
id: tool.schema.string(),
}).strict(),
parameters: tool.schema.record(tool.schema.string(), tool.schema.unknown()),
impact_summary: tool.schema.string(),
preconditions: tool.schema.array(tool.schema.string()).min(1),
expires_at: tool.schema.string(),
}).strict(),
]),
evidence_refs: tool.schema.array(tool.schema.string()),
node_id: tool.schema.string().optional(),
},
async execute(action, context) {
const validatedAction = proposedTaskActionSchema.parse(action);
const { baseUrl, internalToken } = getInternalBridgeConfig();
const response = await fetch(`${baseUrl}/internal/operational-task/actions`, {
method: "POST",
headers: { "Content-Type": "application/json", "x-agent-internal-token": internalToken },
body: JSON.stringify({ session_id: context.sessionID, action: validatedAction }),
});
const text = await response.text();
if (!response.ok) throw new Error(`task action proposal failed (${response.status}): ${text}`);
return text;
},
});