codecane 1.0.310 → 1.0.312
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/dist/cli-handlers/api-key.d.ts +1 -1
- package/dist/cli-handlers/api-key.js +1 -1
- package/dist/cli-handlers/api-key.js.map +1 -1
- package/dist/cli.d.ts +6 -1
- package/dist/cli.js +60 -7
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +1 -0
- package/dist/client.js +14 -1
- package/dist/client.js.map +1 -1
- package/dist/code-map/languages.d.ts +1 -2
- package/dist/code-map/languages.d.ts.map +1 -1
- package/dist/code-map/languages.js +2 -1
- package/dist/code-map/languages.js.map +1 -1
- package/dist/code-map/parse.d.ts +14 -4
- package/dist/code-map/parse.d.ts.map +1 -1
- package/dist/code-map/parse.js +91 -38
- package/dist/code-map/parse.js.map +1 -1
- package/dist/code-map/tree-sitter-queries/tree-sitter-c-tags.scm +6 -1
- package/dist/code-map/tree-sitter-queries/tree-sitter-c_sharp-tags.scm +11 -1
- package/dist/code-map/tree-sitter-queries/tree-sitter-cpp-tags.scm +13 -1
- package/dist/code-map/tree-sitter-queries/tree-sitter-javascript-tags.scm +1 -0
- package/dist/code-map/tree-sitter-queries/tree-sitter-php-tags.scm +5 -8
- package/dist/code-map/tree-sitter-queries/tree-sitter-python-tags.scm +5 -2
- package/dist/code-map/tree-sitter-queries/tree-sitter-typescript-tags.scm +7 -0
- package/dist/code-map/tsconfig.tsbuildinfo +1 -1
- package/dist/common/__tests__/project-file-tree.test.d.ts +1 -0
- package/dist/common/__tests__/project-file-tree.test.js +251 -0
- package/dist/common/__tests__/project-file-tree.test.js.map +1 -0
- package/dist/common/actions.d.ts +58 -32
- package/dist/common/constants/analytics-events.d.ts +1 -0
- package/dist/common/constants/analytics-events.js +1 -0
- package/dist/common/constants/analytics-events.js.map +1 -1
- package/dist/common/constants/tools.d.ts +1 -0
- package/dist/common/constants/tools.js +2 -1
- package/dist/common/constants/tools.js.map +1 -1
- package/dist/common/constants.d.ts +5 -5
- package/dist/common/constants.js +19 -8
- package/dist/common/constants.js.map +1 -1
- package/dist/common/json-config/__tests__/__snapshots__/stringify-schema.test.js.snap +119 -0
- package/dist/common/project-file-tree.js +12 -0
- package/dist/common/project-file-tree.js.map +1 -1
- package/dist/common/types/agent-state.d.ts +13 -8
- package/dist/common/types/message.d.ts +6 -6
- package/dist/common/util/__tests__/saxy.test.js +171 -21
- package/dist/common/util/__tests__/saxy.test.js.map +1 -1
- package/dist/common/util/credentials.d.ts +2 -2
- package/dist/common/util/file.d.ts +3 -0
- package/dist/common/util/file.js +6 -6
- package/dist/common/util/file.js.map +1 -1
- package/dist/common/util/process-stream.d.ts +7 -0
- package/dist/common/util/process-stream.js +162 -0
- package/dist/common/util/process-stream.js.map +1 -0
- package/dist/common/util/promise.js +1 -1
- package/dist/common/util/promise.js.map +1 -1
- package/dist/common/util/saxy.d.ts +19 -5
- package/dist/common/util/saxy.js +101 -37
- package/dist/common/util/saxy.js.map +1 -1
- package/dist/common/websockets/websocket-schema.d.ts +118 -68
- package/dist/display.d.ts +2 -0
- package/dist/display.js +31 -14
- package/dist/display.js.map +1 -1
- package/dist/index.js +19 -59
- package/dist/index.js.map +1 -1
- package/dist/menu.js +35 -113
- package/dist/menu.js.map +1 -1
- package/dist/project-files.d.ts +2 -0
- package/dist/project-files.js +3 -2
- package/dist/project-files.js.map +1 -1
- package/dist/tool-handlers.d.ts +2 -1
- package/dist/tool-handlers.js +15 -2
- package/dist/tool-handlers.js.map +1 -1
- package/dist/utils/__tests__/__snapshots__/background-process-manager.test.js.snap +137 -0
- package/dist/utils/__tests__/file-paths.test.d.ts +1 -0
- package/dist/utils/__tests__/file-paths.test.js +37 -0
- package/dist/utils/__tests__/file-paths.test.js.map +1 -0
- package/dist/utils/__tests__/path.test.d.ts +1 -0
- package/dist/utils/__tests__/path.test.js +37 -0
- package/dist/utils/__tests__/path.test.js.map +1 -0
- package/dist/utils/__tests__/tool-renderers.test.js +37 -3
- package/dist/utils/__tests__/tool-renderers.test.js.map +1 -1
- package/dist/utils/__tests__/xml-stream-parser.test.js +26 -0
- package/dist/utils/__tests__/xml-stream-parser.test.js.map +1 -1
- package/dist/utils/detect-shell.js +1 -1
- package/dist/utils/detect-shell.js.map +1 -1
- package/dist/utils/file-paths.d.ts +9 -0
- package/dist/utils/file-paths.js +24 -0
- package/dist/utils/file-paths.js.map +1 -0
- package/dist/utils/logger.d.ts +1 -1
- package/dist/utils/logger.js +3 -6
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/path.d.ts +9 -0
- package/dist/utils/path.js +27 -0
- package/dist/utils/path.js.map +1 -0
- package/dist/utils/spinner.d.ts +1 -0
- package/dist/utils/spinner.js +8 -1
- package/dist/utils/spinner.js.map +1 -1
- package/dist/utils/system-info.js +2 -2
- package/dist/utils/system-info.js.map +1 -1
- package/dist/utils/terminal.d.ts +2 -2
- package/dist/utils/terminal.js +78 -48
- package/dist/utils/terminal.js.map +1 -1
- package/dist/utils/tool-renderers.js +25 -5
- package/dist/utils/tool-renderers.js.map +1 -1
- package/dist/utils/xml-stream-parser.js +1 -1
- package/dist/utils/xml-stream-parser.js.map +1 -1
- package/dist/workers/project-context.js +4 -1
- package/dist/workers/project-context.js.map +1 -1
- package/package.json +3 -1
|
@@ -30,6 +30,7 @@ export declare const ProjectFileContextSchema: z.ZodObject<{
|
|
|
30
30
|
currentWorkingDirectory: z.ZodString;
|
|
31
31
|
fileTree: z.ZodArray<z.ZodType<FileTreeNode, z.ZodTypeDef, FileTreeNode>, "many">;
|
|
32
32
|
fileTokenScores: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
33
|
+
tokenCallers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>>;
|
|
33
34
|
knowledgeFiles: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
34
35
|
userKnowledgeFiles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
35
36
|
gitChanges: z.ZodObject<{
|
|
@@ -103,6 +104,7 @@ export declare const ProjectFileContextSchema: z.ZodObject<{
|
|
|
103
104
|
homedir: string;
|
|
104
105
|
cpus: number;
|
|
105
106
|
};
|
|
107
|
+
tokenCallers?: Record<string, Record<string, string[]>> | undefined;
|
|
106
108
|
userKnowledgeFiles?: Record<string, string> | undefined;
|
|
107
109
|
fileVersions?: {
|
|
108
110
|
path: string;
|
|
@@ -129,6 +131,7 @@ export declare const ProjectFileContextSchema: z.ZodObject<{
|
|
|
129
131
|
homedir: string;
|
|
130
132
|
cpus: number;
|
|
131
133
|
};
|
|
134
|
+
tokenCallers?: Record<string, Record<string, string[]>> | undefined;
|
|
132
135
|
userKnowledgeFiles?: Record<string, string> | undefined;
|
|
133
136
|
fileVersions?: {
|
|
134
137
|
path: string;
|
package/dist/common/util/file.js
CHANGED
|
@@ -43,6 +43,9 @@ exports.ProjectFileContextSchema = zod_1.z.object({
|
|
|
43
43
|
currentWorkingDirectory: zod_1.z.string(),
|
|
44
44
|
fileTree: zod_1.z.array(zod_1.z.custom()),
|
|
45
45
|
fileTokenScores: zod_1.z.record(zod_1.z.string(), zod_1.z.record(zod_1.z.string(), zod_1.z.number())),
|
|
46
|
+
tokenCallers: zod_1.z
|
|
47
|
+
.record(zod_1.z.string(), zod_1.z.record(zod_1.z.string(), zod_1.z.array(zod_1.z.string())))
|
|
48
|
+
.optional(),
|
|
46
49
|
knowledgeFiles: zod_1.z.record(zod_1.z.string(), zod_1.z.string()),
|
|
47
50
|
userKnowledgeFiles: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
|
|
48
51
|
gitChanges: zod_1.z.object({
|
|
@@ -65,13 +68,10 @@ exports.ProjectFileContextSchema = zod_1.z.object({
|
|
|
65
68
|
});
|
|
66
69
|
const createWriteFileBlock = (filePath, content) => {
|
|
67
70
|
const tagName = 'write_file';
|
|
68
|
-
return
|
|
69
|
-
`${tagName}>
|
|
71
|
+
return `<${tagName}>
|
|
70
72
|
<path>${filePath}</path>
|
|
71
|
-
<content>
|
|
72
|
-
|
|
73
|
-
</content>
|
|
74
|
-
</${tagName}>`);
|
|
73
|
+
<content>${content}</content>
|
|
74
|
+
</${tagName}>`;
|
|
75
75
|
};
|
|
76
76
|
exports.createWriteFileBlock = createWriteFileBlock;
|
|
77
77
|
exports.fileRegex = /<write_file>\s*<path>([^<]+)<\/path>\s*<content>([\s\S]*?)<\/content>\s*<\/write_file>/g;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/util/file.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/util/file.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,sCAaC;AAED,0DAmCC;AAoCD,0CAWC;AA1MD,uCAAwB;AACxB,6BAAuB;AAEV,QAAA,kBAAkB,GAA4B,OAAC,CAAC,MAAM,CAAC;IAClE,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACnC,QAAQ,EAAE,OAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAC,CAAC,KAAK,CAAC,0BAAkB,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC9D,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;CACrB,CAAC,CAAA;AAoBW,QAAA,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;IAChB,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;CACpB,CAAC,CAAA;AAIW,QAAA,wBAAwB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC/C,uBAAuB,EAAE,OAAC,CAAC,MAAM,EAAE;IACnC,QA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A;IAEjC,+BAA+B;IAC/B,MAAM,YAAY,GAAG,qBAAqB,CAAA;IAC1C,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAA;IAEzC,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function processStreamWithTags<T extends string>(stream: AsyncGenerator<T>, tags: {
|
|
2
|
+
[tagName: string]: {
|
|
3
|
+
attributeNames: string[];
|
|
4
|
+
onTagStart: (attributes: Record<string, string>) => void;
|
|
5
|
+
onTagEnd: (content: string, attributes: Record<string, string>) => boolean;
|
|
6
|
+
};
|
|
7
|
+
}): AsyncGenerator<string, void, unknown>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processStreamWithTags = processStreamWithTags;
|
|
4
|
+
const saxy_1 = require("./saxy");
|
|
5
|
+
async function* processStreamWithTags(stream, tags) {
|
|
6
|
+
const saxyParser = new saxy_1.Saxy();
|
|
7
|
+
let currentTagName = null;
|
|
8
|
+
let currentTagAttributes = {};
|
|
9
|
+
let currentTagContentBuffer = '';
|
|
10
|
+
let shouldStopProcessing = false;
|
|
11
|
+
const outputQueue = [];
|
|
12
|
+
const enqueueOutput = (str) => {
|
|
13
|
+
if (str) {
|
|
14
|
+
// Only enqueue non-empty strings
|
|
15
|
+
outputQueue.push(str);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
saxyParser.on('tagopen', (node) => {
|
|
19
|
+
if (shouldStopProcessing)
|
|
20
|
+
return;
|
|
21
|
+
if (currentTagName === null) {
|
|
22
|
+
// Not currently inside a tracked tag
|
|
23
|
+
if (tags[node.name]) {
|
|
24
|
+
// This is a tag we want to track
|
|
25
|
+
currentTagName = node.name;
|
|
26
|
+
try {
|
|
27
|
+
currentTagAttributes = saxy_1.Saxy.parseAttrs(node.attrs);
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
// If attributes are malformed, default to empty or handle as error
|
|
31
|
+
// console.error(`Error parsing attributes for tag ${node.name}: "${node.attrs}"`, e);
|
|
32
|
+
currentTagAttributes = {}; // Default to empty attributes on parsing error
|
|
33
|
+
}
|
|
34
|
+
tags[currentTagName].onTagStart(currentTagAttributes);
|
|
35
|
+
currentTagContentBuffer = '';
|
|
36
|
+
if (node.isSelfClosing) {
|
|
37
|
+
const stop = tags[currentTagName].onTagEnd(currentTagContentBuffer, currentTagAttributes);
|
|
38
|
+
currentTagName = null;
|
|
39
|
+
currentTagAttributes = {};
|
|
40
|
+
if (stop) {
|
|
41
|
+
shouldStopProcessing = true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// A non-tracked tag, pass it through
|
|
47
|
+
enqueueOutput(`<${node.name}${node.attrs ? ' ' + node.attrs : ''}${node.isSelfClosing ? ' /' : ''}>`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// Inside a tracked tag, so this is nested content
|
|
52
|
+
currentTagContentBuffer += `<${node.name}${node.attrs ? ' ' + node.attrs : ''}${node.isSelfClosing ? ' /' : ''}>`;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
saxyParser.on('text', (node) => {
|
|
56
|
+
if (shouldStopProcessing)
|
|
57
|
+
return;
|
|
58
|
+
if (currentTagName !== null) {
|
|
59
|
+
currentTagContentBuffer += node.contents;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
enqueueOutput(node.contents);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
saxyParser.on('tagclose', (node) => {
|
|
66
|
+
if (shouldStopProcessing)
|
|
67
|
+
return;
|
|
68
|
+
if (currentTagName === node.name) {
|
|
69
|
+
const stop = tags[currentTagName].onTagEnd(currentTagContentBuffer, currentTagAttributes);
|
|
70
|
+
currentTagName = null;
|
|
71
|
+
currentTagAttributes = {};
|
|
72
|
+
currentTagContentBuffer = '';
|
|
73
|
+
if (stop) {
|
|
74
|
+
shouldStopProcessing = true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (currentTagName !== null) {
|
|
78
|
+
// Closing a nested tag inside a tracked tag
|
|
79
|
+
currentTagContentBuffer += `</${node.name}>`;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// Closing a non-tracked tag, pass it through
|
|
83
|
+
enqueueOutput(`</${node.name}>`);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
saxyParser.on('cdata', (node) => {
|
|
87
|
+
if (shouldStopProcessing)
|
|
88
|
+
return;
|
|
89
|
+
const cdataStr = `<![CDATA[${node.contents}]]>`;
|
|
90
|
+
if (currentTagName !== null) {
|
|
91
|
+
currentTagContentBuffer += cdataStr;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
enqueueOutput(cdataStr);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
saxyParser.on('comment', (node) => {
|
|
98
|
+
if (shouldStopProcessing)
|
|
99
|
+
return;
|
|
100
|
+
const commentStr = `<!--${node.contents}-->`;
|
|
101
|
+
if (currentTagName !== null) {
|
|
102
|
+
currentTagContentBuffer += commentStr;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
enqueueOutput(commentStr);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
saxyParser.on('processinginstruction', (node) => {
|
|
109
|
+
if (shouldStopProcessing)
|
|
110
|
+
return;
|
|
111
|
+
const piStr = `<?${node.contents}?>`;
|
|
112
|
+
if (currentTagName !== null) {
|
|
113
|
+
currentTagContentBuffer += piStr;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
enqueueOutput(piStr);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
saxyParser.on('error', (err) => {
|
|
120
|
+
// Saxy might emit 'error' for issues not causing write/end to throw.
|
|
121
|
+
// This flag helps stop processing in such cases.
|
|
122
|
+
// console.error("Saxy parser emitted an error:", err);
|
|
123
|
+
shouldStopProcessing = true;
|
|
124
|
+
// The error might need to be explicitly thrown here if it's critical
|
|
125
|
+
// and not otherwise surfaced to the generator's caller.
|
|
126
|
+
// For now, this ensures processing stops.
|
|
127
|
+
});
|
|
128
|
+
try {
|
|
129
|
+
for await (const chunk of stream) {
|
|
130
|
+
if (shouldStopProcessing)
|
|
131
|
+
break;
|
|
132
|
+
saxyParser.write(chunk); // Saxy events fill outputQueue
|
|
133
|
+
while (outputQueue.length > 0) {
|
|
134
|
+
// If stopping and not inside a tracked tag, clear queue to prevent further passthrough.
|
|
135
|
+
if (shouldStopProcessing && currentTagName === null) {
|
|
136
|
+
outputQueue.length = 0;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
yield outputQueue.shift();
|
|
140
|
+
}
|
|
141
|
+
// Re-check stop condition after yielding, as an event during write might have set it.
|
|
142
|
+
if (shouldStopProcessing)
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
if (!shouldStopProcessing) {
|
|
146
|
+
saxyParser.end(); // Finalize parsing
|
|
147
|
+
while (outputQueue.length > 0) {
|
|
148
|
+
if (shouldStopProcessing && currentTagName === null) {
|
|
149
|
+
outputQueue.length = 0;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
yield outputQueue.shift();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
// Catches errors from saxyParser.write() or saxyParser.end()
|
|
158
|
+
// console.error("Error during Saxy stream processing in generator:", error);
|
|
159
|
+
throw error; // Propagate error to the caller
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=process-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-stream.js","sourceRoot":"","sources":["../../src/util/process-stream.ts"],"names":[],"mappings":";;AAUA,sDAkLC;AA5LD,iCAQe;A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M,WAAW,CAAC,KAAK,EAAG,CAAA;YAC5B,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,6DAA6D;QAC7D,6EAA6E;QAC7E,MAAM,KAAK,CAAA,CAAC,gCAAgC;IAC9C,CAAC;AACH,CAAC"}
|
|
@@ -62,7 +62,7 @@ exports.sleep = sleep;
|
|
|
62
62
|
* @param timeoutMessage Optional message for the timeout error
|
|
63
63
|
* @returns A promise that resolves with the result of the original promise or rejects with a timeout error
|
|
64
64
|
*/
|
|
65
|
-
async function withTimeout(promise, timeoutMs, timeoutMessage =
|
|
65
|
+
async function withTimeout(promise, timeoutMs, timeoutMessage = `Operation timed out after ${timeoutMs}ms`) {
|
|
66
66
|
let timeoutId;
|
|
67
67
|
const timeoutPromise = new Promise((_, reject) => {
|
|
68
68
|
timeoutId = setTimeout(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.js","sourceRoot":"","sources":["../../src/util/promise.ts"],"names":[],"mappings":";;;AAEA,8BAqCC;AA2CD,kCAoBC;AAtGY,QAAA,mBAAmB,GAAG,IAAI,CAAA,CAAC,WAAW;AAE5C,KAAK,UAAU,SAAS,CAC7B,SAA2B,EAC3B,UAKI,EAAE;IAEN,MAAM,EACJ,UAAU,GAAG,CAAC,EACd,OAAO,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,oBAAoB,EACzD,OAAO,GAAG,GAAG,EAAE,GAAE,CAAC,EAClB,YAAY,GAAG,2BAAmB,GACnC,GAAG,OAAO,CAAA;IAEX,IAAI,SAAS,GAAQ,IAAI,CAAA;IAEzB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;QACtD,IAAI,CAAC;YACH,OAAO,MAAM,SAAS,EAAE,CAAA;QAC1B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,SAAS,GAAG,K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AEhB,KAAK,EAAE,CAAA;gBACP,YAAY,EAAE,CAAA;YAChB,CAAC;QACH,CAAC,CAAA;QAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,CAAC,EAAE,CAAC,CAAA;;YAC9B,MAAM,EAAE,CAAA;IACf,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AA9BY,QAAA,QAAQ,YA8BpB;AAEM,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAA7D,QAAA,KAAK,SAAwD;AAE1E;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAC/B,OAAmB,EACnB,SAAiB,EACjB,iBAAyB,6BAA6B,SAAS,IAAI;IAEnE,IAAI,SAAyB,CAAA;IAE7B,MAAM,cAAc,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QACtD,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YAC1B,MAAM,CAAC,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC,CAAA;QACnC,CAAC,EAAE,SAAS,CAAC,CAAA;IACf,CAAC,CAAC,CAAA;IAEF,OAAO,OAAO,CAAC,IAAI,CAAC;QAClB,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YACtB,YAAY,CAAC,SAAS,CAAC,CAAA;YACvB,OAAO,MAAM,CAAA;QACf,CAAC,CAAC;QACF,cAAc;KACf,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -25,15 +25,23 @@ export type TagOpenNode = {
|
|
|
25
25
|
*/
|
|
26
26
|
attrs: string;
|
|
27
27
|
/**
|
|
28
|
-
* Whether the tag self-closes (tags of the form
|
|
28
|
+
* Whether the tag self-closes (tags of the form ``).
|
|
29
29
|
* Such tags will not be followed by a closing tag.
|
|
30
30
|
*/
|
|
31
31
|
isSelfClosing: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The original text of the tag, including angle brackets and attributes.
|
|
34
|
+
*/
|
|
35
|
+
rawTag: string;
|
|
32
36
|
};
|
|
33
37
|
/** Information about a closed tag */
|
|
34
38
|
export type TagCloseNode = {
|
|
35
39
|
/** Name of the tag that was closed. */
|
|
36
40
|
name: string;
|
|
41
|
+
/**
|
|
42
|
+
* The original text of the tag, including angle brackets.
|
|
43
|
+
*/
|
|
44
|
+
rawTag: string;
|
|
37
45
|
};
|
|
38
46
|
export type NextFunction = (err?: Error) => void;
|
|
39
47
|
export interface SaxyEvents {
|
|
@@ -66,7 +74,10 @@ export type TagSchema = {
|
|
|
66
74
|
* @throws If the string is malformed
|
|
67
75
|
* @return A map of attribute names to their values
|
|
68
76
|
*/
|
|
69
|
-
export declare const parseAttrs: (input: string) =>
|
|
77
|
+
export declare const parseAttrs: (input: string) => {
|
|
78
|
+
attrs: Record<string, string>;
|
|
79
|
+
errors: string[];
|
|
80
|
+
};
|
|
70
81
|
/**
|
|
71
82
|
* Parse an XML stream and emit events corresponding
|
|
72
83
|
* to the different tokens encountered.
|
|
@@ -76,7 +87,8 @@ export declare class Saxy extends Transform {
|
|
|
76
87
|
private _tagStack;
|
|
77
88
|
private _waiting;
|
|
78
89
|
private _schema;
|
|
79
|
-
private
|
|
90
|
+
private _entityBuffer;
|
|
91
|
+
private _textBuffer;
|
|
80
92
|
/**
|
|
81
93
|
* Parse a string of XML attributes to a map of attribute names
|
|
82
94
|
* to their values
|
|
@@ -85,7 +97,10 @@ export declare class Saxy extends Transform {
|
|
|
85
97
|
* @throws If the string is malformed
|
|
86
98
|
* @return A map of attribute names to their values
|
|
87
99
|
*/
|
|
88
|
-
static parseAttrs: (input: string) =>
|
|
100
|
+
static parseAttrs: (input: string) => {
|
|
101
|
+
attrs: Record<string, string>;
|
|
102
|
+
errors: string[];
|
|
103
|
+
};
|
|
89
104
|
/**
|
|
90
105
|
* Expand a piece of XML text by replacing all XML entities
|
|
91
106
|
* by their canonical value. Ignore invalid and unknown
|
|
@@ -142,7 +157,6 @@ export declare class Saxy extends Transform {
|
|
|
142
157
|
* corresponding event on the event emitter.
|
|
143
158
|
*
|
|
144
159
|
* @param node Information about the opened tag.
|
|
145
|
-
* @param rawTag The raw tag text including angle brackets
|
|
146
160
|
*/
|
|
147
161
|
private _handleTagOpening;
|
|
148
162
|
/**
|
package/dist/common/util/saxy.js
CHANGED
|
@@ -27,7 +27,8 @@ const Node = {
|
|
|
27
27
|
* @return The input string, expanded
|
|
28
28
|
*/
|
|
29
29
|
const parseEntities = (input) => {
|
|
30
|
-
let position = 0
|
|
30
|
+
let position = 0;
|
|
31
|
+
let next = 0;
|
|
31
32
|
const parts = [];
|
|
32
33
|
while ((next = input.indexOf('&', position)) !== -1) {
|
|
33
34
|
// remember anything there was before the entity
|
|
@@ -38,6 +39,7 @@ const parseEntities = (input) => {
|
|
|
38
39
|
// ignore unterminated entities
|
|
39
40
|
if (end === -1) {
|
|
40
41
|
parts.push(input.slice(next));
|
|
42
|
+
position = input.length; // NEW: Set position to end to avoid double-adding
|
|
41
43
|
break;
|
|
42
44
|
}
|
|
43
45
|
const entity = input.slice(next + 1, end);
|
|
@@ -104,40 +106,54 @@ const parseAttrs = (input) => {
|
|
|
104
106
|
const attrs = {};
|
|
105
107
|
const end = input.length;
|
|
106
108
|
let position = 0;
|
|
107
|
-
|
|
109
|
+
const errors = [];
|
|
110
|
+
const seekNextWhitespace = (pos) => {
|
|
111
|
+
pos += 1;
|
|
112
|
+
while (pos < end && !(0, string_1.isWhitespace)(input[pos])) {
|
|
113
|
+
pos += 1;
|
|
114
|
+
}
|
|
115
|
+
return pos;
|
|
116
|
+
};
|
|
117
|
+
attrLoop: while (position < end) {
|
|
108
118
|
// Skip all whitespace
|
|
109
119
|
if ((0, string_1.isWhitespace)(input[position])) {
|
|
110
120
|
position += 1;
|
|
111
121
|
continue;
|
|
112
122
|
}
|
|
113
123
|
// Check that the attribute name contains valid chars
|
|
114
|
-
|
|
124
|
+
let startName = position;
|
|
115
125
|
while (input[position] !== '=' && position < end) {
|
|
116
126
|
if ((0, string_1.isWhitespace)(input[position])) {
|
|
117
|
-
|
|
127
|
+
errors.push(`Attribute names may not contain whitespace: ${input.slice(startName, position)}`);
|
|
128
|
+
continue attrLoop;
|
|
118
129
|
}
|
|
119
130
|
position += 1;
|
|
120
131
|
}
|
|
121
132
|
// This is XML, so we need a value for the attribute
|
|
122
133
|
if (position === end) {
|
|
123
|
-
|
|
134
|
+
errors.push(`Expected a value for the attribute: ${input.slice(startName, position)}`);
|
|
135
|
+
break;
|
|
124
136
|
}
|
|
125
137
|
const attrName = input.slice(startName, position);
|
|
126
138
|
position += 1;
|
|
127
139
|
const startQuote = input[position];
|
|
128
140
|
position += 1;
|
|
129
141
|
if (startQuote !== '"' && startQuote !== "'") {
|
|
130
|
-
|
|
142
|
+
position = seekNextWhitespace(position);
|
|
143
|
+
errors.push(`Attribute values should be quoted: ${input.slice(startName, position)}`);
|
|
144
|
+
continue;
|
|
131
145
|
}
|
|
132
146
|
const endQuote = input.indexOf(startQuote, position);
|
|
133
147
|
if (endQuote === -1) {
|
|
134
|
-
|
|
148
|
+
position = seekNextWhitespace(position);
|
|
149
|
+
errors.push(`Unclosed attribute value: ${input.slice(startName, position)}`);
|
|
150
|
+
continue;
|
|
135
151
|
}
|
|
136
152
|
const attrValue = input.slice(position, endQuote);
|
|
137
153
|
attrs[attrName] = attrValue;
|
|
138
154
|
position = endQuote + 1;
|
|
139
155
|
}
|
|
140
|
-
return attrs;
|
|
156
|
+
return { attrs, errors };
|
|
141
157
|
};
|
|
142
158
|
exports.parseAttrs = parseAttrs;
|
|
143
159
|
/**
|
|
@@ -172,7 +188,8 @@ class Saxy extends readable_stream_1.Transform {
|
|
|
172
188
|
_tagStack;
|
|
173
189
|
_waiting;
|
|
174
190
|
_schema;
|
|
175
|
-
|
|
191
|
+
_entityBuffer;
|
|
192
|
+
_textBuffer; // NEW: Text buffer as class member
|
|
176
193
|
/**
|
|
177
194
|
* Parse a string of XML attributes to a map of attribute names
|
|
178
195
|
* to their values
|
|
@@ -207,7 +224,9 @@ class Saxy extends readable_stream_1.Transform {
|
|
|
207
224
|
// Store schema if provided
|
|
208
225
|
this._schema = schema || null;
|
|
209
226
|
// Pending entity for incomplete entities
|
|
210
|
-
this.
|
|
227
|
+
this._entityBuffer = null;
|
|
228
|
+
// Initialize text buffer
|
|
229
|
+
this._textBuffer = '';
|
|
211
230
|
}
|
|
212
231
|
/**
|
|
213
232
|
* Handle a chunk of data written into the stream.
|
|
@@ -235,9 +254,15 @@ class Saxy extends readable_stream_1.Transform {
|
|
|
235
254
|
callback(err);
|
|
236
255
|
return;
|
|
237
256
|
}
|
|
257
|
+
// Handle any remaining text buffer
|
|
258
|
+
if (this._textBuffer.length > 0) {
|
|
259
|
+
const parsedText = parseEntities(this._textBuffer);
|
|
260
|
+
this.emit(Node.text, { contents: parsedText });
|
|
261
|
+
this._textBuffer = '';
|
|
262
|
+
}
|
|
238
263
|
// Handle any remaining pending entity
|
|
239
|
-
if (this.
|
|
240
|
-
this.emit(Node.text, { contents: this.
|
|
264
|
+
if (this._entityBuffer) {
|
|
265
|
+
this.emit(Node.text, { contents: this._entityBuffer });
|
|
241
266
|
}
|
|
242
267
|
// Handle unclosed nodes
|
|
243
268
|
if (this._waiting !== null) {
|
|
@@ -311,9 +336,8 @@ class Saxy extends readable_stream_1.Transform {
|
|
|
311
336
|
* corresponding event on the event emitter.
|
|
312
337
|
*
|
|
313
338
|
* @param node Information about the opened tag.
|
|
314
|
-
* @param rawTag The raw tag text including angle brackets
|
|
315
339
|
*/
|
|
316
|
-
_handleTagOpening(node
|
|
340
|
+
_handleTagOpening(node) {
|
|
317
341
|
const { name } = node;
|
|
318
342
|
// If we have a schema, validate against it
|
|
319
343
|
if (this._schema) {
|
|
@@ -321,7 +345,7 @@ class Saxy extends readable_stream_1.Transform {
|
|
|
321
345
|
if (this._tagStack.length === 0) {
|
|
322
346
|
// Convert to text if not in schema
|
|
323
347
|
if (!this._schema[name]) {
|
|
324
|
-
this.emit(Node.text, { contents: rawTag });
|
|
348
|
+
this.emit(Node.text, { contents: node.rawTag });
|
|
325
349
|
return;
|
|
326
350
|
}
|
|
327
351
|
}
|
|
@@ -331,7 +355,7 @@ class Saxy extends readable_stream_1.Transform {
|
|
|
331
355
|
// Convert to text if parent not in schema or this tag not allowed as child
|
|
332
356
|
if (!this._schema[parentTag] ||
|
|
333
357
|
!this._schema[parentTag].includes(name)) {
|
|
334
|
-
this.emit(Node.text, { contents: rawTag });
|
|
358
|
+
this.emit(Node.text, { contents: node.rawTag });
|
|
335
359
|
return;
|
|
336
360
|
}
|
|
337
361
|
}
|
|
@@ -340,6 +364,12 @@ class Saxy extends readable_stream_1.Transform {
|
|
|
340
364
|
this._tagStack.push(node.name);
|
|
341
365
|
}
|
|
342
366
|
this.emit(Node.tagOpen, node);
|
|
367
|
+
if (node.isSelfClosing) {
|
|
368
|
+
this.emit(Node.tagClose, {
|
|
369
|
+
name: node.name,
|
|
370
|
+
rawTag: '',
|
|
371
|
+
});
|
|
372
|
+
}
|
|
343
373
|
}
|
|
344
374
|
/**
|
|
345
375
|
* Parse a XML chunk.
|
|
@@ -351,9 +381,9 @@ class Saxy extends readable_stream_1.Transform {
|
|
|
351
381
|
*/
|
|
352
382
|
_parseChunk(input, callback) {
|
|
353
383
|
// Handle pending entity if exists
|
|
354
|
-
if (this.
|
|
355
|
-
input = this.
|
|
356
|
-
this.
|
|
384
|
+
if (this._entityBuffer) {
|
|
385
|
+
input = this._entityBuffer + input;
|
|
386
|
+
this._entityBuffer = null;
|
|
357
387
|
}
|
|
358
388
|
// Use pending data if applicable and get out of waiting mode
|
|
359
389
|
const waitingData = this._unwait();
|
|
@@ -374,19 +404,24 @@ class Saxy extends readable_stream_1.Transform {
|
|
|
374
404
|
// more text data left, so we wait
|
|
375
405
|
if (nextTag === -1) {
|
|
376
406
|
let chunk = input.slice(chunkPos);
|
|
377
|
-
if (this._tagStack.length === 1 && chunk
|
|
407
|
+
if (this._tagStack.length === 1 && !chunk.trim()) {
|
|
378
408
|
chunk = '';
|
|
379
409
|
}
|
|
380
410
|
// Check for incomplete entity at end
|
|
381
411
|
const lastAmp = chunk.lastIndexOf('&');
|
|
382
412
|
if (lastAmp !== -1 && chunk.indexOf(';', lastAmp) === -1) {
|
|
383
|
-
//
|
|
384
|
-
|
|
385
|
-
|
|
413
|
+
// Only consider it a pending entity if it looks like the start of one
|
|
414
|
+
const nextChar = chunk[lastAmp + 1];
|
|
415
|
+
const isPotentialEntity = nextChar === '#' || // Numeric entity
|
|
416
|
+
/[a-zA-Z]/.test(nextChar); // Named entity
|
|
417
|
+
if (isPotentialEntity) {
|
|
418
|
+
// Store incomplete entity for next chunk
|
|
419
|
+
this._entityBuffer = chunk.slice(lastAmp);
|
|
420
|
+
chunk = chunk.slice(0, lastAmp);
|
|
421
|
+
}
|
|
386
422
|
}
|
|
387
423
|
if (chunk.length > 0) {
|
|
388
|
-
|
|
389
|
-
this.emit(Node.text, { contents: chunk });
|
|
424
|
+
this._textBuffer += chunk;
|
|
390
425
|
}
|
|
391
426
|
chunkPos = end;
|
|
392
427
|
break;
|
|
@@ -394,20 +429,31 @@ class Saxy extends readable_stream_1.Transform {
|
|
|
394
429
|
// A tag follows, so we can be confident that
|
|
395
430
|
// we have all the data needed for the TEXT node
|
|
396
431
|
let chunk = input.slice(chunkPos, nextTag);
|
|
397
|
-
if (this._tagStack.length === 1 && chunk
|
|
432
|
+
if (this._tagStack.length === 1 && !chunk.trim()) {
|
|
398
433
|
chunk = '';
|
|
399
434
|
}
|
|
400
435
|
// Check for incomplete entity at end
|
|
401
436
|
const lastAmp = chunk.lastIndexOf('&');
|
|
402
437
|
if (lastAmp !== -1 && chunk.indexOf(';', lastAmp) === -1) {
|
|
403
|
-
//
|
|
404
|
-
|
|
405
|
-
|
|
438
|
+
// Only consider it a pending entity if it looks like the start of one
|
|
439
|
+
const nextChar = chunk[lastAmp + 1];
|
|
440
|
+
const isPotentialEntity = nextChar === '#' || // Numeric entity
|
|
441
|
+
/[a-zA-Z]/.test(nextChar); // Named entity
|
|
442
|
+
if (isPotentialEntity) {
|
|
443
|
+
// Store incomplete entity for next chunk
|
|
444
|
+
this._entityBuffer = chunk.slice(lastAmp);
|
|
445
|
+
chunk = chunk.slice(0, lastAmp);
|
|
446
|
+
}
|
|
406
447
|
}
|
|
407
448
|
// Only emit non-whitespace text or text within a single tag (not between tags)
|
|
408
449
|
if (chunk.length > 0) {
|
|
409
|
-
|
|
410
|
-
|
|
450
|
+
this._textBuffer += chunk;
|
|
451
|
+
}
|
|
452
|
+
// We've reached a tag boundary, emit any buffered text
|
|
453
|
+
if (this._textBuffer.length > 0) {
|
|
454
|
+
const parsedText = parseEntities(this._textBuffer);
|
|
455
|
+
this.emit(Node.text, { contents: parsedText });
|
|
456
|
+
this._textBuffer = '';
|
|
411
457
|
}
|
|
412
458
|
chunkPos = nextTag;
|
|
413
459
|
}
|
|
@@ -447,10 +493,20 @@ class Saxy extends readable_stream_1.Transform {
|
|
|
447
493
|
}
|
|
448
494
|
}
|
|
449
495
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
496
|
+
if (tagName === stackedTagName) {
|
|
497
|
+
this._tagStack.pop();
|
|
498
|
+
}
|
|
499
|
+
// Only emit if the tag matches what we expect (or if there is no schema)
|
|
500
|
+
if (!this._schema || stackedTagName === tagName) {
|
|
501
|
+
this.emit(Node.tagClose, {
|
|
502
|
+
name: tagName,
|
|
503
|
+
rawTag: input.slice(chunkPos - 1, tagClose + 1),
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
// Emit as text if the tag doesn't match
|
|
508
|
+
const rawTag = input.slice(chunkPos - 1, tagClose + 1);
|
|
509
|
+
this.emit(Node.text, { contents: rawTag });
|
|
454
510
|
}
|
|
455
511
|
chunkPos = tagClose + 1;
|
|
456
512
|
continue;
|
|
@@ -468,7 +524,8 @@ class Saxy extends readable_stream_1.Transform {
|
|
|
468
524
|
name: input.slice(chunkPos, realTagClose),
|
|
469
525
|
attrs: '',
|
|
470
526
|
isSelfClosing,
|
|
471
|
-
|
|
527
|
+
rawTag,
|
|
528
|
+
});
|
|
472
529
|
}
|
|
473
530
|
else if (whitespace === 0) {
|
|
474
531
|
// Invalid tag starting with whitespace - emit as text
|
|
@@ -480,10 +537,17 @@ class Saxy extends readable_stream_1.Transform {
|
|
|
480
537
|
name: input.slice(chunkPos, chunkPos + whitespace),
|
|
481
538
|
attrs: input.slice(chunkPos + whitespace, realTagClose),
|
|
482
539
|
isSelfClosing,
|
|
483
|
-
|
|
540
|
+
rawTag,
|
|
541
|
+
});
|
|
484
542
|
}
|
|
485
543
|
chunkPos = tagClose + 1;
|
|
486
544
|
}
|
|
545
|
+
// Emit any buffered text at the end of the chunk if there's no pending entity
|
|
546
|
+
if (this._textBuffer.length > 0) {
|
|
547
|
+
const parsedText = parseEntities(this._textBuffer);
|
|
548
|
+
this.emit(Node.text, { contents: parsedText });
|
|
549
|
+
this._textBuffer = '';
|
|
550
|
+
}
|
|
487
551
|
callback();
|
|
488
552
|
}
|
|
489
553
|
/**
|