cof-cli 1.2.0__tar.gz → 1.2.1__tar.gz

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.
Files changed (46) hide show
  1. {cof_cli-1.2.0 → cof_cli-1.2.1}/PKG-INFO +1 -1
  2. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/__init__.py +1 -1
  3. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/cli.py +129 -9
  4. cof_cli-1.2.1/cof_cli/platform_import.py +1571 -0
  5. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli.egg-info/PKG-INFO +1 -1
  6. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli.egg-info/SOURCES.txt +2 -0
  7. {cof_cli-1.2.0 → cof_cli-1.2.1}/pyproject.toml +1 -1
  8. cof_cli-1.2.1/tests/test_platform_import.py +773 -0
  9. {cof_cli-1.2.0 → cof_cli-1.2.1}/tests/test_roundtrip.py +5 -1
  10. {cof_cli-1.2.0 → cof_cli-1.2.1}/README.md +0 -0
  11. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/cast.py +0 -0
  12. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/completeness.py +0 -0
  13. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/container.py +0 -0
  14. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/convert.py +0 -0
  15. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/memories.py +0 -0
  16. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/migrate.py +0 -0
  17. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/model.py +0 -0
  18. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/ops.py +0 -0
  19. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/profiles.py +0 -0
  20. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/propose.py +0 -0
  21. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/psyche.py +0 -0
  22. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/attitude.schema.json +0 -0
  23. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/body.schema.json +0 -0
  24. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/card.schema.json +0 -0
  25. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/consent.schema.json +0 -0
  26. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/garments-1.0.json +0 -0
  27. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/hair.schema.json +0 -0
  28. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/manifest.schema.json +0 -0
  29. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/memory.schema.json +0 -0
  30. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/pose.schema.json +0 -0
  31. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/psyche-node.schema.json +0 -0
  32. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/psyche.schema.json +0 -0
  33. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/skeleton.schema.json +0 -0
  34. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/visemes.schema.json +0 -0
  35. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/voice-profile.schema.json +0 -0
  36. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/schemas/weights.schema.json +0 -0
  37. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/selfdesc.py +0 -0
  38. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/tokens.py +0 -0
  39. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/validate.py +0 -0
  40. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli/zodiac.py +0 -0
  41. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli.egg-info/dependency_links.txt +0 -0
  42. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli.egg-info/entry_points.txt +0 -0
  43. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli.egg-info/requires.txt +0 -0
  44. {cof_cli-1.2.0 → cof_cli-1.2.1}/cof_cli.egg-info/top_level.txt +0 -0
  45. {cof_cli-1.2.0 → cof_cli-1.2.1}/setup.cfg +0 -0
  46. {cof_cli-1.2.0 → cof_cli-1.2.1}/tests/test_hunt.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cof-cli
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: COF — Character Open File: validate, pack, unpack and convert .cof character containers
5
5
  Author: Yann Souetre
6
6
  License-Expression: MIT
@@ -1,5 +1,5 @@
1
1
  """cof-cli — reference tooling for COF (Character Open File)."""
2
2
 
3
- __version__ = "1.2.0"
3
+ __version__ = "1.2.1"
4
4
  MIMETYPE = "application/vnd.cof.character+zip"
5
5
  SPEC_VERSION = "1.2"
@@ -147,21 +147,125 @@ def cmd_read_text(a):
147
147
 
148
148
 
149
149
  def cmd_import(a):
