Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Thumbs.db

# Editor backups
* 2.*
reports/
30 changes: 30 additions & 0 deletions plan/implementation-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,36 @@ The registry is a **notary proxy** — it does not host `.cgp` files. Publishers
- A1-A10 validation rejects malformed publishes at registry level ✅
- `cpm init my-skill` creates a valid .cgp skeleton ✅

### Phase 8: Autonomous Package Management

**Repos:** `core-mcp-bridges`, `cognitiveosd`, `inference`, `product-specs`

**Goal:** The Wide Model can autonomously discover, install, and remove packages in response to human requests, with every operation validated by the Raw Model.

| Task | Dependencies | Est. effort | Status |
|------|-------------|-------------|--------|
| ADR-004: Package Manager MCP Bridge decision record | None | Small | ✅ Done |
| `product-specs/specs/base-prompt.md` — daemon-level system prompt | None | Small | Pending |
| `cognitiveos.package.*` domain in mcp-conventions.md | None | Small | Pending |
| `validate_package_request` RPC in raw-model.md spec | None | Small | Pending |
| Validation-hook section in cognitiveosd-api.md | None | Small | Pending |
| `package-mcp` bridge in core-mcp-bridges/ | MCP server library | Medium | Pending |
| MCP validation hook in cognitiveosd mcp_lifecycle.go | cognitiveosd-api spec | Small | Pending |
| `validate_package_request` handler in cograw | raw-model.md spec | Small | Pending |
| `ValidatePackageRequest` method in raw_client.go | None | Small | Pending |
| `package-mcp` in default MCPBridges config | None | Small | Pending |
| Base system prompt injection in daemon startup | None | Small | Pending |
| Tool validation wiring in handlers.go (toolLoop) | None | Small | Pending |

**Definition of done:**
- Wide Model calls `cognitiveos.package.search("photo viewer")` → daemon validates → package-mcp runs `cpm search`
- Wide Model calls `cognitiveos.package.install("photo-viewer")` → daemon validates via Raw Model → package-mcp runs `cpm install`
- Raw Model denies install if manifest contains `raw_model` field
- Raw Model enforces rate limit (5 ops / 5 min)
- Read-only ops (search/list/info) go through validation with reduced checks
- Base system prompt tells the Wide Model it can autonomously install capabilities
- All 6 package tools are registered and discoverable via `mcp.list_tools`

## Build Order with Milestones

