@agentmap/opencode 0.1.0 → 0.3.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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAGjD,eAAO,MAAM,cAAc,EAAE,MAa5B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAmHjD,eAAO,MAAM,cAAc,EAAE,MAwD5B,CAAA"}
package/dist/index.js CHANGED
@@ -1,17 +1,153 @@
1
1
  // @agentmap
2
2
  // OpenCode plugin that injects codebase map into system prompt.
3
- import { generateMapYaml } from 'agentmap';
3
+ import { generateMap, toYaml } from 'agentmap';
4
+ const MAX_DEFS_PER_FILE = 25;
5
+ const MAX_LINES = 1000;
6
+ /**
7
+ * Check if a def value indicates exported or extern
8
+ */
9
+ function isExportedDef(value) {
10
+ return value.includes('exported') || value.includes('extern');
11
+ }
12
+ /**
13
+ * Truncate definitions in a file entry to MAX_DEFS_PER_FILE
14
+ * If file has exported symbols, shows only exports field instead
15
+ * Otherwise uses current truncation behavior
16
+ */
17
+ function truncateDefs(entry) {
18
+ if (!entry.defs)
19
+ return entry;
20
+ const defNames = Object.keys(entry.defs);
21
+ if (defNames.length <= MAX_DEFS_PER_FILE)
22
+ return entry;
23
+ // Filter to only exported/extern definitions
24
+ const exportedNames = defNames.filter(name => isExportedDef(entry.defs[name]));
25
+ // If we have exports, use exports field instead of defs
26
+ if (exportedNames.length > 0) {
27
+ const exports = {};
28
+ const maxExports = Math.min(exportedNames.length, MAX_DEFS_PER_FILE);
29
+ for (let i = 0; i < maxExports; i++) {
30
+ const name = exportedNames[i];
31
+ exports[name] = entry.defs[name];
32
+ }
33
+ // Add marker if exports were also truncated
34
+ if (exportedNames.length > MAX_DEFS_PER_FILE) {
35
+ const remaining = exportedNames.length - MAX_DEFS_PER_FILE;
36
+ exports[`__more_${remaining}__`] = `${remaining} more exports`;
37
+ }
38
+ // Return with exports instead of defs
39
+ const { defs, ...rest } = entry;
40
+ return { ...rest, exports };
41
+ }
42
+ // No exports found - use current truncation behavior
43
+ const truncated = {};
44
+ for (let i = 0; i < MAX_DEFS_PER_FILE; i++) {
45
+ const name = defNames[i];
46
+ truncated[name] = entry.defs[name];
47
+ }
48
+ const remaining = defNames.length - MAX_DEFS_PER_FILE;
49
+ // Add marker that will be converted to comment
50
+ truncated[`__more_${remaining}__`] = `${remaining} more definitions`;
51
+ return { ...entry, defs: truncated };
52
+ }
53
+ /**
54
+ * Check if a value is a FileEntry (has description or defs)
55
+ */
56
+ function isFileEntry(value) {
57
+ if (!value || typeof value !== 'object')
58
+ return false;
59
+ const obj = value;
60
+ return 'description' in obj || 'defs' in obj;
61
+ }
62
+ /**
63
+ * Recursively truncate defs in all files in the map
64
+ */
65
+ function truncateMap(node) {
66
+ const result = {};
67
+ for (const [key, value] of Object.entries(node)) {
68
+ if (isFileEntry(value)) {
69
+ result[key] = truncateDefs(value);
70
+ }
71
+ else if (value && typeof value === 'object') {
72
+ result[key] = truncateMap(value);
73
+ }
74
+ else {
75
+ result[key] = value;
76
+ }
77
+ }
78
+ return result;
79
+ }
80
+ /**
81
+ * Convert __more_N__ markers to YAML comments
82
+ */
83
+ function markersToComments(yaml) {
84
+ // Match lines like: __more_25__: 25 more definitions/exports
85
+ // Replace with: # ... 25 more definitions/exports
86
+ return yaml.replace(/^(\s*)__more_(\d+)__: (\d+ more (?:definitions|exports))$/gm, '$1# ... $3');
87
+ }
88
+ /**
89
+ * Truncate YAML to max lines, adding a comment if truncated
90
+ */
91
+ function truncateLines(yaml) {
92
+ const lines = yaml.split('\n');
93
+ if (lines.length <= MAX_LINES)
94
+ return yaml;
95
+ const truncated = lines.slice(0, MAX_LINES);
96
+ truncated.push('# ... truncated');
97
+ return truncated.join('\n');
98
+ }
4
99
  export const AgentMapPlugin = async ({ directory }) => {
100
+ let cachedYaml;
101
+ let lastSessionID;
5
102
  return {
103
+ 'chat.message': async ({ sessionID }) => {
104
+ if (sessionID !== lastSessionID) {
105
+ lastSessionID = sessionID;
106
+ cachedYaml = undefined;
107
+ }
108
+ },
6
109
  'experimental.chat.system.transform': async (_input, output) => {
7
- const yaml = await generateMapYaml({ dir: directory });
8
- if (!yaml.trim())
9
- return;
10
- output.system.push(`<agentmap>
11
- These are some of the files in the repo with their descriptions and definition locations:
110
+ try {
111
+ // Skip if already has agentmap tag
112
+ if (output.system.some((s) => s.includes('<agentmap>')))
113
+ return;
114
+ if (!cachedYaml) {
115
+ const map = await generateMap({ dir: directory });
116
+ // Check if map is empty
117
+ const rootKey = Object.keys(map)[0];
118
+ const rootValue = map[rootKey];
119
+ if (!rootValue || Object.keys(rootValue).length === 0) {
120
+ cachedYaml = '';
121
+ }
122
+ else {
123
+ const truncatedMap = truncateMap(map);
124
+ let yaml = toYaml(truncatedMap);
125
+ yaml = markersToComments(yaml);
126
+ yaml = truncateLines(yaml);
127
+ cachedYaml = yaml;
128
+ }
129
+ }
130
+ if (!cachedYaml.trim())
131
+ return;
132
+ output.system.push(`
133
+
134
+ <agentmap>
135
+ Tree of the most important files in the repo, showing descriptions and definitions:
136
+
137
+ ${cachedYaml}
138
+ </agentmap>
139
+
140
+ <agentmap-instructions>
141
+ When creating new files, add a brief description comment at the top explaining the file's purpose. This makes the file discoverable in the agentmap.
142
+
143
+ When making significant changes to a file's purpose or responsibilities, update its header comment to reflect the changes.
12
144
 
13
- ${yaml}
14
- </agentmap>`);
145
+ These descriptions appear in the agentmap XML at the start of every agent session.
146
+ </agentmap-instructions>`);
147
+ }
148
+ catch (err) {
149
+ console.error('[agentmap] Failed to generate map:', err);
150
+ }
15
151
  },
16
152
  };
