Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·132 lines (118 loc) · 6.29 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·132 lines (118 loc) · 6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env bash
#
# Install the nt ↔ OpenCode memory system into your local OpenCode config.
#
# NOTE: `nt opencode install` (built into the binary since the integration
# bundle was embedded) performs these same steps without a repo checkout, on
# every platform — prefer it. This script remains for repo-checkout installs
# (e.g. iterating on the plugin without rebuilding nt).
#
# It is idempotent and safe to re-run. It will:
# 1. register nt's MCP server with OpenCode (absolute path) → mcp.nt
# 2. copy the nt-memory plugin into ~/.config/opencode/plugins/
# 3. copy the `nt` skill into ~/.config/opencode/skills/nt/
# 4. copy the /learn + /recall commands into ~/.config/opencode/commands/
# 5. install a tiny AGENTS.md (only if you don't already have one)
# 6. merge permission.skill.nt=allow into opencode.json
# 7. seed the rules/ and memory/ nt folders and an initial export
#
# Usage: ./install.sh # global install (~/.config/opencode)
# NT_BIN=/path/to/nt ./install.sh
#
set -euo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cfg="${XDG_CONFIG_HOME:-$HOME/.config}/opencode"
nt="${NT_BIN:-nt}"
if ! command -v "$nt" >/dev/null 2>&1; then
echo "error: nt not found on PATH (set NT_BIN=/abs/path/to/nt)." >&2
exit 1
fi
echo "→ OpenCode config dir: $cfg"
mkdir -p "$cfg/plugins" "$cfg/skills/nt" "$cfg/commands"
# 1. Register the MCP server (writes the absolute nt path, idempotent).
echo "→ registering nt MCP server with OpenCode"
"$nt" mcp install --client opencode
# 2–4. Plugin, skill, and the /learn + /recall commands.
echo "→ installing plugin → $cfg/plugins/nt-memory.ts"
cp "$here/plugins/nt-memory.ts" "$cfg/plugins/nt-memory.ts"
echo "→ installing skill → $cfg/skills/nt/SKILL.md"
cp "$here/skills/nt/SKILL.md" "$cfg/skills/nt/SKILL.md"
echo "→ installing command → $cfg/commands/learn.md (/learn — session review & capture)"
cp "$here/commands/learn.md" "$cfg/commands/learn.md"
echo "→ installing command → $cfg/commands/recall.md (/recall — on-demand memory brief)"
cp "$here/commands/recall.md" "$cfg/commands/recall.md"
# 5. AGENTS.md — never clobber an existing one.
if [ -f "$cfg/AGENTS.md" ]; then
echo "→ keeping your existing $cfg/AGENTS.md (see integrations/opencode/AGENTS.md to merge)"
else
echo "→ installing AGENTS.md → $cfg/AGENTS.md"
cp "$here/AGENTS.md" "$cfg/AGENTS.md"
fi
# 6-7. Merge permission.skill.nt = allow and "nt-rules.md" into instructions
# (the hybrid-mode file baseline) into opencode.json without touching the
# rest. Uses node if available; otherwise prints a manual hint.
ocjson="$cfg/opencode.json"
if command -v node >/dev/null 2>&1; then
echo "→ ensuring permission.skill.nt = allow and instructions += nt-rules.md in $ocjson"
node - "$ocjson" <<'NODE'
const fs = require("fs");
const p = process.argv[2];
let root = {};
try { root = JSON.parse(fs.readFileSync(p, "utf8") || "{}"); } catch { root = {}; }
root["$schema"] ||= "https://opencode.ai/config.json";
root.permission ||= {};
root.permission.skill ||= {};
root.permission.skill.nt ||= "allow";
root.instructions ||= [];
if (!root.instructions.includes("nt-rules.md")) root.instructions.push("nt-rules.md");
fs.writeFileSync(p, JSON.stringify(root, null, 2) + "\n");
NODE
else
echo " (node not found — add \"permission\": { \"skill\": { \"nt\": \"allow\" } } and \"instructions\": [\"nt-rules.md\"] to $ocjson by hand)"
fi
# 7. Seed the always-in-context folders + an initial rules export. These notes are
# examples you can edit or delete; the folders are what matter.
# Guard on the JSON empty-array marker: `nt notes --folder X` prints the human
# string "no notes" (non-empty) on an empty store, so a `[ -z ... ]` test is
# FALSE and would SKIP seeding on the very first run — shipping an empty injected
# block. `--json` returns "[]" on an empty folder, which we can test reliably.
echo "→ seeding nt rules/ and memory/ folders (examples — edit or remove)"
is_empty_folder() { [ "$("$nt" notes --folder "$1" --json 2>/dev/null | tr -d '[:space:]')" = "[]" ]; }
if is_empty_folder rules; then
"$nt" note "Output style: terse factual bullets" \
--description "How the agent should phrase answers by default" \
--body "- Answer in bullet points, not prose.
- Plain, direct words. No filler, hedging, or fancy phrasing.
- Lead with the fact/answer; skip preamble and restating the question.
- Elaborate only when asked." \
--folder rules --tag rule --source opencode >/dev/null || true
fi
if is_empty_folder memory; then
"$nt" note "Project + user facts the agent should always know" \
--description "Durable user preferences and project conventions (edit me)" \
--body "Edit this note (or add siblings tagged memory-core) with durable preferences and conventions." \
--folder memory --tag memory-core --source opencode >/dev/null || true
fi
# Initial export so nt-rules.md exists immediately — the plugin overwrites it
# with the full compiled (rules+memory) block at every session start anyway,
# but this guarantees the file baseline isn't missing before the first session.
"$nt" export --tag rule --title "Rules" --out "$cfg/nt-rules.md" >/dev/null || true
cat <<EOF
✓ Done. Restart OpenCode (or reload MCP) to pick up nt.
Next:
• Edit your rules: nt note "<rule>" --kind rule --description "…"
• Edit core memory: nt note "<fact>" --kind memory --description "…"
• Everything else is normal nt notes, retrieved on demand via the nt_* tools.
• Inspect what gets injected: nt export --tag rule --title Rules
Modes (env on the OpenCode process, e.g. via the plugin):
NT_INJECT=hybrid (default) session-start file baseline (guaranteed — loaded
via "instructions") + live updates via the system-prompt
transform when it changes mid-session (best-effort)
NT_INJECT=system transform-only, no file baseline (the old default)
NT_INJECT=file file-only, no live transform push
NT_INJECT=off rely on AGENTS.md + on-demand MCP only
Learning-loop automation (all ON by default; set =0 to disable):
NT_COMPACT carry open nt tasks + recall directive through compaction
NT_ERROR_RECALL failed bash → auto nt recall --lessons-only into next turn
NT_IDLE_NUDGE toast when a session ends without capturing anything
EOF