galaxy-opc-plugin 0.2.1 → 0.2.3

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.
Files changed (57) hide show
  1. package/README.md +207 -10
  2. package/index.ts +350 -8
  3. package/openclaw.plugin.json +1 -1
  4. package/package.json +17 -3
  5. package/src/__tests__/e2e/company-lifecycle.test.ts +399 -0
  6. package/src/__tests__/integration/business-workflows.test.ts +366 -0
  7. package/src/__tests__/test-utils.ts +316 -0
  8. package/src/api/companies.ts +4 -0
  9. package/src/api/dashboard.ts +368 -16
  10. package/src/api/routes.ts +2 -2
  11. package/src/commands/opc-command.ts +422 -0
  12. package/src/db/index.ts +3 -0
  13. package/src/db/migrations.test.ts +324 -0
  14. package/src/db/migrations.ts +277 -0
  15. package/src/db/schema.ts +312 -0
  16. package/src/db/sqlite-adapter.ts +44 -2
  17. package/src/opc/accounting-parser.ts +178 -0
  18. package/src/opc/autonomy-rules.ts +132 -0
  19. package/src/opc/briefing-builder.ts +1331 -0
  20. package/src/opc/business-workflows.test.ts +535 -0
  21. package/src/opc/business-workflows.ts +325 -0
  22. package/src/opc/context-injector.ts +366 -28
  23. package/src/opc/daily-brief.ts +529 -0
  24. package/src/opc/event-triggers.ts +472 -0
  25. package/src/opc/intelligence-engine.ts +702 -0
  26. package/src/opc/milestone-detector.ts +251 -0
  27. package/src/opc/onboarding-flow.ts +332 -0
  28. package/src/opc/proactive-service.ts +466 -0
  29. package/src/opc/reminder-service.ts +4 -43
  30. package/src/opc/session-task-tracker.ts +60 -0
  31. package/src/opc/stage-detector.ts +168 -0
  32. package/src/opc/task-executor.ts +332 -0
  33. package/src/opc/task-templates.ts +179 -0
  34. package/src/tools/document-tool.ts +1176 -0
  35. package/src/tools/finance-tool.test-payment.ts +326 -0
  36. package/src/tools/finance-tool.test.ts +238 -0
  37. package/src/tools/finance-tool.ts +1574 -14
  38. package/src/tools/hr-tool.ts +10 -1
  39. package/src/tools/legal-tool.test.ts +251 -0
  40. package/src/tools/legal-tool.ts +26 -4
  41. package/src/tools/lifecycle-tool.test.ts +231 -0
  42. package/src/tools/media-tool.ts +156 -1
  43. package/src/tools/monitoring-tool.ts +134 -1
  44. package/src/tools/onboarding-tool.ts +233 -0
  45. package/src/tools/opc-tool.test.ts +250 -0
  46. package/src/tools/opc-tool.ts +251 -28
  47. package/src/tools/order-tool.ts +481 -0
  48. package/src/tools/project-tool.test.ts +218 -0
  49. package/src/tools/schemas.ts +80 -0
  50. package/src/tools/search-tool.ts +227 -0
  51. package/src/tools/smart-accounting-tool.ts +144 -0
  52. package/src/tools/staff-tool.ts +395 -2
  53. package/src/web/DASHBOARD_INTEGRATION_GUIDE.md +478 -0
  54. package/src/web/config-ui-patches.ts +389 -0
  55. package/src/web/config-ui.ts +4162 -3555
  56. package/src/web/dashboard-ui.ts +582 -0
  57. package/src/web/landing-page.ts +56 -6
