@g3nomaly/g3n-mods 0.0.0-stage → 0.1.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/.claude-plugin/marketplace.json +68 -0
- package/LICENSE +95 -0
- package/mods/agents-panel/.claude-plugin/plugin.json +9 -0
- package/mods/agents-panel/hooks/hooks.json +1 -0
- package/mods/agents-panel/hooks/register.tsx +224 -0
- package/mods/agents-panel/types/index.d.ts +24 -0
- package/mods/context-bar/.claude-plugin/plugin.json +9 -0
- package/mods/context-bar/hooks/hooks.json +1 -0
- package/mods/context-bar/hooks/register.tsx +187 -0
- package/mods/context-bar/types/index.d.ts +25 -0
- package/mods/custom-crab-agents/.claude-plugin/plugin.json +9 -0
- package/mods/custom-crab-agents/hooks/hooks.json +1 -0
- package/mods/custom-crab-agents/hooks/register.tsx +369 -0
- package/mods/custom-crab-agents/types/index.d.ts +45 -0
- package/mods/delete-guard/.claude-plugin/plugin.json +9 -0
- package/mods/delete-guard/hooks/hooks.json +1 -0
- package/mods/delete-guard/hooks/register.ts +117 -0
- package/mods/delete-guard/types/index.d.ts +14 -0
- package/mods/focus-mode/.claude-plugin/plugin.json +17 -0
- package/mods/focus-mode/hooks/hooks.json +1 -0
- package/mods/focus-mode/hooks/register.tsx +147 -0
- package/mods/focus-mode/types/index.d.ts +14 -0
- package/mods/handoff/.claude-plugin/plugin.json +9 -0
- package/mods/handoff/hooks/hooks.json +1 -0
- package/mods/handoff/hooks/register.tsx +119 -0
- package/mods/handoff/types/index.d.ts +15 -0
- package/mods/hide-personal-data/.claude-plugin/plugin.json +17 -0
- package/mods/hide-personal-data/hooks/hooks.json +1 -0
- package/mods/hide-personal-data/hooks/register.tsx +163 -0
- package/mods/hide-personal-data/types/index.d.ts +17 -0
- package/mods/mini-game/.claude-plugin/plugin.json +9 -0
- package/mods/mini-game/hooks/hooks.json +1 -0
- package/mods/mini-game/hooks/register.tsx +211 -0
- package/mods/mini-game/types/index.d.ts +21 -0
- package/mods/tool-timeline/.claude-plugin/plugin.json +9 -0
- package/mods/tool-timeline/hooks/hooks.json +1 -0
- package/mods/tool-timeline/hooks/register.tsx +259 -0
- package/mods/tool-timeline/types/index.d.ts +25 -0
- package/mods/tsconfig.json +17 -0
- package/mods/you-should-know/.claude-plugin/plugin.json +23 -0
- package/mods/you-should-know/hooks/hooks.json +1 -0
- package/mods/you-should-know/hooks/register.tsx +98 -0
- package/mods/you-should-know/types/index.d.ts +15 -0
- package/package.json +25 -4
- package/README.md +0 -3
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "g3n-mods",
|
|
3
|
+
"owner": {
|
|
4
|
+
"name": "g3ntrovert"
|
|
5
|
+
},
|
|
6
|
+
"plugins": [
|
|
7
|
+
{
|
|
8
|
+
"name": "agents-panel",
|
|
9
|
+
"source": "./mods/agents-panel",
|
|
10
|
+
"description": "The agents in .claude/agents with their model and a run button.",
|
|
11
|
+
"version": "0.1.0"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "context-bar",
|
|
15
|
+
"source": "./mods/context-bar",
|
|
16
|
+
"description": "Context window use as one bar split by source, with the total and the compaction point.",
|
|
17
|
+
"version": "0.1.0"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"name": "custom-crab-agents",
|
|
21
|
+
"source": "./mods/custom-crab-agents",
|
|
22
|
+
"description": "Each subagent as a crab with a hat: effort tier, model, steps, context, tokens, cost and time.",
|
|
23
|
+
"version": "0.1.0"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "delete-guard",
|
|
27
|
+
"source": "./mods/delete-guard",
|
|
28
|
+
"description": "Denies rm -rf and other permanent deletes and points Claude to the trash.",
|
|
29
|
+
"version": "0.1.0"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "focus-mode",
|
|
33
|
+
"source": "./mods/focus-mode",
|
|
34
|
+
"description": "A timed focus block with a countdown, a progress bar and an end button.",
|
|
35
|
+
"version": "0.1.0"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "handoff",
|
|
39
|
+
"source": "./mods/handoff",
|
|
40
|
+
"description": "Writes a handoff with the handoff skill, clears the session, and starts the fresh one with your next prompt.",
|
|
41
|
+
"version": "0.1.0"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "hide-personal-data",
|
|
45
|
+
"source": "./mods/hide-personal-data",
|
|
46
|
+
"description": "Masks names, emails and other personal data in replies; hover to show them.",
|
|
47
|
+
"version": "0.1.0"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "mini-game",
|
|
51
|
+
"source": "./mods/mini-game",
|
|
52
|
+
"description": "Minesweeper to play while Claude works.",
|
|
53
|
+
"version": "0.1.0"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "tool-timeline",
|
|
57
|
+
"source": "./mods/tool-timeline",
|
|
58
|
+
"description": "Each tool call with its duration; a denied call is struck through next to the call that replaced it.",
|
|
59
|
+
"version": "0.1.0"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"name": "you-should-know",
|
|
63
|
+
"source": "./mods/you-should-know",
|
|
64
|
+
"description": "A card under long replies that flags their key point: a headline and one supporting line.",
|
|
65
|
+
"version": "0.1.0"
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Copyright (c) 2026 G3NTs - G3nomaly
|
|
2
|
+
|
|
3
|
+
Elastic License 2.0
|
|
4
|
+
|
|
5
|
+
URL: https://www.elastic.co/licensing/elastic-license
|
|
6
|
+
|
|
7
|
+
## Acceptance
|
|
8
|
+
|
|
9
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
14
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
15
|
+
available, and prepare derivative works of the software, in each case subject to
|
|
16
|
+
the limitations and conditions below.
|
|
17
|
+
|
|
18
|
+
## Limitations
|
|
19
|
+
|
|
20
|
+
You may not provide the software to third parties as a hosted or managed
|
|
21
|
+
service, where the service provides users with access to any substantial set of
|
|
22
|
+
the features or functionality of the software.
|
|
23
|
+
|
|
24
|
+
You may not move, change, disable, or circumvent the license key functionality
|
|
25
|
+
in the software, and you may not remove or obscure any functionality in the
|
|
26
|
+
software that is protected by the license key.
|
|
27
|
+
|
|
28
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices
|
|
29
|
+
of the licensor in the software. Any use of the licensor’s trademarks is subject
|
|
30
|
+
to applicable law.
|
|
31
|
+
|
|
32
|
+
## Patents
|
|
33
|
+
|
|
34
|
+
The licensor grants you a license, under any patent claims the licensor can
|
|
35
|
+
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
36
|
+
sale, import and have imported the software, in each case subject to the
|
|
37
|
+
limitations and conditions in this license. This license does not cover any
|
|
38
|
+
patent claims that you cause to be infringed by modifications or additions to
|
|
39
|
+
the software. If you or your company make any written claim that the software
|
|
40
|
+
infringes or contributes to infringement of any patent, your patent license for
|
|
41
|
+
the software granted under these terms ends immediately. If your company makes
|
|
42
|
+
such a claim, your patent license ends immediately for work on behalf of your
|
|
43
|
+
company.
|
|
44
|
+
|
|
45
|
+
## Notices
|
|
46
|
+
|
|
47
|
+
You must ensure that anyone who gets a copy of any part of the software from you
|
|
48
|
+
also gets a copy of these terms.
|
|
49
|
+
|
|
50
|
+
If you modify the software, you must include in any modified copies of the
|
|
51
|
+
software prominent notices stating that you have modified the software.
|
|
52
|
+
|
|
53
|
+
## No Other Rights
|
|
54
|
+
|
|
55
|
+
These terms do not imply any licenses other than those expressly granted in
|
|
56
|
+
these terms.
|
|
57
|
+
|
|
58
|
+
## Termination
|
|
59
|
+
|
|
60
|
+
If you use the software in violation of these terms, such use is not licensed,
|
|
61
|
+
and your licenses will automatically terminate. If the licensor provides you
|
|
62
|
+
with a notice of your violation, and you cease all violation of this license no
|
|
63
|
+
later than 30 days after you receive that notice, your licenses will be
|
|
64
|
+
reinstated retroactively. However, if you violate these terms after such
|
|
65
|
+
reinstatement, any additional violation of these terms will cause your licenses
|
|
66
|
+
to terminate automatically and permanently.
|
|
67
|
+
|
|
68
|
+
## No Liability
|
|
69
|
+
|
|
70
|
+
*As far as the law allows, the software comes as is, without any warranty or
|
|
71
|
+
condition, and the licensor will not be liable to you for any damages arising
|
|
72
|
+
out of these terms or the use or nature of the software, under any kind of
|
|
73
|
+
legal claim.*
|
|
74
|
+
|
|
75
|
+
## Definitions
|
|
76
|
+
|
|
77
|
+
The **licensor** is the entity offering these terms, and the **software** is the
|
|
78
|
+
software the licensor makes available under these terms, including any portion
|
|
79
|
+
of it.
|
|
80
|
+
|
|
81
|
+
**you** refers to the individual or entity agreeing to these terms.
|
|
82
|
+
|
|
83
|
+
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
84
|
+
organization that you work for, plus all organizations that have control over,
|
|
85
|
+
are under the control of, or are under common control with that
|
|
86
|
+
organization. **control** means ownership of substantially all the assets of an
|
|
87
|
+
entity, or the power to direct its management and policies by vote, contract, or
|
|
88
|
+
otherwise. Control can be direct or indirect.
|
|
89
|
+
|
|
90
|
+
**your licenses** are all the licenses granted to you for the software under
|
|
91
|
+
these terms.
|
|
92
|
+
|
|
93
|
+
**use** means anything you do with the software requiring one of your licenses.
|
|
94
|
+
|
|
95
|
+
**trademark** means trademarks, service marks, and similar rights.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "modules": ["./register.tsx"] }
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// packages/g3n-mods/mods/agents-panel/hooks/register.tsx
|
|
2
|
+
import { atom, read, update } from 'claude-code'
|
|
3
|
+
import type { EngineInterface, Register } from 'claude-code'
|
|
4
|
+
|
|
5
|
+
import type { AgentDef, RunningAgent } from '../types'
|
|
6
|
+
|
|
7
|
+
const PANE = 'agents-panel'
|
|
8
|
+
const TITLE = 'Agents'
|
|
9
|
+
const agents = atom({ plugin: 'agents-panel', key: 'agents' } as const, [])
|
|
10
|
+
const running = atom({ plugin: 'agents-panel', key: 'running' } as const, [])
|
|
11
|
+
const task = atom({ plugin: 'agents-panel', key: 'task' } as const, '')
|
|
12
|
+
|
|
13
|
+
const AGENTS_DIR = '.claude/agents'
|
|
14
|
+
const DEFAULT_TASK = 'Do the job your instructions describe for this project, then report what you did and what you found.'
|
|
15
|
+
const DOT_COLORS = ['#6b8fd6', '#5fb3c4', '#e6c167', '#e0775a', '#b48ead', '#e06c6c', '#7cc47f', '#9b87f5']
|
|
16
|
+
const NAMED_COLORS: Readonly<Record<string, string>> = {
|
|
17
|
+
red: '#e06c6c', blue: '#6b8fd6', green: '#7cc47f', yellow: '#e6c167',
|
|
18
|
+
purple: '#b48ead', orange: '#e0775a', pink: '#f09bb5', cyan: '#5fb3c4',
|
|
19
|
+
}
|
|
20
|
+
const SPINNER = ['◐', '◓', '◑', '◒']
|
|
21
|
+
const DONE_STATUSES = new Set(['completed', 'failed', 'killed', 'idle'])
|
|
22
|
+
|
|
23
|
+
/** Frontmatter of a Markdown file as flat `key: value` pairs, quotes stripped. */
|
|
24
|
+
export function frontmatter(text: string): Record<string, string> {
|
|
25
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text)
|
|
26
|
+
if (match === null) return {}
|
|
27
|
+
const fields: Record<string, string> = {}
|
|
28
|
+
for (const line of (match[1] ?? '').split(/\r?\n/)) {
|
|
29
|
+
const pair = /^([A-Za-z][\w-]*):\s*(.*)$/.exec(line)
|
|
30
|
+
if (pair === null) continue
|
|
31
|
+
fields[pair[1] ?? ''] = (pair[2] ?? '').trim().replace(/^(['"])(.*)\1$/, '$2')
|
|
32
|
+
}
|
|
33
|
+
return fields
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function dotColor(agent: AgentDef, index: number): string {
|
|
37
|
+
const named = agent.color === undefined ? undefined : NAMED_COLORS[agent.color] ?? agent.color
|
|
38
|
+
return named ?? DOT_COLORS[index % DOT_COLORS.length] ?? '#8a8f98'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Reads every agent definition in one agents folder; a missing folder reads as none. */
|
|
42
|
+
async function readAgentsDir($: EngineInterface, dir: string, scope: AgentDef['scope']): Promise<AgentDef[]> {
|
|
43
|
+
if (!(await $.fs.exists(dir))) return []
|
|
44
|
+
const found: AgentDef[] = []
|
|
45
|
+
for (const entry of await $.fs.list(dir)) {
|
|
46
|
+
if (entry.kind !== 'file' || !entry.name.endsWith('.md')) continue
|
|
47
|
+
const fields = frontmatter(await $.fs.read(`${dir}/${entry.name}`))
|
|
48
|
+
found.push({
|
|
49
|
+
name: fields.name ?? entry.name.replace(/\.md$/, ''),
|
|
50
|
+
description: fields.description ?? '',
|
|
51
|
+
model: fields.model ?? 'inherit',
|
|
52
|
+
color: fields.color,
|
|
53
|
+
scope,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
return found.sort((a, b) => a.name.localeCompare(b.name))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Reloads the project's and the user's agent definitions into state. */
|
|
60
|
+
async function loadAgents($: EngineInterface): Promise<void> {
|
|
61
|
+
const root = await $.session.root()
|
|
62
|
+
const home = await $.env.get('HOME')
|
|
63
|
+
const project = await readAgentsDir($, `${root}/${AGENTS_DIR}`, 'project')
|
|
64
|
+
const user = home === undefined ? [] : await readAgentsDir($, `${home}/${AGENTS_DIR}`, 'user')
|
|
65
|
+
const names = new Set(project.map(agent => agent.name))
|
|
66
|
+
await update($, agents, () => [...project, ...user.filter(agent => !names.has(agent.name))])
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Starts one agent with the task typed in the panel, or its standing job when none was typed. */
|
|
70
|
+
async function runAgent($: EngineInterface, agent: AgentDef): Promise<void> {
|
|
71
|
+
const typed = (await read($, task)).trim()
|
|
72
|
+
const started = await $.agent.spawn({
|
|
73
|
+
prompt: typed.length > 0 ? typed : DEFAULT_TASK,
|
|
74
|
+
subagentType: agent.name,
|
|
75
|
+
description: `Run ${agent.name} from the agents panel`,
|
|
76
|
+
})
|
|
77
|
+
if ('deny' in started) {
|
|
78
|
+
$.ui.toast(`Could not start ${agent.name}: ${started.deny}`)
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
const startedAt = await $.clock.now()
|
|
82
|
+
await update($, running, list => [...list, { name: agent.name, agentId: started.agentId ?? '', startedAt }])
|
|
83
|
+
$.ui.toast(`Started ${agent.name}`)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Drops the agents that finished from the running list and says which ones did. */
|
|
87
|
+
async function pollRunning($: EngineInterface): Promise<void> {
|
|
88
|
+
const list = await read($, running)
|
|
89
|
+
if (list.length === 0) return
|
|
90
|
+
const known = await $.agent.list()
|
|
91
|
+
const finished = list.filter(run => {
|
|
92
|
+
const info = known.find(agent => agent.id === run.agentId)
|
|
93
|
+
return info !== undefined && DONE_STATUSES.has(info.status)
|
|
94
|
+
})
|
|
95
|
+
if (finished.length > 0) {
|
|
96
|
+
await update($, running, current => current.filter(run => !finished.some(done => done.agentId === run.agentId)))
|
|
97
|
+
for (const run of finished) $.ui.toast(`${run.name} finished`)
|
|
98
|
+
} else {
|
|
99
|
+
$.ui.invalidate('ui.render')
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Puts a finished agent's answer in the transcript as a notice the model does not read. */
|
|
104
|
+
async function reportAnswer($: EngineInterface, run: RunningAgent, answer: string): Promise<void> {
|
|
105
|
+
const text = answer.length > 4000 ? `${answer.slice(0, 4000)}…` : answer
|
|
106
|
+
await $.session.append({ message: { type: 'system', content: [{ type: 'text', text: `${run.name} finished:\n\n${text}` }] } })
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const register: Register = on => {
|
|
110
|
+
on('session.start', async ($, e, next) => {
|
|
111
|
+
await $.command.register({ name: 'agents-panel', description: 'Show or hide the agents panel' })
|
|
112
|
+
await loadAgents($)
|
|
113
|
+
$.clock.every(1000, () => void pollRunning($))
|
|
114
|
+
return next(e)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
on('command.run', { command: 'agents-panel' }, async $ => {
|
|
118
|
+
if ((await $.ui.panes()).some(pane => pane.id === PANE)) {
|
|
119
|
+
await $.ui.close({ id: PANE })
|
|
120
|
+
return { text: 'Agents panel hidden.' }
|
|
121
|
+
}
|
|
122
|
+
await loadAgents($)
|
|
123
|
+
await $.ui.open({ id: PANE, title: TITLE })
|
|
124
|
+
return { text: 'Agents panel shown.' }
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
on('turn.complete', async ($, e, next) => {
|
|
128
|
+
const result = await next(e)
|
|
129
|
+
if (e.agentId === undefined) return result
|
|
130
|
+
const run = (await read($, running)).find(one => one.agentId === e.agentId)
|
|
131
|
+
if (run !== undefined) {
|
|
132
|
+
await update($, running, list => list.filter(one => one.agentId !== e.agentId))
|
|
133
|
+
await reportAnswer($, run, e.answer)
|
|
134
|
+
$.ui.toast(`${run.name} finished`)
|
|
135
|
+
}
|
|
136
|
+
return result
|
|
137
|
+
}).catch(($, e, next) => next(e))
|
|
138
|
+
|
|
139
|
+
on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
|
|
140
|
+
const { Box, Text, Button } = $.ui.resolve(e)
|
|
141
|
+
const list = await read($, agents)
|
|
142
|
+
const runs = await read($, running)
|
|
143
|
+
const now = await $.clock.now()
|
|
144
|
+
const frame = SPINNER[Math.floor(now / 250) % SPINNER.length] ?? '◐'
|
|
145
|
+
|
|
146
|
+
const header = (
|
|
147
|
+
<Box flexDirection="row" justifyContent="space-between">
|
|
148
|
+
<Text>
|
|
149
|
+
<Text color="#e0775a">◆ </Text>
|
|
150
|
+
<Text bold>Agents</Text>
|
|
151
|
+
<Text dimColor> in this project</Text>
|
|
152
|
+
</Text>
|
|
153
|
+
<Text dimColor>{runs.length > 0 ? `${frame} ${runs.length} running` : ''}</Text>
|
|
154
|
+
</Box>
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
if (list.length === 0) {
|
|
158
|
+
return (
|
|
159
|
+
<Box flexDirection="column" gap={1}>
|
|
160
|
+
{header}
|
|
161
|
+
<Text dimColor>No agents in {AGENTS_DIR} or ~/{AGENTS_DIR}. Add one with /agents.</Text>
|
|
162
|
+
</Box>
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const section = (scope: AgentDef['scope']) => {
|
|
167
|
+
const members = list.filter(agent => agent.scope === scope)
|
|
168
|
+
if (members.length === 0) return ''
|
|
169
|
+
return (
|
|
170
|
+
<Box flexDirection="column" gap={1}>
|
|
171
|
+
<Text>
|
|
172
|
+
<Text bold color="#8fa1d6">{scope === 'project' ? 'PROJECT' : 'USER'}</Text>
|
|
173
|
+
<Text dimColor> {scope === 'project' ? AGENTS_DIR : `~/${AGENTS_DIR}`} · {members.length}</Text>
|
|
174
|
+
</Text>
|
|
175
|
+
{members.map((agent, index) => {
|
|
176
|
+
const run = runs.find(one => one.name === agent.name)
|
|
177
|
+
return (
|
|
178
|
+
<Box flexDirection="column" paddingLeft={1}>
|
|
179
|
+
<Box flexDirection="row" justifyContent="space-between">
|
|
180
|
+
<Text>
|
|
181
|
+
<Text color={dotColor(agent, index)}>● </Text>
|
|
182
|
+
<Text bold>{agent.name}</Text>
|
|
183
|
+
<Text dimColor> {agent.model}</Text>
|
|
184
|
+
</Text>
|
|
185
|
+
{run === undefined
|
|
186
|
+
? <Button key={`run:${agent.name}`} label="▶ run" onPress={() => runAgent($, agent)} />
|
|
187
|
+
: <Text color="#8fa1d6">{frame} running · {Math.round((now - run.startedAt) / 1000)}s</Text>}
|
|
188
|
+
</Box>
|
|
189
|
+
<Box paddingLeft={2}>
|
|
190
|
+
<Text dimColor wrap="truncate-end">{agent.description}</Text>
|
|
191
|
+
</Box>
|
|
192
|
+
</Box>
|
|
193
|
+
)
|
|
194
|
+
})}
|
|
195
|
+
</Box>
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const input = e.surface === 'mobile'
|
|
200
|
+
? ''
|
|
201
|
+
: (() => {
|
|
202
|
+
const { Input } = $.ui.resolve(e)
|
|
203
|
+
return (
|
|
204
|
+
<Input
|
|
205
|
+
key="task"
|
|
206
|
+
label="Task"
|
|
207
|
+
placeholder="what the next run should do (optional)"
|
|
208
|
+
onInput={value => update($, task, () => value)}
|
|
209
|
+
onSubmit={value => update($, task, () => value)}
|
|
210
|
+
/>
|
|
211
|
+
)
|
|
212
|
+
})()
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<Box flexDirection="column" gap={1}>
|
|
216
|
+
{header}
|
|
217
|
+
{input}
|
|
218
|
+
{section('project')}
|
|
219
|
+
{section('user')}
|
|
220
|
+
<Text dimColor>click ▶ run to start one · /agents-panel to hide</Text>
|
|
221
|
+
</Box>
|
|
222
|
+
)
|
|
223
|
+
})
|
|
224
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// packages/g3n-mods/mods/agents-panel/types/index.d.ts
|
|
2
|
+
|
|
3
|
+
/** One agent definition found in an agents folder, read from its frontmatter. */
|
|
4
|
+
export type AgentDef = {
|
|
5
|
+
name: string
|
|
6
|
+
description: string
|
|
7
|
+
/** `sonnet`, `opus`, `haiku`, a model id, or `inherit` */
|
|
8
|
+
model: string
|
|
9
|
+
color?: string
|
|
10
|
+
scope: 'project' | 'user'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** An agent this panel started that has not finished; `startedAt` is milliseconds since the epoch. */
|
|
14
|
+
export type RunningAgent = {
|
|
15
|
+
name: string
|
|
16
|
+
agentId: string
|
|
17
|
+
startedAt: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare module 'claude-code' {
|
|
21
|
+
interface PluginState {
|
|
22
|
+
'agents-panel': { agents: AgentDef[]; running: RunningAgent[]; task: string }
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "modules": ["./register.tsx"] }
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// packages/g3n-mods/mods/context-bar/hooks/register.tsx
|
|
2
|
+
import { atom, read, update } from 'claude-code'
|
|
3
|
+
import type { EngineInterface, Register } from 'claude-code'
|
|
4
|
+
|
|
5
|
+
import type { ContextRow, ContextSnapshot } from '../types'
|
|
6
|
+
|
|
7
|
+
const PANE = 'context-bar'
|
|
8
|
+
const TITLE = 'Context'
|
|
9
|
+
const snapshot = atom({ plugin: 'context-bar', key: 'snapshot' } as const, null)
|
|
10
|
+
|
|
11
|
+
/** Fewest milliseconds between two measurements; measure events in between fold into one. */
|
|
12
|
+
const MEASURE_GAP_MS = 2000
|
|
13
|
+
|
|
14
|
+
/** Approximate pixel width of one cell of the editor's code font. */
|
|
15
|
+
const CELL_PX = 7
|
|
16
|
+
|
|
17
|
+
const FREE_COLOR = '#2b3240'
|
|
18
|
+
const MARKER_COLOR = '#e6c167'
|
|
19
|
+
|
|
20
|
+
/** Bar label and color per source, matched against the engine's category names in order. */
|
|
21
|
+
const SOURCES: ReadonlyArray<{ match: RegExp; label: string; color: string }> = [
|
|
22
|
+
{ match: /system prompt/i, label: 'system prompt', color: '#6b8fd6' },
|
|
23
|
+
{ match: /mcp/i, label: 'mcp tools', color: '#9b87f5' },
|
|
24
|
+
{ match: /tool/i, label: 'tools', color: '#5fb3c4' },
|
|
25
|
+
{ match: /agent/i, label: 'agents', color: '#7cc47f' },
|
|
26
|
+
{ match: /memory/i, label: 'memory files', color: '#e6c167' },
|
|
27
|
+
{ match: /skill/i, label: 'skills', color: '#f09bb5' },
|
|
28
|
+
{ match: /message/i, label: 'messages', color: '#e0775a' },
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
/** Tokens as the screenshots spell them: `892`, `4.2k`, `52k`, `1M`. */
|
|
32
|
+
export function formatTokens(tokens: number): string {
|
|
33
|
+
if (tokens >= 1_000_000) return `${+(tokens / 1_000_000).toFixed(1)}M`
|
|
34
|
+
if (tokens >= 10_000) return `${Math.round(tokens / 1000)}k`
|
|
35
|
+
if (tokens >= 1000) return `${+(tokens / 1000).toFixed(1)}k`
|
|
36
|
+
return String(Math.round(tokens))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function percentOf(part: number, whole: number): number {
|
|
40
|
+
return whole > 0 ? Math.round((part / whole) * 100) : 0
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Measures the context window by source. Categories of the same source add
|
|
45
|
+
* up into one row; deferred tools and the compaction buffer are left out.
|
|
46
|
+
*
|
|
47
|
+
* @returns the snapshot, or `null` before the session has measured anything
|
|
48
|
+
*/
|
|
49
|
+
async function measure($: EngineInterface): Promise<ContextSnapshot | null> {
|
|
50
|
+
const usage = await $.session.usage({ breakdown: 'summary' })
|
|
51
|
+
const breakdown = usage.context.breakdown
|
|
52
|
+
if (breakdown === undefined) return null
|
|
53
|
+
|
|
54
|
+
const rows: ContextRow[] = SOURCES.map(source => ({ label: source.label, tokens: 0, color: source.color }))
|
|
55
|
+
let free = 0
|
|
56
|
+
for (const category of breakdown.categories) {
|
|
57
|
+
if (category.kind === 'free') free += category.tokens
|
|
58
|
+
if (category.kind !== 'used') continue
|
|
59
|
+
const index = SOURCES.findIndex(source => source.match.test(category.name))
|
|
60
|
+
const row = index === -1 ? undefined : rows[index]
|
|
61
|
+
if (row !== undefined) row.tokens += category.tokens
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
rows: [...rows, { label: 'free', tokens: free, color: FREE_COLOR }],
|
|
66
|
+
used: breakdown.totalTokens,
|
|
67
|
+
window: breakdown.rawMaxTokens,
|
|
68
|
+
compactAt: breakdown.isAutoCompactEnabled ? breakdown.autoCompactThreshold : undefined,
|
|
69
|
+
measuredAt: await $.clock.now(),
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The bar as one SVG: a rect per source, the free remainder, and a mark at the compaction point. */
|
|
74
|
+
function barSvg(snap: ContextSnapshot, width: number): string {
|
|
75
|
+
const height = 14
|
|
76
|
+
let x = 0
|
|
77
|
+
const rects = snap.rows.map(row => {
|
|
78
|
+
const w = snap.window > 0 ? (row.tokens / snap.window) * width : 0
|
|
79
|
+
const rect = `<rect x="${x.toFixed(2)}" y="0" width="${w.toFixed(2)}" height="${height}" fill="${row.color}"/>`
|
|
80
|
+
x += w
|
|
81
|
+
return rect
|
|
82
|
+
})
|
|
83
|
+
const marker = snap.compactAt === undefined || snap.window === 0
|
|
84
|
+
? ''
|
|
85
|
+
: `<rect x="${Math.min(width - 2, (snap.compactAt / snap.window) * width).toFixed(2)}" y="0" width="2" height="${height}" fill="${MARKER_COLOR}"/>`
|
|
86
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}"><rect width="${width}" height="${height}" rx="3" fill="${FREE_COLOR}"/>${rects.join('')}${marker}</svg>`
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let lastMeasured = 0
|
|
90
|
+
let isScheduled = false
|
|
91
|
+
|
|
92
|
+
/** Measures now, or once the gap since the last measurement has passed; calls in between fold into one. */
|
|
93
|
+
async function refresh($: EngineInterface): Promise<void> {
|
|
94
|
+
const now = await $.clock.now()
|
|
95
|
+
const wait = lastMeasured + MEASURE_GAP_MS - now
|
|
96
|
+
if (wait > 0) {
|
|
97
|
+
if (isScheduled) return
|
|
98
|
+
isScheduled = true
|
|
99
|
+
$.clock.after(wait, () => {
|
|
100
|
+
isScheduled = false
|
|
101
|
+
void refresh($)
|
|
102
|
+
})
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
lastMeasured = now
|
|
106
|
+
const snap = await measure($).catch(() => null)
|
|
107
|
+
if (snap !== null) await update($, snapshot, () => snap)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const register: Register = on => {
|
|
111
|
+
on('session.start', async ($, e, next) => {
|
|
112
|
+
await $.command.register({ name: 'context-bar', description: 'Show or hide the context window bar' })
|
|
113
|
+
void $.ui.open({ id: PANE, title: TITLE })
|
|
114
|
+
void refresh($)
|
|
115
|
+
return next(e)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
on('command.run', { command: 'context-bar' }, async $ => {
|
|
119
|
+
const isOpen = (await $.ui.panes()).some(pane => pane.id === PANE)
|
|
120
|
+
if (isOpen) {
|
|
121
|
+
await $.ui.close({ id: PANE })
|
|
122
|
+
return { text: 'Context bar hidden.' }
|
|
123
|
+
}
|
|
124
|
+
await $.ui.open({ id: PANE, title: TITLE })
|
|
125
|
+
await refresh($)
|
|
126
|
+
return { text: 'Context bar shown.' }
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
on('session.measure', async ($, e, next) => {
|
|
130
|
+
const result = await next(e)
|
|
131
|
+
void refresh($)
|
|
132
|
+
return result
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
on('turn.complete', async ($, e, next) => {
|
|
136
|
+
const result = await next(e)
|
|
137
|
+
if (e.agentId === undefined) void refresh($)
|
|
138
|
+
return result
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
|
|
142
|
+
const snap = await read($, snapshot)
|
|
143
|
+
const { Box, Text } = $.ui.resolve(e)
|
|
144
|
+
if (snap === null) return <Text dimColor>No context measured yet. It fills in after the first reply.</Text>
|
|
145
|
+
|
|
146
|
+
const columns = Math.max(24, e.props.bodyColumns)
|
|
147
|
+
const used = percentOf(snap.used, snap.window)
|
|
148
|
+
const compacts = snap.compactAt === undefined ? '' : ` · compacts at ${formatTokens(snap.compactAt)}`
|
|
149
|
+
|
|
150
|
+
let bar
|
|
151
|
+
if (e.surface === 'terminal') {
|
|
152
|
+
const cells = snap.rows.map(row => ({ row, n: Math.round((row.tokens / Math.max(1, snap.window)) * columns) }))
|
|
153
|
+
bar = <Text>{cells.map(({ row, n }) => <Text color={row.color}>{'█'.repeat(n)}</Text>)}</Text>
|
|
154
|
+
} else {
|
|
155
|
+
const { Svg } = $.ui.resolve(e)
|
|
156
|
+
const width = columns * CELL_PX
|
|
157
|
+
bar = <Svg source={barSvg(snap, width)} alt={`context ${used}% used`} width={width} height={14} />
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<Box flexDirection="column" gap={1}>
|
|
162
|
+
<Box flexDirection="row" justifyContent="space-between">
|
|
163
|
+
<Text>
|
|
164
|
+
<Text color="#e0775a">◆ </Text>
|
|
165
|
+
<Text bold>context window</Text>
|
|
166
|
+
</Text>
|
|
167
|
+
<Text>
|
|
168
|
+
<Text bold>{formatTokens(snap.used)}</Text>
|
|
169
|
+
<Text dimColor> of {formatTokens(snap.window)}{compacts} </Text>
|
|
170
|
+
<Text bold color="#9be39f" backgroundColor="#2f4a33"> {used}% </Text>
|
|
171
|
+
</Text>
|
|
172
|
+
</Box>
|
|
173
|
+
{bar}
|
|
174
|
+
<Box flexDirection="row" flexWrap="wrap" columnGap={3}>
|
|
175
|
+
{snap.rows.map(row => (
|
|
176
|
+
<Text>
|
|
177
|
+
<Text color={row.color}>■ </Text>
|
|
178
|
+
<Text dimColor={row.label === 'free'}>{row.label} </Text>
|
|
179
|
+
<Text bold={row.label !== 'free'} dimColor={row.label === 'free'}>{formatTokens(row.tokens)}</Text>
|
|
180
|
+
{row.label === 'free' ? '' : <Text dimColor> {percentOf(row.tokens, snap.window)}%</Text>}
|
|
181
|
+
</Text>
|
|
182
|
+
))}
|
|
183
|
+
</Box>
|
|
184
|
+
</Box>
|
|
185
|
+
)
|
|
186
|
+
})
|
|
187
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// packages/g3n-mods/mods/context-bar/types/index.d.ts
|
|
2
|
+
|
|
3
|
+
/** One source of context use as the bar draws it, e.g. `{ label: "mcp tools", tokens: 52000, color: "#9b87f5" }`. */
|
|
4
|
+
export type ContextRow = {
|
|
5
|
+
label: string
|
|
6
|
+
tokens: number
|
|
7
|
+
color: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** The context window as last measured: what each source uses, the window and where compaction runs. */
|
|
11
|
+
export type ContextSnapshot = {
|
|
12
|
+
rows: ContextRow[]
|
|
13
|
+
used: number
|
|
14
|
+
window: number
|
|
15
|
+
/** Token count at which auto-compaction runs; absent when it is off */
|
|
16
|
+
compactAt?: number
|
|
17
|
+
/** Milliseconds since the epoch */
|
|
18
|
+
measuredAt: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module 'claude-code' {
|
|
22
|
+
interface PluginState {
|
|
23
|
+
'context-bar': { snapshot: ContextSnapshot | null }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "modules": ["./register.tsx"] }
|