-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
120 lines (106 loc) · 4.37 KB
/
Copy pathindex.js
File metadata and controls
120 lines (106 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// quick-notes plugin for LocalCode
// Stores notes in ~/.localcode/quick-notes.json
// The LLM agent can save notes while working; the user reads them with /notes.
const fs = require('fs')
const path = require('path')
const os = require('os')
const NOTES_FILE = path.join(os.homedir(), '.localcode', 'quick-notes.json')
// ── Helpers ──────────────────────────────────────────────────────────────────
function loadNotes() {
try {
return JSON.parse(fs.readFileSync(NOTES_FILE, 'utf-8'))
} catch {
return []
}
}
function saveNotes(notes) {
const dir = path.dirname(NOTES_FILE)
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true })
fs.writeFileSync(NOTES_FILE, JSON.stringify(notes, null, 2), 'utf-8')
}
// ── Plugin registration ───────────────────────────────────────────────────────
module.exports = {
register(registry) {
// ── Tool: save_note ───────────────────────────────────────────────────────
// The LLM calls this to save an important finding during a task.
registry.addTool({
name: 'save_note',
description: 'Save an important note or finding so the user can review it later with /notes.',
parameters: {
type: 'object',
properties: {
text: {
type: 'string',
description: 'The note text to save'
},
tag: {
type: 'string',
description: 'Optional short tag, e.g. "bug", "idea", "todo"'
}
},
required: ['text']
},
execute: async ({ text, tag }) => {
const notes = loadNotes()
const entry = {
id: notes.length + 1,
text: String(text),
tag: tag ? String(tag) : null,
timestamp: new Date().toISOString(),
}
notes.push(entry)
saveNotes(notes)
return `Note #${entry.id} saved${entry.tag ? ` [${entry.tag}]` : ''}.`
}
})
// ── Tool: read_notes ──────────────────────────────────────────────────────
// The LLM can read back all saved notes (e.g. to summarize or continue work).
registry.addTool({
name: 'read_notes',
description: 'Read all saved notes. Use this to recall findings from earlier in the task.',
parameters: {
type: 'object',
properties: {
tag: {
type: 'string',
description: 'Optional: filter by tag'
}
}
},
execute: async ({ tag }) => {
let notes = loadNotes()
if (tag) notes = notes.filter(n => n.tag === String(tag))
if (notes.length === 0) return tag ? `No notes with tag "${tag}".` : 'No notes saved yet.'
return notes
.map(n => `#${n.id}${n.tag ? ` [${n.tag}]` : ''}: ${n.text} (${n.timestamp})`)
.join('\n')
}
})
// ── Command: /notes ───────────────────────────────────────────────────────
// The user types /notes to see all saved notes, or /notes clear to wipe them.
registry.addCommand({
cmd: '/notes',
description: 'Show saved notes (/notes) or clear them (/notes clear)',
handler: async (args, _ctx) => {
const sub = args.trim().toLowerCase()
if (sub === 'clear') {
saveNotes([])
return { type: 'done', content: 'All notes cleared.' }
}
const notes = loadNotes()
if (notes.length === 0) {
return { type: 'text', content: 'No notes yet. Ask the agent to save_note during a task.' }
}
const lines = notes.map(n => {
const tag = n.tag ? ` [${n.tag}]` : ''
const date = new Date(n.timestamp).toLocaleString()
return `#${n.id}${tag} ${date}\n ${n.text}`
})
return {
type: 'done',
content: `${notes.length} note(s):\n\n` + lines.join('\n\n'),
}
}
})
}
}