@apnex/network-adapter 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/dist/hub-error.d.ts +42 -0
- package/dist/hub-error.js +74 -0
- package/dist/hub-error.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/kernel/agent-client.d.ts +192 -0
- package/dist/kernel/agent-client.js +44 -0
- package/dist/kernel/agent-client.js.map +1 -0
- package/dist/kernel/event-router.d.ts +49 -0
- package/dist/kernel/event-router.js +150 -0
- package/dist/kernel/event-router.js.map +1 -0
- package/dist/kernel/handshake.d.ts +161 -0
- package/dist/kernel/handshake.js +257 -0
- package/dist/kernel/handshake.js.map +1 -0
- package/dist/kernel/instance.d.ts +40 -0
- package/dist/kernel/instance.js +79 -0
- package/dist/kernel/instance.js.map +1 -0
- package/dist/kernel/mcp-agent-client.d.ts +139 -0
- package/dist/kernel/mcp-agent-client.js +505 -0
- package/dist/kernel/mcp-agent-client.js.map +1 -0
- package/dist/kernel/poll-backstop.d.ts +108 -0
- package/dist/kernel/poll-backstop.js +243 -0
- package/dist/kernel/poll-backstop.js.map +1 -0
- package/dist/kernel/session-claim.d.ts +67 -0
- package/dist/kernel/session-claim.js +106 -0
- package/dist/kernel/session-claim.js.map +1 -0
- package/dist/kernel/state-sync.d.ts +43 -0
- package/dist/kernel/state-sync.js +85 -0
- package/dist/kernel/state-sync.js.map +1 -0
- package/dist/logger.d.ts +82 -0
- package/dist/logger.js +114 -0
- package/dist/logger.js.map +1 -0
- package/dist/notification-log.d.ts +29 -0
- package/dist/notification-log.js +66 -0
- package/dist/notification-log.js.map +1 -0
- package/dist/prompt-format.d.ts +38 -0
- package/dist/prompt-format.js +220 -0
- package/dist/prompt-format.js.map +1 -0
- package/dist/tool-manager/dispatcher.d.ts +180 -0
- package/dist/tool-manager/dispatcher.js +379 -0
- package/dist/tool-manager/dispatcher.js.map +1 -0
- package/dist/tool-manager/tool-catalog-cache.d.ts +85 -0
- package/dist/tool-manager/tool-catalog-cache.js +137 -0
- package/dist/tool-manager/tool-catalog-cache.js.map +1 -0
- package/dist/wire/mcp-transport.d.ts +120 -0
- package/dist/wire/mcp-transport.js +447 -0
- package/dist/wire/mcp-transport.js.map +1 -0
- package/dist/wire/transport.d.ts +174 -0
- package/dist/wire/transport.js +43 -0
- package/dist/wire/transport.js.map +1 -0
- package/package.json +32 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-sync.js","sourceRoot":"","sources":["../../src/kernel/state-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAmClD,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,GAAqB;IAC1D,MAAM,GAAG,GAAG,kBAAkB,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IACrD,GAAG,CAAC,GAAG,CAAC,kBAAkB,EAAE,SAAS,EAAE,oCAAoC,CAAC,CAAC;IAE7E,IAAI,CAAC;QACH,oEAAoE;QACpE,oEAAoE;QACpE,mEAAmE;QACnE,MAAM,CAAC,SAAS,EAAE,cAAc,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAChE,GAAG,CAAC,WAAW,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;gBACrD,GAAG,CAAC,GAAG,CACL,4BAA4B,EAC5B,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,EACtB,yBAAyB,GAAG,EAAE,CAC/B,CAAC;gBACF,OAAO,IAAI,CAAC;YACd,CAAC,CAAC;YACF,GAAG,CAAC,WAAW,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;gBAChE,GAAG,CAAC,GAAG,CACL,uCAAuC,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AC;QACb,GAAG,CAAC,GAAG,CACL,mBAAmB,EACnB,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,EACtB,uBAAuB,GAAG,EAAE,CAC7B,CAAC;QACF,IAAI,CAAC;YACH,GAAG,CAAC,YAAY,EAAE,CAAC;QACrB,CAAC;QAAC,MAAM,CAAC;YACP,GAAG,CAAC,GAAG,CACL,4BAA4B,EAC5B,SAAS,EACT,wCAAwC,CACzC,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ILogger — structured logging surface shared by Transport (L4) and
|
|
3
|
+
* AgentClient (L7).
|
|
4
|
+
*
|
|
5
|
+
* Phase 1: types only. No implementation. Both layers will accept an
|
|
6
|
+
* injected `ILogger` at construction in later phases; Phase 5 introduces
|
|
7
|
+
* the concrete structured logger.
|
|
8
|
+
*
|
|
9
|
+
* Design intent:
|
|
10
|
+
* - Stable event names. Every log call carries a short, dotted `event`
|
|
11
|
+
* identifier (e.g., "transport.connect.ok", "agent.session.invalid")
|
|
12
|
+
* so downstream telemetry pipelines can aggregate without parsing
|
|
13
|
+
* human-readable text.
|
|
14
|
+
* - Structured fields. `fields` is an arbitrary record of primitives.
|
|
15
|
+
* Implementations MUST NOT introspect contents — the field names are
|
|
16
|
+
* a contract between caller and log sink.
|
|
17
|
+
* - No levels on the call site. Severity is inferred from the event
|
|
18
|
+
* name prefix by the sink (convention: `*.error.*`, `*.warn.*`).
|
|
19
|
+
* This keeps call sites terse and makes it impossible to log the
|
|
20
|
+
* "wrong" level for a known event.
|
|
21
|
+
* - Free-form `message` is optional. Most structured events don't
|
|
22
|
+
* need prose; it's retained for one-off diagnostics during
|
|
23
|
+
* development and bridging legacy string-logger call sites.
|
|
24
|
+
*/
|
|
25
|
+
export type LogField = string | number | boolean | null | undefined;
|
|
26
|
+
export interface LogFields {
|
|
27
|
+
readonly [key: string]: LogField | readonly LogField[];
|
|
28
|
+
}
|
|
29
|
+
export interface ILogger {
|
|
30
|
+
/**
|
|
31
|
+
* Emit a structured log event.
|
|
32
|
+
*
|
|
33
|
+
* @param event Dotted stable name, e.g. "transport.sse.watchdog.fired".
|
|
34
|
+
* Stable across releases; consumed by telemetry.
|
|
35
|
+
* @param fields Optional structured context. Keys are part of the
|
|
36
|
+
* event contract — do not rename without a migration.
|
|
37
|
+
* @param message Optional human-readable prose. Callers should prefer
|
|
38
|
+
* moving information into `fields` over this string.
|
|
39
|
+
*/
|
|
40
|
+
log(event: string, fields?: LogFields, message?: string): void;
|
|
41
|
+
/**
|
|
42
|
+
* Create a child logger with `fields` pre-bound to every emission.
|
|
43
|
+
* Used to scope a logger to a single Transport instance, session,
|
|
44
|
+
* or reconnect attempt without threading context through call sites.
|
|
45
|
+
*/
|
|
46
|
+
child(fields: LogFields): ILogger;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Adapter that bridges a legacy string-only logger (e.g. the existing
|
|
50
|
+
* `(msg: string) => void` used by McpConnectionManager) into the
|
|
51
|
+
* ILogger shape.
|
|
52
|
+
*/
|
|
53
|
+
export type LegacyStringLogger = (message: string) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Render an event + fields + message into the single-string shape the
|
|
56
|
+
* legacy `(msg: string) => void` sink expects.
|
|
57
|
+
*
|
|
58
|
+
* Format: `[event] message | k1=v1 k2=v2` (empty segments elided).
|
|
59
|
+
* Stable enough that tests matching on message substrings still pass;
|
|
60
|
+
* event name appears as a prefix so structured sinks can still parse.
|
|
61
|
+
*/
|
|
62
|
+
export declare function renderLogLine(event: string, fields?: LogFields, message?: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* Wrap a legacy `(msg: string) => void` sink into an `ILogger`. The
|
|
65
|
+
* logger renders structured events back to a single string via
|
|
66
|
+
* `renderLogLine`, preserving substring assertions used by existing
|
|
67
|
+
* integration tests.
|
|
68
|
+
*/
|
|
69
|
+
export declare function bridgeLegacyLogger(fn: LegacyStringLogger): ILogger;
|
|
70
|
+
/**
|
|
71
|
+
* Default `ILogger` that renders to `console.log`, prefixed with a
|
|
72
|
+
* component name for visual scan of interleaved output.
|
|
73
|
+
*/
|
|
74
|
+
export declare function createConsoleLogger(component: string): ILogger;
|
|
75
|
+
/**
|
|
76
|
+
* Normalize the three accepted logger input shapes (undefined, legacy
|
|
77
|
+
* string function, structured `ILogger`) into a single `ILogger` for
|
|
78
|
+
* internal use. Call sites inside `McpTransport` and `McpAgentClient`
|
|
79
|
+
* use this so they can emit structured events regardless of what the
|
|
80
|
+
* caller passed in.
|
|
81
|
+
*/
|
|
82
|
+
export declare function normalizeToILogger(logger: ILogger | LegacyStringLogger | undefined, defaultComponent: string): ILogger;
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ILogger — structured logging surface shared by Transport (L4) and
|
|
3
|
+
* AgentClient (L7).
|
|
4
|
+
*
|
|
5
|
+
* Phase 1: types only. No implementation. Both layers will accept an
|
|
6
|
+
* injected `ILogger` at construction in later phases; Phase 5 introduces
|
|
7
|
+
* the concrete structured logger.
|
|
8
|
+
*
|
|
9
|
+
* Design intent:
|
|
10
|
+
* - Stable event names. Every log call carries a short, dotted `event`
|
|
11
|
+
* identifier (e.g., "transport.connect.ok", "agent.session.invalid")
|
|
12
|
+
* so downstream telemetry pipelines can aggregate without parsing
|
|
13
|
+
* human-readable text.
|
|
14
|
+
* - Structured fields. `fields` is an arbitrary record of primitives.
|
|
15
|
+
* Implementations MUST NOT introspect contents — the field names are
|
|
16
|
+
* a contract between caller and log sink.
|
|
17
|
+
* - No levels on the call site. Severity is inferred from the event
|
|
18
|
+
* name prefix by the sink (convention: `*.error.*`, `*.warn.*`).
|
|
19
|
+
* This keeps call sites terse and makes it impossible to log the
|
|
20
|
+
* "wrong" level for a known event.
|
|
21
|
+
* - Free-form `message` is optional. Most structured events don't
|
|
22
|
+
* need prose; it's retained for one-off diagnostics during
|
|
23
|
+
* development and bridging legacy string-logger call sites.
|
|
24
|
+
*/
|
|
25
|
+
// ── Phase 5: concrete implementations ───────────────────────────────
|
|
26
|
+
function formatValue(v) {
|
|
27
|
+
if (Array.isArray(v))
|
|
28
|
+
return `[${v.map(formatValue).join(",")}]`;
|
|
29
|
+
if (v === undefined)
|
|
30
|
+
return "undef";
|
|
31
|
+
if (v === null)
|
|
32
|
+
return "null";
|
|
33
|
+
return String(v);
|
|
34
|
+
}
|
|
35
|
+
function renderFields(fields) {
|
|
36
|
+
if (!fields)
|
|
37
|
+
return "";
|
|
38
|
+
const parts = [];
|
|
39
|
+
for (const k of Object.keys(fields)) {
|
|
40
|
+
const v = fields[k];
|
|
41
|
+
parts.push(`${k}=${formatValue(v)}`);
|
|
42
|
+
}
|
|
43
|
+
return parts.length > 0 ? ` ${parts.join(" ")}` : "";
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Render an event + fields + message into the single-string shape the
|
|
47
|
+
* legacy `(msg: string) => void` sink expects.
|
|
48
|
+
*
|
|
49
|
+
* Format: `[event] message | k1=v1 k2=v2` (empty segments elided).
|
|
50
|
+
* Stable enough that tests matching on message substrings still pass;
|
|
51
|
+
* event name appears as a prefix so structured sinks can still parse.
|
|
52
|
+
*/
|
|
53
|
+
export function renderLogLine(event, fields, message) {
|
|
54
|
+
const body = message ?? "";
|
|
55
|
+
const tail = renderFields(fields);
|
|
56
|
+
if (!body && !tail)
|
|
57
|
+
return `[${event}]`;
|
|
58
|
+
if (!body)
|
|
59
|
+
return `[${event}]${tail}`;
|
|
60
|
+
if (!tail)
|
|
61
|
+
return `[${event}] ${body}`;
|
|
62
|
+
return `[${event}] ${body} |${tail}`;
|
|
63
|
+
}
|
|
64
|
+
class LoggerBase {
|
|
65
|
+
boundFields;
|
|
66
|
+
sink;
|
|
67
|
+
constructor(boundFields, sink) {
|
|
68
|
+
this.boundFields = boundFields;
|
|
69
|
+
this.sink = sink;
|
|
70
|
+
}
|
|
71
|
+
log(event, fields, message) {
|
|
72
|
+
const merged = this.boundFields
|
|
73
|
+
? { ...this.boundFields, ...(fields ?? {}) }
|
|
74
|
+
: fields;
|
|
75
|
+
this.sink(renderLogLine(event, merged, message));
|
|
76
|
+
}
|
|
77
|
+
child(fields) {
|
|
78
|
+
const merged = this.boundFields
|
|
79
|
+
? { ...this.boundFields, ...fields }
|
|
80
|
+
: { ...fields };
|
|
81
|
+
return new LoggerBase(merged, this.sink);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Wrap a legacy `(msg: string) => void` sink into an `ILogger`. The
|
|
86
|
+
* logger renders structured events back to a single string via
|
|
87
|
+
* `renderLogLine`, preserving substring assertions used by existing
|
|
88
|
+
* integration tests.
|
|
89
|
+
*/
|
|
90
|
+
export function bridgeLegacyLogger(fn) {
|
|
91
|
+
return new LoggerBase(undefined, fn);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Default `ILogger` that renders to `console.log`, prefixed with a
|
|
95
|
+
* component name for visual scan of interleaved output.
|
|
96
|
+
*/
|
|
97
|
+
export function createConsoleLogger(component) {
|
|
98
|
+
return new LoggerBase(undefined, (line) => console.log(`[${component}] ${line}`));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Normalize the three accepted logger input shapes (undefined, legacy
|
|
102
|
+
* string function, structured `ILogger`) into a single `ILogger` for
|
|
103
|
+
* internal use. Call sites inside `McpTransport` and `McpAgentClient`
|
|
104
|
+
* use this so they can emit structured events regardless of what the
|
|
105
|
+
* caller passed in.
|
|
106
|
+
*/
|
|
107
|
+
export function normalizeToILogger(logger, defaultComponent) {
|
|
108
|
+
if (!logger)
|
|
109
|
+
return createConsoleLogger(defaultComponent);
|
|
110
|
+
if (typeof logger === "function")
|
|
111
|
+
return bridgeLegacyLogger(logger);
|
|
112
|
+
return logger;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1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CAAC,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC,CACtC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAgD,EAChD,gBAAwB;IAExB,IAAI,CAAC,MAAM;QAAE,OAAO,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IAC1D,IAAI,OAAO,MAAM,KAAK,UAAU;QAAE,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACpE,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured notification logger.
|
|
3
|
+
*
|
|
4
|
+
* Writes a multi-line human-readable block per event to a caller-supplied
|
|
5
|
+
* log file. Extracts known fields (taskId, threadId, proposalId, assessment,
|
|
6
|
+
* decision, intent, revisionCount, previousReportRef, feedback) so downstream
|
|
7
|
+
* tools can grep them deterministically.
|
|
8
|
+
*
|
|
9
|
+
* OpenCode's pre-refactor logger wrote only `${iso} ${msg}\n`, which is why
|
|
10
|
+
* tonight's investigation could not correlate task IDs between engineers.
|
|
11
|
+
* This module closes that telemetry gap.
|
|
12
|
+
*/
|
|
13
|
+
export interface NotificationLogEntry {
|
|
14
|
+
event: string;
|
|
15
|
+
data: Record<string, unknown>;
|
|
16
|
+
action: string;
|
|
17
|
+
}
|
|
18
|
+
export interface NotificationLogOptions {
|
|
19
|
+
/** Absolute path to the log file. Parent directory will be created. */
|
|
20
|
+
logPath: string;
|
|
21
|
+
/** Optional mirror sink (e.g. process.stderr.write) called with the block. */
|
|
22
|
+
mirror?: (block: string) => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Append a structured notification block to the log file.
|
|
26
|
+
* Best-effort: write failures are silently swallowed (the log must never
|
|
27
|
+
* break the runtime).
|
|
28
|
+
*/
|
|
29
|
+
export declare function appendNotification(entry: NotificationLogEntry, opts: NotificationLogOptions): void;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured notification logger.
|
|
3
|
+
*
|
|
4
|
+
* Writes a multi-line human-readable block per event to a caller-supplied
|
|
5
|
+
* log file. Extracts known fields (taskId, threadId, proposalId, assessment,
|
|
6
|
+
* decision, intent, revisionCount, previousReportRef, feedback) so downstream
|
|
7
|
+
* tools can grep them deterministically.
|
|
8
|
+
*
|
|
9
|
+
* OpenCode's pre-refactor logger wrote only `${iso} ${msg}\n`, which is why
|
|
10
|
+
* tonight's investigation could not correlate task IDs between engineers.
|
|
11
|
+
* This module closes that telemetry gap.
|
|
12
|
+
*/
|
|
13
|
+
import { appendFileSync, mkdirSync, existsSync } from "node:fs";
|
|
14
|
+
import { dirname } from "node:path";
|
|
15
|
+
/**
|
|
16
|
+
* Append a structured notification block to the log file.
|
|
17
|
+
* Best-effort: write failures are silently swallowed (the log must never
|
|
18
|
+
* break the runtime).
|
|
19
|
+
*/
|
|
20
|
+
export function appendNotification(entry, opts) {
|
|
21
|
+
const { event, data, action } = entry;
|
|
22
|
+
const ts = new Date().toISOString().replace("T", " ").slice(0, 19);
|
|
23
|
+
const lines = [`[${ts}] ${event.toUpperCase()}`];
|
|
24
|
+
if (data.taskId) {
|
|
25
|
+
lines.push(` Task: ${data.taskId}${data.title ? ` "${data.title}"` : ""}`);
|
|
26
|
+
}
|
|
27
|
+
if (data.threadId) {
|
|
28
|
+
lines.push(` Thread: ${data.threadId}${data.title ? ` "${data.title}"` : ""}`);
|
|
29
|
+
}
|
|
30
|
+
if (data.proposalId)
|
|
31
|
+
lines.push(` Proposal: ${data.proposalId}`);
|
|
32
|
+
if (data.feedback)
|
|
33
|
+
lines.push(` Feedback: ${data.feedback}`);
|
|
34
|
+
if (data.assessment)
|
|
35
|
+
lines.push(` Assessment: ${data.assessment}`);
|
|
36
|
+
if (data.decision)
|
|
37
|
+
lines.push(` Decision: ${data.decision}`);
|
|
38
|
+
if (data.intent)
|
|
39
|
+
lines.push(` Intent: ${data.intent}`);
|
|
40
|
+
if (data.previousReportRef)
|
|
41
|
+
lines.push(` Previous report: ${data.previousReportRef}`);
|
|
42
|
+
if (data.revisionCount)
|
|
43
|
+
lines.push(` Revision: ${data.revisionCount}`);
|
|
44
|
+
lines.push(` Action: ${action}`);
|
|
45
|
+
lines.push("");
|
|
46
|
+
const block = lines.join("\n");
|
|
47
|
+
try {
|
|
48
|
+
const dir = dirname(opts.logPath);
|
|
49
|
+
if (!existsSync(dir)) {
|
|
50
|
+
mkdirSync(dir, { recursive: true });
|
|
51
|
+
}
|
|
52
|
+
appendFileSync(opts.logPath, block);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
/* best effort */
|
|
56
|
+
}
|
|
57
|
+
if (opts.mirror) {
|
|
58
|
+
try {
|
|
59
|
+
opts.mirror(block);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
/* best effort */
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=notification-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-log.js","sourceRoot":"","sources":["../src/notification-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAepC;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAA2B,EAC3B,IAA4B;IAE5B,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACtC,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACnE,MAAM,KAAK,GAAa,CAAC,IAAI,EAAE,KAAK,KAAK,CAAC,WAAW,EAAE,EAAE,CAA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AAE,CAAC,CAAC;IAClC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE/B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACtC,CAAC;QACD,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,iBAAiB;IACnB,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;QAAC,MAAM,CAAC;YACP,iBAAiB;QACnB,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared formatting helpers for engineer notification delivery.
|
|
3
|
+
*
|
|
4
|
+
* - `getActionText`: short hint used in structured notification logs.
|
|
5
|
+
* - `buildPromptText`: detailed prompt injected into the LLM when an
|
|
6
|
+
* actionable event arrives. Parameterised by `toolPrefix` because
|
|
7
|
+
* Claude Code namespaces MCP tools as `mcp__<server>__<tool>` while
|
|
8
|
+
* OpenCode uses `architect-hub_<tool>`.
|
|
9
|
+
* - `buildToastMessage`: short TUI toast, used by OpenCode only but
|
|
10
|
+
* kept here because the switch-on-event shape duplicates otherwise.
|
|
11
|
+
*
|
|
12
|
+
* mission-63 W3 (M-Wire-Entity-Convergence): converted from per-event-type
|
|
13
|
+
* if-ladder to canonical render-template registry per Design v1.0 §4.2 +
|
|
14
|
+
* ADR-028. Adding a new event-type = registering a template; no if-ladder
|
|
15
|
+
* branch addition cost.
|
|
16
|
+
*
|
|
17
|
+
* Mandatory templates per Design §6.4 substrate-self-dogfood verification:
|
|
18
|
+
* - message_arrived (pulse + note inline rendering)
|
|
19
|
+
* - thread_message (body inlining; calibration #20 retire)
|
|
20
|
+
* - thread_convergence_finalized (truncation removal; calibration #20 sub-finding retire)
|
|
21
|
+
* - agent_state_changed (NEW — diff rendering using `previous` shape)
|
|
22
|
+
*
|
|
23
|
+
* Existing per-event templates (clarification_answered, task_issued,
|
|
24
|
+
* review_completed, revision_required, proposal_decided) are mechanical
|
|
25
|
+
* ports of the prior inline strings — registered as templates with no
|
|
26
|
+
* behavior change.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getActionText(event: string, data: Record<string, unknown>): string;
|
|
29
|
+
export interface PromptFormatConfig {
|
|
30
|
+
/**
|
|
31
|
+
* Tool-name prefix for the host. Examples:
|
|
32
|
+
* - Claude Code: `"mcp__plugin_agent-adapter_proxy__"`
|
|
33
|
+
* - OpenCode: `"architect-hub_"`
|
|
34
|
+
*/
|
|
35
|
+
toolPrefix: string;
|
|
36
|
+
}
|
|
37
|
+
export declare function buildPromptText(event: string, data: Record<string, unknown>, cfg: PromptFormatConfig): string;
|
|
38
|
+
export declare function buildToastMessage(event: string, data: Record<string, unknown>): string;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared formatting helpers for engineer notification delivery.
|
|
3
|
+
*
|
|
4
|
+
* - `getActionText`: short hint used in structured notification logs.
|
|
5
|
+
* - `buildPromptText`: detailed prompt injected into the LLM when an
|
|
6
|
+
* actionable event arrives. Parameterised by `toolPrefix` because
|
|
7
|
+
* Claude Code namespaces MCP tools as `mcp__<server>__<tool>` while
|
|
8
|
+
* OpenCode uses `architect-hub_<tool>`.
|
|
9
|
+
* - `buildToastMessage`: short TUI toast, used by OpenCode only but
|
|
10
|
+
* kept here because the switch-on-event shape duplicates otherwise.
|
|
11
|
+
*
|
|
12
|
+
* mission-63 W3 (M-Wire-Entity-Convergence): converted from per-event-type
|
|
13
|
+
* if-ladder to canonical render-template registry per Design v1.0 §4.2 +
|
|
14
|
+
* ADR-028. Adding a new event-type = registering a template; no if-ladder
|
|
15
|
+
* branch addition cost.
|
|
16
|
+
*
|
|
17
|
+
* Mandatory templates per Design §6.4 substrate-self-dogfood verification:
|
|
18
|
+
* - message_arrived (pulse + note inline rendering)
|
|
19
|
+
* - thread_message (body inlining; calibration #20 retire)
|
|
20
|
+
* - thread_convergence_finalized (truncation removal; calibration #20 sub-finding retire)
|
|
21
|
+
* - agent_state_changed (NEW — diff rendering using `previous` shape)
|
|
22
|
+
*
|
|
23
|
+
* Existing per-event templates (clarification_answered, task_issued,
|
|
24
|
+
* review_completed, revision_required, proposal_decided) are mechanical
|
|
25
|
+
* ports of the prior inline strings — registered as templates with no
|
|
26
|
+
* behavior change.
|
|
27
|
+
*/
|
|
28
|
+
export function getActionText(event, data) {
|
|
29
|
+
switch (event) {
|
|
30
|
+
case "task_issued":
|
|
31
|
+
return "Pick up with get_task";
|
|
32
|
+
case "revision_required":
|
|
33
|
+
return "Revise and resubmit with create_report";
|
|
34
|
+
case "thread_message":
|
|
35
|
+
return `Read with get_thread(threadId="${data.threadId}"), then reply with create_thread_reply`;
|
|
36
|
+
case "thread_convergence_finalized":
|
|
37
|
+
return "Review convergence report and act on follow-up if needed";
|
|
38
|
+
case "clarification_answered":
|
|
39
|
+
return `Read with get_clarification(taskId="${data.taskId}"), then resume work`;
|
|
40
|
+
case "review_completed":
|
|
41
|
+
return `Read with get_review(taskId="${data.taskId}")`;
|
|
42
|
+
case "proposal_decided":
|
|
43
|
+
return "Review decision and act if needed";
|
|
44
|
+
default:
|
|
45
|
+
return "Review and act as needed";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// ── Render templates (per-event) ───────────────────────────────────────
|
|
49
|
+
function renderThreadMessage(data, cfg) {
|
|
50
|
+
// calibration #20 retire (mission-63 W3): surface the body inline so the
|
|
51
|
+
// LLM has the actual message content, not just the envelope-shell. The
|
|
52
|
+
// Hub-side dispatch payload pre-truncates to 200 chars (thread-policy.ts);
|
|
53
|
+
// adapter renders that preview verbatim. Full body still requires get_thread.
|
|
54
|
+
const p = cfg.toolPrefix;
|
|
55
|
+
const authorLabel = data.author === "architect" ? "Architect"
|
|
56
|
+
: data.author === "engineer" ? "Engineer peer"
|
|
57
|
+
: "Peer";
|
|
58
|
+
const title = data.title || data.threadId || "(unknown)";
|
|
59
|
+
const body = data.message || "";
|
|
60
|
+
const bodyLine = body ? `\n\nMessage preview: ${body}` : "";
|
|
61
|
+
return (`[${authorLabel}] Replied to thread "${title}".${bodyLine} ` +
|
|
62
|
+
`\n\nIt is your turn. Call ${p}get_thread with threadId="${data.threadId}" ` +
|
|
63
|
+
`to read the full thread, then reply using ${p}create_thread_reply. ` +
|
|
64
|
+
`Threads 2.0 discipline: when you signal converged=true you MUST also populate ` +
|
|
65
|
+
`\`stagedActions\` (for a purely-ideation thread: ` +
|
|
66
|
+
`[{kind:"stage",type:"close_no_action",payload:{reason:"<short rationale>"}}]) ` +
|
|
67
|
+
`AND a non-empty \`summary\` narrating the agreed outcome. ` +
|
|
68
|
+
`The Hub gate rejects converged=true without both — read the error message and retry with the missing piece populated.`);
|
|
69
|
+
}
|
|
70
|
+
function renderThreadConvergenceFinalized(data, _cfg) {
|
|
71
|
+
// calibration #20 sub-finding retire (mission-63 W3): full summary surfaced
|
|
72
|
+
// inline; mid-string truncation (.slice(0, 200)) removed. ConvergenceReport
|
|
73
|
+
// detail still requires the SSE event payload's full report; this template
|
|
74
|
+
// gives the LLM the negotiated narrative summary verbatim.
|
|
75
|
+
const title = data.title || data.threadId || "(unknown)";
|
|
76
|
+
const intent = data.intent || "none";
|
|
77
|
+
const summary = data.summary || "(none)";
|
|
78
|
+
const committed = data.committedActionCount ?? 0;
|
|
79
|
+
const executed = data.executedCount ?? 0;
|
|
80
|
+
const failed = data.failedCount ?? 0;
|
|
81
|
+
const warning = data.warning ? ", WARNING" : "";
|
|
82
|
+
return (`[Hub] Thread "${title}" converged with intent: ${intent}. ` +
|
|
83
|
+
`Summary: ${summary}. ` +
|
|
84
|
+
`Committed actions: ${committed} (executed=${executed}, failed=${failed}${warning}). ` +
|
|
85
|
+
`Review the full ConvergenceReport in the event payload for any follow-up action.`);
|
|
86
|
+
}
|
|
87
|
+
function renderAgentStateChanged(data, _cfg) {
|
|
88
|
+
// mission-63 W3 NEW template per Design §3.4 + §6.4 verification point 3.
|
|
89
|
+
// Canonical payload: {agent: AgentProjection, previous: {livenessState?,
|
|
90
|
+
// activityState?}, changed[], cause, at}. Diff-renders the FSM transition
|
|
91
|
+
// using `previous` (only fields that changed appear) for a tight
|
|
92
|
+
// signal-to-noise readout.
|
|
93
|
+
const agent = data.agent;
|
|
94
|
+
const previous = data.previous ?? {};
|
|
95
|
+
const cause = data.cause || "unknown";
|
|
96
|
+
const id = agent?.id || "unknown";
|
|
97
|
+
const name = agent?.name || id;
|
|
98
|
+
const role = agent?.role || "agent";
|
|
99
|
+
const newLiveness = agent?.livenessState || "unknown";
|
|
100
|
+
const newActivity = agent?.activityState || "unknown";
|
|
101
|
+
const livenessTransition = "livenessState" in previous
|
|
102
|
+
? `livenessState ${previous.livenessState} → ${newLiveness}`
|
|
103
|
+
: null;
|
|
104
|
+
const activityTransition = "activityState" in previous
|
|
105
|
+
? `activityState ${previous.activityState} → ${newActivity}`
|
|
106
|
+
: null;
|
|
107
|
+
const transitions = [livenessTransition, activityTransition].filter((t) => t !== null);
|
|
108
|
+
const transitionLine = transitions.length > 0 ? transitions.join("; ") : "no FSM-state delta";
|
|
109
|
+
return (`[Hub] Agent ${role}/${name} (${id}) state-changed: ${transitionLine} (cause=${cause}).`);
|
|
110
|
+
}
|
|
111
|
+
function renderClarificationAnswered(data, cfg) {
|
|
112
|
+
const p = cfg.toolPrefix;
|
|
113
|
+
return (`[Architect] Answered your clarification request for ${data.taskId}. ` +
|
|
114
|
+
`Call ${p}get_clarification with taskId="${data.taskId}" ` +
|
|
115
|
+
`to read the answer and resume your work.`);
|
|
116
|
+
}
|
|
117
|
+
function renderTaskIssued(data, cfg) {
|
|
118
|
+
const p = cfg.toolPrefix;
|
|
119
|
+
return (`[Architect] Issued a new directive (${data.taskId || "pending"}). ` +
|
|
120
|
+
`Call ${p}get_task to pick it up and execute it.`);
|
|
121
|
+
}
|
|
122
|
+
function renderReviewCompleted(data, cfg) {
|
|
123
|
+
const p = cfg.toolPrefix;
|
|
124
|
+
return (`[Architect] Reviewed ${data.taskId || "your report"}. ` +
|
|
125
|
+
`Read it with ${p}get_review with taskId="${data.taskId}".`);
|
|
126
|
+
}
|
|
127
|
+
function renderRevisionRequired(data, cfg) {
|
|
128
|
+
const p = cfg.toolPrefix;
|
|
129
|
+
return (`[Architect] Your report for ${data.taskId || "task"} was REJECTED. ` +
|
|
130
|
+
`Feedback: ${data.feedback || data.assessment || "No details provided"}. ` +
|
|
131
|
+
`Previous report: ${data.previousReportRef || "unknown"}. ` +
|
|
132
|
+
`Revision ${data.revisionCount || "?"}. Please revise and resubmit using ${p}create_report.`);
|
|
133
|
+
}
|
|
134
|
+
function renderProposalDecided(data, _cfg) {
|
|
135
|
+
return `[Architect] Proposal ${data.proposalId || ""}: ${data.decision || "decided"}.`;
|
|
136
|
+
}
|
|
137
|
+
function renderMessageArrived(data, cfg) {
|
|
138
|
+
// mission-62 W1+W2 Pass 7 — note-kind + pulse-content rendering fix.
|
|
139
|
+
// Branches on payload discriminators to surface actual Message body
|
|
140
|
+
// inline (pulse / note / wrapped legacy SSE event / generic).
|
|
141
|
+
const p = cfg.toolPrefix;
|
|
142
|
+
const msg = data.message ?? {};
|
|
143
|
+
const payload = msg.payload ?? {};
|
|
144
|
+
const msgId = msg.id || "?";
|
|
145
|
+
const kind = msg.kind || "unknown";
|
|
146
|
+
if (payload.pulseKind && typeof payload.pulseKind === "string") {
|
|
147
|
+
const pMissionId = payload.missionId || "?";
|
|
148
|
+
const pMessage = payload.message || "(empty pulse message)";
|
|
149
|
+
const pResponseShape = payload.responseShape || "short_status";
|
|
150
|
+
return (`[Hub] Pulse fired (${payload.pulseKind}) for mission ${pMissionId}. ${pMessage} ` +
|
|
151
|
+
`Respond with shape "${pResponseShape}" via the appropriate channel ` +
|
|
152
|
+
`(typically ${p}create_message kind=note OR a short status reply on the active coord-thread). ` +
|
|
153
|
+
`Message ID: ${msgId}.`);
|
|
154
|
+
}
|
|
155
|
+
if (payload.event && typeof payload.event === "string") {
|
|
156
|
+
return (`[Hub] Hub event injected: ${payload.event}. ` +
|
|
157
|
+
`${getActionText(payload.event, payload.data ?? {})}. ` +
|
|
158
|
+
`Message ID: ${msgId}.`);
|
|
159
|
+
}
|
|
160
|
+
if (kind === "note") {
|
|
161
|
+
const body = payload.body ||
|
|
162
|
+
payload.text ||
|
|
163
|
+
payload.message ||
|
|
164
|
+
"(empty note body)";
|
|
165
|
+
const sender = msg.authorAgentId || "unknown";
|
|
166
|
+
const senderRole = msg.authorRole || "agent";
|
|
167
|
+
return (`[${senderRole}/${sender}] Note: ${body} ` +
|
|
168
|
+
`(Message ID: ${msgId}; respond via ${p}create_message kind=note targeting the sender.)`);
|
|
169
|
+
}
|
|
170
|
+
return (`[Hub] Message ${msgId} (kind=${kind}) arrived. ` +
|
|
171
|
+
`Use ${p}list_messages or ${p}claim_message to fetch full content + ack.`);
|
|
172
|
+
}
|
|
173
|
+
// ── Registry ────────────────────────────────────────────────────────────
|
|
174
|
+
const RENDER_REGISTRY = new Map([
|
|
175
|
+
["thread_message", renderThreadMessage],
|
|
176
|
+
["thread_convergence_finalized", renderThreadConvergenceFinalized],
|
|
177
|
+
["agent_state_changed", renderAgentStateChanged],
|
|
178
|
+
["message_arrived", renderMessageArrived],
|
|
179
|
+
["clarification_answered", renderClarificationAnswered],
|
|
180
|
+
["task_issued", renderTaskIssued],
|
|
181
|
+
["review_completed", renderReviewCompleted],
|
|
182
|
+
["revision_required", renderRevisionRequired],
|
|
183
|
+
["proposal_decided", renderProposalDecided],
|
|
184
|
+
]);
|
|
185
|
+
function defaultTemplate(event, _data, _cfg) {
|
|
186
|
+
return `[Hub] Notification: ${event}.`;
|
|
187
|
+
}
|
|
188
|
+
export function buildPromptText(event, data, cfg) {
|
|
189
|
+
const template = RENDER_REGISTRY.get(event);
|
|
190
|
+
if (template)
|
|
191
|
+
return template(data, cfg);
|
|
192
|
+
return defaultTemplate(event, data, cfg);
|
|
193
|
+
}
|
|
194
|
+
export function buildToastMessage(event, data) {
|
|
195
|
+
switch (event) {
|
|
196
|
+
case "task_issued":
|
|
197
|
+
return `New directive: ${data.taskId || "unknown"}`;
|
|
198
|
+
case "review_completed":
|
|
199
|
+
return `Review complete: ${data.taskId || "task"}`;
|
|
200
|
+
case "revision_required":
|
|
201
|
+
return `Revision required: ${data.taskId || "task"} — report rejected`;
|
|
202
|
+
case "proposal_decided":
|
|
203
|
+
return `Proposal ${data.proposalId || ""}: ${data.decision || "decided"}`;
|
|
204
|
+
case "clarification_answered":
|
|
205
|
+
return `Clarification answered: ${data.taskId || "task"}`;
|
|
206
|
+
case "thread_message":
|
|
207
|
+
return `Thread reply: "${data.title || data.threadId || "thread"}"`;
|
|
208
|
+
case "thread_convergence_finalized":
|
|
209
|
+
return `Thread converged: "${data.title || data.threadId}" (${data.intent || "no intent"}, ${data.executedCount ?? 0}/${data.committedActionCount ?? 0} executed)`;
|
|
210
|
+
case "agent_state_changed": {
|
|
211
|
+
const agent = data.agent;
|
|
212
|
+
const id = agent?.id || "unknown";
|
|
213
|
+
const cause = data.cause || "unknown";
|
|
214
|
+
return `Agent ${id} state-changed (${cause})`;
|
|
215
|
+
}
|
|
216
|
+
default:
|
|
217
|
+
return `Hub: ${event}`;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=prompt-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-format.js","sourceRoot":"","sources":["../src/prompt-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;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