adp-plugin-dima 0.0.0-stage → 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LitoMore
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,39 @@
1
- # Temporary Holding Version
1
+ # adp-plugin-dima
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Agent Discord Presence integration for dima (Dim Rust alpha). Reports session
4
+ activity, approval waits, failures, and completed replies. Native summaries use
5
+ dima's auxiliary-model service; custom models and OpenAI-compatible services are
6
+ also supported.
7
+
8
+ ## Install
9
+
10
+ Requires an ADP build with external Agent plugins and GitHub installation support.
11
+
12
+ ```sh
13
+ adp plugin install github:weiuou/adp-plugin-dima
14
+ ```
15
+
16
+ Then run the `dima plugin install` command printed by ADP and reload or restart
17
+ dima. The package contains ready-to-run JavaScript and needs no build or npm
18
+ dependencies.
19
+
20
+ In the desktop client, open **Agents → Install from GitHub…** and enter
21
+ `github:weiuou/adp-plugin-dima`. Use **DimAgent → Setup → Manual configuration**
22
+ for the dima installation command and event options. ADP installation alone does
23
+ not load the plugin into dima.
24
+
25
+ The Agent ID remains `dimagent`, preserving existing settings. The installed copy
26
+ uses ADP's generated `.adp-runtime.json`; loading this checkout directly in dima
27
+ is unsupported. Reload dima after changing event options.
28
+
29
+ ## Development
30
+
31
+ Point the tests at a built, plugin-capable ADP checkout:
32
+
33
+ ```sh
34
+ npm run check
35
+ ADP_SOURCE_DIR=../agent-discord-presence npm test
36
+ ```
37
+
38
+ Extracted from [weiuou/adp-plugins](https://github.com/weiuou/adp-plugins/tree/977172b4db8b7a3caf8f6d6664a42efd0a01566d/plugins/dima).
39
+ The original MIT license is retained.
@@ -0,0 +1,232 @@
1
+ {
2
+ "apiVersion": 1,
3
+ "id": "dimagent",
4
+ "name": "DimAgent",
5
+ "version": "0.2.0",
6
+ "description": "Dim Rust alpha (dima) sessions, approval waits and native auxiliary-model summaries. Shares existing DimAgent settings.",
7
+ "icon": "icon.png",
8
+ "presenceImage": "https://dimagent.cn/favicon.png",
9
+ "extension": "extension.mjs",
10
+ "setup": {
11
+ "kind": "manual",
12
+ "instructions": "Install this package into dima, then reload the plugin or restart dima.",
13
+ "command": [
14
+ "dima",
15
+ "plugin",
16
+ "install",
17
+ "{pluginRoot}"
18
+ ]
19
+ },
20
+ "integration": {
21
+ "kind": "policy",
22
+ "events": [
23
+ {
24
+ "id": "branch/start",
25
+ "capability": "presence",
26
+ "description": "Initialize activity for a Dim branch.",
27
+ "required": true,
28
+ "requires": []
29
+ },
30
+ {
31
+ "id": "branch/resume",
32
+ "capability": "presence",
33
+ "description": "Resume activity for a Dim branch.",
34
+ "required": true,
35
+ "requires": []
36
+ },
37
+ {
38
+ "id": "context/configured",
39
+ "capability": "presence",
40
+ "description": "Track the branch model and provider.",
41
+ "required": true,
42
+ "requires": []
43
+ },
44
+ {
45
+ "id": "turn/start",
46
+ "capability": "presence",
47
+ "description": "Show working when a Dim turn starts.",
48
+ "required": true,
49
+ "requires": []
50
+ },
51
+ {
52
+ "id": "turn/end",
53
+ "capability": "presence",
54
+ "description": "Show idle after a Dim turn finishes.",
55
+ "required": true,
56
+ "requires": []
57
+ },
58
+ {
59
+ "id": "stop/interrupt",
60
+ "capability": "presence",
61
+ "description": "Cancel pending summaries and show idle after interruption.",
62
+ "required": true,
63
+ "requires": []
64
+ },
65
+ {
66
+ "id": "branch/end",
67
+ "capability": "cleanup",
68
+ "description": "Close the branch reporter and cancel pending summaries.",
69
+ "required": true,
70
+ "requires": []
71
+ },
72
+ {
73
+ "id": "plugin/unload",
74
+ "capability": "cleanup",
75
+ "description": "Release all reporters and summary jobs.",
76
+ "required": true,
77
+ "requires": [],
78
+ "source": "ctx.effect"
79
+ },
80
+ {
81
+ "id": "approval/request",
82
+ "capability": "waiting",
83
+ "description": "Show waiting when an approval is requested.",
84
+ "required": false,
85
+ "requires": [
86
+ "approval/respond",
87
+ "approval/cancelled"
88
+ ]
89
+ },
90
+ {
91
+ "id": "approval/respond",
92
+ "capability": "waiting",
93
+ "description": "Restore activity after an approval is answered.",
94
+ "required": false,
95
+ "requires": [
96
+ "approval/request",
97
+ "approval/cancelled"
98
+ ]
99
+ },
100
+ {
101
+ "id": "approval/cancelled",
102
+ "capability": "waiting",
103
+ "description": "Restore activity after an approval is cancelled.",
104
+ "required": false,
105
+ "requires": [
106
+ "approval/request",
107
+ "approval/respond"
108
+ ]
109
+ },
110
+ {
111
+ "id": "step/model-start",
112
+ "capability": "summary",
113
+ "description": "Reset reply collection at the start of a model response.",
114
+ "required": false,
115
+ "requires": [
116
+ "step/text",
117
+ "step/model-content",
118
+ "step/model-output-end",
119
+ "step/tool-use-start",
120
+ "step/tool-use"
121
+ ],
122
+ "source": "session/event"
123
+ },
124
+ {
125
+ "id": "step/text",
126
+ "capability": "summary",
127
+ "description": "Collect completed assistant text for automatic summaries.",
128
+ "required": false,
129
+ "requires": [
130
+ "step/model-start",
131
+ "step/model-content",
132
+ "step/model-output-end",
133
+ "step/tool-use-start",
134
+ "step/tool-use"
135
+ ],
136
+ "source": "session/event"
137
+ },
138
+ {
139
+ "id": "step/model-content",
140
+ "capability": "summary",
141
+ "description": "Track completed model content and exclude tool responses.",
142
+ "required": false,
143
+ "requires": [
144
+ "step/model-start",
145
+ "step/text",
146
+ "step/model-output-end",
147
+ "step/tool-use-start",
148
+ "step/tool-use"
149
+ ],
150
+ "source": "session/event"
151
+ },
152
+ {
153
+ "id": "step/model-output-end",
154
+ "capability": "summary",
155
+ "description": "Verify that the model response completed normally.",
156
+ "required": false,
157
+ "requires": [
158
+ "step/model-start",
159
+ "step/text",
160
+ "step/model-content",
161
+ "step/tool-use-start",
162
+ "step/tool-use"
163
+ ],
164
+ "source": "session/event"
165
+ },
166
+ {
167
+ "id": "step/tool-use-start",
168
+ "capability": "summary",
169
+ "description": "Exclude replies that are continuing into a tool call.",
170
+ "required": false,
171
+ "requires": [
172
+ "step/model-start",
173
+ "step/text",
174
+ "step/model-content",
175
+ "step/model-output-end",
176
+ "step/tool-use"
177
+ ],
178
+ "source": "session/event"
179
+ },
180
+ {
181
+ "id": "step/tool-use",
182
+ "capability": "summary",
183
+ "description": "Track tool continuations before final reply completion.",
184
+ "required": false,
185
+ "requires": [
186
+ "step/model-start",
187
+ "step/text",
188
+ "step/model-content",
189
+ "step/model-output-end",
190
+ "step/tool-use-start"
191
+ ],
192
+ "source": "session/event"
193
+ },
194
+ {
195
+ "id": "turn/failure",
196
+ "capability": "errors",
197
+ "description": "Show an error when a Dim turn fails.",
198
+ "required": false,
199
+ "requires": [
200
+ "turn/end"
201
+ ],
202
+ "source": "turn/end"
203
+ }
204
+ ],
205
+ "removalInstructions": "Remove Agent Discord Presence using dima's plugin manager, then reload or restart dima."
206
+ },
207
+ "locales": {
208
+ "zh-CN": {
209
+ "Initialize activity for a Dim branch.": "初始化 Dim 分支的活动状态。",
210
+ "Resume activity for a Dim branch.": "恢复 Dim 分支的活动状态。",
211
+ "Track the branch model and provider.": "跟踪分支所用的模型和服务商。",
212
+ "Show working when a Dim turn starts.": "Dim 开始一轮任务时显示工作中。",
213
+ "Show idle after a Dim turn finishes.": "Dim 一轮任务结束后显示空闲。",
214
+ "Cancel pending summaries and show idle after interruption.": "中断后取消待处理摘要并显示空闲。",
215
+ "Close the branch reporter and cancel pending summaries.": "关闭分支的状态上报并取消待处理摘要。",
216
+ "Release all reporters and summary jobs.": "释放所有活动上报器和摘要任务。",
217
+ "Show waiting when an approval is requested.": "请求审批时显示等待确认。",
218
+ "Restore activity after an approval is answered.": "审批得到答复后恢复活动状态。",
219
+ "Restore activity after an approval is cancelled.": "审批取消后恢复活动状态。",
220
+ "Reset reply collection at the start of a model response.": "模型开始回复时重置回复采集。",
221
+ "Collect completed assistant text for automatic summaries.": "为自动摘要采集完整助手回复。",
222
+ "Track completed model content and exclude tool responses.": "跟踪模型的完整回复,并排除工具响应。",
223
+ "Verify that the model response completed normally.": "确认模型回复已正常完成。",
224
+ "Exclude replies that are continuing into a tool call.": "排除即将继续调用工具的中间回复。",
225
+ "Track tool continuations before final reply completion.": "跟踪最终回复完成前的工具调用续接。",
226
+ "Show an error when a Dim turn fails.": "Dim 一轮任务失败时显示错误状态。",
227
+ "Remove Agent Discord Presence using dima's plugin manager, then reload or restart dima.": "请通过 dima 的插件管理器移除 Agent Discord Presence,然后重新加载或重启 dima。",
228
+ "Dim Rust alpha (dima) sessions, approval waits and native auxiliary-model summaries. Shares existing DimAgent settings.": "支持 Dim Rust alpha(dima)的会话、审批等待和原生辅助模型摘要。沿用已有的 DimAgent 设置。",
229
+ "Install this package into dima, then reload the plugin or restart dima.": "将此插件包安装到 dima,然后重新加载插件或重启 dima。"
230
+ }
231
+ }
232
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "agent-discord-presence",
3
+ "description": "Discord Rich Presence for the Rust Dim harness",
4
+ "code": {
5
+ "entry": "index.js",
6
+ "inject": ["partRegistry", "auxiliaryModel"],
7
+ "provides": {}
8
+ }
9
+ }
@@ -0,0 +1,6 @@
1
+ export declare function dimSessionId(session: string, branch: string): string;
2
+ export declare function createDimPlugin(sdk: unknown): {
3
+ name: string;
4
+ inject: string[];
5
+ apply(ctx: any): Promise<void>;
6
+ };
package/extension.mjs ADDED
@@ -0,0 +1,274 @@
1
+ // Native Dim observer; SDK is supplied by the installed ADP runtime.
2
+ import { createHash } from 'node:crypto';
3
+ /** Stable, bounded and distinct from the legacy TypeScript CLI's session ids. */
4
+ export function dimSessionId(session, branch) {
5
+ return `rust:${createHash('sha256').update(JSON.stringify([session, branch])).digest('hex')}`;
6
+ }
7
+ export function createDimPlugin({Reporter, request, boundedResponse, generateSummary, buildPresencePrompt, loadSettings, resolveSettings, parseSummary, adapterEvents}) {
8
+ function settings() { return resolveSettings(loadSettings(), 'dimagent'); }
9
+ function policy(value) {
10
+ return JSON.stringify([value.enabled, value.summaryTriggers, value.service, value.model, value.provider, value.baseUrl,
11
+ value.apiKeyEnv, value.customPrompt, value.maxLength]);
12
+ }
13
+ /** One worker per loaded plugin; latest completion per branch, at most 32 queued. */
14
+ class Summaries {
15
+ auxiliary;
16
+ pending = new Map();
17
+ active;
18
+ running;
19
+ closed = false;
20
+ constructor(auxiliary) {
21
+ this.auxiliary = auxiliary;
22
+ }
23
+ cancel(entry) {
24
+ entry.epoch++;
25
+ this.pending.delete(entry);
26
+ if (this.active?.job.entry === entry)
27
+ this.active.controller.abort();
28
+ }
29
+ submit(entry, event) {
30
+ if (this.closed || entry.closed || !event.response || !settings().summaryTriggers.includes('reply'))
31
+ return;
32
+ if (this.pending.size >= 32 && !this.pending.has(entry))
33
+ this.pending.delete(this.pending.keys().next().value);
34
+ this.pending.set(entry, { entry, epoch: entry.epoch, event });
35
+ if (!this.running)
36
+ this.running = this.drain().finally(() => { this.running = undefined; });
37
+ }
38
+ current(job) {
39
+ return !this.closed && !job.entry.closed && job.entry.epoch === job.epoch && job.entry.state === 'idle';
40
+ }
41
+ async target(key) {
42
+ const status = await request({ type: 'status' });
43
+ return status.sessions.find(session => session.key === key);
44
+ }
45
+ async drain() {
46
+ while (!this.closed && this.pending.size) {
47
+ const [entry, job] = this.pending.entries().next().value;
48
+ this.pending.delete(entry);
49
+ const controller = new AbortController();
50
+ this.active = { job, controller };
51
+ const timer = setTimeout(() => controller.abort(), 60_000);
52
+ timer.unref();
53
+ try {
54
+ const config = settings();
55
+ if (!config.enabled || !this.current(job))
56
+ continue;
57
+ const key = `dimagent:${job.event.sessionId}`;
58
+ const target = await this.target(key);
59
+ if (!target || target.updatedAt !== job.event.updatedAt || target.state !== 'idle' || !this.current(job))
60
+ continue;
61
+ let summary;
62
+ if (config.service === 'openai-compatible') {
63
+ summary = await generateSummary(config, 'dimagent', job.event.response, controller.signal, job.event);
64
+ }
65
+ else {
66
+ const modelId = config.model || job.event.model;
67
+ const providerId = config.provider || job.event.provider;
68
+ if (!modelId || !providerId)
69
+ continue;
70
+ const input = buildPresencePrompt({ agent: 'dimagent', response: job.event.response }, config);
71
+ const cancelled = new Promise(resolve => {
72
+ if (controller.signal.aborted)
73
+ resolve();
74
+ else
75
+ controller.signal.addEventListener('abort', () => resolve(), { once: true });
76
+ });
77
+ const reply = await this.auxiliary.complete({ model: { modelId, providerId }, request: {
78
+ system: input.systemPrompt + '\nReturn only JSON matching this schema:\n' + JSON.stringify(input.schema),
79
+ messages: [{ role: 'user', content: input.prompt }], maxOutputTokens: 2048,
80
+ } }, () => cancelled);
81
+ if (reply.stopReason !== 'end_turn' || reply.text.length > 16_384)
82
+ continue;
83
+ summary = parseSummary(JSON.parse(reply.text));
84
+ }
85
+ controller.signal.throwIfAborted();
86
+ if (!this.current(job) || policy(settings()) !== policy(config) ||
87
+ Array.from(summary.topic).length > config.maxLength || Array.from(summary.subtitle).length > config.maxLength)
88
+ continue;
89
+ // The generic summary API guards session lifetime and event freshness.
90
+ // Also preserve a manual edit made while the auxiliary call was running.
91
+ const latest = await this.target(key);
92
+ if (!latest || latest.updatedAt !== target.updatedAt || latest.startedAt !== target.startedAt ||
93
+ latest.state !== 'idle' || JSON.stringify(latest.summary) !== JSON.stringify(target.summary) || !this.current(job))
94
+ continue;
95
+ await request({ type: 'summary', key, summary,
96
+ expectedUpdatedAt: target.updatedAt, expectedStartedAt: target.startedAt });
97
+ }
98
+ catch { /* Presence failures never fail a Dim listener or expose source/model output. */ }
99
+ finally {
100
+ clearTimeout(timer);
101
+ this.active = undefined;
102
+ }
103
+ }
104
+ }
105
+ async close() {
106
+ this.closed = true;
107
+ this.pending.clear();
108
+ this.active?.controller.abort();
109
+ await this.running;
110
+ }
111
+ }
112
+ function observer(summaries) {
113
+ return {
114
+ name: 'AgentDiscordPresenceSession', inject: ['sessionIdentity', 'sessionConfig', 'sessionLifecycle'],
115
+ async apply(ctx) {
116
+ if (process.env.ADP_SUMMARY_WORKER === '1')
117
+ return;
118
+ let selected;
119
+ try { selected = adapterEvents('dimagent'); } catch { return; }
120
+ const entries = new Map();
121
+ let closed = false;
122
+ let active = false;
123
+ let closing;
124
+ const close = () => closing ??= (async () => {
125
+ closed = true;
126
+ await Promise.all([...entries.values()].map(async (entry) => {
127
+ entry.closed = true;
128
+ summaries.cancel(entry);
129
+ await entry.reporter.close();
130
+ }));
131
+ entries.clear();
132
+ })();
133
+ ctx.effect(() => close);
134
+ const { sessionId } = await ctx.get('sessionIdentity').get();
135
+ const config = await ctx.get('sessionConfig').get();
136
+ const lifecycle = ctx.get('sessionLifecycle');
137
+ void lifecycle.closing().then(close).catch(close);
138
+ function get(branch) {
139
+ let entry = entries.get(branch);
140
+ if (!entry) {
141
+ const reporter = new Reporter('dimagent', dimSessionId(sessionId, branch), async (event) => {
142
+ try {
143
+ // No response/run-id/activity side channel: the daemon's legacy Dim CLI worker is never used.
144
+ await request({ type: 'event', event: { ...event, response: undefined } });
145
+ if (event.response && entry && !event.heartbeat)
146
+ summaries.submit(entry, event);
147
+ }
148
+ catch { /* The daemon may be offline. Reporter heartbeats reconnect. */ }
149
+ });
150
+ reporter.model = config.model.modelId;
151
+ reporter.provider = config.model.providerId;
152
+ entry = { reporter, response: '', toolContent: false, finalized: false, approvals: new Set(), state: 'idle', epoch: 0, closed: false };
153
+ entries.set(branch, entry);
154
+ }
155
+ return entry;
156
+ }
157
+ function set(entry, state, response) {
158
+ entry.state = state;
159
+ if (active)
160
+ entry.reporter.set(state, response);
161
+ }
162
+ ctx.on(`session/${sessionId}`, record => {
163
+ if (closed || record.kind !== 'event' || !record.event || !record.branchId)
164
+ return;
165
+ const { type, name, data } = record.event;
166
+ const kind = `${type}/${name}`;
167
+ if (!['branch/start', 'branch/resume', 'branch/end', 'context/configured', 'turn/start', 'turn/end',
168
+ 'step/model-start', 'step/text', 'step/model-content', 'step/model-output-end', 'step/tool-use-start', 'step/tool-use',
169
+ 'approval/request', 'approval/respond', 'approval/cancelled', 'stop/interrupt'].includes(kind))
170
+ return;
171
+ if (!selected.has(kind)) return;
172
+ const entry = get(record.branchId);
173
+ if (entry.closed)
174
+ return;
175
+ if (kind === 'context/configured') {
176
+ const route = data.settings;
177
+ if (typeof route?.modelId === 'string')
178
+ entry.reporter.model = route.modelId;
179
+ if (typeof route?.providerId === 'string')
180
+ entry.reporter.provider = route.providerId;
181
+ }
182
+ else if (kind === 'turn/start') {
183
+ summaries.cancel(entry);
184
+ entry.turn = typeof data.turn_id === 'string' ? data.turn_id : undefined;
185
+ entry.response = '';
186
+ entry.request = undefined;
187
+ entry.toolContent = false;
188
+ entry.finalized = false;
189
+ entry.approvals.clear();
190
+ set(entry, 'working');
191
+ }
192
+ else if (kind === 'step/model-start' && data.turn_id === entry.turn) {
193
+ entry.response = '';
194
+ entry.toolContent = false;
195
+ entry.finalized = false;
196
+ entry.request = typeof data.request_id === 'string' ? data.request_id : undefined;
197
+ }
198
+ else if (kind.startsWith('step/') && entry.turn && entry.request && data.turn_id === entry.turn && data.request_id === entry.request) {
199
+ if (kind === 'step/text' && typeof data.delta === 'string') {
200
+ // Some providers omit the optional complete-content snapshot.
201
+ // Preserve whitespace between deltas and bound the retained prefix.
202
+ entry.response = Array.from(entry.response + data.delta.slice(0, 8000)).slice(0, 4000).join('');
203
+ }
204
+ if (kind === 'step/tool-use-start' || kind === 'step/tool-use')
205
+ entry.toolContent = true;
206
+ if (kind === 'step/model-content') {
207
+ const parts = Array.isArray(data.content) ? data.content : [];
208
+ entry.toolContent ||= parts.some(part => part.type === 'tool_use');
209
+ entry.response = boundedResponse(parts.filter(part => part.type === 'text' && typeof part.text === 'string').map(part => part.text).join('\n'));
210
+ }
211
+ if (kind === 'step/model-output-end')
212
+ entry.finalized = data.status === 'completed' && data.finish_reason === 'end_turn';
213
+ }
214
+ else if (kind === 'approval/request') {
215
+ summaries.cancel(entry);
216
+ if (typeof data.approval_id === 'string')
217
+ entry.approvals.add(data.approval_id);
218
+ set(entry, 'waiting');
219
+ }
220
+ else if (kind === 'approval/respond' || kind === 'approval/cancelled') {
221
+ if (typeof data.approval_id === 'string')
222
+ entry.approvals.delete(data.approval_id);
223
+ set(entry, entry.approvals.size ? 'waiting' : entry.turn ? 'working' : 'idle');
224
+ }
225
+ else if (kind === 'turn/end' && entry.turn && data.turn_id === entry.turn) {
226
+ const response = data.status === 'completed' && entry.finalized && !entry.toolContent ? entry.response : undefined;
227
+ entry.turn = undefined;
228
+ entry.approvals.clear();
229
+ set(entry, data.status === 'failed' && selected.has('turn/failure') ? 'error' : 'idle', response);
230
+ entry.response = '';
231
+ }
232
+ else if (kind === 'stop/interrupt') {
233
+ summaries.cancel(entry);
234
+ entry.turn = undefined;
235
+ entry.response = '';
236
+ entry.approvals.clear();
237
+ set(entry, 'idle');
238
+ }
239
+ else if (kind === 'branch/end') {
240
+ entry.closed = true;
241
+ summaries.cancel(entry);
242
+ void entry.reporter.close();
243
+ }
244
+ else if (kind === 'branch/start' || kind === 'branch/resume')
245
+ set(entry, 'idle');
246
+ });
247
+ // Do not hold Session publication by awaiting activated() inside apply.
248
+ void lifecycle.activated().then(published => {
249
+ if (!published || closed)
250
+ return;
251
+ active = true;
252
+ if (!entries.size)
253
+ get('main');
254
+ for (const entry of entries.values())
255
+ if (!entry.closed)
256
+ entry.reporter.set(entry.state);
257
+ }).catch(close);
258
+ },
259
+ };
260
+ }
261
+ /** Dim's process row mounts one advisory observer per Session. */
262
+ return {
263
+ name: 'AgentDiscordPresenceDim', inject: ['partRegistry', 'auxiliaryModel'],
264
+ async apply(ctx) {
265
+ if (process.env.ADP_SUMMARY_WORKER === '1')
266
+ return;
267
+ const summaries = new Summaries(ctx.get('auxiliaryModel'));
268
+ ctx.effect(() => () => summaries.close());
269
+ await ctx.get('partRegistry')
270
+ .registerDefinition('session', 'AgentDiscordPresenceSession', observer(summaries));
271
+ },
272
+ };
273
+
274
+ }
package/icon.png ADDED
Binary file
package/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import {readFileSync, existsSync} from 'node:fs';
2
+ import {createDimPlugin} from './extension.mjs';
3
+ // ADP installs provide a stable SDK binding for both CLI and desktop installs.
4
+ const binding = new URL('./.adp-runtime.json', import.meta.url);
5
+ const runtime = existsSync(binding) ? JSON.parse(readFileSync(binding, 'utf8')) : undefined;
6
+ if (runtime?.config) process.env.ADP_CONFIG ??= runtime.config;
7
+ if (runtime?.socket) process.env.AGENT_PRESENCE_SOCKET ??= runtime.socket;
8
+ if (!runtime?.sdk) throw new Error('Install this package through ADP before loading it in dima.');
9
+ const sdkURL = runtime.sdk;
10
+ const sdk = await import(sdkURL);
11
+ export default createDimPlugin(sdk);
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "adp-plugin-dima",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "description": "Agent Discord Presence plugin for dima (Dim Rust alpha)",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/weiuou/adp-plugin-dima.git"
10
+ },
11
+ "engines": {
12
+ "node": ">=22"
13
+ },
14
+ "files": [
15
+ "adp-plugin.json",
16
+ "dim-plugin.json",
17
+ "index.js",
18
+ "extension.mjs",
19
+ "extension.d.mts",
20
+ "icon.png"
21
+ ],
22
+ "scripts": {
23
+ "check": "node --check index.js && node --check extension.mjs",
24
+ "test": "node --test test/*.test.mjs"
25
+ }
26
+ }