@wrongstack/tools 0.89.1 → 0.104.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/dist/audit.js +1 -7
- package/dist/audit.js.map +1 -1
- package/dist/{background-indexer-DYm1FUxK.d.ts → background-indexer-C2014mH0.d.ts} +1 -1
- package/dist/bash.js +6 -18
- package/dist/bash.js.map +1 -1
- package/dist/builtin.js +187 -133
- package/dist/builtin.js.map +1 -1
- package/dist/circuit-breaker.js +1 -1
- package/dist/circuit-breaker.js.map +1 -1
- package/dist/codebase-index/index.d.ts +2 -21
- package/dist/codebase-index/index.js +25 -69
- package/dist/codebase-index/index.js.map +1 -1
- package/dist/diff.js.map +1 -1
- package/dist/document.js +1 -1
- package/dist/document.js.map +1 -1
- package/dist/edit.js.map +1 -1
- package/dist/exec.js +3 -15
- package/dist/exec.js.map +1 -1
- package/dist/fetch.js.map +1 -1
- package/dist/format.js +4 -16
- package/dist/format.js.map +1 -1
- package/dist/git.js +1 -7
- package/dist/git.js.map +1 -1
- package/dist/glob.js.map +1 -1
- package/dist/grep.js +1 -7
- package/dist/grep.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +301 -136
- package/dist/index.js.map +1 -1
- package/dist/install.js +4 -16
- package/dist/install.js.map +1 -1
- package/dist/lint.js +4 -16
- package/dist/lint.js.map +1 -1
- package/dist/logs.js.map +1 -1
- package/dist/memory.d.ts +29 -1
- package/dist/memory.js +115 -4
- package/dist/memory.js.map +1 -1
- package/dist/outdated.js.map +1 -1
- package/dist/pack.js +187 -133
- package/dist/pack.js.map +1 -1
- package/dist/patch.js.map +1 -1
- package/dist/process-registry.js +2 -7
- package/dist/process-registry.js.map +1 -1
- package/dist/read.js +1 -1
- package/dist/read.js.map +1 -1
- package/dist/replace.js +1 -7
- package/dist/replace.js.map +1 -1
- package/dist/scaffold.js.map +1 -1
- package/dist/search.js +2 -7
- package/dist/search.js.map +1 -1
- package/dist/test.js +4 -16
- package/dist/test.js.map +1 -1
- package/dist/tree.js +1 -7
- package/dist/tree.js.map +1 -1
- package/dist/typecheck.js +4 -16
- package/dist/typecheck.js.map +1 -1
- package/dist/write.js.map +1 -1
- package/package.json +2 -2
package/dist/memory.js
CHANGED
|
@@ -3,8 +3,8 @@ function rememberTool(memory) {
|
|
|
3
3
|
return {
|
|
4
4
|
name: "remember",
|
|
5
5
|
category: "Session",
|
|
6
|
-
description: "Persist
|
|
7
|
-
usageHint:
|
|
6
|
+
description: "Persist facts, conventions, decisions, and preferences into long-term memory. Memories survive restarts and are scored for relevance in future sessions.",
|
|
7
|
+
usageHint: "Persist facts, conventions, decisions, and preferences into long-term memory.\n\nWHEN TO USE:\n- Project conventions discovered during a task (build tool, lint rules, code style)\n- Architecture decisions made (chose X over Y, decided to use pattern Z)\n- User preferences expressed (prefers short names, always uses pnpm)\n- Anti-patterns identified (never do X, avoid pattern Y)\n- File/location references useful across sessions\n\nWHEN NOT TO USE:\n- Temporary task state or progress \u2192 use `todo`\n- One-off debugging notes\n- Information already obvious from the codebase\n\nAlways include `type` and `priority`. Use 1-3 `tags` for grouping.\nBetter to remember a fact now than rediscover it next session.",
|
|
8
8
|
permission: "auto",
|
|
9
9
|
mutating: true,
|
|
10
10
|
timeoutMs: 2e3,
|
|
@@ -19,6 +19,21 @@ function rememberTool(memory) {
|
|
|
19
19
|
type: "string",
|
|
20
20
|
enum: ["project-agents", "project-memory", "user-memory"],
|
|
21
21
|
description: "Where to store it: project-memory (shared), user-memory (personal), or project-agents."
|
|
22
|
+
},
|
|
23
|
+
type: {
|
|
24
|
+
type: "string",
|
|
25
|
+
enum: ["fact", "decision", "convention", "preference", "reference", "anti_pattern"],
|
|
26
|
+
description: "Category for filtering and relevance scoring."
|
|
27
|
+
},
|
|
28
|
+
tags: {
|
|
29
|
+
type: "array",
|
|
30
|
+
items: { type: "string" },
|
|
31
|
+
description: "Hashtag-style tags for grouping and search."
|
|
32
|
+
},
|
|
33
|
+
priority: {
|
|
34
|
+
type: "string",
|
|
35
|
+
enum: ["critical", "high", "medium", "low"],
|
|
36
|
+
description: "Priority level. Critical = always injected into context."
|
|
22
37
|
}
|
|
23
38
|
},
|
|
24
39
|
required: ["text"]
|
|
@@ -26,7 +41,11 @@ function rememberTool(memory) {
|
|
|
26
41
|
async execute(input) {
|
|
27
42
|
if (!input?.text) throw new Error("remember: text is required");
|
|
28
43
|
const scope = input.scope ?? "project-memory";
|
|
29
|
-
await memory.remember(input.text, scope
|
|
44
|
+
await memory.remember(input.text, scope, {
|
|
45
|
+
type: input.type,
|
|
46
|
+
tags: input.tags,
|
|
47
|
+
priority: input.priority
|
|
48
|
+
});
|
|
30
49
|
return { ok: true, scope };
|
|
31
50
|
}
|
|
32
51
|
};
|
|
@@ -56,7 +75,99 @@ function forgetTool(memory) {
|
|
|
56
75
|
}
|
|
57
76
|
};
|
|
58
77
|
}
|
|
78
|
+
function searchMemoryTool(memory) {
|
|
79
|
+
return {
|
|
80
|
+
name: "search_memory",
|
|
81
|
+
category: "Session",
|
|
82
|
+
description: "Search memory entries by content. With the default backend this does substring matching; semantic/graph backends use embedding similarity or graph traversal.",
|
|
83
|
+
usageHint: "Search long-term memory for relevant facts, conventions, or decisions.\n- Returns results ordered by relevance (newest-first for default, similarity for semantic).\n- Use before starting a task to recall project conventions and past decisions.\n- `limit` caps results (default 5, max 20).",
|
|
84
|
+
permission: "auto",
|
|
85
|
+
mutating: false,
|
|
86
|
+
timeoutMs: 2e3,
|
|
87
|
+
inputSchema: {
|
|
88
|
+
type: "object",
|
|
89
|
+
properties: {
|
|
90
|
+
query: {
|
|
91
|
+
type: "string",
|
|
92
|
+
description: "Search query \u2014 words or phrase to find in memory."
|
|
93
|
+
},
|
|
94
|
+
scope: {
|
|
95
|
+
type: "string",
|
|
96
|
+
enum: ["project-agents", "project-memory", "user-memory"],
|
|
97
|
+
description: "Which scope to search. Defaults to project-memory."
|
|
98
|
+
},
|
|
99
|
+
limit: {
|
|
100
|
+
type: "number",
|
|
101
|
+
description: "Maximum results to return (default 5, max 20)."
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
required: ["query"]
|
|
105
|
+
},
|
|
106
|
+
async execute(input) {
|
|
107
|
+
if (!input?.query) throw new Error("search_memory: query is required");
|
|
108
|
+
const scope = input.scope ?? "project-memory";
|
|
109
|
+
const limit = Math.min(input.limit ?? 5, 20);
|
|
110
|
+
const entries = await memory.search(input.query, scope, limit);
|
|
111
|
+
return {
|
|
112
|
+
results: entries.map((e) => ({
|
|
113
|
+
text: e.text,
|
|
114
|
+
ts: e.ts,
|
|
115
|
+
scope: e.scope,
|
|
116
|
+
type: e.type,
|
|
117
|
+
tags: e.tags,
|
|
118
|
+
priority: e.priority
|
|
119
|
+
}))
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function relatedMemoryTool(memory) {
|
|
125
|
+
return {
|
|
126
|
+
name: "find_related_memories",
|
|
127
|
+
category: "Session",
|
|
128
|
+
description: "Find memories related to the given text via graph traversal. Only available with graph backends; falls back to content search with file backends.",
|
|
129
|
+
usageHint: "Discover memories connected to a topic through co-occurrence or similarity edges.\n- Useful for exploring what else the project knows about a given concept.\n- Falls back to content search when no graph backend is configured.\n- `limit` caps results (default 5, max 20).",
|
|
130
|
+
permission: "auto",
|
|
131
|
+
mutating: false,
|
|
132
|
+
timeoutMs: 2e3,
|
|
133
|
+
inputSchema: {
|
|
134
|
+
type: "object",
|
|
135
|
+
properties: {
|
|
136
|
+
text: {
|
|
137
|
+
type: "string",
|
|
138
|
+
description: "Text to find related memories for."
|
|
139
|
+
},
|
|
140
|
+
scope: {
|
|
141
|
+
type: "string",
|
|
142
|
+
enum: ["project-agents", "project-memory", "user-memory"],
|
|
143
|
+
description: "Which scope to search. Defaults to project-memory."
|
|
144
|
+
},
|
|
145
|
+
limit: {
|
|
146
|
+
type: "number",
|
|
147
|
+
description: "Maximum results to return (default 5, max 20)."
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
required: ["text"]
|
|
151
|
+
},
|
|
152
|
+
async execute(input) {
|
|
153
|
+
if (!input?.text) throw new Error("find_related_memories: text is required");
|
|
154
|
+
const scope = input.scope ?? "project-memory";
|
|
155
|
+
const limit = Math.min(input.limit ?? 5, 20);
|
|
156
|
+
const entries = memory.findRelated ? await memory.findRelated(input.text, scope, limit) : await memory.search(input.text, scope, limit);
|
|
157
|
+
return {
|
|
158
|
+
results: entries.map((e) => ({
|
|
159
|
+
text: e.text,
|
|
160
|
+
ts: e.ts,
|
|
161
|
+
scope: e.scope,
|
|
162
|
+
type: e.type,
|
|
163
|
+
tags: e.tags,
|
|
164
|
+
priority: e.priority
|
|
165
|
+
}))
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
59
170
|
|
|
60
|
-
export { forgetTool, rememberTool };
|
|
171
|
+
export { forgetTool, relatedMemoryTool, rememberTool, searchMemoryTool };
|
|
61
172
|
//# sourceMappingURL=memory.js.map
|
|
62
173
|
//# sourceMappingURL=memory.js.map
|
package/dist/memory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/memory.ts"],"names":[],"mappings":";AAsBO,SAAS,aAAa,MAAA,EAA0D;AACrF,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,UAAA;AAAA,IACN,QAAA,EAAU,SAAA;AAAA,IACV,WAAA,EACE,mJAAA;AAAA,IACF,SAAA,EACE,oeAAA;AAAA,IAMF,UAAA,EAAY,MAAA;AAAA,IACZ,QAAA,EAAU,IAAA;AAAA,IACV,SAAA,EAAW,GAAA;AAAA,IACX,WAAA,EAAa;AAAA,MACX,IAAA,EAAM,QAAA;AAAA,MACN,UAAA,EAAY;AAAA,QACV,IAAA,EAAM;AAAA,UACJ,IAAA,EAAM,QAAA;AAAA,UACN,WAAA,EAAa;AAAA,SACf;AAAA,QACA,KAAA,EAAO;AAAA,UACL,IAAA,EAAM,QAAA;AAA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,MAAM,UAAU,MAAM,MAAA,CAAO,MAAA,CAAO,KAAA,CAAM,OAAO,KAAK,CAAA;AACtD,MAAA,OAAO,EAAE,SAAS,KAAA,EAAM;AAAA,IAC1B;AAAA,GACF;AACF","file":"memory.js","sourcesContent":["import type { MemoryScope, MemoryStore, Tool } from '@wrongstack/core';\n\ninterface RememberInput {\n text: string;\n scope?: MemoryScope | undefined;\n}\n\ninterface RememberOutput {\n ok: true;\n scope: MemoryScope;\n}\n\ninterface ForgetInput {\n query: string;\n scope?: MemoryScope | undefined;\n}\n\ninterface ForgetOutput {\n removed: number;\n scope: MemoryScope;\n}\n\nexport function rememberTool(memory: MemoryStore): Tool<RememberInput, RememberOutput> {\n return {\n name: 'remember',\n category: 'Session',\n description:\n 'Persist important long-term facts into project or user memory. These memories survive conversation restarts and are available to future sessions.',\n usageHint:\n 'USE VERY SPARINGLY — ONLY FOR HIGH-VALUE RECURRING KNOWLEDGE:\\n\\n' +\n '- Good: coding standards, project conventions, user preferences, recurring architecture decisions, important facts.\\n' +\n '- Bad: temporary state, current task progress, one-off notes → use `todo` or `plan` instead.\\n' +\n '- `scope: \"project\"` → visible to all agents on this codebase.\\n' +\n '- `scope: \"user\"` → personal to you.\\n\\n' +\n 'Polluting memory with noise hurts future context quality. Be extremely deliberate.',\n permission: 'auto',\n mutating: true,\n timeoutMs: 2_000,\n inputSchema: {\n type: 'object',\n properties: {\n text: {\n type: 'string',\n description: 'The fact or note to remember. Keep it concise and factual.',\n },\n scope: {\n type: 'string',\n enum: ['project-agents', 'project-memory', 'user-memory'],\n description: 'Where to store it: project-memory (shared), user-memory (personal), or project-agents.',\n },\n },\n required: ['text'],\n },\n async execute(input) {\n if (!input?.text) throw new Error('remember: text is required');\n const scope = input.scope ?? 'project-memory';\n await memory.remember(input.text, scope);\n return { ok: true, scope };\n },\n };\n}\n\nexport function forgetTool(memory: MemoryStore): Tool<ForgetInput, ForgetOutput> {\n return {\n name: 'forget',\n category: 'Session',\n description: 'Remove memory entries that contain the given substring (case-insensitive). Use with caution.',\n usageHint:\n 'This permanently deletes matching memories in the chosen scope.\\n' +\n '- Provide a reasonably specific `query` to avoid deleting unrelated memories.\\n' +\n '- Always double-check before calling with broad queries.\\n' +\n '- Use `remember` + `forget` together to maintain clean long-term memory.',\n permission: 'confirm',\n mutating: true,\n timeoutMs: 2_000,\n inputSchema: {\n type: 'object',\n properties: {\n query: { type: 'string' },\n scope: { type: 'string', enum: ['project-agents', 'project-memory', 'user-memory'] },\n },\n required: ['query'],\n },\n async execute(input) {\n if (!input?.query) throw new Error('forget: query is required');\n const scope = input.scope ?? 'project-memory';\n const removed = await memory.forget(input.query, scope);\n return { removed, scope };\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/memory.ts"],"names":[],"mappings":";AA6BO,SAAS,aAAa,MAAA,EAA0D;AACrF,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,UAAA;AAAA,IACN,QAAA,EAAU,SAAA;AAAA,IACV,WAAA,EACE,0JAAA;AAAA,IACF,SAAA,EACE,6sBAAA;AAAA,IAaF,UAAA,EAAY,MAAA;AAAA,IACZ,QAAA,EAAU,IAAA;AAAA,IACV,SAAA,EAAW,GAAA;AAAA,IACX,WAAA,EAAa;AAAA,MACX,IAAA,EAAM,QAAA;AAAA,MACN,UAAA,EAAY;AAAA,QACV,IAAA,EAAM;AAAA,UACJ,IAAA,EAAM,QAAA;AAAA,UACN,WAAA,EAAa;AAAA,SACf;AAAA,QACA,KAAA,EAAO;AAAA,UACL,IAAA,EAAM,QAAA;AAAA,UACN,IAAA,EAAM,CAAC,gBAAA,EAAkB,gBAAA,EAAkB,aAAa,CAAA;AAAA,UACxD,WAAA,EAAa;AAAA,SACf;AAAA,QACA,IAAA,EAAM;AAAA,UACJ,IAAA,EAAM,QAAA;AAAA,UACN,MAAM,CAAC,MAAA,EAAQ,YAAY,YAAA,EAAc,YAAA,EAAc,aAAa,cAAc,CAAA;AAAA,UAClF,WAAA,EAAa;AAAA,SACf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,KAAA,EAAO;AAAA,UACL,IAAA,EAAM,QAAA;AAAA,UACN,WAAA,EAAa;AAAA;AACf,OACF;AAAA,MACA,QAAA,EAAU,CAAC,MAAM;AAAA,KACnB;AAAA,IACA,MAAM,QAAQ,KAAA,EAAO;AACnB,MAAA,IAAI,CAAC,KAAA,EAAO,IAAA,EAAM,MAAM,IAAI,MAAM,yCAAyC,CAAA;AAC3E,MAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,IAAS,gBAAA;AAC7B,MAAA,MAAM,QAAQ,IAAA,CAAK,GAAA,CAAI,KAAA,CAAM,KAAA,IAAS,GAAG,EAAE,CAAA;AAC3C,MAAA,MAAM,UAAU,MAAA,CAAO,WAAA,GACnB,MAAM,MAAA,CAAO,YAAY,KAAA,CAAM,IAAA,EAAM,KAAA,EAAO,KAAK,IACjD,MAAM,MAAA,CAAO,OAAO,KAAA,CAAM,IAAA,EAAM,OAAO,KAAK,CAAA;AAChD,MAAA,OAAO;AAAA,QACL,OAAA,EAAS,OAAA,CAAQ,GAAA,CAAI,CAAC,CAAA,MAAoB;AAAA,UACxC,MAAM,CAAA,CAAE,IAAA;AAAA,UACR,IAAI,CAAA,CAAE,EAAA;AAAA,UACN,OAAO,CAAA,CAAE,KAAA;AAAA,UACT,MAAM,CAAA,CAAE,IAAA;AAAA,UACR,MAAM,CAAA,CAAE,IAAA;AAAA,UACR,UAAU,CAAA,CAAE;AAAA,SACd,CAAE;AAAA,OACJ;AAAA,IACF;AAAA,GACF;AACF","file":"memory.js","sourcesContent":["import type { MemoryScope, MemoryStore, Tool } from '@wrongstack/core';\nimport type { MemoryEntry } from '@wrongstack/core';\n\ninterface RememberInput {\n text: string;\n scope?: MemoryScope | undefined;\n /** Memory type for categorization. */\n type?: 'fact' | 'decision' | 'convention' | 'preference' | 'reference' | 'anti_pattern' | undefined;\n /** Hashtag-style tags for grouping and search. */\n tags?: string[] | undefined;\n /** Priority level — critical entries always injected into context. */\n priority?: 'critical' | 'high' | 'medium' | 'low' | undefined;\n}\n\ninterface RememberOutput {\n ok: true;\n scope: MemoryScope;\n}\n\ninterface ForgetInput {\n query: string;\n scope?: MemoryScope | undefined;\n}\n\ninterface ForgetOutput {\n removed: number;\n scope: MemoryScope;\n}\n\nexport function rememberTool(memory: MemoryStore): Tool<RememberInput, RememberOutput> {\n return {\n name: 'remember',\n category: 'Session',\n description:\n 'Persist facts, conventions, decisions, and preferences into long-term memory. Memories survive restarts and are scored for relevance in future sessions.',\n usageHint:\n 'Persist facts, conventions, decisions, and preferences into long-term memory.\\n\\n' +\n 'WHEN TO USE:\\n' +\n '- Project conventions discovered during a task (build tool, lint rules, code style)\\n' +\n '- Architecture decisions made (chose X over Y, decided to use pattern Z)\\n' +\n '- User preferences expressed (prefers short names, always uses pnpm)\\n' +\n '- Anti-patterns identified (never do X, avoid pattern Y)\\n' +\n '- File/location references useful across sessions\\n\\n' +\n 'WHEN NOT TO USE:\\n' +\n '- Temporary task state or progress → use `todo`\\n' +\n '- One-off debugging notes\\n' +\n '- Information already obvious from the codebase\\n\\n' +\n 'Always include `type` and `priority`. Use 1-3 `tags` for grouping.\\n' +\n 'Better to remember a fact now than rediscover it next session.',\n permission: 'auto',\n mutating: true,\n timeoutMs: 2_000,\n inputSchema: {\n type: 'object',\n properties: {\n text: {\n type: 'string',\n description: 'The fact or note to remember. Keep it concise and factual.',\n },\n scope: {\n type: 'string',\n enum: ['project-agents', 'project-memory', 'user-memory'],\n description: 'Where to store it: project-memory (shared), user-memory (personal), or project-agents.',\n },\n type: {\n type: 'string',\n enum: ['fact', 'decision', 'convention', 'preference', 'reference', 'anti_pattern'],\n description: 'Category for filtering and relevance scoring.',\n },\n tags: {\n type: 'array',\n items: { type: 'string' },\n description: 'Hashtag-style tags for grouping and search.',\n },\n priority: {\n type: 'string',\n enum: ['critical', 'high', 'medium', 'low'],\n description: 'Priority level. Critical = always injected into context.',\n },\n },\n required: ['text'],\n },\n async execute(input) {\n if (!input?.text) throw new Error('remember: text is required');\n const scope = input.scope ?? 'project-memory';\n await memory.remember(input.text, scope, {\n type: input.type,\n tags: input.tags,\n priority: input.priority,\n });\n return { ok: true, scope };\n },\n };\n}\n\nexport function forgetTool(memory: MemoryStore): Tool<ForgetInput, ForgetOutput> {\n return {\n name: 'forget',\n category: 'Session',\n description: 'Remove memory entries that contain the given substring (case-insensitive). Use with caution.',\n usageHint:\n 'This permanently deletes matching memories in the chosen scope.\\n' +\n '- Provide a reasonably specific `query` to avoid deleting unrelated memories.\\n' +\n '- Always double-check before calling with broad queries.\\n' +\n '- Use `remember` + `forget` together to maintain clean long-term memory.',\n permission: 'confirm',\n mutating: true,\n timeoutMs: 2_000,\n inputSchema: {\n type: 'object',\n properties: {\n query: { type: 'string' },\n scope: { type: 'string', enum: ['project-agents', 'project-memory', 'user-memory'] },\n },\n required: ['query'],\n },\n async execute(input) {\n if (!input?.query) throw new Error('forget: query is required');\n const scope = input.scope ?? 'project-memory';\n const removed = await memory.forget(input.query, scope);\n return { removed, scope };\n },\n };\n}\n\n// ── Enhanced memory query tools — use backend capabilities ───────────\n\ninterface SearchMemoryInput {\n query: string;\n scope?: MemoryScope | undefined;\n limit?: number | undefined;\n}\n\ninterface SearchMemoryOutput {\n results: Array<{\n text: string;\n ts: string;\n scope: MemoryScope;\n type?: string | undefined;\n tags?: string[] | undefined;\n priority?: string | undefined;\n }>;\n}\n\nexport function searchMemoryTool(memory: MemoryStore): Tool<SearchMemoryInput, SearchMemoryOutput> {\n return {\n name: 'search_memory',\n category: 'Session',\n description:\n 'Search memory entries by content. With the default backend this does substring matching; semantic/graph backends use embedding similarity or graph traversal.',\n usageHint:\n 'Search long-term memory for relevant facts, conventions, or decisions.\\n' +\n '- Returns results ordered by relevance (newest-first for default, similarity for semantic).\\n' +\n '- Use before starting a task to recall project conventions and past decisions.\\n' +\n '- `limit` caps results (default 5, max 20).',\n permission: 'auto',\n mutating: false,\n timeoutMs: 2_000,\n inputSchema: {\n type: 'object',\n properties: {\n query: {\n type: 'string',\n description: 'Search query — words or phrase to find in memory.',\n },\n scope: {\n type: 'string',\n enum: ['project-agents', 'project-memory', 'user-memory'],\n description: 'Which scope to search. Defaults to project-memory.',\n },\n limit: {\n type: 'number',\n description: 'Maximum results to return (default 5, max 20).',\n },\n },\n required: ['query'],\n },\n async execute(input) {\n if (!input?.query) throw new Error('search_memory: query is required');\n const scope = input.scope ?? 'project-memory';\n const limit = Math.min(input.limit ?? 5, 20);\n const entries = await memory.search(input.query, scope, limit);\n return {\n results: entries.map((e: MemoryEntry) => ({\n text: e.text,\n ts: e.ts,\n scope: e.scope,\n type: e.type,\n tags: e.tags,\n priority: e.priority,\n })),\n };\n },\n };\n}\n\ninterface RelatedMemoryInput {\n text: string;\n scope?: MemoryScope | undefined;\n limit?: number | undefined;\n}\n\nexport function relatedMemoryTool(memory: MemoryStore): Tool<RelatedMemoryInput, SearchMemoryOutput> {\n return {\n name: 'find_related_memories',\n category: 'Session',\n description:\n 'Find memories related to the given text via graph traversal. Only available with graph backends; falls back to content search with file backends.',\n usageHint:\n 'Discover memories connected to a topic through co-occurrence or similarity edges.\\n' +\n '- Useful for exploring what else the project knows about a given concept.\\n' +\n '- Falls back to content search when no graph backend is configured.\\n' +\n '- `limit` caps results (default 5, max 20).',\n permission: 'auto',\n mutating: false,\n timeoutMs: 2_000,\n inputSchema: {\n type: 'object',\n properties: {\n text: {\n type: 'string',\n description: 'Text to find related memories for.',\n },\n scope: {\n type: 'string',\n enum: ['project-agents', 'project-memory', 'user-memory'],\n description: 'Which scope to search. Defaults to project-memory.',\n },\n limit: {\n type: 'number',\n description: 'Maximum results to return (default 5, max 20).',\n },\n },\n required: ['text'],\n },\n async execute(input) {\n if (!input?.text) throw new Error('find_related_memories: text is required');\n const scope = input.scope ?? 'project-memory';\n const limit = Math.min(input.limit ?? 5, 20);\n const entries = memory.findRelated\n ? await memory.findRelated(input.text, scope, limit)\n : await memory.search(input.text, scope, limit);\n return {\n results: entries.map((e: MemoryEntry) => ({\n text: e.text,\n ts: e.ts,\n scope: e.scope,\n type: e.type,\n tags: e.tags,\n priority: e.priority,\n })),\n };\n },\n };\n}\n"]}
|
package/dist/outdated.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/_util.ts","../src/outdated.ts"],"names":["resolve"],"mappings":";;;;;AAuBA,eAAsB,qBAAqB,GAAA,EAAsC;AAC/E,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,OAAO,kBAAkB,CAAA;AAChD,EAAA,IAAI;AACF,IAAA,MAAM,IAAA,CAAK,CAAA,EAAG,GAAG,CAAA,eAAA,CAAiB,CAAA;AAClC,IAAA,OAAO,MAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AAAA,EAER;AACA,EAAA,IAAI;AACF,IAAA,MAAM,IAAA,CAAK,CAAA,EAAG,GAAG,CAAA,UAAA,CAAY,CAAA;AAC7B,IAAA,OAAO,MAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AAAA,EAER;AACA,EAAA,OAAO,KAAA;AACT;AAEO,SAAS,WAAA,CAAY,OAAe,GAAA,EAAsB;AAC/D,EAAA,OAAY,IAAA,CAAA,UAAA,CAAW,KAAK,CAAA,GAAS,IAAA,CAAA,SAAA,CAAU,KAAK,CAAA,GAAS,IAAA,CAAA,OAAA,CAAQ,GAAA,CAAI,GAAA,EAAK,KAAK,CAAA;AACrF;AAEO,SAAS,gBAAA,CAAiB,SAAiB,GAAA,EAAsB;AACtE,EAAA,MAAM,IAAA,GAAY,IAAA,CAAA,OAAA,CAAQ,GAAA,CAAI,WAAW,CAAA;AACzC,EAAA,MAAM,MAAA,GAAc,aAAQ,OAAO,CAAA;AACnC,EAAA,MAAM,GAAA,GAAW,IAAA,CAAA,QAAA,CAAS,IAAA,EAAM,MAAM,CAAA;AACtC,EAAA,IAAI,IAAI,UAAA,CAAW,IAAI,CAAA,IAAU,IAAA,CAAA,UAAA,CAAW,GAAG,CAAA,EAAG;AAChD,IAAA,MAAM,IAAI,KAAA,CAAM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F,CAAA,CAAA,MAAQ;AAAA,EAER;AAEA,EAAA,OAAO;AAAA,IACL,SAAA,EAAW,QAAA;AAAA,IACX,QAAA;AAAA,IACA,OAAO,QAAA,CAAS,MAAA;AAAA,IAChB,MAAA,EAAQ,IAAA;AAAA,IACR,SAAA,EAAW,KAAK,MAAA,IAAU;AAAA,GAC5B;AACF","file":"outdated.js","sourcesContent":["import * as fsp from 'node:fs/promises';\nimport * as path from 'node:path';\nimport * as Core from '@wrongstack/core';\nimport type { Context } from '@wrongstack/core';\n\n\n\nfunction expectDefined<T>(value: T | null | undefined): T {\n if (value === null || value === undefined) {\n throw new Error('Expected value to be defined');\n }\n return value;\n}\n\n/** Detected package manager for a project directory. */\nexport type PackageManager = 'pnpm' | 'yarn' | 'npm';\n\n/**\n * Detect the project's package manager by inspecting lockfiles in `cwd`.\n * Order: pnpm → yarn → npm (default). Missing or unreadable directories fall\n * back to `npm` rather than throwing, so a `safeResolve`-checked cwd that\n * happens to be empty never aborts the tool.\n */\nexport async function detectPackageManager(cwd: string): Promise<PackageManager> {\n const { stat } = await import('node:fs/promises');\n try {\n await stat(`${cwd}/pnpm-lock.yaml`);\n return 'pnpm';\n } catch {\n /* not pnpm */\n }\n try {\n await stat(`${cwd}/yarn.lock`);\n return 'yarn';\n } catch {\n /* not yarn */\n }\n return 'npm';\n}\n\nexport function resolvePath(input: string, ctx: Context): string {\n return path.isAbsolute(input) ? path.normalize(input) : path.resolve(ctx.cwd, input);\n}\n\nexport function ensureInsideRoot(absPath: string, ctx: Context): string {\n const root = path.resolve(ctx.projectRoot);\n const target = path.resolve(absPath);\n const rel = path.relative(root, target);\n if (rel.startsWith('..') || path.isAbsolute(rel)) {\n throw new Error(`Path \"${absPath}\" is outside project root \"${root}\"`);\n }\n return target;\n}\n\nexport function safeResolve(input: string, ctx: Context): string {\n return ensureInsideRoot(resolvePath(input, ctx), ctx);\n}\n\n/**\n * Defense against in-root→out-of-root symlink escape (CWE-59). `safeResolve`\n * only does a syntactic `../` check, so a symlink that lives *inside* the\n * project root but points outside still passes it. This resolves the path\n * through `fs.realpath` and re-verifies containment against the realpath of\n * the project root (comparing like-for-like, since the root itself may be a\n * symlink — macOS `/var`→`/private/var`, Windows 8.3 short names). For a path\n * that does not exist yet (e.g. a `write` to a new file) the nearest existing\n * ancestor directory is checked instead. Throws if the real target escapes.\n *\n * Mirrors the per-file guard already used in `replace.ts`/`grep.ts`; applied\n * to single-file `read`/`edit`/`write` it throws (rather than skips) because\n * the caller named exactly one file.\n */\nexport async function assertRealInsideRoot(absPath: string, ctx: Context): Promise<void> {\n const realRoot = await fsp.realpath(ctx.projectRoot).catch(() => path.resolve(ctx.projectRoot));\n let probe = absPath;\n for (;;) {\n let real: string;\n try {\n real = await fsp.realpath(probe);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n const parent = path.dirname(probe);\n if (parent === probe) return; // reached fs root without escaping\n probe = parent;\n continue;\n }\n throw err;\n }\n const rel = path.relative(realRoot, real);\n if (rel.startsWith('..') || path.isAbsolute(rel)) {\n throw new Error(\n `Path \"${absPath}\" resolves through a symlink outside project root \"${realRoot}\"`,\n );\n }\n return;\n }\n}\n\n/** `safeResolve` + symlink realpath containment check. Async. */\nexport async function safeResolveReal(input: string, ctx: Context): Promise<string> {\n const abs = safeResolve(input, ctx);\n await assertRealInsideRoot(abs, ctx);\n return abs;\n}\n\nexport function truncateMiddle(s: string, max: number): string {\n if (Buffer.byteLength(s, 'utf8') <= max) return s;\n const half = Math.floor(max / 2);\n return (\n s.slice(0, half) +\n `\\n…[truncated ${Buffer.byteLength(s, 'utf8') - max} bytes from middle]…\\n` +\n s.slice(-half)\n );\n}\n\nexport function isBinaryBuffer(buf: Buffer): boolean {\n const len = Math.min(buf.length, 8192);\n for (let i = 0; i < len; i++) {\n if (buf[i] === 0) return true;\n }\n return false;\n}\n\n// ─── Command-output normalization (token-saving) ────────────────────────────\n//\n// Raw process output is full of tokens the model gains nothing from: ANSI\n// escapes, carriage-return progress spam, runs of identical warning lines, and\n// huge tails of build noise. These helpers strip that noise before the output\n// reaches the LLM. They are scoped to COMMAND tools (bash/git/exec and the\n// _spawn-stream consumers) — never applied to structured/code outputs.\n\n/** Unified byte cap for all command tool output fed to the model. */\nexport const COMMAND_OUTPUT_MAX_BYTES = 32_768;\n\n/** Runs of >= this many identical consecutive lines are collapsed. */\nconst REPEAT_RUN_THRESHOLD = 3;\n\n/**\n * Collapse carriage-return overwrites the way a terminal would: `\\r\\n` becomes\n * `\\n`, and a bare `\\r` (progress redraw) keeps only the text after the LAST\n * `\\r` on its physical line. Without this, a single progress bar that redraws\n * 200 times explodes into 200 lines.\n */\nexport function collapseCarriageReturns(text: string): string {\n const lf = text.replace(/\\r\\n/g, '\\n');\n if (!lf.includes('\\r')) return lf;\n return lf\n .split('\\n')\n .map((line) => (line.includes('\\r') ? line.slice(line.lastIndexOf('\\r') + 1) : line))\n .join('\\n');\n}\n\n/**\n * Collapse a run of `minRun`+ identical consecutive lines into the line once\n * plus a marker. Consecutive-only — it never reorders or dedups non-adjacent\n * lines, so diffs/source stay intact.\n */\nexport function collapseConsecutiveDuplicates(text: string, minRun = REPEAT_RUN_THRESHOLD): string {\n const lines = text.split('\\n');\n const out: string[] = [];\n let i = 0;\n while (i < lines.length) {\n let j = i + 1;\n while (j < lines.length && lines[j] === lines[i]) j++;\n const run = j - i;\n if (run >= minRun) {\n out.push(expectDefined(lines[i]), `… ⟨repeated ${run}×⟩`);\n } else {\n for (let k = i; k < j; k++) out.push(expectDefined(lines[k]));\n }\n i = j;\n }\n return out.join('\\n');\n}\n\n/** Largest prefix of `s` whose UTF-8 byte length is <= `maxBytes`. */\nfunction takeHeadBytes(s: string, maxBytes: number): string {\n if (maxBytes <= 0) return '';\n if (Buffer.byteLength(s, 'utf8') <= maxBytes) return s;\n let lo = 0;\n let hi = s.length;\n while (lo < hi) {\n const mid = Math.ceil((lo + hi) / 2);\n if (Buffer.byteLength(s.slice(0, mid), 'utf8') <= maxBytes) lo = mid;\n else hi = mid - 1;\n }\n return s.slice(0, lo);\n}\n\n/** Largest suffix of `s` whose UTF-8 byte length is <= `maxBytes`. */\nfunction takeTailBytes(s: string, maxBytes: number): string {\n if (maxBytes <= 0) return '';\n if (Buffer.byteLength(s, 'utf8') <= maxBytes) return s;\n let lo = 0;\n let hi = s.length;\n while (lo < hi) {\n const mid = Math.ceil((lo + hi) / 2);\n if (Buffer.byteLength(s.slice(s.length - mid), 'utf8') <= maxBytes) lo = mid;\n else hi = mid - 1;\n }\n return s.slice(s.length - lo);\n}\n\n/**\n * Truncate to `maxBytes` keeping BOTH ends — the head (what ran / early context)\n * and the tail (errors and summaries usually land last), biased ~45/55 toward\n * the tail. The result never exceeds `maxBytes`.\n */\nexport function truncateHeadTail(s: string, maxBytes: number): string {\n const total = Buffer.byteLength(s, 'utf8');\n if (total <= maxBytes) return s;\n // Reserve a fixed allowance for the marker so the final string can't exceed\n // the cap even though the dropped-byte count's digit width varies.\n const MARKER_RESERVE = 64;\n const avail = Math.max(0, maxBytes - MARKER_RESERVE);\n const headBudget = Math.floor(avail * 0.45);\n const head = takeHeadBytes(s, headBudget);\n const tail = takeTailBytes(s, avail - Buffer.byteLength(head, 'utf8'));\n const kept = Buffer.byteLength(head, 'utf8') + Buffer.byteLength(tail, 'utf8');\n return `${head}\\n…[truncated ${total - kept} bytes]…\\n${tail}`;\n}\n\n/**\n * Full token-saving pipeline for command tool output: strip ANSI → collapse\n * carriage-return progress → trim trailing whitespace → collapse identical\n * consecutive lines → squeeze blank-line runs → head+tail truncate to the cap.\n */\nexport function normalizeCommandOutput(\n raw: string,\n opts: { maxBytes?: number | undefined } = {},\n): string {\n if (!raw) return raw;\n let text = Core.stripAnsi(raw);\n text = collapseCarriageReturns(text);\n text = text.replace(/[ \\t]+$/gm, ''); // trailing whitespace per line\n text = collapseConsecutiveDuplicates(text);\n text = text.replace(/\\n{3,}/g, '\\n\\n'); // >=2 blank lines → 1\n return truncateHeadTail(text, opts.maxBytes ?? COMMAND_OUTPUT_MAX_BYTES);\n}\n","import { spawn } from 'node:child_process';\nimport { buildChildEnv } from '@wrongstack/core';\nimport type { Tool } from '@wrongstack/core';\nimport { detectPackageManager, safeResolve } from './_util.js';\n\ninterface OutdatedInput {\n cwd?: string | undefined;\n format?: 'list' | 'table' | undefined;\n include_deprecated?: boolean | undefined;\n check?: string | string[] | undefined;\n}\n\ninterface OutdatedPackage {\n name: string;\n current: string;\n latest: string;\n wanted: string;\n type: string;\n location: string;\n}\n\ninterface OutdatedOutput {\n exit_code: number;\n packages: OutdatedPackage[];\n total: number;\n output: string;\n truncated: boolean;\n}\n\nexport const outdatedTool: Tool<OutdatedInput, OutdatedOutput> = {\n name: 'outdated',\n category: 'Package Management',\n description:\n 'Check for outdated dependencies in the project. Reports current, wanted (semver range), and latest versions available.',\n usageHint:\n 'MAINTENANCE & SECURITY TOOL:\\n\\n' +\n '- Run periodically or before dependency-related work.\\n' +\n '- Helps surface packages that may need updates for security or features.\\n' +\n '- Safe, read-only operation.\\n' +\n 'Use the output to decide on upgrades. Prefer this over manual shell commands for dependency hygiene.',\n permission: 'auto',\n mutating: false,\n timeoutMs: 60_000,\n inputSchema: {\n type: 'object',\n properties: {\n cwd: { type: 'string', description: 'Working directory (default: cwd)' },\n format: {\n type: 'string',\n enum: ['list', 'table'],\n description: 'Output format (default: list)',\n },\n include_deprecated: {\n type: 'boolean',\n description: 'Include deprecated packages (default: false)',\n },\n check: {\n type: 'string',\n description: 'Specific package(s) to check (comma-separated)',\n },\n },\n },\n async execute(input, ctx, opts) {\n const cwd = input.cwd ? safeResolve(input.cwd, ctx) : ctx.cwd;\n const manager = await detectPackageManager(cwd);\n\n const args: string[] = ['outdated', '--json'];\n if (input.format === 'table') args.push('--table');\n if (input.include_deprecated) args.push('--include', 'deprecated');\n\n return runOutdated(manager, args, cwd, opts.signal);\n },\n};\n\nfunction runOutdated(\n manager: string,\n args: string[],\n cwd: string,\n signal: AbortSignal,\n): Promise<OutdatedOutput> {\n return new Promise((resolve) => {\n let stdout = '';\n let stderr = '';\n const MAX = 100_000;\n\n const child = spawn(manager, args, { cwd, signal, env: buildChildEnv(), stdio: ['ignore', 'pipe', 'pipe'] });\n child.stdout?.on('data', (c) => {\n if (stdout.length < MAX) stdout += c.toString();\n });\n child.stderr?.on('data', (c) => {\n if (stderr.length < MAX) stderr += c.toString();\n });\n child.on('close', (code) => {\n const result = parseOutdatedOutput(stdout, code ?? 0);\n resolve(result);\n });\n child.on('error', (e) => {\n resolve({\n exit_code: 1,\n packages: [],\n total: 0,\n output: e.message,\n truncated: false,\n });\n });\n });\n}\n\nfunction parseOutdatedOutput(json: string, exitCode: number): OutdatedOutput {\n const packages: OutdatedPackage[] = [];\n\n if (!json) {\n return {\n exit_code: exitCode,\n packages: [],\n total: 0,\n output: exitCode === 0 ? 'All packages up to date' : 'Could not check outdated packages',\n truncated: false,\n };\n }\n\n try {\n const data = JSON.parse(json);\n for (const name of Object.keys(data)) {\n const info = data[name];\n packages.push({\n name,\n current: info.current ?? 'unknown',\n latest: info.latest ?? 'unknown',\n wanted: info.wanted ?? 'unknown',\n type: info.type ?? 'unknown',\n location: info.location ?? name,\n });\n }\n } catch {\n // JSON parse failed, return raw output\n }\n\n return {\n exit_code: exitCode,\n packages,\n total: packages.length,\n output: json,\n truncated: json.length >= 100_000,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/_util.ts","../src/outdated.ts"],"names":["resolve"],"mappings":";;;;;AAcA,eAAsB,qBAAqB,GAAA,EAAsC;AAC/E,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,OAAO,kBAAkB,CAAA;AAChD,EAAA,IAAI;AACF,IAAA,MAAM,IAAA,CAAK,CAAA,EAAG,GAAG,CAAA,eAAA,CAAiB,CAAA;AAClC,IAAA,OAAO,MAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AAAA,EAER;AACA,EAAA,IAAI;AACF,IAAA,MAAM,IAAA,CAAK,CAAA,EAAG,GAAG,CA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AAA;AAAA,MACX,UAAU,EAAC;AAAA,MACX,KAAA,EAAO,CAAA;AAAA,MACP,MAAA,EAAQ,QAAA,KAAa,CAAA,GAAI,yBAAA,GAA4B,mCAAA;AAAA,MACrD,SAAA,EAAW;AAAA,KACb;AAAA,EACF;AAEA,EAAA,IAAI;AACF,IAAA,MAAM,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA;AAC5B,IAAA,KAAA,MAAW,IAAA,IAAQ,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA,EAAG;AACpC,MAAA,MAAM,IAAA,GAAO,KAAK,IAAI,CAAA;AACtB,MAAA,QAAA,CAAS,IAAA,CAAK;AAAA,QACZ,IAAA;AAAA,QACA,OAAA,EAAS,KAAK,OAAA,IAAW,SAAA;AAAA,QACzB,MAAA,EAAQ,KAAK,MAAA,IAAU,SAAA;AAAA,QACvB,MAAA,EAAQ,KAAK,MAAA,IAAU,SAAA;AAAA,QACvB,IAAA,EAAM,KAAK,IAAA,IAAQ,SAAA;AAAA,QACnB,QAAA,EAAU,KAAK,QAAA,IAAY;AAAA,OAC5B,CAAA;AAAA,IACH;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AAEA,EAAA,OAAO;AAAA,IACL,SAAA,EAAW,QAAA;AAAA,IACX,QAAA;AAAA,IACA,OAAO,QAAA,CAAS,MAAA;AAAA,IAChB,MAAA,EAAQ,IAAA;AAAA,IACR,SAAA,EAAW,KAAK,MAAA,IAAU;AAAA,GAC5B;AACF","file":"outdated.js","sourcesContent":["import { expectDefined } from '@wrongstack/core';\nimport * as fsp from 'node:fs/promises';\nimport * as path from 'node:path';\nimport * as Core from '@wrongstack/core';\nimport type { Context } from '@wrongstack/core';\n/** Detected package manager for a project directory. */\nexport type PackageManager = 'pnpm' | 'yarn' | 'npm';\n\n/**\n * Detect the project's package manager by inspecting lockfiles in `cwd`.\n * Order: pnpm → yarn → npm (default). Missing or unreadable directories fall\n * back to `npm` rather than throwing, so a `safeResolve`-checked cwd that\n * happens to be empty never aborts the tool.\n */\nexport async function detectPackageManager(cwd: string): Promise<PackageManager> {\n const { stat } = await import('node:fs/promises');\n try {\n await stat(`${cwd}/pnpm-lock.yaml`);\n return 'pnpm';\n } catch {\n /* not pnpm */\n }\n try {\n await stat(`${cwd}/yarn.lock`);\n return 'yarn';\n } catch {\n /* not yarn */\n }\n return 'npm';\n}\n\nexport function resolvePath(input: string, ctx: Context): string {\n return path.isAbsolute(input) ? path.normalize(input) : path.resolve(ctx.cwd, input);\n}\n\nexport function ensureInsideRoot(absPath: string, ctx: Context): string {\n const root = path.resolve(ctx.projectRoot);\n const target = path.resolve(absPath);\n const rel = path.relative(root, target);\n if (rel.startsWith('..') || path.isAbsolute(rel)) {\n throw new Error(`Path \"${absPath}\" is outside project root \"${root}\"`);\n }\n return target;\n}\n\nexport function safeResolve(input: string, ctx: Context): string {\n return ensureInsideRoot(resolvePath(input, ctx), ctx);\n}\n\n/**\n * Defense against in-root→out-of-root symlink escape (CWE-59). `safeResolve`\n * only does a syntactic `../` check, so a symlink that lives *inside* the\n * project root but points outside still passes it. This resolves the path\n * through `fs.realpath` and re-verifies containment against the realpath of\n * the project root (comparing like-for-like, since the root itself may be a\n * symlink — macOS `/var`→`/private/var`, Windows 8.3 short names). For a path\n * that does not exist yet (e.g. a `write` to a new file) the nearest existing\n * ancestor directory is checked instead. Throws if the real target escapes.\n *\n * Mirrors the per-file guard already used in `replace.ts`/`grep.ts`; applied\n * to single-file `read`/`edit`/`write` it throws (rather than skips) because\n * the caller named exactly one file.\n */\nexport async function assertRealInsideRoot(absPath: string, ctx: Context): Promise<void> {\n const realRoot = await fsp.realpath(ctx.projectRoot).catch(() => path.resolve(ctx.projectRoot));\n let probe = absPath;\n for (;;) {\n let real: string;\n try {\n real = await fsp.realpath(probe);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n const parent = path.dirname(probe);\n if (parent === probe) return; // reached fs root without escaping\n probe = parent;\n continue;\n }\n throw err;\n }\n const rel = path.relative(realRoot, real);\n if (rel.startsWith('..') || path.isAbsolute(rel)) {\n throw new Error(\n `Path \"${absPath}\" resolves through a symlink outside project root \"${realRoot}\"`,\n );\n }\n return;\n }\n}\n\n/** `safeResolve` + symlink realpath containment check. Async. */\nexport async function safeResolveReal(input: string, ctx: Context): Promise<string> {\n const abs = safeResolve(input, ctx);\n await assertRealInsideRoot(abs, ctx);\n return abs;\n}\n\nexport function truncateMiddle(s: string, max: number): string {\n if (Buffer.byteLength(s, 'utf8') <= max) return s;\n const half = Math.floor(max / 2);\n return (\n s.slice(0, half) +\n `\\n…[truncated ${Buffer.byteLength(s, 'utf8') - max} bytes from middle]…\\n` +\n s.slice(-half)\n );\n}\n\nexport function isBinaryBuffer(buf: Buffer): boolean {\n const len = Math.min(buf.length, 8192);\n for (let i = 0; i < len; i++) {\n if (buf[i] === 0) return true;\n }\n return false;\n}\n\n// ─── Command-output normalization (token-saving) ────────────────────────────\n//\n// Raw process output is full of tokens the model gains nothing from: ANSI\n// escapes, carriage-return progress spam, runs of identical warning lines, and\n// huge tails of build noise. These helpers strip that noise before the output\n// reaches the LLM. They are scoped to COMMAND tools (bash/git/exec and the\n// _spawn-stream consumers) — never applied to structured/code outputs.\n\n/** Unified byte cap for all command tool output fed to the model. */\nexport const COMMAND_OUTPUT_MAX_BYTES = 32_768;\n\n/** Runs of >= this many identical consecutive lines are collapsed. */\nconst REPEAT_RUN_THRESHOLD = 3;\n\n/**\n * Collapse carriage-return overwrites the way a terminal would: `\\r\\n` becomes\n * `\\n`, and a bare `\\r` (progress redraw) keeps only the text after the LAST\n * `\\r` on its physical line. Without this, a single progress bar that redraws\n * 200 times explodes into 200 lines.\n */\nexport function collapseCarriageReturns(text: string): string {\n const lf = text.replace(/\\r\\n/g, '\\n');\n if (!lf.includes('\\r')) return lf;\n return lf\n .split('\\n')\n .map((line) => (line.includes('\\r') ? line.slice(line.lastIndexOf('\\r') + 1) : line))\n .join('\\n');\n}\n\n/**\n * Collapse a run of `minRun`+ identical consecutive lines into the line once\n * plus a marker. Consecutive-only — it never reorders or dedups non-adjacent\n * lines, so diffs/source stay intact.\n */\nexport function collapseConsecutiveDuplicates(text: string, minRun = REPEAT_RUN_THRESHOLD): string {\n const lines = text.split('\\n');\n const out: string[] = [];\n let i = 0;\n while (i < lines.length) {\n let j = i + 1;\n while (j < lines.length && lines[j] === lines[i]) j++;\n const run = j - i;\n if (run >= minRun) {\n out.push(expectDefined(lines[i]), `… ⟨repeated ${run}×⟩`);\n } else {\n for (let k = i; k < j; k++) out.push(expectDefined(lines[k]));\n }\n i = j;\n }\n return out.join('\\n');\n}\n\n/** Largest prefix of `s` whose UTF-8 byte length is <= `maxBytes`. */\nfunction takeHeadBytes(s: string, maxBytes: number): string {\n if (maxBytes <= 0) return '';\n if (Buffer.byteLength(s, 'utf8') <= maxBytes) return s;\n let lo = 0;\n let hi = s.length;\n while (lo < hi) {\n const mid = Math.ceil((lo + hi) / 2);\n if (Buffer.byteLength(s.slice(0, mid), 'utf8') <= maxBytes) lo = mid;\n else hi = mid - 1;\n }\n return s.slice(0, lo);\n}\n\n/** Largest suffix of `s` whose UTF-8 byte length is <= `maxBytes`. */\nfunction takeTailBytes(s: string, maxBytes: number): string {\n if (maxBytes <= 0) return '';\n if (Buffer.byteLength(s, 'utf8') <= maxBytes) return s;\n let lo = 0;\n let hi = s.length;\n while (lo < hi) {\n const mid = Math.ceil((lo + hi) / 2);\n if (Buffer.byteLength(s.slice(s.length - mid), 'utf8') <= maxBytes) lo = mid;\n else hi = mid - 1;\n }\n return s.slice(s.length - lo);\n}\n\n/**\n * Truncate to `maxBytes` keeping BOTH ends — the head (what ran / early context)\n * and the tail (errors and summaries usually land last), biased ~45/55 toward\n * the tail. The result never exceeds `maxBytes`.\n */\nexport function truncateHeadTail(s: string, maxBytes: number): string {\n const total = Buffer.byteLength(s, 'utf8');\n if (total <= maxBytes) return s;\n // Reserve a fixed allowance for the marker so the final string can't exceed\n // the cap even though the dropped-byte count's digit width varies.\n const MARKER_RESERVE = 64;\n const avail = Math.max(0, maxBytes - MARKER_RESERVE);\n const headBudget = Math.floor(avail * 0.45);\n const head = takeHeadBytes(s, headBudget);\n const tail = takeTailBytes(s, avail - Buffer.byteLength(head, 'utf8'));\n const kept = Buffer.byteLength(head, 'utf8') + Buffer.byteLength(tail, 'utf8');\n return `${head}\\n…[truncated ${total - kept} bytes]…\\n${tail}`;\n}\n\n/**\n * Full token-saving pipeline for command tool output: strip ANSI → collapse\n * carriage-return progress → trim trailing whitespace → collapse identical\n * consecutive lines → squeeze blank-line runs → head+tail truncate to the cap.\n */\nexport function normalizeCommandOutput(\n raw: string,\n opts: { maxBytes?: number | undefined } = {},\n): string {\n if (!raw) return raw;\n let text = Core.stripAnsi(raw);\n text = collapseCarriageReturns(text);\n text = text.replace(/[ \\t]+$/gm, ''); // trailing whitespace per line\n text = collapseConsecutiveDuplicates(text);\n text = text.replace(/\\n{3,}/g, '\\n\\n'); // >=2 blank lines → 1\n return truncateHeadTail(text, opts.maxBytes ?? COMMAND_OUTPUT_MAX_BYTES);\n}\n","import { spawn } from 'node:child_process';\nimport { buildChildEnv } from '@wrongstack/core';\nimport type { Tool } from '@wrongstack/core';\nimport { detectPackageManager, safeResolve } from './_util.js';\n\ninterface OutdatedInput {\n cwd?: string | undefined;\n format?: 'list' | 'table' | undefined;\n include_deprecated?: boolean | undefined;\n check?: string | string[] | undefined;\n}\n\ninterface OutdatedPackage {\n name: string;\n current: string;\n latest: string;\n wanted: string;\n type: string;\n location: string;\n}\n\ninterface OutdatedOutput {\n exit_code: number;\n packages: OutdatedPackage[];\n total: number;\n output: string;\n truncated: boolean;\n}\n\nexport const outdatedTool: Tool<OutdatedInput, OutdatedOutput> = {\n name: 'outdated',\n category: 'Package Management',\n description:\n 'Check for outdated dependencies in the project. Reports current, wanted (semver range), and latest versions available.',\n usageHint:\n 'MAINTENANCE & SECURITY TOOL:\\n\\n' +\n '- Run periodically or before dependency-related work.\\n' +\n '- Helps surface packages that may need updates for security or features.\\n' +\n '- Safe, read-only operation.\\n' +\n 'Use the output to decide on upgrades. Prefer this over manual shell commands for dependency hygiene.',\n permission: 'auto',\n mutating: false,\n timeoutMs: 60_000,\n inputSchema: {\n type: 'object',\n properties: {\n cwd: { type: 'string', description: 'Working directory (default: cwd)' },\n format: {\n type: 'string',\n enum: ['list', 'table'],\n description: 'Output format (default: list)',\n },\n include_deprecated: {\n type: 'boolean',\n description: 'Include deprecated packages (default: false)',\n },\n check: {\n type: 'string',\n description: 'Specific package(s) to check (comma-separated)',\n },\n },\n },\n async execute(input, ctx, opts) {\n const cwd = input.cwd ? safeResolve(input.cwd, ctx) : ctx.cwd;\n const manager = await detectPackageManager(cwd);\n\n const args: string[] = ['outdated', '--json'];\n if (input.format === 'table') args.push('--table');\n if (input.include_deprecated) args.push('--include', 'deprecated');\n\n return runOutdated(manager, args, cwd, opts.signal);\n },\n};\n\nfunction runOutdated(\n manager: string,\n args: string[],\n cwd: string,\n signal: AbortSignal,\n): Promise<OutdatedOutput> {\n return new Promise((resolve) => {\n let stdout = '';\n let stderr = '';\n const MAX = 100_000;\n\n const child = spawn(manager, args, { cwd, signal, env: buildChildEnv(), stdio: ['ignore', 'pipe', 'pipe'] });\n child.stdout?.on('data', (c) => {\n if (stdout.length < MAX) stdout += c.toString();\n });\n child.stderr?.on('data', (c) => {\n if (stderr.length < MAX) stderr += c.toString();\n });\n child.on('close', (code) => {\n const result = parseOutdatedOutput(stdout, code ?? 0);\n resolve(result);\n });\n child.on('error', (e) => {\n resolve({\n exit_code: 1,\n packages: [],\n total: 0,\n output: e.message,\n truncated: false,\n });\n });\n });\n}\n\nfunction parseOutdatedOutput(json: string, exitCode: number): OutdatedOutput {\n const packages: OutdatedPackage[] = [];\n\n if (!json) {\n return {\n exit_code: exitCode,\n packages: [],\n total: 0,\n output: exitCode === 0 ? 'All packages up to date' : 'Could not check outdated packages',\n truncated: false,\n };\n }\n\n try {\n const data = JSON.parse(json);\n for (const name of Object.keys(data)) {\n const info = data[name];\n packages.push({\n name,\n current: info.current ?? 'unknown',\n latest: info.latest ?? 'unknown',\n wanted: info.wanted ?? 'unknown',\n type: info.type ?? 'unknown',\n location: info.location ?? name,\n });\n }\n } catch {\n // JSON parse failed, return raw output\n }\n\n return {\n exit_code: exitCode,\n packages,\n total: packages.length,\n output: json,\n truncated: json.length >= 100_000,\n };\n}\n"]}
|