@spoons-and-mirrors/iam 0.1.3 → 0.1.4
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/README.md +2 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -10
- package/dist/logger.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,10 +15,10 @@ Agents get friendly names (agentA, agentB, ...) and automatically discover each
|
|
|
15
15
|
|
|
16
16
|
When an agent announces, the response shows all other parallel agents — whether they've announced yet or not. This gives agents instant awareness of who's working alongside them. Agents can re-announce to update their status.
|
|
17
17
|
|
|
18
|
-
Agents who haven't announced are told they MUST announce before continuing.
|
|
19
|
-
|
|
20
18
|
When an agent completes their task, they're encouraged to broadcast a completion message so others know.
|
|
21
19
|
|
|
20
|
+
The plugin injects IAM instructions into the **system prompt** for child sessions only (sessions with a `parentID`).
|
|
21
|
+
|
|
22
22
|
## Actions
|
|
23
23
|
|
|
24
24
|
| Action | Description |
|
|
@@ -40,7 +40,3 @@ action="broadcast", message="Found a bug in config.ts, heads up"
|
|
|
40
40
|
action="broadcast", to="agentA", message="Can you check auth.ts?"
|
|
41
41
|
action="broadcast", to="agentA,agentC", message="Sync up on API changes"
|
|
42
42
|
```
|
|
43
|
-
|
|
44
|
-
## Debug Logs
|
|
45
|
-
|
|
46
|
-
For troubleshooting, check `.logs/iam.log` (clears on restart).
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAqLjD,QAAA,MAAM,MAAM,EAAE,MAiLb,CAAA;AAED,eAAe,MAAM,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -112,18 +112,24 @@ Use the iam tool with action="read" NOW to check your messages before continuing
|
|
|
112
112
|
// logger.ts
|
|
113
113
|
import * as fs from "fs";
|
|
114
114
|
import * as path from "path";
|
|
115
|
+
var __dirname = "/home/spoon/.config/opencode/plugin/iam";
|
|
116
|
+
var IS_DEV = fs.existsSync(path.join(__dirname, "..", ".git"));
|
|
115
117
|
var LOG_DIR = path.join(process.cwd(), ".logs");
|
|
116
118
|
var LOG_FILE = path.join(LOG_DIR, "iam.log");
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
fs.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
if (IS_DEV) {
|
|
120
|
+
try {
|
|
121
|
+
if (!fs.existsSync(LOG_DIR)) {
|
|
122
|
+
fs.mkdirSync(LOG_DIR, { recursive: true });
|
|
123
|
+
}
|
|
124
|
+
fs.writeFileSync(LOG_FILE, "");
|
|
125
|
+
} catch {}
|
|
126
|
+
}
|
|
123
127
|
function formatTimestamp() {
|
|
124
128
|
return new Date().toISOString();
|
|
125
129
|
}
|
|
126
130
|
function writeLog(level, category, message, data) {
|
|
131
|
+
if (!IS_DEV)
|
|
132
|
+
return;
|
|
127
133
|
const timestamp = formatTimestamp();
|
|
128
134
|
const dataStr = data !== undefined ? ` | ${JSON.stringify(data)}` : "";
|
|
129
135
|
const logLine = `[${timestamp}] [${level}] [${category}] ${message}${dataStr}
|
|
@@ -153,6 +159,8 @@ var sessionToAlias = new Map;
|
|
|
153
159
|
var aliasToSession = new Map;
|
|
154
160
|
var agentDescriptions = new Map;
|
|
155
161
|
var nextAgentIndex = 0;
|
|
162
|
+
var instructedSessions = new Set;
|
|
163
|
+
var sessionParentCache = new Map;
|
|
156
164
|
function getNextAlias() {
|
|
157
165
|
const letter = String.fromCharCode(65 + nextAgentIndex % 26);
|
|
158
166
|
const suffix = nextAgentIndex >= 26 ? Math.floor(nextAgentIndex / 26).toString() : "";
|
|
@@ -237,8 +245,25 @@ function registerSession(sessionId) {
|
|
|
237
245
|
log.info(LOG.SESSION, `Session registered`, { sessionId, alias, totalSessions: activeSessions.size });
|
|
238
246
|
}
|
|
239
247
|
}
|
|
240
|
-
|
|
248
|
+
async function getParentId(client, sessionId) {
|
|
249
|
+
if (sessionParentCache.has(sessionId)) {
|
|
250
|
+
return sessionParentCache.get(sessionId);
|
|
251
|
+
}
|
|
252
|
+
try {
|
|
253
|
+
const response = await client.session.get({ path: { id: sessionId } });
|
|
254
|
+
const parentId = response.data?.parentID || null;
|
|
255
|
+
sessionParentCache.set(sessionId, parentId);
|
|
256
|
+
log.debug(LOG.SESSION, `Looked up parentID`, { sessionId, parentId });
|
|
257
|
+
return parentId;
|
|
258
|
+
} catch (e) {
|
|
259
|
+
log.warn(LOG.SESSION, `Failed to get session info`, { sessionId, error: String(e) });
|
|
260
|
+
sessionParentCache.set(sessionId, null);
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
var plugin = async (ctx) => {
|
|
241
265
|
log.info(LOG.HOOK, "Plugin initialized");
|
|
266
|
+
const client = ctx.client;
|
|
242
267
|
return {
|
|
243
268
|
tool: {
|
|
244
269
|
iam: tool({
|
|
@@ -321,8 +346,19 @@ var plugin = async () => {
|
|
|
321
346
|
}
|
|
322
347
|
}
|
|
323
348
|
},
|
|
324
|
-
"experimental.chat.system.transform": async (
|
|
349
|
+
"experimental.chat.system.transform": async (input, output) => {
|
|
350
|
+
const sessionId = input.sessionID;
|
|
351
|
+
if (!sessionId) {
|
|
352
|
+
log.debug(LOG.INJECT, `No sessionID in system.transform input, skipping`);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const parentId = await getParentId(client, sessionId);
|
|
356
|
+
if (!parentId) {
|
|
357
|
+
log.debug(LOG.INJECT, `Skipping system prompt injection for main session (no parentID)`, { sessionId });
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
325
360
|
output.system.push(SYSTEM_PROMPT);
|
|
361
|
+
log.info(LOG.INJECT, `Injected IAM system prompt for child session`, { sessionId, parentId });
|
|
326
362
|
},
|
|
327
363
|
"experimental.chat.messages.transform": async (_input, output) => {
|
|
328
364
|
const lastUserMsg = [...output.messages].reverse().find((m) => m.info.role === "user");
|
|
@@ -333,7 +369,6 @@ var plugin = async () => {
|
|
|
333
369
|
if (unread.length === 0)
|
|
334
370
|
return;
|
|
335
371
|
log.info(LOG.INJECT, `Injecting urgent notification`, { sessionId, unreadCount: unread.length });
|
|
336
|
-
const notification = urgentNotification(unread.length);
|
|
337
372
|
const syntheticMessage = {
|
|
338
373
|
info: {
|
|
339
374
|
id: "msg_iam_" + Date.now(),
|
|
@@ -349,7 +384,7 @@ var plugin = async () => {
|
|
|
349
384
|
sessionID: sessionId,
|
|
350
385
|
messageID: "msg_iam_" + Date.now(),
|
|
351
386
|
type: "text",
|
|
352
|
-
text:
|
|
387
|
+
text: urgentNotification(unread.length)
|
|
353
388
|
}
|
|
354
389
|
]
|
|
355
390
|
};
|
package/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../logger.ts"],"names":[],"mappings":"AA+CA,eAAO,MAAM,GAAG;sBACI,MAAM,WAAW,MAAM,SAAS,OAAO;qBAGxC,MAAM,WAAW,MAAM,SAAS,OAAO;qBAGvC,MAAM,WAAW,MAAM,SAAS,OAAO;sBAGtC,MAAM,WAAW,MAAM,SAAS,OAAO;CAE1D,CAAA;AAGD,eAAO,MAAM,GAAG;;;;;;CAMN,CAAA"}
|