Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 56 additions & 6 deletions .opencode/plugins/daem0n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,28 @@ import type { Plugin } from "@opencode-ai/plugin";
// Covenant rules injected into every system prompt
// ---------------------------------------------------------------------------

const WORKFLOW_SCOPE = `Follow the current task's allowed operations and call order.
system_health is optional; source indexing does not require a health check.
It is not a prerequisite for memory or code tools. Use it only for requested
diagnostics or to investigate an observed failure within that scope; do not
add a startup health probe. The full session_brief is optional in guided mode,
not a prerequisite; strict mode keeps its explicit briefing requirements.
Prefer directly listed typed tools. Discover hidden or unlisted targets with
daem0n_tools_search, then use the gateway for those targets only.
Indexing or searching alone does not require inventing memory writes or outcomes.`;

const COVENANT_RULES_FULL = `<daem0n-covenant>
## The Daem0n v7 Covenant

This project is bound to Daem0n for persistent AI memory. Use exact workspace-scoped
v7 tools: session_brief, memory_preflight, memory_recall, memory_store,
memory_record_outcome, system_health, daem0n_tools_search, and daem0n_tool_call.
Every scoped call must use the supplied opaque workspace_id, never a path or {}.

${WORKFLOW_SCOPE}

### 1. BRIEF
Guided mode automatically briefs an unbriefed session on memory_recall, memory_preflight, memory_store, or memory_record_outcome, returning meta.covenant.auto_brief. Diagnostic and discovery calls do not trigger briefing. Call session_brief for the full brief.
Guided mode automatically briefs an unbriefed session on memory_recall, memory_preflight, memory_store, or memory_record_outcome, returning meta.covenant.auto_brief. Diagnostic and discovery calls do not trigger briefing.

### 2. WRITE
Call memory_store (or any protected tool) directly. If it returns COUNSEL_REQUIRED, read error.counsel (guidance and reasons), then retry exactly error.remedy. memory_preflight remains available for planning a change in advance.
Expand All @@ -36,7 +49,7 @@ valid for 300 seconds, bound to workspace, principal, session, tool and argument
Use a stable idempotency_key for memory_store and save its record_id.

### 3. OTHER CAPABILITIES
Use daem0n_tools_search(query), then daem0n_tool_call(workspace_id, tool, arguments).
For hidden or unlisted tools, use daem0n_tools_search(query), then daem0n_tool_call(workspace_id, tool, arguments).
Defaults: DAEM0NMCP_COVENANT_MODE=guided and DAEM0NMCP_TOOL_SURFACE=core.
DAEM0NMCP_COVENANT_MODE=strict requires explicit session_brief, exact
memory_preflight, and token-bearing writes; DAEM0NMCP_TOOL_SURFACE=full lists all tools.
Expand All @@ -54,9 +67,11 @@ at /mcp. Migration mapping: docs/v6-to-v7-tools.json.
const COVENANT_RULES_SIMPLIFIED = `<daem0n-covenant mode="simplified">
## Memory Protocol

Guided mode automatically briefs an unbriefed session on memory_recall, memory_preflight, memory_store, or memory_record_outcome, returning meta.covenant.auto_brief. Diagnostic and discovery calls do not trigger briefing. Call session_brief for the full brief.
${WORKFLOW_SCOPE}