150
- src = Path(a.src)
151
- if src.suffix.lower() == ".png":
150
+ """A character card (PNG/JSON, V1/V2/V3) as before; a platform export (Character.AI through CAI Tools or PersonaText,
151
+ SillyTavern, Oobabooga, the official zip) through platform_import (RFC 0006): the character, and each conversation
152
+ as one personal memory."""
153
+ from . import platform_import as PI
154
+ srcs = [Path(x) for x in a.src]
155
+ for s_ in srcs:
156
+ if not s_.exists():
157
+ print(f"ERROR {s_}: no such file or folder", file=sys.stderr); return 2
158
+ try:
159
+ ages = PI.parse_age(a.age)
160
+ except ValueError as e:
161
+ print(f"ERROR {e}", file=sys.stderr); return 2
162
+ if a.inspect:
163
+ for s_ in srcs:
164
+ sys.stdout.write(PI.inspect(s_))
165
+ return 0
166
+ kinds = [PI.sniff(s_) for s_ in srcs]
167
+ if len(srcs) == 1 and kinds[0] in ("card-png", "card-json") and not (a.persona or a.no_chats or a.keep_source or a.content or a.apparent or a.original or a.no_avatar or a.card_lang):
168
+ return _import_card(a, srcs[0], ages) # a plain card: the 1.0 path, unchanged
169
+ rep = PI.Report()
170
+ bundle = PI.Bundle(report=rep)
171
+ try:
172
+ for s_ in srcs:
173
+ b = PI.read_file(s_, rep)
174
+ bundle.characters += b.characters; bundle.chats += b.chats
175
+ groups = PI.group(bundle)
176
+ if not groups:
177
+ for x in rep.alerts:
178
+ print(f"ERROR {x}", file=sys.stderr)
179
+ for what, n in rep.ignored:
180
+ print(f"NOTE {what}: {n}", file=sys.stderr)
181
+ print("nothing imported: no character and no conversation recognised", file=sys.stderr)
182
+ return 1
183
+ if len(groups) > 1 and "" in ages:
184
+ print("ERROR several characters found (" + ", ".join(c.name or "?" for c, _ in groups) + "): give each age as --age \"NAME=N\"", file=sys.stderr)
185
+ return 2
186
+ content = [c.strip() for c in a.content.split(",") if c.strip()] if a.content else None
187
+ CONTENT = ("none", "nudity", "sexual", "violence", "gore", "drugs", "profanity", "horror", "political", "religious")
188
+ bad = [c for c in (content or []) if c not in CONTENT] + (["none with another value"] if content and "none" in content and len(content) > 1 else [])
189
+ bad += [f"--{k.replace('_', '-')} {v}" for k, v in (("lang", a.lang), ("card_lang", a.card_lang)) if v and not re.fullmatch(r"[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*", v)]
190
+ if bad: # checked before anything is written (hunt CLI-1)
191
+ print(f"ERROR not valid: {', '.join(bad)} (--content: {', '.join(CONTENT)}; --lang / --card-lang: a language tag such as fr or pt-BR) — nothing written", file=sys.stderr)
192
+ return 2
193
+ opts = PI.Options(lang=a.lang, card_lang=a.card_lang, age=ages, real=a.real, original=a.original, persona=a.persona, no_avatar=a.no_avatar,
194
+ no_chats=a.no_chats, keep_source=a.keep_source, content=content, apparent=a.apparent)
195
+ plans = [PI.plan_character(char, chats, opts) for char, chats in groups] # every stop happens here, before any write
196
+ PI.assign_destinations(plans, Path(a.out) if a.out else None)
197
+ except PI.ImportStop as e:
198
+ print(f"STOP {e}", file=sys.stderr)
199
+ return e.code
200
+ except (ValueError, TypeError) as e:
201
+ print(f"ERROR {e} — nothing written", file=sys.stderr)
202
+ return 1
203
+ dests = []
204
+ try:
205
+ for pl in plans:
206
+ dests.append(PI.write_character(pl, opts, rep))
207
+ except Exception as e: # all or nothing: the characters already written go (RFC 0006 § 3.7.4, hunt CLI-5)
208
+ for d in dests:
209
+ shutil.rmtree(d, ignore_errors=True)
210
+ print(f"ERROR {e} — nothing written", file=sys.stderr)
211
+ return 1
212
+ worst, out_json = 0, []
213
+ for d in dests:
214
+ r = Report()
215
+ manifest = validate_dir(d, r, recompute=True)
216
+ if manifest:
217
+ (d / "manifest.json").write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + "\n", "utf-8")
218
+ from .selfdesc import write_self_description
219
+ write_self_description(d, manifest)
220
+ personal = [w for w in r.warnings if "personal memory (a user's data)" in w]
221
+ head_only = [w for w in r.warnings if "shows only the head" in w]
222
+ r.warnings = [w for w in r.warnings if w not in personal and w not in head_only]
223
+ if personal:
224
+ r.warnings.append(f"{len(personal)} personal memories (a user's data): extract / export / the builder's build drop them unless asked (--keep-personal); do not share this folder as is")
225
+ if head_only:
226
+ r.warnings.append("the avatar is a head only: the default outfit is undefined (expected for an imported avatar)")
227
+ if a.json: # one JSON document on stdout (hunt CLI-15)
228
+ out_json.append({"folder": str(d), **r.to_dict()})
229
+ worst = max(worst, 1 if r.errors else 0)
230
+ continue
231
+ print(f"COF folder created: {d}")
232
+ worst = max(worst, _print_report(r, a.json))
233
+ if a.json:
234
+ print(json.dumps({"characters": out_json, "import": {"lines": rep.lines, "ignored": [list(x) for x in rep.ignored], "alerts": rep.alerts}},
235
+ ensure_ascii=False, indent=2))
236
+ return worst
237
+ _print_import_report(rep)
238
+ return worst
239
+
240
+
241
+ def _print_import_report(rep) -> None:
242
+ print("\nimport report")
243
+ for x in rep.lines:
244
+ print(f" {x}")
245
+ for what, n in rep.ignored:
246
+ print(f" left out / noted: {what}: {n}")
247
+ for x in rep.alerts:
248
+ print(f" CHECK {x}")
249
+ print(" CHECK `fictional` and the intellectual property (tags.ip) were not verified; rights left at the conservative defaults "
250
+ "(personal use, no redistribution, no training). The conversations are your personal data: memories `visibility: personal`.")
251
+
252
+
253
+ def _import_card(a, src: Path, ages: dict):
254
+ if len(ages) > 1:
255
+ print("ERROR one character: give --age N", file=sys.stderr); return 2
256
+ age = next(iter(ages.values()), None)
257
+ if src.suffix.lower() == ".png" or src.read_bytes()[:8] == b"\x89PNG\r\n\x1a\n":
152
258
  png = src.read_bytes()