@@ -0,0 +1,132 @@
1
+ /**
2
+ * 星环OPC中心 — 自主行动边界定义
3
+ *
4
+ * AI 员工在定义好的边界内自主行动,超出边界时升级给老板。
5
+ *
6
+ * needsBossApproval:
7
+ * false → 直接创建 staff_task(status='pending'),cron 触发时自动执行
8
+ * true → 创建 staff_task(status='pending_approval')+ 写入 insight 告知老板
9
+ */
10
+
11
+ export interface AutonomyRule {
12
+ trigger: string;
13
+ action: string;
14
+ needsBossApproval: boolean;
15
+ escalationMsg?: string;
16
+ }
17
+
18
+ export interface AutonomyResult {
19
+ needsBossApproval: boolean;
20
+ escalationMsg?: string;
21
+ action: string;
22
+ }
23
+
24
+ /** 每个 AI 岗位的自主权限定义 */
25
+ const AUTONOMY_RULES: Record<string, AutonomyRule[]> = {
26
+ finance: [
27
+ {
28
+ trigger: "invoice_overdue_7d",
29
+ action: "create_reminder_task",
30
+ needsBossApproval: false,
31
+ },
32
+ {
33
+ trigger: "invoice_overdue_30d",
34
+ action: "create_urgent_task",
35
+ needsBossApproval: true,
36
+ escalationMsg: "有一笔逾期30天的应收款需要决策:是否发送正式催收函?",
37
+ },
38
+ {
39
+ trigger: "monthly_close",
40
+ action: "create_monthly_report",
41
+ needsBossApproval: false,
42
+ },
43
+ {
44
+ trigger: "cashflow_anomaly",
45
+ action: "create_analysis_task",
46
+ needsBossApproval: false,
47
+ },
48
+ ],
49
+ legal: [
50
+ {
51
+ trigger: "contract_expiry_30d",
52
+ action: "create_review_task",
53
+ needsBossApproval: false,
54
+ },
55
+ {
56
+ trigger: "contract_expiry_7d",
57
+ action: "create_urgent_task",
58
+ needsBossApproval: true,
59
+ escalationMsg: "合同即将到期(7天内),需要续签决策",
60
+ },
61
+ ],
62
+ marketing: [
63
+ {
64
+ trigger: "weekly_content",
65
+ action: "create_content_task",
66
+ needsBossApproval: false,
67
+ },
68
+ {
69
+ trigger: "competitor_change",
70
+ action: "create_analysis_task",
71
+ needsBossApproval: false,
72
+ },
73
+ ],
74
+ ops: [
75
+ {
76
+ trigger: "project_overdue",
77
+ action: "create_followup_task",
78
+ needsBossApproval: false,
79
+ },
80
+ {
81
+ trigger: "task_blocked_3d",
82
+ action: "create_escalation_task",
83
+ needsBossApproval: true,
84
+ escalationMsg: "有任务阻塞超过3天,需要老板协调解决",
85
+ },
86
+ ],
87
+ hr: [
88
+ {
89
+ trigger: "contract_expiry_30d",
90
+ action: "create_renewal_task",
91
+ needsBossApproval: false,
92
+ },
93
+ ],
94
+ admin: [
95
+ {
96
+ trigger: "general_alert",
97
+ action: "create_handling_task",
98
+ needsBossApproval: false,
99
+ },
100
+ ],
101
+ };
102
+
103
+ /**
104
+ * 检查指定岗位 + 触发器的自主权限。
105
+ * 返回是否需要老板审批,以及升级消息。
106
+ */
107
+ export function checkAutonomy(staffRole: string, trigger: string): AutonomyResult {
108
+ const rules = AUTONOMY_RULES[staffRole];
109
+ if (!rules) {
110
+ // 未定义的岗位,默认不需要审批
111
+ return { needsBossApproval: false, action: "create_task" };
112
+ }
113
+
114
+ const rule = rules.find(r => r.trigger === trigger);
115
+ if (!rule) {
116
+ // 未定义的触发器,默认不需要审批
117
+ return { needsBossApproval: false, action: "create_task" };
118
+ }
119
+
120
+ return {
121
+ needsBossApproval: rule.needsBossApproval,
122
+ escalationMsg: rule.escalationMsg,
123
+ action: rule.action,
124
+ };
125
+ }
126
+
127
+ /**
128
+ * 获取所有自主行动规则(用于管理界面展示)。
129
+ */
130
+ export function getAllAutonomyRules(): Record<string, AutonomyRule[]> {
131
+ return AUTONOMY_RULES;
132
+ }