@aitne-sh/aitne 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/README.md +195 -829
  2. package/agent-assets/agent-profiles/_safety.md +49 -17
  3. package/agent-assets/agent-profiles/profile-importer.md +1 -1
  4. package/agent-assets/agent-profiles/routine.md +4 -3
  5. package/agent-assets/docs/concepts/agent-day.md +6 -1
  6. package/agent-assets/docs/concepts/auth-health.md +10 -1
  7. package/agent-assets/docs/concepts/backends-and-tiers.md +74 -40
  8. package/agent-assets/docs/concepts/costs-and-quotas.md +25 -5
  9. package/agent-assets/docs/concepts/delegated-mode.md +147 -68
  10. package/agent-assets/docs/concepts/memory-model.md +9 -4
  11. package/agent-assets/docs/concepts/observations.md +13 -1
  12. package/agent-assets/docs/concepts/process-keys.md +20 -5
  13. package/agent-assets/docs/concepts/routines.md +38 -20
  14. package/agent-assets/docs/concepts/safety-model.md +30 -13
  15. package/agent-assets/docs/concepts/skills.md +12 -7
  16. package/agent-assets/docs/features/integrations/calendar.md +1 -1
  17. package/agent-assets/docs/features/integrations/git.md +2 -2
  18. package/agent-assets/docs/features/integrations/github.md +9 -2
  19. package/agent-assets/docs/features/integrations/mail.md +1 -1
  20. package/agent-assets/docs/features/integrations/notion.md +34 -6
  21. package/agent-assets/docs/features/integrations/obsidian.md +7 -2
  22. package/agent-assets/docs/features/lifestyle/git.md +4 -7
  23. package/agent-assets/docs/features/lifestyle/receipts.md +17 -2
  24. package/agent-assets/docs/features/lifestyle/travel-bookings.md +15 -0
  25. package/agent-assets/docs/features/lifestyle/travel-time.md +7 -1
  26. package/agent-assets/docs/features/memory-files/agent-journal.md +2 -2
  27. package/agent-assets/docs/features/memory-files/projects.md +6 -0
  28. package/agent-assets/docs/features/memory-files/roadmap.md +5 -0
  29. package/agent-assets/docs/features/memory-files/today.md +1 -0
  30. package/agent-assets/docs/features/memory-files/user-profile.md +6 -0
  31. package/agent-assets/docs/features/messaging/bang-commands.md +20 -10
  32. package/agent-assets/docs/features/messaging/discord.md +12 -1
  33. package/agent-assets/docs/features/messaging/overview.md +10 -7
  34. package/agent-assets/docs/features/messaging/slack.md +13 -1
  35. package/agent-assets/docs/features/messaging/telegram.md +7 -1
  36. package/agent-assets/docs/features/messaging/whatsapp.md +12 -1
  37. package/agent-assets/docs/features/operations/activity-and-conversations.md +2 -2
  38. package/agent-assets/docs/features/operations/approvals.md +6 -0
  39. package/agent-assets/docs/features/operations/backend-routing.md +7 -0
  40. package/agent-assets/docs/features/operations/cost-tracking.md +6 -0
  41. package/agent-assets/docs/features/operations/notifications.md +6 -0
  42. package/agent-assets/docs/features/operations/schedule-approaching.md +22 -9
  43. package/agent-assets/docs/features/routines/custom-routines.md +10 -4
  44. package/agent-assets/docs/features/routines/evening-review.md +1 -1
  45. package/agent-assets/docs/features/routines/hourly-check.md +1 -1
  46. package/agent-assets/docs/features/routines/morning-routine.md +24 -15
  47. package/agent-assets/docs/features/routines/weekly-review.md +38 -12
  48. package/agent-assets/docs/features/wiki/commands.md +11 -0
  49. package/agent-assets/docs/features/wiki/overview.md +13 -3
  50. package/agent-assets/docs/getting-started/01-what-is-this.md +32 -11
  51. package/agent-assets/docs/getting-started/02-first-steps.md +17 -4
  52. package/agent-assets/docs/getting-started/03-what-can-this-do.md +21 -11
  53. package/agent-assets/docs/getting-started/04-first-day.md +14 -0
  54. package/agent-assets/docs/glossary.md +65 -12
  55. package/agent-assets/docs/guides/add-a-custom-routine.md +12 -0
  56. package/agent-assets/docs/guides/backup-and-restore.md +16 -2
  57. package/agent-assets/docs/guides/budget-and-cost-for-wiki.md +6 -0
  58. package/agent-assets/docs/guides/build-your-wiki.md +14 -0
  59. package/agent-assets/docs/guides/change-which-model-handles-x.md +7 -0
  60. package/agent-assets/docs/guides/connect-a-new-mail-account.md +16 -0
  61. package/agent-assets/docs/guides/explore-with-trace-and-connect.md +6 -0
  62. package/agent-assets/docs/guides/import-knowledge-file.md +11 -0
  63. package/agent-assets/docs/guides/install-and-run.md +20 -4
  64. package/agent-assets/docs/guides/maintain-wiki-health.md +6 -0
  65. package/agent-assets/docs/guides/migrate-machines.md +13 -1
  66. package/agent-assets/docs/guides/multiple-wikis-for-multiple-domains.md +9 -0
  67. package/agent-assets/docs/guides/pause-the-agent.md +12 -4
  68. package/agent-assets/docs/guides/reinstall-cleanly.md +19 -4
  69. package/agent-assets/docs/guides/setup-wizard.md +20 -9
  70. package/agent-assets/docs/guides/switch-default-backend.md +10 -1
  71. package/agent-assets/docs/guides/use-an-existing-obsidian-vault.md +5 -0
  72. package/agent-assets/docs/reference/api.md +29 -1
  73. package/agent-assets/docs/reference/cli-commands.md +22 -3
  74. package/agent-assets/docs/reference/config.md +37 -5
  75. package/agent-assets/docs/reference/disallowed-tools.md +13 -0
  76. package/agent-assets/docs/reference/keyboard-shortcuts.md +13 -0
  77. package/agent-assets/docs/reference/process-keys.md +70 -20
  78. package/agent-assets/docs/reference/skills.md +27 -9
  79. package/agent-assets/docs/troubleshooting/auth-failed.md +7 -2
  80. package/agent-assets/docs/troubleshooting/dashboard-shows-degraded.md +13 -1
  81. package/agent-assets/docs/troubleshooting/fallback-keeps-firing.md +10 -0
  82. package/agent-assets/docs/troubleshooting/messaging-not-pairing.md +11 -0
  83. package/agent-assets/docs/troubleshooting/morning-routine-didnt-run.md +9 -4
  84. package/agent-assets/docs/troubleshooting/observation-not-detected.md +12 -0
  85. package/agent-assets/docs/troubleshooting/quota-exhausted.md +7 -1
  86. package/agent-assets/docs/troubleshooting/wiki-ingest-full-blocked.md +5 -0
  87. package/agent-assets/docs/troubleshooting/wiki-write-failed.md +5 -0
  88. package/agent-assets/optimizer-skills/drift-analysis/SKILL.md +1 -1
  89. package/agent-assets/optimizer-skills/skill-curation/SKILL.md +2 -2
  90. package/agent-assets/skills/agent-actions/SKILL.md +122 -0
  91. package/agent-assets/skills/attach/SKILL.md +1 -2
  92. package/agent-assets/skills/context/SKILL.md +36 -454
  93. package/agent-assets/skills/context/references/api.md +220 -0
  94. package/agent-assets/skills/context/references/required-frontmatter.md +73 -0
  95. package/agent-assets/skills/context/references/snapshot-files.md +103 -0
  96. package/agent-assets/skills/context/seeds/file-responsibilities.seed.json +1 -1
  97. package/agent-assets/skills/docs-search/SKILL.md +13 -13
  98. package/agent-assets/skills/external-services/SKILL.delegated.claude.md +5 -7
  99. package/agent-assets/skills/external-services/SKILL.delegated.codex.md +5 -7
  100. package/agent-assets/skills/external-services/SKILL.delegated.gemini.md +5 -7
  101. package/agent-assets/skills/external-services/SKILL.md +6 -259
  102. package/agent-assets/skills/external-services/SKILL.native.claude.md +1 -2
  103. package/agent-assets/skills/external-services/SKILL.native.codex.md +1 -2
  104. package/agent-assets/skills/external-services/SKILL.native.gemini.md +1 -2
  105. package/agent-assets/skills/external-services/references/calendar-apple.md +97 -0
  106. package/agent-assets/skills/external-services/references/calendar-google.md +72 -0
  107. package/agent-assets/skills/external-services/references/calendar-outlook.md +36 -0
  108. package/agent-assets/skills/external-services/references/github.md +17 -0
  109. package/agent-assets/skills/external-services/references/obsidian.md +49 -0
  110. package/agent-assets/skills/external-services/references/skills-crud.md +27 -0
  111. package/agent-assets/skills/gmail-lifestyle/SKILL.md +224 -0
  112. package/agent-assets/skills/gmail-lifestyle/references/receipts-api.md +93 -0
  113. package/agent-assets/skills/gmail-lifestyle/references/travel-bookings-api.md +75 -0
  114. package/agent-assets/skills/gmail-lifestyle/references/travel-time-api.md +59 -0
  115. package/agent-assets/skills/mail/SKILL.delegated.claude.md +1 -1
  116. package/agent-assets/skills/mail/SKILL.delegated.codex.md +1 -1
  117. package/agent-assets/skills/mail/SKILL.delegated.gemini.md +1 -1
  118. package/agent-assets/skills/mail/SKILL.md +9 -114
  119. package/agent-assets/skills/mail/SKILL.native.claude.md +1 -1
  120. package/agent-assets/skills/mail/SKILL.native.codex.md +1 -1
  121. package/agent-assets/skills/mail/SKILL.native.gemini.md +1 -1
  122. package/agent-assets/skills/mail/references/api.md +108 -0
  123. package/agent-assets/skills/mail/references/examples.md +70 -0
  124. package/agent-assets/skills/mail/references/providers.md +8 -8
  125. package/agent-assets/skills/managed-tasks/SKILL.md +472 -0
  126. package/agent-assets/skills/managed-tasks/references/errors.md +70 -0
  127. package/agent-assets/skills/managed-tasks/references/output-path.md +75 -0
  128. package/agent-assets/skills/managed-tasks/references/recurrence-rule.md +86 -0
  129. package/agent-assets/skills/management-policy/SKILL.md +33 -105
  130. package/agent-assets/skills/management-policy/references/policy-workflow.md +101 -0
  131. package/agent-assets/skills/notify/SKILL.md +6 -78
  132. package/agent-assets/skills/notify/references/priority.md +60 -0
  133. package/agent-assets/skills/notion/SKILL.delegated.claude.md +1 -1
  134. package/agent-assets/skills/notion/SKILL.delegated.codex.md +1 -1
  135. package/agent-assets/skills/notion/SKILL.delegated.gemini.md +1 -1
  136. package/agent-assets/skills/notion/SKILL.md +6 -10
  137. package/agent-assets/skills/notion/SKILL.native.claude.md +1 -2
  138. package/agent-assets/skills/notion/SKILL.native.codex.md +1 -2
  139. package/agent-assets/skills/notion/SKILL.native.gemini.md +1 -2
  140. package/agent-assets/skills/observations/SKILL.md +1 -6
  141. package/agent-assets/skills/project-doc/SKILL.md +1 -5
  142. package/agent-assets/skills/reading/SKILL.md +2 -2
  143. package/agent-assets/skills/roadmap/SKILL.md +37 -135
  144. package/agent-assets/skills/roadmap/references/api.md +100 -0
  145. package/agent-assets/skills/roadmap/references/cross-check.md +73 -0
  146. package/agent-assets/skills/roadmap/references/migration.md +56 -0
  147. package/agent-assets/skills/roadmap/references/preparation-timeline.md +2 -2
  148. package/agent-assets/skills/schedule/SKILL.md +52 -88
  149. package/agent-assets/skills/schedule/references/batch.md +93 -0
  150. package/agent-assets/skills/schedule/references/errors.md +214 -0
  151. package/agent-assets/skills/schedule/references/model-selection.md +96 -0
  152. package/agent-assets/skills/schedule/references/recurrence-rule.md +86 -0
  153. package/agent-assets/skills/schedule/references/recurring.md +185 -0
  154. package/agent-assets/skills/scheduled-managed-task/SKILL.md +13 -15
  155. package/agent-assets/skills/today/SKILL.md +27 -57
  156. package/agent-assets/skills/today/references/agent-plan-lifecycle.md +113 -0
  157. package/agent-assets/skills/user-interview/SKILL.md +12 -59
  158. package/agent-assets/skills/user-interview/references/op-briefing.md +51 -0
  159. package/agent-assets/skills/user-interview/references/op-morning.md +59 -0
  160. package/agent-assets/skills/user-interview/references/sweep-and-fallback.md +1 -1
  161. package/agent-assets/skills/user-profile/SKILL.md +43 -63
  162. package/agent-assets/skills/user-profile/references/character-preferences.md +83 -0
  163. package/agent-assets/skills/user-profile/seeds/topic-files.seed.json +28 -0
  164. package/agent-assets/skills/wiki/wiki-ask/SKILL.md +0 -1
  165. package/agent-assets/skills/wiki/wiki-compile/SKILL.md +0 -1
  166. package/agent-assets/skills/wiki/wiki-connect/SKILL.md +0 -1
  167. package/agent-assets/skills/wiki/wiki-graduate/SKILL.md +0 -1
  168. package/agent-assets/skills/wiki/wiki-ingest/SKILL.md +0 -1
  169. package/agent-assets/skills/wiki/wiki-lint/SKILL.md +0 -1
  170. package/agent-assets/skills/wiki/wiki-trace/SKILL.md +0 -1
  171. package/agent-assets/skills/wiki/wiki-vault-rules/SKILL.md +0 -1
  172. package/agent-assets/system-prompts/routine-fetch-window.md +68 -0
  173. package/agent-assets/system-prompts/skill-index-instruction.md +26 -0
  174. package/agent-assets/task-flows/_partials/calendar-acquire.google_calendar.md +18 -11
  175. package/agent-assets/task-flows/_partials/calendar-acquire.outlook_calendar.md +16 -9
  176. package/agent-assets/task-flows/_partials/capture-user-info.md +24 -0
  177. package/agent-assets/task-flows/_partials/confirm-subflow.md +68 -0
  178. package/agent-assets/task-flows/_partials/dm-intent.long-horizon.md +35 -0
  179. package/agent-assets/task-flows/_partials/dm-intent.project.md +391 -0
  180. package/agent-assets/task-flows/_partials/mail-acquire.gmail.md +20 -11
  181. package/agent-assets/task-flows/_partials/mail-acquire.outlook_mail.md +17 -9
  182. package/agent-assets/task-flows/_partials/notion-acquire.notion.md +18 -12
  183. package/agent-assets/task-flows/knowledge.import.md +1 -1
  184. package/agent-assets/task-flows/message.received.dm.md +13 -15
  185. package/agent-assets/task-flows/message.received.dm_first.md +10 -14
  186. package/agent-assets/task-flows/routine.custom.md +3 -1
  187. package/agent-assets/task-flows/routine.evening_review.md +39 -163
  188. package/agent-assets/task-flows/routine.fetch_window.md +17 -12
  189. package/agent-assets/task-flows/routine.hourly_check.md +16 -8
  190. package/agent-assets/task-flows/routine.hourly_check.triage.md +1 -1
  191. package/agent-assets/task-flows/routine.monthly_review.md +46 -4
  192. package/agent-assets/task-flows/routine.morning_routine_journal.md +113 -0
  193. package/agent-assets/task-flows/routine.morning_routine_today.md +673 -0
  194. package/agent-assets/task-flows/routine.roadmap_refresh.md +60 -15
  195. package/agent-assets/task-flows/routine.user_profile_sweep.md +9 -10
  196. package/agent-assets/task-flows/routine.weekly_review.md +285 -70
  197. package/agent-assets/task-flows/scheduled.dm.md +8 -8
  198. package/agent-assets/task-flows/scheduled.task.md +5 -5
  199. package/agent-assets/task-flows/setup.initial.md +165 -245
  200. package/agent-assets/task-flows/wiki.ingest_url.md +1 -1
  201. package/agent-assets/templates/_manifest.json +7 -7
  202. package/agent-assets/templates/dossiers/_index.md +1 -1
  203. package/agent-assets/templates/rules/journal-format.md +145 -38
  204. package/agent-assets/templates/user/expertise.md +4 -2
  205. package/agent-assets/templates/user/goals.md +4 -2
  206. package/agent-assets/templates/user/people.md +8 -2
  207. package/agent-assets/templates/user/personal.md +4 -2
  208. package/agent-assets/templates/user/work.md +4 -2
  209. package/bin/aitne.mjs +8 -1
  210. package/package.json +4 -4
  211. package/scripts/commands/doctor.mjs +52 -0
  212. package/scripts/commands/run-now.mjs +202 -0
  213. package/scripts/commands/verify.mjs +264 -0
  214. package/agent-assets/docs/features/routines/monthly-review.md +0 -65
  215. package/agent-assets/skills/management-task-modify/SKILL.md +0 -203
  216. package/agent-assets/skills/management-task-register/SKILL.md +0 -330
  217. package/agent-assets/skills/management-task-stop/SKILL.md +0 -166
  218. package/agent-assets/skills/receipts/SKILL.md +0 -134
  219. package/agent-assets/skills/travel/SKILL.md +0 -132
  220. package/agent-assets/skills/travel-time/SKILL.md +0 -158
  221. package/agent-assets/task-flows/routine.morning_routine.md +0 -322
  222. package/agent-assets/task-flows/routine.morning_routine_initial.md +0 -204
