Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat: gate CoS task templates behind feature flag

Adam Eivyb391b3298c47
diff --git a/client/src/components/cos/TaskAddForm.jsx b/client/src/components/cos/TaskAddForm.jsx
index 7a0d54be12..d3ce399642 100644
--- a/client/src/components/cos/TaskAddForm.jsx
+++ b/client/src/components/cos/TaskAddForm.jsx
@@ -18,9 +18,10 @@ import ReviewerPicker from './ReviewerPicker';
import InstancePicker from './InstancePicker';
import useReviewerModelOptions from '../../hooks/useReviewerModelOptions';
import useAssignableInstances from '../../hooks/useAssignableInstances';
+import { useInstanceFeatures } from '../../hooks/useInstanceFeatures';
import { reviewerModelsFromDefaults, reviewerEffortsFromDefaults } from '../../lib/reviewerModels';
import { PORTOS_APP_ID } from '../../lib/appIdentity';
-import { safeReadJsonStorage, safeReadStorage, safeRemoveStorage, safeWriteJsonStorage } from '../../lib/safeStorage';
+import { safeReadJsonStorage, safeReadStorage, safeRemoveStorage, safeWriteJsonStorage, safeWriteStorage } from '../../lib/safeStorage';
const ORCHESTRATION_EFFORTS = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max', 'ultra'];
const ORCHESTRATION_ROLES_META = [
@@ -30,6 +31,7 @@ const ORCHESTRATION_ROLES_META = [
];
const TASK_DESCRIPTION_DRAFT_KEY = 'portos-cos-task-description-draft';
+const QUICK_TEMPLATES_EXPANDED_KEY = 'portos-cos-quick-templates-expanded';
const INVALID_DRAFT = Symbol('invalid task description draft');
// ReviewerPicker's onChange patch keys, mapped to their addCosTask payload
@@ -78,6 +80,13 @@ const readTaskDescriptionDraft = (defaultApp) => {
};
};
+const readQuickTemplatesExpanded = (fallback) => {
+ const stored = safeReadStorage(QUICK_TEMPLATES_EXPANDED_KEY);
+ if (stored === 'true') return true;
+ if (stored === 'false') return false;
+ return fallback;
+};
+
export default function TaskAddForm({ providers, providersLoaded = true, apps, onTaskAdded, compact = false, defaultExpanded = false, defaultApp = '', queueFirst = false }) {
const [initialDraft] = useState(() => readTaskDescriptionDraft(defaultApp));
const [newTask, setNewTask] = useState(() => {
@@ -128,11 +137,13 @@ export default function TaskAddForm({ providers, providersLoaded = true, apps, o
// opportunistic default. Hidden entirely on a single-instance install.
const [targetInstanceId, setTargetInstanceId] = useState('');
const { instances: assignableInstances, isFederated } = useAssignableInstances();
+ const { isFeatureEnabled } = useInstanceFeatures();
+ const quickTemplatesEnabled = isFeatureEnabled('cos-task-templates');
const [createJiraTicket, setCreateJiraTicket] = useState(false);
const [screenshots, setScreenshots] = useState([]);
const [attachments, setAttachments] = useState([]);
const [templates, setTemplates] = useState([]);
- const [showTemplates, setShowTemplates] = useState(queueFirst);
+ const [showTemplates, setShowTemplates] = useState(() => readQuickTemplatesExpanded(queueFirst));
// Compact-mode-only "More options" toggle. Callers that render in a
// tall container (the dashboard Quick Task widget) pass defaultExpanded
// so the card paints as a complete capture form on first render.
@@ -152,6 +163,7 @@ export default function TaskAddForm({ providers, providersLoaded = true, apps, o
implementer: { provider: '', model: '', effort: '' },
reviewer: { provider: '', model: '', effort: '' },
});
+ const showTemplatesInitialized = useRef(false);
useEffect(() => {
api.getOrchestrationProfiles?.({ silent: true })
@@ -239,12 +251,32 @@ export default function TaskAddForm({ providers, providersLoaded = true, apps, o
setNewTask(task => ({ ...task, app: defaultApp }));
}, [apps, defaultApp, newTask.app]);
- // Fetch templates
+ // Fetch templates only when the optional feature is enabled. This keeps the
+ // default form free of template UI and avoids an unnecessary API read.
useEffect(() => {
+ if (!quickTemplatesEnabled) {
+ setTemplates([]);
+ setShowTemplateSave(false);
+ return;
+ }
+ let active = true;
api.getCosPopularTemplates(8)
- .then(data => setTemplates(data.templates || []))
- .catch(() => setTemplates([]));
- }, []);
+ .then(data => {
+ if (active) setTemplates(data.templates || []);
+ })
+ .catch(() => {
+ if (active) setTemplates([]);
+ });
+ return () => { active = false; };
+ }, [quickTemplatesEnabled]);
+
+ useEffect(() => {
+ if (!showTemplatesInitialized.current) {
+ showTemplatesInitialized.current = true;
+ return;
+ }
+ safeWriteStorage(QUICK_TEMPLATES_EXPANDED_KEY, String(showTemplates));
+ }, [showTemplates]);
// Seed reviewer state from the global Code Review Defaults (AI Providers →
// Code Review Defaults panel). One-shot on mount: if the user later toggles
@@ -953,6 +985,7 @@ export default function TaskAddForm({ providers, providersLoaded = true, apps, o
);
function renderTemplates() {
+ if (!quickTemplatesEnabled) return null;
return (
<>
{/* Quick Templates */}
@@ -1493,7 +1526,7 @@ export default function TaskAddForm({ providers, providersLoaded = true, apps, o
)}
</div>
</>}
- {(section === 'all' || section === 'templates') && <>
+ {quickTemplatesEnabled && (section === 'all' || section === 'templates') && <>
{/* Template Save Inline Input */}
{showTemplateSave && (
<div className="flex flex-wrap gap-2 items-center">
diff --git a/client/src/components/cos/TaskAddForm.test.jsx b/client/src/components/cos/TaskAddForm.test.jsx
index 1eea489587..b22752e9d5 100644
--- a/client/src/components/cos/TaskAddForm.test.jsx
+++ b/client/src/components/cos/TaskAddForm.test.jsx
@@ -34,6 +34,7 @@ const apiSystem = vi.hoisted(() => ({ getAssignableInstances: vi.fn() }));
// describe below that clears mocks without re-seeding it still renders without
// unhandled fetch, since `vi.clearAllMocks()` clears calls but keeps this default.
const apiLocalLlm = vi.hoisted(() => ({ getToolUseModels: vi.fn().mockResolvedValue({ models: [] }) }));
+const featureGate = vi.hoisted(() => ({ quickTemplatesEnabled: true }));
const toast = vi.hoisted(() => {
const toastFn = vi.fn();
toastFn.success = vi.fn();
@@ -44,8 +45,18 @@ const toast = vi.hoisted(() => {
vi.mock('../../services/apiSystem', () => apiSystem);
vi.mock('../../services/api', () => api);
vi.mock('../../services/apiLocalLlm', () => apiLocalLlm);
+vi.mock('../../hooks/useInstanceFeatures', () => ({
+ useInstanceFeatures: () => ({
+ isFeatureEnabled: (featureId) => featureId === 'cos-task-templates' ? featureGate.quickTemplatesEnabled : true,
+ }),
+}));
vi.mock('../ui/Toast', () => ({ default: toast }));
+beforeEach(() => {
+ featureGate.quickTemplatesEnabled = true;
+ localStorage.removeItem('portos-cos-quick-templates-expanded');
+});
+
const worktreeToggle = () => screen.getByTitle(/isolated git worktree/i).closest('label').querySelector('input');
const openPrToggle = () => screen.getByTitle(/Open a pull request/i).closest('label').querySelector('input');
const planOnlyToggle = () => screen.getByLabelText(/Plan & file issue/i);
@@ -74,6 +85,20 @@ describe('TaskAddForm responsive layout', () => {
apiLocalLlm.getToolUseModels.mockResolvedValue({ models: [] });
});
+ it('hides quick templates and skips their fetch when the feature is disabled', async () => {
+ featureGate.quickTemplatesEnabled = false;
+ api.getCosPopularTemplates.mockResolvedValue({
+ templates: [{ id: 'hidden-template', name: 'Hidden Template', description: 'Not shown', isBuiltin: true }],
+ });
+
+ render(<TaskAddForm providers={[]} apps={[]} onTaskAdded={vi.fn()} />);
+
+ await waitFor(() => expect(screen.getByPlaceholderText('Task description *')).toBeInTheDocument());
+ expect(screen.queryByText('Quick Templates')).toBeNull();
+ expect(screen.queryByRole('button', { name: /Save Template/i })).toBeNull();
+ expect(api.getCosPopularTemplates).not.toHaveBeenCalled();
+ });
+
// #7796: hiding configuration must not reset the draft or silently change
// app completion defaults, and a failed submission must remain retryable.
it('keeps queue settings inline and retains drafts across collapse and failed submission', async () => {
@@ -483,6 +508,34 @@ describe('TaskAddForm quick templates', () => {
expect(screen.getByLabelText(/target application/i)).toHaveValue('example-app');
});
+ it('remembers a collapsed section across queue-first task forms', async () => {
+ const user = userEvent.setup();
+ api.getCosPopularTemplates.mockResolvedValue({
+ templates: [{ id: 'user-abc', name: 'My Template', description: 'Do the thing', isBuiltin: false }],
+ });
+
+ const formProps = {
+ queueFirst: true,
+ providers: [],
+ apps: [],
+ onTaskAdded: vi.fn(),
+ };
+ const { unmount } = render(<TaskAddForm {...formProps} />);
+ const firstToggle = await screen.findByRole('button', { name: /Quick Templates/ });
+ expect(firstToggle).toHaveAttribute('aria-expanded', 'true');
+
+ await user.click(firstToggle);
+ await waitFor(() => expect(firstToggle).toHaveAttribute('aria-expanded', 'false'));
+ await waitFor(() => expect(localStorage.getItem('portos-cos-quick-templates-expanded')).toBe('false'));
+ expect(screen.queryByText('My Template')).toBeNull();
+
+ unmount();
+ render(<TaskAddForm {...formProps} />);
+ const secondToggle = await screen.findByRole('button', { name: /Quick Templates/ });
+ expect(secondToggle).toHaveAttribute('aria-expanded', 'false');
+ expect(screen.queryByText('My Template')).toBeNull();
+ });
+
it('keeps the local template application and warns when usage recording fails', async () => {
const user = userEvent.setup();
api.getCosPopularTemplates.mockResolvedValue({
diff --git a/server/lib/instanceFeatureRegistry.js b/server/lib/instanceFeatureRegistry.js
index 828110a884..1819fa1f01 100644
--- a/server/lib/instanceFeatureRegistry.js
+++ b/server/lib/instanceFeatureRegistry.js
@@ -82,6 +82,12 @@ export const INSTANCE_FEATURES = Object.freeze([
description: 'Get Stuff Done project planning and progress tracking for managed apps.',
defaultEnabled: false,
}),
+ Object.freeze({
+ id: 'cos-task-templates',
+ label: 'CoS task templates',
+ description: 'Quick reusable task templates in the Chief of Staff task form.',
+ defaultEnabled: false,
+ }),
Object.freeze({
id: 'openclaw',
label: 'OpenClaw',
diff --git a/server/lib/instanceFeatureRegistry.test.js b/server/lib/instanceFeatureRegistry.test.js
index 43a7309217..0427aeca75 100644
--- a/server/lib/instanceFeatureRegistry.test.js
+++ b/server/lib/instanceFeatureRegistry.test.js
@@ -32,6 +32,13 @@ describe('instance feature registry', () => {
defaultEnabled: true,
});
});
+
+ it('keeps CoS task templates opt-in by default', () => {
+ expect(INSTANCE_FEATURES.find((feature) => feature.id === 'cos-task-templates')).toMatchObject({
+ label: 'CoS task templates',
+ defaultEnabled: false,
+ });
+ });
});
describe('instance feature groups (#40)', () => {
diff --git a/server/routes/settings.test.js b/server/routes/settings.test.js
index 0a048edf67..ecf7791576 100644
--- a/server/routes/settings.test.js
+++ b/server/routes/settings.test.js
@@ -209,6 +209,7 @@ describe('Settings routes — instance feature participation', () => {
}));
// GSD and OpenClaw ship disabled by default; the install opts in.
expect(res.body.features).toContainEqual(expect.objectContaining({ id: 'gsd', enabled: false }));
+ expect(res.body.features).toContainEqual(expect.objectContaining({ id: 'cos-task-templates', enabled: false, source: 'default' }));
expect(res.body.features).toContainEqual(expect.objectContaining({ id: 'openclaw', enabled: false }));
expect(res.body.features).toContainEqual(expect.objectContaining({ id: 'health', enabled: true }));
// #40 — iMessage and Signal join the comms group, defaulting to enabled
diff --git a/server/services/instanceFeatures.test.js b/server/services/instanceFeatures.test.js
index 88cb89fd14..924a1f2854 100644
--- a/server/services/instanceFeatures.test.js
+++ b/server/services/instanceFeatures.test.js
@@ -307,7 +307,7 @@ describe('instance features', () => {
const { features } = await getInstanceFeatures();
expect(Object.fromEntries(features.map((f) => [f.id, f.enabled]))).toEqual({
- post: true, autobiography: true, datadog: true, jira: false, eidoverse: false, gsd: false, openclaw: false, health: true,
+ post: true, autobiography: true, datadog: true, jira: false, eidoverse: false, gsd: false, 'cos-task-templates': false, openclaw: false, health: true,
rigging: false, facetime: false, imessage: true, signal: true, x: true, 'stacker-news': true, beeper: false,
jev: false,
'laya-mlx': false,