@cjhyy/code-shell-pet 0.8.1 → 0.8.2

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.
@@ -23,7 +23,7 @@ import { controlLongTaskAvailability, controlLongTaskTool, controlLongTaskToolDe
23
23
  import { PET_BEHAVIOR_PROFILE } from "./profile.js";
24
24
  import { createPetProjectionObserver, PET_HIDDEN_SESSION_KINDS } from "./projection-extension.js";
25
25
  import { PET_REPORT_TO_MIMI_METHOD } from "./protocol.js";
26
- import { reportToMimiAvailability, reportToMimiTool, reportToMimiToolDef, } from "./report-to-mimi.js";
26
+ import { requestMimiDeliveryAvailability, requestMimiDeliveryTool, requestMimiDeliveryToolDef, reportToMimiAvailability, reportToMimiTool, reportToMimiToolDef, } from "./report-to-mimi.js";
27
27
  import { validatePetRunParams } from "./run-params.js";
28
28
  export function createPetCapability() {
29
29
  let reportToMimi;
@@ -45,6 +45,20 @@ export function createPetCapability() {
45
45
  validateRunParams: validatePetRunParams,
46
46
  hiddenSessionKinds: PET_HIDDEN_SESSION_KINDS,
47
47
  catalogTools: [
48
+ {
49
+ definition: {
50
+ ...requestMimiDeliveryToolDef,
51
+ source: "builtin",
52
+ permissionDefault: "ask",
53
+ isReadOnly: false,
54
+ isConcurrencySafe: false,
55
+ },
56
+ execute: (args, ctx) => requestMimiDeliveryTool(args, ctx, reportToMimi),
57
+ exposure: {
58
+ presetTags: ["harness-min", "general"],
59
+ availability: requestMimiDeliveryAvailability,
60
+ },
61
+ },
48
62
  {
49
63
  definition: {
50
64
  ...reportToMimiToolDef,
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ export * from "./types.js";
11
11
  export * from "./delegation.js";
12
12
  export * from "./team.js";
13
13
  export * from "./protocol.js";
14
- export { REPORT_TO_MIMI_TOOL_NAME, reportToMimiToolDef, reportToMimiTool, reportToMimiAvailability, type PetReportToMimiSink, } from "./report-to-mimi.js";
14
+ export { REPORT_TO_MIMI_TOOL_NAME, REQUEST_MIMI_DELIVERY_TOOL_NAME, reportToMimiToolDef, reportToMimiTool, reportToMimiAvailability, requestMimiDeliveryToolDef, requestMimiDeliveryTool, requestMimiDeliveryAvailability, type PetReportToMimiSink, } from "./report-to-mimi.js";
15
15
  export { petRunOptionsFrom, validatePetRunParams, type PetRunOptions } from "./run-params.js";
16
16
  export { SessionIndex } from "./session-index.js";
17
17
  export { PendingDecisionIndex, safePendingTitle } from "./pending-decision-index.js";
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ export * from "./types.js";
11
11
  export * from "./delegation.js";
12
12
  export * from "./team.js";
13
13
  export * from "./protocol.js";
14
- export { REPORT_TO_MIMI_TOOL_NAME, reportToMimiToolDef, reportToMimiTool, reportToMimiAvailability, } from "./report-to-mimi.js";
14
+ export { REPORT_TO_MIMI_TOOL_NAME, REQUEST_MIMI_DELIVERY_TOOL_NAME, reportToMimiToolDef, reportToMimiTool, reportToMimiAvailability, requestMimiDeliveryToolDef, requestMimiDeliveryTool, requestMimiDeliveryAvailability, } from "./report-to-mimi.js";
15
15
  export { petRunOptionsFrom, validatePetRunParams } from "./run-params.js";
16
16
  export { SessionIndex } from "./session-index.js";
17
17
  export { PendingDecisionIndex, safePendingTitle } from "./pending-decision-index.js";
@@ -46,6 +46,10 @@ export interface PetReportToMimiEvent {
46
46
  sessionId: string;
47
47
  message: string;
48
48
  attachmentPaths?: string[];
49
+ /** Permission-gated owner request for Mimi to use one authorized outbound route. */
50
+ deliveryRequest?: {
51
+ channel: string;
52
+ };
49
53
  createdAt: number;
50
54
  }
51
55
  /**
@@ -1,7 +1,11 @@
1
1
  import type { ToolContext, ToolDefinition, ToolVisibilityContext } from "@cjhyy/code-shell-core/extension";
2
2
  import type { PetReportToMimiEvent } from "./protocol.js";
3
3
  export declare const REPORT_TO_MIMI_TOOL_NAME = "ReportToMimi";
4
+ export declare const REQUEST_MIMI_DELIVERY_TOOL_NAME = "RequestMimiDelivery";
4
5
  export declare const reportToMimiToolDef: ToolDefinition;
6
+ export declare const requestMimiDeliveryToolDef: ToolDefinition;
5
7
  export type PetReportToMimiSink = (event: PetReportToMimiEvent) => void;
6
8
  export declare function reportToMimiAvailability(ctx: ToolVisibilityContext): boolean;
9
+ export declare function requestMimiDeliveryAvailability(ctx: ToolVisibilityContext): boolean;
7
10
  export declare function reportToMimiTool(args: Record<string, unknown>, ctx?: ToolContext, report?: PetReportToMimiSink): Promise<string>;
11
+ export declare function requestMimiDeliveryTool(args: Record<string, unknown>, ctx?: ToolContext, report?: PetReportToMimiSink): Promise<string>;
@@ -2,11 +2,26 @@ import { createHash } from "node:crypto";
2
2
  import { isAbsolute } from "node:path";
3
3
  import { hasOnlyDeclaredToolArguments } from "./tool-arguments.js";
4
4
  export const REPORT_TO_MIMI_TOOL_NAME = "ReportToMimi";
5
+ export const REQUEST_MIMI_DELIVERY_TOOL_NAME = "RequestMimiDelivery";
6
+ const ATTACHMENT_PATHS_SCHEMA = {
7
+ type: "array",
8
+ minItems: 1,
9
+ maxItems: 4,
10
+ uniqueItems: true,
11
+ items: {
12
+ type: "string",
13
+ minLength: 1,
14
+ maxLength: 4_096,
15
+ },
16
+ description: "Optional absolute local artifact paths for Mimi. The host independently decides whether any route may send them.",
17
+ };
5
18
  export const reportToMimiToolDef = {
6
19
  name: REPORT_TO_MIMI_TOOL_NAME,
7
20
  description: "Report a result, status update, artifact, or question from the current Session to Mimi. " +
8
21
  "This works from any Session; Mimi decides how to present or act on the report. " +
9
- "Do not search for Mimi's hidden Session id and do not provide a channel or recipient.",
22
+ "This does not request external delivery. When the owner explicitly asks this Session to send " +
23
+ "something to WeChat, use RequestMimiDelivery once instead. Do not search for Mimi's hidden " +
24
+ "Session id and do not provide a channel or recipient here.",
10
25
  inputSchema: {
11
26
  type: "object",
12
27
  additionalProperties: false,
@@ -17,25 +32,44 @@ export const reportToMimiToolDef = {
17
32
  maxLength: 8_000,
18
33
  description: "Complete concise report for Mimi, including outcome, evidence, and any user decision needed.",
19
34
  },
20
- attachment_paths: {
21
- type: "array",
22
- minItems: 1,
23
- maxItems: 4,
24
- uniqueItems: true,
25
- items: {
26
- type: "string",
27
- minLength: 1,
28
- maxLength: 4_096,
29
- },
30
- description: "Optional absolute local artifact paths for Mimi. The host independently decides whether any route may send them.",
31
- },
35
+ attachment_paths: ATTACHMENT_PATHS_SCHEMA,
32
36
  },
33
37
  required: ["message"],
34
38
  },
35
39
  };
40
+ export const requestMimiDeliveryToolDef = {
41
+ name: REQUEST_MIMI_DELIVERY_TOOL_NAME,
42
+ description: "Ask Mimi's trusted host to deliver text and optional existing local artifacts through an " +
43
+ "owner-authorized outbound channel. Use only when the user explicitly asks the current Session " +
44
+ "to send or push something externally. For personal WeChat use channel=wechat. Call this tool " +
45
+ "exactly once; do not search for SendMessage, target ids, or Mimi's Session id. Acceptance means " +
46
+ "Mimi will validate and attempt the request; it is not proof that a platform or device received it.",
47
+ inputSchema: {
48
+ type: "object",
49
+ additionalProperties: false,
50
+ properties: {
51
+ channel: {
52
+ type: "string",
53
+ enum: ["wechat"],
54
+ description: "Semantic outbound channel requested by the owner; personal WeChat is wechat.",
55
+ },
56
+ text: {
57
+ type: "string",
58
+ minLength: 1,
59
+ maxLength: 8_000,
60
+ description: "Exact concise message the owner asked to deliver.",
61
+ },
62
+ attachment_paths: ATTACHMENT_PATHS_SCHEMA,
63
+ },
64
+ required: ["channel", "text"],
65
+ },
66
+ };
36
67
  export function reportToMimiAvailability(ctx) {
37
68
  return isReportableSessionId(ctx.sessionId);
38
69
  }
70
+ export function requestMimiDeliveryAvailability(ctx) {
71
+ return (isReportableSessionId(ctx.sessionId) && ctx.isSubAgent !== true && ctx.behaviorProfile !== "pet");
72
+ }
39
73
  export async function reportToMimiTool(args, ctx, report) {
40
74
  if (!isReportableSessionId(ctx?.sessionId)) {
41
75
  return "Error: ReportToMimi requires a valid current Session.";
@@ -66,6 +100,44 @@ export async function reportToMimiTool(args, ctx, report) {
66
100
  });
67
101
  return "Report accepted by Mimi's host. Delivery is asynchronous; do not search for Mimi's Session id or claim that an IM message was delivered.";
68
102
  }
103
+ export async function requestMimiDeliveryTool(args, ctx, report) {
104
+ if (!isReportableSessionId(ctx?.sessionId)) {
105
+ return "Error: RequestMimiDelivery requires a valid current Session.";
106
+ }
107
+ if (!report)
108
+ return "Error: the Mimi host delivery channel is unavailable.";
109
+ if (!hasOnlyDeclaredToolArguments(args, ["channel", "text", "attachment_paths"])) {
110
+ return "Error: RequestMimiDelivery accepts only channel, text, and attachment_paths.";
111
+ }
112
+ const channel = typeof args.channel === "string" ? args.channel.trim().toLowerCase() : "";
113
+ if (channel !== "wechat") {
114
+ return "Error: channel must be one supported semantic channel (currently: wechat).";
115
+ }
116
+ const message = typeof args.text === "string" ? args.text.trim() : "";
117
+ if (!message || message.length > 8_000) {
118
+ return "Error: RequestMimiDelivery text must be 1 to 8000 characters.";
119
+ }
120
+ const attachmentPaths = parseAttachmentPaths(args.attachment_paths);
121
+ if (attachmentPaths === null) {
122
+ return "Error: attachment_paths must contain 1 to 4 unique absolute paths.";
123
+ }
124
+ const reportId = createReportId(ctx.sessionId, ctx.originClientMessageId, message, attachmentPaths, channel);
125
+ report({
126
+ reportId,
127
+ sessionId: ctx.sessionId,
128
+ message,
129
+ ...(attachmentPaths ? { attachmentPaths } : {}),
130
+ deliveryRequest: { channel },
131
+ createdAt: Date.now(),
132
+ });
133
+ return "Delivery request accepted for Mimi host validation. Stop here: do not search for target ids, retry, or claim that the message was delivered.";
134
+ }
135
+ function createReportId(sessionId, originClientMessageId, message, attachmentPaths, channel = "") {
136
+ return createHash("sha256")
137
+ .update([sessionId, originClientMessageId ?? "", channel, message, ...(attachmentPaths ?? [])].join("\0"))
138
+ .digest("hex")
139
+ .slice(0, 32);
140
+ }
69
141
  function parseAttachmentPaths(value) {
70
142
  if (value === undefined)
71
143
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cjhyy/code-shell-pet",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Pet (top-level personal assistant) capability for CodeShell — projection state machine, DelegateWork contract, Mimi behavior profile.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -35,7 +35,7 @@
35
35
  "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\""
36
36
  },
37
37
  "dependencies": {
38
- "@cjhyy/code-shell-core": "0.8.1"
38
+ "@cjhyy/code-shell-core": "0.8.2"
39
39
  },
40
40
  "engines": {
41
41
  "node": ">=20.10"