Guided mode automatically briefs an unbriefed session on memory_recall, memory_preflight, memory_store, or memory_record_outcome, returning meta.covenant.auto_brief. Diagnostic and discovery calls do not trigger briefing.
Call memory_store (or any protected tool) directly. If it returns COUNSEL_REQUIRED, read error.counsel (guidance and reasons), then retry exactly error.remedy. memory_preflight remains available for planning a change in advance.
Use daem0n_tools_search(query), then daem0n_tool_call(workspace_id, tool, arguments).
For hidden or unlisted tools, use daem0n_tools_search(query), then daem0n_tool_call(workspace_id, tool, arguments).
RECALL: daem0nmcp_memory_recall(workspace_id="<workspace_id>", query="...", limit=10)
STORE: daem0nmcp_memory_store(workspace_id="<workspace_id>", record_type="decision", content="...", idempotency_key="<stable-key>")
OUTCOME: daem0nmcp_memory_record_outcome(workspace_id="<workspace_id>", record_id="<mem_id>", outcome_text="...", worked=true|false, idempotency_key="<stable-key>")
Expand All @@ -66,7 +81,7 @@ Strict ceremony: DAEM0NMCP_COVENANT_MODE=strict. Full listing: DAEM0NMCP_TOOL_SU
Rules:
- Never use paths as workspace selectors.
- Reuse an idempotency key when retrying the same write.
- Use daem0nmcp_system_health for diagnostics.
- Use daem0nmcp_system_health only for diagnostics within the task's scope.
- Exact host-prefixed names are accepted; lookalike substrings are not.
- Migration mapping: docs/v6-to-v7-tools.json.
</daem0n-covenant>`;
Expand All @@ -81,6 +96,7 @@ type HookResult = { exitCode: number; stdout: string; stderr: string };
// under into its copy of this file; it is never read from opencode.json or any
// other file or variable the opened project can supply.
const PYTHON_EXECUTABLE = "python";
const INSTALLED_AUTOMATION_MODE: string | undefined = undefined;

// Hooks start inside the opened project, where "python -m" would import the
// project's own "daem0nmcp" directory first. This runs the module the same way
Expand All @@ -100,6 +116,7 @@ const BRIDGE_ENV_KEYS = new Set([
"DAEM0NMCP_EDIT_HOST_STATE_FILE",
"DAEM0NMCP_PROJECT_ROOT",
"DAEM0NMCP_STORAGE_PATH",
"DAEM0NMCP_AUTOMATION_MODE",
]);

async function loadBridgeEnvironment(directory: string): Promise<Record<string, string>> {
Expand Down Expand Up @@ -202,6 +219,17 @@ function isEditPreflightTool(tool: string): boolean {
);
}

function editExecutionStatus(result: unknown): "succeeded" | "failed" {
if (!result || typeof result !== "object") return "failed";
const value = result as Record<string, unknown>;
if (value.isError === true || value.success === false) return "failed";
if (["error", "failed", "skipped", "cancelled", "denied"].includes(String(value.status))) {
return "failed";
}
// V1 invokes execute.after for an actual completed tool execution.
return "succeeded";
}

function extractAdditionalContext(stdout: string): string {
if (!stdout) return "";
try {
Expand All @@ -226,6 +254,12 @@ function reminderKey(input: { callID?: string; sessionID?: string; tool: string

export const Daem0nPlugin: Plugin = async ({ directory }) => {
const bridgeEnvironment = await loadBridgeEnvironment(directory);
const automationMode = INSTALLED_AUTOMATION_MODE ?? bridgeEnvironment.DAEM0NMCP_AUTOMATION_MODE;
if (automationMode === "off") return {};
const enforce = automationMode === "enforce";
if (INSTALLED_AUTOMATION_MODE !== undefined) {
bridgeEnvironment.DAEM0NMCP_AUTOMATION_MODE = INSTALLED_AUTOMATION_MODE;
}
const pendingReminders = new Map<string, string>();
return {
// -----------------------------------------------------------------------
Expand Down Expand Up @@ -261,7 +295,7 @@ export const Daem0nPlugin: Plugin = async ({ directory }) => {
},
bridgeEnvironment,
5_000,
false,
enforce,
);
if (result.exitCode === 2) {
throw new Error(
Expand Down Expand Up @@ -318,6 +352,7 @@ export const Daem0nPlugin: Plugin = async ({ directory }) => {
tool_input: input.args ?? {},
tool_response: output,
tool_use_id: input.callID,
execution_status: editExecutionStatus(output),
}, bridgeEnvironment);
} else if (isEditTool(input.tool)) {
const result = await runHook(directory, "post_edit", {
Expand All @@ -328,6 +363,7 @@ export const Daem0nPlugin: Plugin = async ({ directory }) => {
tool_input: input.args ?? {},
tool_response: output,
tool_use_id: input.callID,
execution_status: editExecutionStatus(output),
}, bridgeEnvironment);
const postReminder = extractAdditionalContext(result.stdout);
if (postReminder) {
Expand Down Expand Up @@ -358,6 +394,20 @@ export const Daem0nPlugin: Plugin = async ({ directory }) => {
cwd: directory,
hook_event_name: "Stop",
}, bridgeEnvironment, 15_000);
} else if (event.type === "message.part.updated") {
const part = event.properties?.part;
if (enforce && part?.type === "tool" && part.state?.status === "error" && isEditTool(part.tool)) {
await runHook(directory, "post_edit", {
session_id: part.sessionID,
cwd: directory,
hook_event_name: "PostToolUseFailure",
tool_name: part.tool,
tool_input: part.state.input,
tool_response: { isError: true },
tool_use_id: part.callID,
execution_status: "failed",
}, bridgeEnvironment);
}
}
} catch {
// Never throw from event hooks. Best-effort only.
Expand Down
44 changes: 32 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,17 +358,23 @@ does not register every CLI found on the machine.
| Codex (`codex`) | `install-client codex` | `.codex/config.toml` |
| Antigravity CLI (`agy`) | `install-client agy` | `.agents/mcp_config.json` |
| OpenCode V1 (`opencode`) | `install-client opencode` | `opencode.json(c)` or `.opencode/opencode.json(c)` |
| OpenCode V2 (`opencode`) | `install-client opencode --opencode-interface v2 --client-version <version>` | V2 `mcp.servers` in its own project configuration |
| Oh My Pi (`omp`) | `install-client omp` | `.omp/mcp.json` |
| Earendil Works Pi (`pi`) | `install-client pi` | `.pi/mcp.json` |

The project client installer adds native MCP registration and a concise owned
covenant in the effective instruction file: normally `AGENTS.md`, a Codex
override/project fallback, or OpenCode's existing `CLAUDE.md` fallback. It preserves
unrelated configuration and comments, reports backups/conflicts, and leaves
global settings, provider credentials and permission policies alone. The five
new client paths do not automatically install host hooks or legacy edit-bridge
pairing. Guided memory calls return the automatic brief for an unbriefed session;
proactive host reminders are a separate feature.
global settings, provider credentials and permission policies alone. Omitting
`--automation` preserves the previous MCP-only installation behavior. Select
`--automation off|remind|enforce` explicitly to manage supported project hooks
or edit-bridge pairing. Unsupported enforcement requests fail before modifying
the project. See [native automation](docs/native-automation.md) for version
requirements and covered tools, and [client installation](docs/native-client-automation.md)
for configuration examples. Guided memory calls return the automatic brief for
an unbriefed session; instruction loading, reminders, and native edit enforcement
have separate acceptance evidence.

Client support is version-specific. Real Windows client tests passed the core
memory workflow, restart recall and replay checks on Codex 0.167.0, agy 1.4.7,
Expand All @@ -378,7 +384,10 @@ OpenCode 1.18.21, omp 18.16.0 and Earendil Works Pi 1.0.0. See the source-backed
[OMP/Pi](docs/research/cli-hosts-omp-pi-2026-11-12.md) findings for feature and
acceptance boundaries. OpenCode V2 has a different schema and requires separate
integration evidence. Actual setup and live-client results are recorded in the
[multi-CLI acceptance report](docs/release/v7/multi-cli-acceptance-2026-11-12.md).
[historical multi-CLI acceptance report](docs/release/v7/multi-cli-acceptance-2026-11-12.md).
The [native integration follow-up](docs/release/v7/native-integration-2026-11-12.md)
separately records real-source indexing, automation, Windows/macOS/Ubuntu WSL
evidence, frozen backend builds, failed workflows and external blockers.

For agy, keep your normal Google-account sign-in. A Gemini API key is a separate,
optional billing route. To use Google AI credits after your included quota runs
Expand Down Expand Up @@ -769,6 +778,12 @@ Use `system_health` for bounded diagnostics. The complete protocol lives in
python -m daem0nmcp.cli install-claude-hooks
```

