Skip to content

akm tasks: support scheduling tasks from any registered stash, not just the primary stashDir #711

Description

@itlackey

Summary

Scheduled tasks (akm tasks …) are bound exclusively to the primary stash
(config.stashDir). Registered source stashes (config.sources[]) are used
for search/curate, but their tasks/ directories are never scanned, and there is
no way to add/sync/run a task from a source stash. This makes it impossible to
version-control task definitions without either a fragile symlink or committing
secrets to git.

Current behavior (akm 0.8.14)

akm config exposes a primary stash plus additional read sources:

{
  "stashDir": "/stash",
  "sources": [
    { "path": "/host-stash",       "name": "host-akm", "writable": true },
    { "path": "/work/agent-stash", "name": "agent-stash" }
  ]
}
  • akm tasks sync reconciles only ${stashDir}/tasks with the OS scheduler — it
    accepts no --stash / --source / --all flag.
  • akm tasks add writes only to the primary stash — no stash/source target option.
  • akm tasks list lists "tasks in the stash" (the primary one).
  • There is no AKM_TASKS_DIR (or equivalent) override; tasks always resolve to
    ${AKM_STASH_DIR}/tasks.

A task defined in a source stash's tasks/ directory is therefore invisible to akm.

Why this matters

A common setup separates concerns between two stashes:

  • Primary stash (/stash) holds runtime state that must not be in git:
    secrets/, env/ (e.g. env:user credentials), and the akm database/index
    (.akm/).
  • A git-tracked source stash (e.g. agent-stash at /work/agent-stash) holds
    the versioned skills / scripts / content.

Scheduled tasks are automation source that logically belongs in the versioned
repo — but because akm binds tasks to stashDir, they can't be versioned there.
The only options today are both bad:

  1. Symlink ${stashDir}/tasks → <repo>/tasks. Works, but fragile: a container
    restart / re-seed can replace the symlink with a real directory and silently
    diverge, or the sync loop can transiently see no tasks/ dir.
  2. Make the repo the stashDir. This drags secrets/, env/, and the akm DB
    into a git working tree (secret-leak risk) and couples the entire runtime stash
    to the repo.

Neither satisfies the goal: keep secrets out of git, but version the task
definitions.

Recommended changes

  1. Scan tasks across all registered stashes (primary + sources) in
    tasks list / sync / run / history, not just stashDir.
  2. Per-source opt-in for task execution (security-critical). A source's tasks
    should only be scheduled if the source is explicitly trusted for execution —
    e.g. a tasks: true flag on the source in config (or gate on the existing
    writable: true). Do not auto-run tasks from every registered source by
    default: a source stash defining a cron task is arbitrary code execution on
    every host that registers it.
  3. Namespace tasks by stash to avoid id collisions and make provenance clear —
    e.g. agent-stash:reddit-leads. Record the origin stash in the generated cron
    block (# akm:task <stash>/<id> …) and route enable / disable / sync /
    history to the correct stash's file.
  4. akm tasks add --stash <name> to create a task in a chosen registered stash
    (defaulting to the primary for back-compat).
  5. (Simpler alternative / complement) an AKM_TASKS_DIR env var or
    config.tasksDir override to point the task directory somewhere other than
    ${stashDir}/tasks. This lets an operator relocate tasks to a git-tracked path
    without moving the rest of the stash.

Item (2) is the essential guardrail — opt-in per source keeps this from
becoming a mechanism for an untrusted/shared source stash to run code on every
host that registers it.

Environment

  • akm 0.8.14 (also observed as akm-cli@0.9.0-beta.58)
  • OS cron scheduler backend, Linux container
  • Config: one primary stashDir + filesystem source stashes as shown above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions