@mmerterden/multi-agent-pipeline 23.2.0 → 23.4.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/CHANGELOG.md +50 -0
- package/README.md +25 -6
- package/README.tr.md +26 -7
- package/docs/adr/0008-installer-modularization-and-secret-leak-defense.md +1 -1
- package/docs/adr/0010-own-code-graph.md +299 -8
- package/docs/architecture.md +3 -3
- package/docs/ecosystem.md +10 -10
- package/docs/engineering.md +4 -4
- package/docs/facts.json +8 -8
- package/docs/features.md +6 -6
- package/docs/performance.md +17 -17
- package/install/_dev-only-files.mjs +9 -0
- package/install/claude.mjs +28 -2
- package/install/templates/claude-hooks.json +32 -1
- package/manifest.json +229 -161
- package/package.json +11 -3
- package/pipeline/commands/multi-agent/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/design-check/SKILL.md +2 -2
- package/pipeline/commands/multi-agent/diff-explain/SKILL.md +3 -3
- package/pipeline/commands/multi-agent/fable-status/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/graph/SKILL.md +57 -24
- package/pipeline/commands/multi-agent/pair/SKILL.md +92 -0
- package/pipeline/commands/multi-agent/prune-prompts/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/search/SKILL.md +7 -1
- package/pipeline/commands/multi-agent/status/SKILL.md +4 -0
- package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
- package/pipeline/contract/CHANGELOG.md +49 -0
- package/pipeline/contract/build.mjs +13 -1
- package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
- package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
- package/pipeline/contract/fixtures/runs-awaiting-question.json +4 -1
- package/pipeline/contract/fixtures/runs-empty.json +1 -1
- package/pipeline/contract/fixtures/runs-failed.json +4 -1
- package/pipeline/contract/fixtures/runs-old-schema.json +3 -0
- package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +4 -1
- package/pipeline/contract/fixtures/runs-pr-opened.json +4 -1
- package/pipeline/contract/fixtures/runs-running.json +4 -1
- package/pipeline/contract/manifest.json +28 -15
- package/pipeline/contract/types/index.d.ts +55 -3
- package/pipeline/lib/detach-self.mjs +95 -0
- package/pipeline/lib/model-rung.sh +1 -1
- package/pipeline/lib/public-mcp-servers.mjs +33 -0
- package/pipeline/lib/rotated-log.mjs +93 -0
- package/pipeline/lib/tls-trust.mjs +29 -0
- package/pipeline/lib/usage-lifecycle.mjs +9 -11
- package/pipeline/lib/usage-names.generated.mjs +614 -0
- package/pipeline/lib/usage-run-key.mjs +235 -0
- package/pipeline/lib/usage-vocab.mjs +210 -0
- package/pipeline/multi-agent-refs/analysis/intake.md +2 -2
- package/pipeline/multi-agent-refs/analysis/render.md +1 -1
- package/pipeline/multi-agent-refs/channels/generator.md +4 -5
- package/pipeline/multi-agent-refs/cross-cli-contract.md +4 -4
- package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
- package/pipeline/multi-agent-refs/features/code-graph.md +146 -11
- package/pipeline/multi-agent-refs/features/code-intelligence.md +16 -14
- package/pipeline/multi-agent-refs/features/dev-critic.md +7 -7
- package/pipeline/multi-agent-refs/features/model-fallback.md +9 -7
- package/pipeline/multi-agent-refs/features/remote-control.md +252 -0
- package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
- package/pipeline/multi-agent-refs/features/review-file-set.md +3 -3
- package/pipeline/multi-agent-refs/features/review-multi-repo.md +1 -1
- package/pipeline/multi-agent-refs/features/session-brief.md +42 -0
- package/pipeline/multi-agent-refs/features/skill-conformance.md +3 -3
- package/pipeline/multi-agent-refs/features/usage-reporting.md +252 -24
- package/pipeline/multi-agent-refs/help/en.md +3 -2
- package/pipeline/multi-agent-refs/help/tr.md +3 -2
- package/pipeline/multi-agent-refs/knowledge.md +1 -1
- package/pipeline/multi-agent-refs/orchestrator/copilot-pipeline.md +1 -1
- package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +1 -1
- package/pipeline/multi-agent-refs/phases/operations.md +2 -2
- package/pipeline/multi-agent-refs/phases/phase-0-init.md +13 -12
- package/pipeline/multi-agent-refs/phases/phase-1-plan.md +4 -4
- package/pipeline/multi-agent-refs/phases/phase-3-review.md +5 -3
- package/pipeline/multi-agent-refs/phases/phase-5-report.md +1 -1
- package/pipeline/multi-agent-refs/platform-parity.md +2 -2
- package/pipeline/multi-agent-refs/review/panel.md +1 -1
- package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
- package/pipeline/office/index.html +1207 -233
- package/pipeline/office/toolkit.json +1 -1
- package/pipeline/rules/outside-the-pipeline.md +1 -1
- package/pipeline/schemas/activity.schema.json +23 -0
- package/pipeline/schemas/agent-state.schema.json +6 -1
- package/pipeline/schemas/code-graph-calls.schema.json +254 -0
- package/pipeline/schemas/code-graph-docs.schema.json +223 -0
- package/pipeline/schemas/code-graph-infra.schema.json +227 -0
- package/pipeline/schemas/code-graph.schema.json +2 -2
- package/pipeline/schemas/examples/design-check-config.json +27 -0
- package/pipeline/schemas/learning-curve.schema.json +67 -0
- package/pipeline/schemas/office-jobs.json +69 -2
- package/pipeline/schemas/office-jobs.schema.json +8 -1
- package/pipeline/schemas/phases.json +5 -0
- package/pipeline/schemas/phases.schema.json +8 -0
- package/pipeline/schemas/prefs.schema.json +46 -12
- package/pipeline/schemas/runs-index.schema.json +17 -0
- package/pipeline/schemas/toolkit-path-params.json +84 -8
- package/pipeline/scripts/README.md +1 -0
- package/pipeline/scripts/_code-graph.mjs +184 -103
- package/pipeline/scripts/_contract-core.mjs +1 -1
- package/pipeline/scripts/_contract-routes-office.mjs +21 -0
- package/pipeline/scripts/_diff-impact.mjs +21 -2
- package/pipeline/scripts/_graph-sidecars.mjs +372 -0
- package/pipeline/scripts/_http-post.mjs +103 -115
- package/pipeline/scripts/_safe-read.mjs +57 -0
- package/pipeline/scripts/_skill-practices.mjs +26 -0
- package/pipeline/scripts/_strip-code.mjs +380 -0
- package/pipeline/scripts/activity-snapshot.mjs +13 -1
- package/pipeline/scripts/aggregate-metrics.mjs +3 -5
- package/pipeline/scripts/call-graph/index.mjs +78 -0
- package/pipeline/scripts/call-graph/lang/cpp.mjs +308 -0
- package/pipeline/scripts/call-graph/lang/csharp.mjs +130 -0
- package/pipeline/scripts/call-graph/lang/go.mjs +303 -0
- package/pipeline/scripts/call-graph/lang/java.mjs +370 -0
- package/pipeline/scripts/call-graph/lang/kotlin.mjs +397 -0
- package/pipeline/scripts/call-graph/lang/python.mjs +399 -0
- package/pipeline/scripts/call-graph/lang/rust.mjs +345 -0
- package/pipeline/scripts/call-graph/lang/shared.mjs +230 -0
- package/pipeline/scripts/call-graph/lang/swift.mjs +432 -0
- package/pipeline/scripts/call-graph/lang/typescript.mjs +692 -0
- package/pipeline/scripts/call-graph/lex.mjs +396 -0
- package/pipeline/scripts/call-graph/platform.mjs +86 -0
- package/pipeline/scripts/call-graph/profiles.mjs +89 -0
- package/pipeline/scripts/call-graph/resolve.mjs +1125 -0
- package/pipeline/scripts/call-graph/scan.mjs +267 -0
- package/pipeline/scripts/code-graph-rules/android.json +7 -2
- package/pipeline/scripts/code-graph-rules/cpp.json +99 -0
- package/pipeline/scripts/code-graph-rules/csharp.json +102 -0
- package/pipeline/scripts/code-graph-rules/go.json +2 -1
- package/pipeline/scripts/code-graph-rules/ios.json +3 -1
- package/pipeline/scripts/code-graph-rules/java.json +76 -0
- package/pipeline/scripts/code-graph-rules/node.json +7 -2
- package/pipeline/scripts/code-graph-rules/python.json +6 -2
- package/pipeline/scripts/code-graph-rules/rust.json +105 -0
- package/pipeline/scripts/contract-server.mjs +1 -0
- package/pipeline/scripts/cost-table.json +6 -5
- package/pipeline/scripts/feedback-send.mjs +26 -26
- package/pipeline/scripts/gate-ledger.mjs +2 -1
- package/pipeline/scripts/gen-usage-names.mjs +124 -0
- package/pipeline/scripts/graph-affected.mjs +109 -20
- package/pipeline/scripts/graph-build.mjs +95 -15
- package/pipeline/scripts/graph-export.mjs +272 -0
- package/pipeline/scripts/graph-hint.mjs +15 -2
- package/pipeline/scripts/graph-query.mjs +305 -26
- package/pipeline/scripts/graph-report.mjs +187 -1
- package/pipeline/scripts/health-report.mjs +3 -4
- package/pipeline/scripts/infra/docs.mjs +317 -0
- package/pipeline/scripts/infra/extract.mjs +998 -0
- package/pipeline/scripts/infra/graph.mjs +245 -0
- package/pipeline/scripts/infra/yaml-lite.mjs +311 -0
- package/pipeline/scripts/job-launch.mjs +67 -2
- package/pipeline/scripts/learning-curve.mjs +288 -178
- package/pipeline/scripts/log-metric.sh +10 -1
- package/pipeline/scripts/note-agent-event.mjs +3 -4
- package/pipeline/scripts/note-command-use.mjs +333 -0
- package/pipeline/scripts/note-command-use.sh +126 -0
- package/pipeline/scripts/note-mcp-call.sh +89 -0
- package/pipeline/scripts/note-mcp-failure.mjs +272 -1
- package/pipeline/scripts/note-session.sh +62 -3
- package/pipeline/scripts/note-skill-use.mjs +58 -2
- package/pipeline/scripts/office-build.mjs +115 -1
- package/pipeline/scripts/office-memory.mjs +14 -5
- package/pipeline/scripts/pair.mjs +333 -0
- package/pipeline/scripts/pre-push-check.sh +1 -1
- package/pipeline/scripts/remote/cbor.mjs +128 -0
- package/pipeline/scripts/remote/contract.mjs +98 -0
- package/pipeline/scripts/remote/handler.mjs +317 -0
- package/pipeline/scripts/remote/handles.mjs +57 -0
- package/pipeline/scripts/remote/lifecycle.mjs +186 -0
- package/pipeline/scripts/remote/listener.mjs +204 -0
- package/pipeline/scripts/remote/lockout.mjs +103 -0
- package/pipeline/scripts/remote/nonces.mjs +61 -0
- package/pipeline/scripts/remote/pairing.mjs +519 -0
- package/pipeline/scripts/remote/qr-encode.mjs +459 -0
- package/pipeline/scripts/remote/store.mjs +188 -0
- package/pipeline/scripts/remote/transport.mjs +211 -0
- package/pipeline/scripts/remote/verbs.json +70 -0
- package/pipeline/scripts/remote/verbs.mjs +217 -0
- package/pipeline/scripts/remote/webauthn.mjs +169 -0
- package/pipeline/scripts/remote/wire.mjs +364 -0
- package/pipeline/scripts/remote-listener.mjs +83 -0
- package/pipeline/scripts/route-learn.mjs +4 -4
- package/pipeline/scripts/run-kill.mjs +1 -1
- package/pipeline/scripts/run-write.mjs +13 -2
- package/pipeline/scripts/runs-index.mjs +30 -3
- package/pipeline/scripts/search-logs.sh +9 -0
- package/pipeline/scripts/session-brief.mjs +458 -0
- package/pipeline/scripts/session-brief.sh +130 -0
- package/pipeline/scripts/test-gap-rules/cpp.json +25 -0
- package/pipeline/scripts/test-gap-rules/csharp.json +20 -0
- package/pipeline/scripts/test-gap-rules/java.json +20 -0
- package/pipeline/scripts/test-gap-rules/rust.json +14 -0
- package/pipeline/scripts/token-budget-report.mjs +3 -2
- package/pipeline/scripts/uninstall.mjs +29 -0
- package/pipeline/scripts/usage-access.mjs +16 -31
- package/pipeline/scripts/usage-health.mjs +31 -62
- package/pipeline/scripts/usage-register-beacon.mjs +11 -22
- package/pipeline/scripts/usage-register.mjs +39 -29
- package/pipeline/scripts/usage-report.mjs +579 -178
- package/pipeline/scripts/validate-code-graph.mjs +361 -111
- package/pipeline/scripts/write-state.mjs +39 -0
- package/pipeline/skills/.skill-manifest.json +22 -18
- package/pipeline/skills/.skills-index.json +13 -2
- package/pipeline/skills/shared/README.md +5 -4
- package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-diff-explain/SKILL.md +3 -3
- package/pipeline/skills/shared/core/multi-agent-fable-status/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +55 -21
- package/pipeline/skills/shared/core/multi-agent-pair/SKILL.md +41 -0
- package/pipeline/skills/shared/core/multi-agent-prune-prompts/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
- package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -3
- package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +2 -2
- package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +2 -2
- package/pipeline/skills/shared/external/app-store-review/SKILL.md +11 -4
- package/pipeline/skills/shared/external/build-settings-audit/SKILL.md +1 -1
- package/pipeline/skills/shared/external/build-time-benchmark/SKILL.md +5 -5
- package/pipeline/skills/shared/external/build-time-fixes/SKILL.md +5 -5
- package/pipeline/skills/shared/external/build-time-optimizer/SKILL.md +6 -6
- package/pipeline/skills/shared/external/free-llm-apis/references/providers.md +1 -0
- package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +2 -2
- package/pipeline/skills/shared/external/ios-haptics/references/core-haptics.md +1 -1
- package/pipeline/skills/shared/external/localization-reuse-map/references/publish-and-snapshot.md +1 -1
- package/pipeline/skills/shared/external/package-build-audit/SKILL.md +3 -3
- package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +2 -3
- package/pipeline/skills/shared/external/swift-compile-hotspots/SKILL.md +2 -2
- package/pipeline/skills/shared/external/weatherkit/SKILL.md +5 -6
- package/pipeline/skills/skills-index.md +3 -2
- package/docs/FIGMA_PIPELINE.md +0 -137
- package/pipeline/lib/identifier-scan.mjs +0 -156
- package/pipeline/scripts/publish-staged.mjs +0 -324
- package/pipeline/skills/shared/external/ios-coding-standard/scripts/check_structure.py +0 -765
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file python.mjs - Python profile for the call-edge scanner.
|
|
3
|
+
*
|
|
4
|
+
* Structure comes from indentation, as the language defines it: a block runs to
|
|
5
|
+
* the next statement at the same or a lower column. Fields are the class-level
|
|
6
|
+
* annotations and `self.x = ...` assignments (typed by an annotation, a
|
|
7
|
+
* constructor call, or a typed parameter assigned straight through). Dynamic
|
|
8
|
+
* features are out of reach: attributes added at runtime, `getattr`, decorators
|
|
9
|
+
* that change a signature, and duck-typed receivers, which fall back to a
|
|
10
|
+
* method name that is unique in the repository, at low confidence.
|
|
11
|
+
*
|
|
12
|
+
* @module pipeline/scripts/call-graph/lang/python
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { isIdent, readType, splitTop, tick } from "../lex.mjs";
|
|
16
|
+
|
|
17
|
+
const KEYWORDS = new Set(
|
|
18
|
+
`if elif else for while try except finally with as def class return yield raise import from pass
|
|
19
|
+
break continue lambda global nonlocal assert del in is not and or async await None True False
|
|
20
|
+
match case print`.split(/\s+/),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
function parseParams(tk, open, dropFirst) {
|
|
24
|
+
const params = [];
|
|
25
|
+
let min = 0;
|
|
26
|
+
let max = 0;
|
|
27
|
+
let idx = 0;
|
|
28
|
+
for (const [a, b] of splitTop(tk, open)) {
|
|
29
|
+
let k = a;
|
|
30
|
+
let stars = 0;
|
|
31
|
+
while (tk.t[k] === "*") {
|
|
32
|
+
stars++;
|
|
33
|
+
k++;
|
|
34
|
+
}
|
|
35
|
+
const variadic = stars > 0;
|
|
36
|
+
if (tk.t[k] === "/" || !isIdent(tk.t[k])) {
|
|
37
|
+
if (stars > 0 || tk.t[k] === "/") continue;
|
|
38
|
+
idx++;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const name = tk.t[k];
|
|
42
|
+
if (stars === 2) params.push(["**", "**", null]);
|
|
43
|
+
k++;
|
|
44
|
+
let type = null;
|
|
45
|
+
if (tk.t[k] === ":") {
|
|
46
|
+
type = readType(tk, k + 1, { limit: b, union: true }).name;
|
|
47
|
+
}
|
|
48
|
+
let hasDefault = false;
|
|
49
|
+
for (let z = k; z < b; z++) if (tk.t[z] === "=") hasDefault = true;
|
|
50
|
+
idx++;
|
|
51
|
+
if (idx === 1 && dropFirst) {
|
|
52
|
+
params.push([null, name, null]);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
params.push([name, name, type]);
|
|
56
|
+
if (variadic) max = Infinity;
|
|
57
|
+
else if (max !== Infinity) max++;
|
|
58
|
+
if (!hasDefault && !variadic) min++;
|
|
59
|
+
}
|
|
60
|
+
return { params, min, max };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function parse(tk) {
|
|
64
|
+
const t = tk.t;
|
|
65
|
+
const types = [];
|
|
66
|
+
const fns = [];
|
|
67
|
+
const gl = {};
|
|
68
|
+
const stmts = [];
|
|
69
|
+
for (let i = 0; i < tk.n; i++) if (tk.first[i] === 1 && tk.dep[i] === 0) stmts.push(i);
|
|
70
|
+
|
|
71
|
+
const blockEnd = (k, col) => {
|
|
72
|
+
let n = k + 1;
|
|
73
|
+
while (n < stmts.length && tk.col[stmts[n]] > col) n++;
|
|
74
|
+
return n < stmts.length ? stmts[n] : tk.n;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const lineEnd = (idx) => {
|
|
78
|
+
let j = idx;
|
|
79
|
+
while (j < tk.n && !(tk.first[j] === 1 && tk.dep[j] === 0 && j > idx)) j++;
|
|
80
|
+
return j;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const walk = (lo, hi, owner, col) => {
|
|
84
|
+
let k = stmts.findIndex((s) => s >= lo);
|
|
85
|
+
if (k < 0) return;
|
|
86
|
+
let decorators = [];
|
|
87
|
+
while (k < stmts.length && stmts[k] < hi) {
|
|
88
|
+
const i = stmts[k];
|
|
89
|
+
const c = tk.col[i];
|
|
90
|
+
let j = i;
|
|
91
|
+
if (t[j] === "@") {
|
|
92
|
+
decorators.push(t[j + 1]);
|
|
93
|
+
k++;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (t[j] === "async" && t[j + 1] === "def") j++;
|
|
97
|
+
if (t[j] === "class" && isIdent(t[j + 1])) {
|
|
98
|
+
const name = t[j + 1];
|
|
99
|
+
j += 2;
|
|
100
|
+
const sup = [];
|
|
101
|
+
if (t[j] === "[" && tk.m[j] > j) j = tk.m[j] + 1;
|
|
102
|
+
if (t[j] === "(" && tk.m[j] > j) {
|
|
103
|
+
for (const [a, b] of splitTop(tk, j)) {
|
|
104
|
+
if (isIdent(t[a]) && t[a + 1] !== "=") {
|
|
105
|
+
const r = readType(tk, a, { limit: b });
|
|
106
|
+
if (r.name) sup.push(r.name);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const end = blockEnd(k, c);
|
|
111
|
+
const rec = {
|
|
112
|
+
n: name,
|
|
113
|
+
k: "class",
|
|
114
|
+
line: tk.line[i],
|
|
115
|
+
end: tk.line[Math.max(i, end - 1)],
|
|
116
|
+
sup,
|
|
117
|
+
f: {},
|
|
118
|
+
};
|
|
119
|
+
types.push(rec);
|
|
120
|
+
walk(i + 1, end, name, c);
|
|
121
|
+
decorators = [];
|
|
122
|
+
k = nextStmt(k, end);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (t[j] === "def" && isIdent(t[j + 1])) {
|
|
126
|
+
const name = t[j + 1];
|
|
127
|
+
let p = j + 2;
|
|
128
|
+
if (t[p] === "[" && tk.m[p] > p) p = tk.m[p] + 1;
|
|
129
|
+
if (t[p] === "(" && tk.m[p] > p) {
|
|
130
|
+
const isStatic = decorators.includes("staticmethod");
|
|
131
|
+
const dropFirst = owner && !isStatic;
|
|
132
|
+
const sig = parseParams(tk, p, dropFirst);
|
|
133
|
+
let q = tk.m[p] + 1;
|
|
134
|
+
let ret = null;
|
|
135
|
+
if (t[q] === "->") {
|
|
136
|
+
const r = readType(tk, q + 1, { limit: tk.n, union: true });
|
|
137
|
+
ret = r.name;
|
|
138
|
+
q = r.next;
|
|
139
|
+
}
|
|
140
|
+
const end = blockEnd(k, c);
|
|
141
|
+
while (q < end && t[q] !== ":") q = tk.m[q] > q ? tk.m[q] + 1 : q + 1;
|
|
142
|
+
const bodyFrom = q + 1;
|
|
143
|
+
const rec = [...types].reverse().find((x) => x.n === owner);
|
|
144
|
+
if (rec && decorators.includes("property") && ret) rec.f[name] = ret;
|
|
145
|
+
if (rec && name === "__init__") collectFields(rec, bodyFrom, end, sig.params);
|
|
146
|
+
else if (rec) collectFields(rec, bodyFrom, end, sig.params);
|
|
147
|
+
fns.push({
|
|
148
|
+
n: name === "__init__" ? "__init__" : name,
|
|
149
|
+
o: owner,
|
|
150
|
+
a: [sig.min, sig.max],
|
|
151
|
+
p: sig.params.filter((q2) => q2[0] !== null),
|
|
152
|
+
r: name === "__init__" ? owner : ret,
|
|
153
|
+
l: tk.line[i],
|
|
154
|
+
e: tk.line[Math.max(i, end - 1)],
|
|
155
|
+
...(isStatic || decorators.includes("classmethod") ? { s: 1 } : {}),
|
|
156
|
+
body: [bodyFrom, end],
|
|
157
|
+
});
|
|
158
|
+
decorators = [];
|
|
159
|
+
k = nextStmt(k, end);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (owner && c > col && isIdent(t[i]) && t[i + 1] === ":" && tk.col[i] === tk.col[stmts[k]]) {
|
|
164
|
+
const rec = [...types].reverse().find((x) => x.n === owner);
|
|
165
|
+
const r = readType(tk, i + 2, { limit: lineEnd(i), union: true });
|
|
166
|
+
if (rec && r.name && tk.dep[i] === 0 && fieldIsClassLevel(i)) rec.f[t[i]] = r.name;
|
|
167
|
+
} else if (
|
|
168
|
+
owner &&
|
|
169
|
+
isIdent(t[i]) &&
|
|
170
|
+
t[i + 1] === "=" &&
|
|
171
|
+
isIdent(t[i + 2]) &&
|
|
172
|
+
/^[A-Z]/.test(t[i + 2]) &&
|
|
173
|
+
t[i + 3] === "("
|
|
174
|
+
) {
|
|
175
|
+
const rec = [...types].reverse().find((x) => x.n === owner);
|
|
176
|
+
if (rec) rec.f[t[i]] = t[i + 2];
|
|
177
|
+
} else if (!owner && tk.col[i] === 0 && isIdent(t[i])) {
|
|
178
|
+
if (t[i + 1] === "=" && isIdent(t[i + 2]) && /^[A-Z]/.test(t[i + 2]) && t[i + 3] === "(")
|
|
179
|
+
gl[t[i]] = t[i + 2];
|
|
180
|
+
else if (t[i + 1] === ":") {
|
|
181
|
+
const r = readType(tk, i + 2, { limit: lineEnd(i), union: true });
|
|
182
|
+
if (r.name) gl[t[i]] = r.name;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
decorators = [];
|
|
186
|
+
k++;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const fieldIsClassLevel = () => true;
|
|
191
|
+
const nextStmt = (k, end) => {
|
|
192
|
+
let n = k + 1;
|
|
193
|
+
while (n < stmts.length && stmts[n] < end) n++;
|
|
194
|
+
return n;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const collectFields = (rec, from, to, params) => {
|
|
198
|
+
const byName = new Map(params.map((p) => [p[1], p[2]]));
|
|
199
|
+
for (let i = from; i < to - 3; i++) {
|
|
200
|
+
if (t[i] !== "self" || t[i + 1] !== "." || !isIdent(t[i + 2]) || tk.dep[i] !== tk.dep[from])
|
|
201
|
+
continue;
|
|
202
|
+
if (t[i - 1] === ".") continue;
|
|
203
|
+
const name = t[i + 2];
|
|
204
|
+
let j = i + 3;
|
|
205
|
+
let type = null;
|
|
206
|
+
if (t[j] === ":") {
|
|
207
|
+
const r = readType(tk, j + 1, { limit: to, union: true });
|
|
208
|
+
type = r.name;
|
|
209
|
+
j = r.next;
|
|
210
|
+
}
|
|
211
|
+
if (t[j] !== "=") continue;
|
|
212
|
+
if (!type) {
|
|
213
|
+
const c = t[j + 1];
|
|
214
|
+
if (isIdent(c) && /^[A-Z]/.test(c) && t[j + 2] === "(") type = c;
|
|
215
|
+
else if (
|
|
216
|
+
isIdent(c) &&
|
|
217
|
+
byName.get(c) &&
|
|
218
|
+
(tk.first[j + 2] === 1 || j + 2 >= to || t[j + 2] === ";")
|
|
219
|
+
)
|
|
220
|
+
type = byName.get(c);
|
|
221
|
+
}
|
|
222
|
+
if (type && !rec.f[name]) rec.f[name] = type;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
walk(0, tk.n, null, -1);
|
|
227
|
+
|
|
228
|
+
const top = [];
|
|
229
|
+
const covered = [];
|
|
230
|
+
const mark = (lo, hi) => covered.push([lo, hi]);
|
|
231
|
+
for (const f of fns) if (!f.o && f.body) mark(0, 0);
|
|
232
|
+
void mark;
|
|
233
|
+
let k = 0;
|
|
234
|
+
while (k < stmts.length) {
|
|
235
|
+
tick(tk);
|
|
236
|
+
const i = stmts[k];
|
|
237
|
+
if (tk.col[i] !== 0) {
|
|
238
|
+
k++;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
const head = t[i] === "async" ? t[i + 1] : t[i];
|
|
242
|
+
const end = blockEnd(k, 0);
|
|
243
|
+
if (
|
|
244
|
+
head === "def" ||
|
|
245
|
+
head === "class" ||
|
|
246
|
+
head === "@" ||
|
|
247
|
+
head === "import" ||
|
|
248
|
+
head === "from"
|
|
249
|
+
) {
|
|
250
|
+
k = nextStmt(k, end);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
top.push([i, end]);
|
|
254
|
+
k = nextStmt(k, end);
|
|
255
|
+
}
|
|
256
|
+
return { types, fns, binds: [], gl, top };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function localDecl(tk, i, end) {
|
|
260
|
+
const t = tk.t;
|
|
261
|
+
if (tk.dep[i] !== tk.dep[i - 1 < 0 ? 0 : i - 1] && i > 0 && tk.first[i] === 1 && tk.dep[i] > 0)
|
|
262
|
+
return null;
|
|
263
|
+
const s = t[i];
|
|
264
|
+
const defAt = s === "async" && t[i + 1] === "def" ? i + 1 : s === "def" ? i : -1;
|
|
265
|
+
if (defAt >= 0 && isIdent(t[defAt + 1]))
|
|
266
|
+
return { name: t[defAt + 1], type: null, init: null, next: defAt + 2 };
|
|
267
|
+
if (s === "for" && isIdent(t[i + 1])) {
|
|
268
|
+
const names = [];
|
|
269
|
+
let k = i + 1;
|
|
270
|
+
while (k < end && t[k] !== "in") {
|
|
271
|
+
if (isIdent(t[k])) names.push(t[k]);
|
|
272
|
+
k++;
|
|
273
|
+
}
|
|
274
|
+
return names.length
|
|
275
|
+
? { name: names[0], also: names.slice(1), type: null, init: null, next: i + 1 }
|
|
276
|
+
: null;
|
|
277
|
+
}
|
|
278
|
+
if (s === "with" || s === "except") {
|
|
279
|
+
for (let k = i + 1; k < end && !(tk.first[k] === 1); k++) {
|
|
280
|
+
if (t[k] === "as" && isIdent(t[k + 1])) {
|
|
281
|
+
if (s === "except") {
|
|
282
|
+
const ty = readType(tk, i + 1, { limit: k }).name;
|
|
283
|
+
return { name: t[k + 1], type: ty, init: null, next: i + 1 };
|
|
284
|
+
}
|
|
285
|
+
return { name: t[k + 1], type: null, init: null, next: i + 1 };
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
if (!isIdent(s) || KEYWORDS.has(s) || tk.dep[i] !== 0 || tk.first[i] !== 1) return null;
|
|
291
|
+
if (t[i + 1] === ",") {
|
|
292
|
+
const names = [s];
|
|
293
|
+
let k = i + 1;
|
|
294
|
+
while (t[k] === "," && isIdent(t[k + 1])) {
|
|
295
|
+
names.push(t[k + 1]);
|
|
296
|
+
k += 2;
|
|
297
|
+
}
|
|
298
|
+
if (t[k] === "=")
|
|
299
|
+
return { name: names[0], also: names.slice(1), type: null, init: k + 1, next: k + 1 };
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
let j = i + 1;
|
|
303
|
+
let type = null;
|
|
304
|
+
if (t[j] === ":") {
|
|
305
|
+
const r = readType(tk, j + 1, { limit: end, union: true });
|
|
306
|
+
type = r.name;
|
|
307
|
+
j = r.next;
|
|
308
|
+
}
|
|
309
|
+
if (t[j] === "=" && t[j + 1] !== "=") return { name: s, type, init: j + 1, next: j + 1 };
|
|
310
|
+
if (t[j] === "+=" || t[j] === "-=") return null;
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function lambdaParams(tk, i, end) {
|
|
315
|
+
const t = tk.t;
|
|
316
|
+
if (t[i] !== "lambda") return null;
|
|
317
|
+
const params = [];
|
|
318
|
+
let j = i + 1;
|
|
319
|
+
while (j < end && t[j] !== ":") {
|
|
320
|
+
if (isIdent(t[j])) params.push([t[j], null]);
|
|
321
|
+
j++;
|
|
322
|
+
}
|
|
323
|
+
return params.length ? { params } : null;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function binds(text) {
|
|
327
|
+
const out = [];
|
|
328
|
+
for (const m of text.matchAll(
|
|
329
|
+
/^[ \t]*import\s+([\w.]+(?:\s+as\s+\w+)?(?:\s*,\s*[\w.]+(?:\s+as\s+\w+)?)*)/gm,
|
|
330
|
+
)) {
|
|
331
|
+
for (const part of m[1].split(",")) {
|
|
332
|
+
const [mod, alias] = part.trim().split(/\s+as\s+/);
|
|
333
|
+
const last = mod.split(".").pop();
|
|
334
|
+
out.push({
|
|
335
|
+
l: alias || (mod.includes(".") && !alias ? mod.split(".")[0] : last),
|
|
336
|
+
m: mod,
|
|
337
|
+
x: null,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
for (const m of text.matchAll(
|
|
342
|
+
/^[ \t]*from\s+(\.*[\w.]*)\s+import\s+(\([^)]{0,4000}\)|[^\n(]+)/gm,
|
|
343
|
+
)) {
|
|
344
|
+
const mod = m[1];
|
|
345
|
+
const list = m[2].replace(/[()]/g, "").split(/[,\n]/);
|
|
346
|
+
for (const part of list) {
|
|
347
|
+
const [name, alias] = part.trim().split(/\s+as\s+/);
|
|
348
|
+
if (!name || name === "*") continue;
|
|
349
|
+
out.push({
|
|
350
|
+
l: alias || name,
|
|
351
|
+
m: mod,
|
|
352
|
+
x: name,
|
|
353
|
+
alt: mod.endsWith(".") ? `${mod}${name}` : `${mod}.${name}`,
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return out;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function moduleSuffixes(spec, fromPath) {
|
|
361
|
+
let mod = spec;
|
|
362
|
+
let dir = null;
|
|
363
|
+
if (spec.startsWith(".")) {
|
|
364
|
+
const dots = spec.match(/^\.+/)[0].length;
|
|
365
|
+
const parts = fromPath.split("/").slice(0, -1);
|
|
366
|
+
for (let n = 1; n < dots; n++) parts.pop();
|
|
367
|
+
dir = parts.join("/");
|
|
368
|
+
mod = spec.slice(dots);
|
|
369
|
+
}
|
|
370
|
+
const rel = mod.replace(/\./g, "/");
|
|
371
|
+
const stem = dir !== null ? [dir, rel].filter(Boolean).join("/") : rel;
|
|
372
|
+
if (!stem) return dir !== null ? [`${dir}/__init__.py`] : [];
|
|
373
|
+
return [`${stem}.py`, `${stem}/__init__.py`];
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export default {
|
|
377
|
+
id: "python",
|
|
378
|
+
stringType: "str",
|
|
379
|
+
exts: [".py"],
|
|
380
|
+
implicitSelf: false,
|
|
381
|
+
initName: "__init__",
|
|
382
|
+
selfWords: new Set(["self", "cls"]),
|
|
383
|
+
superWords: new Set(["super"]),
|
|
384
|
+
newKeyword: null,
|
|
385
|
+
memberOps: new Set(["."]),
|
|
386
|
+
labelOps: ["="],
|
|
387
|
+
keywords: KEYWORDS,
|
|
388
|
+
declWords: new Set(["def", "class", "import", "from", "as", "global", "nonlocal"]),
|
|
389
|
+
condWords: new Set(["with", "except"]),
|
|
390
|
+
bareCallConstructs: true,
|
|
391
|
+
superCall: true,
|
|
392
|
+
keepStrings: false,
|
|
393
|
+
topLevel: true,
|
|
394
|
+
parse,
|
|
395
|
+
localDecl,
|
|
396
|
+
lambdaParams,
|
|
397
|
+
binds: (text) => binds(text),
|
|
398
|
+
moduleSuffixes,
|
|
399
|
+
};
|