@gtheys/pi-aven-context 0.0.0-stage → 0.2.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/README.md +20 -2
- package/index.ts +114 -0
- package/package.json +31 -4
package/README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pi-aven-context
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Pi extension that injects live [aven](https://aven.cli) workspace state as session-start context.
|
|
4
|
+
|
|
5
|
+
At each new session start it runs `aven prime` from the session's working directory (aven infers the workspace and project from its cwd routes) and appends the live portion — local conventions, open issues, active/ready/blocked breakdown — as a hidden custom message that participates in LLM context.
|
|
6
|
+
|
|
7
|
+
The static CLI primer head is stripped: that reference is already available via the aven skill, so injecting it every session would burn tokens for nothing.
|
|
8
|
+
|
|
9
|
+
## Behavior
|
|
10
|
+
|
|
11
|
+
- **Non-fatal** — a missing or slow `aven` binary silently skips injection; startup never breaks.
|
|
12
|
+
- **Idempotent** — sessions resumed/forked/reloaded skip injection if an aven-context entry already exists in the branch, so context is never duplicated.
|
|
13
|
+
- **Child-session gate** — sessions spawned as background subagents (detected via `PI_SUBAGENT_ID`, set by [pi-interactive-subagents](../pi-interactive-subagents/) on every spawn) never inject the workspace blob. Parent/interactive sessions still inject once per session, with the existing resume/fork dedup.
|
|
14
|
+
|
|
15
|
+
### Why the child gate exists
|
|
16
|
+
|
|
17
|
+
The injected blob is fully dynamic — it changes on every `aven prime` run. Making it the first message of a child subagent's message stream would change that stream's prefix on every spawn, defeating provider prompt caching of the static guidance that follows. Skipping injection in child sessions keeps their prompt prefix stable.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Load the repo package per the [quickstart](../../openwiki/quickstart.md); the extension registers itself, no commands or config.
|
package/index.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aven Context Extension
|
|
3
|
+
*
|
|
4
|
+
* Injects live aven workspace state (open issues, active/ready/blocked tasks)
|
|
5
|
+
* as a hidden custom message at session start, so the agent begins with
|
|
6
|
+
* current task context. Runs `aven prime` from the session cwd (aven infers
|
|
7
|
+
* workspace + project from cwd routing) and strips the static CLI primer
|
|
8
|
+
* head — the primer is already available statically via the aven skill.
|
|
9
|
+
*
|
|
10
|
+
* Non-fatal: a missing/slow aven binary silently skips injection.
|
|
11
|
+
* Idempotent: skips if the session already carries an aven-context entry
|
|
12
|
+
* (resume/fork/reload reuse the existing entry instead of duplicating it).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { execFile } from 'node:child_process'
|
|
16
|
+
import { promisify } from 'node:util'
|
|
17
|
+
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent'
|
|
18
|
+
|
|
19
|
+
const execFileAsync = promisify(execFile)
|
|
20
|
+
|
|
21
|
+
const CUSTOM_TYPE = 'aven-context'
|
|
22
|
+
// ponytail: brittle string marker — if aven renames the section, stripPrimer
|
|
23
|
+
// returns '' and we skip injection rather than dump 200 lines of static primer
|
|
24
|
+
const PRIMER_MARKER = '## Local Conventions'
|
|
25
|
+
const AVEN_TIMEOUT_MS = 5_000
|
|
26
|
+
|
|
27
|
+
// AIDEV-NOTE: cache boundary — a dynamic blob at the front of a child's
|
|
28
|
+
// message stream defeats provider prompt caching, so children never inject.
|
|
29
|
+
// AIDEV-NOTE: prime output = static CLI primer + live workspace sections.
|
|
30
|
+
// Only the tail from "## Local Conventions" onward belongs in session context.
|
|
31
|
+
export function stripPrimer(primeOutput: string): string {
|
|
32
|
+
const idx = primeOutput.indexOf(PRIMER_MARKER)
|
|
33
|
+
if (idx === -1) return ''
|
|
34
|
+
return primeOutput.slice(idx).trim()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// AIDEV-NOTE: pure gate so it is testable without touching process.env.
|
|
38
|
+
export function isChildSession(
|
|
39
|
+
env: Record<string, string | undefined>,
|
|
40
|
+
): boolean {
|
|
41
|
+
const value = env.PI_SUBAGENT_ID
|
|
42
|
+
return typeof value === 'string' && value !== ''
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface MaybeInjectAvenContextDeps {
|
|
46
|
+
env: Record<string, string | undefined>
|
|
47
|
+
runPrime: () => Promise<string>
|
|
48
|
+
branchHasAvenContext: () => boolean
|
|
49
|
+
sendCustomMessage: (content: string) => void
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function maybeInjectAvenContext(
|
|
53
|
+
deps: MaybeInjectAvenContextDeps,
|
|
54
|
+
): Promise<boolean> {
|
|
55
|
+
if (isChildSession(deps.env)) return false
|
|
56
|
+
if (deps.branchHasAvenContext()) return false
|
|
57
|
+
|
|
58
|
+
let primeOutput: string
|
|
59
|
+
try {
|
|
60
|
+
primeOutput = await deps.runPrime()
|
|
61
|
+
} catch {
|
|
62
|
+
// aven missing, db locked, or timed out — context injection never
|
|
63
|
+
// blocks or breaks session startup.
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const context = stripPrimer(primeOutput)
|
|
68
|
+
if (!context) return false
|
|
69
|
+
|
|
70
|
+
const content = [
|
|
71
|
+
'Aven workspace state (live, from `aven prime`):',
|
|
72
|
+
'',
|
|
73
|
+
context,
|
|
74
|
+
'',
|
|
75
|
+
'Aven CLI reference: see the aven skill.',
|
|
76
|
+
].join('\n')
|
|
77
|
+
deps.sendCustomMessage(content)
|
|
78
|
+
return true
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default function (pi: ExtensionAPI) {
|
|
82
|
+
pi.on('session_start', async (_event, ctx) => {
|
|
83
|
+
// AIDEV-NOTE: getBranch() walks leaf→root, so this also covers sessions
|
|
84
|
+
// resumed/forked from a session that already had context injected.
|
|
85
|
+
await maybeInjectAvenContext({
|
|
86
|
+
env: process.env,
|
|
87
|
+
runPrime: async () => {
|
|
88
|
+
const r = await execFileAsync('aven', ['prime'], {
|
|
89
|
+
cwd: ctx.cwd,
|
|
90
|
+
timeout: AVEN_TIMEOUT_MS,
|
|
91
|
+
})
|
|
92
|
+
return r.stdout
|
|
93
|
+
},
|
|
94
|
+
branchHasAvenContext: () =>
|
|
95
|
+
ctx.sessionManager
|
|
96
|
+
.getBranch()
|
|
97
|
+
.some(
|
|
98
|
+
(e) => e.type === 'custom_message' && e.customType === CUSTOM_TYPE,
|
|
99
|
+
),
|
|
100
|
+
// AIDEV-NOTE: pi.sendMessage appends a custom_message entry (participates
|
|
101
|
+
// in LLM context); triggerTurn:false keeps injection passive — no agent run.
|
|
102
|
+
sendCustomMessage: (content) => {
|
|
103
|
+
pi.sendMessage(
|
|
104
|
+
{
|
|
105
|
+
customType: CUSTOM_TYPE,
|
|
106
|
+
content,
|
|
107
|
+
display: false,
|
|
108
|
+
},
|
|
109
|
+
{ triggerTurn: false },
|
|
110
|
+
)
|
|
111
|
+
},
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtheys/pi-aven-context",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Pi extension that injects live aven workspace state (open issues, active/ready/blocked tasks) as session-start context",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"pi-package"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/gtheys/pi-my-rifle-ext.git",
|
|
13
|
+
"directory": "packages/pi-aven-context"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.ts",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "bun test"
|
|
24
|
+
},
|
|
25
|
+
"pi": {
|
|
26
|
+
"extensions": [
|
|
27
|
+
"./index.ts"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
32
|
+
}
|
|
33
|
+
}
|