mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-21 08:22:20 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Agents ask humans for decisions through interaction blocks: plan confirmations, structured questions, suggested tasks, and checkbox prompts > - Each agent writes these decision prompts in its own style, so operators can get long or unclear text at the exact moment they must decide > - There is no instance-level control that makes agents use a controlled language for these decision points only > - This pull request adds an experimental setting that tells agents to write all user-interaction content in ASD-STE100 Simplified Technical English, with the context the user needs and the effect of each choice > - The benefit is faster, clearer human decisions, with agent thinking and normal responses unchanged ## Linked Issues or Issue Description Refs #10410 (optional `/simplified-english` skill in the skills catalog; this PR adds the instance-level toggle for interactions). **Problem or motivation** Agent-posted user interactions (plan confirmations, structured questions, suggested-task proposals, checkbox prompts) are written in each agent's default style. Operators who want fast, unambiguous decisions have no way to ask agents to use a controlled language for exactly those decision points. **Proposed solution** Add an experimental instance setting, `enableSimplifiedEnglishInteractions` ("Simplified English Interactions"). When it is on, the server sets `simplifiedEnglishInteractions: true` in the heartbeat wake payload. The shared wake-prompt renderer, used by every adapter, then emits a directive: write all user-interaction content in ASD-STE100 Simplified Technical English, state what information the user needs to decide, and state what happens for each choice. The directive applies to interaction content only. Thinking, comments, documents, and other responses keep their usual style. **Alternatives considered** Per-agent instructions work today, but someone must maintain them on every agent. An instance-level toggle applies uniformly and turns off in one place. Server-side rewriting of interaction payloads was rejected: post-hoc translation is lossy and cannot add the decision context that only the agent has. **Roadmap alignment** Extends the experimental settings surface with another opt-in agent-behavior refinement, consistent with existing prompt-side flags. ## What Changed - Added `enableSimplifiedEnglishInteractions` to the experimental instance-settings zod schema, mirror type, and feature catalog (default off, tier preference) in `packages/shared`. - Server `instance-settings.ts` normalizes the flag on both read branches; `heartbeat.ts` reads it once and passes `simplifiedEnglishInteractions` into `buildPaperclipWakePayload`. - Shared adapter renderer (`packages/adapter-utils/src/server-utils.ts`): added the field to `PaperclipWakePayload`, normalization, and an `- interaction language (experimental): ...` directive emitted in both fresh and resume prompt lanes, so one injection point covers all adapters. - UI: new experimental settings card "Simplified English Interactions" in `ui/src/pages/InstanceExperimentalSettings.tsx`, in alphabetical card order; fixtures updated. - Tests: renderer coverage for flag on/off in both lanes, plus schema/catalog/UI fixture updates. ## Verification - From the repo root: `node_modules/.bin/vitest run packages/adapter-utils` (88/88), `packages/shared` validators (25/25), server instance-settings + heartbeat suites (47/47 and 70/70 consumer tests), `ui` settings tests (32/32). - Typecheck is clean in all four touched packages. - Manual check: turn the flag on in Settings → Experimental, wake an agent, and confirm the wake prompt contains the interaction-language directive; turn it off and confirm the directive is absent. ## Risks - Low risk: the flag defaults to off, and the only behavior change is one extra directive line in the wake prompt when an operator turns it on. - The directive is advisory to the agent; models can still deviate from STE. No data or API shape changes; no migration. ## Model Used - Claude Fable 5 (Anthropic, model ID `claude-fable-5`), extended thinking, agentic tool use via Claude Agent SDK. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge Co-authored-by: Paperclip <noreply@paperclip.ing>
378 lines
14 KiB
TypeScript
378 lines
14 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import type { InstanceExperimentalSettings } from "@paperclipai/shared";
|
|
import {
|
|
applyExperimentalSettingsPatch,
|
|
normalizeExperimentalSettings,
|
|
resolveWorktreeRunExecutionActivationState,
|
|
} from "../services/instance-settings.js";
|
|
|
|
describe("instance settings service", () => {
|
|
it("ignores retired experimental flags without resetting current settings", () => {
|
|
expect(normalizeExperimentalSettings({
|
|
enableEnvironments: true,
|
|
enableIsolatedWorkspaces: true,
|
|
enableIssuePlanDecompositions: true,
|
|
enableExperimentalFileViewer: true,
|
|
enableTaskWatchdogs: true,
|
|
enableBuiltInAgents: true,
|
|
enableGoalsSidebarLink: true,
|
|
enableServerInfoDebugView: true,
|
|
autoRestartDevServerWhenIdle: true,
|
|
enableIssueGraphLivenessAutoRecovery: true,
|
|
enableWorkspaceBranchReconcileForward: true,
|
|
enableWorkspaceDirtyQuarantineRepair: false,
|
|
issueGraphLivenessAutoRecoveryLookbackHours: 48,
|
|
enableNewestFirstIssueThread: true,
|
|
})).toEqual({
|
|
enableEnvironments: true,
|
|
enableIsolatedWorkspaces: true,
|
|
enableStreamlinedLeftNavigation: true,
|
|
enableApps: false,
|
|
enableConferenceRoomChat: false,
|
|
enableTaskChatRedesign: false,
|
|
enableExternalObjects: false,
|
|
enableSmokeLab: false,
|
|
enablePipelines: false,
|
|
enableCases: false,
|
|
enableIssuePlanDecompositions: true,
|
|
enableExperimentalFileViewer: true,
|
|
enableTaskWatchdogs: true,
|
|
enableBuiltInAgents: true,
|
|
enableBetaSkills: false,
|
|
enableSummaries: false,
|
|
enableStatusCards: false,
|
|
enableDecisions: false,
|
|
enableGoalsSidebarLink: true,
|
|
enableServerInfoDebugView: true,
|
|
enableSimplifiedEnglishInteractions: false,
|
|
autoRestartDevServerWhenIdle: true,
|
|
enableIssueGraphLivenessAutoRecovery: true,
|
|
enableWorkspaceBranchReconcileForward: true,
|
|
enableWorkspaceDirtyQuarantineRepair: false,
|
|
enableOwnerInstanceAdmin: false,
|
|
enableWorktreeRunExecution: false,
|
|
worktreeRunExecutionActivatedAt: null,
|
|
worktreeRunExecutionActivationInstanceId: null,
|
|
issueGraphLivenessAutoRecoveryLookbackHours: 48,
|
|
});
|
|
});
|
|
|
|
it("defaults enableApps to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableApps).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableApps).toBe(false);
|
|
expect(normalizeExperimentalSettings({ enablePipelines: true }).enableApps).toBe(false);
|
|
});
|
|
|
|
it("defaults enableConferenceRoomChat to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableConferenceRoomChat).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableConferenceRoomChat).toBe(false);
|
|
// Rows persisted before the flag existed (PAP-137) must normalize to off.
|
|
expect(
|
|
normalizeExperimentalSettings({ enableStreamlinedLeftNavigation: true }).enableConferenceRoomChat,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("defaults enableSimplifiedEnglishInteractions to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableSimplifiedEnglishInteractions).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableSimplifiedEnglishInteractions).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableStreamlinedLeftNavigation: true })
|
|
.enableSimplifiedEnglishInteractions,
|
|
).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableSimplifiedEnglishInteractions: true })
|
|
.enableSimplifiedEnglishInteractions,
|
|
).toBe(true);
|
|
});
|
|
|
|
it("defaults enableTaskWatchdogs to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableTaskWatchdogs).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableTaskWatchdogs).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableExperimentalFileViewer: true }).enableTaskWatchdogs,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("defaults enableSmokeLab to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableSmokeLab).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableSmokeLab).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableExternalObjects: true }).enableSmokeLab,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("defaults enableServerInfoDebugView to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableServerInfoDebugView).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableServerInfoDebugView).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ autoRestartDevServerWhenIdle: true }).enableServerInfoDebugView,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("defaults enableGoalsSidebarLink to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableGoalsSidebarLink).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableGoalsSidebarLink).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableStreamlinedLeftNavigation: true }).enableGoalsSidebarLink,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("defaults enableDecisions to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableDecisions).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableDecisions).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableStreamlinedLeftNavigation: true }).enableDecisions,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("defaults workspace branch repair settings to true for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableWorkspaceBranchReconcileForward).toBe(true);
|
|
expect(normalizeExperimentalSettings({}).enableWorkspaceBranchReconcileForward).toBe(true);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableIssueGraphLivenessAutoRecovery: true })
|
|
.enableWorkspaceBranchReconcileForward,
|
|
).toBe(true);
|
|
expect(normalizeExperimentalSettings(undefined).enableWorkspaceDirtyQuarantineRepair).toBe(true);
|
|
expect(normalizeExperimentalSettings({}).enableWorkspaceDirtyQuarantineRepair).toBe(true);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableWorkspaceBranchReconcileForward: false })
|
|
.enableWorkspaceDirtyQuarantineRepair,
|
|
).toBe(true);
|
|
});
|
|
|
|
it("round-trips an enableConferenceRoomChat patch through the update merge", () => {
|
|
// updateExperimental merges `{ ...normalize(current), ...patch }` and
|
|
// re-normalizes; emulate that to prove the flag survives the roundtrip
|
|
// without disturbing other settings.
|
|
const current = normalizeExperimentalSettings({});
|
|
const enabled = normalizeExperimentalSettings({ ...current, enableConferenceRoomChat: true });
|
|
expect(enabled.enableConferenceRoomChat).toBe(true);
|
|
expect(enabled.enableStreamlinedLeftNavigation).toBe(true);
|
|
|
|
const disabled = normalizeExperimentalSettings({ ...enabled, enableConferenceRoomChat: false });
|
|
expect(disabled).toEqual(current);
|
|
});
|
|
|
|
it("rejects non-boolean enableConferenceRoomChat values back to the default", () => {
|
|
expect(
|
|
normalizeExperimentalSettings({ enableConferenceRoomChat: "yes" }).enableConferenceRoomChat,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("defaults enableBuiltInAgents to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableBuiltInAgents).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableBuiltInAgents).toBe(false);
|
|
expect(normalizeExperimentalSettings({ enableExternalObjects: true }).enableBuiltInAgents).toBe(false);
|
|
});
|
|
|
|
it("preserves enableBetaSkills and defaults it off for legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableBetaSkills).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableBetaSkills).toBe(false);
|
|
expect(normalizeExperimentalSettings({ enableBetaSkills: true }).enableBetaSkills).toBe(true);
|
|
});
|
|
|
|
it("sets worktree run execution activation fields on a false to true transition", () => {
|
|
const activatedAt = new Date("2026-07-10T12:00:00.000Z");
|
|
|
|
const next = applyExperimentalSettingsPatch(
|
|
{ enableWorktreeRunExecution: false },
|
|
{ enableWorktreeRunExecution: true },
|
|
{
|
|
now: () => activatedAt,
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
},
|
|
);
|
|
|
|
expect(next.enableWorktreeRunExecution).toBe(true);
|
|
expect(next.worktreeRunExecutionActivatedAt).toBe("2026-07-10T12:00:00.000Z");
|
|
expect(next.worktreeRunExecutionActivationInstanceId).toBe("worktree-instance");
|
|
});
|
|
|
|
it("clears worktree run execution activation fields on a true to false transition", () => {
|
|
const next = applyExperimentalSettingsPatch(
|
|
{
|
|
enableWorktreeRunExecution: true,
|
|
worktreeRunExecutionActivatedAt: "2026-07-10T12:00:00.000Z",
|
|
worktreeRunExecutionActivationInstanceId: "worktree-instance",
|
|
},
|
|
{ enableWorktreeRunExecution: false },
|
|
{
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
},
|
|
);
|
|
|
|
expect(next.enableWorktreeRunExecution).toBe(false);
|
|
expect(next.worktreeRunExecutionActivatedAt).toBeNull();
|
|
expect(next.worktreeRunExecutionActivationInstanceId).toBeNull();
|
|
});
|
|
|
|
it("refreshes the activation cutoff when worktree run execution is re-toggled", () => {
|
|
const firstActivation = applyExperimentalSettingsPatch(
|
|
{ enableWorktreeRunExecution: false },
|
|
{ enableWorktreeRunExecution: true },
|
|
{
|
|
now: () => new Date("2026-07-10T12:00:00.000Z"),
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
},
|
|
);
|
|
const disabled = applyExperimentalSettingsPatch(
|
|
firstActivation,
|
|
{ enableWorktreeRunExecution: false },
|
|
{
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
},
|
|
);
|
|
|
|
const secondActivation = applyExperimentalSettingsPatch(
|
|
disabled,
|
|
{ enableWorktreeRunExecution: true },
|
|
{
|
|
now: () => new Date("2026-07-10T12:05:00.000Z"),
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
},
|
|
);
|
|
|
|
expect(secondActivation.worktreeRunExecutionActivatedAt).toBe("2026-07-10T12:05:00.000Z");
|
|
expect(secondActivation.worktreeRunExecutionActivatedAt).not.toBe(
|
|
firstActivation.worktreeRunExecutionActivatedAt,
|
|
);
|
|
});
|
|
|
|
it("strips client-supplied activation fields before applying experimental patches", () => {
|
|
const next = applyExperimentalSettingsPatch(
|
|
{ enableWorktreeRunExecution: false },
|
|
{
|
|
enableWorktreeRunExecution: false,
|
|
worktreeRunExecutionActivatedAt: "2026-07-10T12:00:00.000Z",
|
|
worktreeRunExecutionActivationInstanceId: "copied-instance",
|
|
},
|
|
{
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
},
|
|
);
|
|
|
|
expect(next.worktreeRunExecutionActivatedAt).toBeNull();
|
|
expect(next.worktreeRunExecutionActivationInstanceId).toBeNull();
|
|
});
|
|
|
|
it("resolves worktree run execution as armed only when the cutoff matches the current instance", async () => {
|
|
const experimental = normalizeExperimentalSettings({
|
|
enableWorktreeRunExecution: true,
|
|
worktreeRunExecutionActivatedAt: "2026-07-10T12:00:00.000Z",
|
|
worktreeRunExecutionActivationInstanceId: "worktree-instance",
|
|
});
|
|
|
|
await expect(
|
|
resolveWorktreeRunExecutionActivationState({
|
|
getExperimental: async () => experimental,
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
}),
|
|
).resolves.toEqual({
|
|
armed: true,
|
|
cutoff: "2026-07-10T12:00:00.000Z",
|
|
activationInstanceId: "worktree-instance",
|
|
reason: null,
|
|
});
|
|
});
|
|
|
|
it("fails closed when worktree run execution is missing a cutoff", async () => {
|
|
const experimental = normalizeExperimentalSettings({
|
|
enableWorktreeRunExecution: true,
|
|
worktreeRunExecutionActivationInstanceId: "worktree-instance",
|
|
});
|
|
|
|
await expect(
|
|
resolveWorktreeRunExecutionActivationState({
|
|
getExperimental: async () => experimental,
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
}),
|
|
).resolves.toMatchObject({
|
|
armed: false,
|
|
cutoff: null,
|
|
reason: "missing_cutoff",
|
|
});
|
|
});
|
|
|
|
it("fails closed when worktree run execution was activated by another instance", async () => {
|
|
const experimental = normalizeExperimentalSettings({
|
|
enableWorktreeRunExecution: true,
|
|
worktreeRunExecutionActivatedAt: "2026-07-10T12:00:00.000Z",
|
|
worktreeRunExecutionActivationInstanceId: "source-instance",
|
|
});
|
|
|
|
await expect(
|
|
resolveWorktreeRunExecutionActivationState({
|
|
getExperimental: async () => experimental,
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "target-instance",
|
|
},
|
|
}),
|
|
).resolves.toMatchObject({
|
|
armed: false,
|
|
cutoff: null,
|
|
activationInstanceId: "source-instance",
|
|
reason: "instance_id_mismatch",
|
|
});
|
|
});
|
|
|
|
it("fails closed on settings read errors and avoids reads outside worktree runtimes", async () => {
|
|
await expect(
|
|
resolveWorktreeRunExecutionActivationState({
|
|
getExperimental: async () => {
|
|
throw new Error("settings unavailable");
|
|
},
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
}),
|
|
).resolves.toMatchObject({
|
|
armed: false,
|
|
cutoff: null,
|
|
reason: "settings_read_error",
|
|
});
|
|
|
|
const getExperimental = vi.fn<() => Promise<InstanceExperimentalSettings>>();
|
|
await expect(
|
|
resolveWorktreeRunExecutionActivationState({
|
|
getExperimental,
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "false",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
}),
|
|
).resolves.toMatchObject({
|
|
armed: false,
|
|
cutoff: null,
|
|
reason: "not_worktree_runtime",
|
|
});
|
|
expect(getExperimental).not.toHaveBeenCalled();
|
|
});
|
|
|
|
});
|