dsh-plugin-imem 0.1.0 → 0.2.0

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.
@@ -1,171 +1,172 @@
1
- # iMem Agent Contract
2
-
3
- Use this contract with the authenticated production MCP at
4
- `https://imem.xin/mcp`. Read `mcp-tool-spec.md` for exact parameters and
5
- `product-language.md` for terminology.
6
-
7
- ## Domain Contract
8
-
9
- Every independently manageable note or schedule is one Entry with one stable
10
- `entry_id`:
11
-
12
- ```text
13
- Entry(kind=note) -> schedule_details=null, reminder_rules=[]
14
- Entry(kind=schedule) -> schedule_details object, reminder_rules array
15
- ```
16
-
17
- ScheduleDetails belong one-to-one to a Schedule Entry. Reminder Rules belong
18
- zero-to-many to a Schedule Entry and are not top-level Entries. Occurrences use
19
- `entry_id` and `occurrence_id`; they do not require legacy Memory or Schedule
20
- IDs. Artifact remains a separate private deliverable resource.
21
-
22
- ## Authentication And Workspace
23
-
24
- Use Personal API Key bearer authentication over Streamable HTTP. Let the
25
- service derive `user_id`, `workspace_id`, client identity, and scopes from the
26
- key. Never pass `workspace_id` in normal Agent calls. OAuth remains pending.
27
-
28
- Do not use service internals during normal work:
29
-
30
- ```text
31
- data/
32
- *.db
33
- *.jsonl
34
- scripts/*.py
35
- memory_service.operations
36
- ```
37
-
38
- ## Required Behavior
39
-
40
- 1. Run `imem_health` before user-visible work when practical.
41
- 2. Call `imem_get_time_context` before resolving relative dates and use a fresh
42
- `server_time` and `workspace_timezone` for each operation.
43
- 3. Include `request_id` on mutations.
44
- 4. Include `idempotency_key` on Entry, Reminder Rule, and Artifact creates.
45
- 5. List Entries to select a target when `entry_id` is unknown. Before every
46
- Entry update, read that Entry and capture its top-level `revision`, even if
47
- the ID is already confirmed.
48
- 6. Before every Reminder Rule update, read the owning Schedule Entry and
49
- capture the selected rule's `revision`.
50
- 7. Send the captured revision as `expected_revision` on canonical update calls.
51
- 8. Ask the user to choose when multiple plausible Entries match.
52
- 9. Never guess `entry_id`, `rule_id`, or a revision.
53
- 10. Keep Entry `kind` immutable and nest Schedule changes under
54
- `schedule_details`.
55
- 11. Preserve service error codes and never report a failed write as successful.
56
-
57
- ## Intent Routing
58
-
59
- ```text
60
- fact, note, reference, decision, preference, or context
61
- -> imem_create_entry(kind=note)
62
-
63
- explicit time arrangement
64
- -> imem_create_entry(kind=schedule, schedule_details=...)
65
-
66
- new timed reminder
67
- -> imem_create_entry(kind=schedule, reminder_rules=[...])
68
-
69
- additional reminder for an existing Schedule Entry
70
- -> imem_create_entry_reminder_rule(entry_id=...)
71
-
72
- generated text, Markdown, or HTML deliverable
73
- -> imem_upload_artifact
74
- ```
75
-
76
- Do not route solely from extracted dates. Descriptive or historical dates stay
77
- in a note unless the user asks for time-based behavior.
78
-
79
- ## Scope Matrix
80
-
81
- | Capability | MCP tool | Scope |
82
- |---|---|---|
83
- | Health | `imem_health` | `entries:read` |
84
- | Time baseline | `imem_get_time_context` | `entries:read` |
85
- | Create Entry | `imem_create_entry` | `entries:write` |
86
- | List Entries | `imem_list_entries` | `entries:read` |
87
- | Get Entry | `imem_get_entry` | `entries:read` |
88
- | Update Entry | `imem_update_entry` | `entries:write` |
89
- | Delete/cancel Entry | `imem_delete_entry` | `entries:write` |
90
- | List occurrences | `imem_list_entry_occurrences` | `entries:read` |
91
- | Create Reminder Rule | `imem_create_entry_reminder_rule` | `entries:write` |
92
- | Update Reminder Rule | `imem_update_entry_reminder_rule` | `entries:write` |
93
- | Delete Reminder Rule | `imem_delete_entry_reminder_rule` | `entries:write` |
94
- | Upload private Artifact | `imem_upload_artifact` | `entries:write` |
95
-
96
- Exports, operation logs, API-key administration, scheduler scans, and delivery
97
- operations remain outside the public MCP surface.
98
-
99
- ## Idempotency
100
-
101
- Use idempotency for:
102
-
103
- ```text
104
- imem_create_entry
105
- imem_create_entry_reminder_rule
106
- imem_upload_artifact
107
- ```
108
-
109
- Reuse the same key only to retry the identical intended create. A different
110
- body with the same key returns `IDEMPOTENCY_CONFLICT`. After an uncertain
111
- update or delete, read current state before retrying.
112
-
113
- ## Update And Delete
114
-
115
- Use `imem_update_entry(entry_id=..., expected_revision=...)` with common
116
- fields at the top level and Schedule fields inside `patch.schedule_details`.
117
- Never patch `id`, `kind`, or `revision`. Read the latest Entry immediately
118
- before the update and copy its top-level `revision` into `expected_revision`.
119
-
120
- Use `imem_delete_entry` for soft deletion. A note becomes deleted. A Schedule
121
- Entry becomes canceled/deleted together with its active Reminder Rules
122
- according to service policy. Do not physically delete storage rows or files.
123
-
124
- Manage Reminder Rules through the nested create, update, and delete tools. A
125
- Reminder Rule mutation requires both the owning Schedule `entry_id` and the
126
- rule's `rule_id` where applicable. Before `imem_update_entry_reminder_rule`,
127
- read the Schedule Entry, select the nested rule, and send that rule's `revision`
128
- as `expected_revision`.
129
-
130
- The service keeps `expected_revision` optional for older clients, but canonical
131
- Skill update paths must always send it. On `REVISION_CONFLICT`, re-read the
132
- Entry and explain that another client changed it. Never silently retry without
133
- user review, omit `expected_revision`, or force an overwrite. Retry with the
134
- new revision only after the user chooses to apply or merge the intended change.
135
-
136
- ## Artifact Upload
137
-
138
- Use `imem_upload_artifact` for complete text, Markdown, or HTML deliverables.
139
- Every upload starts private. Do not claim it is public or try to enable a
140
- Public Link; only the user can do that in the authenticated iMem App.
141
-
142
- ## Compatibility
143
-
144
- The following tools remain temporary migration aliases:
145
-
146
- ```text
147
- imem_search
148
- imem_create_memory
149
- imem_create_schedule
150
- imem_create_reminder
151
- imem_cancel_entry
152
- ```
153
-
154
- `imem_update_entry` also accepts the legacy `entity_type + entity_id` form.
155
- New Agent workflows must use canonical tools and `entry_id` only. Do not remove
156
- or recommend legacy aliases until a separate deprecation contract authorizes
157
- it.
158
-
159
- ## Failure Handling
160
-
161
- | Error code | Required Agent behavior |
162
- |---|---|
163
- | `UNAUTHORIZED` | Ask the user/operator to check API key configuration. |
164
- | `FORBIDDEN` | Report the missing scope. |
165
- | `ENTRY_NOT_FOUND` | List again or ask the user to identify the target. |
166
- | `VALIDATION_FAILED` | Fix clear fields or ask for missing information. |
167
- | `INVALID_ENTRY_KIND` | Use `note` or `schedule`. |
168
- | `IDEMPOTENCY_CONFLICT` | Do not retry the same key; confirm intent. |
169
- | `REVISION_CONFLICT` | Re-read current state, explain the concurrent change, and ask whether to retry or merge. Never force overwrite. |
170
- | `CONFIGURATION_ERROR` | Check the MCP URL and host configuration. |
171
- | `MCP_TOOL_ERROR` | Treat the outcome as failed or uncertain. |
1
+ # iMem Agent Contract
2
+
3
+ Use this contract with the authenticated production MCP at
4
+ `https://imem.xin/mcp`. Read `mcp-tool-spec.md` for exact parameters and
5
+ `product-language.md` for terminology.
6
+
7
+ ## Domain Contract
8
+
9
+ Every independently manageable note or schedule is one Entry with one stable
10
+ `entry_id`:
11
+
12
+ ```text
13
+ Entry(kind=note) -> schedule_details=null, reminder_rules=[]
14
+ Entry(kind=schedule) -> schedule_details object, reminder_rules array
15
+ ```
16
+
17
+ ScheduleDetails belong one-to-one to a Schedule Entry. Reminder Rules belong
18
+ zero-to-many to a Schedule Entry and are not top-level Entries. Occurrences use
19
+ `entry_id` and `occurrence_id`; they do not require legacy Memory or Schedule
20
+ IDs. Artifact remains a separate private deliverable resource.
21
+
22
+ ## Authentication And Workspace
23
+
24
+ Use OAuth Authorization Code with PKCE or Personal API Key bearer authentication
25
+ over Streamable HTTP. Let the service derive `user_id`, `workspace_id`, client
26
+ identity, and scopes from the credential. Never pass `workspace_id` in normal
27
+ Agent calls.
28
+
29
+ Do not use service internals during normal work:
30
+
31
+ ```text
32
+ data/
33
+ *.db
34
+ *.jsonl
35
+ scripts/*.py
36
+ memory_service.operations
37
+ ```
38
+
39
+ ## Required Behavior
40
+
41
+ 1. Run `imem_health` before user-visible work when practical.
42
+ 2. Call `imem_get_time_context` before resolving relative dates and use a fresh
43
+ `server_time` and `workspace_timezone` for each operation.
44
+ 3. Include `request_id` on mutations.
45
+ 4. Include `idempotency_key` on Entry, Reminder Rule, and Artifact creates.
46
+ 5. List Entries to select a target when `entry_id` is unknown. Before every
47
+ Entry update, read that Entry and capture its top-level `revision`, even if
48
+ the ID is already confirmed.
49
+ 6. Before every Reminder Rule update, read the owning Schedule Entry and
50
+ capture the selected rule's `revision`.
51
+ 7. Send the captured revision as `expected_revision` on canonical update calls.
52
+ 8. Ask the user to choose when multiple plausible Entries match.
53
+ 9. Never guess `entry_id`, `rule_id`, or a revision.
54
+ 10. Keep Entry `kind` immutable and nest Schedule changes under
55
+ `schedule_details`.
56
+ 11. Preserve service error codes and never report a failed write as successful.
57
+
58
+ ## Intent Routing
59
+
60
+ ```text
61
+ fact, note, reference, decision, preference, or context
62
+ -> imem_create_entry(kind=note)
63
+
64
+ explicit time arrangement
65
+ -> imem_create_entry(kind=schedule, schedule_details=...)
66
+
67
+ new timed reminder
68
+ -> imem_create_entry(kind=schedule, reminder_rules=[...])
69
+
70
+ additional reminder for an existing Schedule Entry
71
+ -> imem_create_entry_reminder_rule(entry_id=...)
72
+
73
+ generated text, Markdown, or HTML deliverable
74
+ -> imem_upload_artifact
75
+ ```
76
+
77
+ Do not route solely from extracted dates. Descriptive or historical dates stay
78
+ in a note unless the user asks for time-based behavior.
79
+
80
+ ## Scope Matrix
81
+
82
+ | Capability | MCP tool | Scope |
83
+ |---|---|---|
84
+ | Health | `imem_health` | `entries:read` |
85
+ | Time baseline | `imem_get_time_context` | `entries:read` |
86
+ | Create Entry | `imem_create_entry` | `entries:write` |
87
+ | List Entries | `imem_list_entries` | `entries:read` |
88
+ | Get Entry | `imem_get_entry` | `entries:read` |
89
+ | Update Entry | `imem_update_entry` | `entries:write` |
90
+ | Delete/cancel Entry | `imem_delete_entry` | `entries:write` |
91
+ | List occurrences | `imem_list_entry_occurrences` | `entries:read` |
92
+ | Create Reminder Rule | `imem_create_entry_reminder_rule` | `entries:write` |
93
+ | Update Reminder Rule | `imem_update_entry_reminder_rule` | `entries:write` |
94
+ | Delete Reminder Rule | `imem_delete_entry_reminder_rule` | `entries:write` |
95
+ | Upload private Artifact | `imem_upload_artifact` | `entries:write` |
96
+
97
+ Exports, operation logs, API-key administration, scheduler scans, and delivery
98
+ operations remain outside the public MCP surface.
99
+
100
+ ## Idempotency
101
+
102
+ Use idempotency for:
103
+
104
+ ```text
105
+ imem_create_entry
106
+ imem_create_entry_reminder_rule
107
+ imem_upload_artifact
108
+ ```
109
+
110
+ Reuse the same key only to retry the identical intended create. A different
111
+ body with the same key returns `IDEMPOTENCY_CONFLICT`. After an uncertain
112
+ update or delete, read current state before retrying.
113
+
114
+ ## Update And Delete
115
+
116
+ Use `imem_update_entry(entry_id=..., expected_revision=...)` with common
117
+ fields at the top level and Schedule fields inside `patch.schedule_details`.
118
+ Never patch `id`, `kind`, or `revision`. Read the latest Entry immediately
119
+ before the update and copy its top-level `revision` into `expected_revision`.
120
+
121
+ Use `imem_delete_entry` for soft deletion. A note becomes deleted. A Schedule
122
+ Entry becomes canceled/deleted together with its active Reminder Rules
123
+ according to service policy. Do not physically delete storage rows or files.
124
+
125
+ Manage Reminder Rules through the nested create, update, and delete tools. A
126
+ Reminder Rule mutation requires both the owning Schedule `entry_id` and the
127
+ rule's `rule_id` where applicable. Before `imem_update_entry_reminder_rule`,
128
+ read the Schedule Entry, select the nested rule, and send that rule's `revision`
129
+ as `expected_revision`.
130
+
131
+ The service keeps `expected_revision` optional for older clients, but canonical
132
+ Skill update paths must always send it. On `REVISION_CONFLICT`, re-read the
133
+ Entry and explain that another client changed it. Never silently retry without
134
+ user review, omit `expected_revision`, or force an overwrite. Retry with the
135
+ new revision only after the user chooses to apply or merge the intended change.
136
+
137
+ ## Artifact Upload
138
+
139
+ Use `imem_upload_artifact` for complete text, Markdown, or HTML deliverables.
140
+ Every upload starts private. Do not claim it is public or try to enable a
141
+ Public Link; only the user can do that in the authenticated iMem App.
142
+
143
+ ## Compatibility
144
+
145
+ The following tools remain temporary migration aliases:
146
+
147
+ ```text
148
+ imem_search
149
+ imem_create_memory
150
+ imem_create_schedule
151
+ imem_create_reminder
152
+ imem_cancel_entry
153
+ ```
154
+
155
+ `imem_update_entry` also accepts the legacy `entity_type + entity_id` form.
156
+ New Agent workflows must use canonical tools and `entry_id` only. Do not remove
157
+ or recommend legacy aliases until a separate deprecation contract authorizes
158
+ it.
159
+
160
+ ## Failure Handling
161
+
162
+ | Error code | Required Agent behavior |
163
+ |---|---|
164
+ | `UNAUTHORIZED` | Ask the user/operator to reconnect or check authentication. |
165
+ | `FORBIDDEN` | Report the missing scope. |
166
+ | `ENTRY_NOT_FOUND` | List again or ask the user to identify the target. |
167
+ | `VALIDATION_FAILED` | Fix clear fields or ask for missing information. |
168
+ | `INVALID_ENTRY_KIND` | Use `note` or `schedule`. |
169
+ | `IDEMPOTENCY_CONFLICT` | Do not retry the same key; confirm intent. |
170
+ | `REVISION_CONFLICT` | Re-read current state, explain the concurrent change, and ask whether to retry or merge. Never force overwrite. |
171
+ | `CONFIGURATION_ERROR` | Check the MCP URL and host configuration. |
172
+ | `MCP_TOOL_ERROR` | Treat the outcome as failed or uncertain. |