17
153
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,gEAAgE;AAGhE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE1C,MAAM,CAAC,MAAM,cAAc,GAAW,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE;IAC5D,OAAO;QACL,oCAAoC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YAC7D,MAAM,IAAI,GAAG,MAAM,eAAe,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAA;YACtD,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;gBAAE,OAAM;YAExB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;;;EAGvB,IAAI;YACM,CAAC,CAAA;QACT,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,gEAAgE;AAGhE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAG9C,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAC5B,MAAM,SAAS,GAAG,IAAI,CAAA;AAEtB;;GAEG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,OAAO,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;AAC/D,CAAC;AAED;;;;GAIG;AACH,SAAS,YAAY,CAAC,KAAgB;IACpC,IAAI,CAAC,KAAK,CAAC,IAAI;QAAE,OAAO,KAAK,CAAA;IAE7B,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACxC,IAAI,QAAQ,CAAC,MAAM,IAAI,iBAAiB;QAAE,OAAO,KAAK,CAAA;IAEtD,6CAA6C;IAC7C,MAAM,aAAa,GAAG,QAAQ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AAE,CAAC;wBACtD,UAAU,GAAG,EAAE,CAAA;oBACjB,CAAC;yBAAM,CAAC;wBACN,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;wBACrC,IAAI,IAAI,GAAG,MAAM,CAAC,YAAY,CAAC,CAAA;wBAC/B,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAA;wBAC9B,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;wBAC1B,UAAU,GAAG,IAAI,CAAA;oBACnB,CAAC;gBACH,CAAC;gBAED,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;oBAAE,OAAM;gBAE9B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;;;;;EAKzB,UAAU;;;;;;;;;yBASa,CAAC,CAAA;YACpB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,GAAG,CAAC,CAAA;YAC1D,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentmap/opencode",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "OpenCode plugin that injects agentmap codebase map into system prompt",
5
5
  "type": "module",
6
6
  "repository": {
@@ -24,10 +24,11 @@
24
24
  "dist"
25
25
  ],
26
26
  "scripts": {
27
- "build": "tsc"
27
+ "build": "tsc",
28
+ "prepublishOnly": "bun run build"
28
29
  },
29
30
  "dependencies": {
30
- "agentmap": "0.2.0"
31
+ "agentmap": "0.5.0"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@opencode-ai/plugin": "^1.0.224",