153
259
  card = read_card_from_png(png)
154
- elif src.suffix.lower() == ".json":
260
+ else:
155
261
  card = json.loads(src.read_text("utf-8"))
156
262
  png = None
157
263
  if "spec" not in card:
158
264
  card = {"spec": "chara_card_v2", "spec_version": "2.0", "data": card}
159
- else:
160
- print("expected source: .png (card) or .json (card)", file=sys.stderr)
161
- return 1
265
+ from .platform_import import _purge_msg_arrays
266
+ removed = _purge_msg_arrays(card) if isinstance(card, dict) else [] # a conversation never stays in a card, whatever its key (RFC 0006 § 3.1.2)
162
267
  dest = Path(a.out) if a.out else Path(src.stem)
163
- removed = []
164
- card_to_cof_dir(card, dest, png=png if a.keep_png else None, age=a.age, fictional=not a.real, language=a.lang, removed=removed)
268
+ card_to_cof_dir(card, dest, png=png if a.keep_png else None, age=age, fictional=not a.real, language=a.lang or "en", removed=removed)
165
269
  rep = Report()
166
270
  validate_dir(dest, rep, recompute=True)
167
271
  if removed:
@@ -615,7 +719,23 @@ def main(argv=None) -> int:
615
719
  s = sub.add_parser("tokens", help="token estimate per block"); s.add_argument("path"); s.set_defaults(fn=cmd_tokens)
616
720
  s = sub.add_parser("embed-text", help="write a text (.md/.txt) into a PNG as iTXt 'Description' — readable by the builder (personality + appearance)"); s.add_argument("png"); s.add_argument("text"); s.add_argument("-o", "--out"); s.set_defaults(fn=cmd_embed_text)
617
721
  s = sub.add_parser("read-text", help="show the descriptive text embedded in an image (PNG/JPEG: iTXt, XMP, EXIF)"); s.add_argument("image"); s.set_defaults(fn=cmd_read_text)
