From a02f8f254802554d7ad74afd9291c2f19aad43f7 Mon Sep 17 00:00:00 2001 From: QINGLU AI BORIS Date: Fri, 23 Oct 2026 03:36:52 +0800 Subject: [PATCH] Explain profile setup in both languages and package a checked release --- .gitattributes | 1 + .github/workflows/checks.yml | 1 + CHANGELOG.md | 6 + CONTRIBUTING.md | 6 +- README.md | 208 +++----------------------------- README.zh-CN.md | 37 ++++++ VERSION | 2 +- docs/images/workflow-v0.1.1.svg | 1 + docs/tutorial.en.md | 37 ++++++ docs/tutorial.zh-CN.md | 37 ++++++ publication.json | 13 ++ scripts/check_package.py | 2 +- scripts/check_publication.py | 30 +++++ scripts/package_release.py | 35 ++++++ 14 files changed, 223 insertions(+), 193 deletions(-) create mode 100644 .gitattributes create mode 100644 README.zh-CN.md create mode 100644 docs/images/workflow-v0.1.1.svg create mode 100644 docs/tutorial.en.md create mode 100644 docs/tutorial.zh-CN.md create mode 100644 publication.json create mode 100644 scripts/check_publication.py create mode 100644 scripts/package_release.py diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 5b42eed..a31e23c 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -23,3 +23,4 @@ jobs: python-version: '3.12' - run: python -B scripts/check_package.py - run: python -B -m unittest discover -s tests -v + - run: python -B scripts/check_publication.py diff --git a/CHANGELOG.md b/CHANGELOG.md index a24794b..8bac49d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.1.1 — 2026-10-23 + +- Add selectable English and Simplified Chinese project and user guides. +- Align download names and workflow illustrations with this release; retain historical evidence at its original version. + + ## 0.1.0 — Initial Package ### Added diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 071037d..ed42e18 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,7 +6,7 @@ Thank you for improving User Behavior Personalization. Focused changes to instru Search existing issues and read the relevant workflow. For a substantial change, describe the concrete behavior and expected result in an issue before implementing a broad redesign. Small corrections can go directly to a pull request. -Use English for repository documentation, templates, issue reports, and pull request descriptions. Examples should be synthetic and clearly labeled. +Provide matching English and Simplified Chinese entry pages and user guides. Keep code, templates, issue reports, and pull request descriptions in English. Examples should be synthetic and clearly labeled. ## Scope @@ -40,3 +40,7 @@ No separate contributor license agreement is required by this package. ## Community Conduct Keep discussion respectful, specific, and relevant to the work. Critique behavior and evidence rather than people. Do not publish another person's private information. Maintainers may moderate content that violates these expectations. + +## Documentation and release changes + +Keep the English and Simplified Chinese entry pages and guides aligned. Explain the reader’s actual task with project-specific examples. Use concrete English commit subjects. New ordinary filenames and versioned release assets use lowercase kebab-case without spaces; conventional README, LICENSE, SKILL and metadata names remain unchanged. Before release, compare each package, version label, command, and current image with the documented behavior. Label diagrams, synthetic data, historical evidence, and unverified integrations accurately. diff --git a/README.md b/README.md index 2a9eb3b..6ebb078 100644 --- a/README.md +++ b/README.md @@ -1,209 +1,37 @@ # User Behavior Personalization -This skill helps an agent remember how you like to work. It keeps preferences in a small guide you can inspect and correct, with a source for each change. +English | [简体中文](README.zh-CN.md) -For example, a request for a short answer on one task should not make every future answer short. An explicit correction should replace an old preference. The skill describes how to handle both. +Keep useful preferences in a profile the user can inspect and correct. This skill describes how an agent should turn explicit feedback into scoped guidance without quietly treating a guess as a personal fact. -Built by [KarmenLoop](https://github.com/KarmenLoop). +[Download v0.1.1](https://github.com/KarmenLoop/user-behavior-personalization/releases/tag/v0.1.1) · [Guide](docs/tutorial.en.md) · [Issues](https://github.com/KarmenLoop/user-behavior-personalization/issues) -[Download](https://github.com/KarmenLoop/user-behavior-personalization/releases) · [Quick Start](docs/quickstart.md) · [Documentation](#documentation) · [Contributing](CONTRIBUTING.md) · [License](LICENSE) · [Contact](#contact) +## What it does -**License:** Apache-2.0. Personal, research, and commercial use are permitted under the terms in [LICENSE](LICENSE). +An instruction package with blank templates and synthetic examples. The host supplies verified identity, private storage, loading, deletion/export, and any scheduling or synchronization. -**Package:** Markdown skill, templates, integration guidance, and evaluation scenarios. No model runtime, background service, or hosted memory service is bundled. +![User Behavior Personalization workflow illustration](docs/images/workflow-v0.1.1.svg) -## Overview +*Workflow illustration for v0.1.1; not an application screenshot or runtime acceptance.* -The agent keeps a per-user `USER_SKILL.md` and reads the relevant preferences before responding. Explicit requests are kept separate from tentative observations, and task-specific instructions stay scoped to the task. +## Start here -The guide can change as you give feedback. Those changes update saved preferences, not model weights, system instructions, tool permissions, or account access. The host needs to provide storage and the hooks that load and update the guide. +Extract the ZIP, then run python3 scripts/install_skill.py --destination ../installed-skills/user-behavior-personalization from its top-level directory. The destination must be new and outside the source. Select that directory with your host’s supported loader. -## Capabilities +Have the host establish PROFILE_ROOT, USER_ID, USER_TIMEZONE, MEMORY_ENABLED, CONVERSATION_SOURCE, and REFLECTION_TRIGGER. These are integration contract fields, not environment variables consumed by bundled code. Start with blank templates in a private user directory. -| Capability | Behavior | Requires from the host | -| --- | --- | --- | -| Communication preferences | Adapts language, detail, tone, structure, terminology, and forms of address | Skill loading and authorized conversation access | -| Working habits | Learns planning, decision, reporting, and delivery preferences | An agent that can apply the guidance | -| Daily reflection | Reviews newly available conversations and proposes specific improvements | A scheduler, session-end event, or next-session catch-up | -| Evolving user skill | Creates and revises a per-user `USER_SKILL.md` | Authorized persistent storage | -| Immediate correction | Applies explicit corrections during the current conversation | Persistence for later-session effects | -| Context-efficient recall | Selects a small set of relevant active rules | A profile-loading step before the response | -| Evidence tracking | Distinguishes confirmed preferences, tentative patterns, and temporary instructions | Stable source message identifiers | -| Memory control | Defines inspect, correct, export, pause, and forget workflows | Host operations that implement those actions | -| Cross-channel continuity | Reuses one profile for the same verified user | Verified identity mapping and an explicit sharing policy | -| Cross-device continuity | Reuses the current committed profile on another device | Host-provided synchronization and conflict handling | +## A first useful task -Installing the skill does not create a timer, connect messaging applications, synchronize devices, or guarantee every response will load it. The integration points are documented and must be wired by the host. +Use a synthetic conversation containing an explicit correction. Ask the host to propose the corresponding scoped preference, show its source, and save it only through available authorized operations. Verify later recall from that saved record. -## How It Works +Review a conflicting correction and test export or deletion through the real host. Repository checks preserve blank templates and package hygiene; no end-to-end live-user or device-continuity certification is claimed. -```mermaid -flowchart LR - A[Authorized conversations] --> B[Extract preferences and corrections] - B --> C[Review evidence and scope] - C --> D[Generate candidate user skill] - D --> E[Validate and commit] - E --> F[Load relevant rules for the next conversation] - F --> G[Observe actual user feedback] - G --> B -``` +## Questions -Two layers keep the process maintainable: +**Will installing it remember every conversation?** No. The host must explicitly provide authorized conversations, storage, and loading. The package starts no service and registers no timer. -1. **Stable controller: `SKILL.md`.** Defines what to learn, how to evaluate evidence, when to reflect, and how to update memory. -2. **Evolving profile: `USER_SKILL.md`.** Holds one user's current preferences and actionable collaboration rules. It remains private user data, separate from the public skill repository. +## Documentation and license -Daily reflection updates the same user guide when evidence justifies a change. It does not produce an ever-growing collection of globally discoverable personal skills. +[Download, setup, practice, and updates](docs/tutorial.en.md) · [LICENSE](LICENSE) -### Example: Learning a Conditional Preference - -> User: "Keep today's status update short." - -The agent records a temporary request for that update. - -> User, later: "For future answers, start with the conclusion. Keep simple questions short, but give me the full implementation details for complex work." - -The user guide gains a confirmed rule: - -> Start with the conclusion. Keep simple answers concise. For complex implementation work, include the necessary reasoning, steps, and validation. - -The agent applies the rule to the next relevant response. Further feedback can narrow, replace, or remove it. - -## Quick Start - -### 1. Obtain the Package - -Download a package from [Releases](https://github.com/KarmenLoop/user-behavior-personalization/releases), use GitHub's **Code → Download ZIP** action, or clone the repository: - -```bash -git clone https://github.com/KarmenLoop/user-behavior-personalization.git -cd user-behavior-personalization -``` - -The checkout must contain `SKILL.md`, `references/`, and `assets/` together. - -### Install a portable copy - -Copy the validated package to a new directory selected for your agent host: - -```sh -python3 scripts/install_skill.py --destination ../installed-skills/user-behavior-personalization -``` - -The installer preserves the blank templates and refuses an existing destination. It does not create a private user profile, schedule reflection, or change host permissions. Run `python3 -B -m unittest discover -s tests -v` to check the installation behavior locally. - -### 2. Load the Skill - -Use your agent host's skill installation or loading mechanism. When it expects a directory named after the skill, use `user-behavior-personalization` as that directory name. - -For a host that reads Markdown instructions explicitly, start with: - -```text -Read SKILL.md from the user-behavior-personalization package. -Apply it to the current user's authorized conversations. -Use only the storage and scheduling operations this host actually provides. -``` - -No package installation command is required to read the skill. Durable memory requires writable storage; unattended reflection requires a host event or scheduler. - -### 3. Configure the Host - -Map the following fields to your host's own configuration. These names describe the integration contract; they are not environment variables consumed by a bundled application. - -| Field | Meaning | -| --- | --- | -| `PROFILE_ROOT` | Approved private storage location, outside the public checkout | -| `USER_ID` | Stable identity verified by the host | -| `USER_TIMEZONE` | Timezone used to group daily reflections | -| `MEMORY_ENABLED` | Whether personalization memory may be read and updated | -| `CONVERSATION_SOURCE` | Authorized messages available for analysis | -| `REFLECTION_TRIGGER` | Session end, scheduled run, or next-session catch-up | - -Copy [the templates](assets/templates/) into that user's private directory and replace the documented template fields. See [Quick Start](docs/quickstart.md) for the exact setup sequence. - -### 4. Connect the Lifecycle - -```text -Before a personalized response: - Load the current user's guide and choose relevant active rules. - -When the user explicitly corrects a preference: - Apply the correction now; persist it when authorized and available. - -At the configured reflection event: - Review new messages, validate changes, commit the guide, then checkpoint progress. -``` - -If a host has no background scheduler, run catch-up at the next conversation. Do not claim that an unattended daily job is active. - -## Private Memory Layout - -```text -// - USER_SKILL.md - state.json - reflections/ - YYYY-MM-DD.md - versions/ - USER_SKILL.vNNNN.md -``` - -Only the public controller, blank templates, and synthetic examples belong in Git. Real profiles, chat exports, reflection logs, credentials, and synchronization configuration stay in approved private storage. - -## Compatibility and Platforms - -The core instructions are plain Markdown and do not require a particular model provider, operating system, vector database, or agent framework. A host must be able to load the instructions and expose the capabilities needed for the workflow it enables. - -The repository includes [optional skill UI metadata](agents/openai.yaml). This is packaging metadata, not evidence of a tested integration with any product. - -| Host capability | Result | -| --- | --- | -| Instruction loading only | Current-conversation adaptation | -| Instruction loading and persistent files | Preferences can survive sessions | -| Persistent files and lifecycle hooks | Repeatable reflection and recall workflow | -| Verified identity and synchronized storage | Cross-channel or cross-device continuity | - -No end-to-end host certification is claimed in this initial package. Review [the evaluation guide](docs/evaluation.md) before enabling a production integration. - -## Documentation - -| Guide | Contents | -| --- | --- | -| [Quick Start](docs/quickstart.md) | Setup, invocation, first correction, and first reflection | -| [Architecture](docs/architecture.md) | Stable instructions, evolving profiles, evidence, and context use | -| [Host Integration](docs/host-integration.md) | Required operations, lifecycle events, identity, commits, and synchronization | -| [Privacy and Memory Control](docs/privacy-and-memory-control.md) | Authorization, sensitive data, sharing, export, deletion, and retention | -| [Evaluation](docs/evaluation.md) | Behavioral scenarios, observable evidence, and release checks | -| [Profile Format](references/profile-format.md) | Profile fields, state format, evidence, and precedence | -| [Reflection Workflow](references/reflection-workflow.md) | Daily review, publication, recovery, and rollback | -| [Examples](examples/conversations.md) | Synthetic conversations and expected outcomes | - -## Contributing - -Bug reports, documentation improvements, host adapters, and focused pull requests are welcome. Read [CONTRIBUTING.md](CONTRIBUTING.md) before submitting a change. - -Useful contributions include clearer evidence handling, better correction and forgetting behavior, realistic evaluation cases, and host integrations with reproducible instructions. Use synthetic data in every public report. - -There is no required contributor license agreement in this package. Contributions are submitted under the repository's Apache-2.0 license. - -## Security and Support - -For reproducible non-sensitive bugs and feature requests, use this repository's Issues tab after publication. Read [SUPPORT.md](SUPPORT.md) for the information to include. - -For a vulnerability or private-data exposure, follow [SECURITY.md](SECURITY.md). Do not publish real profiles, credentials, or conversation histories in a public issue. - -## License - -Copyright © 2026 KarmenLoop and User Behavior Personalization contributors. - -This project is licensed under the [Apache License, Version 2.0](LICENSE). The license permits use, modification, redistribution, and commercial use subject to its terms and includes an express contributor patent grant. Preserve the applicable license and notices when redistributing. Third-party materials and attribution are described in [NOTICE](NOTICE). - -## Acknowledgments - -The package uses the conventional `SKILL.md` structure and Markdown-based, file-backed instructions. It is an independent skill package. It is not an official integration, endorsement, or release of any agent host. - -## Contact - -[GitHub Issues](https://github.com/KarmenLoop/user-behavior-personalization/issues) · [KarmenLoop](https://github.com/KarmenLoop) · [Security Policy](SECURITY.md) - -Private vulnerability reporting depends on the repository owner's configured GitHub reporting channel; see [SECURITY.md](SECURITY.md). +Apache-2.0. The original license terms govern use and redistribution; retain the included legal files. [KarmenLoop](https://karmenloop.com). diff --git a/README.zh-CN.md b/README.zh-CN.md new file mode 100644 index 0000000..aaf3724 --- /dev/null +++ b/README.zh-CN.md @@ -0,0 +1,37 @@ +# User Behavior Personalization · 用户偏好记录 + +[English](README.md) | 简体中文 + +把有用偏好写进用户能检查和更正的资料中。这个技能规定如何将明确反馈整理为有范围的使用指导,避免把猜测悄悄记成个人事实。 + +[下载 v0.1.1](https://github.com/KarmenLoop/user-behavior-personalization/releases/tag/v0.1.1) · [教程](docs/tutorial.zh-CN.md) · [反馈问题](https://github.com/KarmenLoop/user-behavior-personalization/issues) + +## 用途与范围 + +包内是技能说明、空白模板和合成样例。身份核实、私有存储、加载、删除导出,以及调度和同步均由宿主提供。 + +![用户偏好记录流程示意](docs/images/workflow-v0.1.1.svg) + +*v0.1.1 的流程示意,非应用截图或运行验收。* + +## 开始使用 + +解压 ZIP,在顶层目录运行 python3 scripts/install_skill.py --destination ../installed-skills/user-behavior-personalization。目标必须是源目录外的新目录,再通过宿主支持的加载方式选择它。 + +由宿主明确 PROFILE_ROOT、USER_ID、USER_TIMEZONE、MEMORY_ENABLED、CONVERSATION_SOURCE、REFLECTION_TRIGGER。这些是集成约定字段,不是附带程序会读取的环境变量。使用私有用户目录里的空白模板开始。 + +## 第一次有用的任务 + +使用含明确更正的合成对话,让宿主提出对应范围的偏好并展示来源,只通过现有且已授权的操作保存,再从已保存记录验证后续读取。 + +检查一次冲突更正,再通过真实宿主测试导出或删除。仓库检查确保模板空白及包内容规范,不代表已通过真实用户或跨设备全链路认证。 + +## 常见问题 + +**装好后会记住所有对话吗?** 不会。宿主必须明确提供已授权的对话、存储和加载。本包不会启动服务或注册定时器。 + +## 文档与许可证 + +[下载到实践的使用指南](docs/tutorial.zh-CN.md) · [LICENSE](LICENSE) + +Apache-2.0. 许可证条件以原文为准,再分发时保留包内法律文件。 [KarmenLoop](https://karmenloop.com). diff --git a/VERSION b/VERSION index 6e8bf73..17e51c3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0 +0.1.1 diff --git a/docs/images/workflow-v0.1.1.svg b/docs/images/workflow-v0.1.1.svg new file mode 100644 index 0000000..1bbc23e --- /dev/null +++ b/docs/images/workflow-v0.1.1.svg @@ -0,0 +1 @@ +User Behavior Personalization v0.1.1Explanatory workflow diagram for version 0.1.1; not a host screenshot or runtime result.User Behavior Personalizationv0.1.1 · workflow illustration / 流程示意Authorized feedback and verified userScoped preference with sourcePrivate profile under host controlsInspect, correct, export, or delete diff --git a/docs/tutorial.en.md b/docs/tutorial.en.md new file mode 100644 index 0000000..7f9a8c6 --- /dev/null +++ b/docs/tutorial.en.md @@ -0,0 +1,37 @@ +# User Behavior Personalization: user guide + +English | [简体中文](tutorial.zh-CN.md) · [Project](../README.md) + +This guide matches **v0.1.1**. + +## 1. Download and verify + +From the release, download [`user-behavior-personalization-v0.1.1.zip`](https://github.com/KarmenLoop/user-behavior-personalization/releases/tag/v0.1.1) and its checksum file or manifest. Compare the complete SHA-256 before extracting: use shasum -a 256 on macOS, sha256sum on Linux, or Get-FileHash -Algorithm SHA256 in PowerShell. Byte consistency relies on obtaining the expected hash from a trusted source. + +## 2. Install and load + +Extract the ZIP, then run python3 scripts/install_skill.py --destination ../installed-skills/user-behavior-personalization from its top-level directory. The destination must be new and outside the source. Select that directory with your host’s supported loader. + +Refresh host discovery or open a new session, explicitly read the installed SKILL.md, and check the version above. The skill needs no separate model account; the host supplies its own model, tools, and permissions. + +## 3. Configure and try one task + +Have the host establish PROFILE_ROOT, USER_ID, USER_TIMEZONE, MEMORY_ENABLED, CONVERSATION_SOURCE, and REFLECTION_TRIGGER. These are integration contract fields, not environment variables consumed by bundled code. Start with blank templates in a private user directory. + +Use a synthetic conversation containing an explicit correction. Ask the host to propose the corresponding scoped preference, show its source, and save it only through available authorized operations. Verify later recall from that saved record. + +## 4. Develop a repeatable workflow + +Review a conflicting correction and test export or deletion through the real host. Repository checks preserve blank templates and package hygiene; no end-to-end live-user or device-continuity certification is claimed. + +Keep the version, actual command, exit code, resulting files, and unverified limits together. Use synthetic data for the first check. + +## 5. Troubleshoot, update, and remove + +If the host cannot find the skill, check its configured discovery root and SKILL.md readability. A checksum mismatch needs a fresh verified download; do not skip it. + +Finish active writes and back up the skill and private task data separately. Extract updates into a new directory and verify before switching. For rollback, restore the older skill while retaining newer user records and evidence. Uninstall only its exact skill directory or discovery entry; separately registered schedules must be cancelled and confirmed in their host. + +## 6. License + +[Apache-2.0](../LICENSE). This is concise user guidance; consult the original license for use and redistribution terms. diff --git a/docs/tutorial.zh-CN.md b/docs/tutorial.zh-CN.md new file mode 100644 index 0000000..5dae7b0 --- /dev/null +++ b/docs/tutorial.zh-CN.md @@ -0,0 +1,37 @@ +# User Behavior Personalization · 用户偏好记录: 使用指南 + +[English](tutorial.en.md) | 简体中文 · [项目首页](../README.zh-CN.md) + +本指南对应 **v0.1.1**. + +## 1. 下载与校验 + +从发行页下载 [`user-behavior-personalization-v0.1.1.zip`](https://github.com/KarmenLoop/user-behavior-personalization/releases/tag/v0.1.1),同时保留校验文件或 manifest。比较完整 SHA-256 后再解压:macOS 使用 shasum -a 256,Linux 使用 sha256sum,PowerShell 使用 Get-FileHash -Algorithm SHA256。校验只能证明字节一致,预期哈希本身也需要可信来源。 + +## 2. 安装与加载 + +解压 ZIP,在顶层目录运行 python3 scripts/install_skill.py --destination ../installed-skills/user-behavior-personalization。目标必须是源目录外的新目录,再通过宿主支持的加载方式选择它。 + +刷新宿主发现或开启新会话,明确读取已安装的 SKILL.md,并核对上面版本。不需要为技能另开模型账号;宿主使用自己的模型、工具与权限。 + +## 3. 配置与第一项任务 + +由宿主明确 PROFILE_ROOT、USER_ID、USER_TIMEZONE、MEMORY_ENABLED、CONVERSATION_SOURCE、REFLECTION_TRIGGER。这些是集成约定字段,不是附带程序会读取的环境变量。使用私有用户目录里的空白模板开始。 + +使用含明确更正的合成对话,让宿主提出对应范围的偏好并展示来源,只通过现有且已授权的操作保存,再从已保存记录验证后续读取。 + +## 4. 进一步实践 + +检查一次冲突更正,再通过真实宿主测试导出或删除。仓库检查确保模板空白及包内容规范,不代表已通过真实用户或跨设备全链路认证。 + +保留当前版本、真实命令、退出码、结果与未验证限制。使用合成数据做首次检查。 + +## 5. 排错、升级与移除 + +宿主找不到技能时,先检查配置的技能根目录和 SKILL.md 可读性。哈希不一致时停止使用该包并重新核对下载;不要跳过错误。 + +升级前完成当前写入,分别备份技能与私人任务数据。将新版本解压到新目录,核对后再切换;回退时恢复旧技能,保留较新的用户数据与证据。卸载只移除对应技能目录或发现入口;如曾另行注册调度,应在真实宿主中取消并确认。 + +## 6. 许可证 + +[Apache-2.0](../LICENSE). 此处提供简明用户指南;具体使用和再分发条件以许可证原文为准。 diff --git a/publication.json b/publication.json new file mode 100644 index 0000000..0e32450 --- /dev/null +++ b/publication.json @@ -0,0 +1,13 @@ +{ + "version": "0.1.1", + "documents": [ + "README.md", + "README.zh-CN.md", + "docs/tutorial.en.md", + "docs/tutorial.zh-CN.md" + ], + "media_files": { + "docs/images/workflow-v0.1.1.svg": "4a3f2b45afd64cee03e2f019ba7122c02586f5829b430f04a4c2b0bfb902236e" + }, + "source_files": {} +} diff --git a/scripts/check_package.py b/scripts/check_package.py index 64eb13c..4415d6f 100644 --- a/scripts/check_package.py +++ b/scripts/check_package.py @@ -67,7 +67,7 @@ def check(): except (UnicodeError, OSError) as exc: errors.append(f"Cannot read release text {relative}: {exc}") continue - if CJK.search(content): + if path.suffix not in {".md", ".svg"} and CJK.search(content): errors.append(f"CJK text found in English-only package: {relative}") if path.name == "state.json" and relative.as_posix() != "assets/templates/state.json": errors.append(f"Unexpected live state file: {relative}") diff --git a/scripts/check_publication.py b/scripts/check_publication.py new file mode 100644 index 0000000..9720dfb --- /dev/null +++ b/scripts/check_publication.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +"""Check the current bilingual publication and its bound media.""" +import hashlib +import json +from pathlib import Path +import re +import sys + +root=Path(__file__).resolve().parents[1] +data=json.loads((root/'publication.json').read_text(encoding='utf-8')) +errors=[] +for name in data['documents']: + path=root/name + text=path.read_text(encoding='utf-8') + if data['version'] not in text: errors.append('Missing version: '+name) + for link in re.findall(r'\]\(([^)]+)\)',text): + if '://' in link or link.startswith(('#','mailto:')): continue + if not (path.parent/link.split('#',1)[0]).exists(): errors.append('Broken link: '+name+' -> '+link) +for name,digest in data['media_files'].items(): + path=root/name + if not path.is_file() or hashlib.sha256(path.read_bytes()).hexdigest()!=digest: + errors.append('Media drift: '+name) +for name,digest in data['source_files'].items(): + path=root/name + if not path.is_file() or hashlib.sha256(path.read_bytes()).hexdigest()!=digest: + errors.append('Capture source drift: '+name) +for name in data['documents']+list(data['media_files']): + if ' ' in name: errors.append('Space in publication filename: '+name) +print(json.dumps({'ok':not errors,'version':data['version'],'errors':errors,'scope':'bilingual documents, version and media identity'},indent=2)) +sys.exit(bool(errors)) diff --git a/scripts/package_release.py b/scripts/package_release.py new file mode 100644 index 0000000..47ab5a8 --- /dev/null +++ b/scripts/package_release.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +"""Package one clean committed source with both languages and legal notices.""" +import argparse +import hashlib +import json +from pathlib import Path +import subprocess +import sys +import zipfile + +root=Path(__file__).resolve().parents[1] +parser=argparse.ArgumentParser(description=__doc__) +parser.add_argument('--output',type=Path,required=True,help='New directory outside the repository') +args=parser.parse_args() +target=args.output.expanduser().resolve() +if target.exists() or target==root or root in target.parents:parser.error('choose a new output directory outside the source tree') +if subprocess.check_output(['git','status','--porcelain'],cwd=root).strip():parser.error('commit changes before packaging') +subprocess.run([sys.executable,'-B','scripts/check_publication.py'],cwd=root,check=True) +version=(root/'VERSION').read_text().strip() +name='user-behavior-personalization' +stem=name+'-v'+version +target.mkdir(parents=True) +archive=target/(stem+'.zip') +names=subprocess.check_output(['git','ls-files','-z'],cwd=root).decode().split('\0') +with zipfile.ZipFile(archive,'w',zipfile.ZIP_DEFLATED) as output: + for filename in sorted(filter(None,names)):output.write(root/filename,stem+'/'+filename) +assets=[archive] + +receipt={'version':version,'commit':subprocess.check_output(['git','rev-parse','HEAD'],cwd=root).decode().strip(),'artifacts':[]} +for asset in assets: + with zipfile.ZipFile(asset) as output:assert output.testzip() is None + receipt['artifacts'].append({'file':asset.name,'bytes':asset.stat().st_size,'sha256':hashlib.sha256(asset.read_bytes()).hexdigest()}) +(target/'SHA256SUMS.txt').write_text(''.join(x['sha256']+' '+x['file']+'\n' for x in receipt['artifacts'])) +(target/'release-receipt.json').write_text(json.dumps(receipt,indent=2)+'\n') +print(json.dumps(receipt,indent=2))