team-anya-cli 0.1.0

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 (163) hide show
  1. package/README.md +38 -0
  2. package/anya/prompts/execution-guides/git-delivery.md +38 -0
  3. package/anya/prompts/execution-guides/testing-and-self-heal.md +28 -0
  4. package/anya/prompts/protocols/brief-assembly.md +55 -0
  5. package/anya/prompts/protocols/report.md +175 -0
  6. package/anya/prompts/protocols/review.md +90 -0
  7. package/anya/prompts/task-claude-md.template.md +32 -0
  8. package/apps/server/dist/broker/cc-broker.js +257 -0
  9. package/apps/server/dist/cli.js +296 -0
  10. package/apps/server/dist/config.js +76 -0
  11. package/apps/server/dist/daemon.js +51 -0
  12. package/apps/server/dist/gateway/chat-sync.js +135 -0
  13. package/apps/server/dist/gateway/command-router.js +114 -0
  14. package/apps/server/dist/gateway/commands/cancel.js +32 -0
  15. package/apps/server/dist/gateway/commands/help.js +16 -0
  16. package/apps/server/dist/gateway/commands/index.js +26 -0
  17. package/apps/server/dist/gateway/commands/restart.js +34 -0
  18. package/apps/server/dist/gateway/commands/status.js +34 -0
  19. package/apps/server/dist/gateway/commands/tasks.js +33 -0
  20. package/apps/server/dist/gateway/feishu-sender.js +346 -0
  21. package/apps/server/dist/gateway/feishu-ws.js +254 -0
  22. package/apps/server/dist/gateway/http.js +994 -0
  23. package/apps/server/dist/gateway/media-downloader.js +149 -0
  24. package/apps/server/dist/gateway/message-events.js +10 -0
  25. package/apps/server/dist/gateway/message-intake.js +50 -0
  26. package/apps/server/dist/gateway/message-queue.js +104 -0
  27. package/apps/server/dist/gateway/session-reader.js +142 -0
  28. package/apps/server/dist/gateway/ws-push.js +115 -0
  29. package/apps/server/dist/loid/brain.js +104 -0
  30. package/apps/server/dist/loid/clarifier.js +162 -0
  31. package/apps/server/dist/loid/context-builder.js +413 -0
  32. package/apps/server/dist/loid/mcp-server.js +104 -0
  33. package/apps/server/dist/loid/memory-settler.js +189 -0
  34. package/apps/server/dist/loid/opportunity-manager.js +148 -0
  35. package/apps/server/dist/loid/profile-updater.js +179 -0
  36. package/apps/server/dist/loid/reporter.js +148 -0
  37. package/apps/server/dist/loid/schemas.js +117 -0
  38. package/apps/server/dist/loid/self-calibrator.js +314 -0
  39. package/apps/server/dist/loid/session-manager.js +217 -0
  40. package/apps/server/dist/loid/session.js +271 -0
  41. package/apps/server/dist/loid/worktree-manager.js +191 -0
  42. package/apps/server/dist/main.js +337 -0
  43. package/apps/server/dist/tracing/index.js +2 -0
  44. package/apps/server/dist/tracing/trace-context.js +92 -0
  45. package/apps/server/dist/types/message.js +2 -0
  46. package/apps/server/dist/yor/yor-mcp-server.js +104 -0
  47. package/apps/server/dist/yor/yor-orchestrator.js +233 -0
  48. package/apps/web/dist/assets/index-CHIT0Dya.css +1 -0
  49. package/apps/web/dist/assets/index-CJzAjoVH.js +798 -0
  50. package/apps/web/dist/index.html +13 -0
  51. package/package.json +42 -0
  52. package/packages/cc-client/dist/claude-code-backend.js +664 -0
  53. package/packages/cc-client/dist/index.js +2 -0
  54. package/packages/cc-client/package.json +11 -0
  55. package/packages/core/dist/constants.js +59 -0
  56. package/packages/core/dist/errors.js +35 -0
  57. package/packages/core/dist/index.js +7 -0
  58. package/packages/core/dist/office-init.js +97 -0
  59. package/packages/core/dist/scope/checker.js +114 -0
  60. package/packages/core/dist/scope/defaults.js +40 -0
  61. package/packages/core/dist/scope/index.js +3 -0
  62. package/packages/core/dist/state-machine.js +85 -0
  63. package/packages/core/dist/types/audit.js +12 -0
  64. package/packages/core/dist/types/backend.js +2 -0
  65. package/packages/core/dist/types/commitment.js +17 -0
  66. package/packages/core/dist/types/communication.js +18 -0
  67. package/packages/core/dist/types/index.js +8 -0
  68. package/packages/core/dist/types/opportunity.js +27 -0
  69. package/packages/core/dist/types/org.js +26 -0
  70. package/packages/core/dist/types/task.js +46 -0
  71. package/packages/core/package.json +10 -0
  72. package/packages/db/dist/client.js +69 -0
  73. package/packages/db/dist/index.js +603 -0
  74. package/packages/db/dist/schema/audit-events.js +13 -0
  75. package/packages/db/dist/schema/cc-sessions.js +14 -0
  76. package/packages/db/dist/schema/chats.js +33 -0
  77. package/packages/db/dist/schema/commitments.js +18 -0
  78. package/packages/db/dist/schema/communication-events.js +14 -0
  79. package/packages/db/dist/schema/index.js +12 -0
  80. package/packages/db/dist/schema/message-log.js +20 -0
  81. package/packages/db/dist/schema/opportunities.js +23 -0
  82. package/packages/db/dist/schema/org.js +36 -0
  83. package/packages/db/dist/schema/projects.js +23 -0
  84. package/packages/db/dist/schema/tasks.js +46 -0
  85. package/packages/db/dist/schema/trace-spans.js +19 -0
  86. package/packages/db/package.json +12 -0
  87. package/packages/db/src/migrations/0000_simple_magneto.sql +148 -0
  88. package/packages/db/src/migrations/0001_nifty_morph.sql +42 -0
  89. package/packages/db/src/migrations/0002_common_joshua_kane.sql +20 -0
  90. package/packages/db/src/migrations/0003_add_cc_sessions.sql +13 -0
  91. package/packages/db/src/migrations/0004_jittery_triathlon.sql +1 -0
  92. package/packages/db/src/migrations/meta/0000_snapshot.json +987 -0
  93. package/packages/db/src/migrations/meta/0001_snapshot.json +1280 -0
  94. package/packages/db/src/migrations/meta/0002_snapshot.json +1417 -0
  95. package/packages/db/src/migrations/meta/0004_snapshot.json +1505 -0
  96. package/packages/db/src/migrations/meta/_journal.json +41 -0
  97. package/packages/mcp-tools/dist/index.js +41 -0
  98. package/packages/mcp-tools/dist/layer1/audit-append.js +38 -0
  99. package/packages/mcp-tools/dist/layer1/audit-query.js +51 -0
  100. package/packages/mcp-tools/dist/layer1/memory-brief.js +168 -0
  101. package/packages/mcp-tools/dist/layer1/memory-context.js +124 -0
  102. package/packages/mcp-tools/dist/layer1/memory-digest.js +126 -0
  103. package/packages/mcp-tools/dist/layer1/memory-forget.js +108 -0
  104. package/packages/mcp-tools/dist/layer1/memory-learn.js +63 -0
  105. package/packages/mcp-tools/dist/layer1/memory-recall.js +287 -0
  106. package/packages/mcp-tools/dist/layer1/memory-reflect.js +80 -0
  107. package/packages/mcp-tools/dist/layer1/memory-remember.js +119 -0
  108. package/packages/mcp-tools/dist/layer1/memory-search.js +263 -0
  109. package/packages/mcp-tools/dist/layer1/memory-write.js +21 -0
  110. package/packages/mcp-tools/dist/layer1/org-lookup.js +47 -0
  111. package/packages/mcp-tools/dist/layer1/project-get.js +28 -0
  112. package/packages/mcp-tools/dist/layer1/project-list.js +20 -0
  113. package/packages/mcp-tools/dist/layer1/report-daily.js +68 -0
  114. package/packages/mcp-tools/dist/layer1/task-get.js +29 -0
  115. package/packages/mcp-tools/dist/layer1/task-update.js +34 -0
  116. package/packages/mcp-tools/dist/layer2/loid/decision-log.js +15 -0
  117. package/packages/mcp-tools/dist/layer2/loid/decision-no-action.js +15 -0
  118. package/packages/mcp-tools/dist/layer2/loid/delivery-create-pr.js +30 -0
  119. package/packages/mcp-tools/dist/layer2/loid/delivery-share.js +12 -0
  120. package/packages/mcp-tools/dist/layer2/loid/delivery-submit.js +77 -0
  121. package/packages/mcp-tools/dist/layer2/loid/delivery-upload.js +18 -0
  122. package/packages/mcp-tools/dist/layer2/loid/project-remove.js +16 -0
  123. package/packages/mcp-tools/dist/layer2/loid/project-upsert.js +33 -0
  124. package/packages/mcp-tools/dist/layer2/loid/task-dispatch.js +177 -0
  125. package/packages/mcp-tools/dist/layer2/loid/task-lookup.js +38 -0
  126. package/packages/mcp-tools/dist/layer2/loid/yor-approve.js +8 -0
  127. package/packages/mcp-tools/dist/layer2/loid/yor-kill.js +7 -0
  128. package/packages/mcp-tools/dist/layer2/loid/yor-rework.js +7 -0
  129. package/packages/mcp-tools/dist/layer2/loid/yor-spawn.js +15 -0
  130. package/packages/mcp-tools/dist/layer2/loid/yor-status.js +8 -0
  131. package/packages/mcp-tools/dist/layer2/yor/task-block.js +11 -0
  132. package/packages/mcp-tools/dist/layer2/yor/task-deliver.js +35 -0
  133. package/packages/mcp-tools/dist/layer2/yor/task-progress.js +21 -0
  134. package/packages/mcp-tools/dist/layer3/adapters/feishu-adapter.js +191 -0
  135. package/packages/mcp-tools/dist/layer3/adapters/types.js +28 -0
  136. package/packages/mcp-tools/dist/layer3/channel-receive.js +11 -0
  137. package/packages/mcp-tools/dist/layer3/channel-send.js +90 -0
  138. package/packages/mcp-tools/dist/layer3/file-upload.js +44 -0
  139. package/packages/mcp-tools/dist/registry.js +779 -0
  140. package/packages/mcp-tools/package.json +13 -0
  141. package/workspace/.claude/settings.local.json +9 -0
  142. package/workspace/.mcp.json +12 -0
  143. package/workspace/CHARTER.md +73 -0
  144. package/workspace/CLAUDE.md +49 -0
  145. package/workspace/PROTOCOL.md +126 -0
  146. package/workspace/TOOLS.md +464 -0
  147. package/workspace/audit/.gitkeep +0 -0
  148. package/workspace/loid/CLAUDE.md +12 -0
  149. package/workspace/loid/PLAYBOOK.md +198 -0
  150. package/workspace/loid/PROFILE.md +78 -0
  151. package/workspace/memory/commitments/.gitkeep +0 -0
  152. package/workspace/memory/execution/.gitkeep +0 -0
  153. package/workspace/memory/people/.gitkeep +0 -0
  154. package/workspace/memory/projects/.gitkeep +0 -0
  155. package/workspace/memory/self/.gitkeep +0 -0
  156. package/workspace/reference/identity/.gitkeep +0 -0
  157. package/workspace/reference/org/escalation.yaml +24 -0
  158. package/workspace/reference/org/ownership.yaml +28 -0
  159. package/workspace/reports/.gitkeep +0 -0
  160. package/workspace/yor/CLAUDE.md +22 -0
  161. package/workspace/yor/PLAYBOOK.md +73 -0
  162. package/workspace/yor/PROFILE.md +52 -0
  163. package/workspace/yor/SELF-HEAL.md +39 -0