```
Expand Down
115 changes: 101 additions & 14 deletions scripts/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
# shellcheck disable=SC3043
set -e

# ── Config ──
Expand Down Expand Up @@ -49,11 +50,10 @@ EOF

check() {
local name="$1" status="$2" detail="$3"
local tag=""
case "$status" in
pass) tag="PASS"; pass=$((pass+1)) ;;
fail) tag="FAIL"; fail=$((fail+1)) ;;
skip) tag="SKIP"; skip=$((skip+1)) ;;
pass) pass=$((pass+1)) ;;
fail) fail=$((fail+1)) ;;
skip) skip=$((skip+1)) ;;
esac
if [ "$MODE_QUIET" -eq 0 ]; then
case "$status" in
Expand Down Expand Up @@ -89,14 +89,16 @@ clone_repo() {

has_go() { command -v go >/dev/null 2>&1; }
has_shellcheck() { command -v shellcheck >/dev/null 2>&1; }
has_cmake() { command -v cmake >/dev/null 2>&1; }
has_gcc() { command -v gcc >/dev/null 2>&1; }

check_go_build() {
local dir="$1" label="$2"
if ! has_go; then
check "go build $label" skip "go not installed"
return
fi
if CGO_ENABLED=0 go build -o /dev/null ./... 2>&1; then
if (cd "$dir" && CGO_ENABLED=0 go build -o /dev/null ./... 2>&1); then
check "go build $label" pass
else
check "go build $label" fail "build error"
Expand All @@ -109,13 +111,92 @@ check_go_vet() {
check "go vet $label" skip "go not installed"
return
fi
if go vet ./... 2>&1; then
if (cd "$dir" && CGO_ENABLED=0 go vet ./... 2>&1); then
check "go vet $label" pass
else
check "go vet $label" fail "vet errors"
fi
}

check_go_build_cgo() {
local dir="$1" label="$2"
if ! has_go; then
check "cgo build $label" skip "go not installed"
return
fi
if ! has_cmake; then
check "cgo build $label" skip "cmake not installed"
return
fi
if ! has_gcc; then
check "cgo build $label" skip "gcc not installed"
return
fi
local llama_dir="$dir/vendor/llama.cpp"
if [ ! -f "$llama_dir/CMakeLists.txt" ]; then
mkdir -p "$dir/vendor"
git clone --depth=1 https://github.com/ggerganov/llama.cpp.git "$llama_dir" >/dev/null 2>&1 || {
check "cgo build $label" skip "llama.cpp clone failed"
return
}
fi
if [ ! -f "$llama_dir/build/libllama.a" ]; then
(cd "$llama_dir" && cmake -B build -DLLAMA_NATIVE=0 \
-DBUILD_SHARED_LIBS=0 -DLLAMA_BUILD_TESTS=0 \
-DLLAMA_BUILD_EXAMPLES=0 -DLLAMA_BUILD_SERVER=0 \
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY="$PWD/build" && \
cmake --build build --target llama --config Release -j"$(nproc)") >/dev/null 2>&1 || {
check "cgo build $label" fail "llama.cpp cmake build failed"
return
}
fi
local ggml_inc="$llama_dir/ggml/include"
local ggml_ld=""
for lib in $(find "$llama_dir/build" -name "libggml*.a" -type f); do
libname=$(basename "$lib" .a | sed 's/^lib//')
ggml_ld="${ggml_ld} -l${libname}"
done
ggml_ld="${ggml_ld} -lgomp"
if CGO_ENABLED=1 CGO_CFLAGS="-I$ggml_inc" CGO_LDFLAGS="$ggml_ld" go build -tags=cgo -o /dev/null ./cmd/cograw >/dev/null 2>&1; then
check "cgo build $label" pass
else
check "cgo build $label" fail "cgo build error"
fi
}

check_go_vet_cgo() {
local dir="$1" label="$2"
if ! has_go; then
check "cgo vet $label" skip "go not installed"
return
fi
if ! has_cmake; then
check "cgo vet $label" skip "cmake not installed"
return
fi
if ! has_gcc; then
check "cgo vet $label" skip "gcc not installed"
return
fi
local llama_dir="$dir/vendor/llama.cpp"
if [ ! -f "$llama_dir/CMakeLists.txt" ] || [ ! -f "$llama_dir/build/libllama.a" ]; then
check "cgo vet $label" skip "llama.cpp not built (cgo build step handles this)"
return
fi
local ggml_inc="$llama_dir/ggml/include"
local ggml_ld=""
for lib in $(find "$llama_dir/build" -name "libggml*.a" -type f); do
libname=$(basename "$lib" .a | sed 's/^lib//')
ggml_ld="${ggml_ld} -l${libname}"
done
ggml_ld="${ggml_ld} -lgomp"
if CGO_ENABLED=1 CGO_CFLAGS="-I$ggml_inc" CGO_LDFLAGS="$ggml_ld" go vet -tags=cgo ./... >/dev/null 2>&1; then
check "cgo vet $label" pass
else
check "cgo vet $label" fail "cgo vet errors"
fi
}

check_sh_syntax() {
local dir="$1" label="$2"
local errors=0
Expand All @@ -139,7 +220,7 @@ check_shellcheck() {
local errors=0
for script in "$dir"/scripts/*.sh; do
[ -f "$script" ] || continue
shellcheck -s sh -S warning "$script" 2>/dev/null || errors=$((errors+1))
shellcheck -S warning "$script" 2>/dev/null || errors=$((errors+1))
done
if [ "$errors" -eq 0 ]; then
check "shellcheck $label" pass
Expand All @@ -156,11 +237,12 @@ check_build_tags() {
[ -f "$p" ] || continue
head -1 "$p" | grep -q 'cgo' || { errors=$((errors+1)); check "build tag cgo on $f ($label)" fail "missing //go:build cgo"; }
done
for f in cograw_llm.go; do
p="$dir/cmd/cograw/$f"
[ -f "$p" ] || continue
head -1 "$p" | grep -q 'cgo' || { errors=$((errors+1)); check "build tag cgo on $f ($label)" fail "missing //go:build cgo"; }
done
f="cograw_llm.go"
p="$dir/cmd/cograw/$f"
if [ -f "$p" ] && ! head -1 "$p" | grep -q 'cgo'; then
errors=$((errors+1))
check "build tag cgo on $f ($label)" fail "missing //go:build cgo"
fi
for f in cograw_stub.go backend_stub.go; do
for d in cmd/cograw internal/server; do
p="$dir/$d/$f"
Expand Down Expand Up @@ -255,9 +337,12 @@ hr

# ── Tool availability ──
section "Tool Availability"
for tool in git go shellcheck; do
for tool in git go shellcheck cmake; do
if command -v "$tool" >/dev/null 2>&1; then
ver=$("$tool" version 2>&1 | head -1)
case "$tool" in
cmake) ver=$(cmake --version 2>&1 | head -1) ;;
*) ver=$("$tool" version 2>&1 | head -1) ;;
esac
check "$tool" pass "$ver"
else
check "$tool" skip "not installed"
Expand Down Expand Up @@ -328,6 +413,8 @@ for repo in $ALL_REPOS; do
*" $repo "*)
check_build_tags "$dir" "$repo"
check_stale_refs "$dir" "$repo"
check_go_build_cgo "$dir" "$repo"
check_go_vet_cgo "$dir" "$repo"
;;
esac

Expand Down
Loading