618
- s = sub.add_parser("import", help="PNG/JSON card (CCv2/V3) → COF folder"); s.add_argument("src"); s.add_argument("-o", "--out"); s.add_argument("--age", type=int); s.add_argument("--real", action="store_true", help="character based on a real person (consent required)"); s.add_argument("--lang", default="en"); s.add_argument("--keep-png", action="store_true", help="keep the PNG as the head.front view"); s.add_argument("--json", action="store_true"); s.set_defaults(fn=cmd_import)
722
+ s = sub.add_parser("import", help="a character card (PNG/JSON, V1/V2/V3), or a platform export — Character.AI through CAI Tools or PersonaText, SillyTavern, Oobabooga, the official zip (RFC 0006): the character, and each conversation as one personal memory")
723
+ s.add_argument("src", nargs="+", help="files, zips or folders; several files of one character make one COF")
724
+ s.add_argument("-o", "--out", help="output folder (a parent folder when several characters are found)")
725
+ s.add_argument("--age", action="append", metavar="N|NAME=N", help="the character's age (years) — required to keep an avatar; NAME=N for one of several characters")
726
+ s.add_argument("--apparent", action="store_true", help="the --age given is an apparent age (basis apparent), not a declared one")
727
+ s.add_argument("--no-avatar", action="store_true", help="import without the avatar (when no age can be given)")
728
+ s.add_argument("--real", action="store_true", help="character based on a real person (consent required)")
729
+ s.add_argument("--original", action="store_true", help="platform import: the character is your own original creation (tags.ip.original)")
730
+ s.add_argument("--lang", help="the language of the conversations and of the memory texts (en, fr, de, es, zh, ja…); default: detected, else en (a plain card: en)")
731
+ s.add_argument("--card-lang", help="platform import: the language of the character's card; default: detected, else --lang")
732
+ s.add_argument("--persona", help="your name in the conversations (default: the name the export gives, else 'You')")
733
+ s.add_argument("--content", metavar="LIST", help="tags.content after reading, comma separated (none, violence, sexual…): removes the content-unreviewed tag")
734
+ s.add_argument("--no-chats", action="store_true", help="import the character only")
735
+ s.add_argument("--keep-source", action="store_true", help="also keep each source chat file, byte for byte, beside its transcript (personal)")
736
+ s.add_argument("--inspect", action="store_true", help="print the structure of the files with every value redacted (to share an unknown export's shape), write nothing")
737
+ s.add_argument("--keep-png", action="store_true", help="plain card import: keep the PNG as the head.front view")
738
+ s.add_argument("--json", action="store_true"); s.set_defaults(fn=cmd_import)
619
739
  s = sub.add_parser("export", help="folder/.cof → png | soul | card | agent (workspace: SOUL.md, IDENTITY.md, skills/, memories) — from the default preset or --preset"); s.add_argument("src"); s.add_argument("--format", choices=["png", "soul", "card", "agent"], required=True); s.add_argument("-o", "--out"); s.add_argument("--preset"); s.add_argument("--keep-personal", action="store_true", help="agent: also export `visibility: personal` memories and psyche nodes (dropped by default)"); s.add_argument("--keep-dangerous", action="store_true", help="agent: also render psyche nodes of risk `dangerous` (dropped by default: an agent acts — RFC 0004 § 3 septies)"); s.set_defaults(fn=cmd_export)
620
740
  s = sub.add_parser("migrate", help="folder v0.2 … v0.5 → v1.0; --psyche converts the 1.0 lists (goals, fears, values, behaviours) into psyche nodes (1.2)"); s.add_argument("dir"); s.add_argument("--psyche", action="store_true", help="write psyche nodes from psyche.json goals / fears / values and the card's cof.goals / cof.fears / cof.behavior (the lists stay); idempotent"); s.add_argument("--json", action="store_true"); s.set_defaults(fn=cmd_migrate)
621
741
  s = sub.add_parser("merge", help="merge several .cof files/folders (same name, nickname, fictional status and morphology class ⇒ same identity, otherwise multiple identities)"); s.add_argument("sources", nargs="+"); s.add_argument("-o", "--out", required=True); s.add_argument("--json", action="store_true"); s.set_defaults(fn=cmd_merge)