@inkeep/agents-cli 0.51.0 → 0.52.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.
- package/dist/agents-cli/package.js +6 -0
- package/dist/commands/config.js +1 -1
- package/dist/commands/dev.js +1 -1
- package/dist/commands/init.js +1 -1
- package/dist/commands/pull-v3/component-parser.js +4 -10
- package/dist/commands/pull-v4/agent-generator.js +274 -0
- package/dist/commands/pull-v4/artifact-component-generator.js +69 -0
- package/dist/commands/pull-v4/context-config-generator.js +264 -0
- package/dist/commands/pull-v4/credential-generator.js +30 -0
- package/dist/commands/pull-v4/data-component-generator.js +50 -0
- package/dist/commands/pull-v4/environment-generator.js +123 -0
- package/dist/commands/pull-v4/external-agent-generator.js +56 -0
- package/dist/commands/pull-v4/function-tool-generator.js +48 -0
- package/dist/commands/pull-v4/introspect/index.js +365 -0
- package/dist/commands/pull-v4/introspect/test-helpers.js +143 -0
- package/dist/commands/pull-v4/introspect-generator.js +691 -0
- package/dist/commands/pull-v4/mcp-tool-generator.js +91 -0
- package/dist/commands/pull-v4/module-merge.js +379 -0
- package/dist/commands/pull-v4/project-generator.js +101 -0
- package/dist/commands/pull-v4/status-component-generator.js +35 -0
- package/dist/commands/pull-v4/sub-agent-generator.js +168 -0
- package/dist/commands/pull-v4/trigger-generator.js +58 -0
- package/dist/commands/pull-v4/utils.js +219 -0
- package/dist/commands/push.js +1 -1
- package/dist/commands/update.js +2 -2
- package/dist/index.js +18 -44
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/array.js +18 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/base.js +180 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/character.js +8 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/css.js +12 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/json.js +60 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/line.js +37 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/sentence.js +31 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/word.js +118 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/index.js +11 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/patch/create.js +141 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/util/string.js +63 -0
- package/dist/utils/ci-environment.js +1 -1
- package/dist/utils/config.js +1 -1
- package/dist/utils/environment-loader.js +1 -1
- package/dist/utils/file-finder.js +1 -1
- package/dist/utils/mcp-runner.js +1 -1
- package/dist/utils/profile-config.js +1 -1
- package/dist/utils/profiles/profile-manager.js +1 -1
- package/dist/utils/project-directory.js +1 -1
- package/dist/utils/project-loader.js +1 -1
- package/dist/utils/version-check.js +6 -15
- package/package.json +5 -4
- package/dist/commands/pull-v3/component-updater.js +0 -768
- package/dist/commands/pull-v3/components/agent-generator.js +0 -255
- package/dist/commands/pull-v3/components/artifact-component-generator.js +0 -143
- package/dist/commands/pull-v3/components/context-config-generator.js +0 -190
- package/dist/commands/pull-v3/components/credential-generator.js +0 -89
- package/dist/commands/pull-v3/components/data-component-generator.js +0 -102
- package/dist/commands/pull-v3/components/environment-generator.js +0 -173
- package/dist/commands/pull-v3/components/external-agent-generator.js +0 -75
- package/dist/commands/pull-v3/components/function-tool-generator.js +0 -92
- package/dist/commands/pull-v3/components/mcp-tool-generator.js +0 -86
- package/dist/commands/pull-v3/components/project-generator.js +0 -157
- package/dist/commands/pull-v3/components/status-component-generator.js +0 -92
- package/dist/commands/pull-v3/components/sub-agent-generator.js +0 -295
- package/dist/commands/pull-v3/components/trigger-generator.js +0 -185
- package/dist/commands/pull-v3/index.js +0 -510
- package/dist/commands/pull-v3/introspect-generator.js +0 -286
- package/dist/commands/pull-v3/llm-content-merger.js +0 -192
- package/dist/commands/pull-v3/new-component-generator.js +0 -279
- package/dist/commands/pull-v3/project-index-generator.js +0 -32
- package/dist/commands/pull-v3/project-validator.js +0 -358
- package/dist/utils/url.js +0 -26
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
//#region ../node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/base.js
|
|
2
|
+
var Diff = class {
|
|
3
|
+
diff(oldStr, newStr, options = {}) {
|
|
4
|
+
let callback;
|
|
5
|
+
if (typeof options === "function") {
|
|
6
|
+
callback = options;
|
|
7
|
+
options = {};
|
|
8
|
+
} else if ("callback" in options) callback = options.callback;
|
|
9
|
+
const oldString = this.castInput(oldStr, options);
|
|
10
|
+
const newString = this.castInput(newStr, options);
|
|
11
|
+
const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
|
|
12
|
+
const newTokens = this.removeEmpty(this.tokenize(newString, options));
|
|
13
|
+
return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
|
|
14
|
+
}
|
|
15
|
+
diffWithOptionsObj(oldTokens, newTokens, options, callback) {
|
|
16
|
+
var _a;
|
|
17
|
+
const done = (value) => {
|
|
18
|
+
value = this.postProcess(value, options);
|
|
19
|
+
if (callback) {
|
|
20
|
+
setTimeout(function() {
|
|
21
|
+
callback(value);
|
|
22
|
+
}, 0);
|
|
23
|
+
return;
|
|
24
|
+
} else return value;
|
|
25
|
+
};
|
|
26
|
+
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
27
|
+
let editLength = 1;
|
|
28
|
+
let maxEditLength = newLen + oldLen;
|
|
29
|
+
if (options.maxEditLength != null) maxEditLength = Math.min(maxEditLength, options.maxEditLength);
|
|
30
|
+
const maxExecutionTime = (_a = options.timeout) !== null && _a !== void 0 ? _a : Infinity;
|
|
31
|
+
const abortAfterTimestamp = Date.now() + maxExecutionTime;
|
|
32
|
+
const bestPath = [{
|
|
33
|
+
oldPos: -1,
|
|
34
|
+
lastComponent: void 0
|
|
35
|
+
}];
|
|
36
|
+
let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
|
|
37
|
+
if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
|
|
38
|
+
let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
|
|
39
|
+
const execEditLength = () => {
|
|
40
|
+
for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
|
|
41
|
+
let basePath;
|
|
42
|
+
const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
|
|
43
|
+
if (removePath) bestPath[diagonalPath - 1] = void 0;
|
|
44
|
+
let canAdd = false;
|
|
45
|
+
if (addPath) {
|
|
46
|
+
const addPathNewPos = addPath.oldPos - diagonalPath;
|
|
47
|
+
canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
|
|
48
|
+
}
|
|
49
|
+
const canRemove = removePath && removePath.oldPos + 1 < oldLen;
|
|
50
|
+
if (!canAdd && !canRemove) {
|
|
51
|
+
bestPath[diagonalPath] = void 0;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) basePath = this.addToPath(addPath, true, false, 0, options);
|
|
55
|
+
else basePath = this.addToPath(removePath, false, true, 1, options);
|
|
56
|
+
newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
|
|
57
|
+
if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
|
|
58
|
+
else {
|
|
59
|
+
bestPath[diagonalPath] = basePath;
|
|
60
|
+
if (basePath.oldPos + 1 >= oldLen) maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
|
|
61
|
+
if (newPos + 1 >= newLen) minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
editLength++;
|
|
65
|
+
};
|
|
66
|
+
if (callback) (function exec() {
|
|
67
|
+
setTimeout(function() {
|
|
68
|
+
if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) return callback(void 0);
|
|
69
|
+
if (!execEditLength()) exec();
|
|
70
|
+
}, 0);
|
|
71
|
+
})();
|
|
72
|
+
else while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
|
|
73
|
+
const ret = execEditLength();
|
|
74
|
+
if (ret) return ret;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
addToPath(path, added, removed, oldPosInc, options) {
|
|
78
|
+
const last = path.lastComponent;
|
|
79
|
+
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) return {
|
|
80
|
+
oldPos: path.oldPos + oldPosInc,
|
|
81
|
+
lastComponent: {
|
|
82
|
+
count: last.count + 1,
|
|
83
|
+
added,
|
|
84
|
+
removed,
|
|
85
|
+
previousComponent: last.previousComponent
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
else return {
|
|
89
|
+
oldPos: path.oldPos + oldPosInc,
|
|
90
|
+
lastComponent: {
|
|
91
|
+
count: 1,
|
|
92
|
+
added,
|
|
93
|
+
removed,
|
|
94
|
+
previousComponent: last
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
extractCommon(basePath, newTokens, oldTokens, diagonalPath, options) {
|
|
99
|
+
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
100
|
+
let oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
|
|
101
|
+
while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
|
|
102
|
+
newPos++;
|
|
103
|
+
oldPos++;
|
|
104
|
+
commonCount++;
|
|
105
|
+
if (options.oneChangePerToken) basePath.lastComponent = {
|
|
106
|
+
count: 1,
|
|
107
|
+
previousComponent: basePath.lastComponent,
|
|
108
|
+
added: false,
|
|
109
|
+
removed: false
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (commonCount && !options.oneChangePerToken) basePath.lastComponent = {
|
|
113
|
+
count: commonCount,
|
|
114
|
+
previousComponent: basePath.lastComponent,
|
|
115
|
+
added: false,
|
|
116
|
+
removed: false
|
|
117
|
+
};
|
|
118
|
+
basePath.oldPos = oldPos;
|
|
119
|
+
return newPos;
|
|
120
|
+
}
|
|
121
|
+
equals(left, right, options) {
|
|
122
|
+
if (options.comparator) return options.comparator(left, right);
|
|
123
|
+
else return left === right || !!options.ignoreCase && left.toLowerCase() === right.toLowerCase();
|
|
124
|
+
}
|
|
125
|
+
removeEmpty(array) {
|
|
126
|
+
const ret = [];
|
|
127
|
+
for (let i = 0; i < array.length; i++) if (array[i]) ret.push(array[i]);
|
|
128
|
+
return ret;
|
|
129
|
+
}
|
|
130
|
+
castInput(value, options) {
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
tokenize(value, options) {
|
|
134
|
+
return Array.from(value);
|
|
135
|
+
}
|
|
136
|
+
join(chars) {
|
|
137
|
+
return chars.join("");
|
|
138
|
+
}
|
|
139
|
+
postProcess(changeObjects, options) {
|
|
140
|
+
return changeObjects;
|
|
141
|
+
}
|
|
142
|
+
get useLongestToken() {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
buildValues(lastComponent, newTokens, oldTokens) {
|
|
146
|
+
const components = [];
|
|
147
|
+
let nextComponent;
|
|
148
|
+
while (lastComponent) {
|
|
149
|
+
components.push(lastComponent);
|
|
150
|
+
nextComponent = lastComponent.previousComponent;
|
|
151
|
+
delete lastComponent.previousComponent;
|
|
152
|
+
lastComponent = nextComponent;
|
|
153
|
+
}
|
|
154
|
+
components.reverse();
|
|
155
|
+
const componentLen = components.length;
|
|
156
|
+
let componentPos = 0, newPos = 0, oldPos = 0;
|
|
157
|
+
for (; componentPos < componentLen; componentPos++) {
|
|
158
|
+
const component = components[componentPos];
|
|
159
|
+
if (!component.removed) {
|
|
160
|
+
if (!component.added && this.useLongestToken) {
|
|
161
|
+
let value = newTokens.slice(newPos, newPos + component.count);
|
|
162
|
+
value = value.map(function(value$1, i) {
|
|
163
|
+
const oldValue = oldTokens[oldPos + i];
|
|
164
|
+
return oldValue.length > value$1.length ? oldValue : value$1;
|
|
165
|
+
});
|
|
166
|
+
component.value = this.join(value);
|
|
167
|
+
} else component.value = this.join(newTokens.slice(newPos, newPos + component.count));
|
|
168
|
+
newPos += component.count;
|
|
169
|
+
if (!component.added) oldPos += component.count;
|
|
170
|
+
} else {
|
|
171
|
+
component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
|
|
172
|
+
oldPos += component.count;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return components;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
//#endregion
|
|
180
|
+
export { Diff as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Diff from "./base.js";
|
|
2
|
+
|
|
3
|
+
//#region ../node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/css.js
|
|
4
|
+
var CssDiff = class extends Diff {
|
|
5
|
+
tokenize(value) {
|
|
6
|
+
return value.split(/([{}:;,]|\s+)/);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
const cssDiff = new CssDiff();
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import Diff from "./base.js";
|
|
2
|
+
import { tokenize } from "./line.js";
|
|
3
|
+
|
|
4
|
+
//#region ../node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/json.js
|
|
5
|
+
var JsonDiff = class extends Diff {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.tokenize = tokenize;
|
|
9
|
+
}
|
|
10
|
+
get useLongestToken() {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
castInput(value, options) {
|
|
14
|
+
const { undefinedReplacement, stringifyReplacer = (k, v) => typeof v === "undefined" ? undefinedReplacement : v } = options;
|
|
15
|
+
return typeof value === "string" ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), null, " ");
|
|
16
|
+
}
|
|
17
|
+
equals(left, right, options) {
|
|
18
|
+
return super.equals(left.replace(/,([\r\n])/g, "$1"), right.replace(/,([\r\n])/g, "$1"), options);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const jsonDiff = new JsonDiff();
|
|
22
|
+
function canonicalize(obj, stack, replacementStack, replacer, key) {
|
|
23
|
+
stack = stack || [];
|
|
24
|
+
replacementStack = replacementStack || [];
|
|
25
|
+
if (replacer) obj = replacer(key === void 0 ? "" : key, obj);
|
|
26
|
+
let i;
|
|
27
|
+
for (i = 0; i < stack.length; i += 1) if (stack[i] === obj) return replacementStack[i];
|
|
28
|
+
let canonicalizedObj;
|
|
29
|
+
if ("[object Array]" === Object.prototype.toString.call(obj)) {
|
|
30
|
+
stack.push(obj);
|
|
31
|
+
canonicalizedObj = new Array(obj.length);
|
|
32
|
+
replacementStack.push(canonicalizedObj);
|
|
33
|
+
for (i = 0; i < obj.length; i += 1) canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, String(i));
|
|
34
|
+
stack.pop();
|
|
35
|
+
replacementStack.pop();
|
|
36
|
+
return canonicalizedObj;
|
|
37
|
+
}
|
|
38
|
+
if (obj && obj.toJSON) obj = obj.toJSON();
|
|
39
|
+
if (typeof obj === "object" && obj !== null) {
|
|
40
|
+
stack.push(obj);
|
|
41
|
+
canonicalizedObj = {};
|
|
42
|
+
replacementStack.push(canonicalizedObj);
|
|
43
|
+
const sortedKeys = [];
|
|
44
|
+
let key$1;
|
|
45
|
+
for (key$1 in obj)
|
|
46
|
+
/* istanbul ignore else */
|
|
47
|
+
if (Object.prototype.hasOwnProperty.call(obj, key$1)) sortedKeys.push(key$1);
|
|
48
|
+
sortedKeys.sort();
|
|
49
|
+
for (i = 0; i < sortedKeys.length; i += 1) {
|
|
50
|
+
key$1 = sortedKeys[i];
|
|
51
|
+
canonicalizedObj[key$1] = canonicalize(obj[key$1], stack, replacementStack, replacer, key$1);
|
|
52
|
+
}
|
|
53
|
+
stack.pop();
|
|
54
|
+
replacementStack.pop();
|
|
55
|
+
} else canonicalizedObj = obj;
|
|
56
|
+
return canonicalizedObj;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { canonicalize };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Diff from "./base.js";
|
|
2
|
+
|
|
3
|
+
//#region ../node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/line.js
|
|
4
|
+
var LineDiff = class extends Diff {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.tokenize = tokenize;
|
|
8
|
+
}
|
|
9
|
+
equals(left, right, options) {
|
|
10
|
+
if (options.ignoreWhitespace) {
|
|
11
|
+
if (!options.newlineIsToken || !left.includes("\n")) left = left.trim();
|
|
12
|
+
if (!options.newlineIsToken || !right.includes("\n")) right = right.trim();
|
|
13
|
+
} else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
|
|
14
|
+
if (left.endsWith("\n")) left = left.slice(0, -1);
|
|
15
|
+
if (right.endsWith("\n")) right = right.slice(0, -1);
|
|
16
|
+
}
|
|
17
|
+
return super.equals(left, right, options);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const lineDiff = new LineDiff();
|
|
21
|
+
function diffLines(oldStr, newStr, options) {
|
|
22
|
+
return lineDiff.diff(oldStr, newStr, options);
|
|
23
|
+
}
|
|
24
|
+
function tokenize(value, options) {
|
|
25
|
+
if (options.stripTrailingCr) value = value.replace(/\r\n/g, "\n");
|
|
26
|
+
const retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
|
|
27
|
+
if (!linesAndNewlines[linesAndNewlines.length - 1]) linesAndNewlines.pop();
|
|
28
|
+
for (let i = 0; i < linesAndNewlines.length; i++) {
|
|
29
|
+
const line = linesAndNewlines[i];
|
|
30
|
+
if (i % 2 && !options.newlineIsToken) retLines[retLines.length - 1] += line;
|
|
31
|
+
else retLines.push(line);
|
|
32
|
+
}
|
|
33
|
+
return retLines;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { diffLines, lineDiff, tokenize };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Diff from "./base.js";
|
|
2
|
+
|
|
3
|
+
//#region ../node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/sentence.js
|
|
4
|
+
function isSentenceEndPunct(char) {
|
|
5
|
+
return char == "." || char == "!" || char == "?";
|
|
6
|
+
}
|
|
7
|
+
var SentenceDiff = class extends Diff {
|
|
8
|
+
tokenize(value) {
|
|
9
|
+
var _a;
|
|
10
|
+
const result = [];
|
|
11
|
+
let tokenStartI = 0;
|
|
12
|
+
for (let i = 0; i < value.length; i++) {
|
|
13
|
+
if (i == value.length - 1) {
|
|
14
|
+
result.push(value.slice(tokenStartI));
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
if (isSentenceEndPunct(value[i]) && value[i + 1].match(/\s/)) {
|
|
18
|
+
result.push(value.slice(tokenStartI, i + 1));
|
|
19
|
+
i = tokenStartI = i + 1;
|
|
20
|
+
while ((_a = value[i + 1]) === null || _a === void 0 ? void 0 : _a.match(/\s/)) i++;
|
|
21
|
+
result.push(value.slice(tokenStartI, i + 1));
|
|
22
|
+
tokenStartI = i + 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const sentenceDiff = new SentenceDiff();
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import Diff from "./base.js";
|
|
2
|
+
import { leadingWs, longestCommonPrefix, longestCommonSuffix, maximumOverlap, removePrefix, removeSuffix, replacePrefix, replaceSuffix, trailingWs } from "../util/string.js";
|
|
3
|
+
|
|
4
|
+
//#region ../node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/word.js
|
|
5
|
+
const extendedWordChars = "a-zA-Z0-9_\\u{AD}\\u{C0}-\\u{D6}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}";
|
|
6
|
+
const tokenizeIncludingWhitespace = new RegExp(`[${extendedWordChars}]+|\\s+|[^${extendedWordChars}]`, "ug");
|
|
7
|
+
var WordDiff = class extends Diff {
|
|
8
|
+
equals(left, right, options) {
|
|
9
|
+
if (options.ignoreCase) {
|
|
10
|
+
left = left.toLowerCase();
|
|
11
|
+
right = right.toLowerCase();
|
|
12
|
+
}
|
|
13
|
+
return left.trim() === right.trim();
|
|
14
|
+
}
|
|
15
|
+
tokenize(value, options = {}) {
|
|
16
|
+
let parts;
|
|
17
|
+
if (options.intlSegmenter) {
|
|
18
|
+
const segmenter = options.intlSegmenter;
|
|
19
|
+
if (segmenter.resolvedOptions().granularity != "word") throw new Error("The segmenter passed must have a granularity of \"word\"");
|
|
20
|
+
parts = [];
|
|
21
|
+
for (const segmentObj of Array.from(segmenter.segment(value))) {
|
|
22
|
+
const segment = segmentObj.segment;
|
|
23
|
+
if (parts.length && /\s/.test(parts[parts.length - 1]) && /\s/.test(segment)) parts[parts.length - 1] += segment;
|
|
24
|
+
else parts.push(segment);
|
|
25
|
+
}
|
|
26
|
+
} else parts = value.match(tokenizeIncludingWhitespace) || [];
|
|
27
|
+
const tokens = [];
|
|
28
|
+
let prevPart = null;
|
|
29
|
+
parts.forEach((part) => {
|
|
30
|
+
if (/\s/.test(part)) if (prevPart == null) tokens.push(part);
|
|
31
|
+
else tokens.push(tokens.pop() + part);
|
|
32
|
+
else if (prevPart != null && /\s/.test(prevPart)) if (tokens[tokens.length - 1] == prevPart) tokens.push(tokens.pop() + part);
|
|
33
|
+
else tokens.push(prevPart + part);
|
|
34
|
+
else tokens.push(part);
|
|
35
|
+
prevPart = part;
|
|
36
|
+
});
|
|
37
|
+
return tokens;
|
|
38
|
+
}
|
|
39
|
+
join(tokens) {
|
|
40
|
+
return tokens.map((token, i) => {
|
|
41
|
+
if (i == 0) return token;
|
|
42
|
+
else return token.replace(/^\s+/, "");
|
|
43
|
+
}).join("");
|
|
44
|
+
}
|
|
45
|
+
postProcess(changes, options) {
|
|
46
|
+
if (!changes || options.oneChangePerToken) return changes;
|
|
47
|
+
let lastKeep = null;
|
|
48
|
+
let insertion = null;
|
|
49
|
+
let deletion = null;
|
|
50
|
+
changes.forEach((change) => {
|
|
51
|
+
if (change.added) insertion = change;
|
|
52
|
+
else if (change.removed) deletion = change;
|
|
53
|
+
else {
|
|
54
|
+
if (insertion || deletion) dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, change);
|
|
55
|
+
lastKeep = change;
|
|
56
|
+
insertion = null;
|
|
57
|
+
deletion = null;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
if (insertion || deletion) dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, null);
|
|
61
|
+
return changes;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const wordDiff = new WordDiff();
|
|
65
|
+
function dedupeWhitespaceInChangeObjects(startKeep, deletion, insertion, endKeep) {
|
|
66
|
+
if (deletion && insertion) {
|
|
67
|
+
const oldWsPrefix = leadingWs(deletion.value);
|
|
68
|
+
const oldWsSuffix = trailingWs(deletion.value);
|
|
69
|
+
const newWsPrefix = leadingWs(insertion.value);
|
|
70
|
+
const newWsSuffix = trailingWs(insertion.value);
|
|
71
|
+
if (startKeep) {
|
|
72
|
+
const commonWsPrefix = longestCommonPrefix(oldWsPrefix, newWsPrefix);
|
|
73
|
+
startKeep.value = replaceSuffix(startKeep.value, newWsPrefix, commonWsPrefix);
|
|
74
|
+
deletion.value = removePrefix(deletion.value, commonWsPrefix);
|
|
75
|
+
insertion.value = removePrefix(insertion.value, commonWsPrefix);
|
|
76
|
+
}
|
|
77
|
+
if (endKeep) {
|
|
78
|
+
const commonWsSuffix = longestCommonSuffix(oldWsSuffix, newWsSuffix);
|
|
79
|
+
endKeep.value = replacePrefix(endKeep.value, newWsSuffix, commonWsSuffix);
|
|
80
|
+
deletion.value = removeSuffix(deletion.value, commonWsSuffix);
|
|
81
|
+
insertion.value = removeSuffix(insertion.value, commonWsSuffix);
|
|
82
|
+
}
|
|
83
|
+
} else if (insertion) {
|
|
84
|
+
if (startKeep) {
|
|
85
|
+
const ws = leadingWs(insertion.value);
|
|
86
|
+
insertion.value = insertion.value.substring(ws.length);
|
|
87
|
+
}
|
|
88
|
+
if (endKeep) {
|
|
89
|
+
const ws = leadingWs(endKeep.value);
|
|
90
|
+
endKeep.value = endKeep.value.substring(ws.length);
|
|
91
|
+
}
|
|
92
|
+
} else if (startKeep && endKeep) {
|
|
93
|
+
const newWsFull = leadingWs(endKeep.value), delWsStart = leadingWs(deletion.value), delWsEnd = trailingWs(deletion.value);
|
|
94
|
+
const newWsStart = longestCommonPrefix(newWsFull, delWsStart);
|
|
95
|
+
deletion.value = removePrefix(deletion.value, newWsStart);
|
|
96
|
+
const newWsEnd = longestCommonSuffix(removePrefix(newWsFull, newWsStart), delWsEnd);
|
|
97
|
+
deletion.value = removeSuffix(deletion.value, newWsEnd);
|
|
98
|
+
endKeep.value = replacePrefix(endKeep.value, newWsFull, newWsEnd);
|
|
99
|
+
startKeep.value = replaceSuffix(startKeep.value, newWsFull, newWsFull.slice(0, newWsFull.length - newWsEnd.length));
|
|
100
|
+
} else if (endKeep) {
|
|
101
|
+
const endKeepWsPrefix = leadingWs(endKeep.value);
|
|
102
|
+
const overlap = maximumOverlap(trailingWs(deletion.value), endKeepWsPrefix);
|
|
103
|
+
deletion.value = removeSuffix(deletion.value, overlap);
|
|
104
|
+
} else if (startKeep) {
|
|
105
|
+
const overlap = maximumOverlap(trailingWs(startKeep.value), leadingWs(deletion.value));
|
|
106
|
+
deletion.value = removePrefix(deletion.value, overlap);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
var WordsWithSpaceDiff = class extends Diff {
|
|
110
|
+
tokenize(value) {
|
|
111
|
+
const regex = new RegExp(`(\\r?\\n)|[${extendedWordChars}]+|[^\\S\\n\\r]+|[^${extendedWordChars}]`, "ug");
|
|
112
|
+
return value.match(regex) || [];
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const wordsWithSpaceDiff = new WordsWithSpaceDiff();
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
export { };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Diff from "./diff/base.js";
|
|
2
|
+
import "./diff/character.js";
|
|
3
|
+
import "./diff/word.js";
|
|
4
|
+
import { diffLines, lineDiff } from "./diff/line.js";
|
|
5
|
+
import "./diff/sentence.js";
|
|
6
|
+
import "./diff/css.js";
|
|
7
|
+
import { canonicalize } from "./diff/json.js";
|
|
8
|
+
import "./diff/array.js";
|
|
9
|
+
import { INCLUDE_HEADERS, createTwoFilesPatch, formatPatch, structuredPatch } from "./patch/create.js";
|
|
10
|
+
|
|
11
|
+
export { };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { diffLines } from "../diff/line.js";
|
|
2
|
+
|
|
3
|
+
//#region ../node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/patch/create.js
|
|
4
|
+
const INCLUDE_HEADERS = {
|
|
5
|
+
includeIndex: true,
|
|
6
|
+
includeUnderline: true,
|
|
7
|
+
includeFileHeaders: true
|
|
8
|
+
};
|
|
9
|
+
function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
10
|
+
let optionsObj;
|
|
11
|
+
if (!options) optionsObj = {};
|
|
12
|
+
else if (typeof options === "function") optionsObj = { callback: options };
|
|
13
|
+
else optionsObj = options;
|
|
14
|
+
if (typeof optionsObj.context === "undefined") optionsObj.context = 4;
|
|
15
|
+
const context = optionsObj.context;
|
|
16
|
+
if (optionsObj.newlineIsToken) throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");
|
|
17
|
+
if (!optionsObj.callback) return diffLinesResultToPatch(diffLines(oldStr, newStr, optionsObj));
|
|
18
|
+
else {
|
|
19
|
+
const { callback } = optionsObj;
|
|
20
|
+
diffLines(oldStr, newStr, Object.assign(Object.assign({}, optionsObj), { callback: (diff) => {
|
|
21
|
+
callback(diffLinesResultToPatch(diff));
|
|
22
|
+
} }));
|
|
23
|
+
}
|
|
24
|
+
function diffLinesResultToPatch(diff) {
|
|
25
|
+
if (!diff) return;
|
|
26
|
+
diff.push({
|
|
27
|
+
value: "",
|
|
28
|
+
lines: []
|
|
29
|
+
});
|
|
30
|
+
function contextLines(lines) {
|
|
31
|
+
return lines.map(function(entry) {
|
|
32
|
+
return " " + entry;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const hunks = [];
|
|
36
|
+
let oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1;
|
|
37
|
+
for (let i = 0; i < diff.length; i++) {
|
|
38
|
+
const current = diff[i], lines = current.lines || splitLines(current.value);
|
|
39
|
+
current.lines = lines;
|
|
40
|
+
if (current.added || current.removed) {
|
|
41
|
+
if (!oldRangeStart) {
|
|
42
|
+
const prev = diff[i - 1];
|
|
43
|
+
oldRangeStart = oldLine;
|
|
44
|
+
newRangeStart = newLine;
|
|
45
|
+
if (prev) {
|
|
46
|
+
curRange = context > 0 ? contextLines(prev.lines.slice(-context)) : [];
|
|
47
|
+
oldRangeStart -= curRange.length;
|
|
48
|
+
newRangeStart -= curRange.length;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const line of lines) curRange.push((current.added ? "+" : "-") + line);
|
|
52
|
+
if (current.added) newLine += lines.length;
|
|
53
|
+
else oldLine += lines.length;
|
|
54
|
+
} else {
|
|
55
|
+
if (oldRangeStart) if (lines.length <= context * 2 && i < diff.length - 2) for (const line of contextLines(lines)) curRange.push(line);
|
|
56
|
+
else {
|
|
57
|
+
const contextSize = Math.min(lines.length, context);
|
|
58
|
+
for (const line of contextLines(lines.slice(0, contextSize))) curRange.push(line);
|
|
59
|
+
const hunk = {
|
|
60
|
+
oldStart: oldRangeStart,
|
|
61
|
+
oldLines: oldLine - oldRangeStart + contextSize,
|
|
62
|
+
newStart: newRangeStart,
|
|
63
|
+
newLines: newLine - newRangeStart + contextSize,
|
|
64
|
+
lines: curRange
|
|
65
|
+
};
|
|
66
|
+
hunks.push(hunk);
|
|
67
|
+
oldRangeStart = 0;
|
|
68
|
+
newRangeStart = 0;
|
|
69
|
+
curRange = [];
|
|
70
|
+
}
|
|
71
|
+
oldLine += lines.length;
|
|
72
|
+
newLine += lines.length;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (const hunk of hunks) for (let i = 0; i < hunk.lines.length; i++) if (hunk.lines[i].endsWith("\n")) hunk.lines[i] = hunk.lines[i].slice(0, -1);
|
|
76
|
+
else {
|
|
77
|
+
hunk.lines.splice(i + 1, 0, "\");
|
|
78
|
+
i++;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
oldFileName,
|
|
82
|
+
newFileName,
|
|
83
|
+
oldHeader,
|
|
84
|
+
newHeader,
|
|
85
|
+
hunks
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* creates a unified diff patch.
|
|
91
|
+
* @param patch either a single structured patch object (as returned by `structuredPatch`) or an array of them (as returned by `parsePatch`)
|
|
92
|
+
*/
|
|
93
|
+
function formatPatch(patch, headerOptions) {
|
|
94
|
+
if (!headerOptions) headerOptions = INCLUDE_HEADERS;
|
|
95
|
+
if (Array.isArray(patch)) {
|
|
96
|
+
if (patch.length > 1 && !headerOptions.includeFileHeaders) throw new Error("Cannot omit file headers on a multi-file patch. (The result would be unparseable; how would a tool trying to apply the patch know which changes are to which file?)");
|
|
97
|
+
return patch.map((p) => formatPatch(p, headerOptions)).join("\n");
|
|
98
|
+
}
|
|
99
|
+
const ret = [];
|
|
100
|
+
if (headerOptions.includeIndex && patch.oldFileName == patch.newFileName) ret.push("Index: " + patch.oldFileName);
|
|
101
|
+
if (headerOptions.includeUnderline) ret.push("===================================================================");
|
|
102
|
+
if (headerOptions.includeFileHeaders) {
|
|
103
|
+
ret.push("--- " + patch.oldFileName + (typeof patch.oldHeader === "undefined" ? "" : " " + patch.oldHeader));
|
|
104
|
+
ret.push("+++ " + patch.newFileName + (typeof patch.newHeader === "undefined" ? "" : " " + patch.newHeader));
|
|
105
|
+
}
|
|
106
|
+
for (let i = 0; i < patch.hunks.length; i++) {
|
|
107
|
+
const hunk = patch.hunks[i];
|
|
108
|
+
if (hunk.oldLines === 0) hunk.oldStart -= 1;
|
|
109
|
+
if (hunk.newLines === 0) hunk.newStart -= 1;
|
|
110
|
+
ret.push("@@ -" + hunk.oldStart + "," + hunk.oldLines + " +" + hunk.newStart + "," + hunk.newLines + " @@");
|
|
111
|
+
for (const line of hunk.lines) ret.push(line);
|
|
112
|
+
}
|
|
113
|
+
return ret.join("\n") + "\n";
|
|
114
|
+
}
|
|
115
|
+
function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
116
|
+
if (typeof options === "function") options = { callback: options };
|
|
117
|
+
if (!(options === null || options === void 0 ? void 0 : options.callback)) {
|
|
118
|
+
const patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
|
|
119
|
+
if (!patchObj) return;
|
|
120
|
+
return formatPatch(patchObj, options === null || options === void 0 ? void 0 : options.headerOptions);
|
|
121
|
+
} else {
|
|
122
|
+
const { callback } = options;
|
|
123
|
+
structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, Object.assign(Object.assign({}, options), { callback: (patchObj) => {
|
|
124
|
+
if (!patchObj) callback(void 0);
|
|
125
|
+
else callback(formatPatch(patchObj, options.headerOptions));
|
|
126
|
+
} }));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Split `text` into an array of lines, including the trailing newline character (where present)
|
|
131
|
+
*/
|
|
132
|
+
function splitLines(text) {
|
|
133
|
+
const hasTrailingNl = text.endsWith("\n");
|
|
134
|
+
const result = text.split("\n").map((line) => line + "\n");
|
|
135
|
+
if (hasTrailingNl) result.pop();
|
|
136
|
+
else result.push(result.pop().slice(0, -1));
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
export { INCLUDE_HEADERS, createTwoFilesPatch, formatPatch, structuredPatch };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//#region ../node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/util/string.js
|
|
2
|
+
function longestCommonPrefix(str1, str2) {
|
|
3
|
+
let i;
|
|
4
|
+
for (i = 0; i < str1.length && i < str2.length; i++) if (str1[i] != str2[i]) return str1.slice(0, i);
|
|
5
|
+
return str1.slice(0, i);
|
|
6
|
+
}
|
|
7
|
+
function longestCommonSuffix(str1, str2) {
|
|
8
|
+
let i;
|
|
9
|
+
if (!str1 || !str2 || str1[str1.length - 1] != str2[str2.length - 1]) return "";
|
|
10
|
+
for (i = 0; i < str1.length && i < str2.length; i++) if (str1[str1.length - (i + 1)] != str2[str2.length - (i + 1)]) return str1.slice(-i);
|
|
11
|
+
return str1.slice(-i);
|
|
12
|
+
}
|
|
13
|
+
function replacePrefix(string, oldPrefix, newPrefix) {
|
|
14
|
+
if (string.slice(0, oldPrefix.length) != oldPrefix) throw Error(`string ${JSON.stringify(string)} doesn't start with prefix ${JSON.stringify(oldPrefix)}; this is a bug`);
|
|
15
|
+
return newPrefix + string.slice(oldPrefix.length);
|
|
16
|
+
}
|
|
17
|
+
function replaceSuffix(string, oldSuffix, newSuffix) {
|
|
18
|
+
if (!oldSuffix) return string + newSuffix;
|
|
19
|
+
if (string.slice(-oldSuffix.length) != oldSuffix) throw Error(`string ${JSON.stringify(string)} doesn't end with suffix ${JSON.stringify(oldSuffix)}; this is a bug`);
|
|
20
|
+
return string.slice(0, -oldSuffix.length) + newSuffix;
|
|
21
|
+
}
|
|
22
|
+
function removePrefix(string, oldPrefix) {
|
|
23
|
+
return replacePrefix(string, oldPrefix, "");
|
|
24
|
+
}
|
|
25
|
+
function removeSuffix(string, oldSuffix) {
|
|
26
|
+
return replaceSuffix(string, oldSuffix, "");
|
|
27
|
+
}
|
|
28
|
+
function maximumOverlap(string1, string2) {
|
|
29
|
+
return string2.slice(0, overlapCount(string1, string2));
|
|
30
|
+
}
|
|
31
|
+
function overlapCount(a, b) {
|
|
32
|
+
let startA = 0;
|
|
33
|
+
if (a.length > b.length) startA = a.length - b.length;
|
|
34
|
+
let endB = b.length;
|
|
35
|
+
if (a.length < b.length) endB = a.length;
|
|
36
|
+
const map = Array(endB);
|
|
37
|
+
let k = 0;
|
|
38
|
+
map[0] = 0;
|
|
39
|
+
for (let j = 1; j < endB; j++) {
|
|
40
|
+
if (b[j] == b[k]) map[j] = map[k];
|
|
41
|
+
else map[j] = k;
|
|
42
|
+
while (k > 0 && b[j] != b[k]) k = map[k];
|
|
43
|
+
if (b[j] == b[k]) k++;
|
|
44
|
+
}
|
|
45
|
+
k = 0;
|
|
46
|
+
for (let i = startA; i < a.length; i++) {
|
|
47
|
+
while (k > 0 && a[i] != b[k]) k = map[k];
|
|
48
|
+
if (a[i] == b[k]) k++;
|
|
49
|
+
}
|
|
50
|
+
return k;
|
|
51
|
+
}
|
|
52
|
+
function trailingWs(string) {
|
|
53
|
+
let i;
|
|
54
|
+
for (i = string.length - 1; i >= 0; i--) if (!string[i].match(/\s/)) break;
|
|
55
|
+
return string.substring(i + 1);
|
|
56
|
+
}
|
|
57
|
+
function leadingWs(string) {
|
|
58
|
+
const match = string.match(/^\s*/);
|
|
59
|
+
return match ? match[0] : "";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { leadingWs, longestCommonPrefix, longestCommonSuffix, maximumOverlap, removePrefix, removeSuffix, replacePrefix, replaceSuffix, trailingWs };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { checkKeychainAvailability } from "./credentials.js";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
2
|
import { join } from "node:path";
|
|
4
3
|
import chalk from "chalk";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
5
|
import { homedir } from "node:os";
|
|
6
6
|
|
|
7
7
|
//#region src/utils/ci-environment.ts
|