skyloom 1.6.0 → 1.7.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimate.js","sourceRoot":"","sources":["../../src/core/estimate.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAUH,wCAGC;AAmBD,4CAUC;AAaD,4CAuBC;AAKD,gDAeC;AA9FD;;6CAE6C;AAC7C,MAAM,SAAS,GAAG,iBAAiB,CAAC;AAEpC,2EAA2E;AAC3E,SAAgB,cAAc,CAAC,IAAY;IACzC,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IACjD,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AACtD,CAAC;AAED;;6CAE6C;AAC7C,MAAM,kBAAkB,GAAoC;IAC1D,+CAA+C;IAC/C,CAAC,uCAAuC,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC,yCAAyC,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC,6BAA6B,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,CAAC,0BAA0B,EAAE,IAAI,EAAE,CAAC,CAAC;IACrC,CAAC,+BAA+B,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1C,CAAC,6BAA6B,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,CAAC,4BAA4B,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC,4BAA4B,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC,+BAA+B,EAAE,KAAK,EAAE,EAAE,CAAC;CAC7C,CAAC;AAEF,mDAAmD;AACnD,SAAgB,gBAAgB,CAAC,WAAmB;IAClD,IAAI,MAAM,GAAG,IAAI,CAAC,CAAC,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,CAAC,gBAAgB,OAAO;KAChG,CAAC;IAEF,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;QAC/B,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,QAAQ;YAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 输出过滤模块 — sensitive information sanitization.
3
+ *
4
+ * Before agent responses reach the user (or are persisted),
5
+ * scan for and redact sensitive patterns like API keys,
6
+ * tokens, passwords, PII, and internal paths.
7
+ */
8
+ export interface FilterResult {
9
+ clean: string;
10
+ redacted: boolean;
11
+ count: number;
12
+ details: string[];
13
+ }
14
+ export declare function filterOutput(text: string): FilterResult;
15
+ export declare function needsFiltering(text: string): boolean;
16
+ //# sourceMappingURL=filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/core/filter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA2CH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAgCvD;AAKD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CASpD"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ /**
3
+ * 输出过滤模块 — sensitive information sanitization.
4
+ *
5
+ * Before agent responses reach the user (or are persisted),
6
+ * scan for and redact sensitive patterns like API keys,
7
+ * tokens, passwords, PII, and internal paths.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.filterOutput = filterOutput;
11
+ exports.needsFiltering = needsFiltering;
12
+ /* ═══════════════════════════════════════
13
+ Detection patterns — compiled once at module load
14
+ ═══════════════════════════════════════ */
15
+ const SENSITIVE_PATTERNS = [
16
+ // API keys & tokens
17
+ [/sk-[a-zA-Z0-9]{32,}/g, "[REDACTED:API_KEY]"],
18
+ [/(?:api_key|apikey|secret_key|access_token|auth_token)\s*[:=]\s*["']?[^\s"']{8,}["']?/gi, "$1: [REDACTED]"],
19
+ [/ghp_[a-zA-Z0-9]{36}/g, "[REDACTED:GITHUB_TOKEN]"],
20
+ [/gho_[a-zA-Z0-9]{36}/g, "[REDACTED:GITHUB_TOKEN]"],
21
+ // AWS credentials
22
+ [/AKIA[0-9A-Z]{16}/g, "[REDACTED:AWS_KEY]"],
23
+ [/(?:aws_access_key_id|aws_secret_access_key)\s*[:=]\s*["']?[^\s"']+/gi, "$1: [REDACTED]"],
24
+ // Passwords
25
+ [/(?:password|passwd|pwd)\s*[:=]\s*["']?[^\s"']{4,}["']?/gi, "$1: [REDACTED]"],
26
+ [/(?:密码|口令)\s*[:=]\s*["']?[^\s"']{2,}["']?/g, "$1: [已脱敏]"],
27
+ // Connection strings
28
+ [/(?:mongodb|postgres|mysql|redis):\/\/[^\s]+/g, "[REDACTED:DB_URI]"],
29
+ [/(?:jdbc|odbc):[^\s]+/g, "[REDACTED:DB_URI]"],
30
+ // Private keys
31
+ [/-----BEGIN (?:RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----[\s\S]*?-----END .*?PRIVATE KEY-----/g, "[REDACTED:PRIVATE_KEY]"],
32
+ // IP addresses (local only)
33
+ [/192\.168\.\d{1,3}\.\d{1,3}/g, "[REDACTED:LAN_IP]"],
34
+ [/10\.\d{1,3}\.\d{1,3}\.\d{1,3}/g, "[REDACTED:LAN_IP]"],
35
+ [/172\.(1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}/g, "[REDACTED:LAN_IP]"],
36
+ // File paths
37
+ [/(?:\/etc\/(?:passwd|shadow|hosts|sudoers))/g, "[REDACTED:SYSTEM_PATH]"],
38
+ ];
39
+ /* Email masking (function-based, handled separately) */
40
+ const EMAIL_RE = /([a-zA-Z0-9._%+-]{3,})@([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/g;
41
+ function filterOutput(text) {
42
+ if (!text)
43
+ return { clean: "", redacted: false, count: 0, details: [] };
44
+ let clean = text;
45
+ let count = 0;
46
+ const details = [];
47
+ // Email masking (function-based replacement)
48
+ let emailCount = 0;
49
+ clean = clean.replace(EMAIL_RE, (full, user, domain) => {
50
+ emailCount++;
51
+ return user.slice(0, 2) + "***@" + domain;
52
+ });
53
+ if (emailCount > 0) {
54
+ count += emailCount;
55
+ details.push(`Masked ${emailCount}x email addresses`);
56
+ }
57
+ for (const [pattern, replacement] of SENSITIVE_PATTERNS) {
58
+ const matches = clean.match(pattern);
59
+ if (matches) {
60
+ count += matches.length;
61
+ if (typeof replacement === "string") {
62
+ details.push(`Redacted ${matches.length}x ${pattern.source.slice(0, 30)}`);
63
+ }
64
+ else {
65
+ details.push(`Masked ${matches.length}x email addresses`);
66
+ }
67
+ clean = clean.replace(pattern, replacement);
68
+ }
69
+ }
70
+ return { clean, redacted: count > 0, count, details };
71
+ }
72
+ /* ═══════════════════════════════════════
73
+ Quick check — is filtering needed?
74
+ ═══════════════════════════════════════ */
75
+ function needsFiltering(text) {
76
+ if (!text)
77
+ return false;
78
+ // Quick scan with the most common patterns
79
+ if (/sk-[a-zA-Z0-9]{32,}/.test(text))
80
+ return true;
81
+ if (/api_key.*[:=]/.test(text))
82
+ return true;
83
+ if (/password.*[:=]/.test(text))
84
+ return true;
85
+ if (/-----BEGIN.*PRIVATE KEY-----/.test(text))
86
+ return true;
87
+ if (EMAIL_RE.test(text))
88
+ return true;
89
+ return false;
90
+ }
91
+ //# sourceMappingURL=filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.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ACxB,2CAA2C;IAC3C,IAAI,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAClD,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5C,IAAI,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7C,IAAI,8BAA8B,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3D,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACrC,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -25,5 +25,11 @@ export * from './skill';
25
25
  export * from './router';
26
26
  export * from './agent';
27
27
  export * from './factory';
28
- export declare const VERSION = "1.4.0";
28
+ export * from './security';
29
+ export * from './learn';
30
+ export * from './longdoc';
31
+ export * from './filter';
32
+ export * from './estimate';
33
+ export * from './arbitrate';
34
+ export declare const VERSION: any;
29
35
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,eAAe,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AACzL,cAAc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AY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAG5B,eAAO,MAAM,OAAO,KAAgG,CAAC"}
@@ -49,6 +49,17 @@ __exportStar(require("./skill"), exports);
49
49
  __exportStar(require("./router"), exports);
50
50
  __exportStar(require("./agent"), exports);
51
51
  __exportStar(require("./factory"), exports);
52
- // Version
53
- exports.VERSION = '1.4.0';
52
+ __exportStar(require("./security"), exports);
53
+ __exportStar(require("./learn"), exports);
54
+ __exportStar(require("./longdoc"), exports);
55
+ __exportStar(require("./filter"), exports);
56
+ __exportStar(require("./estimate"), exports);
57
+ __exportStar(require("./arbitrate"), exports);
58
+ // Version — read from package.json
59
+ exports.VERSION = (() => { try {
60
+ return require('../../package.json').version;
61
+ }
62
+ catch {
63
+ return '1.6.0';
64
+ } })();
54
65
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAEH,8CAA4B;AAC5B,4CAA0B;AAC1B,2CAAyB;AACzB,2CAAyB;AACzB,yCAAuB;AACvB,oDAAkC;AAClC,wCAAsB;AACtB,0CAAwB;AACxB,2CAAyB;AACzB,+CAA6B;AAC7B,wCAAsB;AACtB,wCAAsB;AACtB,yCAAyL;AAAhL,0GAAA,aAAa,OAAA;AAAE,mHAAA,sBAAsB,OAAA;AAAE,0GAAA,aAAa,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,4GAAA,eAAe,OAAA;AACjI,6CAA2B;AAC3B,0CAAwB;AACxB,+CAA6B;AAC7B,8CAA4B;AAC5B,4CAA0B;AAC1B,gDAA8B;AAC9B,kDAAgC;AAChC,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B;AAE1B,UAAU;AACG,QAAA,OAAO,GAAG,OAAO,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAEH,8CAA4B;AAC5B,4CAA0B;AAC1B,2CAAyB;AACzB,2CAAyB;AACzB,yCAAuB;AACvB,oDAAkC;AAClC,wCAAsB;AACtB,0CAAwB;AACxB,2CAAyB;AACzB,+CAA6B;AAC7B,wCAAsB;AACtB,wCAAsB;AACtB,yCAAyL;AAAhL,0GAAA,aAAa,OAAA;AAAE,mHAAA,sBAAsB,OAAA;AAAE,0GAAA,aAAa,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,4GAAA,eAAe,OAAA;AACjI,6CAA2B;AAC3B,0CAAwB;AACxB,+CAA6B;AAC7B,8CAA4B;AAC5B,4CAA0B;AAC1B,gDAA8B;AAC9B,kDAAgC;AAChC,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B;AAC1B,6CAA2B;AAC3B,0CAAwB;AACxB,4CAA0B;AAC1B,2CAAyB;AACzB,6CAA2B;AAC3B,8CAA4B;AAE5B,mCAAmC;AACtB,QAAA,OAAO,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IAAC,OAAO,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC;AAAC,CAAC;AAAC,MAAM,CAAC;IAAC,OAAO,OAAO,CAAC;AAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 长文档处理策略 — sliding window + summary chain.
3
+ *
4
+ * When an input exceeds the agent's effective context window,
5
+ * split into overlapping chunks, summarize each, then chain
6
+ * summaries into a final digest.
7
+ *
8
+ * Architecture:
9
+ * Input → Chunk(sliding window) → Per-chunk Summary → Chain → Final Digest
10
+ *
11
+ * All summaries are generated by the calling agent's LLM, so quality
12
+ * depends on the model in use. The chunker is pure text processing
13
+ * and works without any LLM call.
14
+ */
15
+ import type { BaseAgent } from "./agent";
16
+ export interface ChunkOptions {
17
+ /** Target chunk size in characters (default 6000) */
18
+ chunkSize?: number;
19
+ /** Overlap between consecutive chunks in characters (default 800) */
20
+ overlap?: number;
21
+ /** Minimum chunk size before we stop splitting (default 500) */
22
+ minChunk?: number;
23
+ }
24
+ export declare function chunkText(text: string, opts?: ChunkOptions): string[];
25
+ export interface SummaryOptions {
26
+ /** Max total chars for the final digest (default 3000) */
27
+ maxDigestChars?: number;
28
+ /** Custom summarization prompt for each chunk */
29
+ chunkPrompt?: string;
30
+ /** Custom chain prompt for combining summaries */
31
+ chainPrompt?: string;
32
+ }
33
+ export declare function summarizeLongDoc(agent: BaseAgent, text: string, opts?: SummaryOptions): Promise<string>;
34
+ export declare function parseStructuredInput(input: string): {
35
+ hasTable: boolean;
36
+ hasJSON: boolean;
37
+ hasCSV: boolean;
38
+ extractedJSON: string | null;
39
+ extractedTable: string[][] | null;
40
+ };
41
+ //# sourceMappingURL=longdoc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"longdoc.d.ts","sourceRoot":"","sources":["../../src/core/longdoc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKzC,MAAM,WAAW,YAAY;IAC3B,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,MAAM,EAAE,CAkCrE;AAKD,MAAM,WAAW,cAAc;IAC7B,0DAA0D;IAC1D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAWD,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,SAAS,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,cAAc,GACpB,OAAO,CAAC,MAAM,CAAC,CAgCjB;AAKD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG;IACnD,QAAQ,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC;IACrD,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,cAAc,EAAE,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC;CACjE,CAwBA"}
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ /**
3
+ * 长文档处理策略 — sliding window + summary chain.
4
+ *
5
+ * When an input exceeds the agent's effective context window,
6
+ * split into overlapping chunks, summarize each, then chain
7
+ * summaries into a final digest.
8
+ *
9
+ * Architecture:
10
+ * Input → Chunk(sliding window) → Per-chunk Summary → Chain → Final Digest
11
+ *
12
+ * All summaries are generated by the calling agent's LLM, so quality
13
+ * depends on the model in use. The chunker is pure text processing
14
+ * and works without any LLM call.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.chunkText = chunkText;
18
+ exports.summarizeLongDoc = summarizeLongDoc;
19
+ exports.parseStructuredInput = parseStructuredInput;
20
+ function chunkText(text, opts) {
21
+ const cs = opts?.chunkSize ?? 6000;
22
+ const ol = opts?.overlap ?? 800;
23
+ const min = opts?.minChunk ?? 500;
24
+ const chunks = [];
25
+ if (text.length <= cs + min) {
26
+ chunks.push(text);
27
+ return chunks;
28
+ }
29
+ let start = 0;
30
+ while (start < text.length) {
31
+ let end = start + cs;
32
+ if (end >= text.length) {
33
+ end = text.length;
34
+ }
35
+ else {
36
+ // Try to break at paragraph boundary
37
+ const searchEnd = Math.min(end + 400, text.length);
38
+ const paraBreak = text.lastIndexOf("\n\n", searchEnd);
39
+ if (paraBreak > start + min)
40
+ end = paraBreak;
41
+ else {
42
+ const lineBreak = text.lastIndexOf("\n", searchEnd);
43
+ if (lineBreak > start + min)
44
+ end = lineBreak;
45
+ else {
46
+ const space = text.lastIndexOf(" ", searchEnd);
47
+ if (space > start + min)
48
+ end = space;
49
+ }
50
+ }
51
+ }
52
+ chunks.push(text.slice(start, end).trim());
53
+ if (end >= text.length)
54
+ break;
55
+ start = end - ol;
56
+ if (start < 0)
57
+ start = 0;
58
+ }
59
+ return chunks;
60
+ }
61
+ const DEFAULT_CHUNK_PROMPT = `Summarize the following text concisely. Keep all key facts, names, numbers, and code snippets. Output the summary directly without preamble. Limit to 300 words.
62
+
63
+ Text:
64
+ {text}`;
65
+ const DEFAULT_CHAIN_PROMPT = `Combine the following section summaries into a single coherent digest. Preserve all key facts, remove redundancy. Output directly without preamble.
66
+
67
+ {summaries}`;
68
+ async function summarizeLongDoc(agent, text, opts) {
69
+ const maxDigest = opts?.maxDigestChars ?? 3000;
70
+ const chunks = chunkText(text);
71
+ // Single chunk — no summarization needed
72
+ if (chunks.length <= 1) {
73
+ if (text.length <= maxDigest)
74
+ return text;
75
+ const prompt = (opts?.chunkPrompt || DEFAULT_CHUNK_PROMPT).replace("{text}", text);
76
+ return agent.chatOneshot(prompt, { maxTokens: maxDigest });
77
+ }
78
+ // Multi-chunk: summarize each, then chain
79
+ const summaries = [];
80
+ for (let i = 0; i < chunks.length; i++) {
81
+ const prompt = (opts?.chunkPrompt || DEFAULT_CHUNK_PROMPT).replace("{text}", chunks[i]);
82
+ try {
83
+ const s = await agent.chatOneshot(prompt, { maxTokens: 600 });
84
+ summaries.push(s);
85
+ }
86
+ catch {
87
+ summaries.push(chunks[i].slice(0, 400) + "...");
88
+ }
89
+ }
90
+ // Chain summaries
91
+ if (summaries.length === 1)
92
+ return summaries[0].slice(0, maxDigest);
93
+ const joined = summaries.map((s, i) => `## Section ${i + 1}\n${s}`).join("\n\n");
94
+ if (joined.length <= maxDigest)
95
+ return joined;
96
+ const chainPrompt = (opts?.chainPrompt || DEFAULT_CHAIN_PROMPT).replace("{summaries}", joined);
97
+ const final = await agent.chatOneshot(chainPrompt, { maxTokens: maxDigest });
98
+ return final.slice(0, maxDigest);
99
+ }
100
+ /* ═══════════════════════════════════════
101
+ Structured data parsing helpers
102
+ ═══════════════════════════════════════ */
103
+ function parseStructuredInput(input) {
104
+ const result = { hasTable: false, hasJSON: false, hasCSV: false, extractedJSON: null, extractedTable: null };
105
+ // Detect JSON
106
+ const jsonMatch = input.match(/\{[\s\S]*\}|\[[\s\S]*\]/);
107
+ if (jsonMatch) {
108
+ try {
109
+ JSON.parse(jsonMatch[0]);
110
+ result.hasJSON = true;
111
+ result.extractedJSON = jsonMatch[0];
112
+ }
113
+ catch { /* not valid JSON */ }
114
+ }
115
+ // Detect markdown table
116
+ const tableMatch = input.match(/\|[\s\S]*?\|/);
117
+ if (tableMatch) {
118
+ result.hasTable = true;
119
+ const lines = input.split("\n").filter(l => l.includes("|") && !l.startsWith("|---") && !l.startsWith("| --"));
120
+ result.extractedTable = lines.map(l => l.split("|").filter(c => c.trim()).map(c => c.trim()));
121
+ }
122
+ // Detect CSV
123
+ if (input.includes(",") && input.split("\n").filter(l => l.includes(",")).length >= 2) {
124
+ result.hasCSV = true;
125
+ }
126
+ return result;
127
+ }
128
+ //# sourceMappingURL=longdoc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"longdoc.js","sourceRoot":"","sources":["../../src/core/longdoc.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AAgBH,8BAkCC;AAuBD,4CAoCC;AAKD,oDA2BC;AA7HD,SAAgB,SAAS,CAAC,IAAY,EAAE,IAAmB;IACzD,MAAM,EAAE,GAAG,IAAI,EAAE,SAAS,IAAI,IAAI,CAAC;IACnC,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,IAAI,GAAG,CAAC;IAChC,MAAM,GAAG,GAAG,IAAI,EAAE,QAAQ,IAAI,GAAG,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skyloom",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "天空织机 Skyloom — 6 weather-themed AI agents: Fog, Rain, Frost, Snow, Dew, Fair",
5
5
  "preferGlobal": true,
6
6
  "type": "commonjs",
package/src/core/agent.ts CHANGED
@@ -731,7 +731,9 @@ export class BaseAgent {
731
731
  try {
732
732
  if (onStatus) onStatus('thinking...');
733
733
  const response = await this.llmLoop({ onStatus });
734
- const content = response?.content || '(no response)';
734
+ let content = response?.content || '(no response)';
735
+ // Apply output filter for sensitive info
736
+ try { const { filterOutput } = require('./filter'); const fr = filterOutput(content); if (fr.redacted) content = fr.clean; } catch {}
735
737
  this.memory.addMessage('assistant', content, {
736
738
  toolCalls: response?.toolCalls || [],
737
739
  reasoningContent: response?.reasoningContent,
@@ -0,0 +1,162 @@
1
+ /**
2
+ * 多Agent冲突仲裁 — majority voting, quality scoring, tie-breaking.
3
+ *
4
+ * When multiple agents produce conflicting outputs on the same task
5
+ * (or when a reviewer disagrees with an executor), this module
6
+ * provides structured conflict resolution.
7
+ */
8
+
9
+ import type { TaskExecutionResult } from "./factory";
10
+
11
+ /* ═══════════════════════════════════════
12
+ Conflict detection
13
+ ═══════════════════════════════════════ */
14
+ export interface Conflict {
15
+ taskId: string;
16
+ results: TaskExecutionResult[];
17
+ description: string;
18
+ severity: "low" | "medium" | "high";
19
+ }
20
+
21
+ /** Detect if two results conflict based on success status and content overlap. */
22
+ export function detectConflicts(results: TaskExecutionResult[]): Conflict[] {
23
+ const byTask = new Map<string, TaskExecutionResult[]>();
24
+ for (const r of results) { const id = r.id; if (!byTask.has(id)) byTask.set(id, []); byTask.get(id)!.push(r); }
25
+
26
+ const conflicts: Conflict[] = [];
27
+ for (const [id, items] of byTask) {
28
+ if (items.length < 2) continue;
29
+
30
+ const successes = items.filter(r => r.success);
31
+ const failures = items.filter(r => !r.success);
32
+
33
+ // All succeeded — check content divergence
34
+ if (successes.length >= 2) {
35
+ const contents = successes.map(r => (r.content || "").toLowerCase());
36
+ const similarity = pairwiseSimilarity(contents);
37
+ if (similarity < 0.3) {
38
+ conflicts.push({ taskId: id, results: successes, description: "Multiple agents produced divergent successful outputs", severity: "medium" });
39
+ }
40
+ }
41
+
42
+ // Mix of success and failure
43
+ if (successes.length > 0 && failures.length > 0) {
44
+ conflicts.push({ taskId: id, results: items, description: `${successes.length} succeeded, ${failures.length} failed — need tiebreaker`, severity: "medium" });
45
+ }
46
+
47
+ // All failed
48
+ if (failures.length >= 2 && successes.length === 0) {
49
+ conflicts.push({ taskId: id, results: failures, description: "All agents failed on this task", severity: "high" });
50
+ }
51
+ }
52
+
53
+ return conflicts;
54
+ }
55
+
56
+ /* ═══════════════════════════════════════
57
+ Content similarity (n-gram Jaccard)
58
+ ═══════════════════════════════════════ */
59
+ function pairwiseSimilarity(texts: string[]): number {
60
+ if (texts.length < 2) return 1.0;
61
+ let total = 0;
62
+ let count = 0;
63
+ for (let i = 0; i < texts.length; i++) {
64
+ for (let j = i + 1; j < texts.length; j++) {
65
+ total += ngramJaccard(texts[i], texts[j], 3);
66
+ count++;
67
+ }
68
+ }
69
+ return count === 0 ? 0 : total / count;
70
+ }
71
+
72
+ function ngramJaccard(a: string, b: string, n: number): number {
73
+ const as = ngrams(a, n), bs = ngrams(b, n);
74
+ if (as.size === 0 && bs.size === 0) return 1;
75
+ let intersection = 0;
76
+ for (const g of as) { if (bs.has(g)) intersection++; }
77
+ const union = as.size + bs.size - intersection;
78
+ return union === 0 ? 0 : intersection / union;
79
+ }
80
+
81
+ function ngrams(s: string, n: number): Set<string> {
82
+ const out = new Set<string>();
83
+ for (let i = 0; i <= s.length - n; i++) out.add(s.slice(i, i + n));
84
+ return out;
85
+ }
86
+
87
+ /* ═══════════════════════════════════════
88
+ Majority voting / arbitration
89
+ ═══════════════════════════════════════ */
90
+ export interface ArbitrationResult {
91
+ winner: TaskExecutionResult;
92
+ method: "unanimous" | "majority" | "tiebreaker" | "single";
93
+ confidence: number; // 0-1
94
+ reasoning: string;
95
+ }
96
+
97
+ /** Pick the best result from conflicting ones via majority vote. */
98
+ export function arbitrate(results: TaskExecutionResult[]): ArbitrationResult {
99
+ if (results.length === 0) throw new Error("No results to arbitrate");
100
+ if (results.length === 1) return { winner: results[0], method: "single", confidence: 0.8, reasoning: "Only one result available" };
101
+
102
+ const success = results.filter(r => r.success);
103
+ const fail = results.filter(r => !r.success);
104
+
105
+ // All agree (success)
106
+ if (success.length === results.length) {
107
+ const longest = success.reduce((a, b) => (b.content || "").length > (a.content || "").length ? b : a);
108
+ return { winner: longest, method: "unanimous", confidence: 0.95, reasoning: `${results.length}/${results.length} agents agreed` };
109
+ }
110
+
111
+ // Majority success
112
+ if (success.length > fail.length) {
113
+ // Pick the longest successful content (most detailed)
114
+ const best = success.reduce((a, b) => (b.content || "").length > (a.content || "").length ? b : a);
115
+ return { winner: best, method: "majority", confidence: success.length / results.length, reasoning: `${success.length}/${results.length} succeeded, selected most detailed` };
116
+ }
117
+
118
+ // Majority failure — pick the "closest to success" (longest content)
119
+ if (fail.length > success.length) {
120
+ const best = fail.reduce((a, b) => (b.content || "").length > (a.content || "").length ? b : a);
121
+ return { winner: best, method: "majority", confidence: 0.3, reasoning: `Majority failed (${fail.length}/${results.length}), best-effort from partial output` };
122
+ }
123
+
124
+ // Tie — prefer success, or longest content
125
+ const tie = success.length > 0 ? success[0] : fail[0];
126
+ return { winner: tie, method: "tiebreaker", confidence: 0.5, reasoning: `Tie — selected ${tie.success ? "success" : "longest"} result` };
127
+ }
128
+
129
+ /* ═══════════════════════════════════════
130
+ Quality scoring for individual results
131
+ ═══════════════════════════════════════ */
132
+ export interface QualityScore {
133
+ score: number; // 0-100
134
+ completeness: number; // how much of the task was addressed
135
+ richness: number; // detail level of the output
136
+ correctness: number; // did it match expectations (requires ground truth)
137
+ }
138
+
139
+ export function scoreQuality(result: TaskExecutionResult): QualityScore {
140
+ const content = result.content || "";
141
+
142
+ // Completeness: length is a weak proxy but useful
143
+ const completeness = content.length > 500 ? 80 : content.length > 100 ? 50 : content.length > 0 ? 20 : 0;
144
+
145
+ // Richness: code blocks, structured output, bullet points
146
+ let richness = 50;
147
+ if (/```/.test(content)) richness += 20;
148
+ if (/\|.*\|.*\|/.test(content)) richness += 15; // tables
149
+ if (/^[-*] /.test(content)) richness += 10; // bullets
150
+ if (/\d+\./.test(content)) richness += 10; // numbered lists
151
+ richness = Math.min(100, richness);
152
+
153
+ // Correctness: basic sanity checks
154
+ let correctness = 70;
155
+ if (content.includes("Error") || content.includes("error")) correctness -= 20;
156
+ if (content.includes("[REDACTED]")) correctness -= 10;
157
+ if (content.includes("truncated")) correctness -= 15;
158
+ correctness = Math.max(0, correctness);
159
+
160
+ const score = Math.round((completeness * 0.3 + richness * 0.3 + correctness * 0.4));
161
+ return { score, completeness, richness, correctness };
162
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * 资源估算模块 — Token & time budget estimation for task planning.
3
+ *
4
+ * Helps Snow and other planning agents estimate the cost of
5
+ * proposed sub-tasks before committing to execution.
6
+ */
7
+
8
+ import type { Task } from "./agent";
9
+
10
+ /* ═══════════════════════════════════════
11
+ Token estimation
12
+ ═══════════════════════════════════════ */
13
+ const CJK_REGEX = /[一-鿿぀-ゟ가-힯㐀-䶿]/g;
14
+
15
+ /** Estimate tokens for a given text (CJK ~2 each, ASCII ~4 chars each). */
16
+ export function estimateTokens(text: string): number {
17
+ const cjk = (text.match(CJK_REGEX) || []).length;
18
+ return cjk * 2 + Math.ceil((text.length - cjk) / 4);
19
+ }
20
+
21
+ /* ═══════════════════════════════════════
22
+ Per-task-type cost estimates
23
+ ═══════════════════════════════════════ */
24
+ const TASK_TYPE_PATTERNS: Array<[RegExp, number, number]> = [
25
+ // [pattern, estimated tokens, estimated tools]
26
+ [/read|read_file|grep|search|查|搜索|list/i, 2000, 2],
27
+ [/write|write_file|生成|写|create|implement/i, 4000, 5],
28
+ [/edit|edit_file|改|修改|fix|修复/i, 3000, 3],
29
+ [/delete|delete_file|删|rm/i, 1500, 2],
30
+ [/deploy|部署|publish|发布|release/i, 8000, 8],
31
+ [/review|审查|audit|审计|scan|扫描/i, 5000, 4],
32
+ [/test|测试|run_test|coverage/i, 3000, 3],
33
+ [/research|研究|调研|analyze|分析/i, 6000, 4],
34
+ [/orchestrate|编排|multi-step|多步/i, 12000, 10],
35
+ ];
36
+
37
+ /** Estimate cost for a single task description. */
38
+ export function estimateTaskCost(description: string): { tokens: number; tools: number; timeSeconds: number } {
39
+ let tokens = 2000; // base
40
+ let tools = 2; // base
41
+ for (const [pattern, t, tc] of TASK_TYPE_PATTERNS) {
42
+ if (pattern.test(description)) { tokens = Math.max(tokens, t); tools = Math.max(tools, tc); }
43
+ }
44
+
45
+ // Time estimate: ~0.5s per tool call + 2s per 1k tokens
46
+ const timeSeconds = (tokens / 1000) * 2 + tools * 0.5 + 2;
47
+ return { tokens, tools, timeSeconds };
48
+ }
49
+
50
+ /* ═══════════════════════════════════════
51
+ Task plan cost summary
52
+ ═══════════════════════════════════════ */
53
+ export interface PlanEstimate {
54
+ totalTokens: number;
55
+ totalTools: number;
56
+ totalTimeSeconds: number;
57
+ perTask: Array<{ id: string; tokens: number; tools: number; time: number }>;
58
+ warnings: string[];
59
+ }
60
+
61
+ export function estimateTaskPlan(tasks: Task[]): PlanEstimate {
62
+ const perTask: PlanEstimate["perTask"] = [];
63
+ let totalTokens = 500; // system prompt overhead
64
+ let totalTools = 0;
65
+ let totalTime = 5; // init overhead
66
+ const warnings: string[] = [];
67
+
68
+ for (const t of tasks) {
69
+ const est = estimateTaskCost(t.description);
70
+ perTask.push({ id: t.id, tokens: est.tokens, tools: est.tools, time: est.timeSeconds });
71
+ totalTokens += est.tokens;
72
+ totalTools += est.tools;
73
+ totalTime += est.timeSeconds;
74
+
75
+ if (est.timeSeconds > 60) warnings.push(`Task ${t.id} may take >${Math.round(est.timeSeconds)}s`);
76
+ if (est.tools > 10) warnings.push(`Task ${t.id} uses many tool calls (${est.tools})`);
77
+ }
78
+
79
+ if (totalTokens > 64000) warnings.push(`Total token estimate (${totalTokens}) exceeds typical context window`);
80
+ if (totalTime > 120) warnings.push(`Estimated total time (${Math.round(totalTime)}s) is significant`);
81
+ if (tasks.length > 6) warnings.push(`Large number of sub-tasks (${tasks.length}) — consider merging simpler ones`);
82
+
83
+ return { totalTokens, totalTools, totalTimeSeconds: Math.round(totalTime), perTask, warnings };
84
+ }
85
+
86
+ /* ═══════════════════════════════════════
87
+ Format estimate for display
88
+ ═══════════════════════════════════════ */
89
+ export function formatPlanEstimate(est: PlanEstimate): string {
90
+ const lines: string[] = [
91
+ `## Plan Estimate`,
92
+ `| Task | Tokens | Tools | Time |`,
93
+ `|------|--------|-------|------|`,
94
+ ...est.perTask.map(t => `| ${t.id} | ${t.tokens} | ${t.tools} | ${t.time.toFixed(0)}s |`),
95
+ `| **Total** | **${est.totalTokens}** | **${est.totalTools}** | **${est.totalTimeSeconds}s** |`,
96
+ ];
97
+
98
+ if (est.warnings.length > 0) {
99
+ lines.push("", "### Warnings");
100
+ for (const w of est.warnings) lines.push(`- ⚠ ${w}`);
101
+ }
102
+
103
+ return lines.join("\n");
104
+ }