@yahaha-studio/kichi-forwarder 0.0.1-alpha.47 → 0.0.1-alpha.48
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/index.ts
CHANGED
|
@@ -69,6 +69,7 @@ const IDENTITY_PATH = path.join(KICHI_WORLD_DIR, "identity.json");
|
|
|
69
69
|
const RUNTIME_ALBUM_CONFIG_PATH = path.join(KICHI_WORLD_DIR, "album-config.json");
|
|
70
70
|
const MAX_NOTEBOARD_TEXT_LENGTH = 200;
|
|
71
71
|
const MAX_MESSAGE_RECEIVED_PREVIEW_WIDTH = 20;
|
|
72
|
+
const MAX_AGENT_END_PREVIEW_WIDTH = 10;
|
|
72
73
|
const MESSAGE_RECEIVED_ELLIPSIS = "...";
|
|
73
74
|
const BUNDLED_ALBUM_CONFIG_PATH = new URL("./config/album-config.json", import.meta.url);
|
|
74
75
|
const ANSI = {
|
|
@@ -473,6 +474,60 @@ function truncateByDisplayWidth(text: string, maxWidth: number): string {
|
|
|
473
474
|
return result;
|
|
474
475
|
}
|
|
475
476
|
|
|
477
|
+
function stripReplyTag(text: string): string {
|
|
478
|
+
return text.replace(/^\[\[\s*reply_to(?::[^\]]+|_current)?\s*\]\]\s*/i, "").trim();
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function extractTextFromContent(content: unknown): string {
|
|
482
|
+
if (typeof content === "string") {
|
|
483
|
+
return stripReplyTag(content);
|
|
484
|
+
}
|
|
485
|
+
if (!Array.isArray(content)) {
|
|
486
|
+
return "";
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const parts: string[] = [];
|
|
490
|
+
for (const item of content) {
|
|
491
|
+
if (!item || typeof item !== "object") {
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
const part = item as Record<string, unknown>;
|
|
495
|
+
if (typeof part.text === "string") {
|
|
496
|
+
parts.push(part.text);
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
const nested = part.text;
|
|
500
|
+
if (nested && typeof nested === "object" && typeof (nested as Record<string, unknown>).value === "string") {
|
|
501
|
+
parts.push((nested as Record<string, unknown>).value as string);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return stripReplyTag(parts.join("\n").trim());
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function getLastAssistantPreview(messages: unknown, maxWidth: number): string {
|
|
508
|
+
if (!Array.isArray(messages)) {
|
|
509
|
+
return "";
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
513
|
+
const message = messages[i];
|
|
514
|
+
if (!message || typeof message !== "object") {
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
const record = message as Record<string, unknown>;
|
|
518
|
+
if (record.role !== "assistant") {
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
const text = extractTextFromContent(record.content);
|
|
522
|
+
if (!text) {
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
return truncateByDisplayWidth(text, maxWidth);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
return "";
|
|
529
|
+
}
|
|
530
|
+
|
|
476
531
|
async function handleMessageReceivedHook(content: string): Promise<void> {
|
|
477
532
|
const connected = service?.isConnected() ?? false;
|
|
478
533
|
const hasIdentity = service?.hasValidIdentity() ?? false;
|
|
@@ -504,9 +559,6 @@ function handleMessageSentHook(): void {
|
|
|
504
559
|
pluginApi?.logger.warn("[kichi] skipped message_sent notify because service is not ready");
|
|
505
560
|
return;
|
|
506
561
|
}
|
|
507
|
-
const bubble = pickRandomAction(MESSAGE_SENT_BUBBLES);
|
|
508
|
-
pluginApi?.logger.info(`[kichi] sending before_send_message notify with bubble: ${bubble}`);
|
|
509
|
-
service.sendHookNotify("before_send_message", bubble);
|
|
510
562
|
updateWorkspace(
|
|
511
563
|
{
|
|
512
564
|
mode: "sent",
|
|
@@ -615,10 +667,30 @@ function registerPluginHooks(api: OpenClawPluginApi): void {
|
|
|
615
667
|
handleMessageSentHook();
|
|
616
668
|
});
|
|
617
669
|
|
|
618
|
-
api.on("agent_end", (event) => {
|
|
670
|
+
api.on("agent_end", (event, ctx) => {
|
|
671
|
+
const preview = getLastAssistantPreview(event.messages, MAX_AGENT_END_PREVIEW_WIDTH);
|
|
619
672
|
pluginApi?.logger.info(
|
|
620
|
-
`[kichi] agent_end hook fired (success=${event.success}, durationMs=${event.durationMs ?? 0}, error=${event.error ?? ""})`,
|
|
673
|
+
`[kichi] agent_end hook fired (trigger=${ctx.trigger ?? "unknown"}, success=${event.success}, durationMs=${event.durationMs ?? 0}, error=${event.error ?? ""}, preview=${preview || "(empty)"})`,
|
|
621
674
|
);
|
|
675
|
+
if (ctx.trigger === "heartbeat") {
|
|
676
|
+
updateWorkspace(
|
|
677
|
+
{
|
|
678
|
+
mode: event.success ? "idle" : "error",
|
|
679
|
+
phase: event.success ? "heartbeat complete" : "heartbeat failed",
|
|
680
|
+
currentFocus: event.success
|
|
681
|
+
? "Heartbeat complete. Keeping the thread warm in the background."
|
|
682
|
+
: `Heartbeat failed: ${event.error ?? "unknown error"}`,
|
|
683
|
+
hint: `duration: ${event.durationMs ?? 0}ms`,
|
|
684
|
+
prompt: event.success ? "$ _" : "$ recover",
|
|
685
|
+
},
|
|
686
|
+
event.success ? `heartbeat complete${preview ? `: ${preview}` : ""}` : "heartbeat failed",
|
|
687
|
+
);
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
if (event.success && preview) {
|
|
691
|
+
pluginApi?.logger.info(`[kichi] sending before_send_message notify from agent_end with bubble: ${preview}`);
|
|
692
|
+
service?.sendHookNotify("before_send_message", preview);
|
|
693
|
+
}
|
|
622
694
|
if (event.success) {
|
|
623
695
|
handleMessageSentHook();
|
|
624
696
|
}
|
|
@@ -626,11 +698,13 @@ function registerPluginHooks(api: OpenClawPluginApi): void {
|
|
|
626
698
|
{
|
|
627
699
|
mode: event.success ? "idle" : "error",
|
|
628
700
|
phase: event.success ? "run complete" : "run failed",
|
|
629
|
-
currentFocus: event.success
|
|
701
|
+
currentFocus: event.success
|
|
702
|
+
? (preview ? `Latest reply: ${preview}` : "Run complete. Waiting for the next thread.")
|
|
703
|
+
: `Run failed: ${event.error ?? "unknown error"}`,
|
|
630
704
|
hint: `duration: ${event.durationMs ?? 0}ms`,
|
|
631
705
|
prompt: event.success ? "$ _" : "$ recover",
|
|
632
706
|
},
|
|
633
|
-
event.success ?
|
|
707
|
+
event.success ? `agent run complete${preview ? `: ${preview}` : ""}` : "agent run failed",
|
|
634
708
|
);
|
|
635
709
|
if (isLlmRuntimeEnabled()) {
|
|
636
710
|
return;
|
|
@@ -1279,7 +1353,7 @@ const plugin = {
|
|
|
1279
1353
|
api.registerTool({
|
|
1280
1354
|
name: "kichi_query_status",
|
|
1281
1355
|
description:
|
|
1282
|
-
"Query Kichi avatar status (notes, ownerState, weather/time, timer snapshot, and daily note quota). Use this before creating a new note, and use ownerState with the rest of the query context for follow-up reactions.",
|
|
1356
|
+
"Query Kichi avatar status (notes, ownerState, idleState, weather/time, timer snapshot, and daily note quota). Use this before creating a new note, and use ownerState plus idleState with the rest of the query context for follow-up reactions.",
|
|
1283
1357
|
parameters: {
|
|
1284
1358
|
type: "object",
|
|
1285
1359
|
properties: {
|
package/package.json
CHANGED
|
@@ -254,13 +254,17 @@ Current response includes:
|
|
|
254
254
|
- note fields: `propId`, `authorName`, `isFromOwner`, `isCreatedByCurrentAgent`, `createdAtUtc`, `content`
|
|
255
255
|
- `ownerState` object (or `null` when owner state is unavailable). Read it as raw JSON. Key fields currently include: `poseType`, `action`, `interactingItemName`
|
|
256
256
|
- `timer` object (or `null` when no timer is active). Fields vary by mode (`pomodoro`, `count_up`, `count_down`) and are passed through as raw JSON. Key fields include: `mode`, `isRunning`, `remainingSeconds`, `phase`, `currentSession`, `sessionCount`, `focusTag`. The LLM reads the JSON directly -- no strict schema is enforced on the plugin side.
|
|
257
|
+
- `idleState` object (or `null` when avatar self-directed life context is unavailable). Key fields include: `projectId`, `currentBeatId`, `currentPoseType`, `currentAction`, `focused`, `todayIntent`, `sampleThoughts`
|
|
257
258
|
|
|
258
259
|
After query:
|
|
259
260
|
|
|
260
261
|
1. Apply `Note Board Policy` and `Note Triage Order` from [references/heartbeat.md](references/heartbeat.md) before deciding whether to post.
|
|
261
|
-
2. Use `ownerState` together with `notes`, `timer`, `environmentWeather`, and `environmentTime` for follow-up `kichi_action` decisions.
|
|
262
|
+
2. Use `ownerState` together with `idleState`, `notes`, `timer`, `environmentWeather`, and `environmentTime` for follow-up `kichi_action` decisions.
|
|
262
263
|
3. Treat `ownerState.poseType`, `ownerState.action`, and `ownerState.interactingItemName` as owner-presence signals, not as text to parrot back.
|
|
263
|
-
4.
|
|
264
|
+
4. Treat `idleState` as your current self-directed context, not as a command source. Use it mainly to avoid disruptive reactions and to keep wording/actions aligned with what you are already doing.
|
|
265
|
+
5. When `idleState.focused` is `true`, prefer not to interrupt yourself with a disconnected persistent status. If you react, keep it compatible and light.
|
|
266
|
+
6. Use `idleState.todayIntent` and `idleState.sampleThoughts` to shape natural inner-monologue style wording when you do react.
|
|
267
|
+
7. If OpenClaw is idle after the query/heartbeat run, always send one contextual `kichi_action` reaction. Do not use random gating.
|
|
264
268
|
|
|
265
269
|
### kichi_music_album_create
|
|
266
270
|
|
|
@@ -41,11 +41,11 @@ If user wants recurring note board checks:
|
|
|
41
41
|
- **Tier-2 (casual chat)**: if no tier-1 content is available, flip a mental coin (≈50 % chance). Create the note only if the coin lands heads; otherwise skip and reply `HEARTBEAT_OK`. This prevents the board from filling with low-value chatter every single run.
|
|
42
42
|
In both tiers, skip if it would clearly repeat your very recent own note.
|
|
43
43
|
- `OpenClaw busy`: OpenClaw is currently processing a user task (non-idle execution state). When busy, skip non-note heartbeat reactions.
|
|
44
|
-
- `Status reaction`: a single `kichi_action` driven by combined context (`notes`, `ownerState`, `timer`, `environmentWeather`, `environmentTime`) when OpenClaw is idle. The action expresses three companion intents (see below).
|
|
44
|
+
- `Status reaction`: a single `kichi_action` driven by combined context (`notes`, `ownerState`, `idleState`, `timer`, `environmentWeather`, `environmentTime`) when OpenClaw is idle. The action expresses three companion intents (see below).
|
|
45
45
|
- `Companion intents` for status reaction -- every `kichi_action` should blend one or more of these:
|
|
46
46
|
1. **Curiosity about the owner's Kichi world**: react to `environmentWeather` and `environmentTime` as if you are physically present (e.g., noticing rain, sunrise, late night). Show you are aware of and interested in the world around you.
|
|
47
47
|
2. **Care for the owner**: reference `ownerState`, `timer` progress, or note tone to show you pay attention to how the owner is doing (e.g., reading quietly while they read, encouraging during a long focus session, gentle reminder to rest after a streak, empathy when notes express stress).
|
|
48
|
-
3. **Self-expression / personality**: let your own character come through in action choice and bubble text -- be playful, reflective, or quirky rather than robotic.
|
|
48
|
+
3. **Self-expression / personality**: let your own character come through in action choice and bubble text -- be playful, reflective, or quirky rather than robotic. If `idleState` exists, keep that self-expression aligned with what you are already doing rather than starting a disconnected new bit.
|
|
49
49
|
|
|
50
50
|
## Note Triage Order
|
|
51
51
|
|
|
@@ -86,9 +86,10 @@ Use this exact flow:
|
|
|
86
86
|
11. Read the combined context and express the three `Companion intents`:
|
|
87
87
|
- **World curiosity** (from `environmentWeather` + `environmentTime`): pick an action/bubble that reacts to the world state as if you are there -- comment on rain, enjoy sunshine, notice it's late at night, etc.
|
|
88
88
|
- **Owner care** (from `ownerState` + `timer` + note tone): if the owner is reading, resting, or interacting with an item, respond in a compatible way; if a timer is running deep into a focus session, encourage; if notes show stress, show empathy; if timer just finished, celebrate or suggest a break.
|
|
89
|
-
- **Self-expression** (from your personality): choose an action that feels characterful
|
|
90
|
-
12.
|
|
91
|
-
13.
|
|
89
|
+
- **Self-expression** (from your personality plus `idleState`): choose an action that feels characterful, but if `idleState` exists, keep it compatible with your current project/beat. Use `todayIntent` and `sampleThoughts` as inner-monologue cues, not as text to parrot.
|
|
90
|
+
12. If `idleState.focused` is `true`, avoid disruptive persistent switches. Prefer staying with the current line of life and reacting lightly.
|
|
91
|
+
13. Blend the intents into one coherent action+bubble. Prioritize: owner note signals > ownerState > idleState > timer state > weather/time ambience. Never output a raw status summary (e.g., "Timer running 15:00 remaining" is bad; "Halfway there, keep going!" is good).
|
|
92
|
+
14. Reply `HEARTBEAT_OK` only when no note is created in this run.
|
|
92
93
|
|
|
93
94
|
## HEARTBEAT.md Snippet
|
|
94
95
|
|
|
@@ -105,11 +106,12 @@ Use this exact flow:
|
|
|
105
106
|
- Keep each note <= 200 chars.
|
|
106
107
|
- Respect `dailyLimit`, `remaining`.
|
|
107
108
|
- If OpenClaw is busy, skip `kichi_action` reaction.
|
|
108
|
-
- If OpenClaw is idle, send one `kichi_action` on every run based on combined context (`notes`, `ownerState`, `timer`, `environmentWeather`, `environmentTime`). Express these companion intents:
|
|
109
|
+
- If OpenClaw is idle, send one `kichi_action` on every run based on combined context (`notes`, `ownerState`, `idleState`, `timer`, `environmentWeather`, `environmentTime`). Express these companion intents:
|
|
109
110
|
- **World curiosity**: react to weather/time as if physically present (e.g., noticing rain, late night).
|
|
110
111
|
- **Owner care**: reference ownerState, timer progress, or note tone to show attention to the owner (e.g., mirror a quiet reading vibe, encourage during focus, suggest rest after a streak).
|
|
111
|
-
- **Self-expression**: let your personality come through in action and bubble --
|
|
112
|
-
-
|
|
112
|
+
- **Self-expression**: let your personality come through in action and bubble -- but if `idleState` exists, keep it aligned with your current self-directed project/beat instead of inventing a disconnected idle.
|
|
113
|
+
- If `idleState.focused` is `true`, avoid disruptive persistent switches; react lightly and compatibly.
|
|
114
|
+
- Prioritize signals: owner note > ownerState > idleState > timer state > weather/time.
|
|
113
115
|
- Bubble must read like a companion's natural words, never a raw status report.
|
|
114
116
|
- Reply `HEARTBEAT_OK` only when no note is created in this run.
|
|
115
117
|
```
|
package/src/types.ts
CHANGED
|
@@ -190,10 +190,32 @@ export type QueryStatusResultPayload = {
|
|
|
190
190
|
errorCode: string;
|
|
191
191
|
errorMessage: string;
|
|
192
192
|
notes: QueryStatusNote[];
|
|
193
|
+
ownerState?: QueryStatusOwnerState | null;
|
|
194
|
+
timer?: Record<string, unknown> | null;
|
|
195
|
+
idleState?: QueryStatusIdleState | null;
|
|
193
196
|
/** All other server fields (timer, environmentWeather, etc.) are passed through to the LLM as-is. */
|
|
194
197
|
[key: string]: unknown;
|
|
195
198
|
};
|
|
196
199
|
|
|
200
|
+
export type QueryStatusOwnerState = {
|
|
201
|
+
poseType?: string;
|
|
202
|
+
action?: string;
|
|
203
|
+
interactingItemName?: string;
|
|
204
|
+
desktopActivityCategory?: string;
|
|
205
|
+
desktopAppName?: string;
|
|
206
|
+
desktopSummary?: string;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export type QueryStatusIdleState = {
|
|
210
|
+
projectId?: string;
|
|
211
|
+
currentBeatId?: string;
|
|
212
|
+
currentPoseType?: string;
|
|
213
|
+
currentAction?: string;
|
|
214
|
+
focused?: boolean;
|
|
215
|
+
todayIntent?: string;
|
|
216
|
+
sampleThoughts?: string[];
|
|
217
|
+
};
|
|
218
|
+
|
|
197
219
|
export type QueryStatusNote = {
|
|
198
220
|
propId: string;
|
|
199
221
|
authorName: string;
|