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
10 changes: 7 additions & 3 deletions bridges/kimaki.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ _kimaki_install_systemd() {

local ENV_BLOCK="Environment=HOME=$SERVICE_HOME
Environment=PATH=$PATH_VALUE
Environment=KIMAKI_DATA_DIR=$KIMAKI_DATA_DIR"
Environment=KIMAKI_DATA_DIR=$KIMAKI_DATA_DIR
Environment=DATAMACHINE_SITE_PATH=$SITE_PATH"
if [ -n "$KIMAKI_BOT_TOKEN" ]; then
ENV_BLOCK="$ENV_BLOCK
Environment=KIMAKI_BOT_TOKEN=$KIMAKI_BOT_TOKEN"
Expand Down Expand Up @@ -398,7 +399,8 @@ bridge_update_systemd() {

local TEMPLATE_ENV="Environment=HOME=$SERVICE_HOME
Environment=PATH=$PATH_VALUE
Environment=KIMAKI_DATA_DIR=$KIMAKI_DATA_DIR"
Environment=KIMAKI_DATA_DIR=$KIMAKI_DATA_DIR
Environment=DATAMACHINE_SITE_PATH=$SITE_PATH"

local MERGED_ENV
MERGED_ENV=$(_merge_systemd_env_lines "$CURRENT_ENV" "$TEMPLATE_ENV")
Expand Down Expand Up @@ -528,7 +530,9 @@ bridge_render_launchd() {
<key>PATH</key>
<string>$path_value</string>
<key>KIMAKI_DATA_DIR</key>
<string>$KIMAKI_DATA_DIR</string>$(if [ -n "${KIMAKI_BOT_TOKEN:-}" ]; then echo "
<string>$KIMAKI_DATA_DIR</string>
<key>DATAMACHINE_SITE_PATH</key>
<string>$SITE_PATH</string>$(if [ -n "${KIMAKI_BOT_TOKEN:-}" ]; then echo "
<key>KIMAKI_BOT_TOKEN</key>
<string>$KIMAKI_BOT_TOKEN</string>"; fi)
</dict>
Expand Down
38 changes: 4 additions & 34 deletions bridges/kimaki/bin/datamachine-kimaki
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Usage: datamachine-kimaki <kimaki-args...>
Data Machine compatibility adapter for Kimaki.

In Data Machine mode, Kimaki is the Discord transport while Data Machine owns
agent identity, site root, and workspace lifecycle. This adapter normalizes the
Kimaki `send` footgun flags before delegating to the real Kimaki binary:
agent identity and site-root memory. This adapter normalizes the Kimaki `send`
agent slot before delegating to the real Kimaki binary:

send --agent <anything> -> send --agent build
send --cwd <anything> -> stripped
send --worktree [name] -> blocked before native Kimaki worktree handling

Kimaki project, --cwd, and --worktree routing are passed through unchanged.

Set DATAMACHINE_REAL_KIMAKI to the real Kimaki binary path. If unset, the
adapter resolves the next non-adapter `kimaki` from PATH.
Expand Down Expand Up @@ -57,8 +57,6 @@ resolve_real_kimaki() {

normalize_send_args() {
normalized_args=()
saw_worktree=false
local worktree_value=""

while [[ $# -gt 0 ]]; do
case "$1" in
Expand All @@ -73,41 +71,13 @@ normalize_send_args() {
normalized_args+=(--agent build)
shift
;;
--cwd)
shift
if [[ $# -gt 0 && "$1" != --* ]]; then
shift
fi
;;
--cwd=*)
shift
;;
--worktree)
saw_worktree=true
shift
if [[ $# -gt 0 && "$1" != --* ]]; then
worktree_value="$1"
shift
fi
;;
--worktree=*)
saw_worktree=true
worktree_value="${1#--worktree=}"
shift
;;
*)
normalized_args+=("$1")
shift
;;
esac
done

if [[ "$saw_worktree" == true ]]; then
echo "Data Machine mode intercepted kimaki send --worktree${worktree_value:+ $worktree_value}." >&2
echo "Native Kimaki worktrees are disabled on wp-coding-agents installs; use Data Machine Code worktrees instead." >&2
exit 2
fi

return 0
}

Expand Down
22 changes: 17 additions & 5 deletions bridges/kimaki/plugins/dm-agent-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface DmPaths {
const dmAgentSync: Plugin = async ({ $ }) => {
return {
config: async (config) => {
const sitePath = getSitePath();
const wpAvailable = await $`command -v wp`.quiet().nothrow();
if (wpAvailable.exitCode !== 0) {
return;
Expand All @@ -55,13 +56,17 @@ const dmAgentSync: Plugin = async ({ $ }) => {
// edits, or other external processes would leave AGENTS.md stale.
// Running compose here guarantees the file matches live state at the
// moment OpenCode loads the session prompt.
const composeResult = await $`wp datamachine memory compose --allow-root`.quiet().nothrow();
const composeResult = sitePath
? await $`wp --path=${sitePath} datamachine memory compose --allow-root`.quiet().nothrow()
: await $`wp datamachine memory compose --allow-root`.quiet().nothrow();
if (composeResult.exitCode !== 0) {
console.warn(`[dm-agent-sync] memory compose failed (exit ${composeResult.exitCode}): ${await shellOutputText(composeResult)}`);
}

// Query all agents from Data Machine.
const agentsResult = await $`wp datamachine agents list --format=json --allow-root`.quiet().nothrow();
const agentsResult = sitePath
? await $`wp --path=${sitePath} datamachine agents list --format=json --allow-root`.quiet().nothrow()
: await $`wp datamachine agents list --format=json --allow-root`.quiet().nothrow();
if (agentsResult.exitCode !== 0) {
console.warn(`[dm-agent-sync] agents list failed (exit ${agentsResult.exitCode}): ${await shellOutputText(agentsResult)}`);
return;
Expand Down Expand Up @@ -89,7 +94,9 @@ const dmAgentSync: Plugin = async ({ $ }) => {
continue;
}

const pathsResult = await $`wp datamachine memory paths --agent=${agent.agent_slug} --format=json --allow-root`.quiet().nothrow();
const pathsResult = sitePath
? await $`wp --path=${sitePath} datamachine memory paths --agent=${agent.agent_slug} --format=json --allow-root`.quiet().nothrow()
: await $`wp datamachine memory paths --agent=${agent.agent_slug} --format=json --allow-root`.quiet().nothrow();
if (pathsResult.exitCode !== 0) {
console.warn(`[dm-agent-sync] memory paths failed for ${agent.agent_slug} (exit ${pathsResult.exitCode}): ${await shellOutputText(pathsResult)}`);
continue;
Expand All @@ -108,9 +115,10 @@ const dmAgentSync: Plugin = async ({ $ }) => {
continue;
}

const promptRoot = sitePath || ".";
const prompt = [
"{file:./AGENTS.md}",
...paths.relative_files.map((f: string) => `{file:./${f}}`),
`{file:${promptRoot}/AGENTS.md}`,
...paths.relative_files.map((f: string) => `{file:${promptRoot}/${f}}`),
].join("\n");

const agentModel =
Expand Down Expand Up @@ -161,6 +169,10 @@ const dmAgentSync: Plugin = async ({ $ }) => {
};
};

function getSitePath(): string {
return process.env.DATAMACHINE_SITE_PATH || process.env.SITE_PATH || process.env.PWD || "";
}

/**
* Populate build/plan defaults without clobbering user-authored fields.
*
Expand Down
Loading
Loading