motif-viewer 0.1.0__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.
- motif_viewer-0.1.0/.gitignore +10 -0
- motif_viewer-0.1.0/LICENSE +201 -0
- motif_viewer-0.1.0/PKG-INFO +124 -0
- motif_viewer-0.1.0/README.md +107 -0
- motif_viewer-0.1.0/pyproject.toml +64 -0
- motif_viewer-0.1.0/src/motif/viewer/__init__.py +17 -0
- motif_viewer-0.1.0/src/motif/viewer/__main__.py +3 -0
- motif_viewer-0.1.0/src/motif/viewer/analysis.py +226 -0
- motif_viewer-0.1.0/src/motif/viewer/cli.py +163 -0
- motif_viewer-0.1.0/src/motif/viewer/index.html +1633 -0
- motif_viewer-0.1.0/src/motif/viewer/loader.py +29 -0
- motif_viewer-0.1.0/src/motif/viewer/manifest.py +326 -0
- motif_viewer-0.1.0/src/motif/viewer/marks.py +72 -0
- motif_viewer-0.1.0/src/motif/viewer/page.py +5 -0
- motif_viewer-0.1.0/src/motif/viewer/py.typed +0 -0
- motif_viewer-0.1.0/src/motif/viewer/schema.py +146 -0
- motif_viewer-0.1.0/src/motif/viewer/server.py +138 -0
- motif_viewer-0.1.0/tests/sample_agents.py +97 -0
- motif_viewer-0.1.0/tests/test_cli.py +208 -0
- motif_viewer-0.1.0/tests/test_dependencies.py +57 -0
- motif_viewer-0.1.0/tests/test_isolation.py +44 -0
- motif_viewer-0.1.0/tests/test_loader.py +48 -0
- motif_viewer-0.1.0/tests/test_manifest.py +187 -0
- motif_viewer-0.1.0/tests/test_marks.py +50 -0
- motif_viewer-0.1.0/tests/test_page.py +68 -0
- motif_viewer-0.1.0/tests/test_public_surface.py +49 -0
- motif_viewer-0.1.0/tests/test_schema.py +100 -0
- motif_viewer-0.1.0/tests/test_server.py +174 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: motif-viewer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 데코레이터만 붙이면 에이전트 구조 그래프를 보여 주는 표준 라이브러리 전용 뷰어
|
|
5
|
+
Project-URL: Repository, https://github.com/motif-agent/motif-viewer
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Typing :: Typed
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# motif-viewer
|
|
19
|
+
|
|
20
|
+
일반 Python 함수에 데코레이터만 붙이면 에이전트 구조 그래프를 브라우저에서 보여 주는 뷰어다. 표준 라이브러리만 쓰며(`dependencies = []`) 본체 패키지 `motif.agent`(motif-agent)를 가져오지 않는다. 의존 방향은 `motif.agent → motif.viewer` 한쪽뿐이다. import 이름은 `motif.viewer`, 명령은 `motif-viewer`다. Python 3.12 이상이 필요하다.
|
|
21
|
+
|
|
22
|
+
## 설치
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
pip install motif-viewer
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`python -m motif.viewer`로도 실행한다. 설치 파일에는 뷰어 페이지(`index.html`)가 들어 있어 따로 받을 것이 없다.
|
|
29
|
+
|
|
30
|
+
## 네임스페이스
|
|
31
|
+
|
|
32
|
+
`motif`는 여러 배포본이 함께 쓰는 네임스페이스 패키지(PEP 420)다. 이 배포본은 `motif/viewer`만 담고 `motif/__init__.py`를 두지 않는다. 그래서 `motif-agent`(`motif.agent`)와 함께 설치해도 두 패키지가 같은 `motif` 아래에서 함께 import된다.
|
|
33
|
+
|
|
34
|
+
## 표시용 데코레이터
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from motif.viewer import agent, model, step, tool
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@tool
|
|
41
|
+
def search(query: str) -> list[str]: ...
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@model(name="claude-sonnet")
|
|
45
|
+
def llm(prompt: str) -> str: ...
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@step
|
|
49
|
+
def draft(question: str) -> str:
|
|
50
|
+
return llm(f"{question} {search(question)}")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@agent(description="질문에 답한다")
|
|
54
|
+
def rag(question: str) -> str:
|
|
55
|
+
return draft(question)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- `agent`·`step`·`tool`·`model`은 함수에 `NodeMark`(종류, `name`, `description`)만 붙이고 같은 함수를 그대로 돌려준다. 호출 방식과 결과는 바뀌지 않는다. `@step`처럼 그대로 쓰거나 `@step(name=..., description=...)`처럼 쓴다.
|
|
59
|
+
- 노드 id는 `모듈.정규 이름`, 이름은 `name`이 없으면 함수 이름이다.
|
|
60
|
+
- `mark_of(함수)`가 붙은 `NodeMark`(없으면 `None`)를 돌려준다.
|
|
61
|
+
|
|
62
|
+
## CLI
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
motif-viewer manifest my_agent:rag [module:attribute ...] [-o manifest.json] [--version V]
|
|
66
|
+
motif-viewer dev my_agent:rag [--host 127.0.0.1] [--port 8000] [--allow-host HOST ...] [--version V]
|
|
67
|
+
motif-viewer page -o viewer_dir [--manifest manifest.json] [--audit audit.jsonl]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
- `module:attribute`는 에이전트 함수 하나나 그 리스트·튜플을 가리킨다. 모듈은 현재 작업 디렉터리에서도 찾는다(`motif.viewer.loader.load_reference`). 성공은 0, 사용법 오류는 2, 실패는 1이다.
|
|
71
|
+
- `manifest`는 매니페스트 JSON을 표준 출력이나 `-o` 파일에 쓴다.
|
|
72
|
+
- `dev`는 로컬 서버를 띄우고 `http://<host>:<port>/index.html?manifest=manifest.json&watch=1` 주소를 출력한다. `/index.html`(뷰어)과 `/manifest.json` 말고는 404다. `/manifest.json`을 요청할 때마다 현재 작업 디렉터리의 `.py` 파일 수정 시각과 크기를 보고, 바뀌었으면 별도 프로세스로 매니페스트를 다시 만든다. DNS 리바인딩을 막으려고 허용하지 않은 `Host` 헤더는 403으로 거절하며, `--host`가 loopback이 아니면 stderr에 경고를 낸다.
|
|
73
|
+
- `page`는 이미 만든 매니페스트 JSON과 감사 로그 JSONL(예: 본체 패키지의 매니페스트 명령·`JsonlAuditSink` 출력)을 보는 정적 페이지를 만든다. 디렉터리에 `index.html`을 쓰고 입력 파일을 그 옆에 복사한 뒤, 열 주소와 `python -m http.server --bind 127.0.0.1` 명령을 출력한다. 입력 파일이 없거나 이름이 겹치면, 출력 위치가 심볼릭 링크면 쓰지 않고 사용법 오류(2)다.
|
|
74
|
+
|
|
75
|
+
## 매니페스트 계약
|
|
76
|
+
|
|
77
|
+
`build_manifest(agents, *, version=None, root=None, generated_at=None)`가 schema v1 JSON(dict)을 만든다. 상수와 검증은 `motif.viewer.schema`가 소유하며, 이 뷰어가 읽는 형태의 단일 정의다.
|
|
78
|
+
|
|
79
|
+
- 최상위 키: `schema_version`(`"1"`), `generated_at`, `version`, `agents`, `nodes`, `slots`, `edges`, `diagnostics`. 이 패키지가 만드는 매니페스트의 `slots`는 빈 목록이다. 뷰어는 `policy`·`catalog`가 있으면 그리고 없어도 읽는다.
|
|
80
|
+
- 노드 필드(`NODE_FIELDS`): `id`, `kind`, `name`, `role`, `description`, `grants`, `requires`, `route`, `dimension`, `location`, `interface`, `calls`, `permission`. 이 패키지가 채우지 않는 선택 필드(`role`·`route`·`dimension`·`calls`·`permission`은 `null`, `grants`·`requires`는 `[]`)의 기본값은 `node_record`가 한 곳에서 정한다.
|
|
81
|
+
- 간선: `{"from", "to", "certainty"}`. `certainty`는 `confirmed`·`possible`·`unresolved`이고 같은 두 노드 사이에서는 가장 강한 값 하나만 남긴다(`strengthen_edge`). 해결하지 못한 대상은 `unresolved:<식>`(`UNRESOLVED_TARGET_PREFIX`)으로 잇는다.
|
|
82
|
+
- 진단: `{"level", "code", "message", "node_id"}`. `level`은 `error`·`warning`·`info`이고 이 순서(`LEVEL_RANK`), 그다음 `code`·`node_id`·`message` 순으로 정렬한다(`Diagnostic`).
|
|
83
|
+
- `validate_manifest(manifest)`는 최상위 키, 목록 형식, 노드 필드, 간선 확실성, 진단 수준을 확인하고 어긋나면 `ManifestError`를 올린다.
|
|
84
|
+
|
|
85
|
+
### 분석 규칙
|
|
86
|
+
|
|
87
|
+
- 진입 함수에서 시작해 `agent`·`step` 노드의 본문을 따라간다. `tool`·`model`은 끝 노드다. 표시하지 않은 진입 함수는 에이전트로 보며, 에이전트가 아닌 진입 함수나 같은 이름의 에이전트 둘은 `ManifestError`다.
|
|
88
|
+
- 호출 대상은 클로저·모듈 전역·내장 이름에서 찾고 점 경로를 따라간다. `self.method()`와 `Planner().plan()`은 클래스에서 찾는다.
|
|
89
|
+
- 표시하지 않은 함수라도 `root`(기본은 현재 작업 디렉터리) 아래이고 `site-packages`·`dist-packages` 밖이면 안으로 따라 들어간다. 같은 함수를 두 번 따라가지 않는다.
|
|
90
|
+
- 인자(또는 인자로 넘긴 리스트·튜플·집합의 원소)로 표시된 함수를 넘기면 `possible` 간선을 만든다.
|
|
91
|
+
- 본문 최상위 호출은 `confirmed`, 분기·반복·`try`·조건 표현식·`and`/`or` 뒤쪽·컴프리헨션·내부 함수 안이거나 앞 문장에 `return`·`raise`가 있으면 `possible`이다. 첨자 호출, 지역 이름 호출, 찾을 수 없는 이름 호출은 `unresolved`다.
|
|
92
|
+
- 진단 코드: `dynamic_dispatch`·`source_unavailable`(경고), `conditional_call`(정보).
|
|
93
|
+
|
|
94
|
+
## 공개 API
|
|
95
|
+
|
|
96
|
+
공개 이름은 각 모듈의 `__all__`이며 `tests/test_public_surface.py`가 고정한다.
|
|
97
|
+
|
|
98
|
+
| 모듈 | 공개 이름 |
|
|
99
|
+
|---|---|
|
|
100
|
+
| `motif.viewer` | `agent`, `step`, `tool`, `model`, `mark_of`, `NodeKind`, `NodeMark`, `build_manifest`, `ManifestError`, `viewer_html` |
|
|
101
|
+
| `motif.viewer.schema` | `MANIFEST_SCHEMA_VERSION`, `UNRESOLVED_TARGET_PREFIX`, `LEVEL_RANK`, `NODE_FIELDS`, `Diagnostic`, `ManifestError`, `node_record`, `strengthen_edge`, `validate_manifest` |
|
|
102
|
+
| `motif.viewer.analysis` | `Certainty`, `FunctionNode`, `conditional_calls`, `definition_of`, `display_path`, `dotted_path`, `find_function`, `interface_of`, `is_local`, `resolve` |
|
|
103
|
+
| `motif.viewer.loader` | `load_reference`, `ReferenceLoadError` |
|
|
104
|
+
|
|
105
|
+
`viewer_html()`은 뷰어 페이지 HTML 문자열을 돌려준다. 다른 도구가 같은 스키마의 매니페스트를 만들어 이 뷰어로 보려면 `motif.viewer.schema`의 계약을 따르면 된다.
|
|
106
|
+
|
|
107
|
+
## 뷰어가 읽는 감사 기록
|
|
108
|
+
|
|
109
|
+
뷰어 페이지는 JSON Lines 감사 기록도 읽는다. 각 줄은 문자열 `schema_version`·`event_id`·`timestamp`·`event_type`·`run_id`를 가져야 하고, `event_type`은 페이지에 적힌 알려진 이벤트 목록(`run.started` 등 15종) 안에 있어야 한다. 목록 밖 이벤트나 형식이 틀린 줄은 건너뛰고 건너뛴 수를 센다.
|
|
110
|
+
|
|
111
|
+
## 시험
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
uv sync
|
|
115
|
+
make quality
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`make quality`는 ruff 검사·서식, mypy strict, 커버리지 90% 이상의 pytest를 차례로 실행한다. 시험은 `motif.agent`를 가져오지 않으며, `site-packages` 없이 소스만으로 `manifest` 명령이 동작하는지 하위 프로세스로 확인한다(`tests/test_isolation.py`). 패키지가 표준 라이브러리와 자기 자신만 가져오는지, 의존성이 비어 있는지, 공용 네임스페이스 `src/motif`에 `__init__.py`가 없는지는 `tests/test_dependencies.py`가 고정한다.
|
|
119
|
+
|
|
120
|
+
## 배포
|
|
121
|
+
|
|
122
|
+
- `.github/workflows/ci.yml`은 PR과 `main` 푸시마다 Python 3.12·3.13에서 `make quality`를 실행한다.
|
|
123
|
+
- `.github/workflows/publish.yml`은 `v*` 태그를 푸시하면 `make quality`와 `uv build`를 거쳐 TestPyPI, PyPI 순서로 올린다. 토큰 없이 Trusted Publishing을 쓰므로 PyPI·TestPyPI에 이 저장소와 `publish.yml`, 환경 이름(`testpypi`, `pypi`)을 신뢰 게시자로 먼저 등록해야 한다.
|
|
124
|
+
- sdist에는 `src/motif`, `tests`, `README.md`, `LICENSE`, `pyproject.toml`만 들어가고, wheel에는 `motif/viewer`만 들어간다.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# motif-viewer
|
|
2
|
+
|
|
3
|
+
일반 Python 함수에 데코레이터만 붙이면 에이전트 구조 그래프를 브라우저에서 보여 주는 뷰어다. 표준 라이브러리만 쓰며(`dependencies = []`) 본체 패키지 `motif.agent`(motif-agent)를 가져오지 않는다. 의존 방향은 `motif.agent → motif.viewer` 한쪽뿐이다. import 이름은 `motif.viewer`, 명령은 `motif-viewer`다. Python 3.12 이상이 필요하다.
|
|
4
|
+
|
|
5
|
+
## 설치
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pip install motif-viewer
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`python -m motif.viewer`로도 실행한다. 설치 파일에는 뷰어 페이지(`index.html`)가 들어 있어 따로 받을 것이 없다.
|
|
12
|
+
|
|
13
|
+
## 네임스페이스
|
|
14
|
+
|
|
15
|
+
`motif`는 여러 배포본이 함께 쓰는 네임스페이스 패키지(PEP 420)다. 이 배포본은 `motif/viewer`만 담고 `motif/__init__.py`를 두지 않는다. 그래서 `motif-agent`(`motif.agent`)와 함께 설치해도 두 패키지가 같은 `motif` 아래에서 함께 import된다.
|
|
16
|
+
|
|
17
|
+
## 표시용 데코레이터
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from motif.viewer import agent, model, step, tool
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@tool
|
|
24
|
+
def search(query: str) -> list[str]: ...
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@model(name="claude-sonnet")
|
|
28
|
+
def llm(prompt: str) -> str: ...
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@step
|
|
32
|
+
def draft(question: str) -> str:
|
|
33
|
+
return llm(f"{question} {search(question)}")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@agent(description="질문에 답한다")
|
|
37
|
+
def rag(question: str) -> str:
|
|
38
|
+
return draft(question)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
- `agent`·`step`·`tool`·`model`은 함수에 `NodeMark`(종류, `name`, `description`)만 붙이고 같은 함수를 그대로 돌려준다. 호출 방식과 결과는 바뀌지 않는다. `@step`처럼 그대로 쓰거나 `@step(name=..., description=...)`처럼 쓴다.
|
|
42
|
+
- 노드 id는 `모듈.정규 이름`, 이름은 `name`이 없으면 함수 이름이다.
|
|
43
|
+
- `mark_of(함수)`가 붙은 `NodeMark`(없으면 `None`)를 돌려준다.
|
|
44
|
+
|
|
45
|
+
## CLI
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
motif-viewer manifest my_agent:rag [module:attribute ...] [-o manifest.json] [--version V]
|
|
49
|
+
motif-viewer dev my_agent:rag [--host 127.0.0.1] [--port 8000] [--allow-host HOST ...] [--version V]
|
|
50
|
+
motif-viewer page -o viewer_dir [--manifest manifest.json] [--audit audit.jsonl]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- `module:attribute`는 에이전트 함수 하나나 그 리스트·튜플을 가리킨다. 모듈은 현재 작업 디렉터리에서도 찾는다(`motif.viewer.loader.load_reference`). 성공은 0, 사용법 오류는 2, 실패는 1이다.
|
|
54
|
+
- `manifest`는 매니페스트 JSON을 표준 출력이나 `-o` 파일에 쓴다.
|
|
55
|
+
- `dev`는 로컬 서버를 띄우고 `http://<host>:<port>/index.html?manifest=manifest.json&watch=1` 주소를 출력한다. `/index.html`(뷰어)과 `/manifest.json` 말고는 404다. `/manifest.json`을 요청할 때마다 현재 작업 디렉터리의 `.py` 파일 수정 시각과 크기를 보고, 바뀌었으면 별도 프로세스로 매니페스트를 다시 만든다. DNS 리바인딩을 막으려고 허용하지 않은 `Host` 헤더는 403으로 거절하며, `--host`가 loopback이 아니면 stderr에 경고를 낸다.
|
|
56
|
+
- `page`는 이미 만든 매니페스트 JSON과 감사 로그 JSONL(예: 본체 패키지의 매니페스트 명령·`JsonlAuditSink` 출력)을 보는 정적 페이지를 만든다. 디렉터리에 `index.html`을 쓰고 입력 파일을 그 옆에 복사한 뒤, 열 주소와 `python -m http.server --bind 127.0.0.1` 명령을 출력한다. 입력 파일이 없거나 이름이 겹치면, 출력 위치가 심볼릭 링크면 쓰지 않고 사용법 오류(2)다.
|
|
57
|
+
|
|
58
|
+
## 매니페스트 계약
|
|
59
|
+
|
|
60
|
+
`build_manifest(agents, *, version=None, root=None, generated_at=None)`가 schema v1 JSON(dict)을 만든다. 상수와 검증은 `motif.viewer.schema`가 소유하며, 이 뷰어가 읽는 형태의 단일 정의다.
|
|
61
|
+
|
|
62
|
+
- 최상위 키: `schema_version`(`"1"`), `generated_at`, `version`, `agents`, `nodes`, `slots`, `edges`, `diagnostics`. 이 패키지가 만드는 매니페스트의 `slots`는 빈 목록이다. 뷰어는 `policy`·`catalog`가 있으면 그리고 없어도 읽는다.
|
|
63
|
+
- 노드 필드(`NODE_FIELDS`): `id`, `kind`, `name`, `role`, `description`, `grants`, `requires`, `route`, `dimension`, `location`, `interface`, `calls`, `permission`. 이 패키지가 채우지 않는 선택 필드(`role`·`route`·`dimension`·`calls`·`permission`은 `null`, `grants`·`requires`는 `[]`)의 기본값은 `node_record`가 한 곳에서 정한다.
|
|
64
|
+
- 간선: `{"from", "to", "certainty"}`. `certainty`는 `confirmed`·`possible`·`unresolved`이고 같은 두 노드 사이에서는 가장 강한 값 하나만 남긴다(`strengthen_edge`). 해결하지 못한 대상은 `unresolved:<식>`(`UNRESOLVED_TARGET_PREFIX`)으로 잇는다.
|
|
65
|
+
- 진단: `{"level", "code", "message", "node_id"}`. `level`은 `error`·`warning`·`info`이고 이 순서(`LEVEL_RANK`), 그다음 `code`·`node_id`·`message` 순으로 정렬한다(`Diagnostic`).
|
|
66
|
+
- `validate_manifest(manifest)`는 최상위 키, 목록 형식, 노드 필드, 간선 확실성, 진단 수준을 확인하고 어긋나면 `ManifestError`를 올린다.
|
|
67
|
+
|
|
68
|
+
### 분석 규칙
|
|
69
|
+
|
|
70
|
+
- 진입 함수에서 시작해 `agent`·`step` 노드의 본문을 따라간다. `tool`·`model`은 끝 노드다. 표시하지 않은 진입 함수는 에이전트로 보며, 에이전트가 아닌 진입 함수나 같은 이름의 에이전트 둘은 `ManifestError`다.
|
|
71
|
+
- 호출 대상은 클로저·모듈 전역·내장 이름에서 찾고 점 경로를 따라간다. `self.method()`와 `Planner().plan()`은 클래스에서 찾는다.
|
|
72
|
+
- 표시하지 않은 함수라도 `root`(기본은 현재 작업 디렉터리) 아래이고 `site-packages`·`dist-packages` 밖이면 안으로 따라 들어간다. 같은 함수를 두 번 따라가지 않는다.
|
|
73
|
+
- 인자(또는 인자로 넘긴 리스트·튜플·집합의 원소)로 표시된 함수를 넘기면 `possible` 간선을 만든다.
|
|
74
|
+
- 본문 최상위 호출은 `confirmed`, 분기·반복·`try`·조건 표현식·`and`/`or` 뒤쪽·컴프리헨션·내부 함수 안이거나 앞 문장에 `return`·`raise`가 있으면 `possible`이다. 첨자 호출, 지역 이름 호출, 찾을 수 없는 이름 호출은 `unresolved`다.
|
|
75
|
+
- 진단 코드: `dynamic_dispatch`·`source_unavailable`(경고), `conditional_call`(정보).
|
|
76
|
+
|
|
77
|
+
## 공개 API
|
|
78
|
+
|
|
79
|
+
공개 이름은 각 모듈의 `__all__`이며 `tests/test_public_surface.py`가 고정한다.
|
|
80
|
+
|
|
81
|
+
| 모듈 | 공개 이름 |
|
|
82
|
+
|---|---|
|
|
83
|
+
| `motif.viewer` | `agent`, `step`, `tool`, `model`, `mark_of`, `NodeKind`, `NodeMark`, `build_manifest`, `ManifestError`, `viewer_html` |
|
|
84
|
+
| `motif.viewer.schema` | `MANIFEST_SCHEMA_VERSION`, `UNRESOLVED_TARGET_PREFIX`, `LEVEL_RANK`, `NODE_FIELDS`, `Diagnostic`, `ManifestError`, `node_record`, `strengthen_edge`, `validate_manifest` |
|
|
85
|
+
| `motif.viewer.analysis` | `Certainty`, `FunctionNode`, `conditional_calls`, `definition_of`, `display_path`, `dotted_path`, `find_function`, `interface_of`, `is_local`, `resolve` |
|
|
86
|
+
| `motif.viewer.loader` | `load_reference`, `ReferenceLoadError` |
|
|
87
|
+
|
|
88
|
+
`viewer_html()`은 뷰어 페이지 HTML 문자열을 돌려준다. 다른 도구가 같은 스키마의 매니페스트를 만들어 이 뷰어로 보려면 `motif.viewer.schema`의 계약을 따르면 된다.
|
|
89
|
+
|
|
90
|
+
## 뷰어가 읽는 감사 기록
|
|
91
|
+
|
|
92
|
+
뷰어 페이지는 JSON Lines 감사 기록도 읽는다. 각 줄은 문자열 `schema_version`·`event_id`·`timestamp`·`event_type`·`run_id`를 가져야 하고, `event_type`은 페이지에 적힌 알려진 이벤트 목록(`run.started` 등 15종) 안에 있어야 한다. 목록 밖 이벤트나 형식이 틀린 줄은 건너뛰고 건너뛴 수를 센다.
|
|
93
|
+
|
|
94
|
+
## 시험
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
uv sync
|
|
98
|
+
make quality
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`make quality`는 ruff 검사·서식, mypy strict, 커버리지 90% 이상의 pytest를 차례로 실행한다. 시험은 `motif.agent`를 가져오지 않으며, `site-packages` 없이 소스만으로 `manifest` 명령이 동작하는지 하위 프로세스로 확인한다(`tests/test_isolation.py`). 패키지가 표준 라이브러리와 자기 자신만 가져오는지, 의존성이 비어 있는지, 공용 네임스페이스 `src/motif`에 `__init__.py`가 없는지는 `tests/test_dependencies.py`가 고정한다.
|
|
102
|
+
|
|
103
|
+
## 배포
|
|
104
|
+
|
|
105
|
+
- `.github/workflows/ci.yml`은 PR과 `main` 푸시마다 Python 3.12·3.13에서 `make quality`를 실행한다.
|
|
106
|
+
- `.github/workflows/publish.yml`은 `v*` 태그를 푸시하면 `make quality`와 `uv build`를 거쳐 TestPyPI, PyPI 순서로 올린다. 토큰 없이 Trusted Publishing을 쓰므로 PyPI·TestPyPI에 이 저장소와 `publish.yml`, 환경 이름(`testpypi`, `pypi`)을 신뢰 게시자로 먼저 등록해야 한다.
|
|
107
|
+
- sdist에는 `src/motif`, `tests`, `README.md`, `LICENSE`, `pyproject.toml`만 들어가고, wheel에는 `motif/viewer`만 들어간다.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "motif-viewer"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "데코레이터만 붙이면 에이전트 구조 그래프를 보여 주는 표준 라이브러리 전용 뷰어"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
dependencies = []
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 3 - Alpha",
|
|
12
|
+
"Intended Audience :: Developers",
|
|
13
|
+
"Operating System :: OS Independent",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3.12",
|
|
16
|
+
"Programming Language :: Python :: 3.13",
|
|
17
|
+
"Typing :: Typed",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Repository = "https://github.com/motif-agent/motif-viewer"
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
motif-viewer = "motif.viewer.cli:main"
|
|
25
|
+
|
|
26
|
+
[dependency-groups]
|
|
27
|
+
dev = [
|
|
28
|
+
"pytest>=8.0",
|
|
29
|
+
"pytest-asyncio>=0.24",
|
|
30
|
+
"pytest-cov>=5.0",
|
|
31
|
+
"ruff>=0.6",
|
|
32
|
+
"mypy>=1.11",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[build-system]
|
|
36
|
+
requires = ["hatchling>=1.27"]
|
|
37
|
+
build-backend = "hatchling.build"
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build.targets.wheel]
|
|
40
|
+
packages = ["src/motif"]
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.sdist]
|
|
43
|
+
include = ["src/motif", "tests", "README.md", "LICENSE", "pyproject.toml"]
|
|
44
|
+
|
|
45
|
+
[tool.ruff]
|
|
46
|
+
line-length = 100
|
|
47
|
+
src = ["src", "tests"]
|
|
48
|
+
|
|
49
|
+
[tool.ruff.lint]
|
|
50
|
+
select = ["E", "F", "I", "B", "UP", "N"]
|
|
51
|
+
ignore = ["N818"]
|
|
52
|
+
|
|
53
|
+
[tool.mypy]
|
|
54
|
+
strict = true
|
|
55
|
+
python_version = "3.12"
|
|
56
|
+
files = ["src", "tests"]
|
|
57
|
+
mypy_path = ["src", "tests"]
|
|
58
|
+
explicit_package_bases = true
|
|
59
|
+
|
|
60
|
+
[tool.pytest.ini_options]
|
|
61
|
+
asyncio_mode = "auto"
|
|
62
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
63
|
+
testpaths = ["tests"]
|
|
64
|
+
addopts = "--strict-markers"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from motif.viewer.manifest import build_manifest
|
|
2
|
+
from motif.viewer.marks import NodeKind, NodeMark, agent, mark_of, model, step, tool
|
|
3
|
+
from motif.viewer.page import viewer_html
|
|
4
|
+
from motif.viewer.schema import ManifestError
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"ManifestError",
|
|
8
|
+
"NodeKind",
|
|
9
|
+
"NodeMark",
|
|
10
|
+
"agent",
|
|
11
|
+
"build_manifest",
|
|
12
|
+
"mark_of",
|
|
13
|
+
"model",
|
|
14
|
+
"step",
|
|
15
|
+
"tool",
|
|
16
|
+
"viewer_html",
|
|
17
|
+
]
|