leos-agent 7.0.0 → 10.2.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/README.md +544 -28
- package/commands/handoff.md +11 -0
- package/commands/handon.md +10 -0
- package/commands/review-pr.md +9 -0
- package/commands-claude/watch-review.md +9 -0
- package/index.js +12 -0
- package/package.json +29 -14
- package/payload/codex-agents/leo-executor.toml +36 -0
- package/payload/codex-agents/leo-runner.toml +28 -0
- package/rules/preferences.md +97 -0
- package/scripts/check.py +244 -0
- package/scripts/ghreview.py +17 -3
- package/scripts/handoff.py +183 -0
- package/scripts/leo-install.py +509 -0
- package/scripts/measure_context.py +113 -0
- package/scripts/publish-npm.py +138 -0
- package/scripts/watch_review.py +169 -0
- package/skills/doctor/SKILL.md +73 -115
- package/skills/doctor/agents/openai.yaml +5 -0
- package/skills/handoff/SKILL.md +99 -0
- package/skills/handoff/agents/openai.yaml +5 -0
- package/skills/handon/SKILL.md +61 -0
- package/skills/install/SKILL.md +79 -0
- package/skills/install/agents/openai.yaml +5 -0
- package/skills/review-pr/SKILL.md +59 -318
- package/skills/review-pr/reference/lenses.md +67 -0
- package/skills/review-pr/reference/procedure.md +348 -0
- package/skills-claude/attach-pr/SKILL.md +178 -0
- package/skills-claude/watch-review/SKILL.md +91 -0
- package/adapters/cursor/agents/executor.md +0 -17
- package/adapters/cursor/agents/expert.md +0 -70
- package/adapters/cursor/agents/explore.md +0 -16
- package/adapters/cursor/agents/implementer.md +0 -18
- package/adapters/cursor/agents/investigator.md +0 -18
- package/adapters/cursor/agents/planner.md +0 -28
- package/adapters/cursor/agents/review-lens.md +0 -22
- package/adapters/cursor/agents/reviewer.md +0 -34
- package/adapters/opencode/agents.json +0 -105
- package/adapters/opencode/plugin.js +0 -576
- package/config/MCP_PINS.md +0 -17
- package/config/models.json +0 -676
- package/hooks/bash-guard.py +0 -583
- package/hooks/cursor-guard.py +0 -84
- package/hooks/hooks-cursor.json +0 -11
- package/hooks/hooks.json +0 -20
- package/hooks/session-start.py +0 -148
- package/roles/executor.md +0 -15
- package/roles/expert.md +0 -67
- package/roles/explore.md +0 -13
- package/roles/implementer.md +0 -16
- package/roles/investigator.md +0 -15
- package/roles/planner.md +0 -25
- package/roles/review-lens.md +0 -20
- package/roles/reviewer.md +0 -31
- package/scripts/doctor.py +0 -520
- package/scripts/jsonc_bridge.cjs +0 -23
- package/scripts/memory.py +0 -744
- package/scripts/render_adapters.py +0 -508
- package/scripts/setup.py +0 -1753
- package/settings.json +0 -7
- package/skills/.gitkeep +0 -0
- package/skills/brainstorming/SKILL.md +0 -111
- package/skills/debugging/SKILL.md +0 -100
- package/skills/delegation/SKILL.md +0 -143
- package/skills/executing-plans/SKILL.md +0 -117
- package/skills/finishing-a-branch/SKILL.md +0 -125
- package/skills/freshness/SKILL.md +0 -131
- package/skills/memory/SKILL.md +0 -154
- package/skills/resolve-ticket/SKILL.md +0 -275
- package/skills/setup/SKILL.md +0 -199
- package/skills/setup/agents/openai.yaml +0 -5
- package/skills/test-first/SKILL.md +0 -92
- package/skills/using-leo/SKILL.md +0 -101
- package/skills/using-leo/references/claude-mapping.md +0 -33
- package/skills/using-leo/references/codex-mapping.md +0 -33
- package/skills/using-leo/references/cursor-mapping.md +0 -35
- package/skills/using-leo/references/hermes-mapping.md +0 -37
- package/skills/using-leo/references/opencode-mapping.md +0 -39
- package/skills/verification/SKILL.md +0 -110
- package/skills/visual-verification/SKILL.md +0 -115
- package/skills/watch-review/SKILL.md +0 -128
- package/skills/watch-review/agents/openai.yaml +0 -5
- package/skills/worktrees/SKILL.md +0 -131
- package/skills/writing-plans/SKILL.md +0 -97
- package/skills/writing-skills/SKILL.md +0 -141
- package/vendor/jsonc-parser-3.3.1/LICENSE.md +0 -21
- package/vendor/jsonc-parser-3.3.1/README.md +0 -26
- package/vendor/jsonc-parser-3.3.1/lib/umd/impl/edit.js +0 -201
- package/vendor/jsonc-parser-3.3.1/lib/umd/impl/format.js +0 -275
- package/vendor/jsonc-parser-3.3.1/lib/umd/impl/parser.js +0 -682
- package/vendor/jsonc-parser-3.3.1/lib/umd/impl/scanner.js +0 -456
- package/vendor/jsonc-parser-3.3.1/lib/umd/impl/string-intern.js +0 -42
- package/vendor/jsonc-parser-3.3.1/lib/umd/main.d.ts +0 -351
- package/vendor/jsonc-parser-3.3.1/lib/umd/main.js +0 -194
- package/vendor/jsonc-parser-3.3.1/package.json +0 -37
- package/workflows/cost-tiered-fix.js +0 -287
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: writing-skills
|
|
3
|
-
description: >
|
|
4
|
-
How to author a skill in Leo's shape — the frontmatter keys and what the
|
|
5
|
-
build enforces about them, a description and trigger pair that routes
|
|
6
|
-
correctly, the closed-exemption-list structure the existing skills share,
|
|
7
|
-
and where a personal skill file goes on each harness so it loads beside
|
|
8
|
-
the plugin's own. Covers both skills that ship with the plugin and
|
|
9
|
-
personal ones kept outside it. Use when authoring a skill or choosing its
|
|
10
|
-
personal load path. Do not use to decide whether a process needs a skill or
|
|
11
|
-
to change plugin packaging or loaders.
|
|
12
|
-
when_to_use: >
|
|
13
|
-
Writing a new skill, revising an existing one's frontmatter, or deciding
|
|
14
|
-
where to put a personal skill so a harness picks it up. NOT for deciding
|
|
15
|
-
whether a piece of process deserves to be a skill at all (that is
|
|
16
|
-
leo:brainstorming), and NOT for plugin packaging or loader changes — this
|
|
17
|
-
covers authoring one file and placing it.
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
# writing-skills
|
|
21
|
-
|
|
22
|
-
A skill is two artifacts sharing a file. The frontmatter is a routing decision,
|
|
23
|
-
read constantly by a model deciding whether to open the body at all. The body is
|
|
24
|
-
a procedure, read rarely, only once routing already succeeded. Most weak skills
|
|
25
|
-
are weak at the first job, and no amount of body quality compensates for it.
|
|
26
|
-
|
|
27
|
-
## Frontmatter
|
|
28
|
-
|
|
29
|
-
| Key | Required | Notes |
|
|
30
|
-
|---|---|---|
|
|
31
|
-
| `name` | yes | must equal the containing directory name, exactly |
|
|
32
|
-
| `description` | yes | what it is and what it produces |
|
|
33
|
-
| `when_to_use` | for process skills | triggers *and* exclusions |
|
|
34
|
-
| `model`, `effort` | no | portable skills omit both |
|
|
35
|
-
| `disable-model-invocation` | no | blocks automatic triggering |
|
|
36
|
-
| `allowed-tools`, `argument-hint` | user-invoked only | command-shaped skills |
|
|
37
|
-
|
|
38
|
-
Anything outside that set fails the build. A portable skill should carry exactly
|
|
39
|
-
`name`, `description`, and `when_to_use` — every process skill in this plugin
|
|
40
|
-
does.
|
|
41
|
-
|
|
42
|
-
## Description and triggers
|
|
43
|
-
|
|
44
|
-
This is the highest-leverage part of the file.
|
|
45
|
-
|
|
46
|
-
The `description` says what the skill *is* and what it *produces*, in the third
|
|
47
|
-
person. It gets read out of context, sitting in a list beside dozens of others.
|
|
48
|
-
|
|
49
|
-
The `when_to_use` is a matched pair: the positive triggers, then the negative
|
|
50
|
-
ones, each pointing at where that case actually belongs. The negative half does
|
|
51
|
-
more work than the positive half — a skill with only triggers fires on
|
|
52
|
-
everything adjacent to them. Name the sibling skill in each exclusion, so the
|
|
53
|
-
reader is routed rather than merely turned away.
|
|
54
|
-
|
|
55
|
-
## The house shape
|
|
56
|
-
|
|
57
|
-
The existing skills share a spine, in this order:
|
|
58
|
-
|
|
59
|
-
1. `# <name>` and a core rule in the opening two or three sentences. Someone who
|
|
60
|
-
reads only that paragraph should still be able to comply.
|
|
61
|
-
2. When it fires — and, just as explicitly, when it does not.
|
|
62
|
-
3. The mechanics: a phase table with exit criteria, a numbered discipline, or a
|
|
63
|
-
procedure. Pick one; stacking all three makes none of them load-bearing.
|
|
64
|
-
4. Exemptions, where the skill warrants them.
|
|
65
|
-
5. Self-talk to catch — the rationalizations that come immediately before the
|
|
66
|
-
violation, each answered in the same bullet. Write the sentence a reader will
|
|
67
|
-
genuinely think, not a strawman.
|
|
68
|
-
6. Reviewable finding, where a reviewer should enforce it.
|
|
69
|
-
7. Works with — the neighbours, and what each of them owns, so the reader
|
|
70
|
-
learns the boundary instead of the overlap.
|
|
71
|
-
|
|
72
|
-
## Exemption lists are closed
|
|
73
|
-
|
|
74
|
-
The signature of this set, and `leo:test-first` is the reference implementation.
|
|
75
|
-
|
|
76
|
-
- Numbered and bold-named, so a skip can cite one by name.
|
|
77
|
-
- Introduced as closed, with the no-analogy line. The failure being prevented is
|
|
78
|
-
not skipping the rule outright; it is reasoning by resemblance into a skip.
|
|
79
|
-
- Each entry says why the underlying risk is absent, not merely that it is
|
|
80
|
-
permitted.
|
|
81
|
-
- Closes with the reporting requirement: an unnamed skip is not a skip.
|
|
82
|
-
|
|
83
|
-
A skill may also deliberately have no exemptions — leo:visual-verification is
|
|
84
|
-
one. When so, say it plainly, because a reader arriving from a skill that has
|
|
85
|
-
them will otherwise read the absence as an oversight.
|
|
86
|
-
|
|
87
|
-
## Where a personal skill goes
|
|
88
|
-
|
|
89
|
-
| Harness | Location |
|
|
90
|
-
|---|---|
|
|
91
|
-
| Claude Code | `~/.claude/skills/<name>/SKILL.md` |
|
|
92
|
-
| Codex | `~/.codex/skills/<name>/SKILL.md` |
|
|
93
|
-
| OpenCode | add the containing directory to the skills paths in `opencode.json` |
|
|
94
|
-
| Cursor | not confirmed here — check the harness's own documentation |
|
|
95
|
-
| Hermes | no personal-skill directory; a skill here means a small local plugin |
|
|
96
|
-
|
|
97
|
-
Plugin skills are namespaced `leo:<name>`; a personal skill is invoked bare, so
|
|
98
|
-
its name is free to collide conceptually without colliding literally. Two rows
|
|
99
|
-
of that table are unverified, which is why the advice is to run leo:doctor and
|
|
100
|
-
confirm the load path rather than trusting a path that may not exist — the same
|
|
101
|
-
discipline leo:freshness applies to a third-party API, turned on the harness.
|
|
102
|
-
|
|
103
|
-
Leo's own skills live in a plugin cache that every update overwrites. Never edit
|
|
104
|
-
one in place to customize it; write a personal skill instead.
|
|
105
|
-
|
|
106
|
-
## Registering a skill that ships with the plugin
|
|
107
|
-
|
|
108
|
-
Four places, all enforced, and a miss fails the build with a message that does
|
|
109
|
-
not obviously point at the omission:
|
|
110
|
-
|
|
111
|
-
1. The `SKILL.md` itself, with `name` matching its directory.
|
|
112
|
-
2. A row in the policy's skill index — keep it short, since that table is
|
|
113
|
-
injected into every session on every harness and the smallest budget wins.
|
|
114
|
-
3. At least one `leo:<name>` reference from some file other than its own body.
|
|
115
|
-
4. The roster constants and metadata tests in the test suite, plus the
|
|
116
|
-
appropriate registration class: portable skills in `skills/`, Claude-only
|
|
117
|
-
skills in `skills-claude/`, and harness metadata under `agents/openai.yaml`
|
|
118
|
-
only when that skill needs Codex invocation policy. Keep the `leo:`
|
|
119
|
-
namespace in portable policy prose; OpenCode's generated copy uses
|
|
120
|
-
`leo-<name>` because it has no namespace.
|
|
121
|
-
|
|
122
|
-
Write example tokens as `leo:<name>` with the angle brackets. A literal
|
|
123
|
-
placeholder like a made-up skill name is scanned as a real reference and fails
|
|
124
|
-
the build when it resolves to nothing.
|
|
125
|
-
|
|
126
|
-
## Self-talk to catch
|
|
127
|
-
|
|
128
|
-
- "The description covers it, triggers are redundant" — the description sells,
|
|
129
|
-
the triggers refuse. Without the refusal it fires on its neighbours.
|
|
130
|
-
- "I'll add an exemption for cases like this one" — "cases like this" is exactly
|
|
131
|
-
the analogy a closed list exists to block. Name the case or do not exempt it.
|
|
132
|
-
- "This is a rule, not a skill" — if it has no procedure and no exemptions, it is
|
|
133
|
-
a line in the policy, and the policy has a budget.
|
|
134
|
-
- "I'll copy the shape from another skill" — copy the structure, write the
|
|
135
|
-
sentences fresh.
|
|
136
|
-
|
|
137
|
-
## Works with
|
|
138
|
-
|
|
139
|
-
- leo:doctor — confirm where this harness looks, and that it registered.
|
|
140
|
-
- leo:brainstorming — whether this should be a skill at all.
|
|
141
|
-
- leo:using-leo — where the index row goes, and what it costs.
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) Microsoft
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# jsonc-parser provenance
|
|
2
|
-
|
|
3
|
-
OpenCode configuration edits use `jsonc-parser` 3.3.1's `modify` plus
|
|
4
|
-
`applyEdits` operations through `scripts/jsonc_bridge.cjs`. It is vendored
|
|
5
|
-
rather than loaded at setup time: setup must be deterministic, work offline,
|
|
6
|
-
and must not turn a user-approved config edit into an unreviewed mutable
|
|
7
|
-
install.
|
|
8
|
-
|
|
9
|
-
Reviewed registry artifact: [jsonc-parser 3.3.1](https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.3.1.tgz), MIT.
|
|
10
|
-
|
|
11
|
-
- npm SHA-1: `f2a524b4f7fd11e3d791e559977ad60b98b798b4`
|
|
12
|
-
- npm integrity: `sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==`
|
|
13
|
-
- fetched tarball SHA-256: `4a0315b8671e7463bae7af7c142cdf19e9aa7ba39eb36dc2df383b8648e3cbc9`
|
|
14
|
-
|
|
15
|
-
The vendored files are `LICENSE.md`, `package.json`, and the complete
|
|
16
|
-
dependency-free `lib/umd/` runtime used by the bridge.
|
|
17
|
-
|
|
18
|
-
Update procedure: download that exact registry tarball, verify its SHA-256
|
|
19
|
-
against the reviewed value above, replace only those files, then run both
|
|
20
|
-
`python3 -m unittest tests.test_setup` and `python3.14 -m unittest tests.test_setup`
|
|
21
|
-
plus `python3 -m unittest tests.test_release`. Review the new release and
|
|
22
|
-
record its exact registry URL, SHA-1, SHA-256, integrity, and version here.
|
|
23
|
-
Core MCP executable pins have their separate review procedure in
|
|
24
|
-
`config/MCP_PINS.md`. Preserve the add-only rule, comments, trailing
|
|
25
|
-
commas, indentation, symlinks, and file modes. Never replace a JSONC edit with
|
|
26
|
-
`JSON.stringify` or `json.dumps`.
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./format", "./parser"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
/*---------------------------------------------------------------------------------------------
|
|
11
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
12
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
13
|
-
*--------------------------------------------------------------------------------------------*/
|
|
14
|
-
'use strict';
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.isWS = exports.applyEdit = exports.setProperty = exports.removeProperty = void 0;
|
|
17
|
-
const format_1 = require("./format");
|
|
18
|
-
const parser_1 = require("./parser");
|
|
19
|
-
function removeProperty(text, path, options) {
|
|
20
|
-
return setProperty(text, path, void 0, options);
|
|
21
|
-
}
|
|
22
|
-
exports.removeProperty = removeProperty;
|
|
23
|
-
function setProperty(text, originalPath, value, options) {
|
|
24
|
-
const path = originalPath.slice();
|
|
25
|
-
const errors = [];
|
|
26
|
-
const root = (0, parser_1.parseTree)(text, errors);
|
|
27
|
-
let parent = void 0;
|
|
28
|
-
let lastSegment = void 0;
|
|
29
|
-
while (path.length > 0) {
|
|
30
|
-
lastSegment = path.pop();
|
|
31
|
-
parent = (0, parser_1.findNodeAtLocation)(root, path);
|
|
32
|
-
if (parent === void 0 && value !== void 0) {
|
|
33
|
-
if (typeof lastSegment === 'string') {
|
|
34
|
-
value = { [lastSegment]: value };
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
value = [value];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (!parent) {
|
|
45
|
-
// empty document
|
|
46
|
-
if (value === void 0) { // delete
|
|
47
|
-
throw new Error('Can not delete in empty document');
|
|
48
|
-
}
|
|
49
|
-
return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
|
|
50
|
-
}
|
|
51
|
-
else if (parent.type === 'object' && typeof lastSegment === 'string' && Array.isArray(parent.children)) {
|
|
52
|
-
const existing = (0, parser_1.findNodeAtLocation)(parent, [lastSegment]);
|
|
53
|
-
if (existing !== void 0) {
|
|
54
|
-
if (value === void 0) { // delete
|
|
55
|
-
if (!existing.parent) {
|
|
56
|
-
throw new Error('Malformed AST');
|
|
57
|
-
}
|
|
58
|
-
const propertyIndex = parent.children.indexOf(existing.parent);
|
|
59
|
-
let removeBegin;
|
|
60
|
-
let removeEnd = existing.parent.offset + existing.parent.length;
|
|
61
|
-
if (propertyIndex > 0) {
|
|
62
|
-
// remove the comma of the previous node
|
|
63
|
-
let previous = parent.children[propertyIndex - 1];
|
|
64
|
-
removeBegin = previous.offset + previous.length;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
removeBegin = parent.offset + 1;
|
|
68
|
-
if (parent.children.length > 1) {
|
|
69
|
-
// remove the comma of the next node
|
|
70
|
-
let next = parent.children[1];
|
|
71
|
-
removeEnd = next.offset;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: '' }, options);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
// set value of existing property
|
|
78
|
-
return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
if (value === void 0) { // delete
|
|
83
|
-
return []; // property does not exist, nothing to do
|
|
84
|
-
}
|
|
85
|
-
const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
|
|
86
|
-
const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map(p => p.children[0].value)) : parent.children.length;
|
|
87
|
-
let edit;
|
|
88
|
-
if (index > 0) {
|
|
89
|
-
let previous = parent.children[index - 1];
|
|
90
|
-
edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
|
|
91
|
-
}
|
|
92
|
-
else if (parent.children.length === 0) {
|
|
93
|
-
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
edit = { offset: parent.offset + 1, length: 0, content: newProperty + ',' };
|
|
97
|
-
}
|
|
98
|
-
return withFormatting(text, edit, options);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
else if (parent.type === 'array' && typeof lastSegment === 'number' && Array.isArray(parent.children)) {
|
|
102
|
-
const insertIndex = lastSegment;
|
|
103
|
-
if (insertIndex === -1) {
|
|
104
|
-
// Insert
|
|
105
|
-
const newProperty = `${JSON.stringify(value)}`;
|
|
106
|
-
let edit;
|
|
107
|
-
if (parent.children.length === 0) {
|
|
108
|
-
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
const previous = parent.children[parent.children.length - 1];
|
|
112
|
-
edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
|
|
113
|
-
}
|
|
114
|
-
return withFormatting(text, edit, options);
|
|
115
|
-
}
|
|
116
|
-
else if (value === void 0 && parent.children.length >= 0) {
|
|
117
|
-
// Removal
|
|
118
|
-
const removalIndex = lastSegment;
|
|
119
|
-
const toRemove = parent.children[removalIndex];
|
|
120
|
-
let edit;
|
|
121
|
-
if (parent.children.length === 1) {
|
|
122
|
-
// only item
|
|
123
|
-
edit = { offset: parent.offset + 1, length: parent.length - 2, content: '' };
|
|
124
|
-
}
|
|
125
|
-
else if (parent.children.length - 1 === removalIndex) {
|
|
126
|
-
// last item
|
|
127
|
-
let previous = parent.children[removalIndex - 1];
|
|
128
|
-
let offset = previous.offset + previous.length;
|
|
129
|
-
let parentEndOffset = parent.offset + parent.length;
|
|
130
|
-
edit = { offset, length: parentEndOffset - 2 - offset, content: '' };
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: '' };
|
|
134
|
-
}
|
|
135
|
-
return withFormatting(text, edit, options);
|
|
136
|
-
}
|
|
137
|
-
else if (value !== void 0) {
|
|
138
|
-
let edit;
|
|
139
|
-
const newProperty = `${JSON.stringify(value)}`;
|
|
140
|
-
if (!options.isArrayInsertion && parent.children.length > lastSegment) {
|
|
141
|
-
const toModify = parent.children[lastSegment];
|
|
142
|
-
edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
|
|
143
|
-
}
|
|
144
|
-
else if (parent.children.length === 0 || lastSegment === 0) {
|
|
145
|
-
edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + ',' };
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
|
|
149
|
-
const previous = parent.children[index - 1];
|
|
150
|
-
edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
|
|
151
|
-
}
|
|
152
|
-
return withFormatting(text, edit, options);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
throw new Error(`Can not ${value === void 0 ? 'remove' : (options.isArrayInsertion ? 'insert' : 'modify')} Array index ${insertIndex} as length is not sufficient`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
throw new Error(`Can not add ${typeof lastSegment !== 'number' ? 'index' : 'property'} to parent of type ${parent.type}`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
exports.setProperty = setProperty;
|
|
163
|
-
function withFormatting(text, edit, options) {
|
|
164
|
-
if (!options.formattingOptions) {
|
|
165
|
-
return [edit];
|
|
166
|
-
}
|
|
167
|
-
// apply the edit
|
|
168
|
-
let newText = applyEdit(text, edit);
|
|
169
|
-
// format the new text
|
|
170
|
-
let begin = edit.offset;
|
|
171
|
-
let end = edit.offset + edit.content.length;
|
|
172
|
-
if (edit.length === 0 || edit.content.length === 0) { // insert or remove
|
|
173
|
-
while (begin > 0 && !(0, format_1.isEOL)(newText, begin - 1)) {
|
|
174
|
-
begin--;
|
|
175
|
-
}
|
|
176
|
-
while (end < newText.length && !(0, format_1.isEOL)(newText, end)) {
|
|
177
|
-
end++;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
const edits = (0, format_1.format)(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
|
|
181
|
-
// apply the formatting edits and track the begin and end offsets of the changes
|
|
182
|
-
for (let i = edits.length - 1; i >= 0; i--) {
|
|
183
|
-
const edit = edits[i];
|
|
184
|
-
newText = applyEdit(newText, edit);
|
|
185
|
-
begin = Math.min(begin, edit.offset);
|
|
186
|
-
end = Math.max(end, edit.offset + edit.length);
|
|
187
|
-
end += edit.content.length - edit.length;
|
|
188
|
-
}
|
|
189
|
-
// create a single edit with all changes
|
|
190
|
-
const editLength = text.length - (newText.length - end) - begin;
|
|
191
|
-
return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
|
|
192
|
-
}
|
|
193
|
-
function applyEdit(text, edit) {
|
|
194
|
-
return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
|
|
195
|
-
}
|
|
196
|
-
exports.applyEdit = applyEdit;
|
|
197
|
-
function isWS(text, offset) {
|
|
198
|
-
return '\r\n \t'.indexOf(text.charAt(offset)) !== -1;
|
|
199
|
-
}
|
|
200
|
-
exports.isWS = isWS;
|
|
201
|
-
});
|
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./scanner", "./string-intern"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
/*---------------------------------------------------------------------------------------------
|
|
11
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
12
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
13
|
-
*--------------------------------------------------------------------------------------------*/
|
|
14
|
-
'use strict';
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.isEOL = exports.format = void 0;
|
|
17
|
-
const scanner_1 = require("./scanner");
|
|
18
|
-
const string_intern_1 = require("./string-intern");
|
|
19
|
-
function format(documentText, range, options) {
|
|
20
|
-
let initialIndentLevel;
|
|
21
|
-
let formatText;
|
|
22
|
-
let formatTextStart;
|
|
23
|
-
let rangeStart;
|
|
24
|
-
let rangeEnd;
|
|
25
|
-
if (range) {
|
|
26
|
-
rangeStart = range.offset;
|
|
27
|
-
rangeEnd = rangeStart + range.length;
|
|
28
|
-
formatTextStart = rangeStart;
|
|
29
|
-
while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
|
|
30
|
-
formatTextStart--;
|
|
31
|
-
}
|
|
32
|
-
let endOffset = rangeEnd;
|
|
33
|
-
while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
|
|
34
|
-
endOffset++;
|
|
35
|
-
}
|
|
36
|
-
formatText = documentText.substring(formatTextStart, endOffset);
|
|
37
|
-
initialIndentLevel = computeIndentLevel(formatText, options);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
formatText = documentText;
|
|
41
|
-
initialIndentLevel = 0;
|
|
42
|
-
formatTextStart = 0;
|
|
43
|
-
rangeStart = 0;
|
|
44
|
-
rangeEnd = documentText.length;
|
|
45
|
-
}
|
|
46
|
-
const eol = getEOL(options, documentText);
|
|
47
|
-
const eolFastPathSupported = string_intern_1.supportedEols.includes(eol);
|
|
48
|
-
let numberLineBreaks = 0;
|
|
49
|
-
let indentLevel = 0;
|
|
50
|
-
let indentValue;
|
|
51
|
-
if (options.insertSpaces) {
|
|
52
|
-
indentValue = string_intern_1.cachedSpaces[options.tabSize || 4] ?? repeat(string_intern_1.cachedSpaces[1], options.tabSize || 4);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
indentValue = '\t';
|
|
56
|
-
}
|
|
57
|
-
const indentType = indentValue === '\t' ? '\t' : ' ';
|
|
58
|
-
let scanner = (0, scanner_1.createScanner)(formatText, false);
|
|
59
|
-
let hasError = false;
|
|
60
|
-
function newLinesAndIndent() {
|
|
61
|
-
if (numberLineBreaks > 1) {
|
|
62
|
-
return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
63
|
-
}
|
|
64
|
-
const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
|
|
65
|
-
if (!eolFastPathSupported || amountOfSpaces > string_intern_1.cachedBreakLinesWithSpaces[indentType][eol].length) {
|
|
66
|
-
return eol + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
67
|
-
}
|
|
68
|
-
if (amountOfSpaces <= 0) {
|
|
69
|
-
return eol;
|
|
70
|
-
}
|
|
71
|
-
return string_intern_1.cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
|
|
72
|
-
}
|
|
73
|
-
function scanNext() {
|
|
74
|
-
let token = scanner.scan();
|
|
75
|
-
numberLineBreaks = 0;
|
|
76
|
-
while (token === 15 /* SyntaxKind.Trivia */ || token === 14 /* SyntaxKind.LineBreakTrivia */) {
|
|
77
|
-
if (token === 14 /* SyntaxKind.LineBreakTrivia */ && options.keepLines) {
|
|
78
|
-
numberLineBreaks += 1;
|
|
79
|
-
}
|
|
80
|
-
else if (token === 14 /* SyntaxKind.LineBreakTrivia */) {
|
|
81
|
-
numberLineBreaks = 1;
|
|
82
|
-
}
|
|
83
|
-
token = scanner.scan();
|
|
84
|
-
}
|
|
85
|
-
hasError = token === 16 /* SyntaxKind.Unknown */ || scanner.getTokenError() !== 0 /* ScanError.None */;
|
|
86
|
-
return token;
|
|
87
|
-
}
|
|
88
|
-
const editOperations = [];
|
|
89
|
-
function addEdit(text, startOffset, endOffset) {
|
|
90
|
-
if (!hasError && (!range || (startOffset < rangeEnd && endOffset > rangeStart)) && documentText.substring(startOffset, endOffset) !== text) {
|
|
91
|
-
editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
let firstToken = scanNext();
|
|
95
|
-
if (options.keepLines && numberLineBreaks > 0) {
|
|
96
|
-
addEdit(repeat(eol, numberLineBreaks), 0, 0);
|
|
97
|
-
}
|
|
98
|
-
if (firstToken !== 17 /* SyntaxKind.EOF */) {
|
|
99
|
-
let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
100
|
-
let initialIndent = (indentValue.length * initialIndentLevel < 20) && options.insertSpaces
|
|
101
|
-
? string_intern_1.cachedSpaces[indentValue.length * initialIndentLevel]
|
|
102
|
-
: repeat(indentValue, initialIndentLevel);
|
|
103
|
-
addEdit(initialIndent, formatTextStart, firstTokenStart);
|
|
104
|
-
}
|
|
105
|
-
while (firstToken !== 17 /* SyntaxKind.EOF */) {
|
|
106
|
-
let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
107
|
-
let secondToken = scanNext();
|
|
108
|
-
let replaceContent = '';
|
|
109
|
-
let needsLineBreak = false;
|
|
110
|
-
while (numberLineBreaks === 0 && (secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */)) {
|
|
111
|
-
let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
112
|
-
addEdit(string_intern_1.cachedSpaces[1], firstTokenEnd, commentTokenStart);
|
|
113
|
-
firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
114
|
-
needsLineBreak = secondToken === 12 /* SyntaxKind.LineCommentTrivia */;
|
|
115
|
-
replaceContent = needsLineBreak ? newLinesAndIndent() : '';
|
|
116
|
-
secondToken = scanNext();
|
|
117
|
-
}
|
|
118
|
-
if (secondToken === 2 /* SyntaxKind.CloseBraceToken */) {
|
|
119
|
-
if (firstToken !== 1 /* SyntaxKind.OpenBraceToken */) {
|
|
120
|
-
indentLevel--;
|
|
121
|
-
}
|
|
122
|
-
;
|
|
123
|
-
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1 /* SyntaxKind.OpenBraceToken */) {
|
|
124
|
-
replaceContent = newLinesAndIndent();
|
|
125
|
-
}
|
|
126
|
-
else if (options.keepLines) {
|
|
127
|
-
replaceContent = string_intern_1.cachedSpaces[1];
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else if (secondToken === 4 /* SyntaxKind.CloseBracketToken */) {
|
|
131
|
-
if (firstToken !== 3 /* SyntaxKind.OpenBracketToken */) {
|
|
132
|
-
indentLevel--;
|
|
133
|
-
}
|
|
134
|
-
;
|
|
135
|
-
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3 /* SyntaxKind.OpenBracketToken */) {
|
|
136
|
-
replaceContent = newLinesAndIndent();
|
|
137
|
-
}
|
|
138
|
-
else if (options.keepLines) {
|
|
139
|
-
replaceContent = string_intern_1.cachedSpaces[1];
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
switch (firstToken) {
|
|
144
|
-
case 3 /* SyntaxKind.OpenBracketToken */:
|
|
145
|
-
case 1 /* SyntaxKind.OpenBraceToken */:
|
|
146
|
-
indentLevel++;
|
|
147
|
-
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
148
|
-
replaceContent = newLinesAndIndent();
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
replaceContent = string_intern_1.cachedSpaces[1];
|
|
152
|
-
}
|
|
153
|
-
break;
|
|
154
|
-
case 5 /* SyntaxKind.CommaToken */:
|
|
155
|
-
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
156
|
-
replaceContent = newLinesAndIndent();
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
replaceContent = string_intern_1.cachedSpaces[1];
|
|
160
|
-
}
|
|
161
|
-
break;
|
|
162
|
-
case 12 /* SyntaxKind.LineCommentTrivia */:
|
|
163
|
-
replaceContent = newLinesAndIndent();
|
|
164
|
-
break;
|
|
165
|
-
case 13 /* SyntaxKind.BlockCommentTrivia */:
|
|
166
|
-
if (numberLineBreaks > 0) {
|
|
167
|
-
replaceContent = newLinesAndIndent();
|
|
168
|
-
}
|
|
169
|
-
else if (!needsLineBreak) {
|
|
170
|
-
replaceContent = string_intern_1.cachedSpaces[1];
|
|
171
|
-
}
|
|
172
|
-
break;
|
|
173
|
-
case 6 /* SyntaxKind.ColonToken */:
|
|
174
|
-
if (options.keepLines && numberLineBreaks > 0) {
|
|
175
|
-
replaceContent = newLinesAndIndent();
|
|
176
|
-
}
|
|
177
|
-
else if (!needsLineBreak) {
|
|
178
|
-
replaceContent = string_intern_1.cachedSpaces[1];
|
|
179
|
-
}
|
|
180
|
-
break;
|
|
181
|
-
case 10 /* SyntaxKind.StringLiteral */:
|
|
182
|
-
if (options.keepLines && numberLineBreaks > 0) {
|
|
183
|
-
replaceContent = newLinesAndIndent();
|
|
184
|
-
}
|
|
185
|
-
else if (secondToken === 6 /* SyntaxKind.ColonToken */ && !needsLineBreak) {
|
|
186
|
-
replaceContent = '';
|
|
187
|
-
}
|
|
188
|
-
break;
|
|
189
|
-
case 7 /* SyntaxKind.NullKeyword */:
|
|
190
|
-
case 8 /* SyntaxKind.TrueKeyword */:
|
|
191
|
-
case 9 /* SyntaxKind.FalseKeyword */:
|
|
192
|
-
case 11 /* SyntaxKind.NumericLiteral */:
|
|
193
|
-
case 2 /* SyntaxKind.CloseBraceToken */:
|
|
194
|
-
case 4 /* SyntaxKind.CloseBracketToken */:
|
|
195
|
-
if (options.keepLines && numberLineBreaks > 0) {
|
|
196
|
-
replaceContent = newLinesAndIndent();
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
if ((secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */) && !needsLineBreak) {
|
|
200
|
-
replaceContent = string_intern_1.cachedSpaces[1];
|
|
201
|
-
}
|
|
202
|
-
else if (secondToken !== 5 /* SyntaxKind.CommaToken */ && secondToken !== 17 /* SyntaxKind.EOF */) {
|
|
203
|
-
hasError = true;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
break;
|
|
207
|
-
case 16 /* SyntaxKind.Unknown */:
|
|
208
|
-
hasError = true;
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
if (numberLineBreaks > 0 && (secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */)) {
|
|
212
|
-
replaceContent = newLinesAndIndent();
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
if (secondToken === 17 /* SyntaxKind.EOF */) {
|
|
216
|
-
if (options.keepLines && numberLineBreaks > 0) {
|
|
217
|
-
replaceContent = newLinesAndIndent();
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
replaceContent = options.insertFinalNewline ? eol : '';
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
224
|
-
addEdit(replaceContent, firstTokenEnd, secondTokenStart);
|
|
225
|
-
firstToken = secondToken;
|
|
226
|
-
}
|
|
227
|
-
return editOperations;
|
|
228
|
-
}
|
|
229
|
-
exports.format = format;
|
|
230
|
-
function repeat(s, count) {
|
|
231
|
-
let result = '';
|
|
232
|
-
for (let i = 0; i < count; i++) {
|
|
233
|
-
result += s;
|
|
234
|
-
}
|
|
235
|
-
return result;
|
|
236
|
-
}
|
|
237
|
-
function computeIndentLevel(content, options) {
|
|
238
|
-
let i = 0;
|
|
239
|
-
let nChars = 0;
|
|
240
|
-
const tabSize = options.tabSize || 4;
|
|
241
|
-
while (i < content.length) {
|
|
242
|
-
let ch = content.charAt(i);
|
|
243
|
-
if (ch === string_intern_1.cachedSpaces[1]) {
|
|
244
|
-
nChars++;
|
|
245
|
-
}
|
|
246
|
-
else if (ch === '\t') {
|
|
247
|
-
nChars += tabSize;
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
i++;
|
|
253
|
-
}
|
|
254
|
-
return Math.floor(nChars / tabSize);
|
|
255
|
-
}
|
|
256
|
-
function getEOL(options, text) {
|
|
257
|
-
for (let i = 0; i < text.length; i++) {
|
|
258
|
-
const ch = text.charAt(i);
|
|
259
|
-
if (ch === '\r') {
|
|
260
|
-
if (i + 1 < text.length && text.charAt(i + 1) === '\n') {
|
|
261
|
-
return '\r\n';
|
|
262
|
-
}
|
|
263
|
-
return '\r';
|
|
264
|
-
}
|
|
265
|
-
else if (ch === '\n') {
|
|
266
|
-
return '\n';
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return (options && options.eol) || '\n';
|
|
270
|
-
}
|
|
271
|
-
function isEOL(text, offset) {
|
|
272
|
-
return '\r\n'.indexOf(text.charAt(offset)) !== -1;
|
|
273
|
-
}
|
|
274
|
-
exports.isEOL = isEOL;
|
|
275
|
-
});
|