@businesskit/agent 1.0.5 → 1.0.8
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +1 -1
- package/.superconsole-plugin/plugin.json +61 -31
- package/AGENTS.md +33 -15
- package/README.md +101 -113
- package/bin/businesskit.js +47 -8
- package/commands/brief.md +12 -0
- package/commands/chase.md +12 -0
- package/commands/competitors.md +12 -0
- package/commands/create-page.md +43 -15
- package/commands/crm.md +13 -0
- package/commands/drafts.md +12 -0
- package/commands/followups.md +13 -0
- package/commands/inbox-rules.md +12 -0
- package/commands/inbox.md +13 -0
- package/commands/otp.md +12 -0
- package/commands/pipeline.md +13 -0
- package/commands/post.md +12 -0
- package/commands/reply.md +12 -0
- package/commands/repurpose.md +12 -0
- package/commands/social-analytics.md +12 -0
- package/commands/social-inbox.md +12 -0
- package/commands/social-reply.md +12 -0
- package/commands/social.md +12 -0
- package/commands/triage.md +12 -0
- package/commands/update-agent.md +33 -0
- package/commands/update-content.md +1 -0
- package/commands/update-page.md +3 -2
- package/commands/write-blog.md +4 -0
- package/commands/write-docs.md +6 -0
- package/commands/write-guide.md +5 -0
- package/commands/write-newsletter.md +4 -0
- package/dist/server.js +7513 -0
- package/mcp_config.json +6 -2
- package/package.json +25 -5
- package/plugin.json +1 -1
- package/scripts/release.js +200 -0
- package/scripts/setup.sh +70 -35
- package/scripts/setup.ts +58 -21
- package/scripts/update.sh +56 -0
- package/server.json +3 -3
- package/skills/README.md +3 -2
- package/skills/cms/SKILL.md +111 -0
- package/skills/cms/references/cms-hubs.md +84 -0
- package/skills/cms/references/html-blocks.md +177 -0
- package/skills/crm/SKILL.md +15 -29
- package/skills/docs/SKILL.md +65 -0
- package/skills/docs/references/how-to.md +155 -0
- package/skills/inbox/SKILL.md +32 -40
- package/skills/pages/SKILL.md +62 -17
- package/skills/pages/references/sections-catalog.json +377 -144
- package/skills/social/SKILL.md +83 -210
- package/skills/social/evals/evals.json +66 -0
- package/skills/social/evals/rubric.md +26 -0
- package/skills/social/examples/repurposing-blog-to-social.md +93 -0
- package/skills/social/examples/weekly-content-calendar.md +30 -0
- package/skills/social/linkedin/SKILL.md +107 -0
- package/skills/social/linkedin/evals/evals.json +106 -0
- package/skills/social/linkedin/evals/rubric.md +28 -0
- package/skills/social/linkedin/examples/gasp-weekly-sprint.md +24 -0
- package/skills/social/linkedin/examples/growth-posts-by-format.md +140 -0
- package/skills/social/linkedin/references/gasp-funnel-and-calibration.md +90 -0
- package/skills/social/linkedin/references/six-growth-formats.md +114 -0
- package/skills/social/references/platforms.md +76 -0
- package/skills/social/references/post-templates.md +105 -0
- package/skills/social/references/reverse-engineering.md +62 -0
- package/src/data/sections-catalog.json +950 -0
- package/src/db.ts +181 -0
- package/src/server.ts +119 -0
- package/src/tools/content.ts +326 -0
- package/src/tools/crm.ts +1416 -0
- package/src/tools/domains.ts +89 -0
- package/src/tools/inbox.ts +1400 -0
- package/src/tools/index.ts +138 -0
- package/src/tools/pages.ts +1217 -0
- package/src/tools/shop.ts +771 -0
- package/src/tools/social.ts +2131 -0
- package/src/tools/system.ts +96 -0
- package/src/tools/types.ts +17 -0
- package/src/worker-tick.ts +394 -0
- package/skills/docs-cms/SKILL.md +0 -53
- package/skills/docs-cms/references/how-to.md +0 -383
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// src/tools/system.ts
|
|
2
|
+
// Platform Introspection & Profile Management MCP Tools
|
|
3
|
+
|
|
4
|
+
import { getActiveProfileId, setActiveProfileId, query, isDbConfigured } from '../db.js';
|
|
5
|
+
import { getAllToolDefinitions } from './index.js';
|
|
6
|
+
import type { ToolDefinition, ToolContext } from './types.js';
|
|
7
|
+
|
|
8
|
+
export const systemTools: ToolDefinition[] = [
|
|
9
|
+
{
|
|
10
|
+
name: 'system_get_capabilities',
|
|
11
|
+
domain: 'system',
|
|
12
|
+
description:
|
|
13
|
+
'Discover all available BusinessKit platform capabilities, domains, tool counts, and features. Call when the user asks what abilities, tools, or domains exist.',
|
|
14
|
+
inputSchema: {
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
domain: { type: 'string', description: "Optional domain filter (e.g. 'shop', 'crm', 'content', 'pages', 'domains')" },
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
handler: async (args: Record<string, any>, _ctx: ToolContext) => {
|
|
21
|
+
const filter = args.domain?.toLowerCase()?.trim();
|
|
22
|
+
const domains = [
|
|
23
|
+
{ name: 'shop', description: 'Shop, inventory restock, purchase invoices, billing, and stock ledger' },
|
|
24
|
+
{ name: 'crm', description: 'Customer relationship management, leads, contacts, and outreach' },
|
|
25
|
+
{
|
|
26
|
+
name: 'content',
|
|
27
|
+
description: 'Multi-hub CMS content publishing (blog, docs, guides, notes, newsletter) with rich HTML',
|
|
28
|
+
},
|
|
29
|
+
{ name: 'pages', description: 'Website pages, landing pages, site content, and publishing' },
|
|
30
|
+
{ name: 'domains', description: 'Domain portfolio management, RDAP status, expiry tracking, and renewal reminders' },
|
|
31
|
+
{ name: 'inbox', description: 'Unified inbox — thread triage, labelling, reply drafting, scheduling, and archiving' },
|
|
32
|
+
{ name: 'social', description: 'Social media accounts, content repurposing, draft composer, inbox conversations, and analytics' },
|
|
33
|
+
{ name: 'system', description: 'Platform introspection, profile switching, and agent system utilities' },
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const matchingDomains = filter && filter !== 'all' ? domains.filter((d) => d.name === filter) : domains;
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
platform: 'BusinessKit',
|
|
40
|
+
architecture: 'Model Context Protocol (MCP) stdio JSON-RPC server',
|
|
41
|
+
active_domains: matchingDomains,
|
|
42
|
+
database_connected: isDbConfigured(),
|
|
43
|
+
total_tools: getAllToolDefinitions().length,
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'profile_list',
|
|
49
|
+
domain: 'system',
|
|
50
|
+
description: 'List all business/organization profiles available in the active database and check which one is active.',
|
|
51
|
+
inputSchema: {
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties: {},
|
|
54
|
+
},
|
|
55
|
+
handler: async (_args: Record<string, any>, ctx: ToolContext) => {
|
|
56
|
+
let profiles: any[] = [];
|
|
57
|
+
if (isDbConfigured()) {
|
|
58
|
+
try {
|
|
59
|
+
profiles = await query<{ id: string; title?: string; slug?: string }>('SELECT id, title, slug FROM profiles LIMIT 50');
|
|
60
|
+
} catch (err) {
|
|
61
|
+
console.error('[Profile] Profiles query error:', err);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
active_profile: ctx.profileId,
|
|
67
|
+
available_profiles: profiles.length > 0 ? profiles : [{ id: ctx.profileId, title: 'Default Business' }],
|
|
68
|
+
total: profiles.length > 0 ? profiles.length : 1,
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'profile_switch',
|
|
74
|
+
domain: 'system',
|
|
75
|
+
description: 'Switch the active business/organization profile for this MCP session.',
|
|
76
|
+
inputSchema: {
|
|
77
|
+
type: 'object',
|
|
78
|
+
properties: {
|
|
79
|
+
profile_id: { type: 'string', description: 'The profile ID to switch to' },
|
|
80
|
+
},
|
|
81
|
+
required: ['profile_id'],
|
|
82
|
+
},
|
|
83
|
+
handler: async (args: Record<string, any>, _ctx: ToolContext) => {
|
|
84
|
+
const newProfileId = String(args.profile_id).trim();
|
|
85
|
+
if (!newProfileId) {
|
|
86
|
+
throw new Error('profile_id is required');
|
|
87
|
+
}
|
|
88
|
+
setActiveProfileId(newProfileId);
|
|
89
|
+
return {
|
|
90
|
+
success: true,
|
|
91
|
+
active_profile: newProfileId,
|
|
92
|
+
status: 'switched',
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/tools/types.ts
|
|
2
|
+
// Shared types for BusinessKit MCP tools
|
|
3
|
+
|
|
4
|
+
export interface ToolDefinition {
|
|
5
|
+
name: string;
|
|
6
|
+
domain: string;
|
|
7
|
+
description: string;
|
|
8
|
+
inputSchema: Record<string, any>;
|
|
9
|
+
handler: (args: Record<string, any>, ctx: ToolContext) => Promise<any>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ToolContext {
|
|
13
|
+
profileId: string;
|
|
14
|
+
userId?: string;
|
|
15
|
+
agentName?: string;
|
|
16
|
+
mediaAttachmentId?: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
// src/worker-tick.ts
|
|
2
|
+
// Off-device headless Inbox automation runner for cron / Cloudflare / worker triggers.
|
|
3
|
+
// Operates directly against the shared UserDB (Turso) via db.ts without touching desktop UI.
|
|
4
|
+
|
|
5
|
+
import { execute, generateId, getActiveProfileId, query, setActiveProfileId } from './db.js';
|
|
6
|
+
|
|
7
|
+
export interface OffDeviceTickSummary {
|
|
8
|
+
profileId: string;
|
|
9
|
+
skippedDisabled: boolean;
|
|
10
|
+
wokenSnoozed: number;
|
|
11
|
+
prefilteredTriaged: number;
|
|
12
|
+
staleNudged: number;
|
|
13
|
+
digestCreated: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function getConfigVal(profileId: string, key: string): Promise<string | null> {
|
|
17
|
+
const rows = await query<{ config_val: string }>(
|
|
18
|
+
'SELECT config_val FROM crm_config WHERE profile_id = ? AND config_key = ? LIMIT 1',
|
|
19
|
+
[profileId, key]
|
|
20
|
+
);
|
|
21
|
+
return rows[0]?.config_val ?? null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function setConfigVal(profileId: string, key: string, value: string): Promise<void> {
|
|
25
|
+
const now = Math.floor(Date.now() / 1000);
|
|
26
|
+
await execute('DELETE FROM crm_config WHERE profile_id = ? AND config_key = ?', [profileId, key]);
|
|
27
|
+
await execute(
|
|
28
|
+
'INSERT INTO crm_config (id, profile_id, config_key, config_val, updated_at) VALUES (?, ?, ?, ?, ?)',
|
|
29
|
+
[generateId('cfg'), profileId, key, value, now]
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isAutomatedPrefilter(fromAddr: string, subject: string, body: string): boolean {
|
|
34
|
+
const from = fromAddr.toLowerCase();
|
|
35
|
+
const subj = subject.toLowerCase();
|
|
36
|
+
const txt = body.toLowerCase();
|
|
37
|
+
return (
|
|
38
|
+
from.includes('noreply@') ||
|
|
39
|
+
from.includes('no-reply@') ||
|
|
40
|
+
from.includes('donotreply@') ||
|
|
41
|
+
from.includes('mailer-daemon@') ||
|
|
42
|
+
txt.includes('list-unsubscribe') ||
|
|
43
|
+
txt.includes('unsubscribe') ||
|
|
44
|
+
subj.includes('newsletter')
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function runOffDeviceInboxTick(explicitProfileId?: string): Promise<OffDeviceTickSummary> {
|
|
49
|
+
if (explicitProfileId) {
|
|
50
|
+
setActiveProfileId(explicitProfileId);
|
|
51
|
+
}
|
|
52
|
+
const profileId = explicitProfileId || (await getActiveProfileId());
|
|
53
|
+
const now = Math.floor(Date.now() / 1000);
|
|
54
|
+
|
|
55
|
+
const jobsFlag = await getConfigVal(profileId, 'inbox.jobs_enabled');
|
|
56
|
+
if (jobsFlag === 'false' || jobsFlag === '0') {
|
|
57
|
+
return {
|
|
58
|
+
profileId,
|
|
59
|
+
skippedDisabled: true,
|
|
60
|
+
wokenSnoozed: 0,
|
|
61
|
+
prefilteredTriaged: 0,
|
|
62
|
+
staleNudged: 0,
|
|
63
|
+
digestCreated: false,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 1. Wake due snoozed threads based on latest message direction
|
|
68
|
+
const dueSnoozed = await query<{ id: string }>(
|
|
69
|
+
`SELECT id FROM inbox_threads
|
|
70
|
+
WHERE profile_id = ? AND state = 'snoozed' AND snoozed_until IS NOT NULL AND snoozed_until <= ?
|
|
71
|
+
LIMIT 50`,
|
|
72
|
+
[profileId, now]
|
|
73
|
+
);
|
|
74
|
+
let wokenSnoozed = 0;
|
|
75
|
+
for (const th of dueSnoozed) {
|
|
76
|
+
const latest = await query<{ direction: string }>(
|
|
77
|
+
'SELECT direction FROM inbox_messages WHERE thread_id = ? ORDER BY received_at DESC LIMIT 1',
|
|
78
|
+
[th.id]
|
|
79
|
+
);
|
|
80
|
+
const nextState = latest[0]?.direction === 'out' ? 'awaiting' : 'needs_reply';
|
|
81
|
+
await execute(
|
|
82
|
+
`UPDATE inbox_threads
|
|
83
|
+
SET state = ?, snoozed_until = NULL, is_unread = 1, updated_by = 'agent_worker', updated_at = ?
|
|
84
|
+
WHERE id = ? AND profile_id = ?`,
|
|
85
|
+
[nextState, now, th.id, profileId]
|
|
86
|
+
);
|
|
87
|
+
wokenSnoozed++;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 2. Zero-LLM deterministic newsletter/automated triage
|
|
91
|
+
const untriaged = await query<{
|
|
92
|
+
id: string;
|
|
93
|
+
from_addr: string;
|
|
94
|
+
subject: string | null;
|
|
95
|
+
body_text: string | null;
|
|
96
|
+
snippet: string | null;
|
|
97
|
+
}>(
|
|
98
|
+
`SELECT t.id, m.from_addr, COALESCE(m.subject, t.subject) AS subject, m.body_text, m.snippet
|
|
99
|
+
FROM inbox_threads t
|
|
100
|
+
JOIN inbox_messages m ON m.id = (
|
|
101
|
+
SELECT m2.id FROM inbox_messages m2
|
|
102
|
+
WHERE m2.thread_id = t.id AND m2.direction = 'in'
|
|
103
|
+
ORDER BY m2.received_at DESC LIMIT 1
|
|
104
|
+
)
|
|
105
|
+
WHERE t.profile_id = ?
|
|
106
|
+
AND (t.state = 'none' OR t.category IS NULL)
|
|
107
|
+
AND NOT EXISTS (
|
|
108
|
+
SELECT 1 FROM inbox_messages h WHERE h.thread_id = t.id AND h.screen_status IN ('suspicious', 'blocked')
|
|
109
|
+
)
|
|
110
|
+
ORDER BY t.last_message_at DESC LIMIT 25`,
|
|
111
|
+
[profileId]
|
|
112
|
+
);
|
|
113
|
+
let prefilteredTriaged = 0;
|
|
114
|
+
for (const row of untriaged) {
|
|
115
|
+
const body = row.body_text || row.snippet || '';
|
|
116
|
+
const subj = row.subject || '';
|
|
117
|
+
if (isAutomatedPrefilter(row.from_addr, subj, body)) {
|
|
118
|
+
await execute(
|
|
119
|
+
`UPDATE inbox_threads
|
|
120
|
+
SET category = COALESCE(category, 'newsletter'),
|
|
121
|
+
state = CASE WHEN state = 'none' THEN 'done' ELSE state END,
|
|
122
|
+
agent_summary = COALESCE(NULLIF(agent_summary, ''), ?),
|
|
123
|
+
updated_by = 'agent_worker', updated_at = ?
|
|
124
|
+
WHERE id = ? AND profile_id = ?`,
|
|
125
|
+
[`Automated/newsletter message from ${row.from_addr}`, now, row.id, profileId]
|
|
126
|
+
);
|
|
127
|
+
prefilteredTriaged++;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 3. Stale waiting-on-reply nudges (default 3 days)
|
|
132
|
+
const staleDaysRaw = Number((await getConfigVal(profileId, 'inbox.stale_days')) ?? '3');
|
|
133
|
+
const staleDays = Number.isFinite(staleDaysRaw) && staleDaysRaw >= 1 ? Math.floor(staleDaysRaw) : 3;
|
|
134
|
+
const cutoff = now - staleDays * 86_400;
|
|
135
|
+
const staleRows = await query<{ id: string; subject: string | null; last_message_at: number }>(
|
|
136
|
+
`SELECT t.id, t.subject, t.last_message_at
|
|
137
|
+
FROM inbox_threads t
|
|
138
|
+
JOIN inbox_messages lm ON lm.id = (
|
|
139
|
+
SELECT m2.id FROM inbox_messages m2 WHERE m2.thread_id = t.id ORDER BY m2.received_at DESC LIMIT 1
|
|
140
|
+
)
|
|
141
|
+
WHERE t.profile_id = ? AND t.state IN ('none', 'awaiting') AND t.last_message_at <= ?
|
|
142
|
+
AND lm.direction = 'out' AND lm.send_status = 'sent'
|
|
143
|
+
ORDER BY t.last_message_at ASC LIMIT 10`,
|
|
144
|
+
[profileId, cutoff]
|
|
145
|
+
);
|
|
146
|
+
let staleNudged = 0;
|
|
147
|
+
for (const row of staleRows) {
|
|
148
|
+
await execute(
|
|
149
|
+
"UPDATE inbox_threads SET state = 'awaiting', updated_by = 'agent_worker', updated_at = ? WHERE id = ? AND profile_id = ?",
|
|
150
|
+
[now, row.id, profileId]
|
|
151
|
+
);
|
|
152
|
+
const idem = `stale:${row.id}:${row.last_message_at}`;
|
|
153
|
+
const exists = await query('SELECT 1 FROM agent_tasks WHERE idempotency_key = ? LIMIT 1', [idem]);
|
|
154
|
+
if (exists.length === 0) {
|
|
155
|
+
await execute(
|
|
156
|
+
`INSERT OR IGNORE INTO agent_tasks
|
|
157
|
+
(id, agent_id, profile_id, title, output, status, task_type, source_id, idempotency_key, is_read, completed_at, created_at, updated_at)
|
|
158
|
+
VALUES (?, 'inbox', ?, ?, ?, 'completed', 'inbox_stale_nudge', ?, ?, 0, ?, ?, ?)`,
|
|
159
|
+
[
|
|
160
|
+
generateId('task'),
|
|
161
|
+
profileId,
|
|
162
|
+
`Waiting on reply (${staleDays}d+): ${row.subject || '(No subject)'}`,
|
|
163
|
+
JSON.stringify({ thread_id: row.id, sources: [`inbox:${row.id}`] }),
|
|
164
|
+
row.id,
|
|
165
|
+
idem,
|
|
166
|
+
now,
|
|
167
|
+
now,
|
|
168
|
+
now,
|
|
169
|
+
]
|
|
170
|
+
);
|
|
171
|
+
staleNudged++;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// 4. Daily digest (once per UTC day after digest_hour)
|
|
176
|
+
let digestCreated = false;
|
|
177
|
+
const dt = new Date();
|
|
178
|
+
const digestHourRaw = Number((await getConfigVal(profileId, 'inbox.digest_hour')) ?? '9');
|
|
179
|
+
const digestHour = Number.isFinite(digestHourRaw) && digestHourRaw >= 0 && digestHourRaw <= 23 ? digestHourRaw : 9;
|
|
180
|
+
const todayStr = dt.toISOString().slice(0, 10);
|
|
181
|
+
const lastDigestDate = await getConfigVal(profileId, 'inbox.last_digest_date');
|
|
182
|
+
if (dt.getUTCHours() >= digestHour && lastDigestDate !== todayStr) {
|
|
183
|
+
const countRows = await query<{ nr: number; aw: number; dr: number; hd: number }>(
|
|
184
|
+
`SELECT
|
|
185
|
+
(SELECT COUNT(*) FROM inbox_threads WHERE profile_id = ? AND state = 'needs_reply') AS nr,
|
|
186
|
+
(SELECT COUNT(*) FROM inbox_threads WHERE profile_id = ? AND state = 'awaiting') AS aw,
|
|
187
|
+
(SELECT COUNT(*) FROM inbox_messages WHERE profile_id = ? AND direction = 'out' AND author = 'agent' AND send_status = 'draft') AS dr,
|
|
188
|
+
(SELECT COUNT(*) FROM inbox_messages WHERE profile_id = ? AND direction = 'in' AND screen_status IN ('suspicious', 'blocked')) AS hd`,
|
|
189
|
+
[profileId, profileId, profileId, profileId]
|
|
190
|
+
);
|
|
191
|
+
const c = countRows[0] ?? { nr: 0, aw: 0, dr: 0, hd: 0 };
|
|
192
|
+
await setConfigVal(profileId, 'inbox.last_digest_date', todayStr);
|
|
193
|
+
if (Number(c.nr) + Number(c.aw) + Number(c.dr) + Number(c.hd) > 0) {
|
|
194
|
+
await execute(
|
|
195
|
+
`INSERT OR IGNORE INTO agent_tasks
|
|
196
|
+
(id, agent_id, profile_id, title, output, status, task_type, idempotency_key, is_read, completed_at, created_at, updated_at)
|
|
197
|
+
VALUES (?, 'inbox', ?, ?, ?, 'completed', 'digest', ?, 0, ?, ?, ?)`,
|
|
198
|
+
[
|
|
199
|
+
generateId('task'),
|
|
200
|
+
profileId,
|
|
201
|
+
`Daily Inbox Digest (${todayStr})`,
|
|
202
|
+
`Daily Inbox Digest (${todayStr}): ${c.nr} needing reply, ${c.dr} AI draft(s), ${c.hd} held, ${c.aw} waiting on reply.`,
|
|
203
|
+
`inbox_digest:${profileId}:${todayStr}`,
|
|
204
|
+
now,
|
|
205
|
+
now,
|
|
206
|
+
now,
|
|
207
|
+
]
|
|
208
|
+
);
|
|
209
|
+
digestCreated = true;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
await setConfigVal(profileId, 'inbox.last_run_at', String(now));
|
|
214
|
+
return {
|
|
215
|
+
profileId,
|
|
216
|
+
skippedDisabled: false,
|
|
217
|
+
wokenSnoozed,
|
|
218
|
+
prefilteredTriaged,
|
|
219
|
+
staleNudged,
|
|
220
|
+
digestCreated,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export interface OffDeviceSocialTickSummary {
|
|
225
|
+
profileId: string;
|
|
226
|
+
skippedDisabled: boolean;
|
|
227
|
+
optedOutMarked: number;
|
|
228
|
+
prefilteredTriaged: number;
|
|
229
|
+
postsLabeled: number;
|
|
230
|
+
digestCreated: boolean;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function isSimpleSocialReaction(text: string): boolean {
|
|
234
|
+
const t = text.trim().toLowerCase();
|
|
235
|
+
if (!t) return true;
|
|
236
|
+
if (['ok', 'okay', 'thx', 'thanks', 'thank you', 'ty', 'cool', 'nice', 'great', '❤️', '🙏', '👍', '🔥', '👏', '💯'].includes(t)) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
return Array.from(t).length <= 3 && !/[a-z0-9?]/i.test(t);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function deterministicPostLabel(content: string): string {
|
|
243
|
+
const txt = content.toLowerCase();
|
|
244
|
+
if (txt.includes('launch') || txt.includes('introducing') || txt.includes('announcing')) return 'announcement';
|
|
245
|
+
if (txt.includes('discount') || txt.includes('% off') || txt.includes('buy') || txt.includes('pricing')) return 'promotional';
|
|
246
|
+
if (txt.includes('how to') || txt.includes('guide') || txt.includes('tip') || txt.includes('thread')) return 'educational';
|
|
247
|
+
if (txt.includes('?')) return 'engagement';
|
|
248
|
+
return 'educational';
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export async function runOffDeviceSocialTick(explicitProfileId?: string): Promise<OffDeviceSocialTickSummary> {
|
|
252
|
+
if (explicitProfileId) {
|
|
253
|
+
setActiveProfileId(explicitProfileId);
|
|
254
|
+
}
|
|
255
|
+
const profileId = explicitProfileId || (await getActiveProfileId());
|
|
256
|
+
const now = Math.floor(Date.now() / 1000);
|
|
257
|
+
|
|
258
|
+
const jobsFlag = await getConfigVal(profileId, 'social.jobs_enabled');
|
|
259
|
+
if (jobsFlag === 'false' || jobsFlag === '0') {
|
|
260
|
+
return {
|
|
261
|
+
profileId,
|
|
262
|
+
skippedDisabled: true,
|
|
263
|
+
optedOutMarked: 0,
|
|
264
|
+
prefilteredTriaged: 0,
|
|
265
|
+
postsLabeled: 0,
|
|
266
|
+
digestCreated: false,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// 1. Honor opt-out keywords & zero-LLM social inbox prefilter
|
|
271
|
+
const unprocessed = await query<{
|
|
272
|
+
id: string;
|
|
273
|
+
account_id: string;
|
|
274
|
+
sender_platform_id: string | null;
|
|
275
|
+
sender_username: string | null;
|
|
276
|
+
content: string | null;
|
|
277
|
+
opt_out_kw: string;
|
|
278
|
+
}>(
|
|
279
|
+
`SELECT m.id, m.account_id, m.sender_platform_id, m.sender_username, m.content,
|
|
280
|
+
COALESCE(NULLIF(TRIM(a.dm_opt_out_keyword), ''), 'STOP') AS opt_out_kw
|
|
281
|
+
FROM social_messages m
|
|
282
|
+
LEFT JOIN social_accounts a ON a.id = m.account_id
|
|
283
|
+
WHERE m.profile_id = ? AND m.is_own = 0 AND COALESCE(m.agent_processed, 0) = 0
|
|
284
|
+
ORDER BY m.received_at ASC LIMIT 40`,
|
|
285
|
+
[profileId]
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
let optedOutMarked = 0;
|
|
289
|
+
let prefilteredTriaged = 0;
|
|
290
|
+
for (const row of unprocessed) {
|
|
291
|
+
const body = String(row.content || '').trim();
|
|
292
|
+
const kw = String(row.opt_out_kw || 'STOP').trim();
|
|
293
|
+
if (body && body.toLowerCase() === kw.toLowerCase()) {
|
|
294
|
+
await execute(
|
|
295
|
+
`UPDATE social_sequence_enrollments
|
|
296
|
+
SET opted_out = 1, status = 'opted_out', opted_out_at = ?, opted_out_reason = 'keyword_stop', updated_at = ?
|
|
297
|
+
WHERE profile_id = ? AND status = 'active' AND COALESCE(opted_out, 0) = 0
|
|
298
|
+
AND ((? IS NOT NULL AND ? != '' AND contact_platform_id = ?)
|
|
299
|
+
OR (? IS NOT NULL AND ? != '' AND LOWER(TRIM(REPLACE(COALESCE(contact_username, ''), '@', ''))) = LOWER(TRIM(REPLACE(?, '@', '')))))`,
|
|
300
|
+
[
|
|
301
|
+
now,
|
|
302
|
+
now,
|
|
303
|
+
profileId,
|
|
304
|
+
row.sender_platform_id,
|
|
305
|
+
row.sender_platform_id,
|
|
306
|
+
row.sender_platform_id,
|
|
307
|
+
row.sender_username,
|
|
308
|
+
row.sender_username,
|
|
309
|
+
row.sender_username,
|
|
310
|
+
]
|
|
311
|
+
);
|
|
312
|
+
await execute(
|
|
313
|
+
`UPDATE social_messages
|
|
314
|
+
SET agent_processed = 1, agent_suggested_action = 'opt_out', approval_status = 'auto_sent', updated_at = ?
|
|
315
|
+
WHERE id = ? AND profile_id = ?`,
|
|
316
|
+
[now, row.id, profileId]
|
|
317
|
+
);
|
|
318
|
+
optedOutMarked++;
|
|
319
|
+
} else if (isSimpleSocialReaction(body)) {
|
|
320
|
+
await execute(
|
|
321
|
+
`UPDATE social_messages
|
|
322
|
+
SET agent_processed = 1, agent_suggested_action = 'none', approval_status = 'auto_sent', updated_at = ?
|
|
323
|
+
WHERE id = ? AND profile_id = ?`,
|
|
324
|
+
[now, row.id, profileId]
|
|
325
|
+
);
|
|
326
|
+
prefilteredTriaged++;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// 2. Deterministic post labeling for unlabeled published posts
|
|
331
|
+
const unlabeled = await query<{ id: string; content: string | null }>(
|
|
332
|
+
`SELECT id, content FROM social_posts
|
|
333
|
+
WHERE profile_id = ? AND status = 'published' AND COALESCE(ai_labeled, 0) = 0
|
|
334
|
+
LIMIT 25`,
|
|
335
|
+
[profileId]
|
|
336
|
+
);
|
|
337
|
+
let postsLabeled = 0;
|
|
338
|
+
for (const p of unlabeled) {
|
|
339
|
+
const lbl = deterministicPostLabel(String(p.content || ''));
|
|
340
|
+
await execute(
|
|
341
|
+
`UPDATE social_posts
|
|
342
|
+
SET ai_labeled = 1, ai_label = COALESCE(ai_label, ?), updated_at = ?
|
|
343
|
+
WHERE id = ? AND profile_id = ?`,
|
|
344
|
+
[lbl, now, p.id, profileId]
|
|
345
|
+
);
|
|
346
|
+
postsLabeled++;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// 3. Daily Social Brief once per UTC day when pending activity exists
|
|
350
|
+
let digestCreated = false;
|
|
351
|
+
const dt = new Date();
|
|
352
|
+
const todayStr = dt.toISOString().slice(0, 10);
|
|
353
|
+
const lastBriefDate = await getConfigVal(profileId, 'social.last_brief_date');
|
|
354
|
+
if (lastBriefDate !== todayStr) {
|
|
355
|
+
const [c] = await query<{ pd: number; pr: number; ur: number; uh: number }>(
|
|
356
|
+
`SELECT
|
|
357
|
+
(SELECT COUNT(*) FROM social_posts WHERE profile_id = ? AND approval_status = 'pending' AND COALESCE(hidden, 0) = 0) AS pd,
|
|
358
|
+
(SELECT COUNT(*) FROM social_messages WHERE profile_id = ? AND approval_status = 'pending') AS pr,
|
|
359
|
+
(SELECT COUNT(*) FROM social_conversations WHERE profile_id = ? AND status = 'open' AND unread_count > 0) AS ur,
|
|
360
|
+
(SELECT COUNT(*) FROM social_accounts WHERE profile_id = ? AND is_active = 1 AND token_status != 'valid') AS uh`,
|
|
361
|
+
[profileId, profileId, profileId, profileId]
|
|
362
|
+
);
|
|
363
|
+
await setConfigVal(profileId, 'social.last_brief_date', todayStr);
|
|
364
|
+
const total = Number(c?.pd || 0) + Number(c?.pr || 0) + Number(c?.ur || 0) + Number(c?.uh || 0);
|
|
365
|
+
if (total > 0) {
|
|
366
|
+
await execute(
|
|
367
|
+
`INSERT OR IGNORE INTO agent_tasks
|
|
368
|
+
(id, agent_id, profile_id, title, output, status, task_type, idempotency_key, is_read, completed_at, created_at, updated_at)
|
|
369
|
+
VALUES (?, 'social', ?, ?, ?, 'completed', 'daily_brief', ?, 0, ?, ?, ?)`,
|
|
370
|
+
[
|
|
371
|
+
generateId('sbrief'),
|
|
372
|
+
profileId,
|
|
373
|
+
`Social Daily Brief — ${todayStr}`,
|
|
374
|
+
`Social Daily Brief (${todayStr}): ${c.pd} pending post draft(s), ${c.pr} pending reply draft(s), ${c.ur} unread thread(s), ${c.uh} unhealthy account(s).`,
|
|
375
|
+
`social_daily_brief:${todayStr}:${profileId}`,
|
|
376
|
+
now,
|
|
377
|
+
now,
|
|
378
|
+
now,
|
|
379
|
+
]
|
|
380
|
+
);
|
|
381
|
+
digestCreated = true;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
await setConfigVal(profileId, 'social.last_run_at', String(now));
|
|
386
|
+
return {
|
|
387
|
+
profileId,
|
|
388
|
+
skippedDisabled: false,
|
|
389
|
+
optedOutMarked,
|
|
390
|
+
prefilteredTriaged,
|
|
391
|
+
postsLabeled,
|
|
392
|
+
digestCreated,
|
|
393
|
+
};
|
|
394
|
+
}
|
package/skills/docs-cms/SKILL.md
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: docs-cms
|
|
3
|
-
description: Manage and publish technical documentation, knowledge base articles, guides, and blog posts via BusinessKit CMS tools.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Docs & CMS Publishing Skill
|
|
7
|
-
|
|
8
|
-
Use this skill when the user asks to write, edit, format, or publish articles, knowledge base docs, guides, or blog posts.
|
|
9
|
-
|
|
10
|
-
## 1. Operating Rules & Constraints
|
|
11
|
-
|
|
12
|
-
- **Category ID**:
|
|
13
|
-
- Documentation / Knowledge Base: `category_id = "cat_32"`
|
|
14
|
-
- Blog: `category_id = "cat_35"`
|
|
15
|
-
- Guides: `category_id = "cat_36"`
|
|
16
|
-
- **Doc Titles**: Strictly **$\le$ 3 words** (e.g., `Install BusinessKit`, `Visual Page Editor`, `What Are Pages`).
|
|
17
|
-
- **SEO Titles**: Prefixed with the Domain name (e.g. `Pages: Visual Site Architecture`).
|
|
18
|
-
- **Semantic HTML**:
|
|
19
|
-
- Never use Markdown syntax (`##`, `*`, ` ``` `) inside `body_html` / `content`.
|
|
20
|
-
- Never use `<h1>` tags (the page layout generates `<h1>` from the title). Start with `<h2>`.
|
|
21
|
-
- Accordions must default to collapsed (`isOpen = false`, `aria-expanded="false"`).
|
|
22
|
-
- Task lists use `<ul data-type="taskList">` with semantic `<li data-type="taskItem">`.
|
|
23
|
-
|
|
24
|
-
## 2. Tool Workflows
|
|
25
|
-
|
|
26
|
-
### A. List Existing Articles
|
|
27
|
-
```json
|
|
28
|
-
call_tool("content_list", {
|
|
29
|
-
"category_id": "cat_32"
|
|
30
|
-
})
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### B. Create / Publish Documentation Article
|
|
34
|
-
```json
|
|
35
|
-
call_tool("blog_post_create", {
|
|
36
|
-
"title": "What Are Pages",
|
|
37
|
-
"slug": "what-are-pages",
|
|
38
|
-
"category_id": "cat_32",
|
|
39
|
-
"collection_id": "col_pg_start",
|
|
40
|
-
"excerpt": "Visual website builder overview for BusinessKit.",
|
|
41
|
-
"seo_title": "Pages: Overview and Visual Site Architecture",
|
|
42
|
-
"body_html": "<h2>Overview</h2><p>Pages allows you to design storefronts...</p>",
|
|
43
|
-
"published": 1
|
|
44
|
-
})
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### C. Update Article
|
|
48
|
-
```json
|
|
49
|
-
call_tool("content_update", {
|
|
50
|
-
"id": "post_what_are_pages",
|
|
51
|
-
"content": "<h2>Updated Section</h2><p>Refined description...</p>"
|
|
52
|
-
})
|
|
53
|
-
```
|