@@ -8,11 +8,7 @@ allowed-tools:
8
8
 
9
9
  # Context File Update Guide
10
10
 
11
- Output language: follow `<output_language_policy>`. Context files are
12
- Policy B — H2/H3 headers from `agent-assets/templates/` are skeleton
13
- (English); body prose, bullets, and summaries are written in
14
- `<settings primary_language>`. Preserve user-customized headers
15
- verbatim (whichever language the user rewrote them in).
11
+ Output language: context files are Policy B — see `<output_language_policy>`. Preserve user-customized headers verbatim (whichever language the user rewrote them in).
16
12
 
17
13
  Context files are the agent's working memory, stored in the **primary
18
14
  management vault**. All writes go through the Daemon API — never touch
@@ -60,470 +56,56 @@ validates only `type: project`, `owner: shared`, `updated`, and an H1
60
56
 
61
57
  ## Project DM-intent detection
62
58
 
63
- Referenced from `message.received.dm`, `message.received.dm_first`, and
64
- any other handler that wants to record project-state changes from a DM.
65
- Identifies user messages about a named, ongoing workstream so the
66
- handler can route them into `projects/<slug>.md` instead of letting the
67
- fact bleed into the model's own scratch memory.
59
+ DM-driven project state writes are dispatched from
60
+ `message.received.dm.md` / `message.received.dm_first.md` Step 4 via
61
+ the `_partials/dm-intent.project.md` task-flow partial that partial
62
+ carries the decision tree (existing-vs-new match, decline-marker
63
+ pre-check, no-match confirm sub-flow scheduling, reply branches,
64
+ cross-path cancellation, slug grammar, tie-breakers).
68
65
 
