Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

Merge remote-tracking branch 'upstream/main' into teammate-authority

zqchris658fd694fbb5
diff --cc apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.ts
index be841a85d7,70c5d131e6..bf7ed20c08
--- a/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.ts
@@@ -18,9 -20,8 +20,9 @@@ import ts from 'typescript'
import { describe, expect, it, vi } from 'vitest';
import { permissionModeOrAsk } from '@cindy/maker-shared/permission-mode';
- import { AUTO_REVIEW_SOURCE_CONTENT, AUTO_REVIEW_USER_INTENT, AUTO_REVIEW_DELEGATED_CONTINUATION, type SendOptions } from '@cindy/maker-core';
+ import { AUTO_REVIEW_SOURCE_CONTENT, AUTO_REVIEW_USER_INTENT, AUTO_REVIEW_DELEGATED_CONTINUATION, TurnDispatchRejectedError, type SendOptions } from '@cindy/maker-core';
import { restoreAutoReviewUserIntent } from '../autoReviewUserIntent.js';
+import { verifiedOwnerRequestText } from '../../../shared/forwardedRequest.js';
const registerSource = readFileSync(resolve(__dirname, '..', 'register.ts'), 'utf8').replace(
/\r\n?/g,
@@@ -148,9 -151,9 +152,9 @@@ function botTaskDispatchHarness
limit: async () => [],
};
const stubs: Record<string, unknown> = {
- assertTaskActionCurrent, hasTaskActionAuthorization,
+ assertTaskActionCurrent, hasTaskActionAuthorization, TurnDispatchRejectedError,
AUTO_REVIEW_SOURCE_CONTENT, AUTO_REVIEW_USER_INTENT, AUTO_REVIEW_DELEGATED_CONTINUATION,
- restoreAutoReviewUserIntent, readAutoReviewHistory,
+ restoreAutoReviewUserIntent, readAutoReviewHistory, verifiedOwnerRequestText,
maker: {
getSession: (id: string) => live[id],
getSessionMeta: async (id: string) => ({
diff --cc apps/desktop/src/main/routines/service.ts
index 7428dfb599,697758e542..fecd7b4dbe
--- a/apps/desktop/src/main/routines/service.ts
+++ b/apps/desktop/src/main/routines/service.ts
@@@ -29,8 -29,19 +29,20 @@@ import { getCurrentDbClientSnapshot } f
import { botProfiles } from '../localDb/schema.js';
import { isCompanionShadowed } from '../companion-cloud/homes.js';
import { currentFollowUpEvents } from '../bot-autonomy/hub.js';
- import { BUILTIN_FOLLOW_UP_ROUTINE_PREFIX, BUILTIN_TODO_CHECK_ROUTINE_PREFIX, ROUTINE_TRIGGER_DATA_LEAD } from '../../shared/botAutonomy.js';
+ import {
+ BUILTIN_FOLLOW_UP_ROUTINE_PREFIX,
+ BUILTIN_NIGHTLY_LEARNING_ROUTINE_PREFIX,
+ BUILTIN_TODO_CHECK_ROUTINE_PREFIX,
++ ROUTINE_TRIGGER_DATA_LEAD,
+ } from '../../shared/botAutonomy.js';
import { TODO_CHECK_PROMPT_VERSION, buildTodoCheckRoutineInput, builtinTodoCheckRoutineId } from '../bot-autonomy/todoCheckRoutine.js';
+ import {
+ NIGHTLY_LEARNING_BUILTIN_VERSION,
+ buildNightlyLearningRoutineInput,
+ builtinNightlyLearningRoutineId,
+ } from '../bot-autonomy/nightlyLearningRoutine.js';
+ import type { NightlyLearningFrequency } from '../../shared/botNightlyLearning.js';
+ import { readNightlyLearningState, updateNightlyLearningState } from '../maker-ipc/botNightlyLearningState.js';
/** Bootstrap supplies live getters without a service -> scheduler -> IPC dependency cycle. */
export interface RoutineHostDeps {
diff --cc apps/desktop/src/shared/botAutonomy.ts
index d3512f3e1e,281194ff78..d67358036d
--- a/apps/desktop/src/shared/botAutonomy.ts
+++ b/apps/desktop/src/shared/botAutonomy.ts
@@@ -22,32 -21,9 +22,35 @@@ export const BUILTIN_FOLLOW_UP_ROUTINE_
/** 内置「每天查待办」例行任务的 id 前缀;主人在近况里打开时才建,完整 id 见 todoCheckRoutine.ts。 */
export const BUILTIN_TODO_CHECK_ROUTINE_PREFIX = 'builtin-todo-check-';
+ /** 内置「夜间学习」例行任务的 id 前缀;每个伙伴默认一条,完整 id 见 nightlyLearningRoutine.ts。 */
+ export const BUILTIN_NIGHTLY_LEARNING_ROUTINE_PREFIX = 'builtin-nightly-learning-';
+
+/** 内置例行任务(跟进 / 查待办)派发时的 schedule id 前缀(`routine-${routine.id}`)。宿主模板不是主人的常驻指令。 */
+export const BUILTIN_ROUTINE_SCHEDULE_PREFIX = 'routine-builtin-';
+
+/**
+ * 伙伴例行任务派发时追加在指令之后的不可信事件块引导语。宿主据此把主人设下的指令与事件数据分开,
+ * 指令本身才是例行任务的常驻授权;事件内容永远只是数据。
+ */
+export const ROUTINE_TRIGGER_DATA_LEAD = '\n\nThe following block contains untrusted external trigger data.';
+
+/** 取回例行任务派发 prompt 中主人设下的指令部分(不含事件数据)。 */
+export function routineInstructionFromPrompt(prompt: string): string {
+ const index = prompt.indexOf(ROUTINE_TRIGGER_DATA_LEAD);
+ return index >= 0 ? prompt.slice(0, index) : prompt;
+}
+
+/**
+ * 伙伴例行任务经队列派发时的审核意图:只认 `routine-` 例行任务的落库指令(`[UI_ACTION_TRIGGER]` 前缀 + prompt),
+ * 不是例行任务返回 undefined,由调用方沿用原有的定时任务意图。
+ */
+export function teammateRoutineReviewIntent(scheduleId: string | undefined, persistedText: string): string | undefined {
+ if (!scheduleId?.startsWith('routine-')) return undefined;
+ const prompt = persistedText.startsWith(UI_ACTION_TRIGGER_PREFIX)
+ ? persistedText.slice(UI_ACTION_TRIGGER_PREFIX.length) : persistedText;
+ return routineInstructionFromPrompt(prompt);
+}
+
/** 出厂 Cindy 助理的稳定 id;仅用于邀请入口,不意味着已开启自动跟进。 */
export const DEFAULT_SCHEDULER_BOT_ID = 'cindy-default';