For explicit project automation, use `--project-path <project>` before
`install-claude-hooks`, followed by `--automation off|remind|enforce`.
Enforcement additionally requires `--client-version <observed-version>` at
2.1.295 or later. Explicit modes write the project's local settings; omitting
the option retains the user-level behavior described below.

This writes the packaged hook entries to the user-level `~/.claude/settings.json`, so
they run in every project; each runs `daem0nmcp.claude_hooks.<hook>`
with the interpreter you installed from. A hook only acts inside a Daem0n
Expand Down Expand Up @@ -799,15 +814,18 @@ by generating and merging the Daem0n hook entries into the actual settings file.
| `PostToolUse` (`Edit\|Write\|NotebookEdit`) | `post_edit` | Retained edit-bridge plumbing: reports an approved edit as a capture candidate. The current remind-only hooks create no requests, so ordinary client edits produce no bridge capture | stdin event | Yes |
| `Stop`, `SubagentStop` | `stop` | When the transcript shows a finished task with no recorded outcome, suggests direct `memory_store` and `memory_record_outcome` calls with counsel-challenge retry guidance as a `systemMessage`. Never writes memory | stdin event (`transcript_path`) | Yes |

No hook blocks a tool call or keeps the agent running: every hook exits 0 and none
returns a `permissionDecision` or `decision`.
The reminder behavior in this table applies to the legacy installation with
`--automation` omitted and to explicit reminder mode. It does not block edits
or keep the agent running. Explicit `--automation enforce` enables the
[native edit gate](docs/native-automation.md) for its declared edit tools.