69
- This block mirrors the shape of `roadmap`'s "Long-horizon DM-intent
70
- detection" so future durable-state domains (e.g. git, personal plans)
71
- can copy the same pattern into their own skills.
66
+ **This skill is the writer.** `projects/<slug>.md` PUT / PATCH / archive
67
+ goes through `/api/context/projects/*` per the API Reference below. The
68
+ partial dispatches; this skill executes the writes.
72
69
 
73
- **Signals (positive):**
74
- - Named project + state verb: *"Project Alpha is now in review"*,
75
- *"the migration project hit its first milestone"*, *"blocked on Y
76
- for the reporting overhaul"*.
77
- - New-project shape: *"let's start a project for X"*, *"I'm kicking
78
- off …"*, *"track this as a project"*, *"add a new project"*. The
79
- same shape in any other language counts — match on intent, not
80
- surface vocabulary.
81
- - Status / progress / blocker / decision phrasing tied to a
82
- recognizable workstream the user has named before.
70
+ Cross-references previously in this section ("Reply branches",
71
+ "Cross-path cancellation", "Decline-marker reversal", "Tie-breakers",
72
+ "Slug grammar") now live alongside their decision-tree steps inside
73
+ the partial.
83
74
 
84
- **Not signalsroute elsewhere:**
85
- - One-off task with a single deadline (*"remind me at 3pm to call …"*)
86
- → `schedule` skill.
87
- - Long-horizon plan with a date or horizon but no named workstream
88
- (*"going to Tokyo next month"*) → `roadmap` skill ("Long-horizon
89
- DM-intent detection"). When BOTH apply (a project with a dated
90
- milestone), run both flows — see "Tie-breakers" below.
91
- - Pure user fact / preference (*"I work on the platform team"*) →
92
- `user-profile` skill.
93
- - Durable management rule with a recurring cadence (*"every morning,
94
- X"*) → `management-policy` skill.
75
+ ## Snapshot files weekly / monthly / rules / routines
95
76
 
96
- **Decision tree:**
77
+ Weekly and monthly review snapshots, the user-controlled `rules/*.md`
78
+ policy files, the built-in `routines/<cadence>.md` rulebooks, custom
79
+ routines under `routines/custom/`, and the agent-private
80
+ `agent/journal.md` all have stable per-file conventions (writer event,
81
+ verb, frontmatter, retention) documented in the snapshot-files
82
+ reference below.
97
83
 
98
- 1. **Existing or new? (Plus decline-marker pre-check.)**
99
- - `GET /api/context/list/projects` and match the user's wording
100
- against returned filenames (slug stem) and, if needed, against
101
- the H1 / title of each candidate via
102
- `GET /api/context/projects/<slug>`. If multiple candidates
103
- match, prefer the one with the closest slug stem; if still
104
- ambiguous, ask *"is this for `<slug-A>` or `<slug-B>`?"* before
105
- writing.
106
- - **Decline-marker pre-check (Goal 3 — never ask twice).** Before
107
- classifying a no-match as new, compute the candidate slug and
108
- read `agent/journal.md ## Declined Intents`:
109
- ```bash
110
- curl -s "http://localhost:8321/api/context/agent/journal" \
111
- | jq -r '.content // ""' \
112
- | awk '/^## Declined Intents/{f=1;next} f && /^## /{exit} f'
113
- ```
114
- (404 from the GET means the journal file does not yet exist →
115
- no marker can exist → treat as "no marker present" and continue
116
- to the no-match path.) If any line under that section contains
117
- `create_project:<slug>` (the dedup_key shape — see §"Reply
118
- branches" below), the user previously declined this exact
119
- intent. The default behaviour is **skip silently** — do NOT
120
- re-ask, do NOT schedule a confirm, do NOT write.
84
+ DM handlers and Hourly Checks should generally not write these files
85
+ the cadence-matching routine is the right writer.
121
86
 
122
- **Reversal-signal carve-out (rare).** If the user's current DM
123
- contains an unambiguous reversal phrase for this exact intent,
124
- treat the DM as a fresh affirmative. Run the
125
- §"Decline-marker reversal" recipe below (remove the matching
126
- marker line, then PUT the project file per Step 4). Pattern
127
- shape: explicit verb of resumption + the topic + action
128
- consent. Match on intent, not surface vocabulary — any
129
- language qualifies.
130
-
131
- Counts as reversal (do the recipe):
132
- - *"actually let's start that LA project after all"*
133
- - *"go ahead and track LA PM"*
134
- - *"changed my mind, let's do it"*
135
-
136
- Does NOT count as reversal (skip silently, marker stays):
137
- - bare re-mention without an action verb: *"still thinking
138
- about LA PM"*, *"made a bit of progress on LA"*
139
- - status update on the topic without consent: *"LA classes
140
- started"*, *"midterm was hard"*
141
- - ambiguous "maybe" / non-commitment: *"maybe I'll track it
142
- eventually"*, *"might revisit this later"*
143
-
144
- The examples are English for prompt clarity only; recognise the
145
- same shapes in any language the user writes in. Bias
146
- conservative — when in doubt, skip silently and wait for a
147
- clearer signal. A missed reversal costs nothing (user can
148
- re-state explicitly); a false reversal silently overwrites a
149
- deliberate "no".
150
-
151
- 2. **Existing match → append a dated bullet.** Default section is
152
- `## Log` (or whatever section the file already uses for time-ordered
153
- entries — match existing files' conventions; do not invent a parallel
154
- section if one already exists).
155
-
156
- ```bash
157
- curl -s -X PATCH http://localhost:8321/api/context/projects/<slug> \
158
- -H 'Content-Type: application/json' \
159
- -d '{"section": "log", "mode": "append", "content": "- 2026-04-30: <one-line summary>"}'
160
- ```
161
-
162
- If the PATCH responds with `{"error": "section_not_found"}` (the
163
- file pre-dates the convention), retry once with `mode:
164
- "append_to_file"` and include the section header in the content:
165
-
166
- ```bash
167
- curl -s -X PATCH http://localhost:8321/api/context/projects/<slug> \
168
- -H 'Content-Type: application/json' \
169
- -d '{"mode": "append_to_file", "content": "\n## Log\n- 2026-04-30: <one-line summary>"}'
170
- ```
171
-
172
- For a **state change** (e.g. `active → on-hold`, milestone reached),
173
- also rebuild the frontmatter `state` field via GET-merge-PUT — the
174
- frontmatter parser is line-scalar so per-key PATCH is not available.
175
- Bump `updated` to today on the same write.
176
-
177
- **Cross-path cancellation.** If this existing-match write resolves
178
- what was previously a "no match" → confirm path (i.e. a confirm row
179
- was scheduled and the user has since clarified the project is the
180
- same as an existing one), delete the pending confirm rows before
181
- completing the write. See §"Reply branches" below.
182
-
183
- 3. **No match — schedule a confirm DM (do NOT ask inline).**
184
- The universal "no topic-pivoting trailing question" rule in
185
- `message.received.dm{,_first}.md` Step 3 forbids appending a
186
- project-creation ask to a content-rich reply. Instead of inline
187
- "Create project `<slug>`? (yes/no)" and waiting on the same DM
188
- turn, schedule a `confirm:` sub-flow row for a natural follow-up
189
- moment (default: next morning briefing slot, or `<current_time>
190
- + 4h` if the DM landed well before quiet hours):
191
-
192
- **a. Pre-flight idempotency check.** Compute the dedup_key
193
- `create_project:<slug>` and ensure no row is already pending
194
- (Goal 3):
195
-
196
- ```bash
197
- curl -s "http://localhost:8321/api/schedule?status=pending,running" \
198
- | jq --arg k "create_project:<slug>" \
199
- '[.items[] | select(.taskContext.confirm_dedup_key == $k)] | length'
200
- ```
201
-
202
- If the count is `≥ 1`, a confirm is already queued — do NOT
203
- schedule a duplicate. Log to today.md `## Agent Log` and proceed:
204
- ```
205
- - HH:MM [confirm] skipped create_project:<slug>: row already pending
206
- ```
207
-
208
- **b. Schedule the confirm.** Use the shape documented in
209
- `scheduled.dm.md` §"Confirmation follow-up":
210
-
211
- ```bash
212
- curl -s -X POST http://localhost:8321/api/schedule \
213
- -H 'Content-Type: application/json' \
214
- -d @- <<JSON
215
- {
216
- "time": "<next morning-briefing slot, or current_time + 4h — ISO 8601 with offset>",
217
- "taskType": "dm_session",
218
- "description": "confirm:create_project:<slug> — track <paraphrase> as a project?",
219
- "model": "sonnet",
220
- "taskContext": {
221
- "scheduledBy": "dm_handler.project_creation_gate",
222
- "sub_flow": "confirm",
223
- "confirm_id": "<short uuid v4 first 8 chars>",
224
- "confirm_dedup_key": "create_project:<slug>",
225
- "confirm_hint": "create project \"<slug>\"? (origin: <one-line paraphrase of user's DM>)",
226
- "confirm_recent_window_hours": 24,
227
- "confirm_attempt": 1,
228
- "confirm_max_attempts": 2,
229
- "confirm_defer_count": 0,
230
- "confirm_max_defers": 3,
231
- "confirm_decline_marker": {
232
- "path": "agent/journal.md",
233
- "section": "declined_intents",
234
- "match": "create_project:<slug>"
235
- },
236
- "confirm_slot": {
237
- "path": "projects/<slug>.md"
238
- },
239
- "importance": "low"
240
- }
241
- }
242
- JSON
243
- ```
244
-
245
- The `confirm_slot.path` (just the file path, no section / anchor)
246
- makes the fire-time slot-filled probe abort if the project file
247
- already exists by the time the confirm fires — covering the case
248
- where the user volunteers an affirmative shape between scheduling
249
- and fire.
250
-
251
- **c. Do NOT inline-ask.** The DM reply must remain in the user's
252
- thread per the universal rule. The confirm sub-flow will surface
253
- the question at the next natural moment. Silently inferring a
254
- slug and writing without confirmation remains forbidden.
255
-
256
- 4. **On confirmed creation → PUT the file.** Required + conventional
257
- frontmatter and an H1:
258
-
259
- ```bash
260
- curl -s -X PUT http://localhost:8321/api/context/projects/<slug> \
261
- -H 'Content-Type: application/json' \
262
- -d @- <<'JSON'
263
- {"content":"---\ntype: project\nslug: <slug>\nstate: active\nowner: shared\nstart: 2026-04-30\nupdated: 2026-04-30\n---\n# <Title>\n\n## Log\n- 2026-04-30: created via DM — <one-line origin>\n"}
264
- JSON
265
- ```
266
-
267
- Add `due`, `stakeholders`, `next_milestone`, `tags` only when the
268
- user supplied them. Do not invent values.
269
-
270
- 5. **Reply branches — how the user's response to a scheduled confirm
271
- is handled.** When the confirm sub-flow fires (`scheduled.dm.md`
272
- ## Confirmation follow-up) and the user replies, the reply routes
273
- through `message.received.dm.md` as usual; the dispatcher injects
274
- `<conversation_history>` so the agent sees both the confirm DM and
275
- the user's reply in the same turn. This gate is the writer for all
276
- three branches; every branch is REQUIRED.
277
-
278
- - **Affirmative** — user gave a clear positive answer to the
279
- confirm question. Examples: *"yes"*, *"go ahead"*,
280
- *"track it as X"*, *"sounds good"*, *"please do"*. Match on
281
- intent, not surface vocabulary — recognise the same shape in
282
- any language the user writes in. Execute the "On confirmed
283
- creation → PUT the file" path in Step 4. Then run
284
- §"Cross-path cancellation" below (delete any sibling confirm
285
- rows with matching `confirm_dedup_key` so a parallel queued
286
- row does not re-fire).
287
-
288
- - **Counter-proposal** — user supplied new info ("call it
289
- `la-pm` instead", "actually make it the syllabus dossier",
290
- "rename it to `la-pm`").
291
- Use the user's wording, not your original paraphrase:
292
- re-compute the slug from the corrected wording, PUT the file,
293
- then cancel pending confirm rows whose `confirm_dedup_key`
294
- matches **either** the original or the new slug:
295
- - `create_project:<original-slug>` — the chained-fire successor
296
- inherits the original key, so this is the primary sweep.
297
- - `create_project:<new-slug>` — a separate gate fire from an
298
- earlier DM may have queued a confirm with the new slug (e.g.
299
- the user previously paraphrased the same project differently
300
- and that fire's confirm has not yet aborted). The fire-time
301
- `slot-filled` probe would catch this (the project file now
302
- exists), but a symmetric sweep here saves a wasted session.
303
-
304
- Run the §"Cross-path cancellation" loop twice — once with each
305
- key — or merge the two `select`s in jq.
306
-
307
- - **Decline** — user wrote a clear negative answer to the
308
- confirm question.
309
-
310
- Counts as decline: *"no"*, *"don't bother"*, *"not now"*,
311
- *"later"*, *"skip it"*, *"forget it"*, *"drop it"*.
312
-
313
- Does NOT count as decline (treat as ambiguous → no DM action
314
- this turn, marker NOT written, sweep NOT run; the chain's
315
- softened re-check will handle it):
316
- - non-answer continuations: *"hmm"*, *"not sure"*, *"I don't
317
- know"*
318
- - questions back to the agent: *"why are you asking?"*,
319
- *"what would that involve?"* — these are clarification
320
- requests, not declines
321
-
322
- The examples are English for prompt clarity only; recognise
323
- the same shapes in any language the user writes in. On a true
324
- decline, do NOT write the project file. Two mandatory writes:
325
-
326
- a. **Write the decline marker** to
327
- `agent/journal.md ## Declined Intents`. Three cases — file
328
- missing entirely, file present but section missing, file +
329
- section both present — are handled in one read-then-branch
330
- sequence:
331
-
332
- ```bash
333
- # 1. GET. HTTP 404 means the journal file does not yet exist.
334
- body=$(curl -sS -w '\n%{http_code}' "http://localhost:8321/api/context/agent/journal")
335
- status=$(printf '%s\n' "$body" | tail -n1)
336
- content=$(printf '%s\n' "$body" | sed '$d' | jq -r '.content // ""' 2>/dev/null)
337
-
338
- marker_line='- 2026-05-12 [create_project:<slug>] user declined inline (DM)'
339
-
340
- if [ "$status" = "404" ]; then
341
- # Case A — file missing. CREATE_ONLY_PUT is enabled for
342
- # agent/journal, so PUT creates the file in a single call.
343
- # Include both the H1 and the Declined Intents section.
344
- curl -s -X PUT "http://localhost:8321/api/context/agent/journal" \
345
- -H 'Content-Type: application/json' \
346
- -d "$(jq -n --arg m "$marker_line" '{content: "# Agent Journal\n\n## Declined Intents\n\($m)\n"}')"
347
- elif printf '%s' "$content" | grep -q '^## Declined Intents'; then
348
- # Case B — file + section present. Append a bullet to the
349
- # existing section.
350
- curl -s -X PATCH "http://localhost:8321/api/context/agent/journal" \
351
- -H 'Content-Type: application/json' \
352
- -d "$(jq -n --arg m "$marker_line" '{section:"declined_intents",mode:"append",content:$m}')"
353
- else
354
- # Case C — file present but section missing. append_to_file
355
- # adds the section header + bullet to the end of the file.
356
- curl -s -X PATCH "http://localhost:8321/api/context/agent/journal" \
357
- -H 'Content-Type: application/json' \
358
- -d "$(jq -n --arg m "$marker_line" '{mode:"append_to_file",content:"\n## Declined Intents\n\($m)\n"}')"
359
- fi
360
- ```
361
-
362
- Use today's date (resolve via `<current_time>`) for the
363
- marker line.
364
-
365
- b. **Cancellation** — see §"Cross-path cancellation" below.
366
- The decline must also delete any pending confirm rows with
367
- the matching `confirm_dedup_key`, otherwise the chained-fire
368
- successor will re-ask 24h later despite the explicit "no".
369
-
370
- The decline marker is what the next DM-intent detection (Step 1
371
- above) consults — without it, the next time the user mentions LA
372
- PM master's, this gate would compute the same slug, see no
373
- existing project, and schedule another confirm. The marker is
374
- how Goal 3 ("never ask the same question twice") survives across
375
- sessions.
376
-
377
- **Decline-marker reversal.** When the user later volunteers an
378
- unambiguously affirmative shape ("OK now let's start that LA
379
- project after all", "actually go ahead and track LA PM") — either
380
- inline in a fresh DM (the carve-out in Step 1) or as a reply to a
381
- confirm DM — run this recipe instead of skipping:
382
-
383
- 1. GET `agent/journal.md`, parse the `## Declined Intents`
384
- section, drop the line whose bracketed dedup_key matches
385
- `create_project:<slug>`, and PATCH the section with
386
- `mode: "replace"` carrying the rebuilt body (the other lines
387
- preserved byte-for-byte). If the rebuilt section is empty,
388
- replace with the empty string — `mode: "replace"` accepts an
389
- empty `content` and leaves the heading in place.
390
- 2. Proceed with Step 4 (PUT the project file).
391
-
392
- Without the reversal, a previously-declined project would stay
393
- dormant forever.
394
-
395
- **Cross-path cancellation (required for affirmative,
396
- counter-proposal, and decline branches).** When this gate
397
- commits durable state via ANY of the three branches above, sweep
398
- pending confirm rows with the same dedup_key so a queued
399
- successor does not re-fire:
400
-
401
- ```bash
402
- curl -s "http://localhost:8321/api/schedule?status=pending,running" \
403
- | jq -r --arg k "create_project:<slug>" \
404
- '.items[] | select(.taskContext.confirm_dedup_key == $k) | .id' \
405
- | while read -r id; do
406
- curl -s -X DELETE "http://localhost:8321/api/schedule/$id" >/dev/null
407
- done
408
- ```
409
-
410
- Apply this after the affirmative write, after the counter-proposal
411
- write (with the ORIGINAL slug, not the corrected one), and after
412
- the decline marker write. The cost is one GET plus zero-to-one
413
- DELETE per write — bounded by "gate wrote something", which is
414
- rare relative to inbound DM volume.
415
-
416
- **Slug grammar (convention only — no API-level validation today):**
417
- - match `^[a-z0-9][a-z0-9-]*[a-z0-9]$` (or a single `[a-z0-9]`)
418
- - ≤ 64 chars
419
- - equal to the filename stem
420
- - avoid the reserved stems `_index`, `_active`
421
-
422
- The context API does not currently reject malformed project slugs, so
423
- the agent is the gate. A non-conforming slug will be written as-is and
424
- later cause friction with the Obsidian Bases view (`_active.base`).
425
-
426
- **Tie-breakers:**
427
- - *Project AND long-horizon* — both can apply. A new project with a
428
- dated milestone gets a `projects/<slug>.md` AND a roadmap entry.
429
- Run both flows in the same turn; reuse the slug across them where
430
- natural so the user can correlate the two.
431
- - *Project AND user fact* — write the project state; do NOT also
432
- write to `user/*.md` unless the message conveys a separate
433
- identity / preference fact.
434
- - *Project AND management policy* — if the user's wording is "from
435
- now on, when X happens to project Y, do Z", that's a durable rule
436
- → `management-policy` skill, not this section. The policy file's
437
- `linked.dossier` may still point at a `projects/<slug>.md`.
438
-
439
- **What this section does NOT cover:**
440
- - Inbox-derived project creation — that path runs in
441
- `routine.morning_routine.md` Step 4 against `inbox/*` source files
442
- with a different file-move semantic; do not duplicate it here.
443
- - Roll-off / archive — when a project ends, flip `state: archived`
444
- via GET-merge-PUT; do not delete the file. The `_active.base`
445
- Obsidian view filters by `state`.
446
-
447
- ## weekly/*.md, monthly/*.md
448
-
449
- weekly: `weekly/YYYY-Www.md` (PUT only, Friday). monthly: `monthly/YYYY-MM.md` (PUT only, month-end). Monthly files are **user-facing only** — agent-side metrics go to `agent/journal.md`.
87
+ {{> ref:snapshot-files }}
450
88
 
451
89
  ## Required frontmatter for guarded files
452
90
 
453
91
  Full-file writes to `user/*.md`, `rules/*.md`, `projects/*.md`,
454
- `daily/*.md`, `weekly/*.md`, and `monthly/*.md` must include YAML
455
- frontmatter with `type`, `owner`, and `updated`, followed by at least one
456
- H1 heading. Use today's date for `updated`.
457
-
458
- - `projects/*.md`: `type: project`, `owner: shared`
459
- - `daily/*.md`: `type: daily`, `owner: agent`
460
- - `weekly/*.md`: `type: weekly`, `owner: agent`
461
- - `monthly/*.md`: `type: monthly`, `owner: agent`
462
- - `rules/*.md`: `type: rule`, `owner: shared`
463
- - `user/*.md`: `type: user`, `owner: shared`
464
-
465
- ## agent/journal.md
92
+ `daily/*.md`, `weekly/*.md`, and `monthly/*.md` must open with the
93
+ matching YAML frontmatter (`type`, `owner`, `updated`) followed by at
94
+ least one H1 heading. Per-glob values and the common rejection
95
+ envelope are in the required-frontmatter reference below.
466
96
 
467
- Agent-owned, never user-facing. Append-only via PATCH `mode: "append_to_file"` (no `section` needed). Weekly sections: `## Weekly YYYY-Www` (What worked / slipped / improvements / Metrics). Monthly: `## Monthly YYYY-MM` (follow-up / self-critique / gap / adjustments / Metrics). **Nothing from this file should appear in notifications.**
468
-
469
- ## rules/*.md, routines/*.md
470
-
471
- Only modify these when the user explicitly asks to change the policy or routine itself.
472
-
473
- - `rules/*.md`: preserve unrelated sections verbatim.
474
- - `rules/policies/<slug>.md` and `rules/policies/_index.md`: route to the `management-policy` skill — it owns the read-before-write, similarity-detection, and pause/resume fan-out for durable policies. Don't hand-edit from this skill.
475
- - `routines/<cadence>.md`: keep the existing frontmatter, keep a `## Checks` section, and append or edit `### <label>` blocks under it.
476
- - `routines/custom/<slug>.md`: full-file PUT is usually safest. Required frontmatter: `type: rule`, `slug`, `cron`, `process_key`, `enabled`, `backend_tier`, `max_budget_usd`. The file must also contain `## Checks`.
477
- - Deleting a custom routine uses `DELETE /api/context/routines/custom/<slug>` only after the user asks to retire it.
97
+ {{> ref:required-frontmatter }}
478
98
 
479
99
  ## API Reference
480
100
 
481
- ### GET /api/context/:pathRead
482
- ```bash
483
- curl -s http://localhost:8321/api/context/roadmap
484
- ```
485
- Response: `{ "content": "...", "lastModified": "ISO8601" }` / 404. Returns the **entire file** no section-level GET.
486
-
487
- ### PUT /api/context/:path — Full replace
488
- Fields: `content` (required), `expectedMtime` (optional, 409 on mismatch). Add `X-Lock-Id` header when the matching lock id is in context (`<today_write_lock_id>` for today.md, `<roadmap_write_lock_id>` for roadmap.md). Validates required sections. Snapshots previous content.
489
-
490
- **rules/management.md**: user-controlled policy. Modify only when the user explicitly asks. Preserve every unrelated section.
491
-
492
- ### PATCH /api/context/:path — Section operation
493
- ```bash
494
- curl -s -X PATCH http://localhost:8321/api/context/today \
495
- -H 'Content-Type: application/json' \
496
- -d '{"section": "agent_log", "mode": "append", "content": "- 09:35 Processed meeting summary"}'
497
- ```
498
-
499
- | Field | Type | Description |
500
- |---|---|---|
501
- | `section` | string | snake_case of heading. **Omit for `append_to_file`**; required for every other mode. |
502
- | `mode` | `append` \| `replace` \| `clear` \| `clear_before` \| `append_to_file` | Default `append` |
503
- | `content` | string | Ignored for `clear` / `clear_before` |
504
- | `cutoff` | string | **Required when `mode: "clear_before"`.** Format `YYYY-MM-DD HH:MM:SS` (zero-padded). Removes bullet rows whose `- [YYYY-MM-DD HH:MM:SS]` timestamp is ≤ cutoff. |
505
- | `maxEntries` | number | Optional for `mode: "append"`. After appending, trim oldest bullet entries from the top of the section body so at most `maxEntries` bullets remain. Non-bullet lines are preserved. |
506
-
507
- `append_to_file`: appends to end of file (no `section`). Use for agent/journal.md.
508
- `clear_before`: rolling-log trim — pass a SQLite-format `cutoff` to drop bullets older than it. Non-bullet lines are preserved.
509
-
510
- **Error responses worth knowing:**
511
- - `400 {error:"section_not_found", section, availableSections:[...]}` — the section name didn't match. The `availableSections` array lists every section heading the file actually has (snake_cased); pick the closest match from that list before retrying. Do NOT retry the same `section` value.
512
- - `400 {error:"validation_error", message, path}` — content failed the file-specific validator (e.g. today.md day-type line, roadmap.md preparation-timeline row). The `message` field names the offending line and (where applicable) the expected shape.
513
- - `400 {error:"cutoff_required", message}` — `clear_before` was called without a valid `cutoff`.
514
-
515
- ### GET /api/context/list/:dir — List files
516
- `curl -s http://localhost:8321/api/context/list/projects` → `{ "files": [{ "name", "lastModified" }] }`
517
-
518
- ### POST /api/context/archive-today — Archive
519
- Rotates today.md → yesterday.md (B-007 §5.9; synthesized daily/YYYY-MM-DD.md is now written by the morning routine, not this endpoint). Called by Morning Routine during day rotation.
101
+ The full `/api/context/*` surface read / write / list / lock /
102
+ archive / restore / health / repair / action-log — is organised by
103
+ operation in the reference below. Add `X-Lock-Id` on every PUT / PATCH
104
+ to `today.md` (`<today_write_lock_id>`) or `roadmap.md`
105
+ (`<roadmap_write_lock_id>`) when the matching lock-id tag is in your
106
+ context.
520
107
 
521
- ### POST /api/action/log — Record action log entry
522
- ```bash
523
- curl -s -X POST http://localhost:8321/api/action/log \
524
- -H 'Content-Type: application/json' \
525
- -d '{"category": "observation", "action": "reviewed", "result": "2 tasks added"}'
526
- ```
108
+ {{> ref:api }}
527
109
 
528
110
  ## Knowledge map — file responsibilities (auto-curated)
529
111