@memorax/memorax-code 0.1.11 → 0.1.12
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 +7 -4
- package/bin/memorax-code-setup.mjs +136 -34
- package/bin/memorax-code-trae.mjs +4 -0
- package/docs/configuration.md +106 -52
- package/docs/troubleshooting.md +45 -6
- package/lib/memorax-code-backend/dist/clients/claude/transcript-turn.js +2 -2
- package/lib/memorax-code-backend/dist/clients/codex/rollout-turn.js +1 -1
- package/lib/memorax-code-backend/dist/clients/trae/lifecycle.js +53 -0
- package/lib/memorax-code-backend/dist/clients/trae/memory-hook-runtime.js +302 -0
- package/lib/memorax-code-backend/dist/clients/trae/turn-id.js +16 -0
- package/lib/memorax-code-backend/dist/config/memorax-code.js +14 -1
- package/lib/memorax-code-backend/dist/entrypoints/backend-cli.js +22 -4
- package/lib/memorax-code-backend/dist/lifecycle/active-clients.js +3 -0
- package/lib/memorax-code-backend/dist/lifecycle/client-plugin-removal.js +14 -2
- package/lib/memorax-code-backend/dist/lifecycle/client-selection.js +5 -3
- package/lib/memorax-code-backend/dist/lifecycle/orchestrator.js +62 -9
- package/lib/memorax-code-backend/dist/memory/hook-command.js +34 -2
- package/lib/memorax-code-backend/dist/memory/reminder-trace-recorder.js +5 -1
- package/lib/memorax-code-backend/dist/memory/service.js +12 -0
- package/lib/memorax-code-backend/dist/trace/config.js +12 -1
- package/lib/memorax-code-backend/dist/trace/context.js +26 -1
- package/lib/memorax-code-backend/package.json +1 -1
- package/lib/memorax-code-claude-adapter/.claude-plugin/plugin.json +1 -1
- package/lib/memorax-code-claude-adapter/hooks/runtime-shell.json +1 -1
- package/lib/memorax-code-claude-adapter/package.json +1 -1
- package/lib/memorax-code-claude-adapter/skills/memorax-code/SKILL.md +3 -1
- package/lib/memorax-code-claude-adapter/skills/memorax-code/references/memorax-add.md +16 -3
- package/lib/memorax-code-claude-adapter/skills/memorax-code/references/memorax-search.md +15 -2
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/.claude-plugin/plugin.json +1 -1
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/hooks/runtime-shell.json +1 -1
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/package.json +1 -1
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/SKILL.md +3 -1
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/references/memorax-add.md +16 -3
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/references/memorax-search.md +15 -2
- package/lib/memorax-code-codebuddy-adapter/.codebuddy-plugin/plugin.json +1 -1
- package/lib/memorax-code-codebuddy-adapter/package.json +1 -1
- package/lib/memorax-code-codebuddy-adapter/skills/memorax-code/SKILL.md +3 -1
- package/lib/memorax-code-codebuddy-adapter/skills/memorax-code/references/memorax-add.md +16 -3
- package/lib/memorax-code-codebuddy-adapter/skills/memorax-code/references/memorax-search.md +15 -2
- package/lib/memorax-code-codex-adapter/.codex-plugin/plugin.json +1 -1
- package/lib/memorax-code-codex-adapter/hooks/runtime-shell.json +1 -1
- package/lib/memorax-code-codex-adapter/package.json +1 -1
- package/lib/memorax-code-codex-adapter/skills/memorax-code/SKILL.md +3 -1
- package/lib/memorax-code-codex-adapter/skills/memorax-code/references/memorax-add.md +16 -3
- package/lib/memorax-code-codex-adapter/skills/memorax-code/references/memorax-search.md +15 -2
- package/lib/memorax-code-dsh-adapter/package.json +1 -1
- package/lib/memorax-code-dsh-adapter/skills/memorax-code/SKILL.md +3 -1
- package/lib/memorax-code-dsh-adapter/skills/memorax-code/references/memorax-add.md +16 -3
- package/lib/memorax-code-dsh-adapter/skills/memorax-code/references/memorax-search.md +15 -2
- package/lib/memorax-code-opencode-adapter/package.json +1 -1
- package/lib/memorax-code-opencode-adapter/skills/memorax-code/SKILL.md +3 -1
- package/lib/memorax-code-opencode-adapter/skills/memorax-code/references/memorax-add.md +16 -3
- package/lib/memorax-code-opencode-adapter/skills/memorax-code/references/memorax-search.md +15 -2
- package/lib/memorax-code-trae-adapter/hooks/runtime-hook.mjs +340 -0
- package/lib/memorax-code-trae-adapter/package.json +9 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/SKILL.md +87 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/agents/claude.yaml +10 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/agents/openai.yaml +7 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/defaults.json +12 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/references/memorax-add.md +101 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/references/memorax-search.md +106 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/references/personal-read.md +46 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/references/personal-write.md +120 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/references/repo-build.md +319 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/references/repo-read.md +103 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/references/repo-templates.md +390 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/references/repo-update.md +127 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/scripts/collect_all.py +579 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/scripts/detect_updates.py +919 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/scripts/git_commit_facets.py +222 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/scripts/github_resource_facets.py +512 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/scripts/gitlab_resource_facets.py +517 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/scripts/prepare_repo_memory.py +411 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/scripts/user_profile_memory.py +528 -0
- package/lib/memorax-code-trae-adapter/skills/memorax-code/scripts/validate_memory.py +248 -0
- package/lib/memorax-code-trae-adapter/src/adapter-paths.mjs +69 -0
- package/lib/memorax-code-trae-adapter/src/cli.mjs +59 -0
- package/lib/memorax-code-trae-adapter/src/config.mjs +630 -0
- package/lib/memorax-code-trae-adapter/src/runtime-observation.mjs +55 -0
- package/lib/run-entrypoint.mjs +6 -0
- package/package.json +5 -3
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Validate authored repo-memory bundles."""
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
BASELINE_FILES = [
|
|
13
|
+
Path("PROFILE.md"),
|
|
14
|
+
Path("resources/commits.md"),
|
|
15
|
+
Path("resources/prs.md"),
|
|
16
|
+
Path("resources/issues.md"),
|
|
17
|
+
Path("raw/git-commits.json"),
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
PROVIDER_RAW_FILES = [Path("raw/github-facets.json"), Path("raw/gitlab-facets.json")]
|
|
21
|
+
PROVIDER_RESOURCE_FILES = [Path("resources/prs.md"), Path("resources/issues.md")]
|
|
22
|
+
DISABLED_RESOURCE_SOURCES = {"history_disabled", "provider_skipped_local_only", "provider_unavailable", "github_resource_facets_unavailable", "gitlab_resource_facets_unavailable", "provider_unavailable_local_only"}
|
|
23
|
+
USER_PROFILE_SIDECAR = Path("user-profile/preferences.md")
|
|
24
|
+
PROCEDURE_SIDECAR_DIRECTORY = "procedure-memory"
|
|
25
|
+
PLACEHOLDER_RE = re.compile(r"\[([^\]\n]+)\]")
|
|
26
|
+
LINK_TARGET_AFTER_BRACKET_RE = re.compile(r"[ \t\r\n]*\(")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def relative(path: Path, memory: Path) -> str:
|
|
30
|
+
return path.relative_to(memory).as_posix()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def resolve_memory_root(path: Path) -> Path:
|
|
34
|
+
candidate = path.expanduser().resolve()
|
|
35
|
+
if candidate.name == ".repo_memory":
|
|
36
|
+
return candidate
|
|
37
|
+
return candidate / ".repo_memory"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def parse_frontmatter(text: str) -> dict[str, Any]:
|
|
41
|
+
if not text.startswith("---\n"):
|
|
42
|
+
return {}
|
|
43
|
+
end = text.find("\n---", 4)
|
|
44
|
+
if end == -1:
|
|
45
|
+
return {}
|
|
46
|
+
values: dict[str, Any] = {}
|
|
47
|
+
for line in text[4:end].splitlines():
|
|
48
|
+
if ":" not in line:
|
|
49
|
+
continue
|
|
50
|
+
key, value = line.split(":", 1)
|
|
51
|
+
key = key.strip()
|
|
52
|
+
value = value.strip()
|
|
53
|
+
if not key:
|
|
54
|
+
continue
|
|
55
|
+
if (value.startswith('"') and value.endswith('"')) or (value.startswith("'") and value.endswith("'")):
|
|
56
|
+
values[key] = value[1:-1]
|
|
57
|
+
elif re.fullmatch(r"-?\d+", value):
|
|
58
|
+
values[key] = int(value)
|
|
59
|
+
elif value.lower() == "true":
|
|
60
|
+
values[key] = True
|
|
61
|
+
elif value.lower() == "false":
|
|
62
|
+
values[key] = False
|
|
63
|
+
else:
|
|
64
|
+
values[key] = value
|
|
65
|
+
return values
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def body_after_frontmatter(text: str) -> str:
|
|
69
|
+
if not text.startswith("---\n"):
|
|
70
|
+
return text
|
|
71
|
+
end = text.find("\n---", 4)
|
|
72
|
+
if end == -1:
|
|
73
|
+
return text
|
|
74
|
+
return text[end + 4 :].lstrip("\n")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def item_section_count(text: str) -> int:
|
|
78
|
+
body = body_after_frontmatter(text)
|
|
79
|
+
lines = body.splitlines()
|
|
80
|
+
title_seen = False
|
|
81
|
+
count = 0
|
|
82
|
+
for line in lines:
|
|
83
|
+
if line.startswith("# ") and not title_seen:
|
|
84
|
+
title_seen = True
|
|
85
|
+
continue
|
|
86
|
+
if title_seen and line.startswith("## "):
|
|
87
|
+
count += 1
|
|
88
|
+
return count
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def placeholder_matches(text: str) -> list[str]:
|
|
92
|
+
text = strip_markdown_code(text)
|
|
93
|
+
matches: list[str] = []
|
|
94
|
+
for match in PLACEHOLDER_RE.finditer(text):
|
|
95
|
+
if LINK_TARGET_AFTER_BRACKET_RE.match(text, match.end()):
|
|
96
|
+
continue
|
|
97
|
+
value = match.group(1).strip()
|
|
98
|
+
if not value or value.startswith("#"):
|
|
99
|
+
continue
|
|
100
|
+
if re.search(r"[A-Za-z]", value):
|
|
101
|
+
matches.append(f"[{value}]")
|
|
102
|
+
return matches
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def strip_markdown_code(text: str) -> str:
|
|
106
|
+
without_fences = re.sub(r"```.*?```", "", text, flags=re.DOTALL)
|
|
107
|
+
return re.sub(r"`[^`\n]*`", "", without_fences)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def check_exists(memory: Path, rel_path: Path, errors: list[str], checked: list[str]) -> bool:
|
|
111
|
+
path = memory / rel_path
|
|
112
|
+
checked.append(rel_path.as_posix())
|
|
113
|
+
if not path.exists():
|
|
114
|
+
errors.append(f"{rel_path.as_posix()}: required file is missing")
|
|
115
|
+
return False
|
|
116
|
+
if not path.is_file():
|
|
117
|
+
errors.append(f"{rel_path.as_posix()}: expected a file")
|
|
118
|
+
return False
|
|
119
|
+
return True
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def validate_json(path: Path, memory: Path, errors: list[str], checked: list[str]) -> None:
|
|
123
|
+
checked.append(relative(path, memory))
|
|
124
|
+
try:
|
|
125
|
+
json.loads(path.read_text(encoding="utf-8"))
|
|
126
|
+
except json.JSONDecodeError as exc:
|
|
127
|
+
errors.append(f"{relative(path, memory)}: invalid JSON at line {exc.lineno}, column {exc.colno}: {exc.msg}")
|
|
128
|
+
except OSError as exc:
|
|
129
|
+
errors.append(f"{relative(path, memory)}: could not read JSON: {exc}")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def raw_source_points_to_provider(raw_source: Any) -> bool:
|
|
133
|
+
return isinstance(raw_source, str) and raw_source.endswith(("github-facets.json", "gitlab-facets.json"))
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def validate_markdown(path: Path, memory: Path, errors: list[str], warnings: list[str], checked: list[str]) -> None:
|
|
137
|
+
checked.append(relative(path, memory))
|
|
138
|
+
try:
|
|
139
|
+
text = path.read_text(encoding="utf-8")
|
|
140
|
+
except OSError as exc:
|
|
141
|
+
errors.append(f"{relative(path, memory)}: could not read Markdown: {exc}")
|
|
142
|
+
return
|
|
143
|
+
|
|
144
|
+
frontmatter = parse_frontmatter(text)
|
|
145
|
+
rel = relative(path, memory)
|
|
146
|
+
if not frontmatter.get("schema"):
|
|
147
|
+
errors.append(f"{rel}: frontmatter field 'schema' is missing")
|
|
148
|
+
|
|
149
|
+
placeholders = placeholder_matches(text)
|
|
150
|
+
if placeholders:
|
|
151
|
+
errors.append(f"{rel}: unresolved bracket placeholder(s): {', '.join(placeholders)}")
|
|
152
|
+
|
|
153
|
+
if path.parent.name != "resources":
|
|
154
|
+
return
|
|
155
|
+
|
|
156
|
+
for field in ["source", "resource_count", "trust_state", "raw_source"]:
|
|
157
|
+
if field not in frontmatter:
|
|
158
|
+
errors.append(f"{rel}: frontmatter field '{field}' is missing")
|
|
159
|
+
|
|
160
|
+
expected = frontmatter.get("resource_count")
|
|
161
|
+
actual = item_section_count(text)
|
|
162
|
+
if isinstance(expected, int):
|
|
163
|
+
if expected != actual:
|
|
164
|
+
errors.append(f"{rel}: resource_count is {expected}, but found {actual} item section(s)")
|
|
165
|
+
elif expected is not None:
|
|
166
|
+
errors.append(f"{rel}: resource_count must be an integer")
|
|
167
|
+
|
|
168
|
+
source = frontmatter.get("source")
|
|
169
|
+
raw_source = frontmatter.get("raw_source")
|
|
170
|
+
if "source" in frontmatter and not source:
|
|
171
|
+
errors.append(f"{rel}: frontmatter field 'source' must not be empty")
|
|
172
|
+
if "trust_state" in frontmatter and not frontmatter.get("trust_state"):
|
|
173
|
+
errors.append(f"{rel}: frontmatter field 'trust_state' must not be empty")
|
|
174
|
+
if source in DISABLED_RESOURCE_SOURCES and isinstance(expected, int) and expected != 0:
|
|
175
|
+
errors.append(f"{rel}: disabled or unavailable resource source {source!r} must use resource_count 0")
|
|
176
|
+
if source in DISABLED_RESOURCE_SOURCES and raw_source:
|
|
177
|
+
errors.append(f"{rel}: disabled or unavailable resource source {source!r} must use an empty raw_source")
|
|
178
|
+
if path.name in {"commits.md", "prs.md", "issues.md"} and source not in DISABLED_RESOURCE_SOURCES and raw_source == "":
|
|
179
|
+
errors.append(f"{rel}: empty raw_source requires a disabled or unavailable source")
|
|
180
|
+
if path.name in {"prs.md", "issues.md"} and raw_source_points_to_provider(raw_source):
|
|
181
|
+
provider_path = (path.parent / raw_source).resolve()
|
|
182
|
+
if not provider_path.exists():
|
|
183
|
+
errors.append(f"{rel}: provider raw evidence is missing for raw_source {raw_source!r}")
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def provider_raw_paths(memory: Path) -> list[Path]:
|
|
187
|
+
return [memory / rel for rel in PROVIDER_RAW_FILES if (memory / rel).exists()]
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def validate(memory: Path) -> dict[str, Any]:
|
|
191
|
+
errors: list[str] = []
|
|
192
|
+
warnings: list[str] = []
|
|
193
|
+
checked: list[str] = []
|
|
194
|
+
|
|
195
|
+
if not memory.exists():
|
|
196
|
+
errors.append(f"{memory}: .repo_memory directory is missing")
|
|
197
|
+
return {"ok": False, "errors": errors, "warnings": warnings, "checked": checked}
|
|
198
|
+
if not memory.is_dir():
|
|
199
|
+
errors.append(f"{memory}: expected .repo_memory to be a directory")
|
|
200
|
+
return {"ok": False, "errors": errors, "warnings": warnings, "checked": checked}
|
|
201
|
+
|
|
202
|
+
for rel_path in BASELINE_FILES:
|
|
203
|
+
check_exists(memory, rel_path, errors, checked)
|
|
204
|
+
|
|
205
|
+
markdown_paths = sorted(
|
|
206
|
+
path
|
|
207
|
+
for path in memory.rglob("*.md")
|
|
208
|
+
if path.is_file()
|
|
209
|
+
and path.relative_to(memory) != USER_PROFILE_SIDECAR
|
|
210
|
+
and path.relative_to(memory).parts[0] != PROCEDURE_SIDECAR_DIRECTORY
|
|
211
|
+
)
|
|
212
|
+
for path in markdown_paths:
|
|
213
|
+
if path.exists() and path.is_file():
|
|
214
|
+
validate_markdown(path, memory, errors, warnings, checked)
|
|
215
|
+
|
|
216
|
+
json_paths = sorted(path for path in (memory / "raw").rglob("*.json") if path.is_file())
|
|
217
|
+
provider_raw = provider_raw_paths(memory)
|
|
218
|
+
|
|
219
|
+
if provider_raw:
|
|
220
|
+
for rel_path in PROVIDER_RESOURCE_FILES:
|
|
221
|
+
check_exists(memory, rel_path, errors, checked)
|
|
222
|
+
|
|
223
|
+
seen_json: set[Path] = set()
|
|
224
|
+
for path in json_paths:
|
|
225
|
+
if path.exists() and path.is_file() and path not in seen_json:
|
|
226
|
+
seen_json.add(path)
|
|
227
|
+
validate_json(path, memory, errors, checked)
|
|
228
|
+
|
|
229
|
+
checked = sorted(dict.fromkeys(checked))
|
|
230
|
+
return {"ok": not errors, "errors": errors, "warnings": warnings, "checked": checked}
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def parse_args(argv: list[str]) -> argparse.Namespace:
|
|
234
|
+
parser = argparse.ArgumentParser(description="Validate a repo-memory bundle.")
|
|
235
|
+
parser.add_argument("path", help="Path to a repository or its .repo_memory directory")
|
|
236
|
+
parser.add_argument("--pretty", action="store_true", help="Pretty-print JSON output")
|
|
237
|
+
return parser.parse_args(argv)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def main(argv: list[str]) -> int:
|
|
241
|
+
args = parse_args(argv)
|
|
242
|
+
report = validate(resolve_memory_root(Path(args.path)))
|
|
243
|
+
print(json.dumps(report, ensure_ascii=False, indent=2 if args.pretty else None))
|
|
244
|
+
return 0 if report["ok"] else 1
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
if __name__ == "__main__":
|
|
248
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join, resolve, win32 } from "node:path";
|
|
4
|
+
|
|
5
|
+
export function defaultTraeHome(env = process.env, home = homedir()) {
|
|
6
|
+
return resolve(stringOption(env.TRAE_CN_HOME) ?? stringOption(env.TRAE_HOME) ?? join(home, ".trae-cn"));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function defaultMemoraxCodeHome(env = process.env, home = homedir()) {
|
|
10
|
+
return resolve(stringOption(env.MEMORAX_CODE_HOME) ?? join(home, ".memorax-code"));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function traeHooksPath(traeHome = defaultTraeHome()) {
|
|
14
|
+
return join(traeHome, "hooks.json");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function traeSkillPath(traeHome = defaultTraeHome()) {
|
|
18
|
+
return join(traeHome, "skills", "memorax-code");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function traeAdapterRoot(memoraxCodeHome = defaultMemoraxCodeHome()) {
|
|
22
|
+
return join(memoraxCodeHome, "adapters", "trae");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function traeAdapterStatePath(memoraxCodeHome = defaultMemoraxCodeHome()) {
|
|
26
|
+
return join(traeAdapterRoot(memoraxCodeHome), "state.json");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function traeRuntimeRoot(memoraxCodeHome = defaultMemoraxCodeHome()) {
|
|
30
|
+
return join(traeAdapterRoot(memoraxCodeHome), "runtime", "generations");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function traeInstallationDetected({
|
|
34
|
+
env = process.env,
|
|
35
|
+
home = homedir(),
|
|
36
|
+
platform = process.platform,
|
|
37
|
+
pathExists = existsSync,
|
|
38
|
+
} = {}) {
|
|
39
|
+
if (stringOption(env.TRAE_CN_HOME) || stringOption(env.TRAE_HOME)) return true;
|
|
40
|
+
if (pathExists(defaultTraeHome(env, home))) return true;
|
|
41
|
+
return traeApplicationCandidates({ env, home, platform }).some(pathExists);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function traeApplicationCandidates({ env = process.env, home = homedir(), platform = process.platform } = {}) {
|
|
45
|
+
if (platform === "darwin") {
|
|
46
|
+
return [
|
|
47
|
+
"/Applications/Trae CN.app",
|
|
48
|
+
join(home, "Applications", "Trae CN.app"),
|
|
49
|
+
"/Applications/Trae.app",
|
|
50
|
+
join(home, "Applications", "Trae.app"),
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
if (platform === "win32") {
|
|
54
|
+
return [
|
|
55
|
+
env.LOCALAPPDATA && win32.join(env.LOCALAPPDATA, "Programs", "Trae CN"),
|
|
56
|
+
env.LOCALAPPDATA && win32.join(env.LOCALAPPDATA, "Programs", "Trae"),
|
|
57
|
+
env.ProgramFiles && win32.join(env.ProgramFiles, "Trae CN"),
|
|
58
|
+
env.ProgramFiles && win32.join(env.ProgramFiles, "Trae"),
|
|
59
|
+
].filter(Boolean);
|
|
60
|
+
}
|
|
61
|
+
return [
|
|
62
|
+
join(home, ".local", "share", "applications", "trae.desktop"),
|
|
63
|
+
"/usr/share/applications/trae.desktop",
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function stringOption(value) {
|
|
68
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
69
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
defaultTraeHome,
|
|
4
|
+
} from "./adapter-paths.mjs";
|
|
5
|
+
import {
|
|
6
|
+
disableTraeAdapter,
|
|
7
|
+
enableTraeAdapter,
|
|
8
|
+
readTraeAdapterStatus,
|
|
9
|
+
removeTraeAdapterInstallation,
|
|
10
|
+
} from "./config.mjs";
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const parsed = parseCli(process.argv);
|
|
14
|
+
if (parsed.help) {
|
|
15
|
+
console.log("Usage: memorax-code-trae [status|enable|disable|remove] [--trae-home DIR] [--json]");
|
|
16
|
+
process.exit(0);
|
|
17
|
+
}
|
|
18
|
+
const options = { traeHome: parsed.home };
|
|
19
|
+
const result = parsed.command === "status"
|
|
20
|
+
? await readTraeAdapterStatus(options)
|
|
21
|
+
: parsed.command === "enable"
|
|
22
|
+
? await enableTraeAdapter(options)
|
|
23
|
+
: parsed.command === "disable"
|
|
24
|
+
? await disableTraeAdapter(options)
|
|
25
|
+
: parsed.command === "remove"
|
|
26
|
+
? await removeTraeAdapterInstallation(options)
|
|
27
|
+
: undefined;
|
|
28
|
+
if (!result) throw new Error(`unknown command: ${parsed.command}`);
|
|
29
|
+
if (parsed.json) console.log(JSON.stringify(result, null, 2));
|
|
30
|
+
else console.log(`${result.action}: ${result.ok ? "ok" : "failed"}\nhome: ${result.traeHome ?? parsed.home}`);
|
|
31
|
+
const ready = result.ok === true
|
|
32
|
+
&& result.installed === true
|
|
33
|
+
&& result.enabled === true
|
|
34
|
+
&& result.traeHooks?.ok === true
|
|
35
|
+
&& result.traeSkills?.ok === true;
|
|
36
|
+
process.exit(parsed.command === "status" ? (ready ? 0 : 1) : (result.ok ? 0 : 1));
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function parseCli(argv) {
|
|
43
|
+
const args = argv.slice(2);
|
|
44
|
+
const command = args[0] && !args[0].startsWith("-") ? args.shift() : "status";
|
|
45
|
+
let home;
|
|
46
|
+
let json = false;
|
|
47
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
48
|
+
const arg = args[index];
|
|
49
|
+
if (arg === "--help") return { command, help: true };
|
|
50
|
+
if (arg === "--json") { json = true; continue; }
|
|
51
|
+
if (arg === "--trae-home") {
|
|
52
|
+
home = args[++index];
|
|
53
|
+
if (!home || home.startsWith("--")) throw new Error("--trae-home requires a value");
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
throw new Error(`unknown option: ${arg}`);
|
|
57
|
+
}
|
|
58
|
+
return { command, home: home ?? defaultTraeHome(), json, help: false };
|
|
59
|
+
}
|