@ericsanchezok/meta-protocol 0.0.0-dev-202603301312 → 0.0.0-dev-202604050856

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/bash.d.ts CHANGED
@@ -51,6 +51,7 @@ export declare namespace MetaProtocolBash {
51
51
  envID: z.ZodString;
52
52
  tool: z.ZodLiteral<"bash">;
53
53
  action: z.ZodLiteral<"execute">;
54
+ sessionID: z.ZodString;
54
55
  payload: z.ZodObject<{
55
56
  command: z.ZodString;
56
57
  description: z.ZodString;
@@ -65,6 +66,8 @@ export declare namespace MetaProtocolBash {
65
66
  version: z.ZodLiteral<1>;
66
67
  requestID: z.ZodString;
67
68
  ok: z.ZodLiteral<true>;
69
+ tool: z.ZodLiteral<"bash">;
70
+ action: z.ZodLiteral<"execute">;
68
71
  result: z.ZodObject<{
69
72
  title: z.ZodString;
70
73
  metadata: z.ZodObject<{
package/dist/bash.js CHANGED
@@ -31,10 +31,13 @@ export var MetaProtocolBash;
31
31
  MetaProtocolBash.ExecuteRequest = MetaProtocolEnvelope.RequestBase.extend({
32
32
  tool: z.literal("bash"),
33
33
  action: z.literal("execute"),
34
+ sessionID: MetaProtocolEnv.SessionID,
34
35
  payload: MetaProtocolBash.ExecutePayload,
35
36
  });
36
- MetaProtocolBash.ExecuteResult = MetaProtocolEnvelope.ResultBase.extend({
37
+ MetaProtocolBash.ExecuteResult = MetaProtocolEnvelope.TypedResultBase.extend({
37
38
  ok: z.literal(true),
39
+ tool: z.literal("bash"),
40
+ action: z.literal("execute"),
38
41
  result: MetaProtocolBash.Result,
39
42
  });
40
43
  })(MetaProtocolBash || (MetaProtocolBash = {}));
@@ -0,0 +1,4 @@
1
+ export declare namespace MetaProtocolBridge {
2
+ const RequestEvent = "meta.execution.request";
3
+ const ResponseEvent = "meta.execution.response";
4
+ }
package/dist/bridge.js ADDED
@@ -0,0 +1,5 @@
1
+ export var MetaProtocolBridge;
2
+ (function (MetaProtocolBridge) {
3
+ MetaProtocolBridge.RequestEvent = "meta.execution.request";
4
+ MetaProtocolBridge.ResponseEvent = "meta.execution.response";
5
+ })(MetaProtocolBridge || (MetaProtocolBridge = {}));
package/dist/client.d.ts CHANGED
@@ -1,9 +1,15 @@
1
1
  import type { MetaProtocolBash } from "./bash";
2
2
  import type { MetaProtocolEnv } from "./env";
3
3
  import type { MetaProtocolProcess } from "./process";
4
+ import type { MetaProtocolSession } from "./session";
4
5
  export declare namespace MetaProtocolClient {
6
+ interface RemoteExecutionOptions {
7
+ sessionID?: MetaProtocolEnv.SessionID;
8
+ targetAgentID?: string;
9
+ }
5
10
  interface ExecutionClient {
6
- executeBash(envID: MetaProtocolEnv.EnvID, input: MetaProtocolBash.ExecutePayload): Promise<MetaProtocolBash.Result>;
7
- executeProcess(envID: MetaProtocolEnv.EnvID, input: MetaProtocolProcess.ExecutePayload): Promise<MetaProtocolProcess.Result>;
11
+ executeBash(envID: MetaProtocolEnv.EnvID, input: MetaProtocolBash.ExecutePayload, options?: RemoteExecutionOptions): Promise<MetaProtocolBash.Result>;
12
+ executeProcess(envID: MetaProtocolEnv.EnvID, input: MetaProtocolProcess.ExecutePayload, options?: RemoteExecutionOptions): Promise<MetaProtocolProcess.Result>;
13
+ executeSession(envID: MetaProtocolEnv.EnvID, input: MetaProtocolSession.ExecutePayload, options?: RemoteExecutionOptions): Promise<MetaProtocolSession.Result>;
8
14
  }
9
15
  }
package/dist/env.d.ts CHANGED
@@ -2,6 +2,8 @@ import z from "zod";
2
2
  export declare namespace MetaProtocolEnv {
3
3
  const EnvID: z.ZodString;
4
4
  type EnvID = z.infer<typeof EnvID>;
5
+ const SessionID: z.ZodString;
6
+ type SessionID = z.infer<typeof SessionID>;
5
7
  const ProcessID: z.ZodString;
6
8
  type ProcessID = z.infer<typeof ProcessID>;
7
9
  const HostSessionID: z.ZodString;
@@ -12,5 +14,12 @@ export declare namespace MetaProtocolEnv {
12
14
  kind: "remote";
13
15
  envID: EnvID;
14
16
  };
17
+ type InvalidReason = "placeholder_alias" | "invalid_format";
18
+ class InvalidEnvIDError extends Error {
19
+ readonly envID: string;
20
+ readonly reason: InvalidReason;
21
+ constructor(envID: string, reason: InvalidReason);
22
+ }
23
+ function normalize(envID?: string): EnvID | undefined;
15
24
  function resolve(envID?: string): Target;
16
25
  }
package/dist/env.js CHANGED
@@ -2,15 +2,73 @@ import z from "zod";
2
2
  export var MetaProtocolEnv;
3
3
  (function (MetaProtocolEnv) {
4
4
  MetaProtocolEnv.EnvID = z.string().min(1).describe("Execution environment ID");
5
+ MetaProtocolEnv.SessionID = z.string().min(1).describe("Remote collaboration session identifier");
5
6
  MetaProtocolEnv.ProcessID = z.string().min(1).describe("Opaque process identifier");
6
7
  MetaProtocolEnv.HostSessionID = z.string().min(1).describe("Remote host session identifier");
8
+ const LOCAL_ALIASES = new Set([
9
+ "local",
10
+ ":local",
11
+ "localhost",
12
+ "127.0.0.1",
13
+ "::1",
14
+ "loopback",
15
+ "self",
16
+ ":self",
17
+ "current",
18
+ ":current",
19
+ "host",
20
+ ":host",
21
+ "this",
22
+ ":this",
23
+ ]);
24
+ const PLACEHOLDER_ALIASES = new Set(["undefined", "null", "none", "nil", "n/a"]);
25
+ const ENVID_PREFIX = "env_";
26
+ class InvalidEnvIDError extends Error {
27
+ envID;
28
+ reason;
29
+ constructor(envID, reason) {
30
+ super(reason === "placeholder_alias"
31
+ ? `Invalid envID "${envID}". This looks like a placeholder value, not a real remote environment ID. ` +
32
+ `For local execution, do NOT include the envID parameter at all — remove it from your tool call. ` +
33
+ `For remote execution, pass a real remote envID such as "env_...".`
34
+ : `Invalid envID "${envID}". Remote environment IDs must start with "${ENVID_PREFIX}". ` +
35
+ `For local execution, do NOT include the envID parameter at all — remove it from your tool call. ` +
36
+ `Do not try to pass a value meaning "local" or "omit" — simply leave out the envID key entirely.`);
37
+ this.envID = envID;
38
+ this.reason = reason;
39
+ this.name = "MetaProtocolInvalidEnvIDError";
40
+ }
41
+ }
42
+ MetaProtocolEnv.InvalidEnvIDError = InvalidEnvIDError;
43
+ function normalize(envID) {
44
+ if (envID === undefined) {
45
+ return undefined;
46
+ }
47
+ const trimmed = envID.trim();
48
+ if (!trimmed) {
49
+ return undefined;
50
+ }
51
+ const lowered = trimmed.toLowerCase();
52
+ if (LOCAL_ALIASES.has(lowered)) {
53
+ return undefined;
54
+ }
55
+ if (PLACEHOLDER_ALIASES.has(lowered)) {
56
+ throw new InvalidEnvIDError(trimmed, "placeholder_alias");
57
+ }
58
+ if (!trimmed.startsWith(ENVID_PREFIX)) {
59
+ throw new InvalidEnvIDError(trimmed, "invalid_format");
60
+ }
61
+ return trimmed;
62
+ }
63
+ MetaProtocolEnv.normalize = normalize;
7
64
  function resolve(envID) {
8
- if (!envID) {
65
+ const normalized = normalize(envID);
66
+ if (!normalized) {
9
67
  return { kind: "local" };
10
68
  }
11
69
  return {
12
70
  kind: "remote",
13
- envID,
71
+ envID: normalized,
14
72
  };
15
73
  }
16
74
  MetaProtocolEnv.resolve = resolve;
@@ -3,6 +3,7 @@ export declare namespace MetaProtocolEnvelope {
3
3
  const Tool: z.ZodEnum<{
4
4
  bash: "bash";
5
5
  process: "process";
6
+ session: "session";
6
7
  }>;
7
8
  type Tool = z.infer<typeof Tool>;
8
9
  const RequestBase: z.ZodObject<{
@@ -12,6 +13,7 @@ export declare namespace MetaProtocolEnvelope {
12
13
  tool: z.ZodEnum<{
13
14
  bash: "bash";
14
15
  process: "process";
16
+ session: "session";
15
17
  }>;
16
18
  action: z.ZodString;
17
19
  }, z.core.$strip>;
@@ -22,10 +24,28 @@ export declare namespace MetaProtocolEnvelope {
22
24
  ok: z.ZodBoolean;
23
25
  }, z.core.$strip>;
24
26
  type ResultBase = z.infer<typeof ResultBase>;
27
+ const TypedResultBase: z.ZodObject<{
28
+ version: z.ZodLiteral<1>;
29
+ requestID: z.ZodString;
30
+ ok: z.ZodBoolean;
31
+ tool: z.ZodEnum<{
32
+ bash: "bash";
33
+ process: "process";
34
+ session: "session";
35
+ }>;
36
+ action: z.ZodString;
37
+ }, z.core.$strip>;
38
+ type TypedResultBase = z.infer<typeof TypedResultBase>;
25
39
  const ErrorResult: z.ZodObject<{
26
40
  version: z.ZodLiteral<1>;
27
41
  requestID: z.ZodString;
28
42
  ok: z.ZodLiteral<false>;
43
+ tool: z.ZodOptional<z.ZodEnum<{
44
+ bash: "bash";
45
+ process: "process";
46
+ session: "session";
47
+ }>>;
48
+ action: z.ZodOptional<z.ZodString>;
29
49
  error: z.ZodObject<{
30
50
  code: z.ZodEnum<{
31
51
  env_not_found: "env_not_found";
@@ -41,6 +61,11 @@ export declare namespace MetaProtocolEnvelope {
41
61
  host_internal_error: "host_internal_error";
42
62
  stale_process_handle: "stale_process_handle";
43
63
  stdin_unavailable: "stdin_unavailable";
64
+ session_required: "session_required";
65
+ session_invalid: "session_invalid";
66
+ session_busy: "session_busy";
67
+ session_refused: "session_refused";
68
+ session_caller_mismatch: "session_caller_mismatch";
44
69
  }>;
45
70
  message: z.ZodString;
46
71
  details: z.ZodOptional<z.ZodUnknown>;
package/dist/envelope.js CHANGED
@@ -3,7 +3,7 @@ import { MetaProtocolEnv } from "./env";
3
3
  import { MetaProtocolError } from "./error";
4
4
  export var MetaProtocolEnvelope;
5
5
  (function (MetaProtocolEnvelope) {
6
- MetaProtocolEnvelope.Tool = z.enum(["bash", "process"]);
6
+ MetaProtocolEnvelope.Tool = z.enum(["bash", "process", "session"]);
7
7
  MetaProtocolEnvelope.RequestBase = z.object({
8
8
  version: z.literal(1),
9
9
  requestID: z.string().min(1),
@@ -16,8 +16,14 @@ export var MetaProtocolEnvelope;
16
16
  requestID: z.string().min(1),
17
17
  ok: z.boolean(),
18
18
  });
19
+ MetaProtocolEnvelope.TypedResultBase = MetaProtocolEnvelope.ResultBase.extend({
20
+ tool: MetaProtocolEnvelope.Tool,
21
+ action: z.string().min(1),
22
+ });
19
23
  MetaProtocolEnvelope.ErrorResult = MetaProtocolEnvelope.ResultBase.extend({
20
24
  ok: z.literal(false),
25
+ tool: MetaProtocolEnvelope.Tool.optional(),
26
+ action: z.string().min(1).optional(),
21
27
  error: MetaProtocolError.Shape,
22
28
  });
23
29
  })(MetaProtocolEnvelope || (MetaProtocolEnvelope = {}));
package/dist/error.d.ts CHANGED
@@ -14,6 +14,11 @@ export declare namespace MetaProtocolError {
14
14
  host_internal_error: "host_internal_error";
15
15
  stale_process_handle: "stale_process_handle";
16
16
  stdin_unavailable: "stdin_unavailable";
17
+ session_required: "session_required";
18
+ session_invalid: "session_invalid";
19
+ session_busy: "session_busy";
20
+ session_refused: "session_refused";
21
+ session_caller_mismatch: "session_caller_mismatch";
17
22
  }>;
18
23
  type Code = z.infer<typeof Code>;
19
24
  const Shape: z.ZodObject<{
@@ -31,6 +36,11 @@ export declare namespace MetaProtocolError {
31
36
  host_internal_error: "host_internal_error";
32
37
  stale_process_handle: "stale_process_handle";
33
38
  stdin_unavailable: "stdin_unavailable";
39
+ session_required: "session_required";
40
+ session_invalid: "session_invalid";
41
+ session_busy: "session_busy";
42
+ session_refused: "session_refused";
43
+ session_caller_mismatch: "session_caller_mismatch";
34
44
  }>;
35
45
  message: z.ZodString;
36
46
  details: z.ZodOptional<z.ZodUnknown>;
package/dist/error.js CHANGED
@@ -15,6 +15,11 @@ export var MetaProtocolError;
15
15
  "host_internal_error",
16
16
  "stale_process_handle",
17
17
  "stdin_unavailable",
18
+ "session_required",
19
+ "session_invalid",
20
+ "session_busy",
21
+ "session_refused",
22
+ "session_caller_mismatch",
18
23
  ]);
19
24
  MetaProtocolError.Shape = z.object({
20
25
  code: MetaProtocolError.Code,
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from "./env";
2
2
  export * from "./error";
3
3
  export * from "./envelope";
4
+ export * from "./bridge";
4
5
  export * from "./bash";
5
6
  export * from "./process";
7
+ export * from "./session";
6
8
  export * from "./client";
7
9
  export * from "./host";
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from "./env";
2
2
  export * from "./error";
3
3
  export * from "./envelope";
4
+ export * from "./bridge";
4
5
  export * from "./bash";
5
6
  export * from "./process";
7
+ export * from "./session";
6
8
  export * from "./client";
7
9
  export * from "./host";
package/dist/process.d.ts CHANGED
@@ -184,6 +184,7 @@ export declare namespace MetaProtocolProcess {
184
184
  clear: "clear";
185
185
  remove: "remove";
186
186
  }>;
187
+ sessionID: z.ZodString;
187
188
  payload: z.ZodDiscriminatedUnion<[z.ZodObject<{
188
189
  action: z.ZodLiteral<"list">;
189
190
  }, z.core.$strip>, z.ZodObject<{
@@ -220,6 +221,17 @@ export declare namespace MetaProtocolProcess {
220
221
  version: z.ZodLiteral<1>;
221
222
  requestID: z.ZodString;
222
223
  ok: z.ZodLiteral<true>;
224
+ tool: z.ZodLiteral<"process">;
225
+ action: z.ZodEnum<{
226
+ list: "list";
227
+ poll: "poll";
228
+ log: "log";
229
+ write: "write";
230
+ "send-keys": "send-keys";
231
+ kill: "kill";
232
+ clear: "clear";
233
+ remove: "remove";
234
+ }>;
223
235
  result: z.ZodObject<{
224
236
  title: z.ZodString;
225
237
  metadata: z.ZodObject<{
package/dist/process.js CHANGED
@@ -80,10 +80,13 @@ export var MetaProtocolProcess;
80
80
  MetaProtocolProcess.ExecuteRequest = MetaProtocolEnvelope.RequestBase.extend({
81
81
  tool: z.literal("process"),
82
82
  action: MetaProtocolProcess.Action,
83
+ sessionID: MetaProtocolEnv.SessionID,
83
84
  payload: MetaProtocolProcess.ExecutePayload,
84
85
  });
85
- MetaProtocolProcess.ExecuteResult = MetaProtocolEnvelope.ResultBase.extend({
86
+ MetaProtocolProcess.ExecuteResult = MetaProtocolEnvelope.TypedResultBase.extend({
86
87
  ok: z.literal(true),
88
+ tool: z.literal("process"),
89
+ action: MetaProtocolProcess.Action,
87
90
  result: MetaProtocolProcess.Result,
88
91
  });
89
92
  })(MetaProtocolProcess || (MetaProtocolProcess = {}));
@@ -0,0 +1,144 @@
1
+ import z from "zod";
2
+ export declare namespace MetaProtocolSession {
3
+ const Action: z.ZodEnum<{
4
+ open: "open";
5
+ close: "close";
6
+ heartbeat: "heartbeat";
7
+ }>;
8
+ type Action = z.infer<typeof Action>;
9
+ const Status: z.ZodEnum<{
10
+ opened: "opened";
11
+ closed: "closed";
12
+ alive: "alive";
13
+ refused: "refused";
14
+ busy: "busy";
15
+ }>;
16
+ type Status = z.infer<typeof Status>;
17
+ const ExecutePayload: z.ZodDiscriminatedUnion<[z.ZodObject<{
18
+ action: z.ZodLiteral<"open">;
19
+ label: z.ZodOptional<z.ZodString>;
20
+ }, z.core.$strip>, z.ZodObject<{
21
+ action: z.ZodLiteral<"close">;
22
+ sessionID: z.ZodString;
23
+ }, z.core.$strip>, z.ZodObject<{
24
+ action: z.ZodLiteral<"heartbeat">;
25
+ sessionID: z.ZodString;
26
+ }, z.core.$strip>], "action">;
27
+ type ExecutePayload = z.infer<typeof ExecutePayload>;
28
+ const ResultMetadata: z.ZodObject<{
29
+ action: z.ZodEnum<{
30
+ open: "open";
31
+ close: "close";
32
+ heartbeat: "heartbeat";
33
+ }>;
34
+ status: z.ZodEnum<{
35
+ opened: "opened";
36
+ closed: "closed";
37
+ alive: "alive";
38
+ refused: "refused";
39
+ busy: "busy";
40
+ }>;
41
+ sessionID: z.ZodOptional<z.ZodString>;
42
+ remoteAgentID: z.ZodOptional<z.ZodString>;
43
+ remoteOwnerUserID: z.ZodOptional<z.ZodNumber>;
44
+ label: z.ZodOptional<z.ZodString>;
45
+ hostSessionID: z.ZodOptional<z.ZodString>;
46
+ envID: z.ZodOptional<z.ZodString>;
47
+ backend: z.ZodOptional<z.ZodEnum<{
48
+ local: "local";
49
+ remote: "remote";
50
+ }>>;
51
+ }, z.core.$strip>;
52
+ type ResultMetadata = z.infer<typeof ResultMetadata>;
53
+ const Result: z.ZodObject<{
54
+ title: z.ZodString;
55
+ metadata: z.ZodObject<{
56
+ action: z.ZodEnum<{
57
+ open: "open";
58
+ close: "close";
59
+ heartbeat: "heartbeat";
60
+ }>;
61
+ status: z.ZodEnum<{
62
+ opened: "opened";
63
+ closed: "closed";
64
+ alive: "alive";
65
+ refused: "refused";
66
+ busy: "busy";
67
+ }>;
68
+ sessionID: z.ZodOptional<z.ZodString>;
69
+ remoteAgentID: z.ZodOptional<z.ZodString>;
70
+ remoteOwnerUserID: z.ZodOptional<z.ZodNumber>;
71
+ label: z.ZodOptional<z.ZodString>;
72
+ hostSessionID: z.ZodOptional<z.ZodString>;
73
+ envID: z.ZodOptional<z.ZodString>;
74
+ backend: z.ZodOptional<z.ZodEnum<{
75
+ local: "local";
76
+ remote: "remote";
77
+ }>>;
78
+ }, z.core.$strip>;
79
+ output: z.ZodString;
80
+ }, z.core.$strip>;
81
+ type Result = z.infer<typeof Result>;
82
+ const ExecuteRequest: z.ZodObject<{
83
+ version: z.ZodLiteral<1>;
84
+ requestID: z.ZodString;
85
+ envID: z.ZodString;
86
+ tool: z.ZodLiteral<"session">;
87
+ action: z.ZodEnum<{
88
+ open: "open";
89
+ close: "close";
90
+ heartbeat: "heartbeat";
91
+ }>;
92
+ payload: z.ZodDiscriminatedUnion<[z.ZodObject<{
93
+ action: z.ZodLiteral<"open">;
94
+ label: z.ZodOptional<z.ZodString>;
95
+ }, z.core.$strip>, z.ZodObject<{
96
+ action: z.ZodLiteral<"close">;
97
+ sessionID: z.ZodString;
98
+ }, z.core.$strip>, z.ZodObject<{
99
+ action: z.ZodLiteral<"heartbeat">;
100
+ sessionID: z.ZodString;
101
+ }, z.core.$strip>], "action">;
102
+ }, z.core.$strip>;
103
+ type ExecuteRequest = z.infer<typeof ExecuteRequest>;
104
+ const ExecuteResult: z.ZodObject<{
105
+ version: z.ZodLiteral<1>;
106
+ requestID: z.ZodString;
107
+ ok: z.ZodLiteral<true>;
108
+ tool: z.ZodLiteral<"session">;
109
+ action: z.ZodEnum<{
110
+ open: "open";
111
+ close: "close";
112
+ heartbeat: "heartbeat";
113
+ }>;
114
+ result: z.ZodObject<{
115
+ title: z.ZodString;
116
+ metadata: z.ZodObject<{
117
+ action: z.ZodEnum<{
118
+ open: "open";
119
+ close: "close";
120
+ heartbeat: "heartbeat";
121
+ }>;
122
+ status: z.ZodEnum<{
123
+ opened: "opened";
124
+ closed: "closed";
125
+ alive: "alive";
126
+ refused: "refused";
127
+ busy: "busy";
128
+ }>;
129
+ sessionID: z.ZodOptional<z.ZodString>;
130
+ remoteAgentID: z.ZodOptional<z.ZodString>;
131
+ remoteOwnerUserID: z.ZodOptional<z.ZodNumber>;
132
+ label: z.ZodOptional<z.ZodString>;
133
+ hostSessionID: z.ZodOptional<z.ZodString>;
134
+ envID: z.ZodOptional<z.ZodString>;
135
+ backend: z.ZodOptional<z.ZodEnum<{
136
+ local: "local";
137
+ remote: "remote";
138
+ }>>;
139
+ }, z.core.$strip>;
140
+ output: z.ZodString;
141
+ }, z.core.$strip>;
142
+ }, z.core.$strip>;
143
+ type ExecuteResult = z.infer<typeof ExecuteResult>;
144
+ }
@@ -0,0 +1,49 @@
1
+ import z from "zod";
2
+ import { MetaProtocolEnvelope } from "./envelope";
3
+ import { MetaProtocolEnv } from "./env";
4
+ export var MetaProtocolSession;
5
+ (function (MetaProtocolSession) {
6
+ MetaProtocolSession.Action = z.enum(["open", "close", "heartbeat"]);
7
+ MetaProtocolSession.Status = z.enum(["opened", "closed", "alive", "refused", "busy"]);
8
+ MetaProtocolSession.ExecutePayload = z.discriminatedUnion("action", [
9
+ z.object({
10
+ action: z.literal("open"),
11
+ label: z.string().optional(),
12
+ }),
13
+ z.object({
14
+ action: z.literal("close"),
15
+ sessionID: MetaProtocolEnv.SessionID,
16
+ }),
17
+ z.object({
18
+ action: z.literal("heartbeat"),
19
+ sessionID: MetaProtocolEnv.SessionID,
20
+ }),
21
+ ]);
22
+ MetaProtocolSession.ResultMetadata = z.object({
23
+ action: MetaProtocolSession.Action,
24
+ status: MetaProtocolSession.Status,
25
+ sessionID: MetaProtocolEnv.SessionID.optional(),
26
+ remoteAgentID: z.string().optional(),
27
+ remoteOwnerUserID: z.number().optional(),
28
+ label: z.string().optional(),
29
+ hostSessionID: MetaProtocolEnv.HostSessionID.optional(),
30
+ envID: MetaProtocolEnv.EnvID.optional(),
31
+ backend: z.enum(["local", "remote"]).optional(),
32
+ });
33
+ MetaProtocolSession.Result = z.object({
34
+ title: z.string(),
35
+ metadata: MetaProtocolSession.ResultMetadata,
36
+ output: z.string(),
37
+ });
38
+ MetaProtocolSession.ExecuteRequest = MetaProtocolEnvelope.RequestBase.extend({
39
+ tool: z.literal("session"),
40
+ action: MetaProtocolSession.Action,
41
+ payload: MetaProtocolSession.ExecutePayload,
42
+ });
43
+ MetaProtocolSession.ExecuteResult = MetaProtocolEnvelope.TypedResultBase.extend({
44
+ ok: z.literal(true),
45
+ tool: z.literal("session"),
46
+ action: MetaProtocolSession.Action,
47
+ result: MetaProtocolSession.Result,
48
+ });
49
+ })(MetaProtocolSession || (MetaProtocolSession = {}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@ericsanchezok/meta-protocol",
4
- "version": "0.0.0-dev-202603301312",
4
+ "version": "0.0.0-dev-202604050856",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "types": "./src/index.ts",
package/script/publish.ts CHANGED
@@ -21,12 +21,18 @@ for (const [key, value] of Object.entries(pkg.exports)) {
21
21
  await Bun.write("package.json", JSON.stringify(pkg, null, 2))
22
22
 
23
23
  try {
24
- const NPM_REGISTRY = "https://registry.npmjs.org"
25
- await $`rm -f *.tgz`.nothrow()
26
- await $`bun pm pack`
27
- const tgz = (await $`ls *.tgz`.text()).trim()
28
- const authFlag = process.env.NPM_TOKEN ? `--//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}` : ""
29
- await $`npm publish ${tgz} --tag ${Script.channel} --registry ${NPM_REGISTRY} --access public ${authFlag}`
24
+ if (await Script.npmVersionExists(pkg.name, Script.version)) {
25
+ console.log(`${pkg.name}@${Script.version} already published, skipping`)
26
+ } else {
27
+ const NPM_REGISTRY = "https://registry.npmjs.org"
28
+ await $`rm -f *.tgz`.nothrow()
29
+ await $`bun pm pack`
30
+ const tgz = (await $`ls *.tgz`.text()).trim()
31
+ const authFlag = process.env.NPM_TOKEN ? `--//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}` : ""
32
+ await Script.retry(
33
+ () => $`npm publish ${tgz} --tag ${Script.channel} --registry ${NPM_REGISTRY} --access public ${authFlag}`,
34
+ )
35
+ }
30
36
  } finally {
31
37
  await Bun.write("package.json", JSON.stringify(original, null, 2))
32
38
  }
package/src/bash.ts CHANGED
@@ -37,12 +37,15 @@ export namespace MetaProtocolBash {
37
37
  export const ExecuteRequest = MetaProtocolEnvelope.RequestBase.extend({
38
38
  tool: z.literal("bash"),
39
39
  action: z.literal("execute"),
40
+ sessionID: MetaProtocolEnv.SessionID,
40
41
  payload: ExecutePayload,
41
42
  })
42
43
  export type ExecuteRequest = z.infer<typeof ExecuteRequest>
43
44
 
44
- export const ExecuteResult = MetaProtocolEnvelope.ResultBase.extend({
45
+ export const ExecuteResult = MetaProtocolEnvelope.TypedResultBase.extend({
45
46
  ok: z.literal(true),
47
+ tool: z.literal("bash"),
48
+ action: z.literal("execute"),
46
49
  result: Result,
47
50
  })
48
51
  export type ExecuteResult = z.infer<typeof ExecuteResult>
package/src/bridge.ts ADDED
@@ -0,0 +1,4 @@
1
+ export namespace MetaProtocolBridge {
2
+ export const RequestEvent = "meta.execution.request"
3
+ export const ResponseEvent = "meta.execution.response"
4
+ }
package/src/client.ts CHANGED
@@ -1,13 +1,29 @@
1
1
  import type { MetaProtocolBash } from "./bash"
2
2
  import type { MetaProtocolEnv } from "./env"
3
3
  import type { MetaProtocolProcess } from "./process"
4
+ import type { MetaProtocolSession } from "./session"
4
5
 
5
6
  export namespace MetaProtocolClient {
7
+ export interface RemoteExecutionOptions {
8
+ sessionID?: MetaProtocolEnv.SessionID
9
+ targetAgentID?: string
10
+ }
11
+
6
12
  export interface ExecutionClient {
7
- executeBash(envID: MetaProtocolEnv.EnvID, input: MetaProtocolBash.ExecutePayload): Promise<MetaProtocolBash.Result>
13
+ executeBash(
14
+ envID: MetaProtocolEnv.EnvID,
15
+ input: MetaProtocolBash.ExecutePayload,
16
+ options?: RemoteExecutionOptions,
17
+ ): Promise<MetaProtocolBash.Result>
8
18
  executeProcess(
9
19
  envID: MetaProtocolEnv.EnvID,
10
20
  input: MetaProtocolProcess.ExecutePayload,
21
+ options?: RemoteExecutionOptions,
11
22
  ): Promise<MetaProtocolProcess.Result>
23
+ executeSession(
24
+ envID: MetaProtocolEnv.EnvID,
25
+ input: MetaProtocolSession.ExecutePayload,
26
+ options?: RemoteExecutionOptions,
27
+ ): Promise<MetaProtocolSession.Result>
12
28
  }
13
29
  }
package/src/env.ts CHANGED
@@ -4,6 +4,9 @@ export namespace MetaProtocolEnv {
4
4
  export const EnvID = z.string().min(1).describe("Execution environment ID")
5
5
  export type EnvID = z.infer<typeof EnvID>
6
6
 
7
+ export const SessionID = z.string().min(1).describe("Remote collaboration session identifier")
8
+ export type SessionID = z.infer<typeof SessionID>
9
+
7
10
  export const ProcessID = z.string().min(1).describe("Opaque process identifier")
8
11
  export type ProcessID = z.infer<typeof ProcessID>
9
12
 
@@ -12,13 +15,81 @@ export namespace MetaProtocolEnv {
12
15
 
13
16
  export type Target = { kind: "local" } | { kind: "remote"; envID: EnvID }
14
17
 
18
+ const LOCAL_ALIASES = new Set([
19
+ "local",
20
+ ":local",
21
+ "localhost",
22
+ "127.0.0.1",
23
+ "::1",
24
+ "loopback",
25
+ "self",
26
+ ":self",
27
+ "current",
28
+ ":current",
29
+ "host",
30
+ ":host",
31
+ "this",
32
+ ":this",
33
+ ])
34
+
35
+ const PLACEHOLDER_ALIASES = new Set(["undefined", "null", "none", "nil", "n/a"])
36
+
37
+ const ENVID_PREFIX = "env_"
38
+
39
+ export type InvalidReason = "placeholder_alias" | "invalid_format"
40
+
41
+ export class InvalidEnvIDError extends Error {
42
+ constructor(
43
+ readonly envID: string,
44
+ readonly reason: InvalidReason,
45
+ ) {
46
+ super(
47
+ reason === "placeholder_alias"
48
+ ? `Invalid envID "${envID}". This looks like a placeholder value, not a real remote environment ID. ` +
49
+ `For local execution, do NOT include the envID parameter at all — remove it from your tool call. ` +
50
+ `For remote execution, pass a real remote envID such as "env_...".`
51
+ : `Invalid envID "${envID}". Remote environment IDs must start with "${ENVID_PREFIX}". ` +
52
+ `For local execution, do NOT include the envID parameter at all — remove it from your tool call. ` +
53
+ `Do not try to pass a value meaning "local" or "omit" — simply leave out the envID key entirely.`,
54
+ )
55
+ this.name = "MetaProtocolInvalidEnvIDError"
56
+ }
57
+ }
58
+
59
+ export function normalize(envID?: string): EnvID | undefined {
60
+ if (envID === undefined) {
61
+ return undefined
62
+ }
63
+
64
+ const trimmed = envID.trim()
65
+ if (!trimmed) {
66
+ return undefined
67
+ }
68
+
69
+ const lowered = trimmed.toLowerCase()
70
+ if (LOCAL_ALIASES.has(lowered)) {
71
+ return undefined
72
+ }
73
+
74
+ if (PLACEHOLDER_ALIASES.has(lowered)) {
75
+ throw new InvalidEnvIDError(trimmed, "placeholder_alias")
76
+ }
77
+
78
+ if (!trimmed.startsWith(ENVID_PREFIX)) {
79
+ throw new InvalidEnvIDError(trimmed, "invalid_format")
80
+ }
81
+
82
+ return trimmed as EnvID
83
+ }
84
+
15
85
  export function resolve(envID?: string): Target {
16
- if (!envID) {
86
+ const normalized = normalize(envID)
87
+ if (!normalized) {
17
88
  return { kind: "local" }
18
89
  }
19
90
  return {
20
91
  kind: "remote",
21
- envID,
92
+ envID: normalized,
22
93
  }
23
94
  }
24
95
  }
package/src/envelope.ts CHANGED
@@ -3,7 +3,7 @@ import { MetaProtocolEnv } from "./env"
3
3
  import { MetaProtocolError } from "./error"
4
4
 
5
5
  export namespace MetaProtocolEnvelope {
6
- export const Tool = z.enum(["bash", "process"])
6
+ export const Tool = z.enum(["bash", "process", "session"])
7
7
  export type Tool = z.infer<typeof Tool>
8
8
 
9
9
  export const RequestBase = z.object({
@@ -22,8 +22,16 @@ export namespace MetaProtocolEnvelope {
22
22
  })
23
23
  export type ResultBase = z.infer<typeof ResultBase>
24
24
 
25
+ export const TypedResultBase = ResultBase.extend({
26
+ tool: Tool,
27
+ action: z.string().min(1),
28
+ })
29
+ export type TypedResultBase = z.infer<typeof TypedResultBase>
30
+
25
31
  export const ErrorResult = ResultBase.extend({
26
32
  ok: z.literal(false),
33
+ tool: Tool.optional(),
34
+ action: z.string().min(1).optional(),
27
35
  error: MetaProtocolError.Shape,
28
36
  })
29
37
  export type ErrorResult = z.infer<typeof ErrorResult>
package/src/error.ts CHANGED
@@ -15,6 +15,11 @@ export namespace MetaProtocolError {
15
15
  "host_internal_error",
16
16
  "stale_process_handle",
17
17
  "stdin_unavailable",
18
+ "session_required",
19
+ "session_invalid",
20
+ "session_busy",
21
+ "session_refused",
22
+ "session_caller_mismatch",
18
23
  ])
19
24
  export type Code = z.infer<typeof Code>
20
25
 
package/src/index.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from "./env"
2
2
  export * from "./error"
3
3
  export * from "./envelope"
4
+ export * from "./bridge"
4
5
  export * from "./bash"
5
6
  export * from "./process"
7
+ export * from "./session"
6
8
  export * from "./client"
7
9
  export * from "./host"
package/src/process.ts CHANGED
@@ -94,12 +94,15 @@ export namespace MetaProtocolProcess {
94
94
  export const ExecuteRequest = MetaProtocolEnvelope.RequestBase.extend({
95
95
  tool: z.literal("process"),
96
96
  action: Action,
97
+ sessionID: MetaProtocolEnv.SessionID,
97
98
  payload: ExecutePayload,
98
99
  })
99
100
  export type ExecuteRequest = z.infer<typeof ExecuteRequest>
100
101
 
101
- export const ExecuteResult = MetaProtocolEnvelope.ResultBase.extend({
102
+ export const ExecuteResult = MetaProtocolEnvelope.TypedResultBase.extend({
102
103
  ok: z.literal(true),
104
+ tool: z.literal("process"),
105
+ action: Action,
103
106
  result: Result,
104
107
  })
105
108
  export type ExecuteResult = z.infer<typeof ExecuteResult>
package/src/session.ts ADDED
@@ -0,0 +1,62 @@
1
+ import z from "zod"
2
+ import { MetaProtocolEnvelope } from "./envelope"
3
+ import { MetaProtocolEnv } from "./env"
4
+
5
+ export namespace MetaProtocolSession {
6
+ export const Action = z.enum(["open", "close", "heartbeat"])
7
+ export type Action = z.infer<typeof Action>
8
+
9
+ export const Status = z.enum(["opened", "closed", "alive", "refused", "busy"])
10
+ export type Status = z.infer<typeof Status>
11
+
12
+ export const ExecutePayload = z.discriminatedUnion("action", [
13
+ z.object({
14
+ action: z.literal("open"),
15
+ label: z.string().optional(),
16
+ }),
17
+ z.object({
18
+ action: z.literal("close"),
19
+ sessionID: MetaProtocolEnv.SessionID,
20
+ }),
21
+ z.object({
22
+ action: z.literal("heartbeat"),
23
+ sessionID: MetaProtocolEnv.SessionID,
24
+ }),
25
+ ])
26
+ export type ExecutePayload = z.infer<typeof ExecutePayload>
27
+
28
+ export const ResultMetadata = z.object({
29
+ action: Action,
30
+ status: Status,
31
+ sessionID: MetaProtocolEnv.SessionID.optional(),
32
+ remoteAgentID: z.string().optional(),
33
+ remoteOwnerUserID: z.number().optional(),
34
+ label: z.string().optional(),
35
+ hostSessionID: MetaProtocolEnv.HostSessionID.optional(),
36
+ envID: MetaProtocolEnv.EnvID.optional(),
37
+ backend: z.enum(["local", "remote"]).optional(),
38
+ })
39
+ export type ResultMetadata = z.infer<typeof ResultMetadata>
40
+
41
+ export const Result = z.object({
42
+ title: z.string(),
43
+ metadata: ResultMetadata,
44
+ output: z.string(),
45
+ })
46
+ export type Result = z.infer<typeof Result>
47
+
48
+ export const ExecuteRequest = MetaProtocolEnvelope.RequestBase.extend({
49
+ tool: z.literal("session"),
50
+ action: Action,
51
+ payload: ExecutePayload,
52
+ })
53
+ export type ExecuteRequest = z.infer<typeof ExecuteRequest>
54
+
55
+ export const ExecuteResult = MetaProtocolEnvelope.TypedResultBase.extend({
56
+ ok: z.literal(true),
57
+ tool: z.literal("session"),
58
+ action: Action,
59
+ result: Result,
60
+ })
61
+ export type ExecuteResult = z.infer<typeof ExecuteResult>
62
+ }
@@ -0,0 +1 @@
1
+ export {}