bugx-cli 0.1.3 → 0.1.5
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/core/README.md +5 -3
- package/core/agent/agent_execution.py +7 -0
- package/core/assets/bugx-wechat-group.png +0 -0
- package/core/bugx.md +2 -2
- package/core/bugx_paths.py +10 -2
- package/core/bundled_docs/OVERVIEW.md +311 -0
- package/core/bundled_docs/README.md +10 -0
- package/core/bundled_docs/README_EN.md +278 -0
- package/core/bundled_docs/ai/01_AI_REFERENCE.md +838 -0
- package/core/bundled_docs/ai/02_AI_USAGE.md +161 -0
- package/core/bundled_docs/ai/03_AI_COMMANDS.md +322 -0
- package/core/bundled_docs/guides/01_USER_GUIDE.md +887 -0
- package/core/bundled_docs/guides/02_COMMANDS.md +935 -0
- package/core/bundled_docs/guides/03_TROUBLESHOOTING.md +763 -0
- package/core/bundled_docs/guides/04_CLOUD_AUTH_AND_SYNC_COOKBOOK.md +48 -0
- package/core/bundled_docs/guides/05_HOST_MATRIX_AND_DISPATCH.md +25 -0
- package/core/bundled_docs/guides/06_PROBES_AND_POC_COOKBOOK.md +49 -0
- package/core/bundled_docs/guides/07_LIFECYCLE_AND_RECOVERY_STATES.md +46 -0
- package/core/bundled_docs/guides/08_LESSONS_AND_PRIVACY_BOUNDARY.md +35 -0
- package/core/bundled_docs/hosts/bugx-claude_SKILL.md +326 -0
- package/core/bundled_docs/hosts/bugx-dsh_SKILL.md +229 -0
- package/core/bundled_docs/hosts/bugx-opencode_SKILL.md +129 -0
- package/core/bundled_docs/hosts/bugx-zcode_SKILL.md +459 -0
- package/core/bundled_docs/hosts/bugx_SKILL.md +118 -0
- package/core/bundled_docs/hosts/cline_bugx_SKILL.md +69 -0
- package/core/bundled_docs/hosts/platform_bugx_SKILL.md +50 -0
- package/core/bundled_docs/manifest.json +140 -0
- package/core/bundled_docs/reference/01_ENVIRONMENT_VARIABLES.md +422 -0
- package/core/bundled_docs/reference/04_REPOSITORY_TOPOLOGY.md +180 -0
- package/core/cli-help.txt +7 -3
- package/core/cloud_sync/cloud_client.py +81 -2
- package/core/cloud_sync/endpoint_router.py +22 -9
- package/core/cloud_sync/issue_uploader.py +297 -0
- package/core/cloud_sync/sensitive_filter.py +77 -7
- package/core/contracts/AGENT_GUIDE.md +3 -9
- package/core/contracts/README.md +1 -1
- package/core/contracts/bugx-runtime-contract.md +10 -20
- package/core/contracts/bugx-worker.md +1 -1
- package/core/coverage/coverage_ai_review.py +15 -11
- package/core/coverage/coverage_bootstrap.py +18 -13
- package/core/coverage/coverage_discovery.py +1 -1
- package/core/dev_harness/interaction_preset.py +1 -1
- package/core/engine-integrity.json +283 -159
- package/core/host_acp/README.md +4 -0
- package/core/host_acp/agnescode.py +128 -0
- package/core/host_acp/antigravity.py +153 -0
- package/core/host_runtime/README.md +3 -0
- package/core/host_runtime/adapters.py +5 -1
- package/core/host_runtime/antigravity.py +162 -0
- package/core/host_runtime/host_bootstrap.py +18 -7
- package/core/host_runtime/host_evaluators.py +4 -4
- package/core/host_runtime/host_registry.py +3 -1
- package/core/host_runtime/mcp_process_tracker.py +30 -3
- package/core/host_runtime/mcp_registry_gate.py +34 -11
- package/core/hosts/README.md +4 -0
- package/core/hosts/agnescode.py +415 -0
- package/core/hosts/antigravity.py +115 -0
- package/core/hosts/codex.py +3 -0
- package/core/hosts/dsh.py +42 -23
- package/core/hosts/minimax.py +5 -4
- package/core/hosts/opencode.py +11 -3
- package/core/i18n.py +94 -5
- package/core/infra/README.md +1 -1
- package/core/infra/build_info.py +2 -2
- package/core/infra/python_runtime.py +4 -1
- package/core/launch_phases/README.md +2 -2
- package/core/launch_phases/finding_confirm_phase.py +1 -1
- package/core/launch_phases/semantic_recon.py +3 -19
- package/core/launch_phases/startup_version_gate.py +2 -2
- package/core/launch_phases/supervisor_bridge.py +2 -0
- package/core/launch_phases/supervisor_degraded.py +7 -5
- package/core/launch_phases/verify_loop.py +3 -19
- package/core/ledger/README.md +1 -1
- package/core/ledger/finding_confirmation.py +1 -1
- package/core/ledger/finding_verification.py +2 -20
- package/core/ledger/fp_ledger.py +3 -19
- package/core/ledger/life_ledger.py +7 -33
- package/core/ledger/schema.py +1 -1
- package/core/locales/en-US.json +3 -3
- package/core/locales/zh-CN.json +3 -3
- package/core/mcp_handlers/supervisor_handlers.py +1 -1
- package/core/mcp_runtime_support/common.py +6 -0
- package/core/mcp_runtime_support/environment.py +88 -24
- package/core/metadata.txt +1 -1
- package/core/planning/README.md +1 -1
- package/core/planning/prompt_harness.py +2 -2
- package/core/planning/target_sandbox_manager.py +2 -0
- package/core/probes/codebase_memory_probe.py +43 -24
- package/core/probes/mobile_probe.py +1 -0
- package/core/probes/probe_registry.py +10 -7
- package/core/probes/sast_probe.py +1 -1
- package/core/probes/sca_scanner.py +1 -1
- package/core/project_profiler/constants.py +1 -1
- package/core/prompts/command_routing_en.md +6 -5
- package/core/prompts/command_routing_zh.md +6 -5
- package/core/repair/rsi_rounds.py +3 -0
- package/core/repair/self_heal.py +160 -6
- package/core/retrieval/README.md +1 -1
- package/core/retrieval/symbol_index.py +227 -52
- package/core/runtime/README.md +1 -1
- package/core/runtime/daemon_runner.py +3 -2
- package/core/runtime/project_init.py +1 -1
- package/core/runtime/scenario_eval.py +5 -1
- package/core/runtime/tool_install_targets.py +12 -2
- package/core/skills/README.md +4 -2
- package/core/skills/bugx_docs_cloud_sync.py +658 -0
- package/core/skills/bugx_docs_mcp_server.py +966 -140
- package/core/skills/bugx_mcp_server.py +9 -0
- package/core/skills/mcp_session_proof.py +3 -31
- package/core/supervisor/README.md +1 -1
- package/core/supervisor/finding_commit.py +3 -24
- package/core/supervisor/task_scheduler.py +5 -2
- package/core/supervisor/worker_execution.py +16 -3
- package/core/supervisor/worker_handoff.py +2 -2
- package/core/webui/docs_session_service.py +40 -2
- package/core/webui/mcp_inspector.py +6 -6
- package/ecosystem/integrations/cline/skills/bugx/SKILL.md +46 -46
- package/ecosystem/integrations/dsh/agents/bugx.md +2 -1
- package/ecosystem/integrations/dsh/mcp/package.json +1 -1
- package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +5 -5
- package/ecosystem/integrations/dsh/ui/package.json +1 -1
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +4 -4
- package/ecosystem/integrations/opencode/mcp-lock.json +1 -1
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
- package/ecosystem/integrations/pi/skills/bugx/SKILL.md +5 -5
- package/ecosystem/integrations/qoder/CONNECTORS.md +11 -23
- package/ecosystem/integrations/qoder/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +8 -7
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/agents/bugx-worker.md +14 -18
- package/ecosystem/plugins/bugx/agents/bugx.md +45 -49
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +7 -7
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +2 -2
- package/interfaces/cli/bugx_cli/__init__.py +1 -1
- package/interfaces/cli/bugx_cli/cli.py +153 -8
- package/interfaces/cli/bugx_cli/commands/agent.py +376 -69
- package/interfaces/cli/bugx_cli/commands/audit.py +2 -1
- package/interfaces/cli/bugx_cli/commands/cloud.py +42 -1
- package/interfaces/cli/bugx_cli/commands/doctor.py +650 -223
- package/interfaces/cli/bugx_cli/commands/guide.py +143 -0
- package/interfaces/cli/bugx_cli/commands/issue.py +262 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +56 -26
- package/interfaces/cli/bugx_cli/commands/patch.py +5 -1
- package/interfaces/cli/bugx_cli/commands/plugin.py +306 -56
- package/interfaces/cli/bugx_cli/commands/plugin_antigravity.py +350 -0
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +2 -2
- package/interfaces/cli/bugx_cli/commands/plugin_kimi.py +154 -62
- package/interfaces/cli/bugx_cli/commands/plugin_minimax.py +308 -108
- package/interfaces/cli/bugx_cli/commands/system.py +11 -1
- package/interfaces/cli/bugx_cli/common.py +39 -8
- package/interfaces/cli/bugx_cli/host_adapters.py +46 -3
- package/interfaces/cli/bugx_cli/hosts/registry.py +3 -2
- package/interfaces/cli/bugx_cli/hosts/template_engine.py +21 -2
- package/interfaces/cli/bugx_cli/infra/__init__.py +4 -0
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +14 -12
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +76 -10
- package/interfaces/cli/bugx_cli/infra/host_sync.py +66 -1
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +240 -50
- package/package.json +3 -2
- package/pyproject.toml +22 -2
- package/scripts/sync-version.mjs +1 -1
- package/skills/README.md +1 -2
- package/skills/platform/bugx/SKILL.md +50 -0
- package/skills/platform/bugx-user/SKILL.md +0 -92
package/core/hosts/dsh.py
CHANGED
|
@@ -250,18 +250,34 @@ def _uninstall_hint() -> str:
|
|
|
250
250
|
)
|
|
251
251
|
|
|
252
252
|
|
|
253
|
-
def
|
|
253
|
+
def _dynamic_mcp_args(argv: list[str]) -> list[str]:
|
|
254
|
+
"""Strip ``--root {ROOT}`` / ``--db {ROOT}/...`` for unbound user-global overlays."""
|
|
255
|
+
out: list[str] = []
|
|
256
|
+
skip_next = False
|
|
257
|
+
for token in argv:
|
|
258
|
+
if skip_next:
|
|
259
|
+
skip_next = False
|
|
260
|
+
continue
|
|
261
|
+
if token == "--root":
|
|
262
|
+
skip_next = True
|
|
263
|
+
continue
|
|
264
|
+
if token == "--db":
|
|
265
|
+
skip_next = True
|
|
266
|
+
continue
|
|
267
|
+
out.append(token)
|
|
268
|
+
return out
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def _mcp_insert_block(root: Path | None) -> str:
|
|
254
272
|
"""生成官方 ``dsh-mcp-client`` 的三条 stdio 条目(顶层 ``- insert:``),根绝对化。
|
|
255
273
|
|
|
256
274
|
``serverName`` 是**必填**且必须唯一(README 的 Config 表);缺它会让
|
|
257
|
-
``loader entries failed to apply
|
|
258
|
-
|
|
259
|
-
历史缺陷:这里原本写死 ``--root .``,假设 dsh 以自己的项目目录为 cwd 启动。
|
|
260
|
-
真机不成立——MCP server 由**长驻宿主进程** spawn,cwd 是宿主自己的目录,
|
|
261
|
-
``.`` 于是指向那个目录而不是被审计项目,Supervisor 在错的 ``.bugx`` 上跑并
|
|
262
|
-
报「缺少有效的 .bugx 项目运行布局」。根必须写成绝对路径。
|
|
275
|
+
``loader entries failed to apply``。当 ``root`` 为 None 或指向用户家目录时,
|
|
276
|
+
写动态工作区解析参数,禁止把用户根目录写死成 ``--root``。
|
|
263
277
|
"""
|
|
264
|
-
|
|
278
|
+
home_resolved = Path.home().resolve()
|
|
279
|
+
resolved_root = Path(root).expanduser().resolve() if root is not None else None
|
|
280
|
+
global_unbound = resolved_root is None or resolved_root == home_resolved
|
|
265
281
|
lines = [_OVERLAY_MARKER, "- insert:"]
|
|
266
282
|
for server_name, argv in _MCP_SERVERS:
|
|
267
283
|
lines.extend([
|
|
@@ -273,29 +289,32 @@ def _mcp_insert_block(root: Path) -> str:
|
|
|
273
289
|
" command: bugx",
|
|
274
290
|
" args:",
|
|
275
291
|
])
|
|
276
|
-
|
|
292
|
+
if global_unbound:
|
|
293
|
+
for token in _dynamic_mcp_args(argv):
|
|
294
|
+
lines.append(f" - '{token}'")
|
|
295
|
+
else:
|
|
296
|
+
root_str = str(resolved_root)
|
|
297
|
+
lines.extend(f" - '{token.replace('{ROOT}', root_str)}'" for token in argv)
|
|
277
298
|
return "\n".join(lines) + "\n"
|
|
278
299
|
|
|
279
300
|
|
|
280
|
-
def _bootstrap(root: Path, servers) -> dict:
|
|
281
|
-
"""把三条 BugX MCP 通道写进用户级 profile patch(幂等、根绝对化)。
|
|
282
|
-
|
|
283
|
-
dsh 没有项目级配置层:实测 ``dsh --profile headless --dump-config`` 里项目级
|
|
284
|
-
``.dsh/patch.yml`` 与 ``.dsh/mcp.json`` 零命中,真正被 compose 的是
|
|
285
|
-
``$DSH_HOME/profiles/<profile>/cordis.patch.yml``。
|
|
286
|
-
|
|
287
|
-
``root`` 必须真正参与写入(条目里的 ``--root``/``--db`` 要绝对化到本项目);
|
|
288
|
-
并且这里**不能**用「命中就跳过」的幂等:那会让换了项目的用户永远停留在旧根,
|
|
289
|
-
Supervisor 于是继续在错的 ``.bugx`` 上跑。已存在的自有 overlay(以
|
|
290
|
-
:data:`_OVERLAY_MARKER` 开头、第二行为顶层 ``- insert:``)由引擎全权拥有,
|
|
291
|
-
直接按本次根重写;他人的块逐字保留。
|
|
292
|
-
"""
|
|
301
|
+
def _bootstrap(root: Path | None, servers) -> dict:
|
|
302
|
+
"""把三条 BugX MCP 通道写进用户级 profile patch(幂等、根绝对化)。"""
|
|
293
303
|
del servers
|
|
294
304
|
path = _profile_patch_path()
|
|
295
305
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
296
306
|
existing = path.read_text(encoding="utf-8") if path.is_file() else ""
|
|
297
|
-
|
|
307
|
+
home_resolved = Path.home().resolve()
|
|
308
|
+
resolved_root = Path(root).expanduser().resolve() if root is not None else None
|
|
309
|
+
global_unbound = resolved_root is None or resolved_root == home_resolved
|
|
298
310
|
owned = _owned_overlay_span(existing)
|
|
311
|
+
if global_unbound and owned is not None:
|
|
312
|
+
existing_block = existing[owned[0]:owned[1]]
|
|
313
|
+
home_marker = f"'{home_resolved}'"
|
|
314
|
+
if home_marker not in existing_block and "--root" in existing_block:
|
|
315
|
+
# 用户级安装不覆写已有的具体项目绑定。
|
|
316
|
+
return {"path": str(path), "changed": False, "inserted": False}
|
|
317
|
+
block = _mcp_insert_block(root)
|
|
299
318
|
if owned is not None:
|
|
300
319
|
begin, finish = owned
|
|
301
320
|
if existing[begin:finish].rstrip("\n") == block.rstrip("\n"):
|
package/core/hosts/minimax.py
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""core/hosts/minimax.py - MiniMax Code desktop Plugin V1 host.
|
|
3
3
|
|
|
4
|
-
Facts captured from the installed MiniMax Code 3.1.
|
|
4
|
+
Facts captured from the installed MiniMax Code 3.1.17 package on Windows and its
|
|
5
5
|
embedded local-plugin-v1 contract:
|
|
6
6
|
|
|
7
7
|
* user plugins are discovered below ~/.minimax/plugins/<plugin>/;
|
|
8
8
|
* the package manifest is .minimax-plugin/plugin.json;
|
|
9
9
|
* MCP servers are declared in servers.mcp.json;
|
|
10
|
-
* plugin
|
|
10
|
+
* plugin subagents are Markdown files under agents/ and Skills under skills/;
|
|
11
|
+
* the Agents roster uses ~/.minimax/agents/<name>/agent.md for Custom Agents.
|
|
11
12
|
|
|
12
13
|
The desktop package exposes the PluginSystem/MCP/Agent surface, but this
|
|
13
14
|
repository has not verified a MiniMax Code headless or standard ACP entry point.
|
|
@@ -125,7 +126,7 @@ def _mcp_config_paths(_root: Path) -> tuple[Path, ...]:
|
|
|
125
126
|
|
|
126
127
|
|
|
127
128
|
def _agent_config_path(_root: Path) -> Path:
|
|
128
|
-
return
|
|
129
|
+
return _minimax_data_dir() / "agents" / "bugx" / "agent.md"
|
|
129
130
|
|
|
130
131
|
|
|
131
132
|
def _resolve_minimax_cli() -> str | None:
|
|
@@ -230,7 +231,7 @@ def run_static_degraded(root: Path | None = None) -> dict:
|
|
|
230
231
|
"aliases": list(PLUGIN.identity.aliases),
|
|
231
232
|
"markers": list(PLUGIN.identity.markers),
|
|
232
233
|
},
|
|
233
|
-
"agent_entry": str(
|
|
234
|
+
"agent_entry": str(_agent_config_path(root or Path.cwd())),
|
|
234
235
|
"worker_entry": str(plugin_root / "agents" / "bugx-worker.md"),
|
|
235
236
|
"plugin_manifest": str(manifest),
|
|
236
237
|
"mcp_config": str(plugin_root / "servers.mcp.json"),
|
package/core/hosts/opencode.py
CHANGED
|
@@ -18,6 +18,7 @@ from contextlib import contextmanager
|
|
|
18
18
|
import json
|
|
19
19
|
import os
|
|
20
20
|
from pathlib import Path
|
|
21
|
+
import shutil
|
|
21
22
|
from typing import Iterator
|
|
22
23
|
|
|
23
24
|
from core.infra.json_utils import unique_json_object
|
|
@@ -208,9 +209,16 @@ def _autonomous_environment(root: Path) -> Iterator[dict[str, str | None]]:
|
|
|
208
209
|
for entry in source_dir.iterdir():
|
|
209
210
|
if entry.name in {"opencode.json", "opencode.jsonc", "plugin", "plugins"}:
|
|
210
211
|
continue
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
dest = private_dir / entry.name
|
|
213
|
+
try:
|
|
214
|
+
dest.symlink_to(entry, target_is_directory=entry.is_dir())
|
|
215
|
+
except OSError:
|
|
216
|
+
if os.name != "nt":
|
|
217
|
+
raise
|
|
218
|
+
if entry.is_dir():
|
|
219
|
+
shutil.copytree(entry, dest, dirs_exist_ok=True)
|
|
220
|
+
else:
|
|
221
|
+
shutil.copy2(entry, dest)
|
|
214
222
|
except OSError as exc:
|
|
215
223
|
raise RuntimeError(
|
|
216
224
|
f"OpenCode 自治配置资产无法隔离 ({type(exc).__name__})"
|
package/core/i18n.py
CHANGED
|
@@ -11,6 +11,8 @@ from __future__ import annotations
|
|
|
11
11
|
from dataclasses import dataclass
|
|
12
12
|
import json
|
|
13
13
|
import os
|
|
14
|
+
import re
|
|
15
|
+
import sys
|
|
14
16
|
from functools import lru_cache
|
|
15
17
|
from pathlib import Path
|
|
16
18
|
from typing import Any, Mapping
|
|
@@ -38,12 +40,22 @@ class LocaleResolution:
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
|
|
43
|
+
def _is_neutral_locale(raw: str) -> bool:
|
|
44
|
+
"""Check if raw locale string represents a neutral POSIX placeholder (e.g. C, POSIX, C.UTF-8)."""
|
|
45
|
+
if not isinstance(raw, str):
|
|
46
|
+
return False
|
|
47
|
+
stripped = raw.strip()
|
|
48
|
+
if not stripped:
|
|
49
|
+
return False
|
|
50
|
+
token = stripped.split(".", 1)[0].split("@", 1)[0].replace("_", "-").casefold()
|
|
51
|
+
return token in {"c", "posix"}
|
|
52
|
+
|
|
53
|
+
|
|
41
54
|
def normalize_locale(value: object) -> str | None:
|
|
42
55
|
"""Normalize a BCP-47/POSIX-ish locale to a supported locale.
|
|
43
56
|
|
|
44
|
-
``None`` means the input is not supported.
|
|
45
|
-
|
|
46
|
-
silently mistaken for Chinese.
|
|
57
|
+
``None`` means the input is not supported or is neutral (e.g. C/POSIX).
|
|
58
|
+
Explicit English and Chinese locales map to ``en-US`` and ``zh-CN`` respectively.
|
|
47
59
|
"""
|
|
48
60
|
if not isinstance(value, str):
|
|
49
61
|
return None
|
|
@@ -56,7 +68,7 @@ def normalize_locale(value: object) -> str | None:
|
|
|
56
68
|
if not parts:
|
|
57
69
|
return None
|
|
58
70
|
primary = parts[0].casefold()
|
|
59
|
-
if primary in {"
|
|
71
|
+
if primary in {"en", "eng"}:
|
|
60
72
|
return "en-US"
|
|
61
73
|
if primary in {"zh", "chi", "zho"}:
|
|
62
74
|
# The first release intentionally has one Chinese regional catalog.
|
|
@@ -82,6 +94,71 @@ def _read_preference(path: Path) -> str | None:
|
|
|
82
94
|
return None
|
|
83
95
|
|
|
84
96
|
|
|
97
|
+
def _detect_system_locale() -> LocaleResolution | None:
|
|
98
|
+
"""Detect display locale from OS native system preferences (macOS, system, timezone)."""
|
|
99
|
+
# 1. macOS (darwin)
|
|
100
|
+
if sys.platform == "darwin":
|
|
101
|
+
# Fast path: read ~/Library/Preferences/.GlobalPreferences.plist (~2ms via plistlib)
|
|
102
|
+
try:
|
|
103
|
+
plist_path = Path.home() / "Library" / "Preferences" / ".GlobalPreferences.plist"
|
|
104
|
+
if plist_path.is_file() and not plist_path.is_symlink():
|
|
105
|
+
import plistlib
|
|
106
|
+
with plist_path.open("rb") as f:
|
|
107
|
+
prefs = plistlib.load(f)
|
|
108
|
+
languages = prefs.get("AppleLanguages")
|
|
109
|
+
if isinstance(languages, (list, tuple)) and languages:
|
|
110
|
+
for lang in languages:
|
|
111
|
+
if isinstance(lang, str):
|
|
112
|
+
resolved = normalize_locale(lang)
|
|
113
|
+
if resolved:
|
|
114
|
+
return LocaleResolution(lang, resolved, "system-preference")
|
|
115
|
+
apple_locale = prefs.get("AppleLocale")
|
|
116
|
+
if isinstance(apple_locale, str) and apple_locale:
|
|
117
|
+
resolved = normalize_locale(apple_locale)
|
|
118
|
+
if resolved:
|
|
119
|
+
return LocaleResolution(apple_locale, resolved, "system-preference")
|
|
120
|
+
except Exception:
|
|
121
|
+
pass
|
|
122
|
+
|
|
123
|
+
# Subprocess fallback for macOS if plist direct read failed
|
|
124
|
+
try:
|
|
125
|
+
import subprocess
|
|
126
|
+
out = subprocess.check_output(
|
|
127
|
+
["defaults", "read", "-g", "AppleLanguages"],
|
|
128
|
+
text=True, stderr=subprocess.DEVNULL, timeout=1,
|
|
129
|
+
)
|
|
130
|
+
for m in re.finditer(r'"([^"]+)"', out):
|
|
131
|
+
lang = m.group(1).strip()
|
|
132
|
+
resolved = normalize_locale(lang)
|
|
133
|
+
if resolved:
|
|
134
|
+
return LocaleResolution(lang, resolved, "system-preference")
|
|
135
|
+
except Exception:
|
|
136
|
+
pass
|
|
137
|
+
|
|
138
|
+
# 2. Python locale.getlocale() (for non-darwin or fallback)
|
|
139
|
+
try:
|
|
140
|
+
import locale as py_locale
|
|
141
|
+
loc = py_locale.getlocale()[0]
|
|
142
|
+
if loc and not _is_neutral_locale(loc):
|
|
143
|
+
resolved = normalize_locale(loc)
|
|
144
|
+
if resolved:
|
|
145
|
+
return LocaleResolution(loc, resolved, "system-locale")
|
|
146
|
+
except Exception:
|
|
147
|
+
pass
|
|
148
|
+
|
|
149
|
+
# 3. Timezone heuristic (East Asia / China UTC+8)
|
|
150
|
+
try:
|
|
151
|
+
import time
|
|
152
|
+
offset_hours = -time.timezone // 3600
|
|
153
|
+
tz_names = tuple(name.upper() for name in time.tzname)
|
|
154
|
+
if offset_hours == 8 and any(name in {"CST", "CHINA", "BEIJING", "SHANGHAI", "HKT", "CST-8"} for name in tz_names):
|
|
155
|
+
return LocaleResolution("zh-CN", "zh-CN", "timezone-hint")
|
|
156
|
+
except Exception:
|
|
157
|
+
pass
|
|
158
|
+
|
|
159
|
+
return None
|
|
160
|
+
|
|
161
|
+
|
|
85
162
|
def resolve_locale(
|
|
86
163
|
*,
|
|
87
164
|
environ: Mapping[str, str] | None = None,
|
|
@@ -122,10 +199,14 @@ def resolve_locale(
|
|
|
122
199
|
f"unsupported locale: {requested}",
|
|
123
200
|
)
|
|
124
201
|
|
|
202
|
+
saw_neutral = False
|
|
125
203
|
for key in _ENV_KEYS:
|
|
126
204
|
raw = env.get(key, "").strip()
|
|
127
205
|
if not raw:
|
|
128
206
|
continue
|
|
207
|
+
if _is_neutral_locale(raw):
|
|
208
|
+
saw_neutral = True
|
|
209
|
+
continue
|
|
129
210
|
resolved = normalize_locale(raw)
|
|
130
211
|
if resolved:
|
|
131
212
|
return LocaleResolution(raw, resolved, key)
|
|
@@ -133,7 +214,15 @@ def resolve_locale(
|
|
|
133
214
|
raw, DEFAULT_LOCALE, key,
|
|
134
215
|
f"unsupported locale: {raw}",
|
|
135
216
|
)
|
|
136
|
-
|
|
217
|
+
|
|
218
|
+
# 4. OS native preference detection (macOS AppleLanguages, system locale, timezone)
|
|
219
|
+
if environ is None:
|
|
220
|
+
detected = _detect_system_locale()
|
|
221
|
+
if detected is not None:
|
|
222
|
+
return detected
|
|
223
|
+
|
|
224
|
+
fallback_reason = "neutral locale: C/POSIX" if saw_neutral else None
|
|
225
|
+
return LocaleResolution(None, DEFAULT_LOCALE, "default", fallback_reason)
|
|
137
226
|
|
|
138
227
|
|
|
139
228
|
def _catalog_path(locale: str) -> Path:
|
package/core/infra/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BugX Core Infrastructure & Primitives (核心基础设施与底层操作系统原语子系统)
|
|
2
2
|
|
|
3
|
-
> **版本契约**: `0.1.
|
|
3
|
+
> **版本契约**: `0.1.5` | **所属分层**: `Layer 0: 基础设施与操作系统抽象`
|
|
4
4
|
> **工程规范**: 参见 [`docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md`](../../docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md) 与 [`docs/02_architecture/06_MODULE_GOVERNANCE_SPEC.md`](../../docs/02_architecture/06_MODULE_GOVERNANCE_SPEC.md)
|
|
5
5
|
> **守卫机制**: `scripts/verify_directory_indices.py` (100% 物理条目索引覆盖)
|
|
6
6
|
|
package/core/infra/build_info.py
CHANGED
|
@@ -12,8 +12,8 @@ import re
|
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
|
|
14
14
|
VERSION_ENV = "BUGX_VERSION"
|
|
15
|
-
VERSION_TOKEN = "0.1.
|
|
16
|
-
_DEFAULT_VERSION = "0.1.
|
|
15
|
+
VERSION_TOKEN = "0.1.5"
|
|
16
|
+
_DEFAULT_VERSION = "0.1.5"
|
|
17
17
|
_VERSION_RE = re.compile(r"^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$")
|
|
18
18
|
|
|
19
19
|
|
|
@@ -47,6 +47,8 @@ def parse_python_version(executable_path):
|
|
|
47
47
|
stdout=subprocess.PIPE,
|
|
48
48
|
stderr=subprocess.PIPE,
|
|
49
49
|
text=True,
|
|
50
|
+
encoding="utf-8",
|
|
51
|
+
errors="replace",
|
|
50
52
|
timeout=2.0,
|
|
51
53
|
check=False,
|
|
52
54
|
)
|
|
@@ -131,7 +133,8 @@ def find_python_candidates(extra_paths=None):
|
|
|
131
133
|
try:
|
|
132
134
|
res = subprocess.run(
|
|
133
135
|
[py_launcher, ver_flag, "-c", "import sys; print(sys.executable)"],
|
|
134
|
-
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True,
|
|
136
|
+
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True,
|
|
137
|
+
encoding="utf-8", errors="replace", timeout=2.0, check=False,
|
|
135
138
|
)
|
|
136
139
|
if res.returncode == 0 and res.stdout.strip():
|
|
137
140
|
add_candidate(res.stdout.strip())
|
|
@@ -91,7 +91,7 @@ flowchart TD
|
|
|
91
91
|
| `startup_gates.py` | 启动前置安全门禁(文件树白名单、脏工作区检查、权限拦截) | `verify_startup_gates` |
|
|
92
92
|
| `startup_interaction.py` | 交互式问答决策引擎,根据终端能力与配置解析交互模式 | `resolve_startup_interaction` |
|
|
93
93
|
| `verify_loop.py` | 独立验证员盲审输入包构造、Anti-Gaming 校验与报错驱动 PoC 自纠错闭环 | `build_verify_bundle`, `execute_verify_attempt`, `run_verification_loop` |
|
|
94
|
-
| `startup_version_gate.py` | 版本硬门禁校验器,确保运行时版本严格等于 `0.1.
|
|
94
|
+
| `startup_version_gate.py` | 版本硬门禁校验器,确保运行时版本严格等于 `0.1.5` 绝不漂移 | `assert_version_integrity` |
|
|
95
95
|
| `supervisor_bridge.py` | Supervisor 模块间解耦桥接层,提供轻量化调用门面 | `SupervisorBridge` |
|
|
96
96
|
| `supervisor_coverage.py` | 覆盖率生命周期继承器,支持空闲历史会话继承与动态分发 | `SupervisorCoverageSync` |
|
|
97
97
|
| `supervisor_degraded.py` | 降级容灾与探针就地自愈控制器,无损处理缺失依赖与环境 | `SupervisorDegradedCoordinator` |
|
|
@@ -103,7 +103,7 @@ flowchart TD
|
|
|
103
103
|
|
|
104
104
|
## 3. 核心设计契约与公理 (Design Axioms)
|
|
105
105
|
|
|
106
|
-
1. **版本绝对固化公理**:`startup_version_gate.py` 必须在任何业务逻辑启动前执行,基线版本严格锁定在 `0.1.
|
|
106
|
+
1. **版本绝对固化公理**:`startup_version_gate.py` 必须在任何业务逻辑启动前执行,基线版本严格锁定在 `0.1.5`,杜绝任何环境版本漂移。
|
|
107
107
|
2. **状态机单向流转与幂等性**:生命周期从 `Pre` $\rightarrow$ `Round` $\rightarrow$ `Worker` $\rightarrow$ `Judge` $\rightarrow$ `Settlement` $\rightarrow$ `Post` 严格单向流动,禁止逆流操作;重试必须走显式的轮次迭代(`advance_round_lifecycle`)。
|
|
108
108
|
3. **证据零伪造公理**:在 `findings_adjudication.py` 与 `candidate_revalidation.py` 中,所有缺陷判定必须有可执行的反事实测试证据,严禁仅凭模型推理文本定性。
|
|
109
109
|
4. **工作树物理安全红线**:`post_dry_run.py` 与 `post_commit.py` 严格遵守工作树保护宪法,未授权时绝对禁止覆盖用户未暂存的修改。
|
|
@@ -153,7 +153,7 @@ def build_recipes_from_verdicts(verdicts_path: Path) -> Path:
|
|
|
153
153
|
"fingerprint": fp, "oracle_file": oracle_rel,
|
|
154
154
|
"positive": pos, "negative": neg,
|
|
155
155
|
})
|
|
156
|
-
out = Path(f"
|
|
156
|
+
out = Path(__import__("tempfile").gettempdir()) / f"recipes-{int(__import__('time').time())}.json"
|
|
157
157
|
out.write_text(json.dumps(recipes, ensure_ascii=False, indent=1), encoding="utf-8")
|
|
158
158
|
print(f"[findings-confirm] 自动生成 {len(recipes)} 条 recipe → {out}")
|
|
159
159
|
return out
|
|
@@ -24,6 +24,8 @@ import time
|
|
|
24
24
|
from pathlib import Path
|
|
25
25
|
from typing import Any, Callable, Mapping, Sequence
|
|
26
26
|
|
|
27
|
+
import core.secure_atomic as secure_atomic
|
|
28
|
+
|
|
27
29
|
OVERLAY_SCHEMA_VERSION = 1
|
|
28
30
|
MAX_FIELD_CHARS = 200
|
|
29
31
|
MAX_CONTEXT_FILES = 24
|
|
@@ -59,26 +61,8 @@ def _sha256_bytes(data: bytes) -> str:
|
|
|
59
61
|
|
|
60
62
|
|
|
61
63
|
def _atomic_write_json(path: Path, payload: Mapping[str, Any]) -> None:
|
|
62
|
-
path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
63
64
|
raw = json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True).encode("utf-8")
|
|
64
|
-
|
|
65
|
-
try:
|
|
66
|
-
os.fchmod(fd, 0o600)
|
|
67
|
-
with os.fdopen(fd, "wb") as handle:
|
|
68
|
-
handle.write(raw)
|
|
69
|
-
handle.flush()
|
|
70
|
-
os.fsync(handle.fileno())
|
|
71
|
-
os.replace(tmp_name, path)
|
|
72
|
-
except BaseException:
|
|
73
|
-
try:
|
|
74
|
-
os.close(fd)
|
|
75
|
-
except OSError:
|
|
76
|
-
pass
|
|
77
|
-
try:
|
|
78
|
-
os.unlink(tmp_name)
|
|
79
|
-
except OSError:
|
|
80
|
-
pass
|
|
81
|
-
raise
|
|
65
|
+
secure_atomic.atomic_write_bytes(path, raw, mode=0o600, parent_mode=0o700)
|
|
82
66
|
|
|
83
67
|
|
|
84
68
|
def _sanitize_text(value: object, *, max_len: int = MAX_FIELD_CHARS) -> tuple[str, bool]:
|
|
@@ -240,8 +240,8 @@ def version_marker(path: Path) -> str | None:
|
|
|
240
240
|
if not match:
|
|
241
241
|
return None
|
|
242
242
|
value = match.group(1)
|
|
243
|
-
if value == "0.1.
|
|
244
|
-
value = os.environ.get("BUGX_VERSION", "0.1.
|
|
243
|
+
if value == "0.1.5":
|
|
244
|
+
value = os.environ.get("BUGX_VERSION", "0.1.5")
|
|
245
245
|
return value
|
|
246
246
|
|
|
247
247
|
def startup_release_version(value: object) -> tuple[int, int, int] | None:
|
|
@@ -992,6 +992,8 @@ def host_entry_gate() -> int:
|
|
|
992
992
|
print(f"[launch_bugx] ✗ 宿主入口就绪性检查失败({type(exc).__name__}):{exc}")
|
|
993
993
|
return RESTART_REQUIRED
|
|
994
994
|
if status.get("ready"):
|
|
995
|
+
for warning in status.get("warnings") or []:
|
|
996
|
+
print(f"[launch_bugx] ⚠ {warning}")
|
|
995
997
|
return 0
|
|
996
998
|
print("[launch_bugx] ✗ 需要重启宿主:宿主侧入口(MCP + skill)未就绪——"
|
|
997
999
|
+ str(status.get("reason") or "未知原因"))
|
|
@@ -185,11 +185,13 @@ def degraded_item_transient(item: Mapping[str, Any]) -> bool:
|
|
|
185
185
|
|
|
186
186
|
|
|
187
187
|
def degraded_item_critical(item: Mapping[str, Any]) -> bool:
|
|
188
|
-
"""能力是否 critical
|
|
188
|
+
"""能力是否 critical:codebase-memory 为必装核心能力,其余以描述符或 mcp 判定。"""
|
|
189
|
+
name = str(item.get("name", "")).casefold()
|
|
190
|
+
if "codebase-memory" in name or "tree-sitter" in name:
|
|
191
|
+
return True
|
|
189
192
|
declared = item.get("critical")
|
|
190
193
|
if isinstance(declared, bool):
|
|
191
194
|
return declared
|
|
192
|
-
name = str(item.get("name", "")).casefold()
|
|
193
195
|
return bool(item.get("kind") == "mcp" or "mcp" in name)
|
|
194
196
|
|
|
195
197
|
|
|
@@ -370,12 +372,12 @@ def auto_provision_accelerators(
|
|
|
370
372
|
if isinstance(probe_report, dict) else "invalid-report"
|
|
371
373
|
)
|
|
372
374
|
print(
|
|
373
|
-
f"[launch_bugx] Codebase Memory
|
|
375
|
+
f"[launch_bugx] Codebase Memory 必装组件未 READY({failed}),将阻断放行"
|
|
374
376
|
)
|
|
375
377
|
except Exception as exc:
|
|
376
378
|
print(
|
|
377
|
-
"[launch_bugx] Codebase Memory
|
|
378
|
-
f"({type(exc).__name__})
|
|
379
|
+
"[launch_bugx] Codebase Memory 必装组件自愈/复核异常 "
|
|
380
|
+
f"({type(exc).__name__}),将阻断放行"
|
|
379
381
|
)
|
|
380
382
|
|
|
381
383
|
# 2. bugx-supervisor / 宿主 MCP 自动就地配置注入
|
|
@@ -28,6 +28,8 @@ import time
|
|
|
28
28
|
from pathlib import Path
|
|
29
29
|
from typing import Any, Callable, Mapping, Sequence
|
|
30
30
|
|
|
31
|
+
import core.secure_atomic as secure_atomic
|
|
32
|
+
|
|
31
33
|
from core.ledger.finding_verification import (
|
|
32
34
|
RETRYABLE_FAILURE_CODES,
|
|
33
35
|
VerificationDiagnostic,
|
|
@@ -68,26 +70,8 @@ def _fp_slug(fingerprint: str) -> str:
|
|
|
68
70
|
|
|
69
71
|
|
|
70
72
|
def _atomic_write_json(path: Path, payload: Mapping[str, Any]) -> None:
|
|
71
|
-
path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
72
73
|
data = json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True).encode("utf-8")
|
|
73
|
-
|
|
74
|
-
try:
|
|
75
|
-
os.fchmod(fd, 0o600)
|
|
76
|
-
with os.fdopen(fd, "wb") as handle:
|
|
77
|
-
handle.write(data)
|
|
78
|
-
handle.flush()
|
|
79
|
-
os.fsync(handle.fileno())
|
|
80
|
-
os.replace(tmp_name, path)
|
|
81
|
-
except BaseException:
|
|
82
|
-
try:
|
|
83
|
-
os.close(fd)
|
|
84
|
-
except OSError:
|
|
85
|
-
pass
|
|
86
|
-
try:
|
|
87
|
-
os.unlink(tmp_name)
|
|
88
|
-
except OSError:
|
|
89
|
-
pass
|
|
90
|
-
raise
|
|
74
|
+
secure_atomic.atomic_write_bytes(path, data, mode=0o600, parent_mode=0o700)
|
|
91
75
|
|
|
92
76
|
|
|
93
77
|
def strip_runner_wrapper(code: str) -> str:
|
package/core/ledger/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BugX Ledger (攻防复盘账本与错题经验库)
|
|
2
2
|
|
|
3
|
-
> **版本契约**: `0.1.
|
|
3
|
+
> **版本契约**: `0.1.5` | **所属分层**: `Layer 3: 并发协调、智能体编排与账本`
|
|
4
4
|
> **工程规范**: 参见 [`docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md`](../../docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md)
|
|
5
5
|
> **守卫机制**: `scripts/verify_directory_indices.py` (100% 物理条目索引覆盖)
|
|
6
6
|
|
|
@@ -251,7 +251,7 @@ def reproduction_not_executable(value: object) -> bool:
|
|
|
251
251
|
try:
|
|
252
252
|
result = subprocess.run(
|
|
253
253
|
["bash", "-n", "-c", text], capture_output=True, text=True,
|
|
254
|
-
timeout=5, check=False,
|
|
254
|
+
encoding="utf-8", errors="replace", timeout=5, check=False,
|
|
255
255
|
)
|
|
256
256
|
except (OSError, subprocess.SubprocessError):
|
|
257
257
|
return False
|
|
@@ -22,6 +22,7 @@ from dataclasses import dataclass
|
|
|
22
22
|
from pathlib import Path
|
|
23
23
|
from typing import Any, Mapping, Sequence
|
|
24
24
|
|
|
25
|
+
import core.secure_atomic as secure_atomic
|
|
25
26
|
from core.supervisor.worker_execution import run_bounded, WorkerExecutionError
|
|
26
27
|
|
|
27
28
|
|
|
@@ -255,26 +256,7 @@ def _result_record(result: Any, *, execution_id: str, case: str, argv: Sequence[
|
|
|
255
256
|
|
|
256
257
|
|
|
257
258
|
def _atomic_json(path: Path, payload: Mapping[str, object]) -> None:
|
|
258
|
-
|
|
259
|
-
raw = _canonical(payload)
|
|
260
|
-
descriptor, temporary = tempfile.mkstemp(prefix=f".{path.name}.", dir=str(path.parent))
|
|
261
|
-
try:
|
|
262
|
-
os.fchmod(descriptor, 0o600)
|
|
263
|
-
with os.fdopen(descriptor, "wb") as handle:
|
|
264
|
-
handle.write(raw)
|
|
265
|
-
handle.flush()
|
|
266
|
-
os.fsync(handle.fileno())
|
|
267
|
-
os.replace(temporary, path)
|
|
268
|
-
except BaseException:
|
|
269
|
-
try:
|
|
270
|
-
os.close(descriptor)
|
|
271
|
-
except OSError:
|
|
272
|
-
pass
|
|
273
|
-
try:
|
|
274
|
-
os.unlink(temporary)
|
|
275
|
-
except OSError:
|
|
276
|
-
pass
|
|
277
|
-
raise
|
|
259
|
+
secure_atomic.atomic_write_bytes(path, _canonical(payload), mode=0o600, parent_mode=0o700)
|
|
278
260
|
|
|
279
261
|
|
|
280
262
|
def verify_finding(root: Path, finding: Mapping[str, object], recipe: Mapping[str, object] | VerificationRecipe,
|
package/core/ledger/fp_ledger.py
CHANGED
|
@@ -20,6 +20,8 @@ import time
|
|
|
20
20
|
from pathlib import Path
|
|
21
21
|
from typing import Any, Mapping, Sequence
|
|
22
22
|
|
|
23
|
+
import core.secure_atomic as secure_atomic
|
|
24
|
+
|
|
23
25
|
LEDGER_SCHEMA_VERSION = 1
|
|
24
26
|
ALLOWED_FP_REJECTION_CLASSES = frozenset({
|
|
25
27
|
"not_reproducible",
|
|
@@ -72,26 +74,8 @@ def ledger_path(root: Path) -> Path:
|
|
|
72
74
|
|
|
73
75
|
|
|
74
76
|
def _atomic_write_json(path: Path, payload: Mapping[str, Any]) -> None:
|
|
75
|
-
path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
76
77
|
raw = json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True).encode("utf-8")
|
|
77
|
-
|
|
78
|
-
try:
|
|
79
|
-
os.fchmod(fd, 0o600)
|
|
80
|
-
with os.fdopen(fd, "wb") as handle:
|
|
81
|
-
handle.write(raw)
|
|
82
|
-
handle.flush()
|
|
83
|
-
os.fsync(handle.fileno())
|
|
84
|
-
os.replace(tmp_name, path)
|
|
85
|
-
except BaseException:
|
|
86
|
-
try:
|
|
87
|
-
os.close(fd)
|
|
88
|
-
except OSError:
|
|
89
|
-
pass
|
|
90
|
-
try:
|
|
91
|
-
os.unlink(tmp_name)
|
|
92
|
-
except OSError:
|
|
93
|
-
pass
|
|
94
|
-
raise
|
|
78
|
+
secure_atomic.atomic_write_bytes(path, raw, mode=0o600, parent_mode=0o700)
|
|
95
79
|
|
|
96
80
|
|
|
97
81
|
def load_fp_ledger(root: Path) -> dict[str, Any]:
|
|
@@ -34,6 +34,8 @@ from contextlib import contextmanager
|
|
|
34
34
|
from dataclasses import dataclass
|
|
35
35
|
from pathlib import Path
|
|
36
36
|
|
|
37
|
+
import core.secure_atomic as secure_atomic
|
|
38
|
+
|
|
37
39
|
try:
|
|
38
40
|
import fcntl
|
|
39
41
|
except ImportError: # pragma: no cover - Windows
|
|
@@ -259,39 +261,11 @@ def _fsync_directory(directory: Path) -> None:
|
|
|
259
261
|
|
|
260
262
|
def atomic_write_json(path: str | os.PathLike[str], data: Mapping[str, Any]) -> None:
|
|
261
263
|
"""Atomically replace *path* with JSON, flushing file and directory metadata."""
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
prefix=f".{target.name}.", suffix=".tmp", dir=str(directory)
|
|
268
|
-
)
|
|
269
|
-
temporary = Path(temporary_name)
|
|
270
|
-
try:
|
|
271
|
-
os.fchmod(descriptor, 0o600)
|
|
272
|
-
with os.fdopen(descriptor, "w", encoding="utf-8") as handle:
|
|
273
|
-
descriptor = -1
|
|
274
|
-
json.dump(
|
|
275
|
-
data,
|
|
276
|
-
handle,
|
|
277
|
-
ensure_ascii=False,
|
|
278
|
-
sort_keys=True,
|
|
279
|
-
separators=(",", ":"),
|
|
280
|
-
)
|
|
281
|
-
handle.write("\n")
|
|
282
|
-
handle.flush()
|
|
283
|
-
os.fsync(handle.fileno())
|
|
284
|
-
os.replace(temporary, target)
|
|
285
|
-
temporary = None
|
|
286
|
-
_fsync_directory(directory)
|
|
287
|
-
finally:
|
|
288
|
-
if descriptor != -1:
|
|
289
|
-
os.close(descriptor)
|
|
290
|
-
if temporary is not None:
|
|
291
|
-
try:
|
|
292
|
-
temporary.unlink()
|
|
293
|
-
except FileNotFoundError:
|
|
294
|
-
pass
|
|
264
|
+
payload = (
|
|
265
|
+
json.dumps(data, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
|
|
266
|
+
+ "\n"
|
|
267
|
+
).encode("utf-8")
|
|
268
|
+
secure_atomic.atomic_write_bytes(path, payload, mode=0o600)
|
|
295
269
|
|
|
296
270
|
|
|
297
271
|
def _lock_for(path: Path) -> threading.RLock:
|
package/core/ledger/schema.py
CHANGED
|
@@ -384,7 +384,7 @@ def _journal_mode_lock(db: Path) -> Iterator[None]:
|
|
|
384
384
|
thread_acquired = True
|
|
385
385
|
if not stat.S_ISREG(os.fstat(descriptor).st_mode):
|
|
386
386
|
raise LessonLedgerError("SQLite journal-mode 锁必须是普通文件")
|
|
387
|
-
if os
|
|
387
|
+
if hasattr(os, "fchmod"):
|
|
388
388
|
os.fchmod(descriptor, 0o600)
|
|
389
389
|
deadline = time.monotonic() + 10.0
|
|
390
390
|
if _fcntl is not None:
|