@@ -0,0 +1,59 @@
1
+ // 任务状态枚举
2
+ export const TaskStatus = {
3
+ NEW: 'NEW',
4
+ NEED_CLARIFICATION: 'NEED_CLARIFICATION',
5
+ READY: 'READY',
6
+ IN_PROGRESS: 'IN_PROGRESS',
7
+ DELIVERING: 'DELIVERING',
8
+ DONE: 'DONE',
9
+ BLOCKED: 'BLOCKED',
10
+ CANCELLED: 'CANCELLED',
11
+ };
12
+ /**
13
+ * @deprecated MCP v3 不再使用 Triage L0-L3 分级。
14
+ * Loid 改为 SOUL 驱动 + 硬约束模式。
15
+ * 保留此常量仅为向后兼容 intent-classifier 和 opportunity-manager。
16
+ */
17
+ export const IntentLevel = {
18
+ L0_NOISE: 0,
19
+ L1_CONTEXT: 1,
20
+ L2_OPPORTUNITY: 2,
21
+ L3_COMMITMENT: 3,
22
+ };
23
+ // 承诺状态
24
+ export const CommitmentStatus = {
25
+ ACTIVE: 'active',
26
+ FULFILLED: 'fulfilled',
27
+ BROKEN: 'broken',
28
+ CANCELLED: 'cancelled',
29
+ };
30
+ // 机会状态
31
+ export const OpportunityStatus = {
32
+ DETECTED: 'detected',
33
+ CONFIRMED: 'confirmed',
34
+ SKIPPED: 'skipped',
35
+ REJECTED: 'rejected',
36
+ CONVERTED: 'converted',
37
+ };
38
+ // 连接状态
39
+ export const ConnectionState = {
40
+ DISCONNECTED: 'disconnected',
41
+ CONNECTING: 'connecting',
42
+ CONNECTED: 'connected',
43
+ EXECUTING: 'executing',
44
+ ERROR: 'error',
45
+ };
46
+ // 任务 ID 前缀
47
+ export const TASK_ID_PREFIX = 'ANYA';
48
+ // 默认配置
49
+ export const DEFAULTS = {
50
+ MAX_RETRIES: 3,
51
+ MAX_YOR_CONCURRENCY: 3,
52
+ HEARTBEAT_INTERVAL_MS: 15_000,
53
+ RECONNECT_BASE_DELAY_MS: 1_000,
54
+ RECONNECT_MAX_RETRIES: 3,
55
+ CONNECT_TIMEOUT_MS: 30_000,
56
+ IDLE_TIMEOUT_MS: 300_000,
57
+ TOTAL_TIMEOUT_MS: 3_600_000,
58
+ };
59
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1,35 @@
1
+ export class AnyaError extends Error {
2
+ code;
3
+ details;
4
+ constructor(message, code, details) {
5
+ super(message);
6
+ this.code = code;
7
+ this.details = details;
8
+ this.name = 'AnyaError';
9
+ }
10
+ }
11
+ export class InvalidTransitionError extends AnyaError {
12
+ constructor(from, to) {
13
+ super(`非法状态转换: ${from} → ${to}`, 'INVALID_TRANSITION', { from, to });
14
+ this.name = 'InvalidTransitionError';
15
+ }
16
+ }
17
+ export class TaskNotFoundError extends AnyaError {
18
+ constructor(taskId) {
19
+ super(`任务不存在: ${taskId}`, 'TASK_NOT_FOUND', { taskId });
20
+ this.name = 'TaskNotFoundError';
21
+ }
22
+ }
23
+ export class StatusConflictError extends AnyaError {
24
+ constructor(taskId, expected, actual) {
25
+ super(`状态冲突: 任务 ${taskId} 期望 ${expected},实际 ${actual}`, 'STATUS_CONFLICT', { taskId, expected, actual });
26
+ this.name = 'StatusConflictError';
27
+ }
28
+ }
29
+ export class ScopeDeniedError extends AnyaError {
30
+ constructor(tool, reason) {
31
+ super(`SCOPE 拒绝: ${tool} - ${reason}`, 'SCOPE_DENIED', { tool, reason });
32
+ this.name = 'ScopeDeniedError';
33
+ }
34
+ }
35
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,7 @@
1
+ export * from './types/index.js';
2
+ export * from './constants.js';
3
+ export * from './state-machine.js';
4
+ export * from './errors.js';
5
+ export * from './office-init.js';
6
+ export * from './scope/index.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,97 @@
1
+ import { mkdir, copyFile, stat } from 'node:fs/promises';
2
+ import { join, dirname } from 'node:path';
3
+ /** 每次启动强制覆盖的文件(提示词/协议,必须与 workspace 保持同步) */
4
+ const ALWAYS_OVERWRITE_FILES = [
5
+ 'CLAUDE.md',
6
+ 'CHARTER.md',
7
+ 'PROTOCOL.md',
8
+ 'TOOLS.md',
9
+ 'loid/CLAUDE.md',
10
+ 'loid/PROFILE.md',
11
+ 'loid/PLAYBOOK.md',
12
+ 'yor/CLAUDE.md',
13
+ 'yor/PROFILE.md',
14
+ 'yor/PLAYBOOK.md',
15
+ 'yor/SELF-HEAL.md',
16
+ ];
17
+ /** 仅当目标不存在时才复制的文件(配置/数据,运行时可能被修改) */
18
+ const COPY_IF_MISSING_FILES = [
19
+ '.mcp.json',
20
+ '.claude/settings.local.json',
21
+ 'reference/org/ownership.yaml',
22
+ 'reference/org/escalation.yaml',
23
+ ];
24
+ /** 需要确保存在的空目录 */
25
+ const REQUIRED_DIRS = [
26
+ 'memory/people',
27
+ 'memory/projects',
28
+ 'memory/execution',
29
+ 'memory/commitments',
30
+ 'memory/self',
31
+ 'reference/org',
32
+ 'reference/identity',
33
+ 'audit',
34
+ 'reports',
35
+ 'yor',
36
+ 'loid',
37
+ '.claude',
38
+ ];
39
+ async function exists(path) {
40
+ try {
41
+ await stat(path);
42
+ return true;
43
+ }
44
+ catch {
45
+ return false;
46
+ }
47
+ }
48
+ /**
49
+ * 确保 office 目录存在并包含所有必需的模板文件和子目录。
50
+ * - 提示词/协议文件(.md):每次启动强制覆盖,保证与 workspace 同步
51
+ * - 配置/数据文件:仅补缺,不覆盖运行时修改
52
+ */
53
+ export async function ensureOffice(officePath, templateDir, logger) {
54
+ const isNew = !(await exists(officePath));
55
+ // 创建所有必需目录
56
+ for (const dir of REQUIRED_DIRS) {
57
+ await mkdir(join(officePath, dir), { recursive: true });
58
+ }
59
+ let overwritten = 0;
60
+ let created = 0;
61
+ let skipped = 0;
62
+ // 强制覆盖提示词/协议文件
63
+ for (const file of ALWAYS_OVERWRITE_FILES) {
64
+ const src = join(templateDir, file);
65
+ const dest = join(officePath, file);
66
+ if (!(await exists(src))) {
67
+ logger?.info(`模板文件不存在,跳过: ${file}`);
68
+ continue;
69
+ }
70
+ await mkdir(dirname(dest), { recursive: true });
71
+ await copyFile(src, dest);
72
+ overwritten++;
73
+ }
74
+ // 仅补缺的配置/数据文件
75
+ for (const file of COPY_IF_MISSING_FILES) {
76
+ const src = join(templateDir, file);
77
+ const dest = join(officePath, file);
78
+ if (await exists(dest)) {
79
+ skipped++;
80
+ continue;
81
+ }
82
+ if (!(await exists(src))) {
83
+ logger?.info(`模板文件不存在,跳过: ${file}`);
84
+ continue;
85
+ }
86
+ await mkdir(dirname(dest), { recursive: true });
87
+ await copyFile(src, dest);
88
+ created++;
89
+ }
90
+ if (isNew) {
91
+ logger?.info(`Office 目录已创建: ${officePath} (${overwritten + created} 个文件)`);
92
+ }
93
+ else {
94
+ logger?.info(`Office 已同步: ${overwritten} 个提示词覆盖, ${created} 个配置补全, ${skipped} 个配置跳过`);
95
+ }
96
+ }
97
+ //# sourceMappingURL=office-init.js.map
@@ -0,0 +1,114 @@
1
+ import { DEFAULT_FORBIDDEN_COMMANDS, DEFAULT_FORBIDDEN_PATHS } from './defaults.js';
2
+ /**
3
+ * 默认 scope(无特定限制,仅启用默认安全守卫)
4
+ */
5
+ export const DEFAULT_SCOPE = {
6
+ allowedPaths: ['**'],
7
+ forbiddenPaths: [],
8
+ allowedCommands: ['**'],
9
+ forbiddenCommands: [],
10
+ };
11
+ /**
12
+ * SCOPE 安全检查器
13
+ *
14
+ * 在协议层拦截工具请求,不依赖提示词约束。
15
+ * Claude Code 每次调用工具前都会发送 control_request,
16
+ * ScopeChecker 在此处做硬拦截。
17
+ */
18
+ export class ScopeChecker {
19
+ scope;
20
+ constructor(scope = DEFAULT_SCOPE) {
21
+ this.scope = scope;
22
+ }
23
+ /**
24
+ * 检查工具请求是否被允许
25
+ */
26
+ check(req) {
27
+ // 文件写入检查
28
+ if (this.isFileWriteTool(req.toolName)) {
29
+ const filePath = (req.input.file_path ?? req.input.path ?? '');
30
+ if (!filePath) {
31
+ return this.allow(req.requestId);
32
+ }
33
+ // 先检查默认禁止路径
34
+ if (this.matchesAnyGlob(filePath, DEFAULT_FORBIDDEN_PATHS)) {
35
+ return this.deny(req.requestId, `默认禁止路径: ${filePath}`);
36
+ }
37
+ // 再检查 task scope 的禁止路径
38
+ if (this.matchesAnyGlob(filePath, this.scope.forbiddenPaths)) {
39
+ return this.deny(req.requestId, `任务禁止路径: ${filePath}`);
40
+ }
41
+ // 检查是否在允许路径中
42
+ if (this.scope.allowedPaths.length > 0 &&
43
+ !this.scope.allowedPaths.includes('**') &&
44
+ !this.matchesAnyGlob(filePath, this.scope.allowedPaths)) {
45
+ return this.deny(req.requestId, `路径不在允许范围: ${filePath}`);
46
+ }
47
+ }
48
+ // 命令执行检查
49
+ if (req.toolName === 'Bash') {
50
+ const command = (req.input.command ?? '');
51
+ if (!command) {
52
+ return this.allow(req.requestId);
53
+ }
54
+ // 先检查默认禁止命令
55
+ if (this.matchesAnyRegex(command, DEFAULT_FORBIDDEN_COMMANDS)) {
56
+ return this.deny(req.requestId, `默认禁止命令: ${command}`);
57
+ }
58
+ // 再检查 task scope 的禁止命令
59
+ const customForbidden = this.scope.forbiddenCommands.map(p => new RegExp(p));
60
+ if (this.matchesAnyRegex(command, customForbidden)) {
61
+ return this.deny(req.requestId, `任务禁止命令: ${command}`);
62
+ }
63
+ }
64
+ return this.allow(req.requestId);
65
+ }
66
+ /**
67
+ * 创建一个绑定了当前 scope 的 onToolRequest handler
68
+ */
69
+ createHandler() {
70
+ return async (req) => this.check(req);
71
+ }
72
+ // ── 私有方法 ──
73
+ isFileWriteTool(toolName) {
74
+ return ['Write', 'Edit', 'NotebookEdit'].includes(toolName);
75
+ }
76
+ matchesAnyGlob(path, patterns) {
77
+ for (const pattern of patterns) {
78
+ if (this.globMatch(path, pattern))
79
+ return true;
80
+ }
81
+ return false;
82
+ }
83
+ matchesAnyRegex(text, patterns) {
84
+ for (const pattern of patterns) {
85
+ if (pattern.test(text))
86
+ return true;
87
+ }
88
+ return false;
89
+ }
90
+ /**
91
+ * 简单 glob 匹配
92
+ * 支持: * (匹配非/字符), ** (匹配任意字符含/), ? (匹配单字符)
93
+ */
94
+ globMatch(text, pattern) {
95
+ // 将 glob 转为正则
96
+ let regex = pattern
97
+ .replace(/\*\*/g, '<<DOUBLESTAR>>')
98
+ .replace(/\*/g, '[^/]*')
99
+ .replace(/<<DOUBLESTAR>>/g, '.*')
100
+ .replace(/\?/g, '.');
101
+ // 如果 pattern 不以 / 开头,允许匹配任意前缀
102
+ if (!pattern.startsWith('/') && !pattern.startsWith('*')) {
103
+ regex = '(.*/)?' + regex;
104
+ }
105
+ return new RegExp(`^${regex}$`).test(text);
106
+ }
107
+ allow(requestId) {
108
+ return { requestId, behavior: 'allow' };
109
+ }
110
+ deny(requestId, reason) {
111
+ return { requestId, behavior: 'deny', reason };
112
+ }
113
+ }
114
+ //# sourceMappingURL=checker.js.map
@@ -0,0 +1,40 @@
1
+ /**
2
+ * 默认禁止命令正则列表
3
+ * 即使 TaskScope 未配置 forbiddenCommands,这些命令也会被拦截
4
+ */
5
+ export const DEFAULT_FORBIDDEN_COMMANDS = [
6
+ /\brm\s+-[rf]{1,2}\b/, // rm -rf
7
+ /\brm\s+-[rf]{1,2}\s+\//, // rm -rf /
8
+ /\bgit\s+push\s+--force\b/, // force push
9
+ /\bgit\s+push\b.*\b(main|master)\b/, // 直接推主分支
10
+ /\bgit\s+reset\s+--hard\b/, // hard reset
11
+ /\bgit\s+clean\s+-[fd]{1,2}\b/, // git clean
12
+ /\b(DROP|TRUNCATE)\s+/i, // 危险 SQL DDL
13
+ /\bDELETE\s+FROM\b/i, // 危险 SQL DML(无 WHERE)
14
+ /\b(shutdown|reboot|poweroff|halt)\b/, // 系统命令
15
+ /\bdd\s+if=/, // 磁盘操作
16
+ /:\(\)\s*\{.*\};\s*:/, // fork bomb
17
+ /\bcurl\b.*\|\s*\b(bash|sh)\b/, // curl | bash
18
+ /\bchmod\s+777\b/, // 过度开放权限
19
+ /\bsudo\b/, // sudo
20
+ ];
21
+ /**
22
+ * 默认禁止写入路径
23
+ * 保护系统和敏感文件
24
+ */
25
+ export const DEFAULT_FORBIDDEN_PATHS = [
26
+ '**/.env',
27
+ '**/.env.*',
28
+ '**/credentials*',
29
+ '**/secrets*',
30
+ '**/*.pem',
31
+ '**/*.key',
32
+ '**/id_rsa*',
33
+ '/etc/**',
34
+ '/usr/**',
35
+ '/var/**',
36
+ '**/node_modules/**',
37
+ '**/.git/objects/**',
38
+ '**/.git/refs/**',
39
+ ];
40
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1,3 @@
1
+ export { ScopeChecker, DEFAULT_SCOPE } from './checker.js';
2
+ export { DEFAULT_FORBIDDEN_COMMANDS, DEFAULT_FORBIDDEN_PATHS } from './defaults.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,85 @@
1
+ import { TaskStatus, TASK_ID_PREFIX } from './constants.js';
2
+ import { InvalidTransitionError } from './errors.js';
3
+ /**
4
+ * 合法状态转换表
5
+ * 定义了每个状态可以转换到哪些目标状态
6
+ */
7
+ export const VALID_TRANSITIONS = {
8
+ [TaskStatus.NEW]: [
9
+ TaskStatus.NEED_CLARIFICATION,
10
+ TaskStatus.READY,
11
+ TaskStatus.BLOCKED,
12
+ TaskStatus.CANCELLED,
13
+ ],
14
+ [TaskStatus.NEED_CLARIFICATION]: [
15
+ TaskStatus.READY,
16
+ TaskStatus.CANCELLED,
17
+ ],
18
+ [TaskStatus.READY]: [
19
+ TaskStatus.IN_PROGRESS,
20
+ TaskStatus.BLOCKED,
21
+ TaskStatus.CANCELLED,
22
+ ],
23
+ [TaskStatus.IN_PROGRESS]: [
24
+ TaskStatus.DELIVERING,
25
+ TaskStatus.BLOCKED,
26
+ TaskStatus.CANCELLED,
27
+ ],
28
+ [TaskStatus.DELIVERING]: [
29
+ TaskStatus.DONE,
30
+ TaskStatus.IN_PROGRESS,
31
+ TaskStatus.CANCELLED,
32
+ ],
33
+ [TaskStatus.BLOCKED]: [
34
+ TaskStatus.READY,
35
+ TaskStatus.CANCELLED,
36
+ ],
37
+ [TaskStatus.DONE]: [],
38
+ [TaskStatus.CANCELLED]: [],
39
+ };
40
+ /**
41
+ * 校验状态转换是否合法
42
+ */
43
+ export function validateTransition(from, to) {
44
+ const allowed = VALID_TRANSITIONS[from];
45
+ if (!allowed)
46
+ return false;
47
+ return allowed.includes(to);
48
+ }
49
+ /**
50
+ * 校验状态转换,非法则抛异常
51
+ */
52
+ export function assertTransition(from, to) {
53
+ if (!validateTransition(from, to)) {
54
+ throw new InvalidTransitionError(from, to);
55
+ }
56
+ }
57
+ /**
58
+ * 判断是否为终态(不可再转换)
59
+ */
60
+ export function isTerminalStatus(status) {
61
+ return VALID_TRANSITIONS[status]?.length === 0;
62
+ }
63
+ /**
64
+ * 生成任务 ID
65
+ * 格式: ANYA-YYYYMMDD-NNN
66
+ */
67
+ export function generateTaskId(sequence) {
68
+ const now = new Date();
69
+ const dateStr = now.toISOString().slice(0, 10).replace(/-/g, '');
70
+ const seqStr = String(sequence).padStart(3, '0');
71
+ return `${TASK_ID_PREFIX}-${dateStr}-${seqStr}`;
72
+ }
73
+ /**
74
+ * 解析任务 ID 中的日期和序号
75
+ */
76
+ export function parseTaskId(taskId) {
77
+ const match = taskId.match(/^ANYA-(\d{8})-(\d{3})$/);
78
+ if (!match)
79
+ return null;
80
+ return {
81
+ date: match[1],
82
+ sequence: parseInt(match[2], 10),
83
+ };
84
+ }
85
+ //# sourceMappingURL=state-machine.js.map
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ export const auditEventSchema = z.object({
3
+ id: z.number().optional(),
4
+ event_type: z.string(),
5
+ actor: z.string(),
6
+ task_id: z.string().nullable().optional(),
7
+ summary: z.string(),
8
+ detail: z.record(z.unknown()).nullable().optional(),
9
+ file_ref: z.string().nullable().optional(),
10
+ created_at: z.string().datetime().optional(),
11
+ });
12
+ //# sourceMappingURL=audit.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=backend.js.map
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @deprecated 此模块已废弃,改为 Agent 自主判断/使用 memory 系统。
3
+ * 保留此文件仅为兼容历史数据,新代码请勿使用。
4
+ */
5
+ import { z } from 'zod';
6
+ import { CommitmentStatus } from '../constants.js';
7
+ export const commitmentSchema = z.object({
8
+ id: z.number().optional(),
9
+ task_id: z.string(),
10
+ promised_to: z.string(),
11
+ promise: z.string(),
12
+ deadline: z.string().datetime().nullable().optional(),
13
+ status: z.nativeEnum(CommitmentStatus).default('active'),
14
+ break_reason: z.string().nullable().optional(),
15
+ promised_at: z.string().datetime().optional(),
16
+ });
17
+ //# sourceMappingURL=commitment.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @deprecated 此模块已废弃,改为 Agent 自主判断/使用 memory 系统。
3
+ * 保留此文件仅为兼容历史数据,新代码请勿使用。
4
+ */
5
+ import { z } from 'zod';
6
+ import { IntentLevel } from '../constants.js';
7
+ export const communicationEventSchema = z.object({
8
+ id: z.number().optional(),
9
+ source_type: z.enum(['feishu', 'file']),
10
+ source_ref: z.string().nullable().optional(),
11
+ intent_level: z.nativeEnum(IntentLevel),
12
+ sender: z.string().nullable().optional(),
13
+ summary: z.string(),
14
+ raw_content_path: z.string().nullable().optional(),
15
+ opportunity_id: z.string().nullable().optional(),
16
+ created_at: z.string().datetime().optional(),
17
+ });
18
+ //# sourceMappingURL=communication.js.map
@@ -0,0 +1,8 @@
1
+ export * from './task.js';
2
+ export * from './commitment.js';
3
+ export * from './opportunity.js';
4
+ export * from './audit.js';
5
+ export * from './communication.js';
6
+ export * from './org.js';
7
+ export * from './backend.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @deprecated 此模块已废弃,改为 Agent 自主判断/使用 memory 系统。
3
+ * 保留此文件仅为兼容历史数据,新代码请勿使用。
4
+ */
5
+ import { z } from 'zod';
6
+ import { OpportunityStatus } from '../constants.js';
7
+ export const opportunityScoreSchema = z.object({
8
+ impact: z.number().min(0).max(1),
9
+ urgency: z.number().min(0).max(1),
10
+ feasibility: z.number().min(0).max(1),
11
+ permission: z.number().min(0).max(1),
12
+ });
13
+ export const opportunitySchema = z.object({
14
+ id: z.string(),
15
+ status: z.nativeEnum(OpportunityStatus).default('detected'),
16
+ source_ref: z.string().nullable().optional(),
17
+ summary: z.string(),
18
+ score_impact: z.number().nullable().optional(),
19
+ score_urgency: z.number().nullable().optional(),
20
+ score_feasibility: z.number().nullable().optional(),
21
+ score_permission: z.number().nullable().optional(),
22
+ total_score: z.number().nullable().optional(),
23
+ converted_task_id: z.string().nullable().optional(),
24
+ detected_at: z.string().datetime().optional(),
25
+ claimed_at: z.string().datetime().nullable().optional(),
26
+ });
27
+ //# sourceMappingURL=opportunity.js.map
@@ -0,0 +1,26 @@
1
+ import { z } from 'zod';
2
+ export const orgMemberSchema = z.object({
3
+ member_id: z.string(),
4
+ name: z.string(),
5
+ role: z.string().nullable().optional(),
6
+ team: z.string().nullable().optional(),
7
+ timezone: z.string().nullable().optional(),
8
+ profile_path: z.string().nullable().optional(),
9
+ response_pattern: z.string().nullable().optional(),
10
+ updated_at: z.string().datetime().optional(),
11
+ });
12
+ export const ownershipSchema = z.object({
13
+ id: z.number().optional(),
14
+ scope: z.enum(['repo', 'module']),
15
+ target: z.string(),
16
+ member_id: z.string(),
17
+ role: z.string().default('owner'),
18
+ });
19
+ export const escalationRuleSchema = z.object({
20
+ id: z.number().optional(),
21
+ scope: z.string().default('global'),
22
+ after_minutes: z.number(),
23
+ action: z.enum(['notify', 'escalate']),
24
+ targets: z.array(z.string()),
25
+ });
26
+ //# sourceMappingURL=org.js.map
@@ -0,0 +1,46 @@
1
+ import { z } from 'zod';
2
+ import { TaskStatus } from '../constants.js';
3
+ // ── Zod Schemas ──
4
+ export const taskSourceSchema = z.object({
5
+ type: z.enum(['file', 'feishu', 'meeting_note', 'manual']),
6
+ ref: z.string().optional(),
7
+ received_at: z.string().datetime().optional(),
8
+ });
9
+ export const clarificationSchema = z.object({
10
+ id: z.number().optional(),
11
+ question: z.string(),
12
+ answer: z.string().nullable().optional(),
13
+ asked_by: z.string().default('loid'),
14
+ answered_by: z.string().nullable().optional(),
15
+ asked_at: z.string().datetime().optional(),
16
+ answered_at: z.string().datetime().nullable().optional(),
17
+ });
18
+ export const taskSchema = z.object({
19
+ task_id: z.string(),
20
+ title: z.string(),
21
+ status: z.nativeEnum(TaskStatus),
22
+ // 来源
23
+ source_type: z.enum(['file', 'feishu', 'meeting_note', 'manual']),
24
+ source_ref: z.string().nullable().optional(),
25
+ // 需求定义
26
+ objective: z.string().nullable().optional(),
27
+ acceptance_criteria: z.array(z.string()).optional(),
28
+ context: z.string().nullable().optional(),
29
+ // 执行指引
30
+ execution_guidance: z.string().nullable().optional(),
31
+ // 执行信息
32
+ project_id: z.string().nullable().optional(),
33
+ assignee: z.string().nullable().optional(),
34
+ deliverable_summary: z.string().nullable().optional(),
35
+ // 重试与阻塞
36
+ retry_count: z.number().default(0),
37
+ max_retries: z.number().default(3),
38
+ blocked_reason: z.string().nullable().optional(),
39
+ blocked_since: z.string().datetime().nullable().optional(),
40
+ // 文件路径
41
+ workspace_path: z.string().nullable().optional(),
42
+ // 时间戳
43
+ created_at: z.string().datetime().optional(),
44
+ updated_at: z.string().datetime().optional(),
45
+ });
46
+ //# sourceMappingURL=task.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "@team-anya/core",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "dependencies": {
8
+ "zod": "^3.24.0"
9
+ }
10
+ }