ofiere-openclaw-plugin 4.54.2 → 4.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -104
- package/dist/src/prompt.js +130 -130
- package/dist/src/staffPersona.js +3 -1
- package/dist/src/tools.js +111 -0
- package/index.ts +105 -105
- package/package.json +12 -2
- package/src/agent-resolver.ts +90 -90
- package/src/agent-tier.ts +192 -192
- package/src/attach-token.ts +106 -106
- package/src/attachments.ts +601 -601
- package/src/cli.ts +247 -247
- package/src/config.ts +78 -78
- package/src/prompt.ts +267 -267
- package/src/sop-render.ts +216 -216
- package/src/staffPersona.ts +299 -289
- package/src/supabase.ts +13 -13
- package/src/tools.ts +112 -0
- package/src/types/openclaw.d.ts +8 -8
- package/src/types.ts +10 -10
package/src/prompt.ts
CHANGED
|
@@ -1,267 +1,267 @@
|
|
|
1
|
-
// src/prompt.ts — Dynamic system prompt for Ofiere PM plugin
|
|
2
|
-
//
|
|
3
|
-
// v4.31.0: Tiered prompt loading strategy.
|
|
4
|
-
// Tier A (always loaded): Core rules + 1-line tool summaries (~2K tokens)
|
|
5
|
-
// Tier B (embedded docs): Full tool docs injected on-demand via meta-tool descriptions
|
|
6
|
-
//
|
|
7
|
-
// This cuts system prompt from ~12K → ~3K tokens, reducing TTFT by 40-60%.
|
|
8
|
-
|
|
9
|
-
// ─── Tier A: One-Line Tool Summaries ────────────────────────────────────────
|
|
10
|
-
// Each tool gets a concise one-liner. Full docs live in the tool's own
|
|
11
|
-
// description field (registered in tools.ts) where the LLM reads them
|
|
12
|
-
// only when it decides to use that tool.
|
|
13
|
-
|
|
14
|
-
const TOOL_SUMMARIES: Record<string, string> = {
|
|
15
|
-
OFIERE_TASK_OPS: "Manage tasks: list, create, update, delete, approvals",
|
|
16
|
-
OFIERE_AGENT_OPS: "Query + manage agents and their staff subagents",
|
|
17
|
-
OFIERE_PROJECT_OPS: "PM hierarchy: spaces, folders, dependencies",
|
|
18
|
-
OFIERE_SCHEDULE_OPS: "Calendar: list, create, update, delete events",
|
|
19
|
-
OFIERE_KNOWLEDGE_OPS: "Knowledge library: search, list, create, update, delete",
|
|
20
|
-
OFIERE_WORKFLOW_OPS: "Workflow automation: 13 actions for DAG-based flows",
|
|
21
|
-
OFIERE_NOTIFY_OPS: "Notifications & channel reports (Telegram/Discord/Slack/WhatsApp)",
|
|
22
|
-
OFIERE_MEMORY_OPS: "Conversation history & knowledge memory search",
|
|
23
|
-
OFIERE_PROMPT_OPS: "Manage prompt instruction chunks (CRUD + ordering)",
|
|
24
|
-
OFIERE_CONSTELLATION_OPS: "Create/edit/delete OpenClaw agents from chat",
|
|
25
|
-
OFIERE_FILE_OPS: "Space files: upload, read, move, share, delete",
|
|
26
|
-
OFIERE_PLAN_OPS: "Visual execution plan builder (DAG drafts → real tasks)",
|
|
27
|
-
OFIERE_SOP_OPS: "Standard Operating Procedures (Staff agents). Includes propose_attach/commit_attach for self-attaching SOPs to runs",
|
|
28
|
-
OFIERE_BRAIN_OPS: "Agent memory, knowledge graph, self-improvement (TMT/MAGMA)",
|
|
29
|
-
OFIERE_TALENT_OPS: "Talents: list, get, activate, deactivate cognitive skill presets",
|
|
30
|
-
OFIERE_FRAMEWORK_OPS: "Corporate Frameworks (C-Suite agents). Includes propose_attach/commit_attach for self-attaching Frameworks to runs",
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// ─── Tier B: Full Tool Documentation ────────────────────────────────────────
|
|
34
|
-
// These are used as tool descriptions in registerTools(), NOT in the system prompt.
|
|
35
|
-
// The LLM sees them only when exploring available tools or preparing a tool call.
|
|
36
|
-
|
|
37
|
-
export const TOOL_DOCS: Record<string, string> = {
|
|
38
|
-
OFIERE_TASK_OPS: `Manage tasks and approvals.
|
|
39
|
-
Actions: "list", "create", "update", "delete", "add_approval", "list_approvals", "resolve_approval"
|
|
40
|
-
- list: Filter by status, agent_id, space_id, folder_id, limit. Returns execution_plan, goals, constraints if present
|
|
41
|
-
- create: Requires title. IMPORTANT: Always pass agent_id with your own name to self-assign (e.g. agent_id: "celia")
|
|
42
|
-
- Optional: description, instructions, execution_plan, goals, constraints, system_prompt, priority, tags, dates
|
|
43
|
-
- For COMPLEX tasks: include execution_plan (step-by-step), goals, constraints, and system_prompt
|
|
44
|
-
- For SIMPLE tasks: just title and optionally description
|
|
45
|
-
- update: Requires task_id. All create fields + progress
|
|
46
|
-
- delete: Requires task_id. Removes task and subtasks
|
|
47
|
-
- add_approval: Request sign-off. Requires: task_id, approver_name. Optional: approver_type (human|agent), due_date, comment
|
|
48
|
-
- list_approvals: List approvals. Optional: task_id, approval_status (pending|approved|rejected)
|
|
49
|
-
- resolve_approval: Approve/reject. Requires: approval_id, approval_status. Optional: comment`,
|
|
50
|
-
|
|
51
|
-
OFIERE_AGENT_OPS: `Query + manage agents and their staff subagents.
|
|
52
|
-
Actions: "list", "list_subagents", "create_subagent", "delete_subagent", "invalidate_tier_cache"
|
|
53
|
-
- list: All top-level agents (chiefs / native + OpenClaw) with IDs, names, roles. Use for task assignment lookup.
|
|
54
|
-
- list_subagents: Staff under a chief. Required: chief_agent_id.
|
|
55
|
-
- create_subagent: Add a staff subagent under a chief (max 5 per chief). Required: chief_agent_id, name. Optional: role (default "Staff"), codename, color_hex.
|
|
56
|
-
- delete_subagent: Remove a staff subagent. Required: subagent_id.
|
|
57
|
-
- invalidate_tier_cache: Flush plugin's in-process tier cache (5 min TTL). Optional: agent_id. Use after direct-DB mutation of agent_tier_overrides.`,
|
|
58
|
-
|
|
59
|
-
OFIERE_PROJECT_OPS: `Manage PM hierarchy.
|
|
60
|
-
Actions: "list_spaces", "create_space", "update_space", "delete_space", "list_folders", "create_folder", "update_folder", "delete_folder", "list_dependencies", "add_dependency", "remove_dependency"
|
|
61
|
-
- Spaces: Top-level containers. CRUD with name, icon, icon_color
|
|
62
|
-
- Folders: Inside spaces. Nest via parent_folder_id. Types: folder, project
|
|
63
|
-
- Dependencies: Link tasks. Types: finish_to_start (default), start_to_start, finish_to_finish, start_to_finish. lag_days optional`,
|
|
64
|
-
|
|
65
|
-
OFIERE_SCHEDULE_OPS: `Calendar events.
|
|
66
|
-
Actions: "list", "create", "update", "delete"
|
|
67
|
-
- list: Filter by start_date, end_date, agent_id
|
|
68
|
-
- create: Requires title + scheduled_date (YYYY-MM-DD). Optional: scheduled_time, duration_minutes, task_id, agent_id, recurrence_type, color
|
|
69
|
-
- Recurrence: none, hourly, daily, weekly, monthly with interval`,
|
|
70
|
-
|
|
71
|
-
OFIERE_KNOWLEDGE_OPS: `Ofiere Knowledge Library.
|
|
72
|
-
Actions: "search", "list", "create", "update", "delete"
|
|
73
|
-
- ALWAYS use when user mentions "knowledge base", "knowledge library", or asks to recall stored knowledge
|
|
74
|
-
- search: Keyword search. Requires: query
|
|
75
|
-
- list: Paginated listing with full content. Optional: search filter
|
|
76
|
-
- create: Requires: file_name. Optional: content, source, author, credibility_tier
|
|
77
|
-
- update/delete: By document ID`,
|
|
78
|
-
|
|
79
|
-
OFIERE_WORKFLOW_OPS: `Full workflow automation (13 actions).
|
|
80
|
-
Actions: "list", "get", "create", "update", "delete", "list_runs", "trigger", "add_nodes", "update_node", "delete_nodes", "add_edges", "delete_edges", "insert_node_between"
|
|
81
|
-
- ALWAYS call "get" before modifying to see node IDs and graph structure
|
|
82
|
-
- Node types: manual_trigger, webhook_trigger, agent_step, formatter_step, http_request, task_call, variable_set, condition, human_approval, delay, loop, convergence, output, checkpoint, note
|
|
83
|
-
- Edge handles: condition edges use "condition-true"/"condition-false". Loop edges use "loop_body"/"done"
|
|
84
|
-
- Variables: {{prev.nodeId.outputText}}, {{variables.key}}`,
|
|
85
|
-
|
|
86
|
-
OFIERE_NOTIFY_OPS: `Notifications & Channel Reports.
|
|
87
|
-
Actions: "list", "mark_read", "mark_all_read", "delete", "send_report", "get_task_detail", "schedule_report", "list_schedules", "delete_schedule"
|
|
88
|
-
- send_report: Send PM progress report to YOUR channels. Required: scope_type, agent_id (YOUR name)
|
|
89
|
-
- get_task_detail: Get full task result by report number. Required: task_number
|
|
90
|
-
- schedule_report: Recurring reports. Required: scope_type, recurrence_type, agent_id`,
|
|
91
|
-
|
|
92
|
-
OFIERE_MEMORY_OPS: `Conversation history & knowledge memory.
|
|
93
|
-
Actions: "list_conversations", "get_messages", "search_messages", "add_knowledge", "search_knowledge"`,
|
|
94
|
-
|
|
95
|
-
OFIERE_PROMPT_OPS: `Manage prompt instruction chunks.
|
|
96
|
-
Actions: "list", "get", "create", "update", "delete"
|
|
97
|
-
- create: New chunk with name (max 30 chars) + content. Optional: color (hex), category`,
|
|
98
|
-
|
|
99
|
-
OFIERE_CONSTELLATION_OPS: `Create/edit/delete OpenClaw agents from chat.
|
|
100
|
-
Actions: "list_agents", "get_agent", "read_file", "write_file", "create_agent", "delete_agent", "delete_file", "read_blueprint", "list_agent_mesh"
|
|
101
|
-
- CRITICAL: ALWAYS call read_blueprint before creating/editing agents
|
|
102
|
-
- delete_agent: IRREVERSIBLE. Always ask user for explicit confirmation first`,
|
|
103
|
-
|
|
104
|
-
OFIERE_FILE_OPS: `Manage Space Files.
|
|
105
|
-
Actions: "list_files", "list_folders", "create_folder", "create_text_file", "upload_file", "read_text_file", "rename_file", "rename_folder", "move_file", "move_folder", "delete_file", "delete_folder", "share_file", "unshare_file"
|
|
106
|
-
- read_text_file: Use when task references @[name](file:ID)
|
|
107
|
-
- Files appear in PM Space Files tab immediately`,
|
|
108
|
-
|
|
109
|
-
OFIERE_PLAN_OPS: `Visual execution plan builder.
|
|
110
|
-
Actions: "list", "get", "create", "update", "delete", "add_nodes", "execute"
|
|
111
|
-
- Plans are visual DAG drafts — not real tasks until "execute"
|
|
112
|
-
- Node types: task, gate, milestone
|
|
113
|
-
- Execution maps ALL fields: execution_steps, goals, constraints, system_prompt`,
|
|
114
|
-
|
|
115
|
-
OFIERE_SOP_OPS: `Standard Operating Procedures.
|
|
116
|
-
Actions: "list_templates", "create", "list", "get", "update", "delete", "list_subagents", "apply_template", "propose_attach", "commit_attach"
|
|
117
|
-
- sop_data: { title, purpose, scope, applicability, prerequisites:{ conditions, required_tools, required_permissions, safety_warnings }, procedure_steps[], expected_outputs[], escalation_rules[], acceptance_criteria[], rollback_procedure, notes }
|
|
118
|
-
- Legacy field names still accepted (objective→purpose, steps→procedure_steps, deliverables→expected_outputs, escalationRules→escalation_rules, successCriteria→acceptance_criteria) — prefer new names.
|
|
119
|
-
- propose_attach / commit_attach: attach SOPs to a run (target_kind: conversation|task|scheduler_event). Tier rule: SOPs only attach to STAFF-tier targets; for c-suite use OFIERE_FRAMEWORK_OPS instead. propose_attach returns a token-cost summary + confirmation_token (5-min ttl). You MUST surface the cost and ask the user before calling commit_attach. The user must explicitly approve.
|
|
120
|
-
- See SOP PROTOCOL section for when to load vs skip`,
|
|
121
|
-
|
|
122
|
-
OFIERE_BRAIN_OPS: `Agent memory, knowledge graph, self-improvement (TMT/MAGMA).
|
|
123
|
-
Memory Tiers: L1_focus (24h), L2_episode (days), L3_pattern (weeks), L4_rule (permanent), L5_persona (permanent)
|
|
124
|
-
Actions: save_memory, recall, delete_memory, promote_memory, log_learning, list_learnings, resolve_learning, save_entity, link_entities, query_graph, start_trajectory, end_trajectory, get_brain_status
|
|
125
|
-
- This is your SUBCONSCIOUS — use instinctively, not deliberately`,
|
|
126
|
-
|
|
127
|
-
OFIERE_TALENT_OPS: `Manage cognitive skill presets (Talents).
|
|
128
|
-
Actions: "list", "get", "activate", "deactivate"
|
|
129
|
-
- list: List all talents. Optional: category, scope, status
|
|
130
|
-
- get: Get full talent details. Required: talent_id OR name
|
|
131
|
-
- activate: Enable a talent (status → active). Required: talent_id
|
|
132
|
-
- deactivate: Disable a talent (status → inactive). Required: talent_id
|
|
133
|
-
- Active talents inject their execution_protocol and guardrails into your system prompt automatically
|
|
134
|
-
- Talents chain other tools: SPHINX chains KNOWLEDGE_OPS+BRAIN_OPS, PRISM chains BRAIN_OPS trajectories, ATLAS chains PLAN_OPS+TASK_OPS+SOP_OPS`,
|
|
135
|
-
|
|
136
|
-
OFIERE_FRAMEWORK_OPS: `Corporate Frameworks — strategic mandates, KPIs, risk governance.
|
|
137
|
-
Actions: "create", "list", "get", "update", "delete", "propose_attach", "commit_attach"
|
|
138
|
-
- content: JSON string with { mission, vision, core_principles[], decision_authority, budget_constraints, resource_limits, tool_stack[], strategic_objectives[], risk_appetite, compliance_requirements[], escalation_matrix[], team_composition (STRING — paragraph or newline-joined, NOT an array), integration_points[], review_frequency, last_reviewed, next_review, notes }
|
|
139
|
-
- propose_attach / commit_attach: attach Frameworks to a run (target_kind: conversation|task|scheduler_event). Tier rule: Frameworks only attach to C-SUITE-tier targets; for staff use OFIERE_SOP_OPS instead. propose_attach returns a token-cost summary + confirmation_token (5-min ttl). You MUST surface the cost and ask the user before calling commit_attach. The user must explicitly approve.`,
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
export function getSystemPrompt(state: {
|
|
143
|
-
ready: boolean;
|
|
144
|
-
toolCount: number;
|
|
145
|
-
agentId: string;
|
|
146
|
-
connectError: string;
|
|
147
|
-
}): string {
|
|
148
|
-
if (state.ready && state.toolCount > 0) {
|
|
149
|
-
const agentLine = state.agentId
|
|
150
|
-
? `Your agent ID is "${state.agentId}". You are registered in the Ofiere system.`
|
|
151
|
-
: `Your agent identity will be auto-detected at runtime. When you call any OFIERE tool, the system knows who you are.`;
|
|
152
|
-
|
|
153
|
-
const assignRule = state.agentId
|
|
154
|
-
? `When you create a task without specifying agent_id, it is assigned to YOU (${state.agentId}).`
|
|
155
|
-
: `When you create a task without specifying agent_id, it is assigned to YOU automatically.`;
|
|
156
|
-
|
|
157
|
-
// Tier A: Compact tool index (~300 tokens vs ~3000 for full docs)
|
|
158
|
-
const toolIndex = Object.entries(TOOL_SUMMARIES)
|
|
159
|
-
.map(([name, desc]) => `- **${name}** — ${desc}`)
|
|
160
|
-
.join("\n");
|
|
161
|
-
|
|
162
|
-
return `<ofiere-pm>
|
|
163
|
-
You are connected to the Ofiere Project Management dashboard via the Ofiere PM plugin.
|
|
164
|
-
${agentLine}
|
|
165
|
-
|
|
166
|
-
## Your Ofiere PM Tools (${state.toolCount} meta-tools)
|
|
167
|
-
|
|
168
|
-
Each tool uses an "action" parameter to select the operation. Always include action.
|
|
169
|
-
Full parameter docs are in each tool's description — call the tool to see details.
|
|
170
|
-
|
|
171
|
-
${toolIndex}
|
|
172
|
-
|
|
173
|
-
## ⛔ PLANNING GATE (NON-NEGOTIABLE)
|
|
174
|
-
- Before creating ANY task with 3+ total execution steps, goals, or constraints, you MUST ask the user: "Would you like me to plan this first, or create the task directly?"
|
|
175
|
-
- If the user chooses to plan, use OFIERE_PLAN_OPS to create a visual plan first, then execute it.
|
|
176
|
-
- NEVER skip this step. The server will block creation of complex tasks — use action: "create_force" only if the user explicitly confirms bypass.
|
|
177
|
-
|
|
178
|
-
## Rules
|
|
179
|
-
- ALWAYS pass agent_id with your own name when creating tasks (e.g. agent_id: "ivy").
|
|
180
|
-
- ${assignRule}
|
|
181
|
-
- To create an unassigned task, pass agent_id as "none" or "unassigned".
|
|
182
|
-
- When user says "create a task for [agent]", use OFIERE_AGENT_OPS action:"list" first.
|
|
183
|
-
- Task statuses: PENDING, IN_PROGRESS, DONE, FAILED. Priority: 0=LOW, 1=MED, 2=HIGH, 3=CRITICAL.
|
|
184
|
-
- Changes appear in the dashboard immediately via real-time sync.
|
|
185
|
-
- Do NOT fabricate task IDs — always look up real IDs first.
|
|
186
|
-
- For complex tasks, include execution_plan, goals, constraints. For simple tasks, just title.
|
|
187
|
-
- When user asks about "knowledge base/library", ALWAYS use OFIERE_KNOWLEDGE_OPS.
|
|
188
|
-
- CONSTELLATION: ALWAYS read_blueprint before creating/editing agents. ALWAYS confirm before delete.
|
|
189
|
-
- WORKFLOWS: ALWAYS "get" before modifying. Use "insert_node_between" for mid-flow additions.
|
|
190
|
-
- CHANNEL REPORTS: ALWAYS include agent_id (YOUR name) in send_report. Use get_task_detail for drill-down.
|
|
191
|
-
- File refs @[name](file:ID): Use OFIERE_FILE_OPS read_text_file to retrieve — don't ask user.
|
|
192
|
-
- Task approvals (OFIERE_TASK_OPS) ≠ workflow gate approvals (human_approval nodes).
|
|
193
|
-
|
|
194
|
-
## SOP PROTOCOL — Adaptive Complexity
|
|
195
|
-
|
|
196
|
-
Classify complexity before executing:
|
|
197
|
-
- **User Override**: "apply full SOP"/"use SOP" → 🔴 COMPLEX. "no SOP"/"just do it" → 🟢 SIMPLE.
|
|
198
|
-
- **🟢 SIMPLE** (≤2 tool calls, no coordination): Execute directly. Do NOT mention SOPs.
|
|
199
|
-
- **🟡 MODERATE** (3-5 calls, single dept): Ask briefly if SOPs needed.
|
|
200
|
-
- **🔴 COMPLEX** (5+ calls, multi-dept, escalation risk): Auto-load relevant SOPs via list→get.
|
|
201
|
-
|
|
202
|
-
## Agent Brain Protocol (TMT Subconscious)
|
|
203
|
-
|
|
204
|
-
Your brain persists across conversations. L5 persona, L4 guardrails, L1 focus are injected at startup.
|
|
205
|
-
- Save memories after significant interactions (not greetings/CRUD). Keep content to 1-3 sentences.
|
|
206
|
-
- Log learnings on corrections, errors, feature requests, insights, best practices.
|
|
207
|
-
- Do NOT announce memory operations — this is subconscious.
|
|
208
|
-
- Never delay your reply to save a memory.
|
|
209
|
-
</ofiere-pm>`;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (state.ready) {
|
|
213
|
-
const diagnostic = diagnoseError(state.connectError);
|
|
214
|
-
return `<ofiere-pm>
|
|
215
|
-
The Ofiere PM plugin failed to connect.${state.connectError ? ` Error: ${state.connectError}` : ""}
|
|
216
|
-
|
|
217
|
-
Diagnosis: ${diagnostic.reason}
|
|
218
|
-
|
|
219
|
-
When the user asks about task management or the Ofiere dashboard, respond with:
|
|
220
|
-
"${diagnostic.userMessage}"
|
|
221
|
-
|
|
222
|
-
Do NOT pretend Ofiere tools exist or hallucinate tool calls. You have zero Ofiere tools available.
|
|
223
|
-
</ofiere-pm>`;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return `<ofiere-pm>
|
|
227
|
-
The Ofiere PM plugin is loading. Tools should be available shortly.
|
|
228
|
-
If the user asks about tasks right now, ask them to wait a moment.
|
|
229
|
-
</ofiere-pm>`;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function diagnoseError(error: string): { reason: string; userMessage: string } {
|
|
233
|
-
const lower = error.toLowerCase();
|
|
234
|
-
|
|
235
|
-
if (!error) {
|
|
236
|
-
return {
|
|
237
|
-
reason: "Connected but no tools were registered.",
|
|
238
|
-
userMessage:
|
|
239
|
-
"The Ofiere PM plugin connected but could not register tools. " +
|
|
240
|
-
"Run `openclaw ofiere doctor` to diagnose.",
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (lower.includes("supabase") || lower.includes("url") || lower.includes("key")) {
|
|
245
|
-
return {
|
|
246
|
-
reason: "Supabase connection configuration issue.",
|
|
247
|
-
userMessage:
|
|
248
|
-
"The Ofiere PM plugin could not connect to Supabase. " +
|
|
249
|
-
"Check your configuration with `openclaw ofiere status` and re-run " +
|
|
250
|
-
"`openclaw ofiere setup` if needed, then `openclaw gateway restart`.",
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (lower.includes("user_id") || lower.includes("userid")) {
|
|
255
|
-
return {
|
|
256
|
-
reason: "Missing or invalid user ID in configuration.",
|
|
257
|
-
userMessage:
|
|
258
|
-
"The Ofiere PM plugin needs a valid user ID. " +
|
|
259
|
-
"Run `openclaw ofiere setup` with your user UUID, then `openclaw gateway restart`.",
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return {
|
|
264
|
-
reason: `Unexpected error: ${error}`,
|
|
265
|
-
userMessage: `The Ofiere PM plugin encountered an error: ${error}. Run \`openclaw ofiere doctor\` for details.`,
|
|
266
|
-
};
|
|
267
|
-
}
|
|
1
|
+
// src/prompt.ts — Dynamic system prompt for Ofiere PM plugin
|
|
2
|
+
//
|
|
3
|
+
// v4.31.0: Tiered prompt loading strategy.
|
|
4
|
+
// Tier A (always loaded): Core rules + 1-line tool summaries (~2K tokens)
|
|
5
|
+
// Tier B (embedded docs): Full tool docs injected on-demand via meta-tool descriptions
|
|
6
|
+
//
|
|
7
|
+
// This cuts system prompt from ~12K → ~3K tokens, reducing TTFT by 40-60%.
|
|
8
|
+
|
|
9
|
+
// ─── Tier A: One-Line Tool Summaries ────────────────────────────────────────
|
|
10
|
+
// Each tool gets a concise one-liner. Full docs live in the tool's own
|
|
11
|
+
// description field (registered in tools.ts) where the LLM reads them
|
|
12
|
+
// only when it decides to use that tool.
|
|
13
|
+
|
|
14
|
+
const TOOL_SUMMARIES: Record<string, string> = {
|
|
15
|
+
OFIERE_TASK_OPS: "Manage tasks: list, create, update, delete, approvals",
|
|
16
|
+
OFIERE_AGENT_OPS: "Query + manage agents and their staff subagents",
|
|
17
|
+
OFIERE_PROJECT_OPS: "PM hierarchy: spaces, folders, dependencies",
|
|
18
|
+
OFIERE_SCHEDULE_OPS: "Calendar: list, create, update, delete events",
|
|
19
|
+
OFIERE_KNOWLEDGE_OPS: "Knowledge library: search, list, create, update, delete",
|
|
20
|
+
OFIERE_WORKFLOW_OPS: "Workflow automation: 13 actions for DAG-based flows",
|
|
21
|
+
OFIERE_NOTIFY_OPS: "Notifications & channel reports (Telegram/Discord/Slack/WhatsApp)",
|
|
22
|
+
OFIERE_MEMORY_OPS: "Conversation history & knowledge memory search",
|
|
23
|
+
OFIERE_PROMPT_OPS: "Manage prompt instruction chunks (CRUD + ordering)",
|
|
24
|
+
OFIERE_CONSTELLATION_OPS: "Create/edit/delete OpenClaw agents from chat",
|
|
25
|
+
OFIERE_FILE_OPS: "Space files: upload, read, move, share, delete",
|
|
26
|
+
OFIERE_PLAN_OPS: "Visual execution plan builder (DAG drafts → real tasks)",
|
|
27
|
+
OFIERE_SOP_OPS: "Standard Operating Procedures (Staff agents). Includes propose_attach/commit_attach for self-attaching SOPs to runs",
|
|
28
|
+
OFIERE_BRAIN_OPS: "Agent memory, knowledge graph, self-improvement (TMT/MAGMA)",
|
|
29
|
+
OFIERE_TALENT_OPS: "Talents: list, get, activate, deactivate cognitive skill presets",
|
|
30
|
+
OFIERE_FRAMEWORK_OPS: "Corporate Frameworks (C-Suite agents). Includes propose_attach/commit_attach for self-attaching Frameworks to runs",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// ─── Tier B: Full Tool Documentation ────────────────────────────────────────
|
|
34
|
+
// These are used as tool descriptions in registerTools(), NOT in the system prompt.
|
|
35
|
+
// The LLM sees them only when exploring available tools or preparing a tool call.
|
|
36
|
+
|
|
37
|
+
export const TOOL_DOCS: Record<string, string> = {
|
|
38
|
+
OFIERE_TASK_OPS: `Manage tasks and approvals.
|
|
39
|
+
Actions: "list", "create", "update", "delete", "add_approval", "list_approvals", "resolve_approval"
|
|
40
|
+
- list: Filter by status, agent_id, space_id, folder_id, limit. Returns execution_plan, goals, constraints if present
|
|
41
|
+
- create: Requires title. IMPORTANT: Always pass agent_id with your own name to self-assign (e.g. agent_id: "celia")
|
|
42
|
+
- Optional: description, instructions, execution_plan, goals, constraints, system_prompt, priority, tags, dates
|
|
43
|
+
- For COMPLEX tasks: include execution_plan (step-by-step), goals, constraints, and system_prompt
|
|
44
|
+
- For SIMPLE tasks: just title and optionally description
|
|
45
|
+
- update: Requires task_id. All create fields + progress
|
|
46
|
+
- delete: Requires task_id. Removes task and subtasks
|
|
47
|
+
- add_approval: Request sign-off. Requires: task_id, approver_name. Optional: approver_type (human|agent), due_date, comment
|
|
48
|
+
- list_approvals: List approvals. Optional: task_id, approval_status (pending|approved|rejected)
|
|
49
|
+
- resolve_approval: Approve/reject. Requires: approval_id, approval_status. Optional: comment`,
|
|
50
|
+
|
|
51
|
+
OFIERE_AGENT_OPS: `Query + manage agents and their staff subagents.
|
|
52
|
+
Actions: "list", "list_subagents", "create_subagent", "delete_subagent", "invalidate_tier_cache"
|
|
53
|
+
- list: All top-level agents (chiefs / native + OpenClaw) with IDs, names, roles. Use for task assignment lookup.
|
|
54
|
+
- list_subagents: Staff under a chief. Required: chief_agent_id.
|
|
55
|
+
- create_subagent: Add a staff subagent under a chief (max 5 per chief). Required: chief_agent_id, name. Optional: role (default "Staff"), codename, color_hex.
|
|
56
|
+
- delete_subagent: Remove a staff subagent. Required: subagent_id.
|
|
57
|
+
- invalidate_tier_cache: Flush plugin's in-process tier cache (5 min TTL). Optional: agent_id. Use after direct-DB mutation of agent_tier_overrides.`,
|
|
58
|
+
|
|
59
|
+
OFIERE_PROJECT_OPS: `Manage PM hierarchy.
|
|
60
|
+
Actions: "list_spaces", "create_space", "update_space", "delete_space", "list_folders", "create_folder", "update_folder", "delete_folder", "list_dependencies", "add_dependency", "remove_dependency"
|
|
61
|
+
- Spaces: Top-level containers. CRUD with name, icon, icon_color
|
|
62
|
+
- Folders: Inside spaces. Nest via parent_folder_id. Types: folder, project
|
|
63
|
+
- Dependencies: Link tasks. Types: finish_to_start (default), start_to_start, finish_to_finish, start_to_finish. lag_days optional`,
|
|
64
|
+
|
|
65
|
+
OFIERE_SCHEDULE_OPS: `Calendar events.
|
|
66
|
+
Actions: "list", "create", "update", "delete"
|
|
67
|
+
- list: Filter by start_date, end_date, agent_id
|
|
68
|
+
- create: Requires title + scheduled_date (YYYY-MM-DD). Optional: scheduled_time, duration_minutes, task_id, agent_id, recurrence_type, color
|
|
69
|
+
- Recurrence: none, hourly, daily, weekly, monthly with interval`,
|
|
70
|
+
|
|
71
|
+
OFIERE_KNOWLEDGE_OPS: `Ofiere Knowledge Library.
|
|
72
|
+
Actions: "search", "list", "create", "update", "delete"
|
|
73
|
+
- ALWAYS use when user mentions "knowledge base", "knowledge library", or asks to recall stored knowledge
|
|
74
|
+
- search: Keyword search. Requires: query
|
|
75
|
+
- list: Paginated listing with full content. Optional: search filter
|
|
76
|
+
- create: Requires: file_name. Optional: content, source, author, credibility_tier
|
|
77
|
+
- update/delete: By document ID`,
|
|
78
|
+
|
|
79
|
+
OFIERE_WORKFLOW_OPS: `Full workflow automation (13 actions).
|
|
80
|
+
Actions: "list", "get", "create", "update", "delete", "list_runs", "trigger", "add_nodes", "update_node", "delete_nodes", "add_edges", "delete_edges", "insert_node_between"
|
|
81
|
+
- ALWAYS call "get" before modifying to see node IDs and graph structure
|
|
82
|
+
- Node types: manual_trigger, webhook_trigger, agent_step, formatter_step, http_request, task_call, variable_set, condition, human_approval, delay, loop, convergence, output, checkpoint, note
|
|
83
|
+
- Edge handles: condition edges use "condition-true"/"condition-false". Loop edges use "loop_body"/"done"
|
|
84
|
+
- Variables: {{prev.nodeId.outputText}}, {{variables.key}}`,
|
|
85
|
+
|
|
86
|
+
OFIERE_NOTIFY_OPS: `Notifications & Channel Reports.
|
|
87
|
+
Actions: "list", "mark_read", "mark_all_read", "delete", "send_report", "get_task_detail", "schedule_report", "list_schedules", "delete_schedule"
|
|
88
|
+
- send_report: Send PM progress report to YOUR channels. Required: scope_type, agent_id (YOUR name)
|
|
89
|
+
- get_task_detail: Get full task result by report number. Required: task_number
|
|
90
|
+
- schedule_report: Recurring reports. Required: scope_type, recurrence_type, agent_id`,
|
|
91
|
+
|
|
92
|
+
OFIERE_MEMORY_OPS: `Conversation history & knowledge memory.
|
|
93
|
+
Actions: "list_conversations", "get_messages", "search_messages", "add_knowledge", "search_knowledge"`,
|
|
94
|
+
|
|
95
|
+
OFIERE_PROMPT_OPS: `Manage prompt instruction chunks.
|
|
96
|
+
Actions: "list", "get", "create", "update", "delete"
|
|
97
|
+
- create: New chunk with name (max 30 chars) + content. Optional: color (hex), category`,
|
|
98
|
+
|
|
99
|
+
OFIERE_CONSTELLATION_OPS: `Create/edit/delete OpenClaw agents from chat.
|
|
100
|
+
Actions: "list_agents", "get_agent", "read_file", "write_file", "create_agent", "delete_agent", "delete_file", "read_blueprint", "list_agent_mesh"
|
|
101
|
+
- CRITICAL: ALWAYS call read_blueprint before creating/editing agents
|
|
102
|
+
- delete_agent: IRREVERSIBLE. Always ask user for explicit confirmation first`,
|
|
103
|
+
|
|
104
|
+
OFIERE_FILE_OPS: `Manage Space Files.
|
|
105
|
+
Actions: "list_files", "list_folders", "create_folder", "create_text_file", "upload_file", "read_text_file", "rename_file", "rename_folder", "move_file", "move_folder", "delete_file", "delete_folder", "share_file", "unshare_file"
|
|
106
|
+
- read_text_file: Use when task references @[name](file:ID)
|
|
107
|
+
- Files appear in PM Space Files tab immediately`,
|
|
108
|
+
|
|
109
|
+
OFIERE_PLAN_OPS: `Visual execution plan builder.
|
|
110
|
+
Actions: "list", "get", "create", "update", "delete", "add_nodes", "execute"
|
|
111
|
+
- Plans are visual DAG drafts — not real tasks until "execute"
|
|
112
|
+
- Node types: task, gate, milestone
|
|
113
|
+
- Execution maps ALL fields: execution_steps, goals, constraints, system_prompt`,
|
|
114
|
+
|
|
115
|
+
OFIERE_SOP_OPS: `Standard Operating Procedures.
|
|
116
|
+
Actions: "list_templates", "create", "list", "get", "update", "delete", "list_subagents", "apply_template", "propose_attach", "commit_attach"
|
|
117
|
+
- sop_data: { title, purpose, scope, applicability, prerequisites:{ conditions, required_tools, required_permissions, safety_warnings }, procedure_steps[], expected_outputs[], escalation_rules[], acceptance_criteria[], rollback_procedure, notes }
|
|
118
|
+
- Legacy field names still accepted (objective→purpose, steps→procedure_steps, deliverables→expected_outputs, escalationRules→escalation_rules, successCriteria→acceptance_criteria) — prefer new names.
|
|
119
|
+
- propose_attach / commit_attach: attach SOPs to a run (target_kind: conversation|task|scheduler_event). Tier rule: SOPs only attach to STAFF-tier targets; for c-suite use OFIERE_FRAMEWORK_OPS instead. propose_attach returns a token-cost summary + confirmation_token (5-min ttl). You MUST surface the cost and ask the user before calling commit_attach. The user must explicitly approve.
|
|
120
|
+
- See SOP PROTOCOL section for when to load vs skip`,
|
|
121
|
+
|
|
122
|
+
OFIERE_BRAIN_OPS: `Agent memory, knowledge graph, self-improvement (TMT/MAGMA).
|
|
123
|
+
Memory Tiers: L1_focus (24h), L2_episode (days), L3_pattern (weeks), L4_rule (permanent), L5_persona (permanent)
|
|
124
|
+
Actions: save_memory, recall, delete_memory, promote_memory, log_learning, list_learnings, resolve_learning, save_entity, link_entities, query_graph, start_trajectory, end_trajectory, get_brain_status
|
|
125
|
+
- This is your SUBCONSCIOUS — use instinctively, not deliberately`,
|
|
126
|
+
|
|
127
|
+
OFIERE_TALENT_OPS: `Manage cognitive skill presets (Talents).
|
|
128
|
+
Actions: "list", "get", "activate", "deactivate"
|
|
129
|
+
- list: List all talents. Optional: category, scope, status
|
|
130
|
+
- get: Get full talent details. Required: talent_id OR name
|
|
131
|
+
- activate: Enable a talent (status → active). Required: talent_id
|
|
132
|
+
- deactivate: Disable a talent (status → inactive). Required: talent_id
|
|
133
|
+
- Active talents inject their execution_protocol and guardrails into your system prompt automatically
|
|
134
|
+
- Talents chain other tools: SPHINX chains KNOWLEDGE_OPS+BRAIN_OPS, PRISM chains BRAIN_OPS trajectories, ATLAS chains PLAN_OPS+TASK_OPS+SOP_OPS`,
|
|
135
|
+
|
|
136
|
+
OFIERE_FRAMEWORK_OPS: `Corporate Frameworks — strategic mandates, KPIs, risk governance.
|
|
137
|
+
Actions: "create", "list", "get", "update", "delete", "propose_attach", "commit_attach"
|
|
138
|
+
- content: JSON string with { mission, vision, core_principles[], decision_authority, budget_constraints, resource_limits, tool_stack[], strategic_objectives[], risk_appetite, compliance_requirements[], escalation_matrix[], team_composition (STRING — paragraph or newline-joined, NOT an array), integration_points[], review_frequency, last_reviewed, next_review, notes }
|
|
139
|
+
- propose_attach / commit_attach: attach Frameworks to a run (target_kind: conversation|task|scheduler_event). Tier rule: Frameworks only attach to C-SUITE-tier targets; for staff use OFIERE_SOP_OPS instead. propose_attach returns a token-cost summary + confirmation_token (5-min ttl). You MUST surface the cost and ask the user before calling commit_attach. The user must explicitly approve.`,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export function getSystemPrompt(state: {
|
|
143
|
+
ready: boolean;
|
|
144
|
+
toolCount: number;
|
|
145
|
+
agentId: string;
|
|
146
|
+
connectError: string;
|
|
147
|
+
}): string {
|
|
148
|
+
if (state.ready && state.toolCount > 0) {
|
|
149
|
+
const agentLine = state.agentId
|
|
150
|
+
? `Your agent ID is "${state.agentId}". You are registered in the Ofiere system.`
|
|
151
|
+
: `Your agent identity will be auto-detected at runtime. When you call any OFIERE tool, the system knows who you are.`;
|
|
152
|
+
|
|
153
|
+
const assignRule = state.agentId
|
|
154
|
+
? `When you create a task without specifying agent_id, it is assigned to YOU (${state.agentId}).`
|
|
155
|
+
: `When you create a task without specifying agent_id, it is assigned to YOU automatically.`;
|
|
156
|
+
|
|
157
|
+
// Tier A: Compact tool index (~300 tokens vs ~3000 for full docs)
|
|
158
|
+
const toolIndex = Object.entries(TOOL_SUMMARIES)
|
|
159
|
+
.map(([name, desc]) => `- **${name}** — ${desc}`)
|
|
160
|
+
.join("\n");
|
|
161
|
+
|
|
162
|
+
return `<ofiere-pm>
|
|
163
|
+
You are connected to the Ofiere Project Management dashboard via the Ofiere PM plugin.
|
|
164
|
+
${agentLine}
|
|
165
|
+
|
|
166
|
+
## Your Ofiere PM Tools (${state.toolCount} meta-tools)
|
|
167
|
+
|
|
168
|
+
Each tool uses an "action" parameter to select the operation. Always include action.
|
|
169
|
+
Full parameter docs are in each tool's description — call the tool to see details.
|
|
170
|
+
|
|
171
|
+
${toolIndex}
|
|
172
|
+
|
|
173
|
+
## ⛔ PLANNING GATE (NON-NEGOTIABLE)
|
|
174
|
+
- Before creating ANY task with 3+ total execution steps, goals, or constraints, you MUST ask the user: "Would you like me to plan this first, or create the task directly?"
|
|
175
|
+
- If the user chooses to plan, use OFIERE_PLAN_OPS to create a visual plan first, then execute it.
|
|
176
|
+
- NEVER skip this step. The server will block creation of complex tasks — use action: "create_force" only if the user explicitly confirms bypass.
|
|
177
|
+
|
|
178
|
+
## Rules
|
|
179
|
+
- ALWAYS pass agent_id with your own name when creating tasks (e.g. agent_id: "ivy").
|
|
180
|
+
- ${assignRule}
|
|
181
|
+
- To create an unassigned task, pass agent_id as "none" or "unassigned".
|
|
182
|
+
- When user says "create a task for [agent]", use OFIERE_AGENT_OPS action:"list" first.
|
|
183
|
+
- Task statuses: PENDING, IN_PROGRESS, DONE, FAILED. Priority: 0=LOW, 1=MED, 2=HIGH, 3=CRITICAL.
|
|
184
|
+
- Changes appear in the dashboard immediately via real-time sync.
|
|
185
|
+
- Do NOT fabricate task IDs — always look up real IDs first.
|
|
186
|
+
- For complex tasks, include execution_plan, goals, constraints. For simple tasks, just title.
|
|
187
|
+
- When user asks about "knowledge base/library", ALWAYS use OFIERE_KNOWLEDGE_OPS.
|
|
188
|
+
- CONSTELLATION: ALWAYS read_blueprint before creating/editing agents. ALWAYS confirm before delete.
|
|
189
|
+
- WORKFLOWS: ALWAYS "get" before modifying. Use "insert_node_between" for mid-flow additions.
|
|
190
|
+
- CHANNEL REPORTS: ALWAYS include agent_id (YOUR name) in send_report. Use get_task_detail for drill-down.
|
|
191
|
+
- File refs @[name](file:ID): Use OFIERE_FILE_OPS read_text_file to retrieve — don't ask user.
|
|
192
|
+
- Task approvals (OFIERE_TASK_OPS) ≠ workflow gate approvals (human_approval nodes).
|
|
193
|
+
|
|
194
|
+
## SOP PROTOCOL — Adaptive Complexity
|
|
195
|
+
|
|
196
|
+
Classify complexity before executing:
|
|
197
|
+
- **User Override**: "apply full SOP"/"use SOP" → 🔴 COMPLEX. "no SOP"/"just do it" → 🟢 SIMPLE.
|
|
198
|
+
- **🟢 SIMPLE** (≤2 tool calls, no coordination): Execute directly. Do NOT mention SOPs.
|
|
199
|
+
- **🟡 MODERATE** (3-5 calls, single dept): Ask briefly if SOPs needed.
|
|
200
|
+
- **🔴 COMPLEX** (5+ calls, multi-dept, escalation risk): Auto-load relevant SOPs via list→get.
|
|
201
|
+
|
|
202
|
+
## Agent Brain Protocol (TMT Subconscious)
|
|
203
|
+
|
|
204
|
+
Your brain persists across conversations. L5 persona, L4 guardrails, L1 focus are injected at startup.
|
|
205
|
+
- Save memories after significant interactions (not greetings/CRUD). Keep content to 1-3 sentences.
|
|
206
|
+
- Log learnings on corrections, errors, feature requests, insights, best practices.
|
|
207
|
+
- Do NOT announce memory operations — this is subconscious.
|
|
208
|
+
- Never delay your reply to save a memory.
|
|
209
|
+
</ofiere-pm>`;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (state.ready) {
|
|
213
|
+
const diagnostic = diagnoseError(state.connectError);
|
|
214
|
+
return `<ofiere-pm>
|
|
215
|
+
The Ofiere PM plugin failed to connect.${state.connectError ? ` Error: ${state.connectError}` : ""}
|
|
216
|
+
|
|
217
|
+
Diagnosis: ${diagnostic.reason}
|
|
218
|
+
|
|
219
|
+
When the user asks about task management or the Ofiere dashboard, respond with:
|
|
220
|
+
"${diagnostic.userMessage}"
|
|
221
|
+
|
|
222
|
+
Do NOT pretend Ofiere tools exist or hallucinate tool calls. You have zero Ofiere tools available.
|
|
223
|
+
</ofiere-pm>`;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return `<ofiere-pm>
|
|
227
|
+
The Ofiere PM plugin is loading. Tools should be available shortly.
|
|
228
|
+
If the user asks about tasks right now, ask them to wait a moment.
|
|
229
|
+
</ofiere-pm>`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function diagnoseError(error: string): { reason: string; userMessage: string } {
|
|
233
|
+
const lower = error.toLowerCase();
|
|
234
|
+
|
|
235
|
+
if (!error) {
|
|
236
|
+
return {
|
|
237
|
+
reason: "Connected but no tools were registered.",
|
|
238
|
+
userMessage:
|
|
239
|
+
"The Ofiere PM plugin connected but could not register tools. " +
|
|
240
|
+
"Run `openclaw ofiere doctor` to diagnose.",
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (lower.includes("supabase") || lower.includes("url") || lower.includes("key")) {
|
|
245
|
+
return {
|
|
246
|
+
reason: "Supabase connection configuration issue.",
|
|
247
|
+
userMessage:
|
|
248
|
+
"The Ofiere PM plugin could not connect to Supabase. " +
|
|
249
|
+
"Check your configuration with `openclaw ofiere status` and re-run " +
|
|
250
|
+
"`openclaw ofiere setup` if needed, then `openclaw gateway restart`.",
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (lower.includes("user_id") || lower.includes("userid")) {
|
|
255
|
+
return {
|
|
256
|
+
reason: "Missing or invalid user ID in configuration.",
|
|
257
|
+
userMessage:
|
|
258
|
+
"The Ofiere PM plugin needs a valid user ID. " +
|
|
259
|
+
"Run `openclaw ofiere setup` with your user UUID, then `openclaw gateway restart`.",
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
reason: `Unexpected error: ${error}`,
|
|
265
|
+
userMessage: `The Ofiere PM plugin encountered an error: ${error}. Run \`openclaw ofiere doctor\` for details.`,
|
|
266
|
+
};
|
|
267
|
+
}
|