@gramatr/mcp 0.7.15 → 0.7.17
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/gramatr +0 -0
- package/dist/hooks/lib/client-runtime.d.ts +1 -1
- package/dist/hooks/lib/client-runtime.d.ts.map +1 -1
- package/dist/hooks/lib/client-runtime.js +9 -5
- package/dist/hooks/lib/client-runtime.js.map +1 -1
- package/dist/hooks/lib/intelligence.d.ts.map +1 -1
- package/dist/hooks/lib/intelligence.js +10 -8
- package/dist/hooks/lib/intelligence.js.map +1 -1
- package/dist/hooks/lib/packet-debug-log.d.ts +31 -0
- package/dist/hooks/lib/packet-debug-log.d.ts.map +1 -0
- package/dist/hooks/lib/packet-debug-log.js +50 -0
- package/dist/hooks/lib/packet-debug-log.js.map +1 -0
- package/dist/hooks/lib/routing.d.ts +1 -0
- package/dist/hooks/lib/routing.d.ts.map +1 -1
- package/dist/hooks/lib/routing.js +1 -0
- package/dist/hooks/lib/routing.js.map +1 -1
- package/dist/hooks/lib/types.d.ts +36 -0
- package/dist/hooks/lib/types.d.ts.map +1 -1
- package/dist/hooks/session-start.d.ts.map +1 -1
- package/dist/hooks/session-start.js +12 -3
- package/dist/hooks/session-start.js.map +1 -1
- package/dist/hooks/user-prompt-submit.d.ts.map +1 -1
- package/dist/hooks/user-prompt-submit.js +48 -14
- package/dist/hooks/user-prompt-submit.js.map +1 -1
- package/dist/proxy/local-client.d.ts +15 -36
- package/dist/proxy/local-client.d.ts.map +1 -1
- package/dist/proxy/local-client.js +18 -116
- package/dist/proxy/local-client.js.map +1 -1
- package/dist/setup/instructions.d.ts +2 -2
- package/dist/setup/instructions.d.ts.map +1 -1
- package/dist/setup/instructions.js +79 -55
- package/dist/setup/instructions.js.map +1 -1
- package/dist/setup/integrations.d.ts.map +1 -1
- package/dist/setup/integrations.js +31 -17
- package/dist/setup/integrations.js.map +1 -1
- package/dist/setup/web-connector.d.ts.map +1 -1
- package/dist/setup/web-connector.js +4 -3
- package/dist/setup/web-connector.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,14 +4,15 @@ import { emitStatus, formatFailureWarning, formatIntelligence, mergeEnrichmentIn
|
|
|
4
4
|
import { fetchEnrichment, persistClassificationResult, routePrompt, shouldSkipPromptRouting, } from './lib/routing.js';
|
|
5
5
|
import { appendOpHistory, appendTurn, getSessionContext, hydrateSessionContextFromServer, isFilesystemAvailable, setLatestClassification, } from './lib/hook-state.js';
|
|
6
6
|
import { resolveHookClientRuntime } from './lib/client-runtime.js';
|
|
7
|
+
import { appendPacketDebugLog } from './lib/packet-debug-log.js';
|
|
7
8
|
let turnCounter = 0;
|
|
8
|
-
const TIMEOUT_MS = getGramatrTimeoutFromEnv(
|
|
9
|
+
const TIMEOUT_MS = getGramatrTimeoutFromEnv(60000);
|
|
9
10
|
const ENABLED = isGramatrEnrichEnabledFromEnv();
|
|
10
11
|
const PACKET_MODE = getGramatrPacketModeFromEnv();
|
|
11
12
|
const PACKET2_WAIT_MS = getGramatrPacket2WaitMsFromEnv(20000);
|
|
12
|
-
const HOOK_ROUTE_TIMEOUT_CAP_MS =
|
|
13
|
-
const HOOK_PACKET2_TIMEOUT_CAP_MS =
|
|
14
|
-
const HOOK_PACKET2_WAIT_CAP_MS =
|
|
13
|
+
const HOOK_ROUTE_TIMEOUT_CAP_MS = 60000;
|
|
14
|
+
const HOOK_PACKET2_TIMEOUT_CAP_MS = 15000;
|
|
15
|
+
const HOOK_PACKET2_WAIT_CAP_MS = 20000;
|
|
15
16
|
const HOOK_PACKET2_POLL_MS = 500;
|
|
16
17
|
function persistLastClassification(prompt, sessionId, route, downstreamModel, clientType, agentName) {
|
|
17
18
|
try {
|
|
@@ -73,32 +74,63 @@ export async function runUserPromptSubmitHook(_args = []) {
|
|
|
73
74
|
sessionContext = getSessionContext(sessionId);
|
|
74
75
|
}
|
|
75
76
|
const projectId = sessionContext?.project_id || (git ? deriveProjectId(git.remote, git.projectName) : null) || undefined;
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
const gramatrSessionId =
|
|
77
|
+
// gramatr interaction_id is the cross-agent session key — use it for
|
|
78
|
+
// both session_id (server history) and interaction_id (explicit resolution).
|
|
79
|
+
const gramatrInteractionId = sessionContext?.interaction_id || null;
|
|
80
|
+
const gramatrSessionId = gramatrInteractionId || sessionId;
|
|
80
81
|
process.stderr.write('[gramatr] classifying...\n');
|
|
81
82
|
const t0 = Date.now();
|
|
82
83
|
const routed = await routePrompt({
|
|
83
84
|
prompt,
|
|
84
85
|
projectId,
|
|
85
86
|
sessionId: gramatrSessionId,
|
|
87
|
+
interactionId: gramatrInteractionId || undefined,
|
|
86
88
|
timeoutMs: Math.min(TIMEOUT_MS, HOOK_ROUTE_TIMEOUT_CAP_MS),
|
|
87
89
|
});
|
|
88
90
|
const result = routed.route;
|
|
89
91
|
const elapsed = Date.now() - t0;
|
|
92
|
+
const isV2 = result?.schema === 'gmtr.intelligence.contract.v2';
|
|
90
93
|
let lastFailure = null;
|
|
91
94
|
if (!result && routed.error) {
|
|
92
95
|
lastFailure = mapRoutingFailure(routed.error.reason, routed.error.detail);
|
|
93
96
|
}
|
|
97
|
+
// Debug log — rolling 100-entry JSONL at ~/.gramatr/debug/packets.jsonl
|
|
98
|
+
appendPacketDebugLog({
|
|
99
|
+
ts: new Date().toISOString(),
|
|
100
|
+
project_id: projectId ?? null,
|
|
101
|
+
session_id: gramatrSessionId,
|
|
102
|
+
client_type: runtime.clientType,
|
|
103
|
+
agent_name: runtime.agentName,
|
|
104
|
+
downstream_model: downstreamModel,
|
|
105
|
+
status: !result && routed.error
|
|
106
|
+
? (routed.error.reason === 'timeout' ? 'timeout' : 'error')
|
|
107
|
+
: result ? 'ok' : 'skipped',
|
|
108
|
+
elapsed_ms: elapsed,
|
|
109
|
+
packet: result ?? null,
|
|
110
|
+
error: routed.error ? { reason: routed.error.reason, detail: routed.error.detail } : null,
|
|
111
|
+
});
|
|
94
112
|
let enrichment = null;
|
|
95
113
|
const packet1 = result?.packet_1;
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
114
|
+
// v2: manifest is a top-level field; v1: it's nested under packet_1
|
|
115
|
+
const manifest = isV2 ? result?.manifest : (packet1?.manifest || result);
|
|
116
|
+
// v2: token_savings lives under result.execution; v1: under packet_1 or result directly
|
|
117
|
+
const packetTokenSavings = packet1?.token_savings
|
|
118
|
+
|| (isV2 ? result?.execution?.token_savings : result?.token_savings)
|
|
119
|
+
|| {};
|
|
120
|
+
const packet2Required = Boolean(
|
|
121
|
+
// v2: enrichment.required is the canonical signal
|
|
122
|
+
result?.enrichment?.required === true
|
|
123
|
+
// v1 fallbacks
|
|
124
|
+
|| result?.packet_2?.required === true
|
|
125
|
+
|| manifest?.packet_2_status === 'required'
|
|
126
|
+
|| manifest?.packet_2_required === true);
|
|
127
|
+
const enrichmentId = result?.enrichment?.enrichment_id
|
|
128
|
+
|| result?.packet_2?.enrichment_id
|
|
129
|
+
|| manifest?.enrichment_id;
|
|
130
|
+
if (result && packet2Required && enrichmentId) {
|
|
131
|
+
enrichment = await fetchEnrichment(enrichmentId, {
|
|
100
132
|
mode: PACKET_MODE,
|
|
101
|
-
timeoutMs:
|
|
133
|
+
timeoutMs: HOOK_PACKET2_TIMEOUT_CAP_MS,
|
|
102
134
|
waitMs: Math.min(PACKET2_WAIT_MS, HOOK_PACKET2_WAIT_CAP_MS),
|
|
103
135
|
pollMs: HOOK_PACKET2_POLL_MS,
|
|
104
136
|
});
|
|
@@ -121,7 +153,9 @@ export async function runUserPromptSubmitHook(_args = []) {
|
|
|
121
153
|
effort: cl.effort_level || null,
|
|
122
154
|
intent: cl.intent_type || null,
|
|
123
155
|
confidence: cl.confidence ?? null,
|
|
124
|
-
memory_delivered:
|
|
156
|
+
memory_delivered: isV2
|
|
157
|
+
? (result?.memory?.search_results?.length ?? null)
|
|
158
|
+
: ((packet1?.memory_context || result?.memory_context)?.results?.length ?? null),
|
|
125
159
|
downstream_model: downstreamModel || null,
|
|
126
160
|
server_version: es.server_version || null,
|
|
127
161
|
stage_timing: es.stage_timing ? JSON.stringify(es.stage_timing) : null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-prompt-submit.js","sourceRoot":"","sources":["../../src/hooks/user-prompt-submit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,8BAA8B,EAC9B,2BAA2B,EAC3B,wBAAwB,EACxB,6BAA6B,GAC9B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,eAAe,EACf,aAAa,EACb,aAAa,GACd,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,GAEzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,eAAe,EACf,2BAA2B,EAC3B,WAAW,EACX,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,+BAA+B,EAC/B,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"user-prompt-submit.js","sourceRoot":"","sources":["../../src/hooks/user-prompt-submit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,8BAA8B,EAC9B,2BAA2B,EAC3B,wBAAwB,EACxB,6BAA6B,GAC9B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,eAAe,EACf,aAAa,EACb,aAAa,GACd,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,GAEzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,eAAe,EACf,2BAA2B,EAC3B,WAAW,EACX,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL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E,kBAAkB;wBACjC,iBAAiB,EAAE,oBAAoB,CAAC,WAAW,CAAC;qBACrD;iBACF,CAAC,CAAC,CAAC;YACN,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;YAC3C,CAAC;YACD,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;YAClC,kBAAkB,EAAE;gBAClB,aAAa,EAAE,kBAAkB;gBACjC,iBAAiB,EAAE,kBAAkB,CAAC,MAAM,EAAE,UAAU,CAAC;aAC1D;SACF,CAAC,CAAC,CAAC;QACJ,OAAO,CAAC,CAAC;IACX,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QACzC,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC"}
|
|
@@ -1,49 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* local-client.ts — Hook-side client for
|
|
2
|
+
* local-client.ts — Hook-side client for gramatr tool calls.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* MCP server when it is running, falling back to direct remote calls otherwise.
|
|
4
|
+
* Hooks call gramatr tools directly through the remote API via callRemoteTool.
|
|
5
|
+
* The compiled binary owns auth resolution — no port-based local HTTP server needed.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* → data shape validated before any remote call
|
|
12
|
-
* 2. Direct remote (callRemoteTool from remote-client.ts)
|
|
13
|
-
* → hooks resolve their own auth token as before
|
|
14
|
-
*
|
|
15
|
-
* The local server's port file is read once per hook process lifetime and
|
|
16
|
-
* cached. Stale port files (server crashed without cleanup) are caught by a
|
|
17
|
-
* connection error on first use, which clears the cache and falls through to
|
|
18
|
-
* direct remote.
|
|
7
|
+
* Session context (project_id, interaction_id) is managed locally via SQLite
|
|
8
|
+
* in hook-state.ts. pushSessionContextToLocal / pullSessionContextFromLocal
|
|
9
|
+
* are retained as no-ops for call-site compatibility while the port IPC is removed.
|
|
19
10
|
*/
|
|
20
|
-
/**
|
|
11
|
+
/** Always false — port-based local server is no longer used. */
|
|
21
12
|
export declare function isLocalHooksServerAvailable(): boolean;
|
|
22
13
|
/**
|
|
23
|
-
* Call a gramatr tool
|
|
24
|
-
*
|
|
25
|
-
* The local server injects auth and enforces data shapes before forwarding to
|
|
26
|
-
* the remote API. If the local server is unavailable or returns an error,
|
|
27
|
-
* falls back to a direct remote call via callRemoteTool.
|
|
14
|
+
* Call a gramatr tool via the remote API.
|
|
15
|
+
* Auth is resolved by the compiled binary's auth module.
|
|
28
16
|
*/
|
|
29
17
|
export declare function callTool(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
30
18
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* Called by the session-start hook after setSessionContext() so later hook
|
|
34
|
-
* processes (user-prompt-submit, session-end) can read the context without
|
|
35
|
-
* hitting the SQLite file or the remote REST API.
|
|
36
|
-
*
|
|
37
|
-
* Returns true if the write was acknowledged. A false return is non-fatal —
|
|
38
|
-
* later hooks fall back to SQLite → remote REST.
|
|
19
|
+
* No-op — session context is persisted to SQLite via setSessionContext in hook-state.ts.
|
|
20
|
+
* Retained for call-site compatibility.
|
|
39
21
|
*/
|
|
40
|
-
export declare function pushSessionContextToLocal(
|
|
22
|
+
export declare function pushSessionContextToLocal(_ctx: unknown): Promise<boolean>;
|
|
41
23
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* Returns the stored context for the given session_id, or the most recently
|
|
45
|
-
* written context as a fallback. Returns null if the local server is
|
|
46
|
-
* unavailable or has no context for this session.
|
|
24
|
+
* No-op — callers fall through to remote REST hydration via hydrateSessionContextFromServer.
|
|
25
|
+
* Retained for call-site compatibility.
|
|
47
26
|
*/
|
|
48
|
-
export declare function pullSessionContextFromLocal(
|
|
27
|
+
export declare function pullSessionContextFromLocal(_sessionId: string): Promise<Record<string, unknown> | null>;
|
|
49
28
|
//# sourceMappingURL=local-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-client.d.ts","sourceRoot":"","sources":["../../src/proxy/local-client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"local-client.d.ts","sourceRoot":"","sources":["../../src/proxy/local-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,gEAAgE;AAChE,wBAAgB,2BAA2B,IAAI,OAAO,CAErD;AAED;;;GAGG;AACH,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,OAAO,CAAC,CAElB;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAE/E;AAED;;;GAGG;AACH,wBAAsB,2BAA2B,CAC/C,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAEzC"}
|
|
@@ -1,135 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* local-client.ts — Hook-side client for
|
|
2
|
+
* local-client.ts — Hook-side client for gramatr tool calls.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* MCP server when it is running, falling back to direct remote calls otherwise.
|
|
4
|
+
* Hooks call gramatr tools directly through the remote API via callRemoteTool.
|
|
5
|
+
* The compiled binary owns auth resolution — no port-based local HTTP server needed.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* → data shape validated before any remote call
|
|
12
|
-
* 2. Direct remote (callRemoteTool from remote-client.ts)
|
|
13
|
-
* → hooks resolve their own auth token as before
|
|
14
|
-
*
|
|
15
|
-
* The local server's port file is read once per hook process lifetime and
|
|
16
|
-
* cached. Stale port files (server crashed without cleanup) are caught by a
|
|
17
|
-
* connection error on first use, which clears the cache and falls through to
|
|
18
|
-
* direct remote.
|
|
7
|
+
* Session context (project_id, interaction_id) is managed locally via SQLite
|
|
8
|
+
* in hook-state.ts. pushSessionContextToLocal / pullSessionContextFromLocal
|
|
9
|
+
* are retained as no-ops for call-site compatibility while the port IPC is removed.
|
|
19
10
|
*/
|
|
20
|
-
import { readFileSync } from 'node:fs';
|
|
21
|
-
import { join } from 'node:path';
|
|
22
|
-
import { getGramatrDirFromEnv, getHomeDir } from '../config-runtime.js';
|
|
23
11
|
import { callRemoteTool } from './remote-client.js';
|
|
24
|
-
|
|
25
|
-
function getPortFilePath() {
|
|
26
|
-
const dir = getGramatrDirFromEnv() || join(getHomeDir(), '.gramatr');
|
|
27
|
-
return join(dir, '.hooks-port');
|
|
28
|
-
}
|
|
29
|
-
// undefined = not yet read; null = not available; number = available
|
|
30
|
-
let _cachedPort = undefined;
|
|
31
|
-
function getLocalPort() {
|
|
32
|
-
if (_cachedPort !== undefined)
|
|
33
|
-
return _cachedPort;
|
|
34
|
-
try {
|
|
35
|
-
const raw = readFileSync(getPortFilePath(), 'utf8').trim();
|
|
36
|
-
const port = parseInt(raw, 10);
|
|
37
|
-
_cachedPort = Number.isFinite(port) && port > 0 ? port : null;
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
_cachedPort = null;
|
|
41
|
-
}
|
|
42
|
-
return _cachedPort;
|
|
43
|
-
}
|
|
44
|
-
/** True when the local hooks server port file exists and contains a valid port. */
|
|
12
|
+
/** Always false — port-based local server is no longer used. */
|
|
45
13
|
export function isLocalHooksServerAvailable() {
|
|
46
|
-
return
|
|
14
|
+
return false;
|
|
47
15
|
}
|
|
48
|
-
// ── Tool call proxy ──
|
|
49
16
|
/**
|
|
50
|
-
* Call a gramatr tool
|
|
51
|
-
*
|
|
52
|
-
* The local server injects auth and enforces data shapes before forwarding to
|
|
53
|
-
* the remote API. If the local server is unavailable or returns an error,
|
|
54
|
-
* falls back to a direct remote call via callRemoteTool.
|
|
17
|
+
* Call a gramatr tool via the remote API.
|
|
18
|
+
* Auth is resolved by the compiled binary's auth module.
|
|
55
19
|
*/
|
|
56
20
|
export async function callTool(name, args) {
|
|
57
|
-
const port = getLocalPort();
|
|
58
|
-
if (port !== null) {
|
|
59
|
-
try {
|
|
60
|
-
const res = await fetch(`http://127.0.0.1:${port}/hooks/tool`, {
|
|
61
|
-
method: 'POST',
|
|
62
|
-
headers: { 'Content-Type': 'application/json' },
|
|
63
|
-
body: JSON.stringify({ name, args }),
|
|
64
|
-
signal: AbortSignal.timeout(30000),
|
|
65
|
-
});
|
|
66
|
-
// gramatr-allow: B1 — HTTP transport sentinel, caught immediately in the enclosing try/catch
|
|
67
|
-
if (!res.ok)
|
|
68
|
-
throw new Error(`HTTP ${res.status}`);
|
|
69
|
-
const data = await res.json();
|
|
70
|
-
// gramatr-allow: B1 — error string forwarded from local server, caught immediately in the enclosing try/catch
|
|
71
|
-
if (data.error)
|
|
72
|
-
throw new Error(data.error);
|
|
73
|
-
return data.result;
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
// Local server failed (stale port file, crash, etc.) — invalidate cache
|
|
77
|
-
// and fall through to direct remote.
|
|
78
|
-
_cachedPort = null;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
21
|
return callRemoteTool(name, args);
|
|
82
22
|
}
|
|
83
|
-
// ── Session context IPC ──
|
|
84
23
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* Called by the session-start hook after setSessionContext() so later hook
|
|
88
|
-
* processes (user-prompt-submit, session-end) can read the context without
|
|
89
|
-
* hitting the SQLite file or the remote REST API.
|
|
90
|
-
*
|
|
91
|
-
* Returns true if the write was acknowledged. A false return is non-fatal —
|
|
92
|
-
* later hooks fall back to SQLite → remote REST.
|
|
24
|
+
* No-op — session context is persisted to SQLite via setSessionContext in hook-state.ts.
|
|
25
|
+
* Retained for call-site compatibility.
|
|
93
26
|
*/
|
|
94
|
-
export async function pushSessionContextToLocal(
|
|
95
|
-
|
|
96
|
-
if (port === null)
|
|
97
|
-
return false;
|
|
98
|
-
try {
|
|
99
|
-
const res = await fetch(`http://127.0.0.1:${port}/hooks/session`, {
|
|
100
|
-
method: 'POST',
|
|
101
|
-
headers: { 'Content-Type': 'application/json' },
|
|
102
|
-
body: JSON.stringify(ctx),
|
|
103
|
-
signal: AbortSignal.timeout(3000),
|
|
104
|
-
});
|
|
105
|
-
return res.ok;
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
_cachedPort = null; // Invalidate on connection failure
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
27
|
+
export async function pushSessionContextToLocal(_ctx) {
|
|
28
|
+
return false;
|
|
111
29
|
}
|
|
112
30
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* Returns the stored context for the given session_id, or the most recently
|
|
116
|
-
* written context as a fallback. Returns null if the local server is
|
|
117
|
-
* unavailable or has no context for this session.
|
|
31
|
+
* No-op — callers fall through to remote REST hydration via hydrateSessionContextFromServer.
|
|
32
|
+
* Retained for call-site compatibility.
|
|
118
33
|
*/
|
|
119
|
-
export async function pullSessionContextFromLocal(
|
|
120
|
-
|
|
121
|
-
if (port === null)
|
|
122
|
-
return null;
|
|
123
|
-
try {
|
|
124
|
-
const res = await fetch(`http://127.0.0.1:${port}/hooks/session?session_id=${encodeURIComponent(sessionId)}`, { signal: AbortSignal.timeout(3000) });
|
|
125
|
-
if (!res.ok)
|
|
126
|
-
return null;
|
|
127
|
-
const data = await res.json();
|
|
128
|
-
return data.ctx;
|
|
129
|
-
}
|
|
130
|
-
catch {
|
|
131
|
-
_cachedPort = null;
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
34
|
+
export async function pullSessionContextFromLocal(_sessionId) {
|
|
35
|
+
return null;
|
|
134
36
|
}
|
|
135
37
|
//# sourceMappingURL=local-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-client.js","sourceRoot":"","sources":["../../src/proxy/local-client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"local-client.js","sourceRoot":"","sources":["../../src/proxy/local-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,gEAAgE;AAChE,MAAM,UAAU,2BAA2B;IACzC,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,IAAY,EACZ,IAA6B;IAE7B,OAAO,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,IAAa;IAC3D,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,UAAkB;IAElB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -3,7 +3,7 @@ export declare const CLAUDE_BLOCK_END = "<!-- GRAMATR-END -->";
|
|
|
3
3
|
export declare const CODEX_BLOCK_START = "<!-- GRAMATR-CODEX-START -->";
|
|
4
4
|
export declare const CODEX_BLOCK_END = "<!-- GRAMATR-CODEX-END -->";
|
|
5
5
|
export type InstallPromptTarget = 'claude-code' | 'codex' | 'gemini-cli' | 'claude-desktop' | 'chatgpt-desktop' | 'cursor' | 'windsurf' | 'vscode';
|
|
6
|
-
export declare const CLAUDE_CODE_GUIDANCE = "<!-- GRAMATR-START -->\n# gramatr\n\nYou have gramatr installed.
|
|
7
|
-
export declare const CODEX_GUIDANCE = "<!-- GRAMATR-CODEX-START -->\n# gramatr codex guidance\n\n## Repo Expectations\n\n- Prefer gramatr memory and project handoff context over ad hoc local summaries.\n- Treat Codex hook augmentation as authoritative when a gramatr
|
|
6
|
+
export declare const CLAUDE_CODE_GUIDANCE = "<!-- GRAMATR-START -->\n# gramatr\n\nYou have gramatr installed. Hooks inject a `gmtr.intelligence.contract.v2`\npacket into your context on every prompt.\n\n**Follow the packet.** It contains classification, behavioral directives,\nphase templates, capability audit, quality gates, memory/search results,\nagent suggestions, and enrichment (RE + ISC scaffold).\n\n**Mandatory fields:**\n- `directives.hard_gates` \u2014 non-negotiable behavioral constraints\n- `directives.behavioral_rules` \u2014 algorithm phases, code rules, safety rules\n- `process.phase_template` \u2014 effort-gated phase sequence\n- `process.quality_gate_config` \u2014 ISC verification rules\n- `enrichment.data.reasoning` \u2014 RE + ISC when present\n\n**Memory:** Use gramatr MCP tools (`search_semantic`, `create_entity`,\n`add_observation`), not local markdown files.\n\n**Sub-agent composition:** Before launching any sub-agent for non-trivial work,\ncall `gramatr_route_request` with the task prompt first. Use the returned\npacket to compose the brief: RE \u2192 task description, ISC scaffold \u2192 acceptance\ncriteria, orchestration.agents.composed \u2192 agent system prompt, hard_gates \u2192\nconstraints.\n\n**Effort-gated phases:**\n- instant: RESPOND only\n- fast: OBSERVE \u2192 RESPOND\n- standard: OBSERVE \u2192 PLAN \u2192 BUILD \u2192 VERIFY\n- extended+: OBSERVE \u2192 THINK \u2192 PLAN \u2192 BUILD \u2192 EXECUTE \u2192 VERIFY \u2192 LEARN\n\n**Identity:** Read from `~/.gramatr/settings.json` \u2014 `daidentity` for your\nname, `principal` for the user's name.\n\n**If the server is unavailable:** Degrade cleanly and keep working. Use the\n7-phase structure. Create ISC before work. Never combine phases.\n<!-- GRAMATR-END -->\n";
|
|
7
|
+
export declare const CODEX_GUIDANCE = "<!-- GRAMATR-CODEX-START -->\n# gramatr codex guidance\n\n## Repo Expectations\n\n- Prefer gramatr memory and project handoff context over ad hoc local summaries.\n- Treat Codex hook augmentation as authoritative when a gramatr intelligence block is present.\n- If gramatr augmentation is missing, query gramatr memory before relying on stale local notes.\n- Prefer TypeScript implementations over shell scripts for client integration code unless the platform requires shell.\n- Maintain test coverage for new hook and utility logic.\n\n## Codex Integration\n\n- Repo-local Codex hooks are configured in `.codex/hooks.json`.\n- `UserPromptSubmit` is responsible for prompt enrichment.\n- `SessionStart` is responsible for session restore and continuity.\n- Hook failures must degrade cleanly and never block the user session.\n- The contract is always `gmtr.intelligence.contract.v2`. There is no\n `unified_packet`, `packet_1`, or `packet_2` \u2014 the v2 packet is the only format.\n- Treat `directives.hard_gates` and `directives.behavioral_rules` as mandatory.\n- Follow `process.phase_template` for effort-gated phase sequencing.\n- Use `process.quality_gate_config` for ISC verification.\n- Consume `enrichment.data.reasoning` for RE and ISC when present.\n- `gramatr_route_request` is mandatory when hook injection is missing/stale.\n- `search_semantic` remains available for follow-up memory expansion.\n<!-- GRAMATR-CODEX-END -->\n";
|
|
8
8
|
export declare function buildInstallPromptSuggestion(target: InstallPromptTarget): string;
|
|
9
9
|
//# sourceMappingURL=instructions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/setup/instructions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,2BAA2B,CAAC;AAC3D,eAAO,MAAM,gBAAgB,yBAAyB,CAAC;AACvD,eAAO,MAAM,iBAAiB,iCAAiC,CAAC;AAChE,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAE5D,MAAM,MAAM,mBAAmB,GAC3B,aAAa,GACb,OAAO,GACP,YAAY,GACZ,gBAAgB,GAChB,iBAAiB,GACjB,QAAQ,GACR,UAAU,GACV,QAAQ,CAAC;AAEb,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/setup/instructions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,2BAA2B,CAAC;AAC3D,eAAO,MAAM,gBAAgB,yBAAyB,CAAC;AACvD,eAAO,MAAM,iBAAiB,iCAAiC,CAAC;AAChE,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAE5D,MAAM,MAAM,mBAAmB,GAC3B,aAAa,GACb,OAAO,GACP,YAAY,GACZ,gBAAgB,GAChB,iBAAiB,GACjB,QAAQ,GACR,UAAU,GACV,QAAQ,CAAC;AAEb,eAAO,MAAM,oBAAoB,4sDAsChC,CAAC;AAEF,eAAO,MAAM,cAAc,s6CA0B1B,CAAC;AAEF,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAehF"}
|
|
@@ -5,24 +5,40 @@ export const CODEX_BLOCK_END = '<!-- GRAMATR-CODEX-END -->';
|
|
|
5
5
|
export const CLAUDE_CODE_GUIDANCE = `${CLAUDE_BLOCK_START}
|
|
6
6
|
# gramatr
|
|
7
7
|
|
|
8
|
-
You have gramatr installed.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Follow the
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
8
|
+
You have gramatr installed. Hooks inject a \`gmtr.intelligence.contract.v2\`
|
|
9
|
+
packet into your context on every prompt.
|
|
10
|
+
|
|
11
|
+
**Follow the packet.** It contains classification, behavioral directives,
|
|
12
|
+
phase templates, capability audit, quality gates, memory/search results,
|
|
13
|
+
agent suggestions, and enrichment (RE + ISC scaffold).
|
|
14
|
+
|
|
15
|
+
**Mandatory fields:**
|
|
16
|
+
- \`directives.hard_gates\` — non-negotiable behavioral constraints
|
|
17
|
+
- \`directives.behavioral_rules\` — algorithm phases, code rules, safety rules
|
|
18
|
+
- \`process.phase_template\` — effort-gated phase sequence
|
|
19
|
+
- \`process.quality_gate_config\` — ISC verification rules
|
|
20
|
+
- \`enrichment.data.reasoning\` — RE + ISC when present
|
|
21
|
+
|
|
22
|
+
**Memory:** Use gramatr MCP tools (\`search_semantic\`, \`create_entity\`,
|
|
23
|
+
\`add_observation\`), not local markdown files.
|
|
24
|
+
|
|
25
|
+
**Sub-agent composition:** Before launching any sub-agent for non-trivial work,
|
|
26
|
+
call \`gramatr_route_request\` with the task prompt first. Use the returned
|
|
27
|
+
packet to compose the brief: RE → task description, ISC scaffold → acceptance
|
|
28
|
+
criteria, orchestration.agents.composed → agent system prompt, hard_gates →
|
|
29
|
+
constraints.
|
|
30
|
+
|
|
31
|
+
**Effort-gated phases:**
|
|
32
|
+
- instant: RESPOND only
|
|
33
|
+
- fast: OBSERVE → RESPOND
|
|
34
|
+
- standard: OBSERVE → PLAN → BUILD → VERIFY
|
|
35
|
+
- extended+: OBSERVE → THINK → PLAN → BUILD → EXECUTE → VERIFY → LEARN
|
|
36
|
+
|
|
37
|
+
**Identity:** Read from \`~/.gramatr/settings.json\` — \`daidentity\` for your
|
|
38
|
+
name, \`principal\` for the user's name.
|
|
39
|
+
|
|
40
|
+
**If the server is unavailable:** Degrade cleanly and keep working. Use the
|
|
41
|
+
7-phase structure. Create ISC before work. Never combine phases.
|
|
26
42
|
${CLAUDE_BLOCK_END}
|
|
27
43
|
`;
|
|
28
44
|
export const CODEX_GUIDANCE = `${CODEX_BLOCK_START}
|
|
@@ -31,7 +47,7 @@ export const CODEX_GUIDANCE = `${CODEX_BLOCK_START}
|
|
|
31
47
|
## Repo Expectations
|
|
32
48
|
|
|
33
49
|
- Prefer gramatr memory and project handoff context over ad hoc local summaries.
|
|
34
|
-
- Treat Codex hook augmentation as authoritative when a gramatr
|
|
50
|
+
- Treat Codex hook augmentation as authoritative when a gramatr intelligence block is present.
|
|
35
51
|
- If gramatr augmentation is missing, query gramatr memory before relying on stale local notes.
|
|
36
52
|
- Prefer TypeScript implementations over shell scripts for client integration code unless the platform requires shell.
|
|
37
53
|
- Maintain test coverage for new hook and utility logic.
|
|
@@ -42,11 +58,14 @@ export const CODEX_GUIDANCE = `${CODEX_BLOCK_START}
|
|
|
42
58
|
- \`UserPromptSubmit\` is responsible for prompt enrichment.
|
|
43
59
|
- \`SessionStart\` is responsible for session restore and continuity.
|
|
44
60
|
- Hook failures must degrade cleanly and never block the user session.
|
|
45
|
-
-
|
|
46
|
-
|
|
47
|
-
-
|
|
48
|
-
- \`
|
|
49
|
-
- \`
|
|
61
|
+
- The contract is always \`gmtr.intelligence.contract.v2\`. There is no
|
|
62
|
+
\`unified_packet\`, \`packet_1\`, or \`packet_2\` — the v2 packet is the only format.
|
|
63
|
+
- Treat \`directives.hard_gates\` and \`directives.behavioral_rules\` as mandatory.
|
|
64
|
+
- Follow \`process.phase_template\` for effort-gated phase sequencing.
|
|
65
|
+
- Use \`process.quality_gate_config\` for ISC verification.
|
|
66
|
+
- Consume \`enrichment.data.reasoning\` for RE and ISC when present.
|
|
67
|
+
- \`gramatr_route_request\` is mandatory when hook injection is missing/stale.
|
|
68
|
+
- \`search_semantic\` remains available for follow-up memory expansion.
|
|
50
69
|
${CODEX_BLOCK_END}
|
|
51
70
|
`;
|
|
52
71
|
export function buildInstallPromptSuggestion(target) {
|
|
@@ -73,28 +92,25 @@ function buildHookedPromptSuggestion(target) {
|
|
|
73
92
|
: 'Codex';
|
|
74
93
|
return `# gramatr (${platform})
|
|
75
94
|
|
|
76
|
-
gramatr is installed locally. Hooks
|
|
77
|
-
|
|
95
|
+
gramatr is installed locally. Hooks inject a \`gmtr.intelligence.contract.v2\`
|
|
96
|
+
packet into your context at session start and on every user prompt.
|
|
78
97
|
|
|
79
|
-
When a
|
|
98
|
+
When a gramatr intelligence block is present, follow it as authoritative.
|
|
80
99
|
When the packet is missing or clearly stale, call \`gramatr_route_request\`
|
|
81
100
|
with the user's request before answering.
|
|
82
101
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
\`
|
|
88
|
-
\`
|
|
89
|
-
|
|
90
|
-
|
|
102
|
+
The packet contains classification (effort, intent, confidence), behavioral
|
|
103
|
+
directives, phase templates, capability audit, quality gates, memory/search
|
|
104
|
+
results, agent suggestions, and enrichment (reverse engineering + ISC scaffold).
|
|
105
|
+
|
|
106
|
+
Treat \`directives.hard_gates\` and \`directives.behavioral_rules\` as mandatory.
|
|
107
|
+
Follow \`process.phase_template\` for effort-gated phase sequencing.
|
|
108
|
+
Use \`process.quality_gate_config\` for ISC verification.
|
|
109
|
+
Consume \`enrichment.data.reasoning\` for RE and ISC when present.
|
|
110
|
+
|
|
91
111
|
If responses are wrapped with \`schema: "gmtr.tool.result.v1"\`, parse the
|
|
92
112
|
\`data\` field as the canonical tool payload.
|
|
93
113
|
|
|
94
|
-
If \`packet_1.manifest.packet_2_status === "required"\`, call
|
|
95
|
-
\`gramatr_get_packet_two\` with \`packet_1.manifest.enrichment_id\` before
|
|
96
|
-
proceeding. Packet 2 is mandatory whenever it is required.
|
|
97
|
-
|
|
98
114
|
For continuity questions like "what were we doing?" or "what changed?",
|
|
99
115
|
call \`gramatr_load_handoff\` first, then \`search_semantic\` for detail.
|
|
100
116
|
|
|
@@ -113,25 +129,33 @@ function buildHooklessLocalPromptSuggestion(target) {
|
|
|
113
129
|
|
|
114
130
|
You have gramatr connected as an MCP server.
|
|
115
131
|
|
|
116
|
-
Before responding to any user message
|
|
117
|
-
user's
|
|
118
|
-
|
|
132
|
+
**Before responding to any user message,** call \`gramatr_route_request\` with
|
|
133
|
+
the user's prompt. This returns a \`gmtr.intelligence.contract.v2\` packet.
|
|
134
|
+
|
|
135
|
+
**Follow the packet.** It contains classification, behavioral directives,
|
|
136
|
+
phase templates, capability audit, quality gates, memory/search results,
|
|
137
|
+
agent suggestions, and enrichment (RE + ISC scaffold).
|
|
138
|
+
|
|
139
|
+
**Mandatory fields:**
|
|
140
|
+
- \`directives.hard_gates\` — non-negotiable behavioral constraints
|
|
141
|
+
- \`directives.behavioral_rules\` — algorithm phases, code rules, safety rules
|
|
142
|
+
- \`process.phase_template\` — effort-gated phase sequence
|
|
143
|
+
- \`process.quality_gate_config\` — ISC verification rules
|
|
144
|
+
- \`enrichment.data.reasoning\` — RE + ISC when present
|
|
145
|
+
|
|
146
|
+
**Memory:** Use gramatr MCP tools (\`search_semantic\`, \`create_entity\`,
|
|
147
|
+
\`add_observation\`) as the source of truth — not local notes.
|
|
148
|
+
|
|
149
|
+
**Effort-gated phases:**
|
|
150
|
+
- instant: RESPOND only
|
|
151
|
+
- fast: OBSERVE → RESPOND
|
|
152
|
+
- standard: OBSERVE → PLAN → BUILD → VERIFY
|
|
153
|
+
- extended+: OBSERVE → THINK → PLAN → BUILD → EXECUTE → VERIFY → LEARN
|
|
119
154
|
|
|
120
|
-
Use \`unified_packet\` as the canonical complete response when present.
|
|
121
|
-
Otherwise use \`packet_1\` as the canonical response envelope. If
|
|
122
|
-
\`packet_1.manifest.packet_2_status === "required"\`, call
|
|
123
|
-
\`gramatr_get_packet_two\` with the returned \`enrichment_id\` and treat Packet 2
|
|
124
|
-
as mandatory before full execution.
|
|
125
155
|
If responses are wrapped with \`schema: "gmtr.tool.result.v1"\`, use
|
|
126
156
|
\`data\` as the canonical payload.
|
|
127
|
-
Consume packet-provided behavioral rules, ISC/quality-gate fields, and
|
|
128
|
-
format constraints directly from the JSON contract when present.
|
|
129
|
-
Treat \`required_actions\` and \`contract_enforcement.hard_gates\` as mandatory.
|
|
130
|
-
|
|
131
|
-
For continuity questions like "what were we doing?" or "what changed?",
|
|
132
|
-
call \`gramatr_load_handoff\` before answering, then \`search_semantic\`
|
|
133
|
-
for additional detail.
|
|
134
157
|
|
|
135
|
-
|
|
158
|
+
For continuity questions ("what were we doing?", "what changed?"),
|
|
159
|
+
call \`gramatr_load_handoff\` before answering, then \`search_semantic\`.`;
|
|
136
160
|
}
|
|
137
161
|
//# sourceMappingURL=instructions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/setup/instructions.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,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