**What optional pairing writes.** When `--enable-edit-bridge` (or explicit remote bridge flags) are passed, the installer also pairs the current project (or
`--project-path`) with the local edit bridge:

- an owner-only credential at `~/.daem0nmcp/edit-bridges/<authority>/credential.json`
(the secret is never written into the project), with the bridge socket under
`~/.daem0nmcp/edit-bridges/run/<authority[:16]>/`;
`~/.daem0nmcp/edit-bridges/run/<authority[:16]>/`, or a protected short per-user
temporary endpoint when the Unix socket path would be too long;
- the env keys `DAEM0NMCP_EDIT_BRIDGE_CREDENTIAL_FILE`,
`DAEM0NMCP_EDIT_BRIDGE_RUNTIME_DIR`, `DAEM0NMCP_PROJECT_ROOT` and
`DAEM0NMCP_STORAGE_PATH` in `<project>/.claude/settings.local.json`.
Expand Down Expand Up @@ -835,10 +853,12 @@ OpenCode V1 connects through its native MCP manager. For a new project use
grimoire's real MCP and restart verification. The new installer creates the
project binding and managed covenant without requiring the legacy plugin.

The optional existing V1 plugin provides Covenant guidance and edit/Bash reminders. Its installed
hooks do not create native edit-bridge requests or enforce a
deny/preflight/retry flow; bridge API acceptance is separate from this
remind-only client integration.
The legacy/default V1 plugin provides Covenant guidance and edit/Bash reminders.
Explicit `install-client opencode --automation enforce` installs the native
deny/preflight/retry flow for declared edit tools. See
[native automation](docs/native-automation.md) for coverage and version
requirements, and the [native acceptance report](docs/release/v7/native-automation-acceptance-2026-11-12.md)
for observed host behavior.

### Configuration

Expand Down
18 changes: 11 additions & 7 deletions daem0nmcp/api/v7/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
)
from .models import CapabilityState
from .policy import V7_TOOL_LEVELS
from .remedies import compact_remedy_arguments
from .responses import ResponseFactory
from .tasks import (
durable_task_execution_var,
Expand Down Expand Up @@ -283,14 +284,17 @@ async def invoke(**arguments: Any) -> object:
ErrorCode.COUNSEL_REQUIRED,
"Review error.counsel, then retry exactly error.remedy.",
remedy_tool=tool_name,
remedy_arguments={
**{
k: v
for k, v in effective.items()
if k != "preflight_token"
remedy_arguments=compact_remedy_arguments(
input_model,
{
**{
k: v
for k, v in effective.items()
if k != "preflight_token"
},
"preflight_token": outcome.challenge.preflight_token,
},
"preflight_token": outcome.challenge.preflight_token,
},
),
counsel=outcome.challenge,
)
if is_capacity_violation(violation):
Expand Down
Loading
Loading